blob: 56b2ea97da1f3e12488e885dafb91f26981ebc9d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * linux/drivers/s390/scsi/zfcp_fsf.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
8 *
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>
17 *
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.
22 *
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.
27 *
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.
31 */
32
33#define ZFCP_FSF_C_REVISION "$Revision: 1.92 $"
34
35#include "zfcp_ext.h"
36
37static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
38static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
39static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
40static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
41static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
42static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
43static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
44static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
45static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
46static int zfcp_fsf_send_fcp_command_task_management_handler(
47 struct zfcp_fsf_req *);
48static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
49static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
50static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
51static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
52static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
53static inline int zfcp_fsf_req_sbal_check(
54 unsigned long *, struct zfcp_qdio_queue *, int);
55static inline int zfcp_use_one_sbal(
56 struct scatterlist *, int, struct scatterlist *, int);
57static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
58static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
59static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
60static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
61static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
62static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
63static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* association between FSF command and FSF QTCB type */
66static u32 fsf_qtcb_type[] = {
67 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
68 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
69 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
76 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
77 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
78 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
79 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
80};
81
82static const char zfcp_act_subtable_type[5][8] = {
83 "unknown", "OS", "WWPN", "DID", "LUN"
84};
85
86/****************************************************************/
87/*************** FSF related Functions *************************/
88/****************************************************************/
89
90#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
91
92/*
93 * function: zfcp_fsf_req_alloc
94 *
95 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
96 * unsolicited requests) via helper functions
97 * Does some initial fsf request set-up.
98 *
99 * returns: pointer to allocated fsf_req if successfull
100 * NULL otherwise
101 *
102 * locks: none
103 *
104 */
105static struct zfcp_fsf_req *
106zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
107{
108 size_t size;
109 void *ptr;
110 struct zfcp_fsf_req *fsf_req = NULL;
111
112 if (req_flags & ZFCP_REQ_NO_QTCB)
113 size = sizeof(struct zfcp_fsf_req);
114 else
115 size = sizeof(struct zfcp_fsf_req_pool_element);
116
117 if (likely(pool != NULL))
118 ptr = mempool_alloc(pool, GFP_ATOMIC);
119 else
120 ptr = kmalloc(size, GFP_ATOMIC);
121
122 if (unlikely(NULL == ptr))
123 goto out;
124
125 memset(ptr, 0, size);
126
127 if (req_flags & ZFCP_REQ_NO_QTCB) {
128 fsf_req = (struct zfcp_fsf_req *) ptr;
129 } else {
130 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
131 fsf_req->qtcb =
132 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
133 }
134
135 fsf_req->pool = pool;
136
137 out:
138 return fsf_req;
139}
140
141/*
142 * function: zfcp_fsf_req_free
143 *
144 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
145 * returns it into the pool via helper functions.
146 *
147 * returns: sod all
148 *
149 * locks: none
150 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200151void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
153{
154 if (likely(fsf_req->pool != NULL))
155 mempool_free(fsf_req, fsf_req->pool);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200156 else
157 kfree(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160/*
161 * function:
162 *
163 * purpose:
164 *
165 * returns:
166 *
167 * note: qdio queues shall be down (no ongoing inbound processing)
168 */
169int
170zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
171{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 struct zfcp_fsf_req *fsf_req, *tmp;
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200173 unsigned long flags;
174 LIST_HEAD(remove_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200176 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
177 list_splice_init(&adapter->fsf_req_list_head, &remove_queue);
178 atomic_set(&adapter->fsf_reqs_active, 0);
179 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
180
181 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
182 list_del(&fsf_req->list);
183 zfcp_fsf_req_dismiss(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 }
185
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200186 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
189/*
190 * function:
191 *
192 * purpose:
193 *
194 * returns:
195 */
196static void
197zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
198{
199 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
200 zfcp_fsf_req_complete(fsf_req);
201}
202
203/*
204 * function: zfcp_fsf_req_complete
205 *
206 * purpose: Updates active counts and timers for openfcp-reqs
207 * May cleanup request after req_eval returns
208 *
209 * returns: 0 - success
210 * !0 - failure
211 *
212 * context:
213 */
214int
215zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
216{
217 int retval = 0;
218 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
221 ZFCP_LOG_DEBUG("Status read response received\n");
222 /*
223 * Note: all cleanup handling is done in the callchain of
224 * the function call-chain below.
225 */
226 zfcp_fsf_status_read_handler(fsf_req);
227 goto out;
228 } else
229 zfcp_fsf_protstatus_eval(fsf_req);
230
231 /*
232 * fsf_req may be deleted due to waking up functions, so
233 * cleanup is saved here and used later
234 */
235 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
236 cleanup = 1;
237 else
238 cleanup = 0;
239
240 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
241
242 /* cleanup request if requested by initiator */
243 if (likely(cleanup)) {
244 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
245 /*
246 * lock must not be held here since it will be
247 * grabed by the called routine, too
248 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200249 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 } else {
251 /* notify initiator waiting for the requests completion */
252 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
253 /*
254 * FIXME: Race! We must not access fsf_req here as it might have been
255 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
256 * flag. It's an improbable case. But, we have the same paranoia for
257 * the cleanup flag already.
258 * Might better be handled using complete()?
259 * (setting the flag and doing wakeup ought to be atomic
260 * with regard to checking the flag as long as waitqueue is
261 * part of the to be released structure)
262 */
263 wake_up(&fsf_req->completion_wq);
264 }
265
266 out:
267 return retval;
268}
269
270/*
271 * function: zfcp_fsf_protstatus_eval
272 *
273 * purpose: evaluates the QTCB of the finished FSF request
274 * and initiates appropriate actions
275 * (usually calling FSF command specific handlers)
276 *
277 * returns:
278 *
279 * context:
280 *
281 * locks:
282 */
283static int
284zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
285{
286 int retval = 0;
287 struct zfcp_adapter *adapter = fsf_req->adapter;
288
289 ZFCP_LOG_DEBUG("QTCB is at %p\n", fsf_req->qtcb);
290
291 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
292 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
293 (unsigned long) fsf_req);
294 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
295 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
296 zfcp_cmd_dbf_event_fsf("dismiss", fsf_req, NULL, 0);
297 goto skip_protstatus;
298 }
299
300 /* log additional information provided by FSF (if any) */
301 if (unlikely(fsf_req->qtcb->header.log_length)) {
302 /* do not trust them ;-) */
303 if (fsf_req->qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
304 ZFCP_LOG_NORMAL
305 ("bug: ULP (FSF logging) log data starts "
306 "beyond end of packet header. Ignored. "
307 "(start=%i, size=%li)\n",
308 fsf_req->qtcb->header.log_start,
309 sizeof(struct fsf_qtcb));
310 goto forget_log;
311 }
312 if ((size_t) (fsf_req->qtcb->header.log_start +
313 fsf_req->qtcb->header.log_length)
314 > sizeof(struct fsf_qtcb)) {
315 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
316 "beyond end of packet header. Ignored. "
317 "(start=%i, length=%i, size=%li)\n",
318 fsf_req->qtcb->header.log_start,
319 fsf_req->qtcb->header.log_length,
320 sizeof(struct fsf_qtcb));
321 goto forget_log;
322 }
323 ZFCP_LOG_TRACE("ULP log data: \n");
324 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
325 (char *) fsf_req->qtcb +
326 fsf_req->qtcb->header.log_start,
327 fsf_req->qtcb->header.log_length);
328 }
329 forget_log:
330
331 /* evaluate FSF Protocol Status */
332 switch (fsf_req->qtcb->prefix.prot_status) {
333
334 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 break;
337
338 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 ZFCP_LOG_NORMAL("error: The adapter %s contains "
340 "microcode of version 0x%x, the device driver "
341 "only supports 0x%x. Aborting.\n",
342 zfcp_get_busid_by_adapter(adapter),
343 fsf_req->qtcb->prefix.prot_status_qual.
344 version_error.fsf_version, ZFCP_QTCB_VERSION);
345 /* stop operation for this adapter */
346 debug_text_exception(adapter->erp_dbf, 0, "prot_ver_err");
347 zfcp_erp_adapter_shutdown(adapter, 0);
348 zfcp_cmd_dbf_event_fsf("qverserr", fsf_req,
349 &fsf_req->qtcb->prefix.prot_status_qual,
350 sizeof (union fsf_prot_status_qual));
351 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
352 break;
353
354 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
356 "driver (0x%x) and adapter %s (0x%x). "
357 "Restarting all operations on this adapter.\n",
358 fsf_req->qtcb->prefix.req_seq_no,
359 zfcp_get_busid_by_adapter(adapter),
360 fsf_req->qtcb->prefix.prot_status_qual.
361 sequence_error.exp_req_seq_no);
362 debug_text_exception(adapter->erp_dbf, 0, "prot_seq_err");
363 /* restart operation on this adapter */
364 zfcp_erp_adapter_reopen(adapter, 0);
365 zfcp_cmd_dbf_event_fsf("seqnoerr", fsf_req,
366 &fsf_req->qtcb->prefix.prot_status_qual,
367 sizeof (union fsf_prot_status_qual));
368 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
369 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
370 break;
371
372 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 ZFCP_LOG_NORMAL("error: Packet header type used by the "
374 "device driver is incompatible with "
375 "that used on adapter %s. "
376 "Stopping all operations on this adapter.\n",
377 zfcp_get_busid_by_adapter(adapter));
378 debug_text_exception(adapter->erp_dbf, 0, "prot_unsup_qtcb");
379 zfcp_erp_adapter_shutdown(adapter, 0);
380 zfcp_cmd_dbf_event_fsf("unsqtcbt", fsf_req,
381 &fsf_req->qtcb->prefix.prot_status_qual,
382 sizeof (union fsf_prot_status_qual));
383 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
384 break;
385
386 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 zfcp_cmd_dbf_event_fsf("hconinit", fsf_req,
388 &fsf_req->qtcb->prefix.prot_status_qual,
389 sizeof (union fsf_prot_status_qual));
390 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
391 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
392 &(adapter->status));
393 debug_text_event(adapter->erp_dbf, 3, "prot_con_init");
394 break;
395
396 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (fsf_req->qtcb) {
398 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
399 "to the adapter %s is ambiguous. "
400 "Stopping all operations on this "
401 "adapter.\n",
402 *(unsigned long long *)
403 (&fsf_req->qtcb->bottom.support.
404 req_handle),
405 zfcp_get_busid_by_adapter(adapter));
406 } else {
407 ZFCP_LOG_NORMAL("bug: The request identifier %p "
408 "to the adapter %s is ambiguous. "
409 "Stopping all operations on this "
410 "adapter. "
411 "(bug: got this for an unsolicited "
412 "status read request)\n",
413 fsf_req,
414 zfcp_get_busid_by_adapter(adapter));
415 }
416 debug_text_exception(adapter->erp_dbf, 0, "prot_dup_id");
417 zfcp_erp_adapter_shutdown(adapter, 0);
418 zfcp_cmd_dbf_event_fsf("dupreqid", fsf_req,
419 &fsf_req->qtcb->prefix.prot_status_qual,
420 sizeof (union fsf_prot_status_qual));
421 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
422 break;
423
424 case FSF_PROT_LINK_DOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 /*
426 * 'test and set' is not atomic here -
427 * it's ok as long as calls to our response queue handler
428 * (and thus execution of this code here) are serialized
429 * by the qdio module
430 */
431 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
432 &adapter->status)) {
433 switch (fsf_req->qtcb->prefix.prot_status_qual.
434 locallink_error.code) {
435 case FSF_PSQ_LINK_NOLIGHT:
436 ZFCP_LOG_INFO("The local link to adapter %s "
437 "is down (no light detected).\n",
438 zfcp_get_busid_by_adapter(
439 adapter));
440 break;
441 case FSF_PSQ_LINK_WRAPPLUG:
442 ZFCP_LOG_INFO("The local link to adapter %s "
443 "is down (wrap plug detected).\n",
444 zfcp_get_busid_by_adapter(
445 adapter));
446 break;
447 case FSF_PSQ_LINK_NOFCP:
448 ZFCP_LOG_INFO("The local link to adapter %s "
449 "is down (adjacent node on "
450 "link does not support FCP).\n",
451 zfcp_get_busid_by_adapter(
452 adapter));
453 break;
454 default:
455 ZFCP_LOG_INFO("The local link to adapter %s "
456 "is down "
457 "(warning: unknown reason "
458 "code).\n",
459 zfcp_get_busid_by_adapter(
460 adapter));
461 break;
462
463 }
464 /*
465 * Due to the 'erp failed' flag the adapter won't
466 * be recovered but will be just set to 'blocked'
467 * state. All subordinary devices will have state
468 * 'blocked' and 'erp failed', too.
469 * Thus the adapter is still able to provide
470 * 'link up' status without being flooded with
471 * requests.
472 * (note: even 'close port' is not permitted)
473 */
474 ZFCP_LOG_INFO("Stopping all operations for adapter "
475 "%s.\n",
476 zfcp_get_busid_by_adapter(adapter));
477 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
478 ZFCP_STATUS_COMMON_ERP_FAILED,
479 &adapter->status);
480 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
483 break;
484
485 case FSF_PROT_REEST_QUEUE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 debug_text_event(adapter->erp_dbf, 1, "prot_reest_queue");
487 ZFCP_LOG_INFO("The local link to adapter with "
488 "%s was re-plugged. "
489 "Re-starting operations on this adapter.\n",
490 zfcp_get_busid_by_adapter(adapter));
491 /* All ports should be marked as ready to run again */
492 zfcp_erp_modify_adapter_status(adapter,
493 ZFCP_STATUS_COMMON_RUNNING,
494 ZFCP_SET);
495 zfcp_erp_adapter_reopen(adapter,
496 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
497 | ZFCP_STATUS_COMMON_ERP_FAILED);
498 zfcp_cmd_dbf_event_fsf("reestque", fsf_req,
499 &fsf_req->qtcb->prefix.prot_status_qual,
500 sizeof (union fsf_prot_status_qual));
501 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
502 break;
503
504 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 ZFCP_LOG_NORMAL("error: The adapter %s "
506 "has entered the error state. "
507 "Restarting all operations on this "
508 "adapter.\n",
509 zfcp_get_busid_by_adapter(adapter));
510 debug_text_event(adapter->erp_dbf, 0, "prot_err_sta");
511 /* restart operation on this adapter */
512 zfcp_erp_adapter_reopen(adapter, 0);
513 zfcp_cmd_dbf_event_fsf("proterrs", fsf_req,
514 &fsf_req->qtcb->prefix.prot_status_qual,
515 sizeof (union fsf_prot_status_qual));
516 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
517 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
518 break;
519
520 default:
521 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
522 "provided by the adapter %s "
523 "is not compatible with the device driver. "
524 "Stopping all operations on this adapter. "
525 "(debug info 0x%x).\n",
526 zfcp_get_busid_by_adapter(adapter),
527 fsf_req->qtcb->prefix.prot_status);
528 debug_text_event(adapter->erp_dbf, 0, "prot_inval:");
529 debug_exception(adapter->erp_dbf, 0,
530 &fsf_req->qtcb->prefix.prot_status,
531 sizeof (u32));
532 zfcp_erp_adapter_shutdown(adapter, 0);
533 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
534 }
535
536 skip_protstatus:
537 /*
538 * always call specific handlers to give them a chance to do
539 * something meaningful even in error cases
540 */
541 zfcp_fsf_fsfstatus_eval(fsf_req);
542 return retval;
543}
544
545/*
546 * function: zfcp_fsf_fsfstatus_eval
547 *
548 * purpose: evaluates FSF status of completed FSF request
549 * and acts accordingly
550 *
551 * returns:
552 */
553static int
554zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
555{
556 int retval = 0;
557
558 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
559 goto skip_fsfstatus;
560 }
561
562 /* evaluate FSF Status */
563 switch (fsf_req->qtcb->header.fsf_status) {
564 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
566 "not known by the adapter %s "
567 "Stopping all operations on this adapter. "
568 "(debug info 0x%x).\n",
569 zfcp_get_busid_by_adapter(fsf_req->adapter),
570 fsf_req->qtcb->header.fsf_command);
571 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
572 "fsf_s_unknown");
573 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
574 zfcp_cmd_dbf_event_fsf("unknownc", fsf_req,
575 &fsf_req->qtcb->header.fsf_status_qual,
576 sizeof (union fsf_status_qual));
577 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
578 break;
579
580 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
582 "SCSI stack.\n");
583 debug_text_event(fsf_req->adapter->erp_dbf, 3, "fsf_s_rsp");
584 break;
585
586 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_astatus");
588 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
589 break;
590
591 default:
592 break;
593 }
594
595 skip_fsfstatus:
596 /*
597 * always call specific handlers to give them a chance to do
598 * something meaningful even in error cases
599 */
600 zfcp_fsf_req_dispatch(fsf_req);
601
602 return retval;
603}
604
605/*
606 * function: zfcp_fsf_fsfstatus_qual_eval
607 *
608 * purpose: evaluates FSF status-qualifier of completed FSF request
609 * and acts accordingly
610 *
611 * returns:
612 */
613static int
614zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
615{
616 int retval = 0;
617
618 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
619 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 debug_text_event(fsf_req->adapter->erp_dbf, 4, "fsf_sq_rsp");
621 break;
622 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* The SCSI-stack may now issue retries or escalate */
624 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_retry");
625 zfcp_cmd_dbf_event_fsf("sqretry", fsf_req,
626 &fsf_req->qtcb->header.fsf_status_qual,
627 sizeof (union fsf_status_qual));
628 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
629 break;
630 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* Carry the aborted state on to upper layer */
632 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_abort");
633 zfcp_cmd_dbf_event_fsf("sqabort", fsf_req,
634 &fsf_req->qtcb->header.fsf_status_qual,
635 sizeof (union fsf_status_qual));
636 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
637 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
638 break;
639 case FSF_SQ_NO_RECOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
641 "fsf_sq_no_rec");
642 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
643 "problem on the adapter %s "
644 "Stopping all operations on this adapter. ",
645 zfcp_get_busid_by_adapter(fsf_req->adapter));
646 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
647 zfcp_cmd_dbf_event_fsf("sqnrecom", fsf_req,
648 &fsf_req->qtcb->header.fsf_status_qual,
649 sizeof (union fsf_status_qual));
650 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
651 break;
652 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
654 "(adapter %s)\n",
655 zfcp_get_busid_by_adapter(fsf_req->adapter));
656 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
657 "fsf_sq_ulp_err");
658 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
659 break;
660 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
661 case FSF_SQ_NO_RETRY_POSSIBLE:
662 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
663 /* dealt with in the respective functions */
664 break;
665 default:
666 ZFCP_LOG_NORMAL("bug: Additional status info could "
667 "not be interpreted properly.\n");
668 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
669 (char *) &fsf_req->qtcb->header.fsf_status_qual,
670 sizeof (union fsf_status_qual));
671 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval:");
672 debug_exception(fsf_req->adapter->erp_dbf, 0,
673 &fsf_req->qtcb->header.fsf_status_qual.word[0],
674 sizeof (u32));
675 zfcp_cmd_dbf_event_fsf("squndef", fsf_req,
676 &fsf_req->qtcb->header.fsf_status_qual,
677 sizeof (union fsf_status_qual));
678 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
679 break;
680 }
681
682 return retval;
683}
684
685/*
686 * function: zfcp_fsf_req_dispatch
687 *
688 * purpose: calls the appropriate command specific handler
689 *
690 * returns:
691 */
692static int
693zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
694{
695 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
696 struct zfcp_adapter *adapter = fsf_req->adapter;
697 int retval = 0;
698
699 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
700 ZFCP_LOG_TRACE("fsf_req=%p, QTCB=%p\n", fsf_req, fsf_req->qtcb);
701 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
702 (char *) fsf_req->qtcb, sizeof(struct fsf_qtcb));
703 }
704
705 switch (fsf_req->fsf_command) {
706
707 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 zfcp_fsf_send_fcp_command_handler(fsf_req);
709 break;
710
711 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 zfcp_fsf_abort_fcp_command_handler(fsf_req);
713 break;
714
715 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 zfcp_fsf_send_ct_handler(fsf_req);
717 break;
718
719 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 zfcp_fsf_open_port_handler(fsf_req);
721 break;
722
723 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 zfcp_fsf_open_unit_handler(fsf_req);
725 break;
726
727 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 zfcp_fsf_close_unit_handler(fsf_req);
729 break;
730
731 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 zfcp_fsf_close_port_handler(fsf_req);
733 break;
734
735 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 zfcp_fsf_close_physical_port_handler(fsf_req);
737 break;
738
739 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 zfcp_fsf_exchange_config_data_handler(fsf_req);
741 break;
742
743 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 zfcp_fsf_exchange_port_data_handler(fsf_req);
745 break;
746
747 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 zfcp_fsf_send_els_handler(fsf_req);
749 break;
750
751 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 zfcp_fsf_control_file_handler(fsf_req);
753 break;
754
755 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 zfcp_fsf_control_file_handler(fsf_req);
757 break;
758
759 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
761 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
762 "not supported by the adapter %s\n",
763 zfcp_get_busid_by_adapter(fsf_req->adapter));
764 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
765 ZFCP_LOG_NORMAL
766 ("bug: Command issued by the device driver differs "
767 "from the command returned by the adapter %s "
768 "(debug info 0x%x, 0x%x).\n",
769 zfcp_get_busid_by_adapter(fsf_req->adapter),
770 fsf_req->fsf_command,
771 fsf_req->qtcb->header.fsf_command);
772 }
773
774 if (!erp_action)
775 return retval;
776
777 debug_text_event(adapter->erp_dbf, 3, "a_frh");
778 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
779 zfcp_erp_async_handler(erp_action, 0);
780
781 return retval;
782}
783
784/*
785 * function: zfcp_fsf_status_read
786 *
787 * purpose: initiates a Status Read command at the specified adapter
788 *
789 * returns:
790 */
791int
792zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
793{
794 struct zfcp_fsf_req *fsf_req;
795 struct fsf_status_read_buffer *status_buffer;
796 unsigned long lock_flags;
797 volatile struct qdio_buffer_element *sbale;
798 int retval = 0;
799
800 /* setup new FSF request */
801 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
802 req_flags | ZFCP_REQ_NO_QTCB,
803 adapter->pool.fsf_req_status_read,
804 &lock_flags, &fsf_req);
805 if (retval < 0) {
806 ZFCP_LOG_INFO("error: Could not create unsolicited status "
807 "buffer for adapter %s.\n",
808 zfcp_get_busid_by_adapter(adapter));
809 goto failed_req_create;
810 }
811
812 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
813 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
814 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
815 fsf_req->sbale_curr = 2;
816
817 status_buffer =
818 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
819 if (!status_buffer) {
820 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
821 goto failed_buf;
822 }
823 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
824 fsf_req->data.status_read.buffer = status_buffer;
825
826 /* insert pointer to respective buffer */
827 sbale = zfcp_qdio_sbale_curr(fsf_req);
828 sbale->addr = (void *) status_buffer;
829 sbale->length = sizeof(struct fsf_status_read_buffer);
830
831 /* start QDIO request for this FSF request */
832 retval = zfcp_fsf_req_send(fsf_req, NULL);
833 if (retval) {
834 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
835 "environment.\n");
836 goto failed_req_send;
837 }
838
839 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
840 zfcp_get_busid_by_adapter(adapter));
841 goto out;
842
843 failed_req_send:
844 mempool_free(status_buffer, adapter->pool.data_status_read);
845
846 failed_buf:
847 zfcp_fsf_req_free(fsf_req);
848 failed_req_create:
849 out:
850 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
851 return retval;
852}
853
854static int
855zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
856{
857 struct fsf_status_read_buffer *status_buffer;
858 struct zfcp_adapter *adapter;
859 struct zfcp_port *port;
860 unsigned long flags;
861
862 status_buffer = fsf_req->data.status_read.buffer;
863 adapter = fsf_req->adapter;
864
865 read_lock_irqsave(&zfcp_data.config_lock, flags);
866 list_for_each_entry(port, &adapter->port_list_head, list)
867 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
868 break;
869 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
870
871 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
872 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
873 "nonexisting port with d_id 0x%08x on "
874 "adapter %s. Ignored.\n",
875 status_buffer->d_id & ZFCP_DID_MASK,
876 zfcp_get_busid_by_adapter(adapter));
877 goto out;
878 }
879
880 switch (status_buffer->status_subtype) {
881
882 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
884 zfcp_erp_port_reopen(port, 0);
885 break;
886
887 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
889 zfcp_erp_port_shutdown(port, 0);
890 break;
891
892 default:
893 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
894 debug_exception(adapter->erp_dbf, 0,
895 &status_buffer->status_subtype, sizeof (u32));
896 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
897 "for a reopen indication on port with "
898 "d_id 0x%08x on the adapter %s. "
899 "Ignored. (debug info 0x%x)\n",
900 status_buffer->d_id,
901 zfcp_get_busid_by_adapter(adapter),
902 status_buffer->status_subtype);
903 }
904 out:
905 return 0;
906}
907
908/*
909 * function: zfcp_fsf_status_read_handler
910 *
911 * purpose: is called for finished Open Port command
912 *
913 * returns:
914 */
915static int
916zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
917{
918 int retval = 0;
919 struct zfcp_adapter *adapter = fsf_req->adapter;
920 struct fsf_status_read_buffer *status_buffer =
921 fsf_req->data.status_read.buffer;
922
923 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
924 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200925 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 goto out;
927 }
928
929 switch (status_buffer->status_type) {
930
931 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 debug_text_event(adapter->erp_dbf, 3, "unsol_pclosed:");
933 debug_event(adapter->erp_dbf, 3,
934 &status_buffer->d_id, sizeof (u32));
935 zfcp_fsf_status_read_port_closed(fsf_req);
936 break;
937
938 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 debug_text_event(adapter->erp_dbf, 3, "unsol_els:");
940 zfcp_fsf_incoming_els(fsf_req);
941 break;
942
943 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 debug_text_event(adapter->erp_dbf, 3, "unsol_sense:");
945 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
946 zfcp_get_busid_by_adapter(adapter));
947 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, (char *) status_buffer,
948 sizeof(struct fsf_status_read_buffer));
949 break;
950
951 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 debug_text_event(adapter->erp_dbf, 3, "unsol_bit_err:");
953 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
954 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
955 (char *) status_buffer,
956 sizeof (struct fsf_status_read_buffer));
957 break;
958
959 case FSF_STATUS_READ_LINK_DOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 debug_text_event(adapter->erp_dbf, 0, "unsol_link_down:");
961 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
962 zfcp_get_busid_by_adapter(adapter));
963 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
964 &adapter->status);
965 zfcp_erp_adapter_failed(adapter);
966 break;
967
968 case FSF_STATUS_READ_LINK_UP:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 debug_text_event(adapter->erp_dbf, 2, "unsol_link_up:");
970 ZFCP_LOG_INFO("Local link to adapter %s was replugged. "
971 "Restarting operations on this adapter\n",
972 zfcp_get_busid_by_adapter(adapter));
973 /* All ports should be marked as ready to run again */
974 zfcp_erp_modify_adapter_status(adapter,
975 ZFCP_STATUS_COMMON_RUNNING,
976 ZFCP_SET);
977 zfcp_erp_adapter_reopen(adapter,
978 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
979 | ZFCP_STATUS_COMMON_ERP_FAILED);
980 break;
981
982 case FSF_STATUS_READ_CFDC_UPDATED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_update:");
984 ZFCP_LOG_INFO("CFDC has been updated on the adapter %s\n",
985 zfcp_get_busid_by_adapter(adapter));
986 zfcp_erp_adapter_access_changed(adapter);
987 break;
988
989 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_harden:");
991 switch (status_buffer->status_subtype) {
992 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
993 ZFCP_LOG_INFO("CFDC of adapter %s saved on SE\n",
994 zfcp_get_busid_by_adapter(adapter));
995 break;
996 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
997 ZFCP_LOG_INFO("CFDC of adapter %s has been copied "
998 "to the secondary SE\n",
999 zfcp_get_busid_by_adapter(adapter));
1000 break;
1001 default:
1002 ZFCP_LOG_INFO("CFDC of adapter %s has been hardened\n",
1003 zfcp_get_busid_by_adapter(adapter));
1004 }
1005 break;
1006
1007 default:
1008 debug_text_event(adapter->erp_dbf, 0, "unsol_unknown:");
1009 debug_exception(adapter->erp_dbf, 0,
1010 &status_buffer->status_type, sizeof (u32));
1011 ZFCP_LOG_NORMAL("bug: An unsolicited status packet of unknown "
1012 "type was received (debug info 0x%x)\n",
1013 status_buffer->status_type);
1014 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1015 status_buffer);
1016 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1017 (char *) status_buffer,
1018 sizeof (struct fsf_status_read_buffer));
1019 break;
1020 }
1021 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001022 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 /*
1024 * recycle buffer and start new request repeat until outbound
1025 * queue is empty or adapter shutdown is requested
1026 */
1027 /*
1028 * FIXME(qdio):
1029 * we may wait in the req_create for 5s during shutdown, so
1030 * qdio_cleanup will have to wait at least that long before returning
1031 * with failure to allow us a proper cleanup under all circumstances
1032 */
1033 /*
1034 * FIXME:
1035 * allocation failure possible? (Is this code needed?)
1036 */
1037 retval = zfcp_fsf_status_read(adapter, 0);
1038 if (retval < 0) {
1039 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1040 "request for the adapter %s.\n",
1041 zfcp_get_busid_by_adapter(adapter));
1042 /* temporary fix to avoid status read buffer shortage */
1043 adapter->status_read_failed++;
1044 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1045 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1046 ZFCP_LOG_INFO("restart adapter %s due to status read "
1047 "buffer shortage\n",
1048 zfcp_get_busid_by_adapter(adapter));
1049 zfcp_erp_adapter_reopen(adapter, 0);
1050 }
1051 }
1052 out:
1053 return retval;
1054}
1055
1056/*
1057 * function: zfcp_fsf_abort_fcp_command
1058 *
1059 * purpose: tells FSF to abort a running SCSI command
1060 *
1061 * returns: address of initiated FSF request
1062 * NULL - request could not be initiated
1063 *
1064 * FIXME(design): should be watched by a timeout !!!
1065 * FIXME(design) shouldn't this be modified to return an int
1066 * also...don't know how though
1067 */
1068struct zfcp_fsf_req *
1069zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1070 struct zfcp_adapter *adapter,
1071 struct zfcp_unit *unit, int req_flags)
1072{
1073 volatile struct qdio_buffer_element *sbale;
1074 unsigned long lock_flags;
1075 struct zfcp_fsf_req *fsf_req = NULL;
1076 int retval = 0;
1077
1078 /* setup new FSF request */
1079 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1080 req_flags, adapter->pool.fsf_req_abort,
1081 &lock_flags, &fsf_req);
1082 if (retval < 0) {
1083 ZFCP_LOG_INFO("error: Failed to create an abort command "
1084 "request for lun 0x%016Lx on port 0x%016Lx "
1085 "on adapter %s.\n",
1086 unit->fcp_lun,
1087 unit->port->wwpn,
1088 zfcp_get_busid_by_adapter(adapter));
1089 goto out;
1090 }
1091
1092 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1093 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1094 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1095
1096 fsf_req->data.abort_fcp_command.unit = unit;
1097
1098 /* set handles of unit and its parent port in QTCB */
1099 fsf_req->qtcb->header.lun_handle = unit->handle;
1100 fsf_req->qtcb->header.port_handle = unit->port->handle;
1101
1102 /* set handle of request which should be aborted */
1103 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1104
1105 /* start QDIO request for this FSF request */
1106
1107 zfcp_fsf_start_scsi_er_timer(adapter);
1108 retval = zfcp_fsf_req_send(fsf_req, NULL);
1109 if (retval) {
1110 del_timer(&adapter->scsi_er_timer);
1111 ZFCP_LOG_INFO("error: Failed to send abort command request "
1112 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1113 zfcp_get_busid_by_adapter(adapter),
1114 unit->port->wwpn, unit->fcp_lun);
1115 zfcp_fsf_req_free(fsf_req);
1116 fsf_req = NULL;
1117 goto out;
1118 }
1119
1120 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1121 "(adapter%s, port d_id=0x%08x, "
1122 "unit x%016Lx, old_req_id=0x%lx)\n",
1123 zfcp_get_busid_by_adapter(adapter),
1124 unit->port->d_id,
1125 unit->fcp_lun, old_req_id);
1126 out:
1127 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1128 return fsf_req;
1129}
1130
1131/*
1132 * function: zfcp_fsf_abort_fcp_command_handler
1133 *
1134 * purpose: is called for finished Abort FCP Command request
1135 *
1136 * returns:
1137 */
1138static int
1139zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1140{
1141 int retval = -EINVAL;
1142 struct zfcp_unit *unit = new_fsf_req->data.abort_fcp_command.unit;
1143 unsigned char status_qual =
1144 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1145
1146 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1147
1148 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1149 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1150 goto skip_fsfstatus;
1151 }
1152
1153 /* evaluate FSF status in QTCB */
1154 switch (new_fsf_req->qtcb->header.fsf_status) {
1155
1156 case FSF_PORT_HANDLE_NOT_VALID:
1157 if (status_qual >> 4 != status_qual % 0xf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1159 "fsf_s_phand_nv0");
1160 /*
1161 * In this case a command that was sent prior to a port
1162 * reopen was aborted (handles are different). This is
1163 * fine.
1164 */
1165 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1167 "port 0x%016Lx on adapter %s invalid. "
1168 "This may happen occasionally.\n",
1169 unit->port->handle,
1170 unit->port->wwpn,
1171 zfcp_get_busid_by_unit(unit));
1172 ZFCP_LOG_INFO("status qualifier:\n");
1173 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1174 (char *) &new_fsf_req->qtcb->header.
1175 fsf_status_qual,
1176 sizeof (union fsf_status_qual));
1177 /* Let's hope this sorts out the mess */
1178 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1179 "fsf_s_phand_nv1");
1180 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1181 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1182 }
1183 break;
1184
1185 case FSF_LUN_HANDLE_NOT_VALID:
1186 if (status_qual >> 4 != status_qual % 0xf) {
1187 /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1189 "fsf_s_lhand_nv0");
1190 /*
1191 * In this case a command that was sent prior to a unit
1192 * reopen was aborted (handles are different).
1193 * This is fine.
1194 */
1195 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 ZFCP_LOG_INFO
1197 ("Warning: Temporary LUN identifier 0x%x of LUN "
1198 "0x%016Lx on port 0x%016Lx on adapter %s is "
1199 "invalid. This may happen in rare cases. "
1200 "Trying to re-establish link.\n",
1201 unit->handle,
1202 unit->fcp_lun,
1203 unit->port->wwpn,
1204 zfcp_get_busid_by_unit(unit));
1205 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1206 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1207 (char *) &new_fsf_req->qtcb->header.
1208 fsf_status_qual,
1209 sizeof (union fsf_status_qual));
1210 /* Let's hope this sorts out the mess */
1211 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1212 "fsf_s_lhand_nv1");
1213 zfcp_erp_port_reopen(unit->port, 0);
1214 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1215 }
1216 break;
1217
1218 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 retval = 0;
1220 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1221 "fsf_s_no_exist");
1222 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1223 break;
1224
1225 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1227 "be reopened\n", unit->port->wwpn,
1228 zfcp_get_busid_by_unit(unit));
1229 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1230 "fsf_s_pboxed");
1231 zfcp_erp_port_reopen(unit->port, 0);
1232 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1233 | ZFCP_STATUS_FSFREQ_RETRY;
1234 break;
1235
1236 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 ZFCP_LOG_INFO(
1238 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1239 "to be reopened\n",
1240 unit->fcp_lun, unit->port->wwpn,
1241 zfcp_get_busid_by_unit(unit));
1242 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1243 zfcp_erp_unit_reopen(unit, 0);
1244 zfcp_cmd_dbf_event_fsf("unitbox", new_fsf_req,
1245 &new_fsf_req->qtcb->header.fsf_status_qual,
1246 sizeof(union fsf_status_qual));
1247 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1248 | ZFCP_STATUS_FSFREQ_RETRY;
1249 break;
1250
1251 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1253 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1255 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001256 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1258 break;
1259 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 /* SCSI stack will escalate */
1261 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1262 "fsf_sq_ulp");
1263 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1264 break;
1265 default:
1266 ZFCP_LOG_NORMAL
1267 ("bug: Wrong status qualifier 0x%x arrived.\n",
1268 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1269 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1270 "fsf_sq_inval:");
1271 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1272 &new_fsf_req->qtcb->header.
1273 fsf_status_qual.word[0], sizeof (u32));
1274 break;
1275 }
1276 break;
1277
1278 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 retval = 0;
1280 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1281 break;
1282
1283 default:
1284 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1285 "(debug info 0x%x)\n",
1286 new_fsf_req->qtcb->header.fsf_status);
1287 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1288 "fsf_s_inval:");
1289 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1290 &new_fsf_req->qtcb->header.fsf_status,
1291 sizeof (u32));
1292 break;
1293 }
1294 skip_fsfstatus:
1295 return retval;
1296}
1297
1298/**
1299 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1300 * one SBALE
1301 * Two scatter-gather lists are passed, one for the reqeust and one for the
1302 * response.
1303 */
1304static inline int
1305zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1306 struct scatterlist *resp, int resp_count)
1307{
1308 return ((req_count == 1) &&
1309 (resp_count == 1) &&
1310 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1311 PAGE_MASK) ==
1312 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1313 req[0].length - 1) & PAGE_MASK)) &&
1314 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1315 PAGE_MASK) ==
1316 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1317 resp[0].length - 1) & PAGE_MASK)));
1318}
1319
1320/**
1321 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1322 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1323 * the request
1324 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1325 * a struct zfcp_fsf_req
1326 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1327 * is sent within error recovery
1328 */
1329int
1330zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1331 struct zfcp_erp_action *erp_action)
1332{
1333 volatile struct qdio_buffer_element *sbale;
1334 struct zfcp_port *port;
1335 struct zfcp_adapter *adapter;
1336 struct zfcp_fsf_req *fsf_req;
1337 unsigned long lock_flags;
1338 int bytes;
1339 int ret = 0;
1340
1341 port = ct->port;
1342 adapter = port->adapter;
1343
1344 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1345 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1346 pool, &lock_flags, &fsf_req);
1347 if (ret < 0) {
1348 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1349 "adapter: %s\n",
1350 zfcp_get_busid_by_adapter(adapter));
1351 goto failed_req;
1352 }
1353
1354 if (erp_action != NULL) {
1355 erp_action->fsf_req = fsf_req;
1356 fsf_req->erp_action = erp_action;
1357 }
1358
1359 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1360 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1361 ct->resp, ct->resp_count)){
1362 /* both request buffer and response buffer
1363 fit into one sbale each */
1364 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1365 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1366 sbale[2].length = ct->req[0].length;
1367 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1368 sbale[3].length = ct->resp[0].length;
1369 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1370 } else if (adapter->supported_features &
1371 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1372 /* try to use chained SBALs */
1373 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1374 SBAL_FLAGS0_TYPE_WRITE_READ,
1375 ct->req, ct->req_count,
1376 ZFCP_MAX_SBALS_PER_CT_REQ);
1377 if (bytes <= 0) {
1378 ZFCP_LOG_INFO("error: creation of CT request failed "
1379 "on adapter %s\n",
1380 zfcp_get_busid_by_adapter(adapter));
1381 if (bytes == 0)
1382 ret = -ENOMEM;
1383 else
1384 ret = bytes;
1385
1386 goto failed_send;
1387 }
1388 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1389 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1390 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1391 SBAL_FLAGS0_TYPE_WRITE_READ,
1392 ct->resp, ct->resp_count,
1393 ZFCP_MAX_SBALS_PER_CT_REQ);
1394 if (bytes <= 0) {
1395 ZFCP_LOG_INFO("error: creation of CT request failed "
1396 "on adapter %s\n",
1397 zfcp_get_busid_by_adapter(adapter));
1398 if (bytes == 0)
1399 ret = -ENOMEM;
1400 else
1401 ret = bytes;
1402
1403 goto failed_send;
1404 }
1405 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1406 } else {
1407 /* reject send generic request */
1408 ZFCP_LOG_INFO(
1409 "error: microcode does not support chained SBALs,"
1410 "CT request too big (adapter %s)\n",
1411 zfcp_get_busid_by_adapter(adapter));
1412 ret = -EOPNOTSUPP;
1413 goto failed_send;
1414 }
1415
1416 /* settings in QTCB */
1417 fsf_req->qtcb->header.port_handle = port->handle;
1418 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1419 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1420 fsf_req->data.send_ct = ct;
1421
1422 /* start QDIO request for this FSF request */
1423 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1424 if (ret) {
1425 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1426 "(adapter %s, port 0x%016Lx)\n",
1427 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1428 goto failed_send;
1429 }
1430
1431 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1432 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1433 goto out;
1434
1435 failed_send:
1436 zfcp_fsf_req_free(fsf_req);
1437 if (erp_action != NULL) {
1438 erp_action->fsf_req = NULL;
1439 }
1440 failed_req:
1441 out:
1442 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1443 lock_flags);
1444 return ret;
1445}
1446
1447/**
1448 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1449 * @fsf_req: pointer to struct zfcp_fsf_req
1450 *
1451 * Data specific for the Generic Service request is passed by
1452 * fsf_req->data.send_ct
1453 * Usually a specific handler for the request is called via
1454 * fsf_req->data.send_ct->handler at end of this function.
1455 */
1456static int
1457zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1458{
1459 struct zfcp_port *port;
1460 struct zfcp_adapter *adapter;
1461 struct zfcp_send_ct *send_ct;
1462 struct fsf_qtcb_header *header;
1463 struct fsf_qtcb_bottom_support *bottom;
1464 int retval = -EINVAL;
1465 u16 subtable, rule, counter;
1466
1467 adapter = fsf_req->adapter;
1468 send_ct = fsf_req->data.send_ct;
1469 port = send_ct->port;
1470 header = &fsf_req->qtcb->header;
1471 bottom = &fsf_req->qtcb->bottom.support;
1472
1473 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1474 goto skip_fsfstatus;
1475
1476 /* evaluate FSF status in QTCB */
1477 switch (header->fsf_status) {
1478
1479 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 retval = 0;
1481 break;
1482
1483 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 if (adapter->fc_service_class <= 3) {
1485 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1486 "class %d.\n",
1487 zfcp_get_busid_by_port(port),
1488 adapter->fc_service_class);
1489 } else {
1490 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1491 "adapter %s is invalid. "
1492 "(debug info %d)\n",
1493 zfcp_get_busid_by_port(port),
1494 adapter->fc_service_class);
1495 }
1496 /* stop operation for this adapter */
1497 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1498 zfcp_erp_adapter_shutdown(adapter, 0);
1499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1500 break;
1501
1502 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 switch (header->fsf_status_qual.word[0]){
1504 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 /* reopening link to port */
1506 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1507 zfcp_test_link(port);
1508 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1509 break;
1510 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 /* ERP strategy will escalate */
1512 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1513 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1514 break;
1515 default:
1516 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1517 "arrived.\n",
1518 header->fsf_status_qual.word[0]);
1519 break;
1520 }
1521 break;
1522
1523 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1525 "command (adapter %s, port d_id=0x%08x)\n",
1526 zfcp_get_busid_by_port(port), port->d_id);
1527 for (counter = 0; counter < 2; counter++) {
1528 subtable = header->fsf_status_qual.halfword[counter * 2];
1529 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1530 switch (subtable) {
1531 case FSF_SQ_CFDC_SUBTABLE_OS:
1532 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1533 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1534 case FSF_SQ_CFDC_SUBTABLE_LUN:
1535 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1536 zfcp_act_subtable_type[subtable], rule);
1537 break;
1538 }
1539 }
1540 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1541 zfcp_erp_port_access_denied(port);
1542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1543 break;
1544
1545 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 ZFCP_LOG_INFO("generic service command rejected "
1547 "(adapter %s, port d_id=0x%08x)\n",
1548 zfcp_get_busid_by_port(port), port->d_id);
1549 ZFCP_LOG_INFO("status qualifier:\n");
1550 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1551 (char *) &header->fsf_status_qual,
1552 sizeof (union fsf_status_qual));
1553 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1555 break;
1556
1557 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1559 "0x%016Lx on adapter %s invalid. This may "
1560 "happen occasionally.\n", port->handle,
1561 port->wwpn, zfcp_get_busid_by_port(port));
1562 ZFCP_LOG_INFO("status qualifier:\n");
1563 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1564 (char *) &header->fsf_status_qual,
1565 sizeof (union fsf_status_qual));
1566 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1567 zfcp_erp_adapter_reopen(adapter, 0);
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1569 break;
1570
1571 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 ZFCP_LOG_INFO("port needs to be reopened "
1573 "(adapter %s, port d_id=0x%08x)\n",
1574 zfcp_get_busid_by_port(port), port->d_id);
1575 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1576 zfcp_erp_port_reopen(port, 0);
1577 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1578 | ZFCP_STATUS_FSFREQ_RETRY;
1579 break;
1580
1581 /* following states should never occure, all cases avoided
1582 in zfcp_fsf_send_ct - but who knows ... */
1583 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1585 "req_buf_length=%d, resp_buf_length=%d)\n",
1586 zfcp_get_busid_by_adapter(adapter),
1587 bottom->req_buf_length, bottom->resp_buf_length);
1588 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1589 break;
1590 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1592 "req_buf_length=%d)\n",
1593 zfcp_get_busid_by_adapter(adapter),
1594 bottom->req_buf_length);
1595 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1596 break;
1597 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1599 "resp_buf_length=%d)\n",
1600 zfcp_get_busid_by_adapter(adapter),
1601 bottom->resp_buf_length);
1602 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1603 break;
1604 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1606 "resp_buf_length=%d)\n",
1607 zfcp_get_busid_by_adapter(adapter),
1608 bottom->req_buf_length, bottom->resp_buf_length);
1609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1610 break;
1611
1612 default:
1613 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1614 "(debug info 0x%x)\n", header->fsf_status);
1615 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1616 debug_exception(adapter->erp_dbf, 0,
1617 &header->fsf_status_qual.word[0], sizeof (u32));
1618 break;
1619 }
1620
1621skip_fsfstatus:
1622 send_ct->status = retval;
1623
1624 if (send_ct->handler != NULL)
1625 send_ct->handler(send_ct->handler_data);
1626
1627 return retval;
1628}
1629
1630/**
1631 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1632 * @els: pointer to struct zfcp_send_els which contains all needed data for
1633 * the command.
1634 */
1635int
1636zfcp_fsf_send_els(struct zfcp_send_els *els)
1637{
1638 volatile struct qdio_buffer_element *sbale;
1639 struct zfcp_fsf_req *fsf_req;
1640 fc_id_t d_id;
1641 struct zfcp_adapter *adapter;
1642 unsigned long lock_flags;
1643 int bytes;
1644 int ret = 0;
1645
1646 d_id = els->d_id;
1647 adapter = els->adapter;
1648
1649 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1650 ZFCP_REQ_AUTO_CLEANUP,
1651 NULL, &lock_flags, &fsf_req);
1652 if (ret < 0) {
1653 ZFCP_LOG_INFO("error: creation of ELS request failed "
1654 "(adapter %s, port d_id: 0x%08x)\n",
1655 zfcp_get_busid_by_adapter(adapter), d_id);
1656 goto failed_req;
1657 }
1658
1659 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1660 if (zfcp_use_one_sbal(els->req, els->req_count,
1661 els->resp, els->resp_count)){
1662 /* both request buffer and response buffer
1663 fit into one sbale each */
1664 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1665 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1666 sbale[2].length = els->req[0].length;
1667 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1668 sbale[3].length = els->resp[0].length;
1669 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1670 } else if (adapter->supported_features &
1671 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1672 /* try to use chained SBALs */
1673 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1674 SBAL_FLAGS0_TYPE_WRITE_READ,
1675 els->req, els->req_count,
1676 ZFCP_MAX_SBALS_PER_ELS_REQ);
1677 if (bytes <= 0) {
1678 ZFCP_LOG_INFO("error: creation of ELS request failed "
1679 "(adapter %s, port d_id: 0x%08x)\n",
1680 zfcp_get_busid_by_adapter(adapter), d_id);
1681 if (bytes == 0) {
1682 ret = -ENOMEM;
1683 } else {
1684 ret = bytes;
1685 }
1686 goto failed_send;
1687 }
1688 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1689 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1690 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1691 SBAL_FLAGS0_TYPE_WRITE_READ,
1692 els->resp, els->resp_count,
1693 ZFCP_MAX_SBALS_PER_ELS_REQ);
1694 if (bytes <= 0) {
1695 ZFCP_LOG_INFO("error: creation of ELS request failed "
1696 "(adapter %s, port d_id: 0x%08x)\n",
1697 zfcp_get_busid_by_adapter(adapter), d_id);
1698 if (bytes == 0) {
1699 ret = -ENOMEM;
1700 } else {
1701 ret = bytes;
1702 }
1703 goto failed_send;
1704 }
1705 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1706 } else {
1707 /* reject request */
1708 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1709 ", ELS request too big (adapter %s, "
1710 "port d_id: 0x%08x)\n",
1711 zfcp_get_busid_by_adapter(adapter), d_id);
1712 ret = -EOPNOTSUPP;
1713 goto failed_send;
1714 }
1715
1716 /* settings in QTCB */
1717 fsf_req->qtcb->bottom.support.d_id = d_id;
1718 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1719 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1720 fsf_req->data.send_els = els;
1721
1722 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1723
1724 /* start QDIO request for this FSF request */
1725 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1726 if (ret) {
1727 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1728 "(adapter %s, port d_id: 0x%08x)\n",
1729 zfcp_get_busid_by_adapter(adapter), d_id);
1730 goto failed_send;
1731 }
1732
1733 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1734 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1735 goto out;
1736
1737 failed_send:
1738 zfcp_fsf_req_free(fsf_req);
1739
1740 failed_req:
1741 out:
1742 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1743 lock_flags);
1744
1745 return ret;
1746}
1747
1748/**
1749 * zfcp_fsf_send_els_handler - handler for ELS commands
1750 * @fsf_req: pointer to struct zfcp_fsf_req
1751 *
1752 * Data specific for the ELS command is passed by
1753 * fsf_req->data.send_els
1754 * Usually a specific handler for the command is called via
1755 * fsf_req->data.send_els->handler at end of this function.
1756 */
1757static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1758{
1759 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 struct zfcp_port *port;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001761 fc_id_t d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 struct fsf_qtcb_header *header;
1763 struct fsf_qtcb_bottom_support *bottom;
1764 struct zfcp_send_els *send_els;
1765 int retval = -EINVAL;
1766 u16 subtable, rule, counter;
1767
1768 send_els = fsf_req->data.send_els;
1769 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001770 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 d_id = send_els->d_id;
1772 header = &fsf_req->qtcb->header;
1773 bottom = &fsf_req->qtcb->bottom.support;
1774
1775 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1776 goto skip_fsfstatus;
1777
1778 switch (header->fsf_status) {
1779
1780 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 retval = 0;
1782 break;
1783
1784 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 if (adapter->fc_service_class <= 3) {
1786 ZFCP_LOG_INFO("error: adapter %s does "
1787 "not support fibrechannel class %d.\n",
1788 zfcp_get_busid_by_adapter(adapter),
1789 adapter->fc_service_class);
1790 } else {
1791 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1792 "adapter %s is invalid. "
1793 "(debug info %d)\n",
1794 zfcp_get_busid_by_adapter(adapter),
1795 adapter->fc_service_class);
1796 }
1797 /* stop operation for this adapter */
1798 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1799 zfcp_erp_adapter_shutdown(adapter, 0);
1800 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1801 break;
1802
1803 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 switch (header->fsf_status_qual.word[0]){
1805 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001807 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1808 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1810 break;
1811 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1813 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1814 retval =
1815 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1816 (struct zfcp_ls_rjt_par *)
1817 &header->fsf_status_qual.word[2]);
1818 break;
1819 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1821 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1822 break;
1823 default:
1824 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1825 header->fsf_status_qual.word[0]);
1826 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1827 (char*)header->fsf_status_qual.word, 16);
1828 }
1829 break;
1830
1831 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1833 "prohibited sending "
1834 "(adapter: %s, port d_id: 0x%08x)\n",
1835 zfcp_get_busid_by_adapter(adapter), d_id);
1836
1837 break;
1838
1839 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 ZFCP_LOG_INFO(
1841 "ELS request size and ELS response size must be either "
1842 "both 0, or both greater than 0 "
1843 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1844 zfcp_get_busid_by_adapter(adapter),
1845 bottom->req_buf_length,
1846 bottom->resp_buf_length);
1847 break;
1848
1849 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 ZFCP_LOG_INFO(
1851 "Length of the ELS request buffer, "
1852 "specified in QTCB bottom, "
1853 "exceeds the size of the buffers "
1854 "that have been allocated for ELS request data "
1855 "(adapter: %s, req_buf_length=%d)\n",
1856 zfcp_get_busid_by_adapter(adapter),
1857 bottom->req_buf_length);
1858 break;
1859
1860 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 ZFCP_LOG_INFO(
1862 "Length of the ELS response buffer, "
1863 "specified in QTCB bottom, "
1864 "exceeds the size of the buffers "
1865 "that have been allocated for ELS response data "
1866 "(adapter: %s, resp_buf_length=%d)\n",
1867 zfcp_get_busid_by_adapter(adapter),
1868 bottom->resp_buf_length);
1869 break;
1870
1871 case FSF_SBAL_MISMATCH:
1872 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1874 "resp_buf_length=%d)\n",
1875 zfcp_get_busid_by_adapter(adapter),
1876 bottom->req_buf_length, bottom->resp_buf_length);
1877 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1878 break;
1879
1880 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1882 "(adapter %s, port d_id=0x%08x)\n",
1883 zfcp_get_busid_by_adapter(adapter), d_id);
1884 for (counter = 0; counter < 2; counter++) {
1885 subtable = header->fsf_status_qual.halfword[counter * 2];
1886 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1887 switch (subtable) {
1888 case FSF_SQ_CFDC_SUBTABLE_OS:
1889 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1890 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1891 case FSF_SQ_CFDC_SUBTABLE_LUN:
1892 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1893 zfcp_act_subtable_type[subtable], rule);
1894 break;
1895 }
1896 }
1897 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 if (port != NULL)
1899 zfcp_erp_port_access_denied(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1901 break;
1902
1903 default:
1904 ZFCP_LOG_NORMAL(
1905 "bug: An unknown FSF Status was presented "
1906 "(adapter: %s, fsf_status=0x%08x)\n",
1907 zfcp_get_busid_by_adapter(adapter),
1908 header->fsf_status);
1909 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1910 debug_exception(adapter->erp_dbf, 0,
1911 &header->fsf_status_qual.word[0], sizeof(u32));
1912 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1913 break;
1914 }
1915
1916skip_fsfstatus:
1917 send_els->status = retval;
1918
1919 if (send_els->handler != 0)
1920 send_els->handler(send_els->handler_data);
1921
1922 return retval;
1923}
1924
1925/*
1926 * function:
1927 *
1928 * purpose:
1929 *
1930 * returns: address of initiated FSF request
1931 * NULL - request could not be initiated
1932 */
1933int
1934zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1935{
1936 volatile struct qdio_buffer_element *sbale;
1937 unsigned long lock_flags;
1938 int retval = 0;
1939
1940 /* setup new FSF request */
1941 retval = zfcp_fsf_req_create(erp_action->adapter,
1942 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1943 ZFCP_REQ_AUTO_CLEANUP,
1944 erp_action->adapter->pool.fsf_req_erp,
1945 &lock_flags, &(erp_action->fsf_req));
1946 if (retval < 0) {
1947 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1948 "data request for adapter %s.\n",
1949 zfcp_get_busid_by_adapter(erp_action->adapter));
1950 goto out;
1951 }
1952
1953 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1954 erp_action->fsf_req->sbal_curr, 0);
1955 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1956 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1957
1958 erp_action->fsf_req->erp_action = erp_action;
1959 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1960 (FSF_FEATURE_CFDC | FSF_FEATURE_LUN_SHARING);
1961
1962 /* start QDIO request for this FSF request */
1963 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1964 if (retval) {
1965 ZFCP_LOG_INFO
1966 ("error: Could not send exchange configuration data "
1967 "command on the adapter %s\n",
1968 zfcp_get_busid_by_adapter(erp_action->adapter));
1969 zfcp_fsf_req_free(erp_action->fsf_req);
1970 erp_action->fsf_req = NULL;
1971 goto out;
1972 }
1973
1974 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1975 "(adapter %s)\n",
1976 zfcp_get_busid_by_adapter(erp_action->adapter));
1977
1978 out:
1979 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
1980 lock_flags);
1981 return retval;
1982}
1983
1984/**
1985 * zfcp_fsf_exchange_config_evaluate
1986 * @fsf_req: fsf_req which belongs to xchg config data request
1987 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1988 *
1989 * returns: -EIO on error, 0 otherwise
1990 */
1991static int
1992zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1993{
1994 struct fsf_qtcb_bottom_config *bottom;
1995 struct zfcp_adapter *adapter = fsf_req->adapter;
1996
1997 bottom = &fsf_req->qtcb->bottom.config;
1998 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1999 bottom->low_qtcb_version, bottom->high_qtcb_version);
2000 adapter->fsf_lic_version = bottom->lic_version;
2001 adapter->supported_features = bottom->supported_features;
6f71d9b2005-04-10 23:04:28 -05002002 adapter->peer_wwpn = 0;
2003 adapter->peer_wwnn = 0;
2004 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006 if (xchg_ok) {
2007 adapter->wwnn = bottom->nport_serv_param.wwnn;
2008 adapter->wwpn = bottom->nport_serv_param.wwpn;
2009 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2010 adapter->fc_topology = bottom->fc_topology;
2011 adapter->fc_link_speed = bottom->fc_link_speed;
2012 adapter->hydra_version = bottom->adapter_type;
2013 } else {
2014 adapter->wwnn = 0;
2015 adapter->wwpn = 0;
2016 adapter->s_id = 0;
2017 adapter->fc_topology = 0;
2018 adapter->fc_link_speed = 0;
2019 adapter->hydra_version = 0;
2020 }
2021
6f71d9b2005-04-10 23:04:28 -05002022 if (adapter->fc_topology == FSF_TOPO_P2P) {
2023 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2024 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2025 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2026 }
2027
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2029 adapter->hardware_version = bottom->hardware_version;
2030 memcpy(adapter->serial_number, bottom->serial_number, 17);
2031 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2032 }
2033
6f71d9b2005-04-10 23:04:28 -05002034 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 "WWNN 0x%016Lx, "
2036 "WWPN 0x%016Lx, "
2037 "S_ID 0x%08x,\n"
2038 "adapter version 0x%x, "
2039 "LIC version 0x%x, "
2040 "FC link speed %d Gb/s\n",
2041 zfcp_get_busid_by_adapter(adapter),
2042 adapter->wwnn,
2043 adapter->wwpn,
2044 (unsigned int) adapter->s_id,
2045 adapter->hydra_version,
2046 adapter->fsf_lic_version,
2047 adapter->fc_link_speed);
2048 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2049 ZFCP_LOG_NORMAL("error: the adapter %s "
2050 "only supports newer control block "
2051 "versions in comparison to this device "
2052 "driver (try updated device driver)\n",
2053 zfcp_get_busid_by_adapter(adapter));
2054 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2055 zfcp_erp_adapter_shutdown(adapter, 0);
2056 return -EIO;
2057 }
2058 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2059 ZFCP_LOG_NORMAL("error: the adapter %s "
2060 "only supports older control block "
2061 "versions than this device driver uses"
2062 "(consider a microcode upgrade)\n",
2063 zfcp_get_busid_by_adapter(adapter));
2064 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2065 zfcp_erp_adapter_shutdown(adapter, 0);
2066 return -EIO;
2067 }
2068 return 0;
2069}
2070
2071/*
2072 * function: zfcp_fsf_exchange_config_data_handler
2073 *
2074 * purpose: is called for finished Exchange Configuration Data command
2075 *
2076 * returns:
2077 */
2078static int
2079zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2080{
2081 struct fsf_qtcb_bottom_config *bottom;
2082 struct zfcp_adapter *adapter = fsf_req->adapter;
2083
2084 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2085 return -EIO;
2086
2087 switch (fsf_req->qtcb->header.fsf_status) {
2088
2089 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2091 return -EIO;
2092
2093 switch (adapter->fc_topology) {
2094 case FSF_TOPO_P2P:
6f71d9b2005-04-10 23:04:28 -05002095 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2096 "configuration detected at adapter %s\n"
2097 "Peer WWNN 0x%016llx, "
2098 "peer WWPN 0x%016llx, "
2099 "peer d_id 0x%06x\n",
2100 zfcp_get_busid_by_adapter(adapter),
2101 adapter->peer_wwnn,
2102 adapter->peer_wwpn,
2103 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2105 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002106 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 case FSF_TOPO_AL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2109 "topology detected at adapter %s "
2110 "unsupported, shutting down adapter\n",
2111 zfcp_get_busid_by_adapter(adapter));
2112 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2113 "top-al");
2114 zfcp_erp_adapter_shutdown(adapter, 0);
2115 return -EIO;
2116 case FSF_TOPO_FABRIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2118 "network detected at adapter %s.\n",
2119 zfcp_get_busid_by_adapter(adapter));
2120 break;
2121 default:
2122 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2123 "reported by the exchange "
2124 "configuration command for "
2125 "the adapter %s is not "
2126 "of a type known to the zfcp "
2127 "driver, shutting down adapter\n",
2128 zfcp_get_busid_by_adapter(adapter));
6f71d9b2005-04-10 23:04:28 -05002129 adapter->fc_topology = FSF_TOPO_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2131 "unknown-topo");
2132 zfcp_erp_adapter_shutdown(adapter, 0);
2133 return -EIO;
2134 }
2135 bottom = &fsf_req->qtcb->bottom.config;
2136 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2137 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2138 "allowed by the adapter %s "
2139 "is lower than the minimum "
2140 "required by the driver (%ld bytes).\n",
2141 bottom->max_qtcb_size,
2142 zfcp_get_busid_by_adapter(adapter),
2143 sizeof(struct fsf_qtcb));
2144 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2145 "qtcb-size");
2146 debug_event(fsf_req->adapter->erp_dbf, 0,
2147 &bottom->max_qtcb_size, sizeof (u32));
2148 zfcp_erp_adapter_shutdown(adapter, 0);
2149 return -EIO;
2150 }
2151 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2152 &adapter->status);
2153 break;
2154 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2155 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2156
2157 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2158 return -EIO;
2159
2160 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2161 zfcp_get_busid_by_adapter(adapter));
2162 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2163 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2164 &adapter->status);
2165 zfcp_erp_adapter_failed(adapter);
2166 break;
2167 default:
2168 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2169 debug_event(fsf_req->adapter->erp_dbf, 0,
2170 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2171 zfcp_erp_adapter_shutdown(adapter, 0);
2172 return -EIO;
2173 }
2174 return 0;
2175}
2176
2177/**
2178 * zfcp_fsf_exchange_port_data - request information about local port
2179 * @adapter: for which port data is requested
2180 * @data: response to exchange port data request
2181 */
2182int
2183zfcp_fsf_exchange_port_data(struct zfcp_adapter *adapter,
2184 struct fsf_qtcb_bottom_port *data)
2185{
2186 volatile struct qdio_buffer_element *sbale;
2187 int retval = 0;
2188 unsigned long lock_flags;
2189 struct zfcp_fsf_req *fsf_req;
2190 struct timer_list *timer;
2191
2192 if(!(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT)){
2193 ZFCP_LOG_INFO("error: exchange port data "
2194 "command not supported by adapter %s\n",
2195 zfcp_get_busid_by_adapter(adapter));
2196 return -EOPNOTSUPP;
2197 }
2198
2199 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2200 if (!timer)
2201 return -ENOMEM;
2202
2203 /* setup new FSF request */
2204 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2205 0, 0, &lock_flags, &fsf_req);
2206 if (retval < 0) {
2207 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2208 "exchange port data request for"
2209 "the adapter %s.\n",
2210 zfcp_get_busid_by_adapter(adapter));
2211 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2212 lock_flags);
2213 goto out;
2214 }
2215
2216 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2217 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2218 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2219
2220 fsf_req->data.port_data = data;
2221
2222 init_timer(timer);
2223 timer->function = zfcp_fsf_request_timeout_handler;
2224 timer->data = (unsigned long) adapter;
2225 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2226
2227 retval = zfcp_fsf_req_send(fsf_req, timer);
2228 if (retval) {
2229 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2230 "command on the adapter %s\n",
2231 zfcp_get_busid_by_adapter(adapter));
2232 zfcp_fsf_req_free(fsf_req);
2233 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2234 lock_flags);
2235 goto out;
2236 }
2237
2238 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2239 zfcp_get_busid_by_adapter(adapter));
2240
2241 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2242 lock_flags);
2243
2244 wait_event(fsf_req->completion_wq,
2245 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2246 del_timer_sync(timer);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02002247 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 out:
2249 kfree(timer);
2250 return retval;
2251}
2252
2253
2254/**
2255 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2256 * @fsf_req: pointer to struct zfcp_fsf_req
2257 */
2258static void
2259zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2260{
2261 struct fsf_qtcb_bottom_port *bottom;
2262 struct fsf_qtcb_bottom_port *data = fsf_req->data.port_data;
2263
2264 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2265 return;
2266
2267 switch (fsf_req->qtcb->header.fsf_status) {
2268 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 bottom = &fsf_req->qtcb->bottom.port;
2270 memcpy(data, bottom, sizeof(*data));
2271 break;
2272
2273 default:
2274 debug_text_event(fsf_req->adapter->erp_dbf, 0, "xchg-port-ng");
2275 debug_event(fsf_req->adapter->erp_dbf, 0,
2276 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2277 }
2278}
2279
2280
2281/*
2282 * function: zfcp_fsf_open_port
2283 *
2284 * purpose:
2285 *
2286 * returns: address of initiated FSF request
2287 * NULL - request could not be initiated
2288 */
2289int
2290zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2291{
2292 volatile struct qdio_buffer_element *sbale;
2293 unsigned long lock_flags;
2294 int retval = 0;
2295
2296 /* setup new FSF request */
2297 retval = zfcp_fsf_req_create(erp_action->adapter,
2298 FSF_QTCB_OPEN_PORT_WITH_DID,
2299 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2300 erp_action->adapter->pool.fsf_req_erp,
2301 &lock_flags, &(erp_action->fsf_req));
2302 if (retval < 0) {
2303 ZFCP_LOG_INFO("error: Could not create open port request "
2304 "for port 0x%016Lx on adapter %s.\n",
2305 erp_action->port->wwpn,
2306 zfcp_get_busid_by_adapter(erp_action->adapter));
2307 goto out;
2308 }
2309
2310 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2311 erp_action->fsf_req->sbal_curr, 0);
2312 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2313 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2314
2315 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2316 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2317 erp_action->fsf_req->data.open_port.port = erp_action->port;
2318 erp_action->fsf_req->erp_action = erp_action;
2319
2320 /* start QDIO request for this FSF request */
2321 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2322 if (retval) {
2323 ZFCP_LOG_INFO("error: Could not send open port request for "
2324 "port 0x%016Lx on adapter %s.\n",
2325 erp_action->port->wwpn,
2326 zfcp_get_busid_by_adapter(erp_action->adapter));
2327 zfcp_fsf_req_free(erp_action->fsf_req);
2328 erp_action->fsf_req = NULL;
2329 goto out;
2330 }
2331
2332 ZFCP_LOG_DEBUG("open port request initiated "
2333 "(adapter %s, port 0x%016Lx)\n",
2334 zfcp_get_busid_by_adapter(erp_action->adapter),
2335 erp_action->port->wwpn);
2336 out:
2337 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2338 lock_flags);
2339 return retval;
2340}
2341
2342/*
2343 * function: zfcp_fsf_open_port_handler
2344 *
2345 * purpose: is called for finished Open Port command
2346 *
2347 * returns:
2348 */
2349static int
2350zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2351{
2352 int retval = -EINVAL;
2353 struct zfcp_port *port;
2354 struct fsf_plogi *plogi;
2355 struct fsf_qtcb_header *header;
2356 u16 subtable, rule, counter;
2357
2358 port = fsf_req->data.open_port.port;
2359 header = &fsf_req->qtcb->header;
2360
2361 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2362 /* don't change port status in our bookkeeping */
2363 goto skip_fsfstatus;
2364 }
2365
2366 /* evaluate FSF status in QTCB */
2367 switch (header->fsf_status) {
2368
2369 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2371 "is already open.\n",
2372 port->wwpn, zfcp_get_busid_by_port(port));
2373 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2374 "fsf_s_popen");
2375 /*
2376 * This is a bug, however operation should continue normally
2377 * if it is simply ignored
2378 */
2379 break;
2380
2381 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2383 "on adapter %s\n",
2384 port->wwpn, zfcp_get_busid_by_port(port));
2385 for (counter = 0; counter < 2; counter++) {
2386 subtable = header->fsf_status_qual.halfword[counter * 2];
2387 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2388 switch (subtable) {
2389 case FSF_SQ_CFDC_SUBTABLE_OS:
2390 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2391 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2392 case FSF_SQ_CFDC_SUBTABLE_LUN:
2393 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2394 zfcp_act_subtable_type[subtable], rule);
2395 break;
2396 }
2397 }
2398 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2399 zfcp_erp_port_access_denied(port);
2400 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2401 break;
2402
2403 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2405 "The remote port 0x%016Lx on adapter %s "
2406 "could not be opened. Disabling it.\n",
2407 port->wwpn, zfcp_get_busid_by_port(port));
2408 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2409 "fsf_s_max_ports");
2410 zfcp_erp_port_failed(port);
2411 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2412 break;
2413
2414 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 switch (header->fsf_status_qual.word[0]) {
2416 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2418 "fsf_sq_ltest");
2419 /* ERP strategy will escalate */
2420 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2421 break;
2422 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2423 /* ERP strategy will escalate */
2424 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2425 "fsf_sq_ulp");
2426 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2427 break;
2428 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2430 "adapter %s could not be opened. "
2431 "Disabling it.\n",
2432 port->wwpn,
2433 zfcp_get_busid_by_port(port));
2434 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2435 "fsf_sq_no_retry");
2436 zfcp_erp_port_failed(port);
2437 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2438 break;
2439 default:
2440 ZFCP_LOG_NORMAL
2441 ("bug: Wrong status qualifier 0x%x arrived.\n",
2442 header->fsf_status_qual.word[0]);
2443 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2444 "fsf_sq_inval:");
2445 debug_exception(
2446 fsf_req->adapter->erp_dbf, 0,
2447 &header->fsf_status_qual.word[0],
2448 sizeof (u32));
2449 break;
2450 }
2451 break;
2452
2453 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 /* save port handle assigned by FSF */
2455 port->handle = header->port_handle;
2456 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2457 "was opened, it's port handle is 0x%x\n",
2458 port->wwpn, zfcp_get_busid_by_port(port),
2459 port->handle);
2460 /* mark port as open */
2461 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2462 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2463 retval = 0;
2464 /* check whether D_ID has changed during open */
2465 /*
2466 * FIXME: This check is not airtight, as the FCP channel does
2467 * not monitor closures of target port connections caused on
2468 * the remote side. Thus, they might miss out on invalidating
2469 * locally cached WWPNs (and other N_Port parameters) of gone
2470 * target ports. So, our heroic attempt to make things safe
2471 * could be undermined by 'open port' response data tagged with
2472 * obsolete WWPNs. Another reason to monitor potential
2473 * connection closures ourself at least (by interpreting
2474 * incoming ELS' and unsolicited status). It just crosses my
2475 * mind that one should be able to cross-check by means of
2476 * another GID_PN straight after a port has been opened.
2477 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2478 */
2479 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2480 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2481 {
2482 if (fsf_req->qtcb->bottom.support.els1_length <
2483 ((((unsigned long) &plogi->serv_param.wwpn) -
2484 ((unsigned long) plogi)) + sizeof (u64))) {
2485 ZFCP_LOG_INFO(
2486 "warning: insufficient length of "
2487 "PLOGI payload (%i)\n",
2488 fsf_req->qtcb->bottom.support.els1_length);
2489 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2490 "fsf_s_short_plogi:");
2491 /* skip sanity check and assume wwpn is ok */
2492 } else {
2493 if (plogi->serv_param.wwpn != port->wwpn) {
2494 ZFCP_LOG_INFO("warning: d_id of port "
2495 "0x%016Lx changed during "
2496 "open\n", port->wwpn);
2497 debug_text_event(
2498 fsf_req->adapter->erp_dbf, 0,
2499 "fsf_s_did_change:");
2500 atomic_clear_mask(
2501 ZFCP_STATUS_PORT_DID_DID,
2502 &port->status);
2503 } else
2504 port->wwnn = plogi->serv_param.wwnn;
2505 }
2506 }
2507 break;
2508
2509 case FSF_UNKNOWN_OP_SUBTYPE:
2510 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2512 "op_subtype=0x%x)\n",
2513 zfcp_get_busid_by_port(port),
2514 fsf_req->qtcb->bottom.support.operation_subtype);
2515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2516 break;
2517
2518 default:
2519 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2520 "(debug info 0x%x)\n",
2521 header->fsf_status);
2522 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2523 debug_exception(fsf_req->adapter->erp_dbf, 0,
2524 &header->fsf_status, sizeof (u32));
2525 break;
2526 }
2527
2528 skip_fsfstatus:
2529 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2530 return retval;
2531}
2532
2533/*
2534 * function: zfcp_fsf_close_port
2535 *
2536 * purpose: submit FSF command "close port"
2537 *
2538 * returns: address of initiated FSF request
2539 * NULL - request could not be initiated
2540 */
2541int
2542zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2543{
2544 volatile struct qdio_buffer_element *sbale;
2545 unsigned long lock_flags;
2546 int retval = 0;
2547
2548 /* setup new FSF request */
2549 retval = zfcp_fsf_req_create(erp_action->adapter,
2550 FSF_QTCB_CLOSE_PORT,
2551 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2552 erp_action->adapter->pool.fsf_req_erp,
2553 &lock_flags, &(erp_action->fsf_req));
2554 if (retval < 0) {
2555 ZFCP_LOG_INFO("error: Could not create a close port request "
2556 "for port 0x%016Lx on adapter %s.\n",
2557 erp_action->port->wwpn,
2558 zfcp_get_busid_by_adapter(erp_action->adapter));
2559 goto out;
2560 }
2561
2562 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2563 erp_action->fsf_req->sbal_curr, 0);
2564 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2565 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2566
2567 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2568 erp_action->fsf_req->data.close_port.port = erp_action->port;
2569 erp_action->fsf_req->erp_action = erp_action;
2570 erp_action->fsf_req->qtcb->header.port_handle =
2571 erp_action->port->handle;
2572
2573 /* start QDIO request for this FSF request */
2574 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2575 if (retval) {
2576 ZFCP_LOG_INFO("error: Could not send a close port request for "
2577 "port 0x%016Lx on adapter %s.\n",
2578 erp_action->port->wwpn,
2579 zfcp_get_busid_by_adapter(erp_action->adapter));
2580 zfcp_fsf_req_free(erp_action->fsf_req);
2581 erp_action->fsf_req = NULL;
2582 goto out;
2583 }
2584
2585 ZFCP_LOG_TRACE("close port request initiated "
2586 "(adapter %s, port 0x%016Lx)\n",
2587 zfcp_get_busid_by_adapter(erp_action->adapter),
2588 erp_action->port->wwpn);
2589 out:
2590 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2591 lock_flags);
2592 return retval;
2593}
2594
2595/*
2596 * function: zfcp_fsf_close_port_handler
2597 *
2598 * purpose: is called for finished Close Port FSF command
2599 *
2600 * returns:
2601 */
2602static int
2603zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2604{
2605 int retval = -EINVAL;
2606 struct zfcp_port *port;
2607
2608 port = fsf_req->data.close_port.port;
2609
2610 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2611 /* don't change port status in our bookkeeping */
2612 goto skip_fsfstatus;
2613 }
2614
2615 /* evaluate FSF status in QTCB */
2616 switch (fsf_req->qtcb->header.fsf_status) {
2617
2618 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2620 "0x%016Lx on adapter %s invalid. This may happen "
2621 "occasionally.\n", port->handle,
2622 port->wwpn, zfcp_get_busid_by_port(port));
2623 ZFCP_LOG_DEBUG("status qualifier:\n");
2624 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2625 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2626 sizeof (union fsf_status_qual));
2627 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2628 "fsf_s_phand_nv");
2629 zfcp_erp_adapter_reopen(port->adapter, 0);
2630 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2631 break;
2632
2633 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 /* Note: FSF has actually closed the port in this case.
2635 * The status code is just daft. Fingers crossed for a change
2636 */
2637 retval = 0;
2638 break;
2639
2640 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2642 "port handle 0x%x\n", port->wwpn,
2643 zfcp_get_busid_by_port(port), port->handle);
2644 zfcp_erp_modify_port_status(port,
2645 ZFCP_STATUS_COMMON_OPEN,
2646 ZFCP_CLEAR);
2647 retval = 0;
2648 break;
2649
2650 default:
2651 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2652 "(debug info 0x%x)\n",
2653 fsf_req->qtcb->header.fsf_status);
2654 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2655 debug_exception(fsf_req->adapter->erp_dbf, 0,
2656 &fsf_req->qtcb->header.fsf_status,
2657 sizeof (u32));
2658 break;
2659 }
2660
2661 skip_fsfstatus:
2662 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2663 return retval;
2664}
2665
2666/*
2667 * function: zfcp_fsf_close_physical_port
2668 *
2669 * purpose: submit FSF command "close physical port"
2670 *
2671 * returns: address of initiated FSF request
2672 * NULL - request could not be initiated
2673 */
2674int
2675zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2676{
2677 int retval = 0;
2678 unsigned long lock_flags;
2679 volatile struct qdio_buffer_element *sbale;
2680
2681 /* setup new FSF request */
2682 retval = zfcp_fsf_req_create(erp_action->adapter,
2683 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2684 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2685 erp_action->adapter->pool.fsf_req_erp,
2686 &lock_flags, &erp_action->fsf_req);
2687 if (retval < 0) {
2688 ZFCP_LOG_INFO("error: Could not create close physical port "
2689 "request (adapter %s, port 0x%016Lx)\n",
2690 zfcp_get_busid_by_adapter(erp_action->adapter),
2691 erp_action->port->wwpn);
2692
2693 goto out;
2694 }
2695
2696 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2697 erp_action->fsf_req->sbal_curr, 0);
2698 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2699 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2700
2701 /* mark port as being closed */
2702 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2703 &erp_action->port->status);
2704 /* save a pointer to this port */
2705 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2706 /* port to be closeed */
2707 erp_action->fsf_req->qtcb->header.port_handle =
2708 erp_action->port->handle;
2709 erp_action->fsf_req->erp_action = erp_action;
2710
2711 /* start QDIO request for this FSF request */
2712 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2713 if (retval) {
2714 ZFCP_LOG_INFO("error: Could not send close physical port "
2715 "request (adapter %s, port 0x%016Lx)\n",
2716 zfcp_get_busid_by_adapter(erp_action->adapter),
2717 erp_action->port->wwpn);
2718 zfcp_fsf_req_free(erp_action->fsf_req);
2719 erp_action->fsf_req = NULL;
2720 goto out;
2721 }
2722
2723 ZFCP_LOG_TRACE("close physical port request initiated "
2724 "(adapter %s, port 0x%016Lx)\n",
2725 zfcp_get_busid_by_adapter(erp_action->adapter),
2726 erp_action->port->wwpn);
2727 out:
2728 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2729 lock_flags);
2730 return retval;
2731}
2732
2733/*
2734 * function: zfcp_fsf_close_physical_port_handler
2735 *
2736 * purpose: is called for finished Close Physical Port FSF command
2737 *
2738 * returns:
2739 */
2740static int
2741zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2742{
2743 int retval = -EINVAL;
2744 struct zfcp_port *port;
2745 struct zfcp_unit *unit;
2746 struct fsf_qtcb_header *header;
2747 u16 subtable, rule, counter;
2748
2749 port = fsf_req->data.close_physical_port.port;
2750 header = &fsf_req->qtcb->header;
2751
2752 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2753 /* don't change port status in our bookkeeping */
2754 goto skip_fsfstatus;
2755 }
2756
2757 /* evaluate FSF status in QTCB */
2758 switch (header->fsf_status) {
2759
2760 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2762 "(adapter %s, port 0x%016Lx). "
2763 "This may happen occasionally.\n",
2764 port->handle,
2765 zfcp_get_busid_by_port(port),
2766 port->wwpn);
2767 ZFCP_LOG_DEBUG("status qualifier:\n");
2768 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2769 (char *) &header->fsf_status_qual,
2770 sizeof (union fsf_status_qual));
2771 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2772 "fsf_s_phand_nv");
2773 zfcp_erp_adapter_reopen(port->adapter, 0);
2774 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2775 break;
2776
2777 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 ZFCP_LOG_NORMAL("Access denied, cannot close "
2779 "physical port 0x%016Lx on adapter %s\n",
2780 port->wwpn, zfcp_get_busid_by_port(port));
2781 for (counter = 0; counter < 2; counter++) {
2782 subtable = header->fsf_status_qual.halfword[counter * 2];
2783 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2784 switch (subtable) {
2785 case FSF_SQ_CFDC_SUBTABLE_OS:
2786 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2787 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2788 case FSF_SQ_CFDC_SUBTABLE_LUN:
2789 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2790 zfcp_act_subtable_type[subtable], rule);
2791 break;
2792 }
2793 }
2794 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2795 zfcp_erp_port_access_denied(port);
2796 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2797 break;
2798
2799 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2801 "%s needs to be reopened but it was attempted "
2802 "to close it physically.\n",
2803 port->wwpn,
2804 zfcp_get_busid_by_port(port));
2805 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2806 zfcp_erp_port_reopen(port, 0);
2807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2808 ZFCP_STATUS_FSFREQ_RETRY;
2809 break;
2810
2811 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 switch (header->fsf_status_qual.word[0]) {
2813 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2815 "fsf_sq_ltest");
2816 /* This will now be escalated by ERP */
2817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2818 break;
2819 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 /* ERP strategy will escalate */
2821 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2822 "fsf_sq_ulp");
2823 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2824 break;
2825 default:
2826 ZFCP_LOG_NORMAL
2827 ("bug: Wrong status qualifier 0x%x arrived.\n",
2828 header->fsf_status_qual.word[0]);
2829 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2830 "fsf_sq_inval:");
2831 debug_exception(
2832 fsf_req->adapter->erp_dbf, 0,
2833 &header->fsf_status_qual.word[0], sizeof (u32));
2834 break;
2835 }
2836 break;
2837
2838 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2840 "physically closed, port handle 0x%x\n",
2841 port->wwpn,
2842 zfcp_get_busid_by_port(port), port->handle);
2843 /* can't use generic zfcp_erp_modify_port_status because
2844 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2845 */
2846 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2847 list_for_each_entry(unit, &port->unit_list_head, list)
2848 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2849 retval = 0;
2850 break;
2851
2852 default:
2853 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2854 "(debug info 0x%x)\n",
2855 header->fsf_status);
2856 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2857 debug_exception(fsf_req->adapter->erp_dbf, 0,
2858 &header->fsf_status, sizeof (u32));
2859 break;
2860 }
2861
2862 skip_fsfstatus:
2863 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2864 return retval;
2865}
2866
2867/*
2868 * function: zfcp_fsf_open_unit
2869 *
2870 * purpose:
2871 *
2872 * returns:
2873 *
2874 * assumptions: This routine does not check whether the associated
2875 * remote port has already been opened. This should be
2876 * done by calling routines. Otherwise some status
2877 * may be presented by FSF
2878 */
2879int
2880zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2881{
2882 volatile struct qdio_buffer_element *sbale;
2883 unsigned long lock_flags;
2884 int retval = 0;
2885
2886 /* setup new FSF request */
2887 retval = zfcp_fsf_req_create(erp_action->adapter,
2888 FSF_QTCB_OPEN_LUN,
2889 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2890 erp_action->adapter->pool.fsf_req_erp,
2891 &lock_flags, &(erp_action->fsf_req));
2892 if (retval < 0) {
2893 ZFCP_LOG_INFO("error: Could not create open unit request for "
2894 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2895 erp_action->unit->fcp_lun,
2896 erp_action->unit->port->wwpn,
2897 zfcp_get_busid_by_adapter(erp_action->adapter));
2898 goto out;
2899 }
2900
2901 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2902 erp_action->fsf_req->sbal_curr, 0);
2903 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2904 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2905
2906 erp_action->fsf_req->qtcb->header.port_handle =
2907 erp_action->port->handle;
2908 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2909 erp_action->unit->fcp_lun;
2910 erp_action->fsf_req->qtcb->bottom.support.option =
2911 FSF_OPEN_LUN_SUPPRESS_BOXING;
2912 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2913 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2914 erp_action->fsf_req->erp_action = erp_action;
2915
2916 /* start QDIO request for this FSF request */
2917 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2918 if (retval) {
2919 ZFCP_LOG_INFO("error: Could not send an open unit request "
2920 "on the adapter %s, port 0x%016Lx for "
2921 "unit 0x%016Lx\n",
2922 zfcp_get_busid_by_adapter(erp_action->adapter),
2923 erp_action->port->wwpn,
2924 erp_action->unit->fcp_lun);
2925 zfcp_fsf_req_free(erp_action->fsf_req);
2926 erp_action->fsf_req = NULL;
2927 goto out;
2928 }
2929
2930 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2931 "port 0x%016Lx, unit 0x%016Lx)\n",
2932 zfcp_get_busid_by_adapter(erp_action->adapter),
2933 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2934 out:
2935 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2936 lock_flags);
2937 return retval;
2938}
2939
2940/*
2941 * function: zfcp_fsf_open_unit_handler
2942 *
2943 * purpose: is called for finished Open LUN command
2944 *
2945 * returns:
2946 */
2947static int
2948zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2949{
2950 int retval = -EINVAL;
2951 struct zfcp_adapter *adapter;
2952 struct zfcp_unit *unit;
2953 struct fsf_qtcb_header *header;
2954 struct fsf_qtcb_bottom_support *bottom;
2955 struct fsf_queue_designator *queue_designator;
2956 u16 subtable, rule, counter;
2957 u32 allowed, exclusive, readwrite;
2958
2959 unit = fsf_req->data.open_unit.unit;
2960
2961 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2962 /* don't change unit status in our bookkeeping */
2963 goto skip_fsfstatus;
2964 }
2965
2966 adapter = fsf_req->adapter;
2967 header = &fsf_req->qtcb->header;
2968 bottom = &fsf_req->qtcb->bottom.support;
2969 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2970
2971 allowed = bottom->lun_access_info & FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED;
2972 exclusive = bottom->lun_access_info & FSF_UNIT_ACCESS_EXCLUSIVE;
2973 readwrite = bottom->lun_access_info & FSF_UNIT_ACCESS_OUTBOUND_TRANSFER;
2974
2975 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2976 ZFCP_STATUS_UNIT_SHARED |
2977 ZFCP_STATUS_UNIT_READONLY,
2978 &unit->status);
2979
2980 /* evaluate FSF status in QTCB */
2981 switch (header->fsf_status) {
2982
2983 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
2985 "for port 0x%016Lx on adapter %s invalid "
2986 "This may happen occasionally\n",
2987 unit->port->handle,
2988 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2989 ZFCP_LOG_DEBUG("status qualifier:\n");
2990 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2991 (char *) &header->fsf_status_qual,
2992 sizeof (union fsf_status_qual));
2993 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
2994 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
2995 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2996 break;
2997
2998 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3000 "remote port 0x%016Lx on adapter %s twice.\n",
3001 unit->fcp_lun,
3002 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3003 debug_text_exception(adapter->erp_dbf, 0,
3004 "fsf_s_uopen");
3005 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3006 break;
3007
3008 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3010 "remote port 0x%016Lx on adapter %s\n",
3011 unit->fcp_lun, unit->port->wwpn,
3012 zfcp_get_busid_by_unit(unit));
3013 for (counter = 0; counter < 2; counter++) {
3014 subtable = header->fsf_status_qual.halfword[counter * 2];
3015 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3016 switch (subtable) {
3017 case FSF_SQ_CFDC_SUBTABLE_OS:
3018 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3019 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3020 case FSF_SQ_CFDC_SUBTABLE_LUN:
3021 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3022 zfcp_act_subtable_type[subtable], rule);
3023 break;
3024 }
3025 }
3026 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3027 zfcp_erp_unit_access_denied(unit);
3028 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3029 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3030 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3031 break;
3032
3033 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3035 "needs to be reopened\n",
3036 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3037 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3038 zfcp_erp_port_reopen(unit->port, 0);
3039 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3040 ZFCP_STATUS_FSFREQ_RETRY;
3041 break;
3042
3043 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 if (header->fsf_status_qual.word[0] != 0) {
3045 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3046 "with WWPN 0x%Lx "
3047 "connected to the adapter %s "
3048 "is already in use in LPAR%d, CSS%d\n",
3049 unit->fcp_lun,
3050 unit->port->wwpn,
3051 zfcp_get_busid_by_unit(unit),
3052 queue_designator->hla,
3053 queue_designator->cssid);
3054 } else {
3055 subtable = header->fsf_status_qual.halfword[4];
3056 rule = header->fsf_status_qual.halfword[5];
3057 switch (subtable) {
3058 case FSF_SQ_CFDC_SUBTABLE_OS:
3059 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3060 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3061 case FSF_SQ_CFDC_SUBTABLE_LUN:
3062 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3063 "remote port with WWPN 0x%Lx "
3064 "connected to the adapter %s "
3065 "is denied (%s rule %d)\n",
3066 unit->fcp_lun,
3067 unit->port->wwpn,
3068 zfcp_get_busid_by_unit(unit),
3069 zfcp_act_subtable_type[subtable],
3070 rule);
3071 break;
3072 }
3073 }
3074 ZFCP_LOG_DEBUG("status qualifier:\n");
3075 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3076 (char *) &header->fsf_status_qual,
3077 sizeof (union fsf_status_qual));
3078 debug_text_event(adapter->erp_dbf, 2,
3079 "fsf_s_l_sh_vio");
3080 zfcp_erp_unit_access_denied(unit);
3081 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3082 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3083 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3084 break;
3085
3086 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3088 "There is no handle (temporary port identifier) "
3089 "available for unit 0x%016Lx on port 0x%016Lx "
3090 "on adapter %s\n",
3091 unit->fcp_lun,
3092 unit->port->wwpn,
3093 zfcp_get_busid_by_unit(unit));
3094 debug_text_event(adapter->erp_dbf, 1,
3095 "fsf_s_max_units");
3096 zfcp_erp_unit_failed(unit);
3097 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3098 break;
3099
3100 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 switch (header->fsf_status_qual.word[0]) {
3102 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 /* Re-establish link to port */
3104 debug_text_event(adapter->erp_dbf, 1,
3105 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003106 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3108 break;
3109 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 /* ERP strategy will escalate */
3111 debug_text_event(adapter->erp_dbf, 1,
3112 "fsf_sq_ulp");
3113 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3114 break;
3115 default:
3116 ZFCP_LOG_NORMAL
3117 ("bug: Wrong status qualifier 0x%x arrived.\n",
3118 header->fsf_status_qual.word[0]);
3119 debug_text_event(adapter->erp_dbf, 0,
3120 "fsf_sq_inval:");
3121 debug_exception(adapter->erp_dbf, 0,
3122 &header->fsf_status_qual.word[0],
3123 sizeof (u32));
3124 }
3125 break;
3126
3127 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 ZFCP_LOG_NORMAL(
3129 "Invalid option 0x%x has been specified "
3130 "in QTCB bottom sent to the adapter %s\n",
3131 bottom->option,
3132 zfcp_get_busid_by_adapter(adapter));
3133 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3134 retval = -EINVAL;
3135 break;
3136
3137 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 /* save LUN handle assigned by FSF */
3139 unit->handle = header->lun_handle;
3140 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3141 "adapter %s opened, port handle 0x%x\n",
3142 unit->fcp_lun,
3143 unit->port->wwpn,
3144 zfcp_get_busid_by_unit(unit),
3145 unit->handle);
3146 /* mark unit as open */
3147 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3148
3149 if (adapter->supported_features & FSF_FEATURE_LUN_SHARING){
3150 if (!exclusive)
3151 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3152 &unit->status);
3153
3154 if (!readwrite) {
3155 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3156 &unit->status);
3157 ZFCP_LOG_NORMAL("read-only access for unit "
3158 "(adapter %s, wwpn=0x%016Lx, "
3159 "fcp_lun=0x%016Lx)\n",
3160 zfcp_get_busid_by_unit(unit),
3161 unit->port->wwpn,
3162 unit->fcp_lun);
3163 }
3164
3165 if (exclusive && !readwrite) {
3166 ZFCP_LOG_NORMAL("exclusive access of read-only "
3167 "unit not supported\n");
3168 zfcp_erp_unit_failed(unit);
3169 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3170 zfcp_erp_unit_shutdown(unit, 0);
3171 } else if (!exclusive && readwrite) {
3172 ZFCP_LOG_NORMAL("shared access of read-write "
3173 "unit not supported\n");
3174 zfcp_erp_unit_failed(unit);
3175 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3176 zfcp_erp_unit_shutdown(unit, 0);
3177 }
3178 }
3179
3180 retval = 0;
3181 break;
3182
3183 default:
3184 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3185 "(debug info 0x%x)\n",
3186 header->fsf_status);
3187 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3188 debug_exception(adapter->erp_dbf, 0,
3189 &header->fsf_status, sizeof (u32));
3190 break;
3191 }
3192
3193 skip_fsfstatus:
3194 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3195 return retval;
3196}
3197
3198/*
3199 * function: zfcp_fsf_close_unit
3200 *
3201 * purpose:
3202 *
3203 * returns: address of fsf_req - request successfully initiated
3204 * NULL -
3205 *
3206 * assumptions: This routine does not check whether the associated
3207 * remote port/lun has already been opened. This should be
3208 * done by calling routines. Otherwise some status
3209 * may be presented by FSF
3210 */
3211int
3212zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3213{
3214 volatile struct qdio_buffer_element *sbale;
3215 unsigned long lock_flags;
3216 int retval = 0;
3217
3218 /* setup new FSF request */
3219 retval = zfcp_fsf_req_create(erp_action->adapter,
3220 FSF_QTCB_CLOSE_LUN,
3221 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3222 erp_action->adapter->pool.fsf_req_erp,
3223 &lock_flags, &(erp_action->fsf_req));
3224 if (retval < 0) {
3225 ZFCP_LOG_INFO("error: Could not create close unit request for "
3226 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3227 erp_action->unit->fcp_lun,
3228 erp_action->port->wwpn,
3229 zfcp_get_busid_by_adapter(erp_action->adapter));
3230 goto out;
3231 }
3232
3233 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3234 erp_action->fsf_req->sbal_curr, 0);
3235 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3236 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3237
3238 erp_action->fsf_req->qtcb->header.port_handle =
3239 erp_action->port->handle;
3240 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3241 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3242 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3243 erp_action->fsf_req->erp_action = erp_action;
3244
3245 /* start QDIO request for this FSF request */
3246 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3247 if (retval) {
3248 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3249 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3250 erp_action->unit->fcp_lun,
3251 erp_action->port->wwpn,
3252 zfcp_get_busid_by_adapter(erp_action->adapter));
3253 zfcp_fsf_req_free(erp_action->fsf_req);
3254 erp_action->fsf_req = NULL;
3255 goto out;
3256 }
3257
3258 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3259 "port 0x%016Lx, unit 0x%016Lx)\n",
3260 zfcp_get_busid_by_adapter(erp_action->adapter),
3261 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3262 out:
3263 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3264 lock_flags);
3265 return retval;
3266}
3267
3268/*
3269 * function: zfcp_fsf_close_unit_handler
3270 *
3271 * purpose: is called for finished Close LUN FSF command
3272 *
3273 * returns:
3274 */
3275static int
3276zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3277{
3278 int retval = -EINVAL;
3279 struct zfcp_unit *unit;
3280
3281 unit = fsf_req->data.close_unit.unit; /* restore unit */
3282
3283 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3284 /* don't change unit status in our bookkeeping */
3285 goto skip_fsfstatus;
3286 }
3287
3288 /* evaluate FSF status in QTCB */
3289 switch (fsf_req->qtcb->header.fsf_status) {
3290
3291 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3293 "0x%016Lx on adapter %s invalid. This may "
3294 "happen in rare circumstances\n",
3295 unit->port->handle,
3296 unit->port->wwpn,
3297 zfcp_get_busid_by_unit(unit));
3298 ZFCP_LOG_DEBUG("status qualifier:\n");
3299 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3300 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3301 sizeof (union fsf_status_qual));
3302 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3303 "fsf_s_phand_nv");
3304 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3305 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3306 &fsf_req->qtcb->header.fsf_status_qual,
3307 sizeof (union fsf_status_qual));
3308 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3309 break;
3310
3311 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3313 "0x%016Lx on port 0x%016Lx on adapter %s is "
3314 "invalid. This may happen occasionally.\n",
3315 unit->handle,
3316 unit->fcp_lun,
3317 unit->port->wwpn,
3318 zfcp_get_busid_by_unit(unit));
3319 ZFCP_LOG_DEBUG("Status qualifier data:\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_lhand_nv");
3325 zfcp_erp_port_reopen(unit->port, 0);
3326 zfcp_cmd_dbf_event_fsf("lunhinv", 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;
3331
3332 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3334 "needs to be reopened\n",
3335 unit->port->wwpn,
3336 zfcp_get_busid_by_unit(unit));
3337 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3338 zfcp_erp_port_reopen(unit->port, 0);
3339 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3340 ZFCP_STATUS_FSFREQ_RETRY;
3341 break;
3342
3343 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3345 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 /* re-establish link to port */
3347 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3348 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003349 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3351 break;
3352 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 /* ERP strategy will escalate */
3354 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3355 "fsf_sq_ulp");
3356 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3357 break;
3358 default:
3359 ZFCP_LOG_NORMAL
3360 ("bug: Wrong status qualifier 0x%x arrived.\n",
3361 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3362 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3363 "fsf_sq_inval:");
3364 debug_exception(
3365 fsf_req->adapter->erp_dbf, 0,
3366 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3367 sizeof (u32));
3368 break;
3369 }
3370 break;
3371
3372 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3374 "closed, port handle 0x%x\n",
3375 unit->fcp_lun,
3376 unit->port->wwpn,
3377 zfcp_get_busid_by_unit(unit),
3378 unit->handle);
3379 /* mark unit as closed */
3380 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3381 retval = 0;
3382 break;
3383
3384 default:
3385 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3386 "(debug info 0x%x)\n",
3387 fsf_req->qtcb->header.fsf_status);
3388 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3389 debug_exception(fsf_req->adapter->erp_dbf, 0,
3390 &fsf_req->qtcb->header.fsf_status,
3391 sizeof (u32));
3392 break;
3393 }
3394
3395 skip_fsfstatus:
3396 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3397 return retval;
3398}
3399
3400/**
3401 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3402 * @adapter: adapter where scsi command is issued
3403 * @unit: unit where command is sent to
3404 * @scsi_cmnd: scsi command to be sent
3405 * @timer: timer to be started when request is initiated
3406 * @req_flags: flags for fsf_request
3407 */
3408int
3409zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3410 struct zfcp_unit *unit,
3411 struct scsi_cmnd * scsi_cmnd,
3412 struct timer_list *timer, int req_flags)
3413{
3414 struct zfcp_fsf_req *fsf_req = NULL;
3415 struct fcp_cmnd_iu *fcp_cmnd_iu;
3416 unsigned int sbtype;
3417 unsigned long lock_flags;
3418 int real_bytes = 0;
3419 int retval = 0;
3420 int mask;
3421
3422 /* setup new FSF request */
3423 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3424 adapter->pool.fsf_req_scsi,
3425 &lock_flags, &fsf_req);
3426 if (unlikely(retval < 0)) {
3427 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3428 "for unit 0x%016Lx on port 0x%016Lx on "
3429 "adapter %s\n",
3430 unit->fcp_lun,
3431 unit->port->wwpn,
3432 zfcp_get_busid_by_adapter(adapter));
3433 goto failed_req_create;
3434 }
3435
3436 /*
3437 * associate FSF request with SCSI request
3438 * (need this for look up on abort)
3439 */
3440 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3441 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3442
3443 /*
3444 * associate SCSI command with FSF request
3445 * (need this for look up on normal command completion)
3446 */
3447 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3448 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3449 fsf_req->data.send_fcp_command_task.unit = unit;
3450 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3451
3452 /* set handles of unit and its parent port in QTCB */
3453 fsf_req->qtcb->header.lun_handle = unit->handle;
3454 fsf_req->qtcb->header.port_handle = unit->port->handle;
3455
3456 /* FSF does not define the structure of the FCP_CMND IU */
3457 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3458 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3459
3460 /*
3461 * set depending on data direction:
3462 * data direction bits in SBALE (SB Type)
3463 * data direction bits in QTCB
3464 * data direction bits in FCP_CMND IU
3465 */
3466 switch (scsi_cmnd->sc_data_direction) {
3467 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3469 /*
3470 * FIXME(qdio):
3471 * what is the correct type for commands
3472 * without 'real' data buffers?
3473 */
3474 sbtype = SBAL_FLAGS0_TYPE_READ;
3475 break;
3476 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3478 sbtype = SBAL_FLAGS0_TYPE_READ;
3479 fcp_cmnd_iu->rddata = 1;
3480 break;
3481 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3483 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3484 fcp_cmnd_iu->wddata = 1;
3485 break;
3486 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 default:
3488 /*
3489 * dummy, catch this condition earlier
3490 * in zfcp_scsi_queuecommand
3491 */
3492 goto failed_scsi_cmnd;
3493 }
3494
3495 /* set FC service class in QTCB (3 per default) */
3496 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3497
3498 /* set FCP_LUN in FCP_CMND IU in QTCB */
3499 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3500
3501 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3502
3503 /* set task attributes in FCP_CMND IU in QTCB */
3504 if (likely((scsi_cmnd->device->simple_tags) ||
3505 (atomic_test_mask(mask, &unit->status))))
3506 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3507 else
3508 fcp_cmnd_iu->task_attribute = UNTAGGED;
3509
3510 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3511 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3512 fcp_cmnd_iu->add_fcp_cdb_length
3513 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3514 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3515 "additional FCP_CDB length is 0x%x "
3516 "(shifted right 2 bits)\n",
3517 scsi_cmnd->cmd_len,
3518 fcp_cmnd_iu->add_fcp_cdb_length);
3519 }
3520 /*
3521 * copy SCSI CDB (including additional length, if any) to
3522 * FCP_CDB in FCP_CMND IU in QTCB
3523 */
3524 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3525
3526 /* FCP CMND IU length in QTCB */
3527 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3528 sizeof (struct fcp_cmnd_iu) +
3529 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3530
3531 /* generate SBALEs from data buffer */
3532 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3533 if (unlikely(real_bytes < 0)) {
3534 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3535 ZFCP_LOG_DEBUG(
3536 "Data did not fit into available buffer(s), "
3537 "waiting for more...\n");
3538 retval = -EIO;
3539 } else {
3540 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3541 "required. Shutting down unit "
3542 "(adapter %s, port 0x%016Lx, "
3543 "unit 0x%016Lx)\n",
3544 zfcp_get_busid_by_unit(unit),
3545 unit->port->wwpn,
3546 unit->fcp_lun);
3547 zfcp_erp_unit_shutdown(unit, 0);
3548 retval = -EINVAL;
3549 }
3550 goto no_fit;
3551 }
3552
3553 /* set length of FCP data length in FCP_CMND IU in QTCB */
3554 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3555
3556 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3557 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3558 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3559
3560 /*
3561 * start QDIO request for this FSF request
3562 * covered by an SBALE)
3563 */
3564 retval = zfcp_fsf_req_send(fsf_req, timer);
3565 if (unlikely(retval < 0)) {
3566 ZFCP_LOG_INFO("error: Could not send FCP command request "
3567 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3568 zfcp_get_busid_by_adapter(adapter),
3569 unit->port->wwpn,
3570 unit->fcp_lun);
3571 goto send_failed;
3572 }
3573
3574 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3575 "port 0x%016Lx, unit 0x%016Lx)\n",
3576 zfcp_get_busid_by_adapter(adapter),
3577 unit->port->wwpn,
3578 unit->fcp_lun);
3579 goto success;
3580
3581 send_failed:
3582 no_fit:
3583 failed_scsi_cmnd:
3584 zfcp_fsf_req_free(fsf_req);
3585 fsf_req = NULL;
3586 scsi_cmnd->host_scribble = NULL;
3587 success:
3588 failed_req_create:
3589 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3590 return retval;
3591}
3592
3593/*
3594 * function: zfcp_fsf_send_fcp_command_task_management
3595 *
3596 * purpose:
3597 *
3598 * returns:
3599 *
3600 * FIXME(design): should be watched by a timeout!!!
3601 * FIXME(design) shouldn't this be modified to return an int
3602 * also...don't know how though
3603 *
3604 */
3605struct zfcp_fsf_req *
3606zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3607 struct zfcp_unit *unit,
3608 u8 tm_flags, int req_flags)
3609{
3610 struct zfcp_fsf_req *fsf_req = NULL;
3611 int retval = 0;
3612 struct fcp_cmnd_iu *fcp_cmnd_iu;
3613 unsigned long lock_flags;
3614 volatile struct qdio_buffer_element *sbale;
3615
3616 /* setup new FSF request */
3617 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3618 adapter->pool.fsf_req_scsi,
3619 &lock_flags, &fsf_req);
3620 if (retval < 0) {
3621 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3622 "management) request for adapter %s, port "
3623 " 0x%016Lx, unit 0x%016Lx.\n",
3624 zfcp_get_busid_by_adapter(adapter),
3625 unit->port->wwpn, unit->fcp_lun);
3626 goto out;
3627 }
3628
3629 /*
3630 * Used to decide on proper handler in the return path,
3631 * could be either zfcp_fsf_send_fcp_command_task_handler or
3632 * zfcp_fsf_send_fcp_command_task_management_handler */
3633
3634 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3635
3636 /*
3637 * hold a pointer to the unit being target of this
3638 * task management request
3639 */
3640 fsf_req->data.send_fcp_command_task_management.unit = unit;
3641
3642 /* set FSF related fields in QTCB */
3643 fsf_req->qtcb->header.lun_handle = unit->handle;
3644 fsf_req->qtcb->header.port_handle = unit->port->handle;
3645 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3646 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3647 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3648 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3649
3650 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3651 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3652 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3653
3654 /* set FCP related fields in FCP_CMND IU in QTCB */
3655 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3656 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3657 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3658 fcp_cmnd_iu->task_management_flags = tm_flags;
3659
3660 /* start QDIO request for this FSF request */
3661 zfcp_fsf_start_scsi_er_timer(adapter);
3662 retval = zfcp_fsf_req_send(fsf_req, NULL);
3663 if (retval) {
3664 del_timer(&adapter->scsi_er_timer);
3665 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3666 "management) on adapter %s, port 0x%016Lx for "
3667 "unit LUN 0x%016Lx\n",
3668 zfcp_get_busid_by_adapter(adapter),
3669 unit->port->wwpn,
3670 unit->fcp_lun);
3671 zfcp_fsf_req_free(fsf_req);
3672 fsf_req = NULL;
3673 goto out;
3674 }
3675
3676 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3677 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3678 "tm_flags=0x%x)\n",
3679 zfcp_get_busid_by_adapter(adapter),
3680 unit->port->wwpn,
3681 unit->fcp_lun,
3682 tm_flags);
3683 out:
3684 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3685 return fsf_req;
3686}
3687
3688/*
3689 * function: zfcp_fsf_send_fcp_command_handler
3690 *
3691 * purpose: is called for finished Send FCP Command
3692 *
3693 * returns:
3694 */
3695static int
3696zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3697{
3698 int retval = -EINVAL;
3699 struct zfcp_unit *unit;
3700 struct fsf_qtcb_header *header;
3701 u16 subtable, rule, counter;
3702
3703 header = &fsf_req->qtcb->header;
3704
3705 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3706 unit = fsf_req->data.send_fcp_command_task_management.unit;
3707 else
3708 unit = fsf_req->data.send_fcp_command_task.unit;
3709
3710 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3711 /* go directly to calls of special handlers */
3712 goto skip_fsfstatus;
3713 }
3714
3715 /* evaluate FSF status in QTCB */
3716 switch (header->fsf_status) {
3717
3718 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3720 "0x%016Lx on adapter %s invalid\n",
3721 unit->port->handle,
3722 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3723 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3724 (char *) &header->fsf_status_qual,
3725 sizeof (union fsf_status_qual));
3726 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3727 "fsf_s_phand_nv");
3728 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3729 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3730 break;
3731
3732 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3734 "0x%016Lx on port 0x%016Lx on adapter %s is "
3735 "invalid. This may happen occasionally.\n",
3736 unit->handle,
3737 unit->fcp_lun,
3738 unit->port->wwpn,
3739 zfcp_get_busid_by_unit(unit));
3740 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3741 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3742 (char *) &header->fsf_status_qual,
3743 sizeof (union fsf_status_qual));
3744 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3745 "fsf_s_uhand_nv");
3746 zfcp_erp_port_reopen(unit->port, 0);
3747 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3748 break;
3749
3750 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3752 "unexpectedly. (adapter %s, port 0x%016Lx, "
3753 "unit 0x%016Lx)\n",
3754 unit->port->handle,
3755 zfcp_get_busid_by_unit(unit),
3756 unit->port->wwpn,
3757 unit->fcp_lun);
3758 ZFCP_LOG_NORMAL("status qualifier:\n");
3759 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3760 (char *) &header->fsf_status_qual,
3761 sizeof (union fsf_status_qual));
3762 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3763 "fsf_s_hand_mis");
3764 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3765 zfcp_cmd_dbf_event_fsf("handmism",
3766 fsf_req,
3767 &header->fsf_status_qual,
3768 sizeof (union fsf_status_qual));
3769 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3770 break;
3771
3772 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 if (fsf_req->adapter->fc_service_class <= 3) {
3774 ZFCP_LOG_NORMAL("error: The adapter %s does "
3775 "not support fibrechannel class %d.\n",
3776 zfcp_get_busid_by_unit(unit),
3777 fsf_req->adapter->fc_service_class);
3778 } else {
3779 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3780 "adapter %s is invalid. "
3781 "(debug info %d)\n",
3782 zfcp_get_busid_by_unit(unit),
3783 fsf_req->adapter->fc_service_class);
3784 }
3785 /* stop operation for this adapter */
3786 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3787 "fsf_s_class_nsup");
3788 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3789 zfcp_cmd_dbf_event_fsf("unsclass",
3790 fsf_req,
3791 &header->fsf_status_qual,
3792 sizeof (union fsf_status_qual));
3793 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3794 break;
3795
3796 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3798 "adapter %s does not have correct unit "
3799 "handle 0x%x\n",
3800 unit->fcp_lun,
3801 unit->port->wwpn,
3802 zfcp_get_busid_by_unit(unit),
3803 unit->handle);
3804 ZFCP_LOG_DEBUG("status qualifier:\n");
3805 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3806 (char *) &header->fsf_status_qual,
3807 sizeof (union fsf_status_qual));
3808 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3809 "fsf_s_fcp_lun_nv");
3810 zfcp_erp_port_reopen(unit->port, 0);
3811 zfcp_cmd_dbf_event_fsf("fluninv",
3812 fsf_req,
3813 &header->fsf_status_qual,
3814 sizeof (union fsf_status_qual));
3815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3816 break;
3817
3818 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3820 "unit 0x%016Lx on port 0x%016Lx on "
3821 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3822 zfcp_get_busid_by_unit(unit));
3823 for (counter = 0; counter < 2; counter++) {
3824 subtable = header->fsf_status_qual.halfword[counter * 2];
3825 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3826 switch (subtable) {
3827 case FSF_SQ_CFDC_SUBTABLE_OS:
3828 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3829 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3830 case FSF_SQ_CFDC_SUBTABLE_LUN:
3831 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3832 zfcp_act_subtable_type[subtable], rule);
3833 break;
3834 }
3835 }
3836 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3837 zfcp_erp_unit_access_denied(unit);
3838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3839 break;
3840
3841 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3843 "0x%016Lx on port 0x%016Lx on adapter %s "
3844 "(debug info %d)\n",
3845 unit->fcp_lun,
3846 unit->port->wwpn,
3847 zfcp_get_busid_by_unit(unit),
3848 fsf_req->qtcb->bottom.io.data_direction);
3849 /* stop operation for this adapter */
3850 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3851 "fsf_s_dir_ind_nv");
3852 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3853 zfcp_cmd_dbf_event_fsf("dirinv",
3854 fsf_req,
3855 &header->fsf_status_qual,
3856 sizeof (union fsf_status_qual));
3857 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3858 break;
3859
3860 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 ZFCP_LOG_NORMAL
3862 ("bug: An invalid control-data-block length field "
3863 "was found in a command for unit 0x%016Lx on port "
3864 "0x%016Lx on adapter %s " "(debug info %d)\n",
3865 unit->fcp_lun, unit->port->wwpn,
3866 zfcp_get_busid_by_unit(unit),
3867 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3868 /* stop operation for this adapter */
3869 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3870 "fsf_s_cmd_len_nv");
3871 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3872 zfcp_cmd_dbf_event_fsf("cleninv",
3873 fsf_req,
3874 &header->fsf_status_qual,
3875 sizeof (union fsf_status_qual));
3876 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3877 break;
3878
3879 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3881 "needs to be reopened\n",
3882 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3883 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3884 zfcp_erp_port_reopen(unit->port, 0);
3885 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3886 &header->fsf_status_qual,
3887 sizeof (union fsf_status_qual));
3888 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3889 ZFCP_STATUS_FSFREQ_RETRY;
3890 break;
3891
3892 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3894 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3895 zfcp_get_busid_by_unit(unit),
3896 unit->port->wwpn, unit->fcp_lun);
3897 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3898 zfcp_erp_unit_reopen(unit, 0);
3899 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3900 &header->fsf_status_qual,
3901 sizeof(union fsf_status_qual));
3902 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3903 | ZFCP_STATUS_FSFREQ_RETRY;
3904 break;
3905
3906 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 switch (header->fsf_status_qual.word[0]) {
3908 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 /* re-establish link to port */
3910 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3911 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003912 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 break;
3914 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 /* FIXME(hw) need proper specs for proper action */
3916 /* let scsi stack deal with retries and escalation */
3917 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3918 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 break;
3920 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003922 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 header->fsf_status_qual.word[0]);
3924 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3925 "fsf_sq_inval:");
3926 debug_exception(fsf_req->adapter->erp_dbf, 0,
3927 &header->fsf_status_qual.word[0],
3928 sizeof(u32));
3929 break;
3930 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003931 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 break;
3933
3934 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 break;
3936
3937 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 break;
3939
3940 default:
3941 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3942 debug_exception(fsf_req->adapter->erp_dbf, 0,
3943 &header->fsf_status, sizeof(u32));
3944 break;
3945 }
3946
3947 skip_fsfstatus:
3948 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3949 retval =
3950 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3951 } else {
3952 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3953 }
3954 return retval;
3955}
3956
3957/*
3958 * function: zfcp_fsf_send_fcp_command_task_handler
3959 *
3960 * purpose: evaluates FCP_RSP IU
3961 *
3962 * returns:
3963 */
3964static int
3965zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3966{
3967 int retval = 0;
3968 struct scsi_cmnd *scpnt;
3969 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3970 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3971 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3972 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3973 u32 sns_len;
3974 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3975 unsigned long flags;
3976 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
3977
3978 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3979 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
3980 if (unlikely(!scpnt)) {
3981 ZFCP_LOG_DEBUG
3982 ("Command with fsf_req %p is not associated to "
3983 "a scsi command anymore. Aborted?\n", fsf_req);
3984 goto out;
3985 }
3986 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3987 /* FIXME: (design) mid-layer should handle DID_ABORT like
3988 * DID_SOFT_ERROR by retrying the request for devices
3989 * that allow retries.
3990 */
3991 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3992 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3993 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3994 goto skip_fsfstatus;
3995 }
3996
3997 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3998 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3999 set_host_byte(&scpnt->result, DID_ERROR);
4000 goto skip_fsfstatus;
4001 }
4002
4003 /* set message byte of result in SCSI command */
4004 scpnt->result |= COMMAND_COMPLETE << 8;
4005
4006 /*
4007 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4008 * of result in SCSI command
4009 */
4010 scpnt->result |= fcp_rsp_iu->scsi_status;
4011 if (unlikely(fcp_rsp_iu->scsi_status)) {
4012 /* DEBUG */
4013 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4014 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4015 scpnt->cmnd, scpnt->cmd_len);
4016 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4017 fcp_rsp_iu->scsi_status);
4018 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4019 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4020 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4021 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4022 fcp_rsp_iu->fcp_sns_len);
4023 }
4024
4025 /* check FCP_RSP_INFO */
4026 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4027 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4028 switch (fcp_rsp_info[3]) {
4029 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 /* ok, continue */
4031 ZFCP_LOG_TRACE("no failure or Task Management "
4032 "Function complete\n");
4033 set_host_byte(&scpnt->result, DID_OK);
4034 break;
4035 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 /* hardware bug */
4037 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4038 "that the fibrechannel protocol data "
4039 "length differs from the burst length. "
4040 "The problem occured on unit 0x%016Lx "
4041 "on port 0x%016Lx on adapter %s",
4042 unit->fcp_lun,
4043 unit->port->wwpn,
4044 zfcp_get_busid_by_unit(unit));
4045 /* dump SCSI CDB as prepared by zfcp */
4046 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4047 (char *) &fsf_req->qtcb->
4048 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4049 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4050 set_host_byte(&scpnt->result, DID_ERROR);
4051 goto skip_fsfstatus;
4052 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 /* driver or hardware bug */
4054 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4055 "that the fibrechannel protocol data "
4056 "fields were incorrectly set up. "
4057 "The problem occured on the unit "
4058 "0x%016Lx on port 0x%016Lx on "
4059 "adapter %s",
4060 unit->fcp_lun,
4061 unit->port->wwpn,
4062 zfcp_get_busid_by_unit(unit));
4063 /* dump SCSI CDB as prepared by zfcp */
4064 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4065 (char *) &fsf_req->qtcb->
4066 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4067 set_host_byte(&scpnt->result, DID_ERROR);
4068 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4069 goto skip_fsfstatus;
4070 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 /* hardware bug */
4072 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4073 "that conflicting values for the "
4074 "fibrechannel payload offset from the "
4075 "header were found. "
4076 "The problem occured on unit 0x%016Lx "
4077 "on port 0x%016Lx on adapter %s.\n",
4078 unit->fcp_lun,
4079 unit->port->wwpn,
4080 zfcp_get_busid_by_unit(unit));
4081 /* dump SCSI CDB as prepared by zfcp */
4082 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4083 (char *) &fsf_req->qtcb->
4084 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4085 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4086 set_host_byte(&scpnt->result, DID_ERROR);
4087 goto skip_fsfstatus;
4088 default:
4089 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4090 "code was detected for a command. "
4091 "The problem occured on the unit "
4092 "0x%016Lx on port 0x%016Lx on "
4093 "adapter %s (debug info 0x%x)\n",
4094 unit->fcp_lun,
4095 unit->port->wwpn,
4096 zfcp_get_busid_by_unit(unit),
4097 fcp_rsp_info[3]);
4098 /* dump SCSI CDB as prepared by zfcp */
4099 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4100 (char *) &fsf_req->qtcb->
4101 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4102 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4103 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004104 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 }
4106 }
4107
4108 /* check for sense data */
4109 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4110 sns_len = FSF_FCP_RSP_SIZE -
4111 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4112 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4113 sns_len);
4114 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4115 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4116 SCSI_SENSE_BUFFERSIZE);
4117 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4118 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4119 scpnt->result);
4120 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4121 (void *) &scpnt->cmnd, scpnt->cmd_len);
4122
4123 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4124 fcp_rsp_iu->fcp_sns_len);
4125 memcpy(&scpnt->sense_buffer,
4126 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4127 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4128 (void *) &scpnt->sense_buffer, sns_len);
4129 }
4130
4131 /* check for overrun */
4132 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4133 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4134 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4135 "The response data length is "
4136 "%d, the original length was %d.\n",
4137 unit->fcp_lun,
4138 unit->port->wwpn,
4139 zfcp_get_busid_by_unit(unit),
4140 fcp_rsp_iu->fcp_resid,
4141 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4142 }
4143
4144 /* check for underrun */
4145 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4146 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4147 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4148 "The response data length is "
4149 "%d, the original length was %d.\n",
4150 unit->fcp_lun,
4151 unit->port->wwpn,
4152 zfcp_get_busid_by_unit(unit),
4153 fcp_rsp_iu->fcp_resid,
4154 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4155
4156 scpnt->resid = fcp_rsp_iu->fcp_resid;
4157 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004158 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 }
4160
4161 skip_fsfstatus:
4162 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4163
4164 zfcp_cmd_dbf_event_scsi("response", scpnt);
4165
4166 /* cleanup pointer (need this especially for abort) */
4167 scpnt->host_scribble = NULL;
4168
4169 /*
4170 * NOTE:
4171 * according to the outcome of a discussion on linux-scsi we
4172 * don't need to grab the io_request_lock here since we use
4173 * the new eh
4174 */
4175 /* always call back */
4176
4177 (scpnt->scsi_done) (scpnt);
4178
4179 /*
4180 * We must hold this lock until scsi_done has been called.
4181 * Otherwise we may call scsi_done after abort regarding this
4182 * command has completed.
4183 * Note: scsi_done must not block!
4184 */
4185 out:
4186 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4187 return retval;
4188}
4189
4190/*
4191 * function: zfcp_fsf_send_fcp_command_task_management_handler
4192 *
4193 * purpose: evaluates FCP_RSP IU
4194 *
4195 * returns:
4196 */
4197static int
4198zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4199{
4200 int retval = 0;
4201 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4202 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4203 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4204 struct zfcp_unit *unit =
4205 fsf_req->data.send_fcp_command_task_management.unit;
4206
4207 del_timer(&fsf_req->adapter->scsi_er_timer);
4208 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4209 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4210 goto skip_fsfstatus;
4211 }
4212
4213 /* check FCP_RSP_INFO */
4214 switch (fcp_rsp_info[3]) {
4215 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 /* ok, continue */
4217 ZFCP_LOG_DEBUG("no failure or Task Management "
4218 "Function complete\n");
4219 break;
4220 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4222 "is not supported on the target device "
4223 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4224 unit->fcp_lun,
4225 unit->port->wwpn,
4226 zfcp_get_busid_by_unit(unit));
4227 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4228 break;
4229 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4231 "failed to complete successfully. "
4232 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4233 unit->fcp_lun,
4234 unit->port->wwpn,
4235 zfcp_get_busid_by_unit(unit));
4236 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4237 break;
4238 default:
4239 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4240 "code was detected for a command. "
4241 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4242 "(debug info 0x%x)\n",
4243 unit->fcp_lun,
4244 unit->port->wwpn,
4245 zfcp_get_busid_by_unit(unit),
4246 fcp_rsp_info[3]);
4247 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4248 }
4249
4250 skip_fsfstatus:
4251 return retval;
4252}
4253
4254
4255/*
4256 * function: zfcp_fsf_control_file
4257 *
4258 * purpose: Initiator of the control file upload/download FSF requests
4259 *
4260 * returns: 0 - FSF request is successfuly created and queued
4261 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4262 * -EINVAL - Invalid direction specified
4263 * -ENOMEM - Insufficient memory
4264 * -EPERM - Cannot create FSF request or place it in QDIO queue
4265 */
4266int
4267zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4268 struct zfcp_fsf_req **fsf_req_ptr,
4269 u32 fsf_command,
4270 u32 option,
4271 struct zfcp_sg_list *sg_list)
4272{
4273 struct zfcp_fsf_req *fsf_req;
4274 struct fsf_qtcb_bottom_support *bottom;
4275 volatile struct qdio_buffer_element *sbale;
4276 struct timer_list *timer;
4277 unsigned long lock_flags;
4278 int req_flags = 0;
4279 int direction;
4280 int retval = 0;
4281
4282 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4283 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4284 zfcp_get_busid_by_adapter(adapter));
4285 retval = -EOPNOTSUPP;
4286 goto out;
4287 }
4288
4289 switch (fsf_command) {
4290
4291 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4292 direction = SBAL_FLAGS0_TYPE_WRITE;
4293 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4294 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4295 req_flags = ZFCP_WAIT_FOR_SBAL;
4296 break;
4297
4298 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4299 direction = SBAL_FLAGS0_TYPE_READ;
4300 break;
4301
4302 default:
4303 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4304 retval = -EINVAL;
4305 goto out;
4306 }
4307
4308 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4309 if (!timer) {
4310 retval = -ENOMEM;
4311 goto out;
4312 }
4313
4314 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4315 NULL, &lock_flags, &fsf_req);
4316 if (retval < 0) {
4317 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4318 "adapter %s\n",
4319 zfcp_get_busid_by_adapter(adapter));
4320 retval = -EPERM;
4321 goto unlock_queue_lock;
4322 }
4323
4324 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4325 sbale[0].flags |= direction;
4326
4327 bottom = &fsf_req->qtcb->bottom.support;
4328 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4329 bottom->option = option;
4330
4331 if (sg_list->count > 0) {
4332 int bytes;
4333
4334 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4335 sg_list->sg, sg_list->count,
4336 ZFCP_MAX_SBALS_PER_REQ);
4337 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4338 ZFCP_LOG_INFO(
4339 "error: Could not create sufficient number of "
4340 "SBALS for an FSF request to the adapter %s\n",
4341 zfcp_get_busid_by_adapter(adapter));
4342 retval = -ENOMEM;
4343 goto free_fsf_req;
4344 }
4345 } else
4346 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4347
4348 init_timer(timer);
4349 timer->function = zfcp_fsf_request_timeout_handler;
4350 timer->data = (unsigned long) adapter;
4351 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4352
4353 retval = zfcp_fsf_req_send(fsf_req, timer);
4354 if (retval < 0) {
4355 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4356 "(adapter %s)\n",
4357 zfcp_get_busid_by_adapter(adapter));
4358 retval = -EPERM;
4359 goto free_fsf_req;
4360 }
4361 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4362
4363 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4364 "adapter %s\n",
4365 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4366 "download" : "upload",
4367 zfcp_get_busid_by_adapter(adapter));
4368
4369 wait_event(fsf_req->completion_wq,
4370 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4371
4372 *fsf_req_ptr = fsf_req;
4373 del_timer_sync(timer);
4374 goto free_timer;
4375
4376 free_fsf_req:
4377 zfcp_fsf_req_free(fsf_req);
4378 unlock_queue_lock:
4379 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4380 free_timer:
4381 kfree(timer);
4382 out:
4383 return retval;
4384}
4385
4386
4387/*
4388 * function: zfcp_fsf_control_file_handler
4389 *
4390 * purpose: Handler of the control file upload/download FSF requests
4391 *
4392 * returns: 0 - FSF request successfuly processed
4393 * -EAGAIN - Operation has to be repeated because of a temporary problem
4394 * -EACCES - There is no permission to execute an operation
4395 * -EPERM - The control file is not in a right format
4396 * -EIO - There is a problem with the FCP adapter
4397 * -EINVAL - Invalid operation
4398 * -EFAULT - User space memory I/O operation fault
4399 */
4400static int
4401zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4402{
4403 struct zfcp_adapter *adapter = fsf_req->adapter;
4404 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4405 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4406 int retval = 0;
4407
4408 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4409 retval = -EINVAL;
4410 goto skip_fsfstatus;
4411 }
4412
4413 switch (header->fsf_status) {
4414
4415 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 ZFCP_LOG_NORMAL(
4417 "The FSF request has been successfully completed "
4418 "on the adapter %s\n",
4419 zfcp_get_busid_by_adapter(adapter));
4420 break;
4421
4422 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4424 switch (header->fsf_status_qual.word[0]) {
4425
6f71d9b2005-04-10 23:04:28 -05004426 case FSF_SQ_CFDC_HARDENED_ON_SE:
4427 ZFCP_LOG_NORMAL(
4428 "CFDC on the adapter %s has being "
4429 "hardened on primary and secondary SE\n",
4430 zfcp_get_busid_by_adapter(adapter));
4431 break;
4432
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4434 ZFCP_LOG_NORMAL(
4435 "CFDC of the adapter %s could not "
4436 "be saved on the SE\n",
4437 zfcp_get_busid_by_adapter(adapter));
4438 break;
4439
4440 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4441 ZFCP_LOG_NORMAL(
4442 "CFDC of the adapter %s could not "
4443 "be copied to the secondary SE\n",
4444 zfcp_get_busid_by_adapter(adapter));
4445 break;
4446
4447 default:
4448 ZFCP_LOG_NORMAL(
4449 "CFDC could not be hardened "
4450 "on the adapter %s\n",
4451 zfcp_get_busid_by_adapter(adapter));
4452 }
4453 }
4454 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4455 retval = -EAGAIN;
4456 break;
4457
4458 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 ZFCP_LOG_NORMAL(
4460 "Adapter %s does not accept privileged commands\n",
4461 zfcp_get_busid_by_adapter(adapter));
4462 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4463 retval = -EACCES;
4464 break;
4465
4466 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 ZFCP_LOG_NORMAL(
4468 "Error at position %d in the CFDC, "
4469 "CFDC is discarded by the adapter %s\n",
4470 header->fsf_status_qual.word[0],
4471 zfcp_get_busid_by_adapter(adapter));
4472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4473 retval = -EPERM;
4474 break;
4475
4476 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 ZFCP_LOG_NORMAL(
4478 "Adapter %s cannot harden the control file, "
4479 "file is discarded\n",
4480 zfcp_get_busid_by_adapter(adapter));
4481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4482 retval = -EIO;
4483 break;
4484
4485 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 ZFCP_LOG_NORMAL(
4487 "Control file is too large, file is discarded "
4488 "by the adapter %s\n",
4489 zfcp_get_busid_by_adapter(adapter));
4490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4491 retval = -EIO;
4492 break;
4493
4494 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4496 ZFCP_LOG_NORMAL(
4497 "CFDC has been discarded by the adapter %s, "
4498 "because activation would impact "
4499 "%d active connection(s)\n",
4500 zfcp_get_busid_by_adapter(adapter),
4501 header->fsf_status_qual.word[0]);
4502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4503 retval = -EIO;
4504 break;
4505
4506 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4508 ZFCP_LOG_NORMAL(
4509 "CFDC has been activated on the adapter %s, "
4510 "but activation has impacted "
4511 "%d active connection(s)\n",
4512 zfcp_get_busid_by_adapter(adapter),
4513 header->fsf_status_qual.word[0]);
4514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4515 retval = -EIO;
4516 break;
4517
4518 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4520 "op_subtype=0x%x)\n",
4521 zfcp_get_busid_by_adapter(adapter),
4522 bottom->operation_subtype);
4523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4524 retval = -EINVAL;
4525 break;
4526
4527 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 ZFCP_LOG_NORMAL(
4529 "Invalid option 0x%x has been specified "
4530 "in QTCB bottom sent to the adapter %s\n",
4531 bottom->option,
4532 zfcp_get_busid_by_adapter(adapter));
4533 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4534 retval = -EINVAL;
4535 break;
4536
4537 default:
4538 ZFCP_LOG_NORMAL(
4539 "bug: An unknown/unexpected FSF status 0x%08x "
4540 "was presented on the adapter %s\n",
4541 header->fsf_status,
4542 zfcp_get_busid_by_adapter(adapter));
4543 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4544 debug_exception(fsf_req->adapter->erp_dbf, 0,
4545 &header->fsf_status_qual.word[0], sizeof(u32));
4546 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4547 retval = -EINVAL;
4548 break;
4549 }
4550
4551skip_fsfstatus:
4552 return retval;
4553}
4554
4555
4556/*
4557 * function: zfcp_fsf_req_wait_and_cleanup
4558 *
4559 * purpose:
4560 *
4561 * FIXME(design): signal seems to be <0 !!!
4562 * returns: 0 - request completed (*status is valid), cleanup succ.
4563 * <0 - request completed (*status is valid), cleanup failed
4564 * >0 - signal which interrupted waiting (*status invalid),
4565 * request not completed, no cleanup
4566 *
4567 * *status is a copy of status of completed fsf_req
4568 */
4569int
4570zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4571 int interruptible, u32 * status)
4572{
4573 int retval = 0;
4574 int signal = 0;
4575
4576 if (interruptible) {
4577 __wait_event_interruptible(fsf_req->completion_wq,
4578 fsf_req->status &
4579 ZFCP_STATUS_FSFREQ_COMPLETED,
4580 signal);
4581 if (signal) {
4582 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4583 "completion of the request at %p\n",
4584 signal, fsf_req);
4585 retval = signal;
4586 goto out;
4587 }
4588 } else {
4589 __wait_event(fsf_req->completion_wq,
4590 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4591 }
4592
4593 *status = fsf_req->status;
4594
4595 /* cleanup request */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004596 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 out:
4598 return retval;
4599}
4600
4601static inline int
4602zfcp_fsf_req_sbal_check(unsigned long *flags,
4603 struct zfcp_qdio_queue *queue, int needed)
4604{
4605 write_lock_irqsave(&queue->queue_lock, *flags);
4606 if (likely(atomic_read(&queue->free_count) >= needed))
4607 return 1;
4608 write_unlock_irqrestore(&queue->queue_lock, *flags);
4609 return 0;
4610}
4611
4612/*
4613 * set qtcb pointer in fsf_req and initialize QTCB
4614 */
4615static inline void
4616zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4617{
4618 if (likely(fsf_req->qtcb != NULL)) {
4619 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4620 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4621 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4622 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4623 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4624 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4625 }
4626}
4627
4628/**
4629 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4630 * @adapter: adapter for which request queue is examined
4631 * @req_flags: flags indicating whether to wait for needed SBAL or not
4632 * @lock_flags: lock_flags if queue_lock is taken
4633 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4634 * Locks: lock adapter->request_queue->queue_lock on success
4635 */
4636static int
4637zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4638 unsigned long *lock_flags)
4639{
4640 long ret;
4641 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4642
4643 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4644 ret = wait_event_interruptible_timeout(adapter->request_wq,
4645 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4646 ZFCP_SBAL_TIMEOUT);
4647 if (ret < 0)
4648 return ret;
4649 if (!ret)
4650 return -EIO;
4651 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4652 return -EIO;
4653
4654 return 0;
4655}
4656
4657/*
4658 * function: zfcp_fsf_req_create
4659 *
4660 * purpose: create an FSF request at the specified adapter and
4661 * setup common fields
4662 *
4663 * returns: -ENOMEM if there was insufficient memory for a request
4664 * -EIO if no qdio buffers could be allocate to the request
4665 * -EINVAL/-EPERM on bug conditions in req_dequeue
4666 * 0 in success
4667 *
4668 * note: The created request is returned by reference.
4669 *
4670 * locks: lock of concerned request queue must not be held,
4671 * but is held on completion (write, irqsave)
4672 */
4673int
4674zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4675 mempool_t *pool, unsigned long *lock_flags,
4676 struct zfcp_fsf_req **fsf_req_p)
4677{
4678 volatile struct qdio_buffer_element *sbale;
4679 struct zfcp_fsf_req *fsf_req = NULL;
4680 int ret = 0;
4681 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4682
4683 /* allocate new FSF request */
4684 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4685 if (unlikely(NULL == fsf_req)) {
4686 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4687 "the outbound (send) queue.\n");
4688 ret = -ENOMEM;
4689 goto failed_fsf_req;
4690 }
4691
4692 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4693
4694 /* initialize waitqueue which may be used to wait on
4695 this request completion */
4696 init_waitqueue_head(&fsf_req->completion_wq);
4697
4698 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4699 if(ret < 0) {
4700 goto failed_sbals;
4701 }
4702
4703 /*
4704 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4705 * if it is not set (see also *_open_qdio and *_close_qdio).
4706 */
4707
4708 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4709 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4710 ret = -EIO;
4711 goto failed_sbals;
4712 }
4713
4714 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4715 fsf_req->fsf_command = fsf_cmd;
4716 fsf_req->sbal_number = 1;
4717 fsf_req->sbal_first = req_queue->free_index;
4718 fsf_req->sbal_curr = req_queue->free_index;
4719 fsf_req->sbale_curr = 1;
4720
4721 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4722 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4723 }
4724
4725 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4726
4727 /* setup common SBALE fields */
4728 sbale[0].addr = fsf_req;
4729 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4730 if (likely(fsf_req->qtcb != NULL)) {
4731 sbale[1].addr = (void *) fsf_req->qtcb;
4732 sbale[1].length = sizeof(struct fsf_qtcb);
4733 }
4734
4735 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4736 fsf_req->sbal_number, fsf_req->sbal_first);
4737
4738 goto success;
4739
4740 failed_sbals:
4741/* dequeue new FSF request previously enqueued */
4742 zfcp_fsf_req_free(fsf_req);
4743 fsf_req = NULL;
4744
4745 failed_fsf_req:
4746 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4747 success:
4748 *fsf_req_p = fsf_req;
4749 return ret;
4750}
4751
4752/*
4753 * function: zfcp_fsf_req_send
4754 *
4755 * purpose: start transfer of FSF request via QDIO
4756 *
4757 * returns: 0 - request transfer succesfully started
4758 * !0 - start of request transfer failed
4759 */
4760static int
4761zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4762{
4763 struct zfcp_adapter *adapter;
4764 struct zfcp_qdio_queue *req_queue;
4765 volatile struct qdio_buffer_element *sbale;
4766 int new_distance_from_int;
4767 unsigned long flags;
4768 int inc_seq_no = 1;
4769 int retval = 0;
4770
4771 adapter = fsf_req->adapter;
4772 req_queue = &adapter->request_queue,
4773
4774
4775 /* FIXME(debug): remove it later */
4776 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4777 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4778 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4779 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4780 sbale[1].length);
4781
4782 /* set sequence counter in QTCB */
4783 if (likely(fsf_req->qtcb)) {
4784 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4785 fsf_req->seq_no = adapter->fsf_req_seq_no;
4786 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4787 "FSF sequence counter value of %i\n",
4788 fsf_req,
4789 zfcp_get_busid_by_adapter(adapter),
4790 fsf_req->qtcb->prefix.req_seq_no);
4791 } else
4792 inc_seq_no = 0;
4793
4794 /* put allocated FSF request at list tail */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004795 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004797 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798
4799 /* figure out expiration time of timeout and start timeout */
4800 if (unlikely(timer)) {
4801 timer->expires += jiffies;
4802 add_timer(timer);
4803 }
4804
4805 ZFCP_LOG_TRACE("request queue of adapter %s: "
4806 "next free SBAL is %i, %i free SBALs\n",
4807 zfcp_get_busid_by_adapter(adapter),
4808 req_queue->free_index,
4809 atomic_read(&req_queue->free_count));
4810
4811 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4812 "index_in_queue=%i, count=%i, buffers=%p\n",
4813 zfcp_get_busid_by_adapter(adapter),
4814 QDIO_FLAG_SYNC_OUTPUT,
4815 0, fsf_req->sbal_first, fsf_req->sbal_number,
4816 &req_queue->buffer[fsf_req->sbal_first]);
4817
4818 /*
4819 * adjust the number of free SBALs in request queue as well as
4820 * position of first one
4821 */
4822 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4823 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4824 req_queue->free_index += fsf_req->sbal_number; /* increase */
4825 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4826 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4827
4828 retval = do_QDIO(adapter->ccw_device,
4829 QDIO_FLAG_SYNC_OUTPUT,
4830 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4831
4832 if (unlikely(retval)) {
4833 /* Queues are down..... */
4834 retval = -EIO;
4835 /*
4836 * FIXME(potential race):
4837 * timer might be expired (absolutely unlikely)
4838 */
4839 if (timer)
4840 del_timer(timer);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004841 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 list_del(&fsf_req->list);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004843 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 /*
4845 * adjust the number of free SBALs in request queue as well as
4846 * position of first one
4847 */
4848 zfcp_qdio_zero_sbals(req_queue->buffer,
4849 fsf_req->sbal_first, fsf_req->sbal_number);
4850 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4851 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4852 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4853 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4854 ZFCP_LOG_DEBUG
4855 ("error: do_QDIO failed. Buffers could not be enqueued "
4856 "to request queue.\n");
4857 } else {
4858 req_queue->distance_from_int = new_distance_from_int;
4859 /*
4860 * increase FSF sequence counter -
4861 * this must only be done for request successfully enqueued to
4862 * QDIO this rejected requests may be cleaned up by calling
4863 * routines resulting in missing sequence counter values
4864 * otherwise,
4865 */
4866 /* Don't increase for unsolicited status */
4867 if (likely(inc_seq_no)) {
4868 adapter->fsf_req_seq_no++;
4869 ZFCP_LOG_TRACE
4870 ("FSF sequence counter value of adapter %s "
4871 "increased to %i\n",
4872 zfcp_get_busid_by_adapter(adapter),
4873 adapter->fsf_req_seq_no);
4874 }
4875 /* count FSF requests pending */
4876 atomic_inc(&adapter->fsf_reqs_active);
4877 }
4878 return retval;
4879}
4880
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881#undef ZFCP_LOG_AREA