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