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