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