[SCSI] zfcp: fix: mark fsf request failed when receiving unknown status qualifier
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / s390 / scsi / zfcp_fsf.c
blobbf66fc6d8a97d458f0bf7c58bf8e4cec491ec1c5
1 /*
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>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #define ZFCP_FSF_C_REVISION "$Revision: 1.92 $"
35 #include "zfcp_ext.h"
37 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
38 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
40 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
41 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
42 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
43 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
44 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
45 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
46 static int zfcp_fsf_send_fcp_command_task_management_handler(
47 struct zfcp_fsf_req *);
48 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
49 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
50 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
51 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
52 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
53 static inline int zfcp_fsf_req_sbal_check(
54 unsigned long *, struct zfcp_qdio_queue *, int);
55 static inline int zfcp_use_one_sbal(
56 struct scatterlist *, int, struct scatterlist *, int);
57 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
58 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
59 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
60 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
61 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
62 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
63 static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
64 static void zfcp_fsf_req_free(struct zfcp_fsf_req *);
66 /* association between FSF command and FSF QTCB type */
67 static u32 fsf_qtcb_type[] = {
68 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
69 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
76 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
77 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
78 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
79 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
80 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
83 static const char zfcp_act_subtable_type[5][8] = {
84 "unknown", "OS", "WWPN", "DID", "LUN"
87 /****************************************************************/
88 /*************** FSF related Functions *************************/
89 /****************************************************************/
91 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
94 * function: zfcp_fsf_req_alloc
96 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
97 * unsolicited requests) via helper functions
98 * Does some initial fsf request set-up.
100 * returns: pointer to allocated fsf_req if successfull
101 * NULL otherwise
103 * locks: none
106 static struct zfcp_fsf_req *
107 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
109 size_t size;
110 void *ptr;
111 struct zfcp_fsf_req *fsf_req = NULL;
113 if (req_flags & ZFCP_REQ_NO_QTCB)
114 size = sizeof(struct zfcp_fsf_req);
115 else
116 size = sizeof(struct zfcp_fsf_req_pool_element);
118 if (likely(pool != NULL))
119 ptr = mempool_alloc(pool, GFP_ATOMIC);
120 else
121 ptr = kmalloc(size, GFP_ATOMIC);
123 if (unlikely(NULL == ptr))
124 goto out;
126 memset(ptr, 0, size);
128 if (req_flags & ZFCP_REQ_NO_QTCB) {
129 fsf_req = (struct zfcp_fsf_req *) ptr;
130 } else {
131 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
132 fsf_req->qtcb =
133 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
136 fsf_req->pool = pool;
138 out:
139 return fsf_req;
143 * function: zfcp_fsf_req_free
145 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
146 * returns it into the pool via helper functions.
148 * returns: sod all
150 * locks: none
152 static void
153 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
155 if (likely(fsf_req->pool != NULL))
156 mempool_free(fsf_req, fsf_req->pool);
157 else
158 kfree(fsf_req);
162 * function:
164 * purpose:
166 * returns:
168 * note: qdio queues shall be down (no ongoing inbound processing)
171 zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
173 int retval = 0;
174 struct zfcp_fsf_req *fsf_req, *tmp;
176 list_for_each_entry_safe(fsf_req, tmp, &adapter->fsf_req_list_head,
177 list)
178 zfcp_fsf_req_dismiss(fsf_req);
179 /* wait_event_timeout? */
180 while (!list_empty(&adapter->fsf_req_list_head)) {
181 ZFCP_LOG_DEBUG("fsf req list of adapter %s not yet empty\n",
182 zfcp_get_busid_by_adapter(adapter));
183 /* wait for woken intiators to clean up their requests */
184 msleep(jiffies_to_msecs(ZFCP_FSFREQ_CLEANUP_TIMEOUT));
187 /* consistency check */
188 if (atomic_read(&adapter->fsf_reqs_active)) {
189 ZFCP_LOG_NORMAL("bug: There are still %d FSF requests pending "
190 "on adapter %s after cleanup.\n",
191 atomic_read(&adapter->fsf_reqs_active),
192 zfcp_get_busid_by_adapter(adapter));
193 atomic_set(&adapter->fsf_reqs_active, 0);
196 return retval;
200 * function:
202 * purpose:
204 * returns:
206 static void
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
220 * !0 - failure
222 * context:
225 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
227 int retval = 0;
228 int cleanup;
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);
241 goto out;
242 } else
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))
250 cleanup = 1;
251 else
252 cleanup = 0;
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);
264 } else {
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);
280 out:
281 return retval;
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)
291 * returns:
293 * context:
295 * locks:
297 static int
298 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
300 int retval = 0;
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)) {
318 ZFCP_LOG_NORMAL
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));
324 goto forget_log;
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));
335 goto forget_log;
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);
343 forget_log:
345 /* evaluate FSF Protocol Status */
346 switch (fsf_req->qtcb->prefix.prot_status) {
348 case FSF_PROT_GOOD:
349 case FSF_PROT_FSF_STATUS_PRESENTED:
350 break;
352 case FSF_PROT_QTCB_VERSION_ERROR:
353 ZFCP_LOG_NORMAL("error: The adapter %s contains "
354 "microcode of version 0x%x, the device driver "
355 "only supports 0x%x. Aborting.\n",
356 zfcp_get_busid_by_adapter(adapter),
357 fsf_req->qtcb->prefix.prot_status_qual.
358 version_error.fsf_version, ZFCP_QTCB_VERSION);
359 /* stop operation for this adapter */
360 debug_text_exception(adapter->erp_dbf, 0, "prot_ver_err");
361 zfcp_erp_adapter_shutdown(adapter, 0);
362 zfcp_cmd_dbf_event_fsf("qverserr", fsf_req,
363 &fsf_req->qtcb->prefix.prot_status_qual,
364 sizeof (union fsf_prot_status_qual));
365 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
366 break;
368 case FSF_PROT_SEQ_NUMB_ERROR:
369 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
370 "driver (0x%x) and adapter %s (0x%x). "
371 "Restarting all operations on this adapter.\n",
372 fsf_req->qtcb->prefix.req_seq_no,
373 zfcp_get_busid_by_adapter(adapter),
374 fsf_req->qtcb->prefix.prot_status_qual.
375 sequence_error.exp_req_seq_no);
376 debug_text_exception(adapter->erp_dbf, 0, "prot_seq_err");
377 /* restart operation on this adapter */
378 zfcp_erp_adapter_reopen(adapter, 0);
379 zfcp_cmd_dbf_event_fsf("seqnoerr", fsf_req,
380 &fsf_req->qtcb->prefix.prot_status_qual,
381 sizeof (union fsf_prot_status_qual));
382 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
383 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
384 break;
386 case FSF_PROT_UNSUPP_QTCB_TYPE:
387 ZFCP_LOG_NORMAL("error: Packet header type used by the "
388 "device driver is incompatible with "
389 "that used on adapter %s. "
390 "Stopping all operations on this adapter.\n",
391 zfcp_get_busid_by_adapter(adapter));
392 debug_text_exception(adapter->erp_dbf, 0, "prot_unsup_qtcb");
393 zfcp_erp_adapter_shutdown(adapter, 0);
394 zfcp_cmd_dbf_event_fsf("unsqtcbt", fsf_req,
395 &fsf_req->qtcb->prefix.prot_status_qual,
396 sizeof (union fsf_prot_status_qual));
397 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
398 break;
400 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
401 zfcp_cmd_dbf_event_fsf("hconinit", fsf_req,
402 &fsf_req->qtcb->prefix.prot_status_qual,
403 sizeof (union fsf_prot_status_qual));
404 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
405 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
406 &(adapter->status));
407 debug_text_event(adapter->erp_dbf, 3, "prot_con_init");
408 break;
410 case FSF_PROT_DUPLICATE_REQUEST_ID:
411 if (fsf_req->qtcb) {
412 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
413 "to the adapter %s is ambiguous. "
414 "Stopping all operations on this "
415 "adapter.\n",
416 *(unsigned long long *)
417 (&fsf_req->qtcb->bottom.support.
418 req_handle),
419 zfcp_get_busid_by_adapter(adapter));
420 } else {
421 ZFCP_LOG_NORMAL("bug: The request identifier %p "
422 "to the adapter %s is ambiguous. "
423 "Stopping all operations on this "
424 "adapter. "
425 "(bug: got this for an unsolicited "
426 "status read request)\n",
427 fsf_req,
428 zfcp_get_busid_by_adapter(adapter));
430 debug_text_exception(adapter->erp_dbf, 0, "prot_dup_id");
431 zfcp_erp_adapter_shutdown(adapter, 0);
432 zfcp_cmd_dbf_event_fsf("dupreqid", fsf_req,
433 &fsf_req->qtcb->prefix.prot_status_qual,
434 sizeof (union fsf_prot_status_qual));
435 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
436 break;
438 case FSF_PROT_LINK_DOWN:
440 * 'test and set' is not atomic here -
441 * it's ok as long as calls to our response queue handler
442 * (and thus execution of this code here) are serialized
443 * by the qdio module
445 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
446 &adapter->status)) {
447 switch (fsf_req->qtcb->prefix.prot_status_qual.
448 locallink_error.code) {
449 case FSF_PSQ_LINK_NOLIGHT:
450 ZFCP_LOG_INFO("The local link to adapter %s "
451 "is down (no light detected).\n",
452 zfcp_get_busid_by_adapter(
453 adapter));
454 break;
455 case FSF_PSQ_LINK_WRAPPLUG:
456 ZFCP_LOG_INFO("The local link to adapter %s "
457 "is down (wrap plug detected).\n",
458 zfcp_get_busid_by_adapter(
459 adapter));
460 break;
461 case FSF_PSQ_LINK_NOFCP:
462 ZFCP_LOG_INFO("The local link to adapter %s "
463 "is down (adjacent node on "
464 "link does not support FCP).\n",
465 zfcp_get_busid_by_adapter(
466 adapter));
467 break;
468 default:
469 ZFCP_LOG_INFO("The local link to adapter %s "
470 "is down "
471 "(warning: unknown reason "
472 "code).\n",
473 zfcp_get_busid_by_adapter(
474 adapter));
475 break;
479 * Due to the 'erp failed' flag the adapter won't
480 * be recovered but will be just set to 'blocked'
481 * state. All subordinary devices will have state
482 * 'blocked' and 'erp failed', too.
483 * Thus the adapter is still able to provide
484 * 'link up' status without being flooded with
485 * requests.
486 * (note: even 'close port' is not permitted)
488 ZFCP_LOG_INFO("Stopping all operations for adapter "
489 "%s.\n",
490 zfcp_get_busid_by_adapter(adapter));
491 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
492 ZFCP_STATUS_COMMON_ERP_FAILED,
493 &adapter->status);
494 zfcp_erp_adapter_reopen(adapter, 0);
496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
497 break;
499 case FSF_PROT_REEST_QUEUE:
500 debug_text_event(adapter->erp_dbf, 1, "prot_reest_queue");
501 ZFCP_LOG_INFO("The local link to adapter with "
502 "%s was re-plugged. "
503 "Re-starting operations on this adapter.\n",
504 zfcp_get_busid_by_adapter(adapter));
505 /* All ports should be marked as ready to run again */
506 zfcp_erp_modify_adapter_status(adapter,
507 ZFCP_STATUS_COMMON_RUNNING,
508 ZFCP_SET);
509 zfcp_erp_adapter_reopen(adapter,
510 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
511 | ZFCP_STATUS_COMMON_ERP_FAILED);
512 zfcp_cmd_dbf_event_fsf("reestque", fsf_req,
513 &fsf_req->qtcb->prefix.prot_status_qual,
514 sizeof (union fsf_prot_status_qual));
515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
516 break;
518 case FSF_PROT_ERROR_STATE:
519 ZFCP_LOG_NORMAL("error: The adapter %s "
520 "has entered the error state. "
521 "Restarting all operations on this "
522 "adapter.\n",
523 zfcp_get_busid_by_adapter(adapter));
524 debug_text_event(adapter->erp_dbf, 0, "prot_err_sta");
525 /* restart operation on this adapter */
526 zfcp_erp_adapter_reopen(adapter, 0);
527 zfcp_cmd_dbf_event_fsf("proterrs", fsf_req,
528 &fsf_req->qtcb->prefix.prot_status_qual,
529 sizeof (union fsf_prot_status_qual));
530 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
531 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
532 break;
534 default:
535 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
536 "provided by the adapter %s "
537 "is not compatible with the device driver. "
538 "Stopping all operations on this adapter. "
539 "(debug info 0x%x).\n",
540 zfcp_get_busid_by_adapter(adapter),
541 fsf_req->qtcb->prefix.prot_status);
542 debug_text_event(adapter->erp_dbf, 0, "prot_inval:");
543 debug_exception(adapter->erp_dbf, 0,
544 &fsf_req->qtcb->prefix.prot_status,
545 sizeof (u32));
546 zfcp_erp_adapter_shutdown(adapter, 0);
547 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
550 skip_protstatus:
552 * always call specific handlers to give them a chance to do
553 * something meaningful even in error cases
555 zfcp_fsf_fsfstatus_eval(fsf_req);
556 return retval;
560 * function: zfcp_fsf_fsfstatus_eval
562 * purpose: evaluates FSF status of completed FSF request
563 * and acts accordingly
565 * returns:
567 static int
568 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
570 int retval = 0;
572 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
573 goto skip_fsfstatus;
576 /* evaluate FSF Status */
577 switch (fsf_req->qtcb->header.fsf_status) {
578 case FSF_UNKNOWN_COMMAND:
579 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
580 "not known by the adapter %s "
581 "Stopping all operations on this adapter. "
582 "(debug info 0x%x).\n",
583 zfcp_get_busid_by_adapter(fsf_req->adapter),
584 fsf_req->qtcb->header.fsf_command);
585 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
586 "fsf_s_unknown");
587 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
588 zfcp_cmd_dbf_event_fsf("unknownc", fsf_req,
589 &fsf_req->qtcb->header.fsf_status_qual,
590 sizeof (union fsf_status_qual));
591 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
592 break;
594 case FSF_FCP_RSP_AVAILABLE:
595 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
596 "SCSI stack.\n");
597 debug_text_event(fsf_req->adapter->erp_dbf, 3, "fsf_s_rsp");
598 break;
600 case FSF_ADAPTER_STATUS_AVAILABLE:
601 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_astatus");
602 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
603 break;
605 default:
606 break;
609 skip_fsfstatus:
611 * always call specific handlers to give them a chance to do
612 * something meaningful even in error cases
614 zfcp_fsf_req_dispatch(fsf_req);
616 return retval;
620 * function: zfcp_fsf_fsfstatus_qual_eval
622 * purpose: evaluates FSF status-qualifier of completed FSF request
623 * and acts accordingly
625 * returns:
627 static int
628 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
630 int retval = 0;
632 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
633 case FSF_SQ_FCP_RSP_AVAILABLE:
634 debug_text_event(fsf_req->adapter->erp_dbf, 4, "fsf_sq_rsp");
635 break;
636 case FSF_SQ_RETRY_IF_POSSIBLE:
637 /* The SCSI-stack may now issue retries or escalate */
638 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_retry");
639 zfcp_cmd_dbf_event_fsf("sqretry", fsf_req,
640 &fsf_req->qtcb->header.fsf_status_qual,
641 sizeof (union fsf_status_qual));
642 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
643 break;
644 case FSF_SQ_COMMAND_ABORTED:
645 /* Carry the aborted state on to upper layer */
646 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_abort");
647 zfcp_cmd_dbf_event_fsf("sqabort", fsf_req,
648 &fsf_req->qtcb->header.fsf_status_qual,
649 sizeof (union fsf_status_qual));
650 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
651 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
652 break;
653 case FSF_SQ_NO_RECOM:
654 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
655 "fsf_sq_no_rec");
656 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
657 "problem on the adapter %s "
658 "Stopping all operations on this adapter. ",
659 zfcp_get_busid_by_adapter(fsf_req->adapter));
660 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
661 zfcp_cmd_dbf_event_fsf("sqnrecom", fsf_req,
662 &fsf_req->qtcb->header.fsf_status_qual,
663 sizeof (union fsf_status_qual));
664 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
665 break;
666 case FSF_SQ_ULP_PROGRAMMING_ERROR:
667 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
668 "(adapter %s)\n",
669 zfcp_get_busid_by_adapter(fsf_req->adapter));
670 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
671 "fsf_sq_ulp_err");
672 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
673 break;
674 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
675 case FSF_SQ_NO_RETRY_POSSIBLE:
676 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
677 /* dealt with in the respective functions */
678 break;
679 default:
680 ZFCP_LOG_NORMAL("bug: Additional status info could "
681 "not be interpreted properly.\n");
682 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
683 (char *) &fsf_req->qtcb->header.fsf_status_qual,
684 sizeof (union fsf_status_qual));
685 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval:");
686 debug_exception(fsf_req->adapter->erp_dbf, 0,
687 &fsf_req->qtcb->header.fsf_status_qual.word[0],
688 sizeof (u32));
689 zfcp_cmd_dbf_event_fsf("squndef", fsf_req,
690 &fsf_req->qtcb->header.fsf_status_qual,
691 sizeof (union fsf_status_qual));
692 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
693 break;
696 return retval;
700 * function: zfcp_fsf_req_dispatch
702 * purpose: calls the appropriate command specific handler
704 * returns:
706 static int
707 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
709 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
710 struct zfcp_adapter *adapter = fsf_req->adapter;
711 int retval = 0;
713 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
714 ZFCP_LOG_TRACE("fsf_req=%p, QTCB=%p\n", fsf_req, fsf_req->qtcb);
715 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
716 (char *) fsf_req->qtcb, sizeof(struct fsf_qtcb));
719 switch (fsf_req->fsf_command) {
721 case FSF_QTCB_FCP_CMND:
722 zfcp_fsf_send_fcp_command_handler(fsf_req);
723 break;
725 case FSF_QTCB_ABORT_FCP_CMND:
726 zfcp_fsf_abort_fcp_command_handler(fsf_req);
727 break;
729 case FSF_QTCB_SEND_GENERIC:
730 zfcp_fsf_send_ct_handler(fsf_req);
731 break;
733 case FSF_QTCB_OPEN_PORT_WITH_DID:
734 zfcp_fsf_open_port_handler(fsf_req);
735 break;
737 case FSF_QTCB_OPEN_LUN:
738 zfcp_fsf_open_unit_handler(fsf_req);
739 break;
741 case FSF_QTCB_CLOSE_LUN:
742 zfcp_fsf_close_unit_handler(fsf_req);
743 break;
745 case FSF_QTCB_CLOSE_PORT:
746 zfcp_fsf_close_port_handler(fsf_req);
747 break;
749 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
750 zfcp_fsf_close_physical_port_handler(fsf_req);
751 break;
753 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
754 zfcp_fsf_exchange_config_data_handler(fsf_req);
755 break;
757 case FSF_QTCB_EXCHANGE_PORT_DATA:
758 zfcp_fsf_exchange_port_data_handler(fsf_req);
759 break;
761 case FSF_QTCB_SEND_ELS:
762 zfcp_fsf_send_els_handler(fsf_req);
763 break;
765 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
766 zfcp_fsf_control_file_handler(fsf_req);
767 break;
769 case FSF_QTCB_UPLOAD_CONTROL_FILE:
770 zfcp_fsf_control_file_handler(fsf_req);
771 break;
773 default:
774 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
775 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
776 "not supported by the adapter %s\n",
777 zfcp_get_busid_by_adapter(fsf_req->adapter));
778 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
779 ZFCP_LOG_NORMAL
780 ("bug: Command issued by the device driver differs "
781 "from the command returned by the adapter %s "
782 "(debug info 0x%x, 0x%x).\n",
783 zfcp_get_busid_by_adapter(fsf_req->adapter),
784 fsf_req->fsf_command,
785 fsf_req->qtcb->header.fsf_command);
788 if (!erp_action)
789 return retval;
791 debug_text_event(adapter->erp_dbf, 3, "a_frh");
792 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
793 zfcp_erp_async_handler(erp_action, 0);
795 return retval;
799 * function: zfcp_fsf_status_read
801 * purpose: initiates a Status Read command at the specified adapter
803 * returns:
806 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
808 struct zfcp_fsf_req *fsf_req;
809 struct fsf_status_read_buffer *status_buffer;
810 unsigned long lock_flags;
811 volatile struct qdio_buffer_element *sbale;
812 int retval = 0;
814 /* setup new FSF request */
815 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
816 req_flags | ZFCP_REQ_NO_QTCB,
817 adapter->pool.fsf_req_status_read,
818 &lock_flags, &fsf_req);
819 if (retval < 0) {
820 ZFCP_LOG_INFO("error: Could not create unsolicited status "
821 "buffer for adapter %s.\n",
822 zfcp_get_busid_by_adapter(adapter));
823 goto failed_req_create;
826 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
827 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
828 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
829 fsf_req->sbale_curr = 2;
831 status_buffer =
832 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
833 if (!status_buffer) {
834 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
835 goto failed_buf;
837 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
838 fsf_req->data.status_read.buffer = status_buffer;
840 /* insert pointer to respective buffer */
841 sbale = zfcp_qdio_sbale_curr(fsf_req);
842 sbale->addr = (void *) status_buffer;
843 sbale->length = sizeof(struct fsf_status_read_buffer);
845 /* start QDIO request for this FSF request */
846 retval = zfcp_fsf_req_send(fsf_req, NULL);
847 if (retval) {
848 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
849 "environment.\n");
850 goto failed_req_send;
853 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
854 zfcp_get_busid_by_adapter(adapter));
855 goto out;
857 failed_req_send:
858 mempool_free(status_buffer, adapter->pool.data_status_read);
860 failed_buf:
861 zfcp_fsf_req_free(fsf_req);
862 failed_req_create:
863 out:
864 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
865 return retval;
868 static int
869 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
871 struct fsf_status_read_buffer *status_buffer;
872 struct zfcp_adapter *adapter;
873 struct zfcp_port *port;
874 unsigned long flags;
876 status_buffer = fsf_req->data.status_read.buffer;
877 adapter = fsf_req->adapter;
879 read_lock_irqsave(&zfcp_data.config_lock, flags);
880 list_for_each_entry(port, &adapter->port_list_head, list)
881 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
882 break;
883 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
885 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
886 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
887 "nonexisting port with d_id 0x%08x on "
888 "adapter %s. Ignored.\n",
889 status_buffer->d_id & ZFCP_DID_MASK,
890 zfcp_get_busid_by_adapter(adapter));
891 goto out;
894 switch (status_buffer->status_subtype) {
896 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
897 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
898 zfcp_erp_port_reopen(port, 0);
899 break;
901 case FSF_STATUS_READ_SUB_ERROR_PORT:
902 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
903 zfcp_erp_port_shutdown(port, 0);
904 break;
906 default:
907 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
908 debug_exception(adapter->erp_dbf, 0,
909 &status_buffer->status_subtype, sizeof (u32));
910 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
911 "for a reopen indication on port with "
912 "d_id 0x%08x on the adapter %s. "
913 "Ignored. (debug info 0x%x)\n",
914 status_buffer->d_id,
915 zfcp_get_busid_by_adapter(adapter),
916 status_buffer->status_subtype);
918 out:
919 return 0;
923 * function: zfcp_fsf_status_read_handler
925 * purpose: is called for finished Open Port command
927 * returns:
929 static int
930 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
932 int retval = 0;
933 struct zfcp_adapter *adapter = fsf_req->adapter;
934 struct fsf_status_read_buffer *status_buffer =
935 fsf_req->data.status_read.buffer;
937 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
938 mempool_free(status_buffer, adapter->pool.data_status_read);
939 zfcp_fsf_req_cleanup(fsf_req);
940 goto out;
943 switch (status_buffer->status_type) {
945 case FSF_STATUS_READ_PORT_CLOSED:
946 debug_text_event(adapter->erp_dbf, 3, "unsol_pclosed:");
947 debug_event(adapter->erp_dbf, 3,
948 &status_buffer->d_id, sizeof (u32));
949 zfcp_fsf_status_read_port_closed(fsf_req);
950 break;
952 case FSF_STATUS_READ_INCOMING_ELS:
953 debug_text_event(adapter->erp_dbf, 3, "unsol_els:");
954 zfcp_fsf_incoming_els(fsf_req);
955 break;
957 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
958 debug_text_event(adapter->erp_dbf, 3, "unsol_sense:");
959 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
960 zfcp_get_busid_by_adapter(adapter));
961 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, (char *) status_buffer,
962 sizeof(struct fsf_status_read_buffer));
963 break;
965 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
966 debug_text_event(adapter->erp_dbf, 3, "unsol_bit_err:");
967 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
968 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
969 (char *) status_buffer,
970 sizeof (struct fsf_status_read_buffer));
971 break;
973 case FSF_STATUS_READ_LINK_DOWN:
974 debug_text_event(adapter->erp_dbf, 0, "unsol_link_down:");
975 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
976 zfcp_get_busid_by_adapter(adapter));
977 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
978 &adapter->status);
979 zfcp_erp_adapter_failed(adapter);
980 break;
982 case FSF_STATUS_READ_LINK_UP:
983 debug_text_event(adapter->erp_dbf, 2, "unsol_link_up:");
984 ZFCP_LOG_INFO("Local link to adapter %s was replugged. "
985 "Restarting operations on this adapter\n",
986 zfcp_get_busid_by_adapter(adapter));
987 /* All ports should be marked as ready to run again */
988 zfcp_erp_modify_adapter_status(adapter,
989 ZFCP_STATUS_COMMON_RUNNING,
990 ZFCP_SET);
991 zfcp_erp_adapter_reopen(adapter,
992 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
993 | ZFCP_STATUS_COMMON_ERP_FAILED);
994 break;
996 case FSF_STATUS_READ_CFDC_UPDATED:
997 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_update:");
998 ZFCP_LOG_INFO("CFDC has been updated on the adapter %s\n",
999 zfcp_get_busid_by_adapter(adapter));
1000 zfcp_erp_adapter_access_changed(adapter);
1001 break;
1003 case FSF_STATUS_READ_CFDC_HARDENED:
1004 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_harden:");
1005 switch (status_buffer->status_subtype) {
1006 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1007 ZFCP_LOG_INFO("CFDC of adapter %s saved on SE\n",
1008 zfcp_get_busid_by_adapter(adapter));
1009 break;
1010 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1011 ZFCP_LOG_INFO("CFDC of adapter %s has been copied "
1012 "to the secondary SE\n",
1013 zfcp_get_busid_by_adapter(adapter));
1014 break;
1015 default:
1016 ZFCP_LOG_INFO("CFDC of adapter %s has been hardened\n",
1017 zfcp_get_busid_by_adapter(adapter));
1019 break;
1021 default:
1022 debug_text_event(adapter->erp_dbf, 0, "unsol_unknown:");
1023 debug_exception(adapter->erp_dbf, 0,
1024 &status_buffer->status_type, sizeof (u32));
1025 ZFCP_LOG_NORMAL("bug: An unsolicited status packet of unknown "
1026 "type was received (debug info 0x%x)\n",
1027 status_buffer->status_type);
1028 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1029 status_buffer);
1030 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1031 (char *) status_buffer,
1032 sizeof (struct fsf_status_read_buffer));
1033 break;
1035 mempool_free(status_buffer, adapter->pool.data_status_read);
1036 zfcp_fsf_req_cleanup(fsf_req);
1038 * recycle buffer and start new request repeat until outbound
1039 * queue is empty or adapter shutdown is requested
1042 * FIXME(qdio):
1043 * we may wait in the req_create for 5s during shutdown, so
1044 * qdio_cleanup will have to wait at least that long before returning
1045 * with failure to allow us a proper cleanup under all circumstances
1048 * FIXME:
1049 * allocation failure possible? (Is this code needed?)
1051 retval = zfcp_fsf_status_read(adapter, 0);
1052 if (retval < 0) {
1053 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1054 "request for the adapter %s.\n",
1055 zfcp_get_busid_by_adapter(adapter));
1056 /* temporary fix to avoid status read buffer shortage */
1057 adapter->status_read_failed++;
1058 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1059 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1060 ZFCP_LOG_INFO("restart adapter %s due to status read "
1061 "buffer shortage\n",
1062 zfcp_get_busid_by_adapter(adapter));
1063 zfcp_erp_adapter_reopen(adapter, 0);
1066 out:
1067 return retval;
1071 * function: zfcp_fsf_abort_fcp_command
1073 * purpose: tells FSF to abort a running SCSI command
1075 * returns: address of initiated FSF request
1076 * NULL - request could not be initiated
1078 * FIXME(design): should be watched by a timeout !!!
1079 * FIXME(design) shouldn't this be modified to return an int
1080 * also...don't know how though
1082 struct zfcp_fsf_req *
1083 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1084 struct zfcp_adapter *adapter,
1085 struct zfcp_unit *unit, int req_flags)
1087 volatile struct qdio_buffer_element *sbale;
1088 unsigned long lock_flags;
1089 struct zfcp_fsf_req *fsf_req = NULL;
1090 int retval = 0;
1092 /* setup new FSF request */
1093 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1094 req_flags, adapter->pool.fsf_req_abort,
1095 &lock_flags, &fsf_req);
1096 if (retval < 0) {
1097 ZFCP_LOG_INFO("error: Failed to create an abort command "
1098 "request for lun 0x%016Lx on port 0x%016Lx "
1099 "on adapter %s.\n",
1100 unit->fcp_lun,
1101 unit->port->wwpn,
1102 zfcp_get_busid_by_adapter(adapter));
1103 goto out;
1106 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1107 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1108 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1110 fsf_req->data.abort_fcp_command.unit = unit;
1112 /* set handles of unit and its parent port in QTCB */
1113 fsf_req->qtcb->header.lun_handle = unit->handle;
1114 fsf_req->qtcb->header.port_handle = unit->port->handle;
1116 /* set handle of request which should be aborted */
1117 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1119 /* start QDIO request for this FSF request */
1121 zfcp_fsf_start_scsi_er_timer(adapter);
1122 retval = zfcp_fsf_req_send(fsf_req, NULL);
1123 if (retval) {
1124 del_timer(&adapter->scsi_er_timer);
1125 ZFCP_LOG_INFO("error: Failed to send abort command request "
1126 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1127 zfcp_get_busid_by_adapter(adapter),
1128 unit->port->wwpn, unit->fcp_lun);
1129 zfcp_fsf_req_free(fsf_req);
1130 fsf_req = NULL;
1131 goto out;
1134 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1135 "(adapter%s, port d_id=0x%08x, "
1136 "unit x%016Lx, old_req_id=0x%lx)\n",
1137 zfcp_get_busid_by_adapter(adapter),
1138 unit->port->d_id,
1139 unit->fcp_lun, old_req_id);
1140 out:
1141 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1142 return fsf_req;
1146 * function: zfcp_fsf_abort_fcp_command_handler
1148 * purpose: is called for finished Abort FCP Command request
1150 * returns:
1152 static int
1153 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1155 int retval = -EINVAL;
1156 struct zfcp_unit *unit = new_fsf_req->data.abort_fcp_command.unit;
1157 unsigned char status_qual =
1158 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1160 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1162 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1163 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1164 goto skip_fsfstatus;
1167 /* evaluate FSF status in QTCB */
1168 switch (new_fsf_req->qtcb->header.fsf_status) {
1170 case FSF_PORT_HANDLE_NOT_VALID:
1171 if (status_qual >> 4 != status_qual % 0xf) {
1172 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1173 "fsf_s_phand_nv0");
1175 * In this case a command that was sent prior to a port
1176 * reopen was aborted (handles are different). This is
1177 * fine.
1179 } else {
1180 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1181 "port 0x%016Lx on adapter %s invalid. "
1182 "This may happen occasionally.\n",
1183 unit->port->handle,
1184 unit->port->wwpn,
1185 zfcp_get_busid_by_unit(unit));
1186 ZFCP_LOG_INFO("status qualifier:\n");
1187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1188 (char *) &new_fsf_req->qtcb->header.
1189 fsf_status_qual,
1190 sizeof (union fsf_status_qual));
1191 /* Let's hope this sorts out the mess */
1192 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1193 "fsf_s_phand_nv1");
1194 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1195 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1197 break;
1199 case FSF_LUN_HANDLE_NOT_VALID:
1200 if (status_qual >> 4 != status_qual % 0xf) {
1201 /* 2 */
1202 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1203 "fsf_s_lhand_nv0");
1205 * In this case a command that was sent prior to a unit
1206 * reopen was aborted (handles are different).
1207 * This is fine.
1209 } else {
1210 ZFCP_LOG_INFO
1211 ("Warning: Temporary LUN identifier 0x%x of LUN "
1212 "0x%016Lx on port 0x%016Lx on adapter %s is "
1213 "invalid. This may happen in rare cases. "
1214 "Trying to re-establish link.\n",
1215 unit->handle,
1216 unit->fcp_lun,
1217 unit->port->wwpn,
1218 zfcp_get_busid_by_unit(unit));
1219 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1220 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1221 (char *) &new_fsf_req->qtcb->header.
1222 fsf_status_qual,
1223 sizeof (union fsf_status_qual));
1224 /* Let's hope this sorts out the mess */
1225 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1226 "fsf_s_lhand_nv1");
1227 zfcp_erp_port_reopen(unit->port, 0);
1228 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1230 break;
1232 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1233 retval = 0;
1234 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1235 "fsf_s_no_exist");
1236 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1237 break;
1239 case FSF_PORT_BOXED:
1240 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1241 "be reopened\n", unit->port->wwpn,
1242 zfcp_get_busid_by_unit(unit));
1243 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1244 "fsf_s_pboxed");
1245 zfcp_erp_port_reopen(unit->port, 0);
1246 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1247 | ZFCP_STATUS_FSFREQ_RETRY;
1248 break;
1250 case FSF_LUN_BOXED:
1251 ZFCP_LOG_INFO(
1252 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1253 "to be reopened\n",
1254 unit->fcp_lun, unit->port->wwpn,
1255 zfcp_get_busid_by_unit(unit));
1256 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1257 zfcp_erp_unit_reopen(unit, 0);
1258 zfcp_cmd_dbf_event_fsf("unitbox", new_fsf_req,
1259 &new_fsf_req->qtcb->header.fsf_status_qual,
1260 sizeof(union fsf_status_qual));
1261 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1262 | ZFCP_STATUS_FSFREQ_RETRY;
1263 break;
1265 case FSF_ADAPTER_STATUS_AVAILABLE:
1266 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1267 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1268 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1269 "fsf_sq_ltest");
1270 zfcp_test_link(unit->port);
1271 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1272 break;
1273 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1274 /* SCSI stack will escalate */
1275 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1276 "fsf_sq_ulp");
1277 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1278 break;
1279 default:
1280 ZFCP_LOG_NORMAL
1281 ("bug: Wrong status qualifier 0x%x arrived.\n",
1282 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1283 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1284 "fsf_sq_inval:");
1285 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1286 &new_fsf_req->qtcb->header.
1287 fsf_status_qual.word[0], sizeof (u32));
1288 break;
1290 break;
1292 case FSF_GOOD:
1293 retval = 0;
1294 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1295 break;
1297 default:
1298 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1299 "(debug info 0x%x)\n",
1300 new_fsf_req->qtcb->header.fsf_status);
1301 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1302 "fsf_s_inval:");
1303 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1304 &new_fsf_req->qtcb->header.fsf_status,
1305 sizeof (u32));
1306 break;
1308 skip_fsfstatus:
1309 return retval;
1313 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1314 * one SBALE
1315 * Two scatter-gather lists are passed, one for the reqeust and one for the
1316 * response.
1318 static inline int
1319 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1320 struct scatterlist *resp, int resp_count)
1322 return ((req_count == 1) &&
1323 (resp_count == 1) &&
1324 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1325 PAGE_MASK) ==
1326 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1327 req[0].length - 1) & PAGE_MASK)) &&
1328 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1329 PAGE_MASK) ==
1330 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1331 resp[0].length - 1) & PAGE_MASK)));
1335 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1336 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1337 * the request
1338 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1339 * a struct zfcp_fsf_req
1340 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1341 * is sent within error recovery
1344 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1345 struct zfcp_erp_action *erp_action)
1347 volatile struct qdio_buffer_element *sbale;
1348 struct zfcp_port *port;
1349 struct zfcp_adapter *adapter;
1350 struct zfcp_fsf_req *fsf_req;
1351 unsigned long lock_flags;
1352 int bytes;
1353 int ret = 0;
1355 port = ct->port;
1356 adapter = port->adapter;
1358 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1359 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1360 pool, &lock_flags, &fsf_req);
1361 if (ret < 0) {
1362 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1363 "adapter: %s\n",
1364 zfcp_get_busid_by_adapter(adapter));
1365 goto failed_req;
1368 if (erp_action != NULL) {
1369 erp_action->fsf_req = fsf_req;
1370 fsf_req->erp_action = erp_action;
1373 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1374 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1375 ct->resp, ct->resp_count)){
1376 /* both request buffer and response buffer
1377 fit into one sbale each */
1378 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1379 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1380 sbale[2].length = ct->req[0].length;
1381 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1382 sbale[3].length = ct->resp[0].length;
1383 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1384 } else if (adapter->supported_features &
1385 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1386 /* try to use chained SBALs */
1387 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1388 SBAL_FLAGS0_TYPE_WRITE_READ,
1389 ct->req, ct->req_count,
1390 ZFCP_MAX_SBALS_PER_CT_REQ);
1391 if (bytes <= 0) {
1392 ZFCP_LOG_INFO("error: creation of CT request failed "
1393 "on adapter %s\n",
1394 zfcp_get_busid_by_adapter(adapter));
1395 if (bytes == 0)
1396 ret = -ENOMEM;
1397 else
1398 ret = bytes;
1400 goto failed_send;
1402 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1403 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1404 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1405 SBAL_FLAGS0_TYPE_WRITE_READ,
1406 ct->resp, ct->resp_count,
1407 ZFCP_MAX_SBALS_PER_CT_REQ);
1408 if (bytes <= 0) {
1409 ZFCP_LOG_INFO("error: creation of CT request failed "
1410 "on adapter %s\n",
1411 zfcp_get_busid_by_adapter(adapter));
1412 if (bytes == 0)
1413 ret = -ENOMEM;
1414 else
1415 ret = bytes;
1417 goto failed_send;
1419 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1420 } else {
1421 /* reject send generic request */
1422 ZFCP_LOG_INFO(
1423 "error: microcode does not support chained SBALs,"
1424 "CT request too big (adapter %s)\n",
1425 zfcp_get_busid_by_adapter(adapter));
1426 ret = -EOPNOTSUPP;
1427 goto failed_send;
1430 /* settings in QTCB */
1431 fsf_req->qtcb->header.port_handle = port->handle;
1432 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1433 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1434 fsf_req->data.send_ct = ct;
1436 /* start QDIO request for this FSF request */
1437 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1438 if (ret) {
1439 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1440 "(adapter %s, port 0x%016Lx)\n",
1441 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1442 goto failed_send;
1445 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1446 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1447 goto out;
1449 failed_send:
1450 zfcp_fsf_req_free(fsf_req);
1451 if (erp_action != NULL) {
1452 erp_action->fsf_req = NULL;
1454 failed_req:
1455 out:
1456 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1457 lock_flags);
1458 return ret;
1462 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1463 * @fsf_req: pointer to struct zfcp_fsf_req
1465 * Data specific for the Generic Service request is passed by
1466 * fsf_req->data.send_ct
1467 * Usually a specific handler for the request is called via
1468 * fsf_req->data.send_ct->handler at end of this function.
1470 static int
1471 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1473 struct zfcp_port *port;
1474 struct zfcp_adapter *adapter;
1475 struct zfcp_send_ct *send_ct;
1476 struct fsf_qtcb_header *header;
1477 struct fsf_qtcb_bottom_support *bottom;
1478 int retval = -EINVAL;
1479 u16 subtable, rule, counter;
1481 adapter = fsf_req->adapter;
1482 send_ct = fsf_req->data.send_ct;
1483 port = send_ct->port;
1484 header = &fsf_req->qtcb->header;
1485 bottom = &fsf_req->qtcb->bottom.support;
1487 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1488 goto skip_fsfstatus;
1490 /* evaluate FSF status in QTCB */
1491 switch (header->fsf_status) {
1493 case FSF_GOOD:
1494 retval = 0;
1495 break;
1497 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1498 if (adapter->fc_service_class <= 3) {
1499 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1500 "class %d.\n",
1501 zfcp_get_busid_by_port(port),
1502 adapter->fc_service_class);
1503 } else {
1504 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1505 "adapter %s is invalid. "
1506 "(debug info %d)\n",
1507 zfcp_get_busid_by_port(port),
1508 adapter->fc_service_class);
1510 /* stop operation for this adapter */
1511 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1512 zfcp_erp_adapter_shutdown(adapter, 0);
1513 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1514 break;
1516 case FSF_ADAPTER_STATUS_AVAILABLE:
1517 switch (header->fsf_status_qual.word[0]){
1518 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1519 /* reopening link to port */
1520 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1521 zfcp_test_link(port);
1522 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1523 break;
1524 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1525 /* ERP strategy will escalate */
1526 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1528 break;
1529 default:
1530 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1531 "arrived.\n",
1532 header->fsf_status_qual.word[0]);
1533 break;
1535 break;
1537 case FSF_ACCESS_DENIED:
1538 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1539 "command (adapter %s, port d_id=0x%08x)\n",
1540 zfcp_get_busid_by_port(port), port->d_id);
1541 for (counter = 0; counter < 2; counter++) {
1542 subtable = header->fsf_status_qual.halfword[counter * 2];
1543 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1544 switch (subtable) {
1545 case FSF_SQ_CFDC_SUBTABLE_OS:
1546 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1547 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1548 case FSF_SQ_CFDC_SUBTABLE_LUN:
1549 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1550 zfcp_act_subtable_type[subtable], rule);
1551 break;
1554 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1555 zfcp_erp_port_access_denied(port);
1556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1557 break;
1559 case FSF_GENERIC_COMMAND_REJECTED:
1560 ZFCP_LOG_INFO("generic service command rejected "
1561 "(adapter %s, port d_id=0x%08x)\n",
1562 zfcp_get_busid_by_port(port), port->d_id);
1563 ZFCP_LOG_INFO("status qualifier:\n");
1564 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1565 (char *) &header->fsf_status_qual,
1566 sizeof (union fsf_status_qual));
1567 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1569 break;
1571 case FSF_PORT_HANDLE_NOT_VALID:
1572 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1573 "0x%016Lx on adapter %s invalid. This may "
1574 "happen occasionally.\n", port->handle,
1575 port->wwpn, zfcp_get_busid_by_port(port));
1576 ZFCP_LOG_INFO("status qualifier:\n");
1577 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1578 (char *) &header->fsf_status_qual,
1579 sizeof (union fsf_status_qual));
1580 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1581 zfcp_erp_adapter_reopen(adapter, 0);
1582 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1583 break;
1585 case FSF_PORT_BOXED:
1586 ZFCP_LOG_INFO("port needs to be reopened "
1587 "(adapter %s, port d_id=0x%08x)\n",
1588 zfcp_get_busid_by_port(port), port->d_id);
1589 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1590 zfcp_erp_port_reopen(port, 0);
1591 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1592 | ZFCP_STATUS_FSFREQ_RETRY;
1593 break;
1595 /* following states should never occure, all cases avoided
1596 in zfcp_fsf_send_ct - but who knows ... */
1597 case FSF_PAYLOAD_SIZE_MISMATCH:
1598 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1599 "req_buf_length=%d, resp_buf_length=%d)\n",
1600 zfcp_get_busid_by_adapter(adapter),
1601 bottom->req_buf_length, bottom->resp_buf_length);
1602 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1603 break;
1604 case FSF_REQUEST_SIZE_TOO_LARGE:
1605 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1606 "req_buf_length=%d)\n",
1607 zfcp_get_busid_by_adapter(adapter),
1608 bottom->req_buf_length);
1609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1610 break;
1611 case FSF_RESPONSE_SIZE_TOO_LARGE:
1612 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1613 "resp_buf_length=%d)\n",
1614 zfcp_get_busid_by_adapter(adapter),
1615 bottom->resp_buf_length);
1616 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1617 break;
1618 case FSF_SBAL_MISMATCH:
1619 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1620 "resp_buf_length=%d)\n",
1621 zfcp_get_busid_by_adapter(adapter),
1622 bottom->req_buf_length, bottom->resp_buf_length);
1623 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1624 break;
1626 default:
1627 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1628 "(debug info 0x%x)\n", header->fsf_status);
1629 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1630 debug_exception(adapter->erp_dbf, 0,
1631 &header->fsf_status_qual.word[0], sizeof (u32));
1632 break;
1635 skip_fsfstatus:
1636 send_ct->status = retval;
1638 if (send_ct->handler != NULL)
1639 send_ct->handler(send_ct->handler_data);
1641 return retval;
1645 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1646 * @els: pointer to struct zfcp_send_els which contains all needed data for
1647 * the command.
1650 zfcp_fsf_send_els(struct zfcp_send_els *els)
1652 volatile struct qdio_buffer_element *sbale;
1653 struct zfcp_fsf_req *fsf_req;
1654 fc_id_t d_id;
1655 struct zfcp_adapter *adapter;
1656 unsigned long lock_flags;
1657 int bytes;
1658 int ret = 0;
1660 d_id = els->d_id;
1661 adapter = els->adapter;
1663 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1664 ZFCP_REQ_AUTO_CLEANUP,
1665 NULL, &lock_flags, &fsf_req);
1666 if (ret < 0) {
1667 ZFCP_LOG_INFO("error: creation of ELS request failed "
1668 "(adapter %s, port d_id: 0x%08x)\n",
1669 zfcp_get_busid_by_adapter(adapter), d_id);
1670 goto failed_req;
1673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1674 if (zfcp_use_one_sbal(els->req, els->req_count,
1675 els->resp, els->resp_count)){
1676 /* both request buffer and response buffer
1677 fit into one sbale each */
1678 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1679 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1680 sbale[2].length = els->req[0].length;
1681 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1682 sbale[3].length = els->resp[0].length;
1683 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1684 } else if (adapter->supported_features &
1685 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1686 /* try to use chained SBALs */
1687 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1688 SBAL_FLAGS0_TYPE_WRITE_READ,
1689 els->req, els->req_count,
1690 ZFCP_MAX_SBALS_PER_ELS_REQ);
1691 if (bytes <= 0) {
1692 ZFCP_LOG_INFO("error: creation of ELS request failed "
1693 "(adapter %s, port d_id: 0x%08x)\n",
1694 zfcp_get_busid_by_adapter(adapter), d_id);
1695 if (bytes == 0) {
1696 ret = -ENOMEM;
1697 } else {
1698 ret = bytes;
1700 goto failed_send;
1702 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1703 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1704 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1705 SBAL_FLAGS0_TYPE_WRITE_READ,
1706 els->resp, els->resp_count,
1707 ZFCP_MAX_SBALS_PER_ELS_REQ);
1708 if (bytes <= 0) {
1709 ZFCP_LOG_INFO("error: creation of ELS request failed "
1710 "(adapter %s, port d_id: 0x%08x)\n",
1711 zfcp_get_busid_by_adapter(adapter), d_id);
1712 if (bytes == 0) {
1713 ret = -ENOMEM;
1714 } else {
1715 ret = bytes;
1717 goto failed_send;
1719 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1720 } else {
1721 /* reject request */
1722 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1723 ", ELS request too big (adapter %s, "
1724 "port d_id: 0x%08x)\n",
1725 zfcp_get_busid_by_adapter(adapter), d_id);
1726 ret = -EOPNOTSUPP;
1727 goto failed_send;
1730 /* settings in QTCB */
1731 fsf_req->qtcb->bottom.support.d_id = d_id;
1732 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1733 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1734 fsf_req->data.send_els = els;
1736 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1738 /* start QDIO request for this FSF request */
1739 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1740 if (ret) {
1741 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1742 "(adapter %s, port d_id: 0x%08x)\n",
1743 zfcp_get_busid_by_adapter(adapter), d_id);
1744 goto failed_send;
1747 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1748 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1749 goto out;
1751 failed_send:
1752 zfcp_fsf_req_free(fsf_req);
1754 failed_req:
1755 out:
1756 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1757 lock_flags);
1759 return ret;
1763 * zfcp_fsf_send_els_handler - handler for ELS commands
1764 * @fsf_req: pointer to struct zfcp_fsf_req
1766 * Data specific for the ELS command is passed by
1767 * fsf_req->data.send_els
1768 * Usually a specific handler for the command is called via
1769 * fsf_req->data.send_els->handler at end of this function.
1771 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1773 struct zfcp_adapter *adapter;
1774 fc_id_t d_id;
1775 struct zfcp_port *port;
1776 struct fsf_qtcb_header *header;
1777 struct fsf_qtcb_bottom_support *bottom;
1778 struct zfcp_send_els *send_els;
1779 int retval = -EINVAL;
1780 u16 subtable, rule, counter;
1782 send_els = fsf_req->data.send_els;
1783 adapter = send_els->adapter;
1784 d_id = send_els->d_id;
1785 header = &fsf_req->qtcb->header;
1786 bottom = &fsf_req->qtcb->bottom.support;
1788 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1789 goto skip_fsfstatus;
1791 switch (header->fsf_status) {
1793 case FSF_GOOD:
1794 retval = 0;
1795 break;
1797 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1798 if (adapter->fc_service_class <= 3) {
1799 ZFCP_LOG_INFO("error: adapter %s does "
1800 "not support fibrechannel class %d.\n",
1801 zfcp_get_busid_by_adapter(adapter),
1802 adapter->fc_service_class);
1803 } else {
1804 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1805 "adapter %s is invalid. "
1806 "(debug info %d)\n",
1807 zfcp_get_busid_by_adapter(adapter),
1808 adapter->fc_service_class);
1810 /* stop operation for this adapter */
1811 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1812 zfcp_erp_adapter_shutdown(adapter, 0);
1813 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1814 break;
1816 case FSF_ADAPTER_STATUS_AVAILABLE:
1817 switch (header->fsf_status_qual.word[0]){
1818 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1819 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1820 if (send_els->ls_code != ZFCP_LS_ADISC) {
1821 read_lock(&zfcp_data.config_lock);
1822 port = zfcp_get_port_by_did(adapter, d_id);
1823 if (port)
1824 zfcp_test_link(port);
1825 read_unlock(&zfcp_data.config_lock);
1827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1828 break;
1829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1830 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1831 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1832 retval =
1833 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1834 (struct zfcp_ls_rjt_par *)
1835 &header->fsf_status_qual.word[2]);
1836 break;
1837 case FSF_SQ_RETRY_IF_POSSIBLE:
1838 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1840 break;
1841 default:
1842 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1843 header->fsf_status_qual.word[0]);
1844 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1845 (char*)header->fsf_status_qual.word, 16);
1847 break;
1849 case FSF_ELS_COMMAND_REJECTED:
1850 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1851 "prohibited sending "
1852 "(adapter: %s, port d_id: 0x%08x)\n",
1853 zfcp_get_busid_by_adapter(adapter), d_id);
1855 break;
1857 case FSF_PAYLOAD_SIZE_MISMATCH:
1858 ZFCP_LOG_INFO(
1859 "ELS request size and ELS response size must be either "
1860 "both 0, or both greater than 0 "
1861 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1862 zfcp_get_busid_by_adapter(adapter),
1863 bottom->req_buf_length,
1864 bottom->resp_buf_length);
1865 break;
1867 case FSF_REQUEST_SIZE_TOO_LARGE:
1868 ZFCP_LOG_INFO(
1869 "Length of the ELS request buffer, "
1870 "specified in QTCB bottom, "
1871 "exceeds the size of the buffers "
1872 "that have been allocated for ELS request data "
1873 "(adapter: %s, req_buf_length=%d)\n",
1874 zfcp_get_busid_by_adapter(adapter),
1875 bottom->req_buf_length);
1876 break;
1878 case FSF_RESPONSE_SIZE_TOO_LARGE:
1879 ZFCP_LOG_INFO(
1880 "Length of the ELS response buffer, "
1881 "specified in QTCB bottom, "
1882 "exceeds the size of the buffers "
1883 "that have been allocated for ELS response data "
1884 "(adapter: %s, resp_buf_length=%d)\n",
1885 zfcp_get_busid_by_adapter(adapter),
1886 bottom->resp_buf_length);
1887 break;
1889 case FSF_SBAL_MISMATCH:
1890 /* should never occure, avoided in zfcp_fsf_send_els */
1891 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1892 "resp_buf_length=%d)\n",
1893 zfcp_get_busid_by_adapter(adapter),
1894 bottom->req_buf_length, bottom->resp_buf_length);
1895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1896 break;
1898 case FSF_ACCESS_DENIED:
1899 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1900 "(adapter %s, port d_id=0x%08x)\n",
1901 zfcp_get_busid_by_adapter(adapter), d_id);
1902 for (counter = 0; counter < 2; counter++) {
1903 subtable = header->fsf_status_qual.halfword[counter * 2];
1904 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1905 switch (subtable) {
1906 case FSF_SQ_CFDC_SUBTABLE_OS:
1907 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1908 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1909 case FSF_SQ_CFDC_SUBTABLE_LUN:
1910 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1911 zfcp_act_subtable_type[subtable], rule);
1912 break;
1915 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1916 read_lock(&zfcp_data.config_lock);
1917 port = zfcp_get_port_by_did(adapter, d_id);
1918 if (port != NULL)
1919 zfcp_erp_port_access_denied(port);
1920 read_unlock(&zfcp_data.config_lock);
1921 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1922 break;
1924 default:
1925 ZFCP_LOG_NORMAL(
1926 "bug: An unknown FSF Status was presented "
1927 "(adapter: %s, fsf_status=0x%08x)\n",
1928 zfcp_get_busid_by_adapter(adapter),
1929 header->fsf_status);
1930 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1931 debug_exception(adapter->erp_dbf, 0,
1932 &header->fsf_status_qual.word[0], sizeof(u32));
1933 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1934 break;
1937 skip_fsfstatus:
1938 send_els->status = retval;
1940 if (send_els->handler != 0)
1941 send_els->handler(send_els->handler_data);
1943 return retval;
1947 * function:
1949 * purpose:
1951 * returns: address of initiated FSF request
1952 * NULL - request could not be initiated
1955 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1957 volatile struct qdio_buffer_element *sbale;
1958 unsigned long lock_flags;
1959 int retval = 0;
1961 /* setup new FSF request */
1962 retval = zfcp_fsf_req_create(erp_action->adapter,
1963 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1964 ZFCP_REQ_AUTO_CLEANUP,
1965 erp_action->adapter->pool.fsf_req_erp,
1966 &lock_flags, &(erp_action->fsf_req));
1967 if (retval < 0) {
1968 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1969 "data request for adapter %s.\n",
1970 zfcp_get_busid_by_adapter(erp_action->adapter));
1971 goto out;
1974 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1975 erp_action->fsf_req->sbal_curr, 0);
1976 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1977 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1979 erp_action->fsf_req->erp_action = erp_action;
1980 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1981 (FSF_FEATURE_CFDC | FSF_FEATURE_LUN_SHARING);
1983 /* start QDIO request for this FSF request */
1984 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1985 if (retval) {
1986 ZFCP_LOG_INFO
1987 ("error: Could not send exchange configuration data "
1988 "command on the adapter %s\n",
1989 zfcp_get_busid_by_adapter(erp_action->adapter));
1990 zfcp_fsf_req_free(erp_action->fsf_req);
1991 erp_action->fsf_req = NULL;
1992 goto out;
1995 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1996 "(adapter %s)\n",
1997 zfcp_get_busid_by_adapter(erp_action->adapter));
1999 out:
2000 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2001 lock_flags);
2002 return retval;
2006 * zfcp_fsf_exchange_config_evaluate
2007 * @fsf_req: fsf_req which belongs to xchg config data request
2008 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2010 * returns: -EIO on error, 0 otherwise
2012 static int
2013 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2015 struct fsf_qtcb_bottom_config *bottom;
2016 struct zfcp_adapter *adapter = fsf_req->adapter;
2018 bottom = &fsf_req->qtcb->bottom.config;
2019 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2020 bottom->low_qtcb_version, bottom->high_qtcb_version);
2021 adapter->fsf_lic_version = bottom->lic_version;
2022 adapter->supported_features = bottom->supported_features;
2023 adapter->peer_wwpn = 0;
2024 adapter->peer_wwnn = 0;
2025 adapter->peer_d_id = 0;
2027 if (xchg_ok) {
2028 adapter->wwnn = bottom->nport_serv_param.wwnn;
2029 adapter->wwpn = bottom->nport_serv_param.wwpn;
2030 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2031 adapter->fc_topology = bottom->fc_topology;
2032 adapter->fc_link_speed = bottom->fc_link_speed;
2033 adapter->hydra_version = bottom->adapter_type;
2034 } else {
2035 adapter->wwnn = 0;
2036 adapter->wwpn = 0;
2037 adapter->s_id = 0;
2038 adapter->fc_topology = 0;
2039 adapter->fc_link_speed = 0;
2040 adapter->hydra_version = 0;
2043 if (adapter->fc_topology == FSF_TOPO_P2P) {
2044 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2045 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2046 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2049 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2050 adapter->hardware_version = bottom->hardware_version;
2051 memcpy(adapter->serial_number, bottom->serial_number, 17);
2052 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2055 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2056 "WWNN 0x%016Lx, "
2057 "WWPN 0x%016Lx, "
2058 "S_ID 0x%08x,\n"
2059 "adapter version 0x%x, "
2060 "LIC version 0x%x, "
2061 "FC link speed %d Gb/s\n",
2062 zfcp_get_busid_by_adapter(adapter),
2063 adapter->wwnn,
2064 adapter->wwpn,
2065 (unsigned int) adapter->s_id,
2066 adapter->hydra_version,
2067 adapter->fsf_lic_version,
2068 adapter->fc_link_speed);
2069 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2070 ZFCP_LOG_NORMAL("error: the adapter %s "
2071 "only supports newer control block "
2072 "versions in comparison to this device "
2073 "driver (try updated device driver)\n",
2074 zfcp_get_busid_by_adapter(adapter));
2075 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2076 zfcp_erp_adapter_shutdown(adapter, 0);
2077 return -EIO;
2079 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2080 ZFCP_LOG_NORMAL("error: the adapter %s "
2081 "only supports older control block "
2082 "versions than this device driver uses"
2083 "(consider a microcode upgrade)\n",
2084 zfcp_get_busid_by_adapter(adapter));
2085 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2086 zfcp_erp_adapter_shutdown(adapter, 0);
2087 return -EIO;
2089 return 0;
2093 * function: zfcp_fsf_exchange_config_data_handler
2095 * purpose: is called for finished Exchange Configuration Data command
2097 * returns:
2099 static int
2100 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2102 struct fsf_qtcb_bottom_config *bottom;
2103 struct zfcp_adapter *adapter = fsf_req->adapter;
2105 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2106 return -EIO;
2108 switch (fsf_req->qtcb->header.fsf_status) {
2110 case FSF_GOOD:
2111 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2112 return -EIO;
2114 switch (adapter->fc_topology) {
2115 case FSF_TOPO_P2P:
2116 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2117 "configuration detected at adapter %s\n"
2118 "Peer WWNN 0x%016llx, "
2119 "peer WWPN 0x%016llx, "
2120 "peer d_id 0x%06x\n",
2121 zfcp_get_busid_by_adapter(adapter),
2122 adapter->peer_wwnn,
2123 adapter->peer_wwpn,
2124 adapter->peer_d_id);
2125 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2126 "top-p-to-p");
2127 break;
2128 case FSF_TOPO_AL:
2129 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2130 "topology detected at adapter %s "
2131 "unsupported, shutting down adapter\n",
2132 zfcp_get_busid_by_adapter(adapter));
2133 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2134 "top-al");
2135 zfcp_erp_adapter_shutdown(adapter, 0);
2136 return -EIO;
2137 case FSF_TOPO_FABRIC:
2138 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2139 "network detected at adapter %s.\n",
2140 zfcp_get_busid_by_adapter(adapter));
2141 break;
2142 default:
2143 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2144 "reported by the exchange "
2145 "configuration command for "
2146 "the adapter %s is not "
2147 "of a type known to the zfcp "
2148 "driver, shutting down adapter\n",
2149 zfcp_get_busid_by_adapter(adapter));
2150 adapter->fc_topology = FSF_TOPO_ERROR;
2151 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2152 "unknown-topo");
2153 zfcp_erp_adapter_shutdown(adapter, 0);
2154 return -EIO;
2156 bottom = &fsf_req->qtcb->bottom.config;
2157 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2158 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2159 "allowed by the adapter %s "
2160 "is lower than the minimum "
2161 "required by the driver (%ld bytes).\n",
2162 bottom->max_qtcb_size,
2163 zfcp_get_busid_by_adapter(adapter),
2164 sizeof(struct fsf_qtcb));
2165 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2166 "qtcb-size");
2167 debug_event(fsf_req->adapter->erp_dbf, 0,
2168 &bottom->max_qtcb_size, sizeof (u32));
2169 zfcp_erp_adapter_shutdown(adapter, 0);
2170 return -EIO;
2172 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2173 &adapter->status);
2174 break;
2175 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2176 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2178 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2179 return -EIO;
2181 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2182 zfcp_get_busid_by_adapter(adapter));
2183 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2184 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2185 &adapter->status);
2186 zfcp_erp_adapter_failed(adapter);
2187 break;
2188 default:
2189 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2190 debug_event(fsf_req->adapter->erp_dbf, 0,
2191 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2192 zfcp_erp_adapter_shutdown(adapter, 0);
2193 return -EIO;
2195 return 0;
2199 * zfcp_fsf_exchange_port_data - request information about local port
2200 * @adapter: for which port data is requested
2201 * @data: response to exchange port data request
2204 zfcp_fsf_exchange_port_data(struct zfcp_adapter *adapter,
2205 struct fsf_qtcb_bottom_port *data)
2207 volatile struct qdio_buffer_element *sbale;
2208 int retval = 0;
2209 unsigned long lock_flags;
2210 struct zfcp_fsf_req *fsf_req;
2211 struct timer_list *timer;
2213 if(!(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT)){
2214 ZFCP_LOG_INFO("error: exchange port data "
2215 "command not supported by adapter %s\n",
2216 zfcp_get_busid_by_adapter(adapter));
2217 return -EOPNOTSUPP;
2220 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2221 if (!timer)
2222 return -ENOMEM;
2224 /* setup new FSF request */
2225 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2226 0, 0, &lock_flags, &fsf_req);
2227 if (retval < 0) {
2228 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2229 "exchange port data request for"
2230 "the adapter %s.\n",
2231 zfcp_get_busid_by_adapter(adapter));
2232 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2233 lock_flags);
2234 goto out;
2237 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2238 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2239 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2241 fsf_req->data.port_data = data;
2243 init_timer(timer);
2244 timer->function = zfcp_fsf_request_timeout_handler;
2245 timer->data = (unsigned long) adapter;
2246 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2248 retval = zfcp_fsf_req_send(fsf_req, timer);
2249 if (retval) {
2250 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2251 "command on the adapter %s\n",
2252 zfcp_get_busid_by_adapter(adapter));
2253 zfcp_fsf_req_free(fsf_req);
2254 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2255 lock_flags);
2256 goto out;
2259 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2260 zfcp_get_busid_by_adapter(adapter));
2262 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2263 lock_flags);
2265 wait_event(fsf_req->completion_wq,
2266 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2267 del_timer_sync(timer);
2268 zfcp_fsf_req_cleanup(fsf_req);
2269 out:
2270 kfree(timer);
2271 return retval;
2276 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2277 * @fsf_req: pointer to struct zfcp_fsf_req
2279 static void
2280 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2282 struct fsf_qtcb_bottom_port *bottom;
2283 struct fsf_qtcb_bottom_port *data = fsf_req->data.port_data;
2285 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2286 return;
2288 switch (fsf_req->qtcb->header.fsf_status) {
2289 case FSF_GOOD:
2290 bottom = &fsf_req->qtcb->bottom.port;
2291 memcpy(data, bottom, sizeof(*data));
2292 break;
2294 default:
2295 debug_text_event(fsf_req->adapter->erp_dbf, 0, "xchg-port-ng");
2296 debug_event(fsf_req->adapter->erp_dbf, 0,
2297 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2303 * function: zfcp_fsf_open_port
2305 * purpose:
2307 * returns: address of initiated FSF request
2308 * NULL - request could not be initiated
2311 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2313 volatile struct qdio_buffer_element *sbale;
2314 unsigned long lock_flags;
2315 int retval = 0;
2317 /* setup new FSF request */
2318 retval = zfcp_fsf_req_create(erp_action->adapter,
2319 FSF_QTCB_OPEN_PORT_WITH_DID,
2320 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2321 erp_action->adapter->pool.fsf_req_erp,
2322 &lock_flags, &(erp_action->fsf_req));
2323 if (retval < 0) {
2324 ZFCP_LOG_INFO("error: Could not create open port request "
2325 "for port 0x%016Lx on adapter %s.\n",
2326 erp_action->port->wwpn,
2327 zfcp_get_busid_by_adapter(erp_action->adapter));
2328 goto out;
2331 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2332 erp_action->fsf_req->sbal_curr, 0);
2333 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2334 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2336 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2337 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2338 erp_action->fsf_req->data.open_port.port = erp_action->port;
2339 erp_action->fsf_req->erp_action = erp_action;
2341 /* start QDIO request for this FSF request */
2342 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2343 if (retval) {
2344 ZFCP_LOG_INFO("error: Could not send open port request for "
2345 "port 0x%016Lx on adapter %s.\n",
2346 erp_action->port->wwpn,
2347 zfcp_get_busid_by_adapter(erp_action->adapter));
2348 zfcp_fsf_req_free(erp_action->fsf_req);
2349 erp_action->fsf_req = NULL;
2350 goto out;
2353 ZFCP_LOG_DEBUG("open port request initiated "
2354 "(adapter %s, port 0x%016Lx)\n",
2355 zfcp_get_busid_by_adapter(erp_action->adapter),
2356 erp_action->port->wwpn);
2357 out:
2358 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2359 lock_flags);
2360 return retval;
2364 * function: zfcp_fsf_open_port_handler
2366 * purpose: is called for finished Open Port command
2368 * returns:
2370 static int
2371 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2373 int retval = -EINVAL;
2374 struct zfcp_port *port;
2375 struct fsf_plogi *plogi;
2376 struct fsf_qtcb_header *header;
2377 u16 subtable, rule, counter;
2379 port = fsf_req->data.open_port.port;
2380 header = &fsf_req->qtcb->header;
2382 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2383 /* don't change port status in our bookkeeping */
2384 goto skip_fsfstatus;
2387 /* evaluate FSF status in QTCB */
2388 switch (header->fsf_status) {
2390 case FSF_PORT_ALREADY_OPEN:
2391 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2392 "is already open.\n",
2393 port->wwpn, zfcp_get_busid_by_port(port));
2394 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2395 "fsf_s_popen");
2397 * This is a bug, however operation should continue normally
2398 * if it is simply ignored
2400 break;
2402 case FSF_ACCESS_DENIED:
2403 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2404 "on adapter %s\n",
2405 port->wwpn, zfcp_get_busid_by_port(port));
2406 for (counter = 0; counter < 2; counter++) {
2407 subtable = header->fsf_status_qual.halfword[counter * 2];
2408 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2409 switch (subtable) {
2410 case FSF_SQ_CFDC_SUBTABLE_OS:
2411 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2412 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2413 case FSF_SQ_CFDC_SUBTABLE_LUN:
2414 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2415 zfcp_act_subtable_type[subtable], rule);
2416 break;
2419 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2420 zfcp_erp_port_access_denied(port);
2421 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2422 break;
2424 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2425 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2426 "The remote port 0x%016Lx on adapter %s "
2427 "could not be opened. Disabling it.\n",
2428 port->wwpn, zfcp_get_busid_by_port(port));
2429 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2430 "fsf_s_max_ports");
2431 zfcp_erp_port_failed(port);
2432 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2433 break;
2435 case FSF_ADAPTER_STATUS_AVAILABLE:
2436 switch (header->fsf_status_qual.word[0]) {
2437 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2438 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2439 "fsf_sq_ltest");
2440 /* ERP strategy will escalate */
2441 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2442 break;
2443 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2444 /* ERP strategy will escalate */
2445 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2446 "fsf_sq_ulp");
2447 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2448 break;
2449 case FSF_SQ_NO_RETRY_POSSIBLE:
2450 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2451 "adapter %s could not be opened. "
2452 "Disabling it.\n",
2453 port->wwpn,
2454 zfcp_get_busid_by_port(port));
2455 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2456 "fsf_sq_no_retry");
2457 zfcp_erp_port_failed(port);
2458 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2459 break;
2460 default:
2461 ZFCP_LOG_NORMAL
2462 ("bug: Wrong status qualifier 0x%x arrived.\n",
2463 header->fsf_status_qual.word[0]);
2464 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2465 "fsf_sq_inval:");
2466 debug_exception(
2467 fsf_req->adapter->erp_dbf, 0,
2468 &header->fsf_status_qual.word[0],
2469 sizeof (u32));
2470 break;
2472 break;
2474 case FSF_GOOD:
2475 /* save port handle assigned by FSF */
2476 port->handle = header->port_handle;
2477 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2478 "was opened, it's port handle is 0x%x\n",
2479 port->wwpn, zfcp_get_busid_by_port(port),
2480 port->handle);
2481 /* mark port as open */
2482 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2483 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2484 retval = 0;
2485 /* check whether D_ID has changed during open */
2487 * FIXME: This check is not airtight, as the FCP channel does
2488 * not monitor closures of target port connections caused on
2489 * the remote side. Thus, they might miss out on invalidating
2490 * locally cached WWPNs (and other N_Port parameters) of gone
2491 * target ports. So, our heroic attempt to make things safe
2492 * could be undermined by 'open port' response data tagged with
2493 * obsolete WWPNs. Another reason to monitor potential
2494 * connection closures ourself at least (by interpreting
2495 * incoming ELS' and unsolicited status). It just crosses my
2496 * mind that one should be able to cross-check by means of
2497 * another GID_PN straight after a port has been opened.
2498 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2500 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2501 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2503 if (fsf_req->qtcb->bottom.support.els1_length <
2504 ((((unsigned long) &plogi->serv_param.wwpn) -
2505 ((unsigned long) plogi)) + sizeof (u64))) {
2506 ZFCP_LOG_INFO(
2507 "warning: insufficient length of "
2508 "PLOGI payload (%i)\n",
2509 fsf_req->qtcb->bottom.support.els1_length);
2510 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2511 "fsf_s_short_plogi:");
2512 /* skip sanity check and assume wwpn is ok */
2513 } else {
2514 if (plogi->serv_param.wwpn != port->wwpn) {
2515 ZFCP_LOG_INFO("warning: d_id of port "
2516 "0x%016Lx changed during "
2517 "open\n", port->wwpn);
2518 debug_text_event(
2519 fsf_req->adapter->erp_dbf, 0,
2520 "fsf_s_did_change:");
2521 atomic_clear_mask(
2522 ZFCP_STATUS_PORT_DID_DID,
2523 &port->status);
2524 } else
2525 port->wwnn = plogi->serv_param.wwnn;
2528 break;
2530 case FSF_UNKNOWN_OP_SUBTYPE:
2531 /* should never occure, subtype not set in zfcp_fsf_open_port */
2532 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2533 "op_subtype=0x%x)\n",
2534 zfcp_get_busid_by_port(port),
2535 fsf_req->qtcb->bottom.support.operation_subtype);
2536 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2537 break;
2539 default:
2540 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2541 "(debug info 0x%x)\n",
2542 header->fsf_status);
2543 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2544 debug_exception(fsf_req->adapter->erp_dbf, 0,
2545 &header->fsf_status, sizeof (u32));
2546 break;
2549 skip_fsfstatus:
2550 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2551 return retval;
2555 * function: zfcp_fsf_close_port
2557 * purpose: submit FSF command "close port"
2559 * returns: address of initiated FSF request
2560 * NULL - request could not be initiated
2563 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2565 volatile struct qdio_buffer_element *sbale;
2566 unsigned long lock_flags;
2567 int retval = 0;
2569 /* setup new FSF request */
2570 retval = zfcp_fsf_req_create(erp_action->adapter,
2571 FSF_QTCB_CLOSE_PORT,
2572 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2573 erp_action->adapter->pool.fsf_req_erp,
2574 &lock_flags, &(erp_action->fsf_req));
2575 if (retval < 0) {
2576 ZFCP_LOG_INFO("error: Could not create a close port request "
2577 "for port 0x%016Lx on adapter %s.\n",
2578 erp_action->port->wwpn,
2579 zfcp_get_busid_by_adapter(erp_action->adapter));
2580 goto out;
2583 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2584 erp_action->fsf_req->sbal_curr, 0);
2585 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2586 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2588 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2589 erp_action->fsf_req->data.close_port.port = erp_action->port;
2590 erp_action->fsf_req->erp_action = erp_action;
2591 erp_action->fsf_req->qtcb->header.port_handle =
2592 erp_action->port->handle;
2594 /* start QDIO request for this FSF request */
2595 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2596 if (retval) {
2597 ZFCP_LOG_INFO("error: Could not send a close port request for "
2598 "port 0x%016Lx on adapter %s.\n",
2599 erp_action->port->wwpn,
2600 zfcp_get_busid_by_adapter(erp_action->adapter));
2601 zfcp_fsf_req_free(erp_action->fsf_req);
2602 erp_action->fsf_req = NULL;
2603 goto out;
2606 ZFCP_LOG_TRACE("close port request initiated "
2607 "(adapter %s, port 0x%016Lx)\n",
2608 zfcp_get_busid_by_adapter(erp_action->adapter),
2609 erp_action->port->wwpn);
2610 out:
2611 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2612 lock_flags);
2613 return retval;
2617 * function: zfcp_fsf_close_port_handler
2619 * purpose: is called for finished Close Port FSF command
2621 * returns:
2623 static int
2624 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2626 int retval = -EINVAL;
2627 struct zfcp_port *port;
2629 port = fsf_req->data.close_port.port;
2631 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2632 /* don't change port status in our bookkeeping */
2633 goto skip_fsfstatus;
2636 /* evaluate FSF status in QTCB */
2637 switch (fsf_req->qtcb->header.fsf_status) {
2639 case FSF_PORT_HANDLE_NOT_VALID:
2640 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2641 "0x%016Lx on adapter %s invalid. This may happen "
2642 "occasionally.\n", port->handle,
2643 port->wwpn, zfcp_get_busid_by_port(port));
2644 ZFCP_LOG_DEBUG("status qualifier:\n");
2645 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2646 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2647 sizeof (union fsf_status_qual));
2648 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2649 "fsf_s_phand_nv");
2650 zfcp_erp_adapter_reopen(port->adapter, 0);
2651 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2652 break;
2654 case FSF_ADAPTER_STATUS_AVAILABLE:
2655 /* Note: FSF has actually closed the port in this case.
2656 * The status code is just daft. Fingers crossed for a change
2658 retval = 0;
2659 break;
2661 case FSF_GOOD:
2662 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2663 "port handle 0x%x\n", port->wwpn,
2664 zfcp_get_busid_by_port(port), port->handle);
2665 zfcp_erp_modify_port_status(port,
2666 ZFCP_STATUS_COMMON_OPEN,
2667 ZFCP_CLEAR);
2668 retval = 0;
2669 break;
2671 default:
2672 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2673 "(debug info 0x%x)\n",
2674 fsf_req->qtcb->header.fsf_status);
2675 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2676 debug_exception(fsf_req->adapter->erp_dbf, 0,
2677 &fsf_req->qtcb->header.fsf_status,
2678 sizeof (u32));
2679 break;
2682 skip_fsfstatus:
2683 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2684 return retval;
2688 * function: zfcp_fsf_close_physical_port
2690 * purpose: submit FSF command "close physical port"
2692 * returns: address of initiated FSF request
2693 * NULL - request could not be initiated
2696 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2698 int retval = 0;
2699 unsigned long lock_flags;
2700 volatile struct qdio_buffer_element *sbale;
2702 /* setup new FSF request */
2703 retval = zfcp_fsf_req_create(erp_action->adapter,
2704 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2705 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2706 erp_action->adapter->pool.fsf_req_erp,
2707 &lock_flags, &erp_action->fsf_req);
2708 if (retval < 0) {
2709 ZFCP_LOG_INFO("error: Could not create close physical port "
2710 "request (adapter %s, port 0x%016Lx)\n",
2711 zfcp_get_busid_by_adapter(erp_action->adapter),
2712 erp_action->port->wwpn);
2714 goto out;
2717 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2718 erp_action->fsf_req->sbal_curr, 0);
2719 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2720 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2722 /* mark port as being closed */
2723 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2724 &erp_action->port->status);
2725 /* save a pointer to this port */
2726 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2727 /* port to be closeed */
2728 erp_action->fsf_req->qtcb->header.port_handle =
2729 erp_action->port->handle;
2730 erp_action->fsf_req->erp_action = erp_action;
2732 /* start QDIO request for this FSF request */
2733 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2734 if (retval) {
2735 ZFCP_LOG_INFO("error: Could not send close physical port "
2736 "request (adapter %s, port 0x%016Lx)\n",
2737 zfcp_get_busid_by_adapter(erp_action->adapter),
2738 erp_action->port->wwpn);
2739 zfcp_fsf_req_free(erp_action->fsf_req);
2740 erp_action->fsf_req = NULL;
2741 goto out;
2744 ZFCP_LOG_TRACE("close physical port request initiated "
2745 "(adapter %s, port 0x%016Lx)\n",
2746 zfcp_get_busid_by_adapter(erp_action->adapter),
2747 erp_action->port->wwpn);
2748 out:
2749 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2750 lock_flags);
2751 return retval;
2755 * function: zfcp_fsf_close_physical_port_handler
2757 * purpose: is called for finished Close Physical Port FSF command
2759 * returns:
2761 static int
2762 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2764 int retval = -EINVAL;
2765 struct zfcp_port *port;
2766 struct zfcp_unit *unit;
2767 struct fsf_qtcb_header *header;
2768 u16 subtable, rule, counter;
2770 port = fsf_req->data.close_physical_port.port;
2771 header = &fsf_req->qtcb->header;
2773 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2774 /* don't change port status in our bookkeeping */
2775 goto skip_fsfstatus;
2778 /* evaluate FSF status in QTCB */
2779 switch (header->fsf_status) {
2781 case FSF_PORT_HANDLE_NOT_VALID:
2782 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2783 "(adapter %s, port 0x%016Lx). "
2784 "This may happen occasionally.\n",
2785 port->handle,
2786 zfcp_get_busid_by_port(port),
2787 port->wwpn);
2788 ZFCP_LOG_DEBUG("status qualifier:\n");
2789 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2790 (char *) &header->fsf_status_qual,
2791 sizeof (union fsf_status_qual));
2792 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2793 "fsf_s_phand_nv");
2794 zfcp_erp_adapter_reopen(port->adapter, 0);
2795 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2796 break;
2798 case FSF_ACCESS_DENIED:
2799 ZFCP_LOG_NORMAL("Access denied, cannot close "
2800 "physical port 0x%016Lx on adapter %s\n",
2801 port->wwpn, zfcp_get_busid_by_port(port));
2802 for (counter = 0; counter < 2; counter++) {
2803 subtable = header->fsf_status_qual.halfword[counter * 2];
2804 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2805 switch (subtable) {
2806 case FSF_SQ_CFDC_SUBTABLE_OS:
2807 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2808 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2809 case FSF_SQ_CFDC_SUBTABLE_LUN:
2810 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2811 zfcp_act_subtable_type[subtable], rule);
2812 break;
2815 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2816 zfcp_erp_port_access_denied(port);
2817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2818 break;
2820 case FSF_PORT_BOXED:
2821 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2822 "%s needs to be reopened but it was attempted "
2823 "to close it physically.\n",
2824 port->wwpn,
2825 zfcp_get_busid_by_port(port));
2826 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2827 zfcp_erp_port_reopen(port, 0);
2828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2829 ZFCP_STATUS_FSFREQ_RETRY;
2830 break;
2832 case FSF_ADAPTER_STATUS_AVAILABLE:
2833 switch (header->fsf_status_qual.word[0]) {
2834 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2835 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2836 "fsf_sq_ltest");
2837 /* This will now be escalated by ERP */
2838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2839 break;
2840 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2841 /* ERP strategy will escalate */
2842 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2843 "fsf_sq_ulp");
2844 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2845 break;
2846 default:
2847 ZFCP_LOG_NORMAL
2848 ("bug: Wrong status qualifier 0x%x arrived.\n",
2849 header->fsf_status_qual.word[0]);
2850 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2851 "fsf_sq_inval:");
2852 debug_exception(
2853 fsf_req->adapter->erp_dbf, 0,
2854 &header->fsf_status_qual.word[0], sizeof (u32));
2855 break;
2857 break;
2859 case FSF_GOOD:
2860 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2861 "physically closed, port handle 0x%x\n",
2862 port->wwpn,
2863 zfcp_get_busid_by_port(port), port->handle);
2864 /* can't use generic zfcp_erp_modify_port_status because
2865 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2867 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2868 list_for_each_entry(unit, &port->unit_list_head, list)
2869 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2870 retval = 0;
2871 break;
2873 default:
2874 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2875 "(debug info 0x%x)\n",
2876 header->fsf_status);
2877 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2878 debug_exception(fsf_req->adapter->erp_dbf, 0,
2879 &header->fsf_status, sizeof (u32));
2880 break;
2883 skip_fsfstatus:
2884 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2885 return retval;
2889 * function: zfcp_fsf_open_unit
2891 * purpose:
2893 * returns:
2895 * assumptions: This routine does not check whether the associated
2896 * remote port has already been opened. This should be
2897 * done by calling routines. Otherwise some status
2898 * may be presented by FSF
2901 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2903 volatile struct qdio_buffer_element *sbale;
2904 unsigned long lock_flags;
2905 int retval = 0;
2907 /* setup new FSF request */
2908 retval = zfcp_fsf_req_create(erp_action->adapter,
2909 FSF_QTCB_OPEN_LUN,
2910 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2911 erp_action->adapter->pool.fsf_req_erp,
2912 &lock_flags, &(erp_action->fsf_req));
2913 if (retval < 0) {
2914 ZFCP_LOG_INFO("error: Could not create open unit request for "
2915 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2916 erp_action->unit->fcp_lun,
2917 erp_action->unit->port->wwpn,
2918 zfcp_get_busid_by_adapter(erp_action->adapter));
2919 goto out;
2922 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2923 erp_action->fsf_req->sbal_curr, 0);
2924 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2925 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2927 erp_action->fsf_req->qtcb->header.port_handle =
2928 erp_action->port->handle;
2929 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2930 erp_action->unit->fcp_lun;
2931 erp_action->fsf_req->qtcb->bottom.support.option =
2932 FSF_OPEN_LUN_SUPPRESS_BOXING;
2933 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2934 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2935 erp_action->fsf_req->erp_action = erp_action;
2937 /* start QDIO request for this FSF request */
2938 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2939 if (retval) {
2940 ZFCP_LOG_INFO("error: Could not send an open unit request "
2941 "on the adapter %s, port 0x%016Lx for "
2942 "unit 0x%016Lx\n",
2943 zfcp_get_busid_by_adapter(erp_action->adapter),
2944 erp_action->port->wwpn,
2945 erp_action->unit->fcp_lun);
2946 zfcp_fsf_req_free(erp_action->fsf_req);
2947 erp_action->fsf_req = NULL;
2948 goto out;
2951 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2952 "port 0x%016Lx, unit 0x%016Lx)\n",
2953 zfcp_get_busid_by_adapter(erp_action->adapter),
2954 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2955 out:
2956 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2957 lock_flags);
2958 return retval;
2962 * function: zfcp_fsf_open_unit_handler
2964 * purpose: is called for finished Open LUN command
2966 * returns:
2968 static int
2969 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2971 int retval = -EINVAL;
2972 struct zfcp_adapter *adapter;
2973 struct zfcp_unit *unit;
2974 struct fsf_qtcb_header *header;
2975 struct fsf_qtcb_bottom_support *bottom;
2976 struct fsf_queue_designator *queue_designator;
2977 u16 subtable, rule, counter;
2978 u32 allowed, exclusive, readwrite;
2980 unit = fsf_req->data.open_unit.unit;
2982 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2983 /* don't change unit status in our bookkeeping */
2984 goto skip_fsfstatus;
2987 adapter = fsf_req->adapter;
2988 header = &fsf_req->qtcb->header;
2989 bottom = &fsf_req->qtcb->bottom.support;
2990 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2992 allowed = bottom->lun_access_info & FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED;
2993 exclusive = bottom->lun_access_info & FSF_UNIT_ACCESS_EXCLUSIVE;
2994 readwrite = bottom->lun_access_info & FSF_UNIT_ACCESS_OUTBOUND_TRANSFER;
2996 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2997 ZFCP_STATUS_UNIT_SHARED |
2998 ZFCP_STATUS_UNIT_READONLY,
2999 &unit->status);
3001 /* evaluate FSF status in QTCB */
3002 switch (header->fsf_status) {
3004 case FSF_PORT_HANDLE_NOT_VALID:
3005 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3006 "for port 0x%016Lx on adapter %s invalid "
3007 "This may happen occasionally\n",
3008 unit->port->handle,
3009 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3010 ZFCP_LOG_DEBUG("status qualifier:\n");
3011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3012 (char *) &header->fsf_status_qual,
3013 sizeof (union fsf_status_qual));
3014 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3015 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3016 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3017 break;
3019 case FSF_LUN_ALREADY_OPEN:
3020 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3021 "remote port 0x%016Lx on adapter %s twice.\n",
3022 unit->fcp_lun,
3023 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3024 debug_text_exception(adapter->erp_dbf, 0,
3025 "fsf_s_uopen");
3026 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3027 break;
3029 case FSF_ACCESS_DENIED:
3030 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3031 "remote port 0x%016Lx on adapter %s\n",
3032 unit->fcp_lun, unit->port->wwpn,
3033 zfcp_get_busid_by_unit(unit));
3034 for (counter = 0; counter < 2; counter++) {
3035 subtable = header->fsf_status_qual.halfword[counter * 2];
3036 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3037 switch (subtable) {
3038 case FSF_SQ_CFDC_SUBTABLE_OS:
3039 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3040 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3041 case FSF_SQ_CFDC_SUBTABLE_LUN:
3042 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3043 zfcp_act_subtable_type[subtable], rule);
3044 break;
3047 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3048 zfcp_erp_unit_access_denied(unit);
3049 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3050 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3051 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3052 break;
3054 case FSF_PORT_BOXED:
3055 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3056 "needs to be reopened\n",
3057 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3058 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3059 zfcp_erp_port_reopen(unit->port, 0);
3060 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3061 ZFCP_STATUS_FSFREQ_RETRY;
3062 break;
3064 case FSF_LUN_SHARING_VIOLATION:
3065 if (header->fsf_status_qual.word[0] != 0) {
3066 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3067 "with WWPN 0x%Lx "
3068 "connected to the adapter %s "
3069 "is already in use in LPAR%d, CSS%d\n",
3070 unit->fcp_lun,
3071 unit->port->wwpn,
3072 zfcp_get_busid_by_unit(unit),
3073 queue_designator->hla,
3074 queue_designator->cssid);
3075 } else {
3076 subtable = header->fsf_status_qual.halfword[4];
3077 rule = header->fsf_status_qual.halfword[5];
3078 switch (subtable) {
3079 case FSF_SQ_CFDC_SUBTABLE_OS:
3080 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3081 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3082 case FSF_SQ_CFDC_SUBTABLE_LUN:
3083 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3084 "remote port with WWPN 0x%Lx "
3085 "connected to the adapter %s "
3086 "is denied (%s rule %d)\n",
3087 unit->fcp_lun,
3088 unit->port->wwpn,
3089 zfcp_get_busid_by_unit(unit),
3090 zfcp_act_subtable_type[subtable],
3091 rule);
3092 break;
3095 ZFCP_LOG_DEBUG("status qualifier:\n");
3096 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3097 (char *) &header->fsf_status_qual,
3098 sizeof (union fsf_status_qual));
3099 debug_text_event(adapter->erp_dbf, 2,
3100 "fsf_s_l_sh_vio");
3101 zfcp_erp_unit_access_denied(unit);
3102 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3103 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3104 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3105 break;
3107 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3108 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3109 "There is no handle (temporary port identifier) "
3110 "available for unit 0x%016Lx on port 0x%016Lx "
3111 "on adapter %s\n",
3112 unit->fcp_lun,
3113 unit->port->wwpn,
3114 zfcp_get_busid_by_unit(unit));
3115 debug_text_event(adapter->erp_dbf, 1,
3116 "fsf_s_max_units");
3117 zfcp_erp_unit_failed(unit);
3118 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3119 break;
3121 case FSF_ADAPTER_STATUS_AVAILABLE:
3122 switch (header->fsf_status_qual.word[0]) {
3123 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3124 /* Re-establish link to port */
3125 debug_text_event(adapter->erp_dbf, 1,
3126 "fsf_sq_ltest");
3127 zfcp_test_link(unit->port);
3128 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3129 break;
3130 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3131 /* ERP strategy will escalate */
3132 debug_text_event(adapter->erp_dbf, 1,
3133 "fsf_sq_ulp");
3134 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3135 break;
3136 default:
3137 ZFCP_LOG_NORMAL
3138 ("bug: Wrong status qualifier 0x%x arrived.\n",
3139 header->fsf_status_qual.word[0]);
3140 debug_text_event(adapter->erp_dbf, 0,
3141 "fsf_sq_inval:");
3142 debug_exception(adapter->erp_dbf, 0,
3143 &header->fsf_status_qual.word[0],
3144 sizeof (u32));
3146 break;
3148 case FSF_INVALID_COMMAND_OPTION:
3149 ZFCP_LOG_NORMAL(
3150 "Invalid option 0x%x has been specified "
3151 "in QTCB bottom sent to the adapter %s\n",
3152 bottom->option,
3153 zfcp_get_busid_by_adapter(adapter));
3154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3155 retval = -EINVAL;
3156 break;
3158 case FSF_GOOD:
3159 /* save LUN handle assigned by FSF */
3160 unit->handle = header->lun_handle;
3161 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3162 "adapter %s opened, port handle 0x%x\n",
3163 unit->fcp_lun,
3164 unit->port->wwpn,
3165 zfcp_get_busid_by_unit(unit),
3166 unit->handle);
3167 /* mark unit as open */
3168 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3170 if (adapter->supported_features & FSF_FEATURE_LUN_SHARING){
3171 if (!exclusive)
3172 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3173 &unit->status);
3175 if (!readwrite) {
3176 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3177 &unit->status);
3178 ZFCP_LOG_NORMAL("read-only access for unit "
3179 "(adapter %s, wwpn=0x%016Lx, "
3180 "fcp_lun=0x%016Lx)\n",
3181 zfcp_get_busid_by_unit(unit),
3182 unit->port->wwpn,
3183 unit->fcp_lun);
3186 if (exclusive && !readwrite) {
3187 ZFCP_LOG_NORMAL("exclusive access of read-only "
3188 "unit not supported\n");
3189 zfcp_erp_unit_failed(unit);
3190 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3191 zfcp_erp_unit_shutdown(unit, 0);
3192 } else if (!exclusive && readwrite) {
3193 ZFCP_LOG_NORMAL("shared access of read-write "
3194 "unit not supported\n");
3195 zfcp_erp_unit_failed(unit);
3196 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3197 zfcp_erp_unit_shutdown(unit, 0);
3201 retval = 0;
3202 break;
3204 default:
3205 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3206 "(debug info 0x%x)\n",
3207 header->fsf_status);
3208 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3209 debug_exception(adapter->erp_dbf, 0,
3210 &header->fsf_status, sizeof (u32));
3211 break;
3214 skip_fsfstatus:
3215 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3216 return retval;
3220 * function: zfcp_fsf_close_unit
3222 * purpose:
3224 * returns: address of fsf_req - request successfully initiated
3225 * NULL -
3227 * assumptions: This routine does not check whether the associated
3228 * remote port/lun has already been opened. This should be
3229 * done by calling routines. Otherwise some status
3230 * may be presented by FSF
3233 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3235 volatile struct qdio_buffer_element *sbale;
3236 unsigned long lock_flags;
3237 int retval = 0;
3239 /* setup new FSF request */
3240 retval = zfcp_fsf_req_create(erp_action->adapter,
3241 FSF_QTCB_CLOSE_LUN,
3242 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3243 erp_action->adapter->pool.fsf_req_erp,
3244 &lock_flags, &(erp_action->fsf_req));
3245 if (retval < 0) {
3246 ZFCP_LOG_INFO("error: Could not create close unit request for "
3247 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3248 erp_action->unit->fcp_lun,
3249 erp_action->port->wwpn,
3250 zfcp_get_busid_by_adapter(erp_action->adapter));
3251 goto out;
3254 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3255 erp_action->fsf_req->sbal_curr, 0);
3256 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3257 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3259 erp_action->fsf_req->qtcb->header.port_handle =
3260 erp_action->port->handle;
3261 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3262 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3263 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3264 erp_action->fsf_req->erp_action = erp_action;
3266 /* start QDIO request for this FSF request */
3267 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3268 if (retval) {
3269 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3270 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3271 erp_action->unit->fcp_lun,
3272 erp_action->port->wwpn,
3273 zfcp_get_busid_by_adapter(erp_action->adapter));
3274 zfcp_fsf_req_free(erp_action->fsf_req);
3275 erp_action->fsf_req = NULL;
3276 goto out;
3279 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3280 "port 0x%016Lx, unit 0x%016Lx)\n",
3281 zfcp_get_busid_by_adapter(erp_action->adapter),
3282 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3283 out:
3284 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3285 lock_flags);
3286 return retval;
3290 * function: zfcp_fsf_close_unit_handler
3292 * purpose: is called for finished Close LUN FSF command
3294 * returns:
3296 static int
3297 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3299 int retval = -EINVAL;
3300 struct zfcp_unit *unit;
3302 unit = fsf_req->data.close_unit.unit; /* restore unit */
3304 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3305 /* don't change unit status in our bookkeeping */
3306 goto skip_fsfstatus;
3309 /* evaluate FSF status in QTCB */
3310 switch (fsf_req->qtcb->header.fsf_status) {
3312 case FSF_PORT_HANDLE_NOT_VALID:
3313 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3314 "0x%016Lx on adapter %s invalid. This may "
3315 "happen in rare circumstances\n",
3316 unit->port->handle,
3317 unit->port->wwpn,
3318 zfcp_get_busid_by_unit(unit));
3319 ZFCP_LOG_DEBUG("status qualifier:\n");
3320 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3321 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3322 sizeof (union fsf_status_qual));
3323 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3324 "fsf_s_phand_nv");
3325 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3326 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3327 &fsf_req->qtcb->header.fsf_status_qual,
3328 sizeof (union fsf_status_qual));
3329 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3330 break;
3332 case FSF_LUN_HANDLE_NOT_VALID:
3333 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3334 "0x%016Lx on port 0x%016Lx on adapter %s is "
3335 "invalid. This may happen occasionally.\n",
3336 unit->handle,
3337 unit->fcp_lun,
3338 unit->port->wwpn,
3339 zfcp_get_busid_by_unit(unit));
3340 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3341 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3342 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3343 sizeof (union fsf_status_qual));
3344 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3345 "fsf_s_lhand_nv");
3346 zfcp_erp_port_reopen(unit->port, 0);
3347 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3348 &fsf_req->qtcb->header.fsf_status_qual,
3349 sizeof (union fsf_status_qual));
3350 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3351 break;
3353 case FSF_PORT_BOXED:
3354 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3355 "needs to be reopened\n",
3356 unit->port->wwpn,
3357 zfcp_get_busid_by_unit(unit));
3358 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3359 zfcp_erp_port_reopen(unit->port, 0);
3360 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3361 ZFCP_STATUS_FSFREQ_RETRY;
3362 break;
3364 case FSF_ADAPTER_STATUS_AVAILABLE:
3365 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3366 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3367 /* re-establish link to port */
3368 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3369 "fsf_sq_ltest");
3370 zfcp_test_link(unit->port);
3371 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3372 break;
3373 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3374 /* ERP strategy will escalate */
3375 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3376 "fsf_sq_ulp");
3377 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3378 break;
3379 default:
3380 ZFCP_LOG_NORMAL
3381 ("bug: Wrong status qualifier 0x%x arrived.\n",
3382 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3383 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3384 "fsf_sq_inval:");
3385 debug_exception(
3386 fsf_req->adapter->erp_dbf, 0,
3387 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3388 sizeof (u32));
3389 break;
3391 break;
3393 case FSF_GOOD:
3394 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3395 "closed, port handle 0x%x\n",
3396 unit->fcp_lun,
3397 unit->port->wwpn,
3398 zfcp_get_busid_by_unit(unit),
3399 unit->handle);
3400 /* mark unit as closed */
3401 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3402 retval = 0;
3403 break;
3405 default:
3406 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3407 "(debug info 0x%x)\n",
3408 fsf_req->qtcb->header.fsf_status);
3409 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3410 debug_exception(fsf_req->adapter->erp_dbf, 0,
3411 &fsf_req->qtcb->header.fsf_status,
3412 sizeof (u32));
3413 break;
3416 skip_fsfstatus:
3417 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3418 return retval;
3422 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3423 * @adapter: adapter where scsi command is issued
3424 * @unit: unit where command is sent to
3425 * @scsi_cmnd: scsi command to be sent
3426 * @timer: timer to be started when request is initiated
3427 * @req_flags: flags for fsf_request
3430 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3431 struct zfcp_unit *unit,
3432 struct scsi_cmnd * scsi_cmnd,
3433 struct timer_list *timer, int req_flags)
3435 struct zfcp_fsf_req *fsf_req = NULL;
3436 struct fcp_cmnd_iu *fcp_cmnd_iu;
3437 unsigned int sbtype;
3438 unsigned long lock_flags;
3439 int real_bytes = 0;
3440 int retval = 0;
3441 int mask;
3443 /* setup new FSF request */
3444 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3445 adapter->pool.fsf_req_scsi,
3446 &lock_flags, &fsf_req);
3447 if (unlikely(retval < 0)) {
3448 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3449 "for unit 0x%016Lx on port 0x%016Lx on "
3450 "adapter %s\n",
3451 unit->fcp_lun,
3452 unit->port->wwpn,
3453 zfcp_get_busid_by_adapter(adapter));
3454 goto failed_req_create;
3458 * associate FSF request with SCSI request
3459 * (need this for look up on abort)
3461 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3462 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3465 * associate SCSI command with FSF request
3466 * (need this for look up on normal command completion)
3468 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3469 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3470 fsf_req->data.send_fcp_command_task.unit = unit;
3471 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3473 /* set handles of unit and its parent port in QTCB */
3474 fsf_req->qtcb->header.lun_handle = unit->handle;
3475 fsf_req->qtcb->header.port_handle = unit->port->handle;
3477 /* FSF does not define the structure of the FCP_CMND IU */
3478 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3479 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3482 * set depending on data direction:
3483 * data direction bits in SBALE (SB Type)
3484 * data direction bits in QTCB
3485 * data direction bits in FCP_CMND IU
3487 switch (scsi_cmnd->sc_data_direction) {
3488 case DMA_NONE:
3489 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3491 * FIXME(qdio):
3492 * what is the correct type for commands
3493 * without 'real' data buffers?
3495 sbtype = SBAL_FLAGS0_TYPE_READ;
3496 break;
3497 case DMA_FROM_DEVICE:
3498 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3499 sbtype = SBAL_FLAGS0_TYPE_READ;
3500 fcp_cmnd_iu->rddata = 1;
3501 break;
3502 case DMA_TO_DEVICE:
3503 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3504 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3505 fcp_cmnd_iu->wddata = 1;
3506 break;
3507 case DMA_BIDIRECTIONAL:
3508 default:
3510 * dummy, catch this condition earlier
3511 * in zfcp_scsi_queuecommand
3513 goto failed_scsi_cmnd;
3516 /* set FC service class in QTCB (3 per default) */
3517 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3519 /* set FCP_LUN in FCP_CMND IU in QTCB */
3520 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3522 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3524 /* set task attributes in FCP_CMND IU in QTCB */
3525 if (likely((scsi_cmnd->device->simple_tags) ||
3526 (atomic_test_mask(mask, &unit->status))))
3527 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3528 else
3529 fcp_cmnd_iu->task_attribute = UNTAGGED;
3531 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3532 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3533 fcp_cmnd_iu->add_fcp_cdb_length
3534 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3535 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3536 "additional FCP_CDB length is 0x%x "
3537 "(shifted right 2 bits)\n",
3538 scsi_cmnd->cmd_len,
3539 fcp_cmnd_iu->add_fcp_cdb_length);
3542 * copy SCSI CDB (including additional length, if any) to
3543 * FCP_CDB in FCP_CMND IU in QTCB
3545 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3547 /* FCP CMND IU length in QTCB */
3548 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3549 sizeof (struct fcp_cmnd_iu) +
3550 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3552 /* generate SBALEs from data buffer */
3553 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3554 if (unlikely(real_bytes < 0)) {
3555 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3556 ZFCP_LOG_DEBUG(
3557 "Data did not fit into available buffer(s), "
3558 "waiting for more...\n");
3559 retval = -EIO;
3560 } else {
3561 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3562 "required. Shutting down unit "
3563 "(adapter %s, port 0x%016Lx, "
3564 "unit 0x%016Lx)\n",
3565 zfcp_get_busid_by_unit(unit),
3566 unit->port->wwpn,
3567 unit->fcp_lun);
3568 zfcp_erp_unit_shutdown(unit, 0);
3569 retval = -EINVAL;
3571 goto no_fit;
3574 /* set length of FCP data length in FCP_CMND IU in QTCB */
3575 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3577 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3578 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3579 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3582 * start QDIO request for this FSF request
3583 * covered by an SBALE)
3585 retval = zfcp_fsf_req_send(fsf_req, timer);
3586 if (unlikely(retval < 0)) {
3587 ZFCP_LOG_INFO("error: Could not send FCP command request "
3588 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3589 zfcp_get_busid_by_adapter(adapter),
3590 unit->port->wwpn,
3591 unit->fcp_lun);
3592 goto send_failed;
3595 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3596 "port 0x%016Lx, unit 0x%016Lx)\n",
3597 zfcp_get_busid_by_adapter(adapter),
3598 unit->port->wwpn,
3599 unit->fcp_lun);
3600 goto success;
3602 send_failed:
3603 no_fit:
3604 failed_scsi_cmnd:
3605 zfcp_fsf_req_free(fsf_req);
3606 fsf_req = NULL;
3607 scsi_cmnd->host_scribble = NULL;
3608 success:
3609 failed_req_create:
3610 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3611 return retval;
3615 * function: zfcp_fsf_send_fcp_command_task_management
3617 * purpose:
3619 * returns:
3621 * FIXME(design): should be watched by a timeout!!!
3622 * FIXME(design) shouldn't this be modified to return an int
3623 * also...don't know how though
3626 struct zfcp_fsf_req *
3627 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3628 struct zfcp_unit *unit,
3629 u8 tm_flags, int req_flags)
3631 struct zfcp_fsf_req *fsf_req = NULL;
3632 int retval = 0;
3633 struct fcp_cmnd_iu *fcp_cmnd_iu;
3634 unsigned long lock_flags;
3635 volatile struct qdio_buffer_element *sbale;
3637 /* setup new FSF request */
3638 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3639 adapter->pool.fsf_req_scsi,
3640 &lock_flags, &fsf_req);
3641 if (retval < 0) {
3642 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3643 "management) request for adapter %s, port "
3644 " 0x%016Lx, unit 0x%016Lx.\n",
3645 zfcp_get_busid_by_adapter(adapter),
3646 unit->port->wwpn, unit->fcp_lun);
3647 goto out;
3651 * Used to decide on proper handler in the return path,
3652 * could be either zfcp_fsf_send_fcp_command_task_handler or
3653 * zfcp_fsf_send_fcp_command_task_management_handler */
3655 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3658 * hold a pointer to the unit being target of this
3659 * task management request
3661 fsf_req->data.send_fcp_command_task_management.unit = unit;
3663 /* set FSF related fields in QTCB */
3664 fsf_req->qtcb->header.lun_handle = unit->handle;
3665 fsf_req->qtcb->header.port_handle = unit->port->handle;
3666 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3667 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3668 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3669 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3671 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3672 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3673 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3675 /* set FCP related fields in FCP_CMND IU in QTCB */
3676 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3677 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3678 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3679 fcp_cmnd_iu->task_management_flags = tm_flags;
3681 /* start QDIO request for this FSF request */
3682 zfcp_fsf_start_scsi_er_timer(adapter);
3683 retval = zfcp_fsf_req_send(fsf_req, NULL);
3684 if (retval) {
3685 del_timer(&adapter->scsi_er_timer);
3686 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3687 "management) on adapter %s, port 0x%016Lx for "
3688 "unit LUN 0x%016Lx\n",
3689 zfcp_get_busid_by_adapter(adapter),
3690 unit->port->wwpn,
3691 unit->fcp_lun);
3692 zfcp_fsf_req_free(fsf_req);
3693 fsf_req = NULL;
3694 goto out;
3697 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3698 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3699 "tm_flags=0x%x)\n",
3700 zfcp_get_busid_by_adapter(adapter),
3701 unit->port->wwpn,
3702 unit->fcp_lun,
3703 tm_flags);
3704 out:
3705 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3706 return fsf_req;
3710 * function: zfcp_fsf_send_fcp_command_handler
3712 * purpose: is called for finished Send FCP Command
3714 * returns:
3716 static int
3717 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3719 int retval = -EINVAL;
3720 struct zfcp_unit *unit;
3721 struct fsf_qtcb_header *header;
3722 u16 subtable, rule, counter;
3724 header = &fsf_req->qtcb->header;
3726 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3727 unit = fsf_req->data.send_fcp_command_task_management.unit;
3728 else
3729 unit = fsf_req->data.send_fcp_command_task.unit;
3731 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3732 /* go directly to calls of special handlers */
3733 goto skip_fsfstatus;
3736 /* evaluate FSF status in QTCB */
3737 switch (header->fsf_status) {
3739 case FSF_PORT_HANDLE_NOT_VALID:
3740 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3741 "0x%016Lx on adapter %s invalid\n",
3742 unit->port->handle,
3743 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3744 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3745 (char *) &header->fsf_status_qual,
3746 sizeof (union fsf_status_qual));
3747 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3748 "fsf_s_phand_nv");
3749 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3750 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3751 break;
3753 case FSF_LUN_HANDLE_NOT_VALID:
3754 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3755 "0x%016Lx on port 0x%016Lx on adapter %s is "
3756 "invalid. This may happen occasionally.\n",
3757 unit->handle,
3758 unit->fcp_lun,
3759 unit->port->wwpn,
3760 zfcp_get_busid_by_unit(unit));
3761 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3762 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3763 (char *) &header->fsf_status_qual,
3764 sizeof (union fsf_status_qual));
3765 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3766 "fsf_s_uhand_nv");
3767 zfcp_erp_port_reopen(unit->port, 0);
3768 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3769 break;
3771 case FSF_HANDLE_MISMATCH:
3772 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3773 "unexpectedly. (adapter %s, port 0x%016Lx, "
3774 "unit 0x%016Lx)\n",
3775 unit->port->handle,
3776 zfcp_get_busid_by_unit(unit),
3777 unit->port->wwpn,
3778 unit->fcp_lun);
3779 ZFCP_LOG_NORMAL("status qualifier:\n");
3780 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3781 (char *) &header->fsf_status_qual,
3782 sizeof (union fsf_status_qual));
3783 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3784 "fsf_s_hand_mis");
3785 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3786 zfcp_cmd_dbf_event_fsf("handmism",
3787 fsf_req,
3788 &header->fsf_status_qual,
3789 sizeof (union fsf_status_qual));
3790 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3791 break;
3793 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3794 if (fsf_req->adapter->fc_service_class <= 3) {
3795 ZFCP_LOG_NORMAL("error: The adapter %s does "
3796 "not support fibrechannel class %d.\n",
3797 zfcp_get_busid_by_unit(unit),
3798 fsf_req->adapter->fc_service_class);
3799 } else {
3800 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3801 "adapter %s is invalid. "
3802 "(debug info %d)\n",
3803 zfcp_get_busid_by_unit(unit),
3804 fsf_req->adapter->fc_service_class);
3806 /* stop operation for this adapter */
3807 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3808 "fsf_s_class_nsup");
3809 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3810 zfcp_cmd_dbf_event_fsf("unsclass",
3811 fsf_req,
3812 &header->fsf_status_qual,
3813 sizeof (union fsf_status_qual));
3814 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3815 break;
3817 case FSF_FCPLUN_NOT_VALID:
3818 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3819 "adapter %s does not have correct unit "
3820 "handle 0x%x\n",
3821 unit->fcp_lun,
3822 unit->port->wwpn,
3823 zfcp_get_busid_by_unit(unit),
3824 unit->handle);
3825 ZFCP_LOG_DEBUG("status qualifier:\n");
3826 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3827 (char *) &header->fsf_status_qual,
3828 sizeof (union fsf_status_qual));
3829 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3830 "fsf_s_fcp_lun_nv");
3831 zfcp_erp_port_reopen(unit->port, 0);
3832 zfcp_cmd_dbf_event_fsf("fluninv",
3833 fsf_req,
3834 &header->fsf_status_qual,
3835 sizeof (union fsf_status_qual));
3836 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3837 break;
3839 case FSF_ACCESS_DENIED:
3840 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3841 "unit 0x%016Lx on port 0x%016Lx on "
3842 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3843 zfcp_get_busid_by_unit(unit));
3844 for (counter = 0; counter < 2; counter++) {
3845 subtable = header->fsf_status_qual.halfword[counter * 2];
3846 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3847 switch (subtable) {
3848 case FSF_SQ_CFDC_SUBTABLE_OS:
3849 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3850 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3851 case FSF_SQ_CFDC_SUBTABLE_LUN:
3852 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3853 zfcp_act_subtable_type[subtable], rule);
3854 break;
3857 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3858 zfcp_erp_unit_access_denied(unit);
3859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3860 break;
3862 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3863 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3864 "0x%016Lx on port 0x%016Lx on adapter %s "
3865 "(debug info %d)\n",
3866 unit->fcp_lun,
3867 unit->port->wwpn,
3868 zfcp_get_busid_by_unit(unit),
3869 fsf_req->qtcb->bottom.io.data_direction);
3870 /* stop operation for this adapter */
3871 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3872 "fsf_s_dir_ind_nv");
3873 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3874 zfcp_cmd_dbf_event_fsf("dirinv",
3875 fsf_req,
3876 &header->fsf_status_qual,
3877 sizeof (union fsf_status_qual));
3878 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3879 break;
3881 case FSF_CMND_LENGTH_NOT_VALID:
3882 ZFCP_LOG_NORMAL
3883 ("bug: An invalid control-data-block length field "
3884 "was found in a command for unit 0x%016Lx on port "
3885 "0x%016Lx on adapter %s " "(debug info %d)\n",
3886 unit->fcp_lun, unit->port->wwpn,
3887 zfcp_get_busid_by_unit(unit),
3888 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3889 /* stop operation for this adapter */
3890 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3891 "fsf_s_cmd_len_nv");
3892 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3893 zfcp_cmd_dbf_event_fsf("cleninv",
3894 fsf_req,
3895 &header->fsf_status_qual,
3896 sizeof (union fsf_status_qual));
3897 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3898 break;
3900 case FSF_PORT_BOXED:
3901 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3902 "needs to be reopened\n",
3903 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3904 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3905 zfcp_erp_port_reopen(unit->port, 0);
3906 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3907 &header->fsf_status_qual,
3908 sizeof (union fsf_status_qual));
3909 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3910 ZFCP_STATUS_FSFREQ_RETRY;
3911 break;
3913 case FSF_LUN_BOXED:
3914 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3915 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3916 zfcp_get_busid_by_unit(unit),
3917 unit->port->wwpn, unit->fcp_lun);
3918 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3919 zfcp_erp_unit_reopen(unit, 0);
3920 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3921 &header->fsf_status_qual,
3922 sizeof(union fsf_status_qual));
3923 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3924 | ZFCP_STATUS_FSFREQ_RETRY;
3925 break;
3927 case FSF_ADAPTER_STATUS_AVAILABLE:
3928 switch (header->fsf_status_qual.word[0]) {
3929 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3930 /* re-establish link to port */
3931 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3932 "fsf_sq_ltest");
3933 zfcp_test_link(unit->port);
3934 break;
3935 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3936 /* FIXME(hw) need proper specs for proper action */
3937 /* let scsi stack deal with retries and escalation */
3938 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3939 "fsf_sq_ulp");
3940 break;
3941 default:
3942 ZFCP_LOG_NORMAL
3943 ("Unknown status qualifier 0x%x arrived.\n",
3944 header->fsf_status_qual.word[0]);
3945 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3946 "fsf_sq_inval:");
3947 debug_exception(fsf_req->adapter->erp_dbf, 0,
3948 &header->fsf_status_qual.word[0],
3949 sizeof(u32));
3950 break;
3952 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3953 break;
3955 case FSF_GOOD:
3956 break;
3958 case FSF_FCP_RSP_AVAILABLE:
3959 break;
3961 default:
3962 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3963 debug_exception(fsf_req->adapter->erp_dbf, 0,
3964 &header->fsf_status, sizeof(u32));
3965 break;
3968 skip_fsfstatus:
3969 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3970 retval =
3971 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3972 } else {
3973 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3975 return retval;
3979 * function: zfcp_fsf_send_fcp_command_task_handler
3981 * purpose: evaluates FCP_RSP IU
3983 * returns:
3985 static int
3986 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3988 int retval = 0;
3989 struct scsi_cmnd *scpnt;
3990 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3991 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3992 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3993 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3994 u32 sns_len;
3995 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3996 unsigned long flags;
3997 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
3999 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4000 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
4001 if (unlikely(!scpnt)) {
4002 ZFCP_LOG_DEBUG
4003 ("Command with fsf_req %p is not associated to "
4004 "a scsi command anymore. Aborted?\n", fsf_req);
4005 goto out;
4007 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4008 /* FIXME: (design) mid-layer should handle DID_ABORT like
4009 * DID_SOFT_ERROR by retrying the request for devices
4010 * that allow retries.
4012 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4013 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4014 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4015 goto skip_fsfstatus;
4018 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4019 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4020 set_host_byte(&scpnt->result, DID_ERROR);
4021 goto skip_fsfstatus;
4024 /* set message byte of result in SCSI command */
4025 scpnt->result |= COMMAND_COMPLETE << 8;
4028 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4029 * of result in SCSI command
4031 scpnt->result |= fcp_rsp_iu->scsi_status;
4032 if (unlikely(fcp_rsp_iu->scsi_status)) {
4033 /* DEBUG */
4034 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4035 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4036 scpnt->cmnd, scpnt->cmd_len);
4037 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4038 fcp_rsp_iu->scsi_status);
4039 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4040 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4041 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4042 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4043 fcp_rsp_iu->fcp_sns_len);
4046 /* check FCP_RSP_INFO */
4047 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4048 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4049 switch (fcp_rsp_info[3]) {
4050 case RSP_CODE_GOOD:
4051 /* ok, continue */
4052 ZFCP_LOG_TRACE("no failure or Task Management "
4053 "Function complete\n");
4054 set_host_byte(&scpnt->result, DID_OK);
4055 break;
4056 case RSP_CODE_LENGTH_MISMATCH:
4057 /* hardware bug */
4058 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4059 "that the fibrechannel protocol data "
4060 "length differs from the burst length. "
4061 "The problem occured on unit 0x%016Lx "
4062 "on port 0x%016Lx on adapter %s",
4063 unit->fcp_lun,
4064 unit->port->wwpn,
4065 zfcp_get_busid_by_unit(unit));
4066 /* dump SCSI CDB as prepared by zfcp */
4067 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4068 (char *) &fsf_req->qtcb->
4069 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4070 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4071 set_host_byte(&scpnt->result, DID_ERROR);
4072 goto skip_fsfstatus;
4073 case RSP_CODE_FIELD_INVALID:
4074 /* driver or hardware bug */
4075 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4076 "that the fibrechannel protocol data "
4077 "fields were incorrectly set up. "
4078 "The problem occured on the unit "
4079 "0x%016Lx on port 0x%016Lx on "
4080 "adapter %s",
4081 unit->fcp_lun,
4082 unit->port->wwpn,
4083 zfcp_get_busid_by_unit(unit));
4084 /* dump SCSI CDB as prepared by zfcp */
4085 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4086 (char *) &fsf_req->qtcb->
4087 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4088 set_host_byte(&scpnt->result, DID_ERROR);
4089 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4090 goto skip_fsfstatus;
4091 case RSP_CODE_RO_MISMATCH:
4092 /* hardware bug */
4093 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4094 "that conflicting values for the "
4095 "fibrechannel payload offset from the "
4096 "header were found. "
4097 "The problem occured on unit 0x%016Lx "
4098 "on port 0x%016Lx on adapter %s.\n",
4099 unit->fcp_lun,
4100 unit->port->wwpn,
4101 zfcp_get_busid_by_unit(unit));
4102 /* dump SCSI CDB as prepared by zfcp */
4103 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4104 (char *) &fsf_req->qtcb->
4105 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4106 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4107 set_host_byte(&scpnt->result, DID_ERROR);
4108 goto skip_fsfstatus;
4109 default:
4110 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4111 "code was detected for a command. "
4112 "The problem occured on the unit "
4113 "0x%016Lx on port 0x%016Lx on "
4114 "adapter %s (debug info 0x%x)\n",
4115 unit->fcp_lun,
4116 unit->port->wwpn,
4117 zfcp_get_busid_by_unit(unit),
4118 fcp_rsp_info[3]);
4119 /* dump SCSI CDB as prepared by zfcp */
4120 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4121 (char *) &fsf_req->qtcb->
4122 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4123 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4124 set_host_byte(&scpnt->result, DID_ERROR);
4125 goto skip_fsfstatus;
4129 /* check for sense data */
4130 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4131 sns_len = FSF_FCP_RSP_SIZE -
4132 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4133 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4134 sns_len);
4135 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4136 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4137 SCSI_SENSE_BUFFERSIZE);
4138 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4139 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4140 scpnt->result);
4141 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4142 (void *) &scpnt->cmnd, scpnt->cmd_len);
4144 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4145 fcp_rsp_iu->fcp_sns_len);
4146 memcpy(&scpnt->sense_buffer,
4147 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4148 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4149 (void *) &scpnt->sense_buffer, sns_len);
4152 /* check for overrun */
4153 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4154 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4155 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4156 "The response data length is "
4157 "%d, the original length was %d.\n",
4158 unit->fcp_lun,
4159 unit->port->wwpn,
4160 zfcp_get_busid_by_unit(unit),
4161 fcp_rsp_iu->fcp_resid,
4162 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4165 /* check for underrun */
4166 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4167 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4168 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4169 "The response data length is "
4170 "%d, the original length was %d.\n",
4171 unit->fcp_lun,
4172 unit->port->wwpn,
4173 zfcp_get_busid_by_unit(unit),
4174 fcp_rsp_iu->fcp_resid,
4175 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4177 scpnt->resid = fcp_rsp_iu->fcp_resid;
4178 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4179 set_host_byte(&scpnt->result, DID_ERROR);
4182 skip_fsfstatus:
4183 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4185 zfcp_cmd_dbf_event_scsi("response", scpnt);
4187 /* cleanup pointer (need this especially for abort) */
4188 scpnt->host_scribble = NULL;
4191 * NOTE:
4192 * according to the outcome of a discussion on linux-scsi we
4193 * don't need to grab the io_request_lock here since we use
4194 * the new eh
4196 /* always call back */
4198 (scpnt->scsi_done) (scpnt);
4201 * We must hold this lock until scsi_done has been called.
4202 * Otherwise we may call scsi_done after abort regarding this
4203 * command has completed.
4204 * Note: scsi_done must not block!
4206 out:
4207 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4208 return retval;
4212 * function: zfcp_fsf_send_fcp_command_task_management_handler
4214 * purpose: evaluates FCP_RSP IU
4216 * returns:
4218 static int
4219 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4221 int retval = 0;
4222 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4223 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4224 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4225 struct zfcp_unit *unit =
4226 fsf_req->data.send_fcp_command_task_management.unit;
4228 del_timer(&fsf_req->adapter->scsi_er_timer);
4229 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4230 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4231 goto skip_fsfstatus;
4234 /* check FCP_RSP_INFO */
4235 switch (fcp_rsp_info[3]) {
4236 case RSP_CODE_GOOD:
4237 /* ok, continue */
4238 ZFCP_LOG_DEBUG("no failure or Task Management "
4239 "Function complete\n");
4240 break;
4241 case RSP_CODE_TASKMAN_UNSUPP:
4242 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4243 "is not supported on the target device "
4244 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4245 unit->fcp_lun,
4246 unit->port->wwpn,
4247 zfcp_get_busid_by_unit(unit));
4248 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4249 break;
4250 case RSP_CODE_TASKMAN_FAILED:
4251 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4252 "failed to complete successfully. "
4253 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4254 unit->fcp_lun,
4255 unit->port->wwpn,
4256 zfcp_get_busid_by_unit(unit));
4257 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4258 break;
4259 default:
4260 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4261 "code was detected for a command. "
4262 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4263 "(debug info 0x%x)\n",
4264 unit->fcp_lun,
4265 unit->port->wwpn,
4266 zfcp_get_busid_by_unit(unit),
4267 fcp_rsp_info[3]);
4268 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4271 skip_fsfstatus:
4272 return retval;
4277 * function: zfcp_fsf_control_file
4279 * purpose: Initiator of the control file upload/download FSF requests
4281 * returns: 0 - FSF request is successfuly created and queued
4282 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4283 * -EINVAL - Invalid direction specified
4284 * -ENOMEM - Insufficient memory
4285 * -EPERM - Cannot create FSF request or place it in QDIO queue
4288 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4289 struct zfcp_fsf_req **fsf_req_ptr,
4290 u32 fsf_command,
4291 u32 option,
4292 struct zfcp_sg_list *sg_list)
4294 struct zfcp_fsf_req *fsf_req;
4295 struct fsf_qtcb_bottom_support *bottom;
4296 volatile struct qdio_buffer_element *sbale;
4297 struct timer_list *timer;
4298 unsigned long lock_flags;
4299 int req_flags = 0;
4300 int direction;
4301 int retval = 0;
4303 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4304 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4305 zfcp_get_busid_by_adapter(adapter));
4306 retval = -EOPNOTSUPP;
4307 goto out;
4310 switch (fsf_command) {
4312 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4313 direction = SBAL_FLAGS0_TYPE_WRITE;
4314 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4315 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4316 req_flags = ZFCP_WAIT_FOR_SBAL;
4317 break;
4319 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4320 direction = SBAL_FLAGS0_TYPE_READ;
4321 break;
4323 default:
4324 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4325 retval = -EINVAL;
4326 goto out;
4329 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4330 if (!timer) {
4331 retval = -ENOMEM;
4332 goto out;
4335 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4336 NULL, &lock_flags, &fsf_req);
4337 if (retval < 0) {
4338 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4339 "adapter %s\n",
4340 zfcp_get_busid_by_adapter(adapter));
4341 retval = -EPERM;
4342 goto unlock_queue_lock;
4345 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4346 sbale[0].flags |= direction;
4348 bottom = &fsf_req->qtcb->bottom.support;
4349 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4350 bottom->option = option;
4352 if (sg_list->count > 0) {
4353 int bytes;
4355 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4356 sg_list->sg, sg_list->count,
4357 ZFCP_MAX_SBALS_PER_REQ);
4358 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4359 ZFCP_LOG_INFO(
4360 "error: Could not create sufficient number of "
4361 "SBALS for an FSF request to the adapter %s\n",
4362 zfcp_get_busid_by_adapter(adapter));
4363 retval = -ENOMEM;
4364 goto free_fsf_req;
4366 } else
4367 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4369 init_timer(timer);
4370 timer->function = zfcp_fsf_request_timeout_handler;
4371 timer->data = (unsigned long) adapter;
4372 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4374 retval = zfcp_fsf_req_send(fsf_req, timer);
4375 if (retval < 0) {
4376 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4377 "(adapter %s)\n",
4378 zfcp_get_busid_by_adapter(adapter));
4379 retval = -EPERM;
4380 goto free_fsf_req;
4382 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4384 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4385 "adapter %s\n",
4386 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4387 "download" : "upload",
4388 zfcp_get_busid_by_adapter(adapter));
4390 wait_event(fsf_req->completion_wq,
4391 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4393 *fsf_req_ptr = fsf_req;
4394 del_timer_sync(timer);
4395 goto free_timer;
4397 free_fsf_req:
4398 zfcp_fsf_req_free(fsf_req);
4399 unlock_queue_lock:
4400 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4401 free_timer:
4402 kfree(timer);
4403 out:
4404 return retval;
4409 * function: zfcp_fsf_control_file_handler
4411 * purpose: Handler of the control file upload/download FSF requests
4413 * returns: 0 - FSF request successfuly processed
4414 * -EAGAIN - Operation has to be repeated because of a temporary problem
4415 * -EACCES - There is no permission to execute an operation
4416 * -EPERM - The control file is not in a right format
4417 * -EIO - There is a problem with the FCP adapter
4418 * -EINVAL - Invalid operation
4419 * -EFAULT - User space memory I/O operation fault
4421 static int
4422 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4424 struct zfcp_adapter *adapter = fsf_req->adapter;
4425 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4426 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4427 int retval = 0;
4429 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4430 retval = -EINVAL;
4431 goto skip_fsfstatus;
4434 switch (header->fsf_status) {
4436 case FSF_GOOD:
4437 ZFCP_LOG_NORMAL(
4438 "The FSF request has been successfully completed "
4439 "on the adapter %s\n",
4440 zfcp_get_busid_by_adapter(adapter));
4441 break;
4443 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4444 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4445 switch (header->fsf_status_qual.word[0]) {
4447 case FSF_SQ_CFDC_HARDENED_ON_SE:
4448 ZFCP_LOG_NORMAL(
4449 "CFDC on the adapter %s has being "
4450 "hardened on primary and secondary SE\n",
4451 zfcp_get_busid_by_adapter(adapter));
4452 break;
4454 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4455 ZFCP_LOG_NORMAL(
4456 "CFDC of the adapter %s could not "
4457 "be saved on the SE\n",
4458 zfcp_get_busid_by_adapter(adapter));
4459 break;
4461 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4462 ZFCP_LOG_NORMAL(
4463 "CFDC of the adapter %s could not "
4464 "be copied to the secondary SE\n",
4465 zfcp_get_busid_by_adapter(adapter));
4466 break;
4468 default:
4469 ZFCP_LOG_NORMAL(
4470 "CFDC could not be hardened "
4471 "on the adapter %s\n",
4472 zfcp_get_busid_by_adapter(adapter));
4475 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4476 retval = -EAGAIN;
4477 break;
4479 case FSF_AUTHORIZATION_FAILURE:
4480 ZFCP_LOG_NORMAL(
4481 "Adapter %s does not accept privileged commands\n",
4482 zfcp_get_busid_by_adapter(adapter));
4483 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4484 retval = -EACCES;
4485 break;
4487 case FSF_CFDC_ERROR_DETECTED:
4488 ZFCP_LOG_NORMAL(
4489 "Error at position %d in the CFDC, "
4490 "CFDC is discarded by the adapter %s\n",
4491 header->fsf_status_qual.word[0],
4492 zfcp_get_busid_by_adapter(adapter));
4493 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4494 retval = -EPERM;
4495 break;
4497 case FSF_CONTROL_FILE_UPDATE_ERROR:
4498 ZFCP_LOG_NORMAL(
4499 "Adapter %s cannot harden the control file, "
4500 "file is discarded\n",
4501 zfcp_get_busid_by_adapter(adapter));
4502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4503 retval = -EIO;
4504 break;
4506 case FSF_CONTROL_FILE_TOO_LARGE:
4507 ZFCP_LOG_NORMAL(
4508 "Control file is too large, file is discarded "
4509 "by the adapter %s\n",
4510 zfcp_get_busid_by_adapter(adapter));
4511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4512 retval = -EIO;
4513 break;
4515 case FSF_ACCESS_CONFLICT_DETECTED:
4516 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4517 ZFCP_LOG_NORMAL(
4518 "CFDC has been discarded by the adapter %s, "
4519 "because activation would impact "
4520 "%d active connection(s)\n",
4521 zfcp_get_busid_by_adapter(adapter),
4522 header->fsf_status_qual.word[0]);
4523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4524 retval = -EIO;
4525 break;
4527 case FSF_CONFLICTS_OVERRULED:
4528 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4529 ZFCP_LOG_NORMAL(
4530 "CFDC has been activated on the adapter %s, "
4531 "but activation has impacted "
4532 "%d active connection(s)\n",
4533 zfcp_get_busid_by_adapter(adapter),
4534 header->fsf_status_qual.word[0]);
4535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4536 retval = -EIO;
4537 break;
4539 case FSF_UNKNOWN_OP_SUBTYPE:
4540 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4541 "op_subtype=0x%x)\n",
4542 zfcp_get_busid_by_adapter(adapter),
4543 bottom->operation_subtype);
4544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4545 retval = -EINVAL;
4546 break;
4548 case FSF_INVALID_COMMAND_OPTION:
4549 ZFCP_LOG_NORMAL(
4550 "Invalid option 0x%x has been specified "
4551 "in QTCB bottom sent to the adapter %s\n",
4552 bottom->option,
4553 zfcp_get_busid_by_adapter(adapter));
4554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4555 retval = -EINVAL;
4556 break;
4558 default:
4559 ZFCP_LOG_NORMAL(
4560 "bug: An unknown/unexpected FSF status 0x%08x "
4561 "was presented on the adapter %s\n",
4562 header->fsf_status,
4563 zfcp_get_busid_by_adapter(adapter));
4564 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4565 debug_exception(fsf_req->adapter->erp_dbf, 0,
4566 &header->fsf_status_qual.word[0], sizeof(u32));
4567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4568 retval = -EINVAL;
4569 break;
4572 skip_fsfstatus:
4573 return retval;
4578 * function: zfcp_fsf_req_wait_and_cleanup
4580 * purpose:
4582 * FIXME(design): signal seems to be <0 !!!
4583 * returns: 0 - request completed (*status is valid), cleanup succ.
4584 * <0 - request completed (*status is valid), cleanup failed
4585 * >0 - signal which interrupted waiting (*status invalid),
4586 * request not completed, no cleanup
4588 * *status is a copy of status of completed fsf_req
4591 zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4592 int interruptible, u32 * status)
4594 int retval = 0;
4595 int signal = 0;
4597 if (interruptible) {
4598 __wait_event_interruptible(fsf_req->completion_wq,
4599 fsf_req->status &
4600 ZFCP_STATUS_FSFREQ_COMPLETED,
4601 signal);
4602 if (signal) {
4603 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4604 "completion of the request at %p\n",
4605 signal, fsf_req);
4606 retval = signal;
4607 goto out;
4609 } else {
4610 __wait_event(fsf_req->completion_wq,
4611 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4614 *status = fsf_req->status;
4616 /* cleanup request */
4617 zfcp_fsf_req_cleanup(fsf_req);
4618 out:
4619 return retval;
4622 static inline int
4623 zfcp_fsf_req_sbal_check(unsigned long *flags,
4624 struct zfcp_qdio_queue *queue, int needed)
4626 write_lock_irqsave(&queue->queue_lock, *flags);
4627 if (likely(atomic_read(&queue->free_count) >= needed))
4628 return 1;
4629 write_unlock_irqrestore(&queue->queue_lock, *flags);
4630 return 0;
4634 * set qtcb pointer in fsf_req and initialize QTCB
4636 static inline void
4637 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4639 if (likely(fsf_req->qtcb != NULL)) {
4640 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4641 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4642 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4643 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4644 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4645 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4650 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4651 * @adapter: adapter for which request queue is examined
4652 * @req_flags: flags indicating whether to wait for needed SBAL or not
4653 * @lock_flags: lock_flags if queue_lock is taken
4654 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4655 * Locks: lock adapter->request_queue->queue_lock on success
4657 static int
4658 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4659 unsigned long *lock_flags)
4661 long ret;
4662 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4664 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4665 ret = wait_event_interruptible_timeout(adapter->request_wq,
4666 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4667 ZFCP_SBAL_TIMEOUT);
4668 if (ret < 0)
4669 return ret;
4670 if (!ret)
4671 return -EIO;
4672 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4673 return -EIO;
4675 return 0;
4679 * function: zfcp_fsf_req_create
4681 * purpose: create an FSF request at the specified adapter and
4682 * setup common fields
4684 * returns: -ENOMEM if there was insufficient memory for a request
4685 * -EIO if no qdio buffers could be allocate to the request
4686 * -EINVAL/-EPERM on bug conditions in req_dequeue
4687 * 0 in success
4689 * note: The created request is returned by reference.
4691 * locks: lock of concerned request queue must not be held,
4692 * but is held on completion (write, irqsave)
4695 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4696 mempool_t *pool, unsigned long *lock_flags,
4697 struct zfcp_fsf_req **fsf_req_p)
4699 volatile struct qdio_buffer_element *sbale;
4700 struct zfcp_fsf_req *fsf_req = NULL;
4701 int ret = 0;
4702 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4704 /* allocate new FSF request */
4705 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4706 if (unlikely(NULL == fsf_req)) {
4707 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4708 "the outbound (send) queue.\n");
4709 ret = -ENOMEM;
4710 goto failed_fsf_req;
4713 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4715 /* initialize waitqueue which may be used to wait on
4716 this request completion */
4717 init_waitqueue_head(&fsf_req->completion_wq);
4719 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4720 if(ret < 0) {
4721 goto failed_sbals;
4725 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4726 * if it is not set (see also *_open_qdio and *_close_qdio).
4729 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4730 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4731 ret = -EIO;
4732 goto failed_sbals;
4735 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4736 fsf_req->fsf_command = fsf_cmd;
4737 fsf_req->sbal_number = 1;
4738 fsf_req->sbal_first = req_queue->free_index;
4739 fsf_req->sbal_curr = req_queue->free_index;
4740 fsf_req->sbale_curr = 1;
4742 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4743 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4746 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4748 /* setup common SBALE fields */
4749 sbale[0].addr = fsf_req;
4750 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4751 if (likely(fsf_req->qtcb != NULL)) {
4752 sbale[1].addr = (void *) fsf_req->qtcb;
4753 sbale[1].length = sizeof(struct fsf_qtcb);
4756 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4757 fsf_req->sbal_number, fsf_req->sbal_first);
4759 goto success;
4761 failed_sbals:
4762 /* dequeue new FSF request previously enqueued */
4763 zfcp_fsf_req_free(fsf_req);
4764 fsf_req = NULL;
4766 failed_fsf_req:
4767 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4768 success:
4769 *fsf_req_p = fsf_req;
4770 return ret;
4774 * function: zfcp_fsf_req_send
4776 * purpose: start transfer of FSF request via QDIO
4778 * returns: 0 - request transfer succesfully started
4779 * !0 - start of request transfer failed
4781 static int
4782 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4784 struct zfcp_adapter *adapter;
4785 struct zfcp_qdio_queue *req_queue;
4786 volatile struct qdio_buffer_element *sbale;
4787 int new_distance_from_int;
4788 unsigned long flags;
4789 int inc_seq_no = 1;
4790 int retval = 0;
4792 adapter = fsf_req->adapter;
4793 req_queue = &adapter->request_queue,
4796 /* FIXME(debug): remove it later */
4797 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4798 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4799 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4800 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4801 sbale[1].length);
4803 /* set sequence counter in QTCB */
4804 if (likely(fsf_req->qtcb)) {
4805 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4806 fsf_req->seq_no = adapter->fsf_req_seq_no;
4807 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4808 "FSF sequence counter value of %i\n",
4809 fsf_req,
4810 zfcp_get_busid_by_adapter(adapter),
4811 fsf_req->qtcb->prefix.req_seq_no);
4812 } else
4813 inc_seq_no = 0;
4815 /* put allocated FSF request at list tail */
4816 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4817 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4818 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4820 /* figure out expiration time of timeout and start timeout */
4821 if (unlikely(timer)) {
4822 timer->expires += jiffies;
4823 add_timer(timer);
4826 ZFCP_LOG_TRACE("request queue of adapter %s: "
4827 "next free SBAL is %i, %i free SBALs\n",
4828 zfcp_get_busid_by_adapter(adapter),
4829 req_queue->free_index,
4830 atomic_read(&req_queue->free_count));
4832 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4833 "index_in_queue=%i, count=%i, buffers=%p\n",
4834 zfcp_get_busid_by_adapter(adapter),
4835 QDIO_FLAG_SYNC_OUTPUT,
4836 0, fsf_req->sbal_first, fsf_req->sbal_number,
4837 &req_queue->buffer[fsf_req->sbal_first]);
4840 * adjust the number of free SBALs in request queue as well as
4841 * position of first one
4843 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4844 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4845 req_queue->free_index += fsf_req->sbal_number; /* increase */
4846 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4847 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4849 retval = do_QDIO(adapter->ccw_device,
4850 QDIO_FLAG_SYNC_OUTPUT,
4851 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4853 if (unlikely(retval)) {
4854 /* Queues are down..... */
4855 retval = -EIO;
4857 * FIXME(potential race):
4858 * timer might be expired (absolutely unlikely)
4860 if (timer)
4861 del_timer(timer);
4862 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4863 list_del(&fsf_req->list);
4864 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4866 * adjust the number of free SBALs in request queue as well as
4867 * position of first one
4869 zfcp_qdio_zero_sbals(req_queue->buffer,
4870 fsf_req->sbal_first, fsf_req->sbal_number);
4871 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4872 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4873 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4874 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4875 ZFCP_LOG_DEBUG
4876 ("error: do_QDIO failed. Buffers could not be enqueued "
4877 "to request queue.\n");
4878 } else {
4879 req_queue->distance_from_int = new_distance_from_int;
4881 * increase FSF sequence counter -
4882 * this must only be done for request successfully enqueued to
4883 * QDIO this rejected requests may be cleaned up by calling
4884 * routines resulting in missing sequence counter values
4885 * otherwise,
4887 /* Don't increase for unsolicited status */
4888 if (likely(inc_seq_no)) {
4889 adapter->fsf_req_seq_no++;
4890 ZFCP_LOG_TRACE
4891 ("FSF sequence counter value of adapter %s "
4892 "increased to %i\n",
4893 zfcp_get_busid_by_adapter(adapter),
4894 adapter->fsf_req_seq_no);
4896 /* count FSF requests pending */
4897 atomic_inc(&adapter->fsf_reqs_active);
4899 return retval;
4903 * function: zfcp_fsf_req_cleanup
4905 * purpose: cleans up an FSF request and removes it from the specified list
4907 * returns:
4909 * assumption: no pending SB in SBALEs other than QTCB
4911 void
4912 zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
4914 struct zfcp_adapter *adapter = fsf_req->adapter;
4915 unsigned long flags;
4917 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4918 list_del(&fsf_req->list);
4919 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4920 zfcp_fsf_req_free(fsf_req);
4923 #undef ZFCP_LOG_AREA