[SCSI] mpt fusion: make struct mpt_proc_root_dir static
[GitHub/mt8127/android_kernel_alcatel_ttab.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);
1f6f7129 301 zfcp_erp_adapter_shutdown(adapter, 0, 117, 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);
1f6f7129 312 zfcp_erp_adapter_reopen(adapter, 0, 98, 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));
1f6f7129 323 zfcp_erp_adapter_shutdown(adapter, 0, 118, 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));
1f6f7129 340 zfcp_erp_adapter_shutdown(adapter, 0, 78, 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 347 /* FIXME: reopening adapter now? better wait for link up */
1f6f7129 348 zfcp_erp_adapter_reopen(adapter, 0, 79, 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 */
1f6f7129
MP
358 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
359 ZFCP_STATUS_COMMON_RUNNING,
1da177e4
LT
360 ZFCP_SET);
361 zfcp_erp_adapter_reopen(adapter,
362 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
9467a9b3 363 | ZFCP_STATUS_COMMON_ERP_FAILED,
1f6f7129 364 99, 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));
1f6f7129 374 zfcp_erp_adapter_reopen(adapter, 0, 100, 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);
1f6f7129 387 zfcp_erp_adapter_shutdown(adapter, 0, 119, 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);
1f6f7129 426 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
1da177e4
LT
427 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
428 break;
429
430 case FSF_FCP_RSP_AVAILABLE:
1da177e4
LT
431 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
432 "SCSI stack.\n");
1da177e4
LT
433 break;
434
435 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
436 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
437 break;
1da177e4
LT
438 }
439
440 skip_fsfstatus:
441 /*
442 * always call specific handlers to give them a chance to do
443 * something meaningful even in error cases
444 */
445 zfcp_fsf_req_dispatch(fsf_req);
446
447 return retval;
448}
449
450/*
451 * function: zfcp_fsf_fsfstatus_qual_eval
452 *
453 * purpose: evaluates FSF status-qualifier of completed FSF request
454 * and acts accordingly
455 *
456 * returns:
457 */
458static int
459zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
460{
461 int retval = 0;
462
463 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
464 case FSF_SQ_FCP_RSP_AVAILABLE:
1da177e4
LT
465 break;
466 case FSF_SQ_RETRY_IF_POSSIBLE:
1da177e4 467 /* The SCSI-stack may now issue retries or escalate */
1da177e4
LT
468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
469 break;
470 case FSF_SQ_COMMAND_ABORTED:
1da177e4 471 /* Carry the aborted state on to upper layer */
1da177e4
LT
472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
474 break;
475 case FSF_SQ_NO_RECOM:
ceb3dfba 476 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
1da177e4
LT
477 "problem on the adapter %s "
478 "Stopping all operations on this adapter. ",
479 zfcp_get_busid_by_adapter(fsf_req->adapter));
1f6f7129 480 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
1da177e4
LT
481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
482 break;
483 case FSF_SQ_ULP_PROGRAMMING_ERROR:
1da177e4
LT
484 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
485 "(adapter %s)\n",
486 zfcp_get_busid_by_adapter(fsf_req->adapter));
1da177e4
LT
487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
488 break;
489 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
490 case FSF_SQ_NO_RETRY_POSSIBLE:
491 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
492 /* dealt with in the respective functions */
493 break;
494 default:
495 ZFCP_LOG_NORMAL("bug: Additional status info could "
496 "not be interpreted properly.\n");
497 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
498 (char *) &fsf_req->qtcb->header.fsf_status_qual,
499 sizeof (union fsf_status_qual));
1da177e4
LT
500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
501 break;
502 }
503
504 return retval;
505}
506
aef4a983
MS
507/**
508 * zfcp_fsf_link_down_info_eval - evaluate link down information block
509 */
510static void
698ec016 511zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
aef4a983
MS
512 struct fsf_link_down_info *link_down)
513{
698ec016
MP
514 struct zfcp_adapter *adapter = fsf_req->adapter;
515
ee69ab7a
MS
516 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
517 &adapter->status))
518 return;
519
520 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
521
2f8f3ed5
AH
522 if (link_down == NULL)
523 goto out;
ee69ab7a 524
aef4a983
MS
525 switch (link_down->error_code) {
526 case FSF_PSQ_LINK_NO_LIGHT:
527 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
528 "(no light detected)\n",
529 zfcp_get_busid_by_adapter(adapter));
530 break;
531 case FSF_PSQ_LINK_WRAP_PLUG:
532 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
533 "(wrap plug detected)\n",
534 zfcp_get_busid_by_adapter(adapter));
535 break;
536 case FSF_PSQ_LINK_NO_FCP:
537 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
538 "(adjacent node on link does not support FCP)\n",
539 zfcp_get_busid_by_adapter(adapter));
540 break;
541 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
542 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
543 "(firmware update in progress)\n",
544 zfcp_get_busid_by_adapter(adapter));
545 break;
546 case FSF_PSQ_LINK_INVALID_WWPN:
547 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
548 "(duplicate or invalid WWPN detected)\n",
549 zfcp_get_busid_by_adapter(adapter));
550 break;
551 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
552 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
553 "(no support for NPIV by Fabric)\n",
554 zfcp_get_busid_by_adapter(adapter));
555 break;
556 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
557 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
558 "(out of resource in FCP daughtercard)\n",
559 zfcp_get_busid_by_adapter(adapter));
560 break;
561 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
562 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
563 "(out of resource in Fabric)\n",
564 zfcp_get_busid_by_adapter(adapter));
565 break;
566 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
567 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
568 "(unable to Fabric login)\n",
569 zfcp_get_busid_by_adapter(adapter));
570 break;
571 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
572 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
573 zfcp_get_busid_by_adapter(adapter));
574 break;
575 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
576 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
577 zfcp_get_busid_by_adapter(adapter));
578 break;
579 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
580 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
581 zfcp_get_busid_by_adapter(adapter));
582 break;
583 default:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(warning: unknown reason code %d)\n",
586 zfcp_get_busid_by_adapter(adapter),
587 link_down->error_code);
588 }
589
590 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
591 ZFCP_LOG_DEBUG("Debug information to link down: "
592 "primary_status=0x%02x "
593 "ioerr_code=0x%02x "
594 "action_code=0x%02x "
595 "reason_code=0x%02x "
596 "explanation_code=0x%02x "
597 "vendor_specific_code=0x%02x\n",
598 link_down->primary_status,
599 link_down->ioerr_code,
600 link_down->action_code,
601 link_down->reason_code,
602 link_down->explanation_code,
603 link_down->vendor_specific_code);
604
2f8f3ed5 605 out:
1f6f7129 606 zfcp_erp_adapter_failed(adapter, id, fsf_req);
aef4a983
MS
607}
608
1da177e4
LT
609/*
610 * function: zfcp_fsf_req_dispatch
611 *
612 * purpose: calls the appropriate command specific handler
613 *
41fa2ada 614 * returns:
1da177e4
LT
615 */
616static int
617zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
618{
619 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
620 struct zfcp_adapter *adapter = fsf_req->adapter;
621 int retval = 0;
622
1da177e4
LT
623
624 switch (fsf_req->fsf_command) {
625
626 case FSF_QTCB_FCP_CMND:
1da177e4
LT
627 zfcp_fsf_send_fcp_command_handler(fsf_req);
628 break;
629
630 case FSF_QTCB_ABORT_FCP_CMND:
1da177e4
LT
631 zfcp_fsf_abort_fcp_command_handler(fsf_req);
632 break;
633
634 case FSF_QTCB_SEND_GENERIC:
1da177e4
LT
635 zfcp_fsf_send_ct_handler(fsf_req);
636 break;
637
638 case FSF_QTCB_OPEN_PORT_WITH_DID:
1da177e4
LT
639 zfcp_fsf_open_port_handler(fsf_req);
640 break;
641
642 case FSF_QTCB_OPEN_LUN:
1da177e4
LT
643 zfcp_fsf_open_unit_handler(fsf_req);
644 break;
645
646 case FSF_QTCB_CLOSE_LUN:
1da177e4
LT
647 zfcp_fsf_close_unit_handler(fsf_req);
648 break;
649
650 case FSF_QTCB_CLOSE_PORT:
1da177e4
LT
651 zfcp_fsf_close_port_handler(fsf_req);
652 break;
653
654 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
1da177e4
LT
655 zfcp_fsf_close_physical_port_handler(fsf_req);
656 break;
657
658 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
1da177e4
LT
659 zfcp_fsf_exchange_config_data_handler(fsf_req);
660 break;
661
662 case FSF_QTCB_EXCHANGE_PORT_DATA:
1da177e4
LT
663 zfcp_fsf_exchange_port_data_handler(fsf_req);
664 break;
665
666 case FSF_QTCB_SEND_ELS:
1da177e4
LT
667 zfcp_fsf_send_els_handler(fsf_req);
668 break;
669
670 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
1da177e4
LT
671 zfcp_fsf_control_file_handler(fsf_req);
672 break;
673
674 case FSF_QTCB_UPLOAD_CONTROL_FILE:
1da177e4
LT
675 zfcp_fsf_control_file_handler(fsf_req);
676 break;
677
678 default:
1da177e4
LT
679 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
680 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
681 "not supported by the adapter %s\n",
8a36e453 682 zfcp_get_busid_by_adapter(adapter));
1da177e4
LT
683 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
684 ZFCP_LOG_NORMAL
685 ("bug: Command issued by the device driver differs "
686 "from the command returned by the adapter %s "
687 "(debug info 0x%x, 0x%x).\n",
8a36e453 688 zfcp_get_busid_by_adapter(adapter),
1da177e4
LT
689 fsf_req->fsf_command,
690 fsf_req->qtcb->header.fsf_command);
691 }
692
693 if (!erp_action)
694 return retval;
695
1da177e4
LT
696 zfcp_erp_async_handler(erp_action, 0);
697
698 return retval;
699}
700
701/*
702 * function: zfcp_fsf_status_read
703 *
704 * purpose: initiates a Status Read command at the specified adapter
705 *
706 * returns:
707 */
708int
709zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
710{
711 struct zfcp_fsf_req *fsf_req;
712 struct fsf_status_read_buffer *status_buffer;
713 unsigned long lock_flags;
714 volatile struct qdio_buffer_element *sbale;
715 int retval = 0;
716
717 /* setup new FSF request */
718 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
719 req_flags | ZFCP_REQ_NO_QTCB,
720 adapter->pool.fsf_req_status_read,
721 &lock_flags, &fsf_req);
722 if (retval < 0) {
723 ZFCP_LOG_INFO("error: Could not create unsolicited status "
724 "buffer for adapter %s.\n",
725 zfcp_get_busid_by_adapter(adapter));
726 goto failed_req_create;
727 }
728
729 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
730 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
731 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
732 fsf_req->sbale_curr = 2;
733
734 status_buffer =
735 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
736 if (!status_buffer) {
737 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
738 goto failed_buf;
739 }
740 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
059c97d0 741 fsf_req->data = (unsigned long) status_buffer;
1da177e4
LT
742
743 /* insert pointer to respective buffer */
744 sbale = zfcp_qdio_sbale_curr(fsf_req);
745 sbale->addr = (void *) status_buffer;
746 sbale->length = sizeof(struct fsf_status_read_buffer);
747
2abbe866 748 retval = zfcp_fsf_req_send(fsf_req);
1da177e4
LT
749 if (retval) {
750 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
751 "environment.\n");
752 goto failed_req_send;
753 }
754
755 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
756 zfcp_get_busid_by_adapter(adapter));
757 goto out;
758
759 failed_req_send:
760 mempool_free(status_buffer, adapter->pool.data_status_read);
761
762 failed_buf:
763 zfcp_fsf_req_free(fsf_req);
764 failed_req_create:
8a36e453 765 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
1da177e4
LT
766 out:
767 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
768 return retval;
769}
770
771static int
772zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
773{
774 struct fsf_status_read_buffer *status_buffer;
775 struct zfcp_adapter *adapter;
776 struct zfcp_port *port;
777 unsigned long flags;
778
059c97d0 779 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
1da177e4
LT
780 adapter = fsf_req->adapter;
781
782 read_lock_irqsave(&zfcp_data.config_lock, flags);
783 list_for_each_entry(port, &adapter->port_list_head, list)
784 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
785 break;
786 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
787
788 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
ceb3dfba 789 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
1d589edf 790 "nonexisting port with d_id 0x%06x on "
1da177e4
LT
791 "adapter %s. Ignored.\n",
792 status_buffer->d_id & ZFCP_DID_MASK,
793 zfcp_get_busid_by_adapter(adapter));
794 goto out;
795 }
796
797 switch (status_buffer->status_subtype) {
798
799 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
1f6f7129 800 zfcp_erp_port_reopen(port, 0, 101, fsf_req);
1da177e4
LT
801 break;
802
803 case FSF_STATUS_READ_SUB_ERROR_PORT:
1f6f7129 804 zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
1da177e4
LT
805 break;
806
807 default:
1da177e4
LT
808 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
809 "for a reopen indication on port with "
1d589edf 810 "d_id 0x%06x on the adapter %s. "
1da177e4
LT
811 "Ignored. (debug info 0x%x)\n",
812 status_buffer->d_id,
813 zfcp_get_busid_by_adapter(adapter),
814 status_buffer->status_subtype);
815 }
816 out:
817 return 0;
818}
819
820/*
821 * function: zfcp_fsf_status_read_handler
822 *
823 * purpose: is called for finished Open Port command
824 *
41fa2ada 825 * returns:
1da177e4
LT
826 */
827static int
828zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
829{
830 int retval = 0;
831 struct zfcp_adapter *adapter = fsf_req->adapter;
832 struct fsf_status_read_buffer *status_buffer =
059c97d0 833 (struct fsf_status_read_buffer *) fsf_req->data;
b7a52fa7 834 struct fsf_bit_error_payload *fsf_bit_error;
1da177e4
LT
835
836 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
8a36e453 837 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
1da177e4 838 mempool_free(status_buffer, adapter->pool.data_status_read);
1db2c9c0 839 zfcp_fsf_req_free(fsf_req);
1da177e4
LT
840 goto out;
841 }
842
8a36e453
MS
843 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
844
1da177e4
LT
845 switch (status_buffer->status_type) {
846
847 case FSF_STATUS_READ_PORT_CLOSED:
1da177e4
LT
848 zfcp_fsf_status_read_port_closed(fsf_req);
849 break;
850
851 case FSF_STATUS_READ_INCOMING_ELS:
1da177e4
LT
852 zfcp_fsf_incoming_els(fsf_req);
853 break;
854
855 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
1da177e4
LT
856 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
857 zfcp_get_busid_by_adapter(adapter));
1da177e4
LT
858 break;
859
860 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
b7a52fa7
RW
861 fsf_bit_error = (struct fsf_bit_error_payload *)
862 status_buffer->payload;
863 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
864 "received (adapter %s, "
865 "link failures = %i, loss of sync errors = %i, "
866 "loss of signal errors = %i, "
867 "primitive sequence errors = %i, "
868 "invalid transmission word errors = %i, "
869 "CRC errors = %i)\n",
870 zfcp_get_busid_by_adapter(adapter),
871 fsf_bit_error->link_failure_error_count,
872 fsf_bit_error->loss_of_sync_error_count,
873 fsf_bit_error->loss_of_signal_error_count,
874 fsf_bit_error->primitive_sequence_error_count,
875 fsf_bit_error->invalid_transmission_word_error_count,
876 fsf_bit_error->crc_error_count);
877 ZFCP_LOG_INFO("Additional bit error threshold data "
878 "(adapter %s, "
879 "primitive sequence event time-outs = %i, "
880 "elastic buffer overrun errors = %i, "
881 "advertised receive buffer-to-buffer credit = %i, "
882 "current receice buffer-to-buffer credit = %i, "
883 "advertised transmit buffer-to-buffer credit = %i, "
884 "current transmit buffer-to-buffer credit = %i)\n",
885 zfcp_get_busid_by_adapter(adapter),
886 fsf_bit_error->primitive_sequence_event_timeout_count,
887 fsf_bit_error->elastic_buffer_overrun_error_count,
888 fsf_bit_error->advertised_receive_b2b_credit,
889 fsf_bit_error->current_receive_b2b_credit,
890 fsf_bit_error->advertised_transmit_b2b_credit,
891 fsf_bit_error->current_transmit_b2b_credit);
1da177e4
LT
892 break;
893
894 case FSF_STATUS_READ_LINK_DOWN:
aef4a983
MS
895 switch (status_buffer->status_subtype) {
896 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
897 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
898 zfcp_get_busid_by_adapter(adapter));
698ec016 899 zfcp_fsf_link_down_info_eval(fsf_req, 38,
ee69ab7a
MS
900 (struct fsf_link_down_info *)
901 &status_buffer->payload);
aef4a983
MS
902 break;
903 case FSF_STATUS_READ_SUB_FDISC_FAILED:
904 ZFCP_LOG_INFO("Local link to adapter %s is down "
905 "due to failed FDISC login\n",
ee69ab7a 906 zfcp_get_busid_by_adapter(adapter));
698ec016 907 zfcp_fsf_link_down_info_eval(fsf_req, 39,
ee69ab7a
MS
908 (struct fsf_link_down_info *)
909 &status_buffer->payload);
aef4a983
MS
910 break;
911 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
912 ZFCP_LOG_INFO("Local link to adapter %s is down "
913 "due to firmware update on adapter\n",
914 zfcp_get_busid_by_adapter(adapter));
698ec016 915 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
aef4a983
MS
916 break;
917 default:
918 ZFCP_LOG_INFO("Local link to adapter %s is down "
919 "due to unknown reason\n",
920 zfcp_get_busid_by_adapter(adapter));
698ec016 921 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
aef4a983 922 };
1da177e4
LT
923 break;
924
925 case FSF_STATUS_READ_LINK_UP:
aef4a983 926 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
ee69ab7a
MS
927 "Restarting operations on this adapter\n",
928 zfcp_get_busid_by_adapter(adapter));
1da177e4 929 /* All ports should be marked as ready to run again */
1f6f7129 930 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
1da177e4
LT
931 ZFCP_STATUS_COMMON_RUNNING,
932 ZFCP_SET);
933 zfcp_erp_adapter_reopen(adapter,
934 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
9467a9b3 935 | ZFCP_STATUS_COMMON_ERP_FAILED,
1f6f7129 936 102, fsf_req);
1da177e4
LT
937 break;
938
9eb69aff
MS
939 case FSF_STATUS_READ_NOTIFICATION_LOST:
940 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
941 "adapter %s%s%s%s%s%s%s%s%s\n",
942 zfcp_get_busid_by_adapter(adapter),
943 (status_buffer->status_subtype &
944 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
945 ", incoming ELS" : "",
946 (status_buffer->status_subtype &
947 FSF_STATUS_READ_SUB_SENSE_DATA) ?
948 ", sense data" : "",
949 (status_buffer->status_subtype &
950 FSF_STATUS_READ_SUB_LINK_STATUS) ?
951 ", link status change" : "",
952 (status_buffer->status_subtype &
953 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
954 ", port close" : "",
955 (status_buffer->status_subtype &
956 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
957 ", bit error exception" : "",
958 (status_buffer->status_subtype &
959 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
960 ", ACT update" : "",
961 (status_buffer->status_subtype &
962 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
963 ", ACT hardening" : "",
964 (status_buffer->status_subtype &
965 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
966 ", adapter feature change" : "");
967
968 if (status_buffer->status_subtype &
969 FSF_STATUS_READ_SUB_ACT_UPDATED)
1f6f7129 970 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
9eb69aff
MS
971 break;
972
1da177e4 973 case FSF_STATUS_READ_CFDC_UPDATED:
8a36e453 974 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
1da177e4 975 zfcp_get_busid_by_adapter(adapter));
1f6f7129 976 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
1da177e4
LT
977 break;
978
979 case FSF_STATUS_READ_CFDC_HARDENED:
1da177e4
LT
980 switch (status_buffer->status_subtype) {
981 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
8a36e453 982 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1da177e4
LT
983 zfcp_get_busid_by_adapter(adapter));
984 break;
985 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
8a36e453 986 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1da177e4
LT
987 "to the secondary SE\n",
988 zfcp_get_busid_by_adapter(adapter));
989 break;
990 default:
8a36e453 991 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1da177e4
LT
992 zfcp_get_busid_by_adapter(adapter));
993 }
994 break;
995
aef4a983 996 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
aef4a983
MS
997 ZFCP_LOG_INFO("List of supported features on adapter %s has "
998 "been changed from 0x%08X to 0x%08X\n",
999 zfcp_get_busid_by_adapter(adapter),
1000 *(u32*) (status_buffer->payload + 4),
1001 *(u32*) (status_buffer->payload));
1002 adapter->adapter_features = *(u32*) status_buffer->payload;
1003 break;
1004
1da177e4 1005 default:
8a36e453 1006 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1da177e4
LT
1007 "type was received (debug info 0x%x)\n",
1008 status_buffer->status_type);
1009 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1010 status_buffer);
1011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1012 (char *) status_buffer,
1013 sizeof (struct fsf_status_read_buffer));
1014 break;
1015 }
1016 mempool_free(status_buffer, adapter->pool.data_status_read);
1db2c9c0 1017 zfcp_fsf_req_free(fsf_req);
1da177e4
LT
1018 /*
1019 * recycle buffer and start new request repeat until outbound
1020 * queue is empty or adapter shutdown is requested
1021 */
1022 /*
1023 * FIXME(qdio):
1024 * we may wait in the req_create for 5s during shutdown, so
1025 * qdio_cleanup will have to wait at least that long before returning
1026 * with failure to allow us a proper cleanup under all circumstances
1027 */
1028 /*
1029 * FIXME:
1030 * allocation failure possible? (Is this code needed?)
1031 */
1032 retval = zfcp_fsf_status_read(adapter, 0);
1033 if (retval < 0) {
1034 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1035 "request for the adapter %s.\n",
1036 zfcp_get_busid_by_adapter(adapter));
1037 /* temporary fix to avoid status read buffer shortage */
1038 adapter->status_read_failed++;
1039 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1040 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1041 ZFCP_LOG_INFO("restart adapter %s due to status read "
1042 "buffer shortage\n",
1043 zfcp_get_busid_by_adapter(adapter));
1f6f7129 1044 zfcp_erp_adapter_reopen(adapter, 0, 103, fsf_req);
1da177e4
LT
1045 }
1046 }
1047 out:
1048 return retval;
1049}
1050
1051/*
1052 * function: zfcp_fsf_abort_fcp_command
1053 *
1054 * purpose: tells FSF to abort a running SCSI command
1055 *
1056 * returns: address of initiated FSF request
1057 * NULL - request could not be initiated
1058 *
41fa2ada 1059 * FIXME(design): should be watched by a timeout !!!
1da177e4
LT
1060 * FIXME(design) shouldn't this be modified to return an int
1061 * also...don't know how though
1062 */
1063struct zfcp_fsf_req *
1064zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1065 struct zfcp_adapter *adapter,
1066 struct zfcp_unit *unit, int req_flags)
1067{
1068 volatile struct qdio_buffer_element *sbale;
1da177e4 1069 struct zfcp_fsf_req *fsf_req = NULL;
2abbe866 1070 unsigned long lock_flags;
1da177e4
LT
1071 int retval = 0;
1072
1073 /* setup new FSF request */
1074 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1075 req_flags, adapter->pool.fsf_req_abort,
1076 &lock_flags, &fsf_req);
1077 if (retval < 0) {
1078 ZFCP_LOG_INFO("error: Failed to create an abort command "
1079 "request for lun 0x%016Lx on port 0x%016Lx "
1080 "on adapter %s.\n",
1081 unit->fcp_lun,
1082 unit->port->wwpn,
1083 zfcp_get_busid_by_adapter(adapter));
1084 goto out;
1085 }
1086
951f746f
CS
1087 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1088 &unit->status)))
1089 goto unit_blocked;
1090
1da177e4
LT
1091 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1092 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1093 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1094
059c97d0 1095 fsf_req->data = (unsigned long) unit;
1da177e4
LT
1096
1097 /* set handles of unit and its parent port in QTCB */
1098 fsf_req->qtcb->header.lun_handle = unit->handle;
1099 fsf_req->qtcb->header.port_handle = unit->port->handle;
1100
1101 /* set handle of request which should be aborted */
1102 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1103
2abbe866
AH
1104 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1105 retval = zfcp_fsf_req_send(fsf_req);
951f746f
CS
1106 if (!retval)
1107 goto out;
1108
1109 unit_blocked:
1da177e4
LT
1110 zfcp_fsf_req_free(fsf_req);
1111 fsf_req = NULL;
1da177e4 1112
1da177e4
LT
1113 out:
1114 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1115 return fsf_req;
1116}
1117
1118/*
1119 * function: zfcp_fsf_abort_fcp_command_handler
1120 *
1121 * purpose: is called for finished Abort FCP Command request
1122 *
41fa2ada 1123 * returns:
1da177e4
LT
1124 */
1125static int
1126zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1127{
1128 int retval = -EINVAL;
059c97d0 1129 struct zfcp_unit *unit;
8627533c
CS
1130 union fsf_status_qual *fsf_stat_qual =
1131 &new_fsf_req->qtcb->header.fsf_status_qual;
1da177e4 1132
1da177e4
LT
1133 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1134 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1135 goto skip_fsfstatus;
1136 }
1137
059c97d0
AH
1138 unit = (struct zfcp_unit *) new_fsf_req->data;
1139
1da177e4
LT
1140 /* evaluate FSF status in QTCB */
1141 switch (new_fsf_req->qtcb->header.fsf_status) {
1142
1143 case FSF_PORT_HANDLE_NOT_VALID:
8627533c 1144 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
1da177e4
LT
1145 /*
1146 * In this case a command that was sent prior to a port
1147 * reopen was aborted (handles are different). This is
1148 * fine.
1149 */
1150 } else {
1da177e4
LT
1151 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1152 "port 0x%016Lx on adapter %s invalid. "
1153 "This may happen occasionally.\n",
1154 unit->port->handle,
1155 unit->port->wwpn,
1156 zfcp_get_busid_by_unit(unit));
1157 ZFCP_LOG_INFO("status qualifier:\n");
1158 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1159 (char *) &new_fsf_req->qtcb->header.
1160 fsf_status_qual,
1161 sizeof (union fsf_status_qual));
1162 /* Let's hope this sorts out the mess */
9467a9b3 1163 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
1f6f7129 1164 new_fsf_req);
1da177e4
LT
1165 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1166 }
1167 break;
1168
1169 case FSF_LUN_HANDLE_NOT_VALID:
8627533c 1170 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
1da177e4
LT
1171 /*
1172 * In this case a command that was sent prior to a unit
1173 * reopen was aborted (handles are different).
1174 * This is fine.
1175 */
1176 } else {
1da177e4
LT
1177 ZFCP_LOG_INFO
1178 ("Warning: Temporary LUN identifier 0x%x of LUN "
1179 "0x%016Lx on port 0x%016Lx on adapter %s is "
1180 "invalid. This may happen in rare cases. "
1181 "Trying to re-establish link.\n",
1182 unit->handle,
1183 unit->fcp_lun,
1184 unit->port->wwpn,
1185 zfcp_get_busid_by_unit(unit));
1186 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1188 (char *) &new_fsf_req->qtcb->header.
1189 fsf_status_qual,
1190 sizeof (union fsf_status_qual));
1191 /* Let's hope this sorts out the mess */
1f6f7129 1192 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
1da177e4
LT
1193 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1194 }
1195 break;
1196
1197 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1da177e4 1198 retval = 0;
1da177e4
LT
1199 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1200 break;
1201
1202 case FSF_PORT_BOXED:
1da177e4
LT
1203 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1204 "be reopened\n", unit->port->wwpn,
1205 zfcp_get_busid_by_unit(unit));
1f6f7129 1206 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
1da177e4
LT
1207 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1208 | ZFCP_STATUS_FSFREQ_RETRY;
1209 break;
1210
1211 case FSF_LUN_BOXED:
1da177e4
LT
1212 ZFCP_LOG_INFO(
1213 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1214 "to be reopened\n",
1215 unit->fcp_lun, unit->port->wwpn,
1216 zfcp_get_busid_by_unit(unit));
1f6f7129 1217 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
1da177e4
LT
1218 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1219 | ZFCP_STATUS_FSFREQ_RETRY;
1220 break;
1221
1222 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
1223 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1224 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
65a8d4e1 1225 zfcp_test_link(unit->port);
1da177e4
LT
1226 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1227 break;
1228 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1da177e4 1229 /* SCSI stack will escalate */
1da177e4
LT
1230 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1231 break;
1232 default:
1233 ZFCP_LOG_NORMAL
1234 ("bug: Wrong status qualifier 0x%x arrived.\n",
1235 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1da177e4
LT
1236 break;
1237 }
1238 break;
1239
1240 case FSF_GOOD:
1da177e4
LT
1241 retval = 0;
1242 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1243 break;
1244
1245 default:
1246 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1247 "(debug info 0x%x)\n",
1248 new_fsf_req->qtcb->header.fsf_status);
1da177e4
LT
1249 break;
1250 }
1251 skip_fsfstatus:
1252 return retval;
1253}
1254
1255/**
1256 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1257 * one SBALE
1258 * Two scatter-gather lists are passed, one for the reqeust and one for the
1259 * response.
1260 */
1261static inline int
1262zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1263 struct scatterlist *resp, int resp_count)
1264{
1265 return ((req_count == 1) &&
1266 (resp_count == 1) &&
1267 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1268 PAGE_MASK) ==
1269 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1270 req[0].length - 1) & PAGE_MASK)) &&
1271 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1272 PAGE_MASK) ==
1273 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1274 resp[0].length - 1) & PAGE_MASK)));
1275}
1276
1277/**
1278 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1279 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1280 * the request
1281 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1282 * a struct zfcp_fsf_req
1283 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1284 * is sent within error recovery
1285 */
1286int
1287zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1288 struct zfcp_erp_action *erp_action)
1289{
1290 volatile struct qdio_buffer_element *sbale;
1291 struct zfcp_port *port;
1292 struct zfcp_adapter *adapter;
1293 struct zfcp_fsf_req *fsf_req;
1294 unsigned long lock_flags;
1295 int bytes;
1296 int ret = 0;
1297
1298 port = ct->port;
1299 adapter = port->adapter;
1300
1301 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1302 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1303 pool, &lock_flags, &fsf_req);
1304 if (ret < 0) {
1305 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1306 "adapter: %s\n",
1307 zfcp_get_busid_by_adapter(adapter));
1308 goto failed_req;
1309 }
1310
1da177e4
LT
1311 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1312 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1313 ct->resp, ct->resp_count)){
1314 /* both request buffer and response buffer
1315 fit into one sbale each */
1316 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1317 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1318 sbale[2].length = ct->req[0].length;
1319 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1320 sbale[3].length = ct->resp[0].length;
1321 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
aef4a983 1322 } else if (adapter->adapter_features &
1da177e4
LT
1323 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1324 /* try to use chained SBALs */
1325 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1326 SBAL_FLAGS0_TYPE_WRITE_READ,
1327 ct->req, ct->req_count,
1328 ZFCP_MAX_SBALS_PER_CT_REQ);
1329 if (bytes <= 0) {
1330 ZFCP_LOG_INFO("error: creation of CT request failed "
1331 "on adapter %s\n",
1332 zfcp_get_busid_by_adapter(adapter));
1333 if (bytes == 0)
1334 ret = -ENOMEM;
1335 else
1336 ret = bytes;
1337
1338 goto failed_send;
1339 }
1340 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1341 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1342 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1343 SBAL_FLAGS0_TYPE_WRITE_READ,
1344 ct->resp, ct->resp_count,
1345 ZFCP_MAX_SBALS_PER_CT_REQ);
1346 if (bytes <= 0) {
1347 ZFCP_LOG_INFO("error: creation of CT request failed "
1348 "on adapter %s\n",
1349 zfcp_get_busid_by_adapter(adapter));
1350 if (bytes == 0)
1351 ret = -ENOMEM;
1352 else
1353 ret = bytes;
1354
1355 goto failed_send;
1356 }
1357 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1358 } else {
1359 /* reject send generic request */
1360 ZFCP_LOG_INFO(
1361 "error: microcode does not support chained SBALs,"
1362 "CT request too big (adapter %s)\n",
1363 zfcp_get_busid_by_adapter(adapter));
1364 ret = -EOPNOTSUPP;
1365 goto failed_send;
1366 }
1367
1368 /* settings in QTCB */
1369 fsf_req->qtcb->header.port_handle = port->handle;
06506d00
AH
1370 fsf_req->qtcb->bottom.support.service_class =
1371 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1da177e4 1372 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
059c97d0 1373 fsf_req->data = (unsigned long) ct;
1da177e4 1374
8a36e453
MS
1375 zfcp_san_dbf_event_ct_request(fsf_req);
1376
2abbe866
AH
1377 if (erp_action) {
1378 erp_action->fsf_req = fsf_req;
1379 fsf_req->erp_action = erp_action;
1380 zfcp_erp_start_timer(fsf_req);
1381 } else
1382 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1383
1384 ret = zfcp_fsf_req_send(fsf_req);
1da177e4
LT
1385 if (ret) {
1386 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1387 "(adapter %s, port 0x%016Lx)\n",
1388 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1389 goto failed_send;
1390 }
1391
1392 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1393 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1394 goto out;
1395
1396 failed_send:
1397 zfcp_fsf_req_free(fsf_req);
1398 if (erp_action != NULL) {
1399 erp_action->fsf_req = NULL;
1400 }
1401 failed_req:
1402 out:
1403 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1404 lock_flags);
1405 return ret;
1406}
1407
1408/**
1409 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1410 * @fsf_req: pointer to struct zfcp_fsf_req
1411 *
059c97d0
AH
1412 * Data specific for the Generic Service request is passed using
1413 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1414 * Usually a specific handler for the CT request is called which is
1415 * found in this structure.
1da177e4
LT
1416 */
1417static int
1418zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1419{
1420 struct zfcp_port *port;
1421 struct zfcp_adapter *adapter;
1422 struct zfcp_send_ct *send_ct;
1423 struct fsf_qtcb_header *header;
1424 struct fsf_qtcb_bottom_support *bottom;
1425 int retval = -EINVAL;
1426 u16 subtable, rule, counter;
1427
1428 adapter = fsf_req->adapter;
059c97d0 1429 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1da177e4
LT
1430 port = send_ct->port;
1431 header = &fsf_req->qtcb->header;
1432 bottom = &fsf_req->qtcb->bottom.support;
1433
1434 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1435 goto skip_fsfstatus;
1436
1437 /* evaluate FSF status in QTCB */
1438 switch (header->fsf_status) {
1439
1440 case FSF_GOOD:
8a36e453 1441 zfcp_san_dbf_event_ct_response(fsf_req);
1da177e4
LT
1442 retval = 0;
1443 break;
1444
1445 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
06506d00
AH
1446 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1447 "class %d.\n",
1448 zfcp_get_busid_by_port(port),
1449 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1da177e4 1450 /* stop operation for this adapter */
1f6f7129 1451 zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
1da177e4
LT
1452 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1453 break;
1454
1455 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
1456 switch (header->fsf_status_qual.word[0]){
1457 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1da177e4 1458 /* reopening link to port */
1da177e4
LT
1459 zfcp_test_link(port);
1460 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1461 break;
1462 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1da177e4 1463 /* ERP strategy will escalate */
1da177e4
LT
1464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1465 break;
1466 default:
1467 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1468 "arrived.\n",
1469 header->fsf_status_qual.word[0]);
1470 break;
1471 }
1472 break;
1473
1474 case FSF_ACCESS_DENIED:
1da177e4 1475 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1d589edf 1476 "command (adapter %s, port d_id=0x%06x)\n",
1da177e4
LT
1477 zfcp_get_busid_by_port(port), port->d_id);
1478 for (counter = 0; counter < 2; counter++) {
1479 subtable = header->fsf_status_qual.halfword[counter * 2];
1480 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1481 switch (subtable) {
1482 case FSF_SQ_CFDC_SUBTABLE_OS:
1483 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1484 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1485 case FSF_SQ_CFDC_SUBTABLE_LUN:
1486 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1487 zfcp_act_subtable_type[subtable], rule);
1488 break;
1489 }
1490 }
1f6f7129 1491 zfcp_erp_port_access_denied(port, 55, fsf_req);
1da177e4
LT
1492 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1493 break;
1494
1495 case FSF_GENERIC_COMMAND_REJECTED:
1da177e4 1496 ZFCP_LOG_INFO("generic service command rejected "
1d589edf 1497 "(adapter %s, port d_id=0x%06x)\n",
1da177e4
LT
1498 zfcp_get_busid_by_port(port), port->d_id);
1499 ZFCP_LOG_INFO("status qualifier:\n");
1500 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1501 (char *) &header->fsf_status_qual,
1502 sizeof (union fsf_status_qual));
1da177e4
LT
1503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1504 break;
1505
1506 case FSF_PORT_HANDLE_NOT_VALID:
1da177e4
LT
1507 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1508 "0x%016Lx on adapter %s invalid. This may "
1509 "happen occasionally.\n", port->handle,
1510 port->wwpn, zfcp_get_busid_by_port(port));
1511 ZFCP_LOG_INFO("status qualifier:\n");
1512 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1513 (char *) &header->fsf_status_qual,
1514 sizeof (union fsf_status_qual));
1f6f7129 1515 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
1da177e4
LT
1516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1517 break;
1518
1519 case FSF_PORT_BOXED:
1da177e4 1520 ZFCP_LOG_INFO("port needs to be reopened "
1d589edf 1521 "(adapter %s, port d_id=0x%06x)\n",
1da177e4 1522 zfcp_get_busid_by_port(port), port->d_id);
1f6f7129 1523 zfcp_erp_port_boxed(port, 49, fsf_req);
1da177e4
LT
1524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1525 | ZFCP_STATUS_FSFREQ_RETRY;
1526 break;
1527
1528 /* following states should never occure, all cases avoided
1529 in zfcp_fsf_send_ct - but who knows ... */
1530 case FSF_PAYLOAD_SIZE_MISMATCH:
1da177e4
LT
1531 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1532 "req_buf_length=%d, resp_buf_length=%d)\n",
1533 zfcp_get_busid_by_adapter(adapter),
1534 bottom->req_buf_length, bottom->resp_buf_length);
1535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1536 break;
1537 case FSF_REQUEST_SIZE_TOO_LARGE:
1da177e4
LT
1538 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1539 "req_buf_length=%d)\n",
1540 zfcp_get_busid_by_adapter(adapter),
1541 bottom->req_buf_length);
1542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1543 break;
1544 case FSF_RESPONSE_SIZE_TOO_LARGE:
1da177e4
LT
1545 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1546 "resp_buf_length=%d)\n",
1547 zfcp_get_busid_by_adapter(adapter),
1548 bottom->resp_buf_length);
1549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1550 break;
1551 case FSF_SBAL_MISMATCH:
1da177e4
LT
1552 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1553 "resp_buf_length=%d)\n",
1554 zfcp_get_busid_by_adapter(adapter),
1555 bottom->req_buf_length, bottom->resp_buf_length);
1556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1557 break;
1558
1559 default:
1560 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1561 "(debug info 0x%x)\n", header->fsf_status);
1da177e4
LT
1562 break;
1563 }
1564
1565skip_fsfstatus:
1566 send_ct->status = retval;
1567
1568 if (send_ct->handler != NULL)
1569 send_ct->handler(send_ct->handler_data);
1570
1571 return retval;
1572}
1573
1574/**
1575 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1576 * @els: pointer to struct zfcp_send_els which contains all needed data for
1577 * the command.
1578 */
1579int
1580zfcp_fsf_send_els(struct zfcp_send_els *els)
1581{
1582 volatile struct qdio_buffer_element *sbale;
1583 struct zfcp_fsf_req *fsf_req;
13e1e1f0 1584 u32 d_id;
1da177e4
LT
1585 struct zfcp_adapter *adapter;
1586 unsigned long lock_flags;
1587 int bytes;
1588 int ret = 0;
1589
1590 d_id = els->d_id;
1591 adapter = els->adapter;
1592
1593 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1594 ZFCP_REQ_AUTO_CLEANUP,
1595 NULL, &lock_flags, &fsf_req);
1596 if (ret < 0) {
1597 ZFCP_LOG_INFO("error: creation of ELS request failed "
1d589edf 1598 "(adapter %s, port d_id: 0x%06x)\n",
1da177e4
LT
1599 zfcp_get_busid_by_adapter(adapter), d_id);
1600 goto failed_req;
1601 }
1602
3f0ca62a
CS
1603 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1604 &els->port->status))) {
1605 ret = -EBUSY;
1606 goto port_blocked;
1607 }
1608
1da177e4
LT
1609 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1610 if (zfcp_use_one_sbal(els->req, els->req_count,
1611 els->resp, els->resp_count)){
1612 /* both request buffer and response buffer
1613 fit into one sbale each */
1614 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1615 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1616 sbale[2].length = els->req[0].length;
1617 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1618 sbale[3].length = els->resp[0].length;
1619 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
aef4a983 1620 } else if (adapter->adapter_features &
1da177e4
LT
1621 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1622 /* try to use chained SBALs */
1623 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1624 SBAL_FLAGS0_TYPE_WRITE_READ,
1625 els->req, els->req_count,
1626 ZFCP_MAX_SBALS_PER_ELS_REQ);
1627 if (bytes <= 0) {
1628 ZFCP_LOG_INFO("error: creation of ELS request failed "
1d589edf 1629 "(adapter %s, port d_id: 0x%06x)\n",
1da177e4
LT
1630 zfcp_get_busid_by_adapter(adapter), d_id);
1631 if (bytes == 0) {
1632 ret = -ENOMEM;
1633 } else {
1634 ret = bytes;
1635 }
1636 goto failed_send;
1637 }
1638 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1639 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1640 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1641 SBAL_FLAGS0_TYPE_WRITE_READ,
1642 els->resp, els->resp_count,
1643 ZFCP_MAX_SBALS_PER_ELS_REQ);
1644 if (bytes <= 0) {
1645 ZFCP_LOG_INFO("error: creation of ELS request failed "
1d589edf 1646 "(adapter %s, port d_id: 0x%06x)\n",
1da177e4
LT
1647 zfcp_get_busid_by_adapter(adapter), d_id);
1648 if (bytes == 0) {
1649 ret = -ENOMEM;
1650 } else {
1651 ret = bytes;
1652 }
1653 goto failed_send;
1654 }
1655 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1656 } else {
1657 /* reject request */
1658 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1659 ", ELS request too big (adapter %s, "
1d589edf 1660 "port d_id: 0x%06x)\n",
1da177e4
LT
1661 zfcp_get_busid_by_adapter(adapter), d_id);
1662 ret = -EOPNOTSUPP;
1663 goto failed_send;
1664 }
1665
1666 /* settings in QTCB */
1667 fsf_req->qtcb->bottom.support.d_id = d_id;
06506d00
AH
1668 fsf_req->qtcb->bottom.support.service_class =
1669 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1da177e4 1670 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
059c97d0 1671 fsf_req->data = (unsigned long) els;
1da177e4
LT
1672
1673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1674
8a36e453
MS
1675 zfcp_san_dbf_event_els_request(fsf_req);
1676
2abbe866
AH
1677 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1678 ret = zfcp_fsf_req_send(fsf_req);
1da177e4
LT
1679 if (ret) {
1680 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1d589edf 1681 "(adapter %s, port d_id: 0x%06x)\n",
1da177e4
LT
1682 zfcp_get_busid_by_adapter(adapter), d_id);
1683 goto failed_send;
1684 }
1685
1686 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1d589edf 1687 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1da177e4
LT
1688 goto out;
1689
3f0ca62a 1690 port_blocked:
1da177e4
LT
1691 failed_send:
1692 zfcp_fsf_req_free(fsf_req);
1693
1694 failed_req:
1695 out:
1696 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1697 lock_flags);
1698
1699 return ret;
1700}
1701
1702/**
1703 * zfcp_fsf_send_els_handler - handler for ELS commands
1704 * @fsf_req: pointer to struct zfcp_fsf_req
1705 *
059c97d0
AH
1706 * Data specific for the ELS command is passed using
1707 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1708 * Usually a specific handler for the ELS command is called which is
1709 * found in this structure.
1da177e4
LT
1710 */
1711static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1712{
1713 struct zfcp_adapter *adapter;
1da177e4 1714 struct zfcp_port *port;
13e1e1f0 1715 u32 d_id;
1da177e4
LT
1716 struct fsf_qtcb_header *header;
1717 struct fsf_qtcb_bottom_support *bottom;
1718 struct zfcp_send_els *send_els;
1719 int retval = -EINVAL;
1720 u16 subtable, rule, counter;
1721
059c97d0 1722 send_els = (struct zfcp_send_els *) fsf_req->data;
1da177e4 1723 adapter = send_els->adapter;
64b29a13 1724 port = send_els->port;
1da177e4
LT
1725 d_id = send_els->d_id;
1726 header = &fsf_req->qtcb->header;
1727 bottom = &fsf_req->qtcb->bottom.support;
1728
1729 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1730 goto skip_fsfstatus;
1731
1732 switch (header->fsf_status) {
1733
1734 case FSF_GOOD:
8a36e453 1735 zfcp_san_dbf_event_els_response(fsf_req);
1da177e4
LT
1736 retval = 0;
1737 break;
1738
1739 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
06506d00
AH
1740 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1741 "class %d.\n",
1742 zfcp_get_busid_by_adapter(adapter),
1743 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1da177e4 1744 /* stop operation for this adapter */
1f6f7129 1745 zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
1da177e4
LT
1746 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1747 break;
1748
1749 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
1750 switch (header->fsf_status_qual.word[0]){
1751 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
64b29a13
AH
1752 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1753 zfcp_test_link(port);
1da177e4
LT
1754 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1755 break;
1756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1da177e4
LT
1757 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1758 retval =
1759 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1760 (struct zfcp_ls_rjt_par *)
1761 &header->fsf_status_qual.word[2]);
1762 break;
1763 case FSF_SQ_RETRY_IF_POSSIBLE:
1da177e4
LT
1764 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1765 break;
1766 default:
1767 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1768 header->fsf_status_qual.word[0]);
1769 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1770 (char*)header->fsf_status_qual.word, 16);
1771 }
1772 break;
1773
1774 case FSF_ELS_COMMAND_REJECTED:
1da177e4
LT
1775 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1776 "prohibited sending "
1d589edf 1777 "(adapter: %s, port d_id: 0x%06x)\n",
1da177e4
LT
1778 zfcp_get_busid_by_adapter(adapter), d_id);
1779
1780 break;
1781
1782 case FSF_PAYLOAD_SIZE_MISMATCH:
1da177e4
LT
1783 ZFCP_LOG_INFO(
1784 "ELS request size and ELS response size must be either "
1785 "both 0, or both greater than 0 "
1786 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1787 zfcp_get_busid_by_adapter(adapter),
1788 bottom->req_buf_length,
1789 bottom->resp_buf_length);
1790 break;
1791
1792 case FSF_REQUEST_SIZE_TOO_LARGE:
1da177e4
LT
1793 ZFCP_LOG_INFO(
1794 "Length of the ELS request buffer, "
1795 "specified in QTCB bottom, "
1796 "exceeds the size of the buffers "
1797 "that have been allocated for ELS request data "
1798 "(adapter: %s, req_buf_length=%d)\n",
1799 zfcp_get_busid_by_adapter(adapter),
1800 bottom->req_buf_length);
1801 break;
1802
1803 case FSF_RESPONSE_SIZE_TOO_LARGE:
1da177e4
LT
1804 ZFCP_LOG_INFO(
1805 "Length of the ELS response buffer, "
1806 "specified in QTCB bottom, "
1807 "exceeds the size of the buffers "
1808 "that have been allocated for ELS response data "
1809 "(adapter: %s, resp_buf_length=%d)\n",
1810 zfcp_get_busid_by_adapter(adapter),
1811 bottom->resp_buf_length);
1812 break;
1813
1814 case FSF_SBAL_MISMATCH:
1815 /* should never occure, avoided in zfcp_fsf_send_els */
1da177e4
LT
1816 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1817 "resp_buf_length=%d)\n",
1818 zfcp_get_busid_by_adapter(adapter),
1819 bottom->req_buf_length, bottom->resp_buf_length);
1820 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1821 break;
1822
1823 case FSF_ACCESS_DENIED:
1da177e4 1824 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1d589edf 1825 "(adapter %s, port d_id=0x%06x)\n",
1da177e4
LT
1826 zfcp_get_busid_by_adapter(adapter), d_id);
1827 for (counter = 0; counter < 2; counter++) {
1828 subtable = header->fsf_status_qual.halfword[counter * 2];
1829 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1830 switch (subtable) {
1831 case FSF_SQ_CFDC_SUBTABLE_OS:
1832 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1833 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1834 case FSF_SQ_CFDC_SUBTABLE_LUN:
1835 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1836 zfcp_act_subtable_type[subtable], rule);
1837 break;
1838 }
1839 }
1da177e4 1840 if (port != NULL)
1f6f7129 1841 zfcp_erp_port_access_denied(port, 56, fsf_req);
1da177e4
LT
1842 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1843 break;
1844
1845 default:
1846 ZFCP_LOG_NORMAL(
1847 "bug: An unknown FSF Status was presented "
1848 "(adapter: %s, fsf_status=0x%08x)\n",
1849 zfcp_get_busid_by_adapter(adapter),
1850 header->fsf_status);
1da177e4
LT
1851 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1852 break;
1853 }
1854
1855skip_fsfstatus:
1856 send_els->status = retval;
1857
aa551daf 1858 if (send_els->handler)
1da177e4
LT
1859 send_els->handler(send_els->handler_data);
1860
1861 return retval;
1862}
1863
1da177e4
LT
1864int
1865zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1866{
1867 volatile struct qdio_buffer_element *sbale;
2abbe866 1868 struct zfcp_fsf_req *fsf_req;
52ef11a7 1869 struct zfcp_adapter *adapter = erp_action->adapter;
1da177e4 1870 unsigned long lock_flags;
52ef11a7 1871 int retval;
1da177e4
LT
1872
1873 /* setup new FSF request */
52ef11a7 1874 retval = zfcp_fsf_req_create(adapter,
1da177e4
LT
1875 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1876 ZFCP_REQ_AUTO_CLEANUP,
52ef11a7 1877 adapter->pool.fsf_req_erp,
2abbe866 1878 &lock_flags, &fsf_req);
52ef11a7 1879 if (retval) {
1da177e4
LT
1880 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1881 "data request for adapter %s.\n",
52ef11a7
SS
1882 zfcp_get_busid_by_adapter(adapter));
1883 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1884 lock_flags);
1885 return retval;
1da177e4
LT
1886 }
1887
2abbe866 1888 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
52ef11a7
SS
1889 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1890 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1da177e4 1891
2abbe866 1892 fsf_req->qtcb->bottom.config.feature_selection =
aef4a983
MS
1893 FSF_FEATURE_CFDC |
1894 FSF_FEATURE_LUN_SHARING |
9eb69aff 1895 FSF_FEATURE_NOTIFICATION_LOST |
aef4a983 1896 FSF_FEATURE_UPDATE_ALERT;
2abbe866
AH
1897 fsf_req->erp_action = erp_action;
1898 erp_action->fsf_req = fsf_req;
1da177e4 1899
2abbe866
AH
1900 zfcp_erp_start_timer(fsf_req);
1901 retval = zfcp_fsf_req_send(fsf_req);
52ef11a7
SS
1902 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1903 lock_flags);
1da177e4 1904 if (retval) {
52ef11a7
SS
1905 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1906 "data command on the adapter %s\n",
1907 zfcp_get_busid_by_adapter(adapter));
2abbe866 1908 zfcp_fsf_req_free(fsf_req);
1da177e4 1909 erp_action->fsf_req = NULL;
1da177e4 1910 }
52ef11a7
SS
1911 else
1912 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1913 "(adapter %s)\n",
1914 zfcp_get_busid_by_adapter(adapter));
1da177e4 1915
52ef11a7
SS
1916 return retval;
1917}
1da177e4 1918
52ef11a7
SS
1919int
1920zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1921 struct fsf_qtcb_bottom_config *data)
1922{
1923 volatile struct qdio_buffer_element *sbale;
1924 struct zfcp_fsf_req *fsf_req;
1925 unsigned long lock_flags;
1926 int retval;
1927
1928 /* setup new FSF request */
1929 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
aee6ef18
SS
1930 ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
1931 &fsf_req);
52ef11a7
SS
1932 if (retval) {
1933 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1934 "data request for adapter %s.\n",
1935 zfcp_get_busid_by_adapter(adapter));
1936 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1937 lock_flags);
1938 return retval;
1939 }
1940
1941 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1942 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1943 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1944
1945 fsf_req->qtcb->bottom.config.feature_selection =
1946 FSF_FEATURE_CFDC |
1947 FSF_FEATURE_LUN_SHARING |
1948 FSF_FEATURE_NOTIFICATION_LOST |
1949 FSF_FEATURE_UPDATE_ALERT;
1950
1951 if (data)
1952 fsf_req->data = (unsigned long) data;
1953
1954 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1955 retval = zfcp_fsf_req_send(fsf_req);
1956 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1da177e4 1957 lock_flags);
52ef11a7
SS
1958 if (retval)
1959 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1960 "data command on the adapter %s\n",
1961 zfcp_get_busid_by_adapter(adapter));
1962 else
1963 wait_event(fsf_req->completion_wq,
1964 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1965
1966 zfcp_fsf_req_free(fsf_req);
1967
1da177e4
LT
1968 return retval;
1969}
1970
1971/**
1972 * zfcp_fsf_exchange_config_evaluate
1973 * @fsf_req: fsf_req which belongs to xchg config data request
1974 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1975 *
1976 * returns: -EIO on error, 0 otherwise
1977 */
1978static int
1979zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1980{
1981 struct fsf_qtcb_bottom_config *bottom;
1982 struct zfcp_adapter *adapter = fsf_req->adapter;
13e1e1f0 1983 struct Scsi_Host *shost = adapter->scsi_host;
1da177e4
LT
1984
1985 bottom = &fsf_req->qtcb->bottom.config;
1986 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1987 bottom->low_qtcb_version, bottom->high_qtcb_version);
1988 adapter->fsf_lic_version = bottom->lic_version;
aef4a983
MS
1989 adapter->adapter_features = bottom->adapter_features;
1990 adapter->connection_features = bottom->connection_features;
6f71d9bc
JB
1991 adapter->peer_wwpn = 0;
1992 adapter->peer_wwnn = 0;
1993 adapter->peer_d_id = 0;
1da177e4
LT
1994
1995 if (xchg_ok) {
52ef11a7
SS
1996
1997 if (fsf_req->data)
1998 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1999 bottom, sizeof (struct fsf_qtcb_bottom_config));
2000
13e1e1f0
AH
2001 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2002 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2003 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2004 fc_host_speed(shost) = bottom->fc_link_speed;
52ef11a7
SS
2005 fc_host_supported_classes(shost) =
2006 FC_COS_CLASS2 | FC_COS_CLASS3;
1da177e4 2007 adapter->hydra_version = bottom->adapter_type;
c9615858 2008 adapter->timer_ticks = bottom->timer_interval;
ad757cdf
AH
2009 if (fc_host_permanent_port_name(shost) == -1)
2010 fc_host_permanent_port_name(shost) =
2011 fc_host_port_name(shost);
2012 if (bottom->fc_topology == FSF_TOPO_P2P) {
2013 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2014 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2015 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2016 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2017 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2018 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2019 else if (bottom->fc_topology == FSF_TOPO_AL)
2020 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2021 else
2022 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1da177e4 2023 } else {
13e1e1f0
AH
2024 fc_host_node_name(shost) = 0;
2025 fc_host_port_name(shost) = 0;
2026 fc_host_port_id(shost) = 0;
2027 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
ad757cdf 2028 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1da177e4
LT
2029 adapter->hydra_version = 0;
2030 }
2031
aef4a983 2032 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
1da177e4 2033 adapter->hardware_version = bottom->hardware_version;
13e1e1f0
AH
2034 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2035 min(FC_SERIAL_NUMBER_SIZE, 17));
2036 EBCASC(fc_host_serial_number(shost),
2037 min(FC_SERIAL_NUMBER_SIZE, 17));
1da177e4
LT
2038 }
2039
ec258fe4
SS
2040 if (fsf_req->erp_action)
2041 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2042 "characteristics:\n"
2043 "WWNN 0x%016Lx, WWPN 0x%016Lx, "
2044 "S_ID 0x%06x,\n"
2045 "adapter version 0x%x, "
2046 "LIC version 0x%x, "
2047 "FC link speed %d Gb/s\n",
2048 zfcp_get_busid_by_adapter(adapter),
2049 (wwn_t) fc_host_node_name(shost),
2050 (wwn_t) fc_host_port_name(shost),
2051 fc_host_port_id(shost),
2052 adapter->hydra_version,
2053 adapter->fsf_lic_version,
2054 fc_host_speed(shost));
1da177e4
LT
2055 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2056 ZFCP_LOG_NORMAL("error: the adapter %s "
2057 "only supports newer control block "
2058 "versions in comparison to this device "
2059 "driver (try updated device driver)\n",
2060 zfcp_get_busid_by_adapter(adapter));
1f6f7129 2061 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
1da177e4
LT
2062 return -EIO;
2063 }
2064 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2065 ZFCP_LOG_NORMAL("error: the adapter %s "
2066 "only supports older control block "
2067 "versions than this device driver uses"
2068 "(consider a microcode upgrade)\n",
2069 zfcp_get_busid_by_adapter(adapter));
1f6f7129 2070 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
1da177e4
LT
2071 return -EIO;
2072 }
2073 return 0;
2074}
2075
52ef11a7 2076/**
1da177e4
LT
2077 * function: zfcp_fsf_exchange_config_data_handler
2078 *
2079 * purpose: is called for finished Exchange Configuration Data command
2080 *
2081 * returns:
2082 */
2083static int
2084zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2085{
2086 struct fsf_qtcb_bottom_config *bottom;
2087 struct zfcp_adapter *adapter = fsf_req->adapter;
aef4a983 2088 struct fsf_qtcb *qtcb = fsf_req->qtcb;
1da177e4
LT
2089
2090 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2091 return -EIO;
2092
aef4a983 2093 switch (qtcb->header.fsf_status) {
1da177e4
LT
2094
2095 case FSF_GOOD:
1da177e4
LT
2096 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2097 return -EIO;
2098
ad757cdf
AH
2099 switch (fc_host_port_type(adapter->scsi_host)) {
2100 case FC_PORTTYPE_PTP:
6f71d9bc
JB
2101 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2102 "configuration detected at adapter %s\n"
2103 "Peer WWNN 0x%016llx, "
2104 "peer WWPN 0x%016llx, "
2105 "peer d_id 0x%06x\n",
2106 zfcp_get_busid_by_adapter(adapter),
2107 adapter->peer_wwnn,
2108 adapter->peer_wwpn,
2109 adapter->peer_d_id);
6f71d9bc 2110 break;
ad757cdf 2111 case FC_PORTTYPE_NLPORT:
1da177e4
LT
2112 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2113 "topology detected at adapter %s "
2114 "unsupported, shutting down adapter\n",
2115 zfcp_get_busid_by_adapter(adapter));
1f6f7129 2116 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
1da177e4 2117 return -EIO;
ad757cdf 2118 case FC_PORTTYPE_NPORT:
ec258fe4
SS
2119 if (fsf_req->erp_action)
2120 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2121 "network detected at adapter "
2122 "%s.\n",
52ef11a7 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));
1f6f7129 2133 zfcp_erp_adapter_shutdown(adapter, 0, 128, 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));
1f6f7129 2145 zfcp_erp_adapter_shutdown(adapter, 0, 129, 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:
1f6f7129 2162 zfcp_erp_adapter_shutdown(adapter, 0, 130, 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 }
1f6f7129 2461 zfcp_erp_port_access_denied(port, 57, 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));
1f6f7129 2470 zfcp_erp_port_failed(port, 31, 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));
1f6f7129 2490 zfcp_erp_port_failed(port, 32, 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));
1f6f7129 2672 zfcp_erp_adapter_reopen(port->adapter, 0, 107, 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);
1f6f7129 2687 zfcp_erp_modify_port_status(port, 33, 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));
1f6f7129 2809 zfcp_erp_adapter_reopen(port->adapter, 0, 108, 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 }
1f6f7129 2830 zfcp_erp_port_access_denied(port, 58, 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));
1f6f7129 2840 zfcp_erp_port_boxed(port, 50, 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));
1f6f7129 3019 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
1da177e4
LT
3020 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3021 break;
3022
3023 case FSF_LUN_ALREADY_OPEN:
1da177e4
LT
3024 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3025 "remote port 0x%016Lx on adapter %s twice.\n",
3026 unit->fcp_lun,
3027 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1da177e4
LT
3028 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3029 break;
3030
3031 case FSF_ACCESS_DENIED:
1da177e4
LT
3032 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3033 "remote port 0x%016Lx on adapter %s\n",
3034 unit->fcp_lun, unit->port->wwpn,
3035 zfcp_get_busid_by_unit(unit));
3036 for (counter = 0; counter < 2; counter++) {
3037 subtable = header->fsf_status_qual.halfword[counter * 2];
3038 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3039 switch (subtable) {
3040 case FSF_SQ_CFDC_SUBTABLE_OS:
3041 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3042 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3043 case FSF_SQ_CFDC_SUBTABLE_LUN:
3044 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3045 zfcp_act_subtable_type[subtable], rule);
3046 break;
3047 }
3048 }
1f6f7129 3049 zfcp_erp_unit_access_denied(unit, 59, fsf_req);
1da177e4
LT
3050 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3051 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3052 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3053 break;
3054
3055 case FSF_PORT_BOXED:
1da177e4
LT
3056 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3057 "needs to be reopened\n",
3058 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1f6f7129 3059 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
1da177e4
LT
3060 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3061 ZFCP_STATUS_FSFREQ_RETRY;
3062 break;
3063
3064 case FSF_LUN_SHARING_VIOLATION:
1da177e4
LT
3065 if (header->fsf_status_qual.word[0] != 0) {
3066 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3067 "with WWPN 0x%Lx "
3068 "connected to the adapter %s "
3069 "is already in use in LPAR%d, CSS%d\n",
3070 unit->fcp_lun,
3071 unit->port->wwpn,
3072 zfcp_get_busid_by_unit(unit),
3073 queue_designator->hla,
3074 queue_designator->cssid);
3075 } else {
3076 subtable = header->fsf_status_qual.halfword[4];
3077 rule = header->fsf_status_qual.halfword[5];
3078 switch (subtable) {
3079 case FSF_SQ_CFDC_SUBTABLE_OS:
3080 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3081 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3082 case FSF_SQ_CFDC_SUBTABLE_LUN:
3083 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3084 "remote port with WWPN 0x%Lx "
3085 "connected to the adapter %s "
3086 "is denied (%s rule %d)\n",
3087 unit->fcp_lun,
3088 unit->port->wwpn,
3089 zfcp_get_busid_by_unit(unit),
3090 zfcp_act_subtable_type[subtable],
3091 rule);
3092 break;
3093 }
3094 }
3095 ZFCP_LOG_DEBUG("status qualifier:\n");
3096 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3097 (char *) &header->fsf_status_qual,
3098 sizeof (union fsf_status_qual));
1f6f7129 3099 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
1da177e4
LT
3100 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3101 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3102 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3103 break;
3104
3105 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1da177e4
LT
3106 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3107 "There is no handle (temporary port identifier) "
3108 "available for unit 0x%016Lx on port 0x%016Lx "
3109 "on adapter %s\n",
3110 unit->fcp_lun,
3111 unit->port->wwpn,
3112 zfcp_get_busid_by_unit(unit));
1f6f7129 3113 zfcp_erp_unit_failed(unit, 34, fsf_req);
1da177e4
LT
3114 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3115 break;
3116
3117 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
3118 switch (header->fsf_status_qual.word[0]) {
3119 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1da177e4 3120 /* Re-establish link to port */
65a8d4e1 3121 zfcp_test_link(unit->port);
1da177e4
LT
3122 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3123 break;
3124 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1da177e4 3125 /* ERP strategy will escalate */
1da177e4
LT
3126 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3127 break;
3128 default:
3129 ZFCP_LOG_NORMAL
3130 ("bug: Wrong status qualifier 0x%x arrived.\n",
3131 header->fsf_status_qual.word[0]);
1da177e4
LT
3132 }
3133 break;
3134
3135 case FSF_INVALID_COMMAND_OPTION:
1da177e4
LT
3136 ZFCP_LOG_NORMAL(
3137 "Invalid option 0x%x has been specified "
3138 "in QTCB bottom sent to the adapter %s\n",
3139 bottom->option,
3140 zfcp_get_busid_by_adapter(adapter));
3141 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3142 retval = -EINVAL;
3143 break;
3144
3145 case FSF_GOOD:
1da177e4
LT
3146 /* save LUN handle assigned by FSF */
3147 unit->handle = header->lun_handle;
3148 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3149 "adapter %s opened, port handle 0x%x\n",
3150 unit->fcp_lun,
3151 unit->port->wwpn,
3152 zfcp_get_busid_by_unit(unit),
3153 unit->handle);
3154 /* mark unit as open */
3155 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
aef4a983
MS
3156
3157 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3158 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3159 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3160 exclusive = (bottom->lun_access_info &
3161 FSF_UNIT_ACCESS_EXCLUSIVE);
3162 readwrite = (bottom->lun_access_info &
3163 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3164
1da177e4
LT
3165 if (!exclusive)
3166 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3167 &unit->status);
3168
3169 if (!readwrite) {
3170 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3171 &unit->status);
3172 ZFCP_LOG_NORMAL("read-only access for unit "
3173 "(adapter %s, wwpn=0x%016Lx, "
3174 "fcp_lun=0x%016Lx)\n",
3175 zfcp_get_busid_by_unit(unit),
3176 unit->port->wwpn,
3177 unit->fcp_lun);
3178 }
3179
3180 if (exclusive && !readwrite) {
3181 ZFCP_LOG_NORMAL("exclusive access of read-only "
3182 "unit not supported\n");
1f6f7129 3183 zfcp_erp_unit_failed(unit, 35, fsf_req);
1da177e4 3184 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1f6f7129 3185 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
1da177e4
LT
3186 } else if (!exclusive && readwrite) {
3187 ZFCP_LOG_NORMAL("shared access of read-write "
3188 "unit not supported\n");
1f6f7129 3189 zfcp_erp_unit_failed(unit, 36, fsf_req);
1da177e4 3190 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1f6f7129 3191 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
1da177e4
LT
3192 }
3193 }
3194
3195 retval = 0;
3196 break;
3197
3198 default:
3199 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3200 "(debug info 0x%x)\n",
3201 header->fsf_status);
1da177e4
LT
3202 break;
3203 }
3204
3205 skip_fsfstatus:
3206 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3207 return retval;
3208}
3209
3210/*
3211 * function: zfcp_fsf_close_unit
3212 *
3213 * purpose:
3214 *
3215 * returns: address of fsf_req - request successfully initiated
41fa2ada 3216 * NULL -
1da177e4
LT
3217 *
3218 * assumptions: This routine does not check whether the associated
3219 * remote port/lun has already been opened. This should be
3220 * done by calling routines. Otherwise some status
3221 * may be presented by FSF
3222 */
3223int
3224zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3225{
3226 volatile struct qdio_buffer_element *sbale;
2abbe866 3227 struct zfcp_fsf_req *fsf_req;
1da177e4
LT
3228 unsigned long lock_flags;
3229 int retval = 0;
3230
3231 /* setup new FSF request */
3232 retval = zfcp_fsf_req_create(erp_action->adapter,
3233 FSF_QTCB_CLOSE_LUN,
3234 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3235 erp_action->adapter->pool.fsf_req_erp,
2abbe866 3236 &lock_flags, &fsf_req);
1da177e4
LT
3237 if (retval < 0) {
3238 ZFCP_LOG_INFO("error: Could not create close unit request for "
3239 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3240 erp_action->unit->fcp_lun,
3241 erp_action->port->wwpn,
3242 zfcp_get_busid_by_adapter(erp_action->adapter));
3243 goto out;
3244 }
3245
2abbe866 3246 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1da177e4
LT
3247 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3248 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3249
2abbe866
AH
3250 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3251 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
1da177e4 3252 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
2abbe866
AH
3253 fsf_req->data = (unsigned long) erp_action->unit;
3254 fsf_req->erp_action = erp_action;
3255 erp_action->fsf_req = fsf_req;
1da177e4 3256
2abbe866
AH
3257 zfcp_erp_start_timer(fsf_req);
3258 retval = zfcp_fsf_req_send(erp_action->fsf_req);
1da177e4
LT
3259 if (retval) {
3260 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3261 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3262 erp_action->unit->fcp_lun,
3263 erp_action->port->wwpn,
3264 zfcp_get_busid_by_adapter(erp_action->adapter));
2abbe866 3265 zfcp_fsf_req_free(fsf_req);
1da177e4
LT
3266 erp_action->fsf_req = NULL;
3267 goto out;
3268 }
3269
3270 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3271 "port 0x%016Lx, unit 0x%016Lx)\n",
3272 zfcp_get_busid_by_adapter(erp_action->adapter),
3273 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3274 out:
3275 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3276 lock_flags);
3277 return retval;
3278}
3279
3280/*
3281 * function: zfcp_fsf_close_unit_handler
3282 *
3283 * purpose: is called for finished Close LUN FSF command
3284 *
3285 * returns:
3286 */
3287static int
3288zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3289{
3290 int retval = -EINVAL;
3291 struct zfcp_unit *unit;
3292
059c97d0 3293 unit = (struct zfcp_unit *) fsf_req->data;
1da177e4
LT
3294
3295 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3296 /* don't change unit status in our bookkeeping */
3297 goto skip_fsfstatus;
3298 }
3299
3300 /* evaluate FSF status in QTCB */
3301 switch (fsf_req->qtcb->header.fsf_status) {
3302
3303 case FSF_PORT_HANDLE_NOT_VALID:
1da177e4
LT
3304 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3305 "0x%016Lx on adapter %s invalid. This may "
3306 "happen in rare circumstances\n",
3307 unit->port->handle,
3308 unit->port->wwpn,
3309 zfcp_get_busid_by_unit(unit));
3310 ZFCP_LOG_DEBUG("status qualifier:\n");
3311 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3312 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3313 sizeof (union fsf_status_qual));
1f6f7129 3314 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
1da177e4
LT
3315 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3316 break;
3317
3318 case FSF_LUN_HANDLE_NOT_VALID:
1da177e4
LT
3319 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3320 "0x%016Lx on port 0x%016Lx on adapter %s is "
3321 "invalid. This may happen occasionally.\n",
3322 unit->handle,
3323 unit->fcp_lun,
3324 unit->port->wwpn,
3325 zfcp_get_busid_by_unit(unit));
3326 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3327 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3328 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3329 sizeof (union fsf_status_qual));
1f6f7129 3330 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
1da177e4
LT
3331 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3332 break;
3333
3334 case FSF_PORT_BOXED:
1da177e4
LT
3335 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3336 "needs to be reopened\n",
3337 unit->port->wwpn,
3338 zfcp_get_busid_by_unit(unit));
1f6f7129 3339 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
1da177e4
LT
3340 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3341 ZFCP_STATUS_FSFREQ_RETRY;
3342 break;
3343
3344 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
3345 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3346 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1da177e4 3347 /* re-establish link to port */
65a8d4e1 3348 zfcp_test_link(unit->port);
1da177e4
LT
3349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3350 break;
3351 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1da177e4 3352 /* ERP strategy will escalate */
1da177e4
LT
3353 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3354 break;
3355 default:
3356 ZFCP_LOG_NORMAL
3357 ("bug: Wrong status qualifier 0x%x arrived.\n",
3358 fsf_req->qtcb->header.fsf_status_qual.word[0]);
1da177e4
LT
3359 break;
3360 }
3361 break;
3362
3363 case FSF_GOOD:
1da177e4
LT
3364 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3365 "closed, port handle 0x%x\n",
3366 unit->fcp_lun,
3367 unit->port->wwpn,
3368 zfcp_get_busid_by_unit(unit),
3369 unit->handle);
3370 /* mark unit as closed */
3371 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3372 retval = 0;
3373 break;
3374
3375 default:
3376 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3377 "(debug info 0x%x)\n",
3378 fsf_req->qtcb->header.fsf_status);
1da177e4
LT
3379 break;
3380 }
3381
3382 skip_fsfstatus:
3383 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3384 return retval;
3385}
3386
3387/**
3388 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3389 * @adapter: adapter where scsi command is issued
3390 * @unit: unit where command is sent to
3391 * @scsi_cmnd: scsi command to be sent
3392 * @timer: timer to be started when request is initiated
3393 * @req_flags: flags for fsf_request
3394 */
3395int
3396zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3397 struct zfcp_unit *unit,
3398 struct scsi_cmnd * scsi_cmnd,
2abbe866 3399 int use_timer, int req_flags)
1da177e4
LT
3400{
3401 struct zfcp_fsf_req *fsf_req = NULL;
3402 struct fcp_cmnd_iu *fcp_cmnd_iu;
3403 unsigned int sbtype;
3404 unsigned long lock_flags;
3405 int real_bytes = 0;
3406 int retval = 0;
3407 int mask;
3408
3409 /* setup new FSF request */
3410 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3411 adapter->pool.fsf_req_scsi,
3412 &lock_flags, &fsf_req);
3413 if (unlikely(retval < 0)) {
3414 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3415 "for unit 0x%016Lx on port 0x%016Lx on "
3416 "adapter %s\n",
3417 unit->fcp_lun,
3418 unit->port->wwpn,
3419 zfcp_get_busid_by_adapter(adapter));
3420 goto failed_req_create;
3421 }
3422
ba172420
CS
3423 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3424 &unit->status))) {
3425 retval = -EBUSY;
3426 goto unit_blocked;
3427 }
3428
059c97d0
AH
3429 zfcp_unit_get(unit);
3430 fsf_req->unit = unit;
1da177e4 3431
059c97d0 3432 /* associate FSF request with SCSI request (for look up on abort) */
4eff4a36 3433 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
059c97d0
AH
3434
3435 /* associate SCSI command with FSF request */
3436 fsf_req->data = (unsigned long) scsi_cmnd;
1da177e4
LT
3437
3438 /* set handles of unit and its parent port in QTCB */
3439 fsf_req->qtcb->header.lun_handle = unit->handle;
3440 fsf_req->qtcb->header.port_handle = unit->port->handle;
3441
3442 /* FSF does not define the structure of the FCP_CMND IU */
3443 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3444 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3445
3446 /*
3447 * set depending on data direction:
3448 * data direction bits in SBALE (SB Type)
3449 * data direction bits in QTCB
3450 * data direction bits in FCP_CMND IU
3451 */
3452 switch (scsi_cmnd->sc_data_direction) {
3453 case DMA_NONE:
1da177e4
LT
3454 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3455 /*
3456 * FIXME(qdio):
3457 * what is the correct type for commands
3458 * without 'real' data buffers?
3459 */
3460 sbtype = SBAL_FLAGS0_TYPE_READ;
3461 break;
3462 case DMA_FROM_DEVICE:
1da177e4
LT
3463 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3464 sbtype = SBAL_FLAGS0_TYPE_READ;
3465 fcp_cmnd_iu->rddata = 1;
3466 break;
3467 case DMA_TO_DEVICE:
1da177e4
LT
3468 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3469 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3470 fcp_cmnd_iu->wddata = 1;
3471 break;
3472 case DMA_BIDIRECTIONAL:
1da177e4
LT
3473 default:
3474 /*
3475 * dummy, catch this condition earlier
3476 * in zfcp_scsi_queuecommand
3477 */
3478 goto failed_scsi_cmnd;
3479 }
3480
3481 /* set FC service class in QTCB (3 per default) */
06506d00 3482 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1da177e4
LT
3483
3484 /* set FCP_LUN in FCP_CMND IU in QTCB */
3485 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3486
3487 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3488
3489 /* set task attributes in FCP_CMND IU in QTCB */
3490 if (likely((scsi_cmnd->device->simple_tags) ||
3491 (atomic_test_mask(mask, &unit->status))))
3492 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3493 else
3494 fcp_cmnd_iu->task_attribute = UNTAGGED;
3495
3496 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3497 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3498 fcp_cmnd_iu->add_fcp_cdb_length
3499 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3500 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3501 "additional FCP_CDB length is 0x%x "
3502 "(shifted right 2 bits)\n",
3503 scsi_cmnd->cmd_len,
3504 fcp_cmnd_iu->add_fcp_cdb_length);
3505 }
3506 /*
3507 * copy SCSI CDB (including additional length, if any) to
3508 * FCP_CDB in FCP_CMND IU in QTCB
3509 */
3510 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3511
3512 /* FCP CMND IU length in QTCB */
3513 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3514 sizeof (struct fcp_cmnd_iu) +
3515 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3516
3517 /* generate SBALEs from data buffer */
3518 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3519 if (unlikely(real_bytes < 0)) {
3520 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3521 ZFCP_LOG_DEBUG(
3522 "Data did not fit into available buffer(s), "
3523 "waiting for more...\n");
2282f658
CS
3524 retval = -EIO;
3525 } else {
3526 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3527 "required. Shutting down unit "
3528 "(adapter %s, port 0x%016Lx, "
3529 "unit 0x%016Lx)\n",
3530 zfcp_get_busid_by_unit(unit),
3531 unit->port->wwpn,
3532 unit->fcp_lun);
1f6f7129 3533 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
2282f658 3534 retval = -EINVAL;
1da177e4
LT
3535 }
3536 goto no_fit;
3537 }
3538
3539 /* set length of FCP data length in FCP_CMND IU in QTCB */
3540 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3541
3542 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3543 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3544 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3545
2abbe866
AH
3546 if (use_timer)
3547 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3548
3549 retval = zfcp_fsf_req_send(fsf_req);
1da177e4
LT
3550 if (unlikely(retval < 0)) {
3551 ZFCP_LOG_INFO("error: Could not send FCP command request "
3552 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3553 zfcp_get_busid_by_adapter(adapter),
3554 unit->port->wwpn,
3555 unit->fcp_lun);
3556 goto send_failed;
3557 }
3558
3559 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3560 "port 0x%016Lx, unit 0x%016Lx)\n",
3561 zfcp_get_busid_by_adapter(adapter),
3562 unit->port->wwpn,
3563 unit->fcp_lun);
3564 goto success;
3565
3566 send_failed:
3567 no_fit:
3568 failed_scsi_cmnd:
059c97d0 3569 zfcp_unit_put(unit);
57b7658a 3570 unit_blocked:
1da177e4
LT
3571 zfcp_fsf_req_free(fsf_req);
3572 fsf_req = NULL;
3573 scsi_cmnd->host_scribble = NULL;
3574 success:
3575 failed_req_create:
3576 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3577 return retval;
3578}
3579
1da177e4
LT
3580struct zfcp_fsf_req *
3581zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3582 struct zfcp_unit *unit,
3583 u8 tm_flags, int req_flags)
3584{
3585 struct zfcp_fsf_req *fsf_req = NULL;
3586 int retval = 0;
3587 struct fcp_cmnd_iu *fcp_cmnd_iu;
3588 unsigned long lock_flags;
3589 volatile struct qdio_buffer_element *sbale;
3590
3591 /* setup new FSF request */
3592 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3593 adapter->pool.fsf_req_scsi,
3594 &lock_flags, &fsf_req);
3595 if (retval < 0) {
3596 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3597 "management) request for adapter %s, port "
3598 " 0x%016Lx, unit 0x%016Lx.\n",
3599 zfcp_get_busid_by_adapter(adapter),
3600 unit->port->wwpn, unit->fcp_lun);
3601 goto out;
3602 }
3603
fdf23452
CS
3604 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3605 &unit->status)))
3606 goto unit_blocked;
3607
1da177e4
LT
3608 /*
3609 * Used to decide on proper handler in the return path,
3610 * could be either zfcp_fsf_send_fcp_command_task_handler or
3611 * zfcp_fsf_send_fcp_command_task_management_handler */
3612
3613 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3614
3615 /*
3616 * hold a pointer to the unit being target of this
3617 * task management request
3618 */
059c97d0 3619 fsf_req->data = (unsigned long) unit;
1da177e4
LT
3620
3621 /* set FSF related fields in QTCB */
3622 fsf_req->qtcb->header.lun_handle = unit->handle;
3623 fsf_req->qtcb->header.port_handle = unit->port->handle;
3624 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
06506d00 3625 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
1da177e4
LT
3626 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3627 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3628
3629 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3630 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3631 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3632
3633 /* set FCP related fields in FCP_CMND IU in QTCB */
3634 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3635 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3636 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3637 fcp_cmnd_iu->task_management_flags = tm_flags;
3638
2abbe866
AH
3639 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3640 retval = zfcp_fsf_req_send(fsf_req);
fdf23452 3641 if (!retval)
1da177e4 3642 goto out;
1da177e4 3643
fdf23452
CS
3644 unit_blocked:
3645 zfcp_fsf_req_free(fsf_req);
3646 fsf_req = NULL;
3647
1da177e4
LT
3648 out:
3649 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3650 return fsf_req;
3651}
3652
c9615858
CS
3653static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
3654{
3655 lat_rec->sum += lat;
3656 if (lat_rec->min > lat)
3657 lat_rec->min = lat;
3658 if (lat_rec->max < lat)
3659 lat_rec->max = lat;
3660}
3661
3662static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
3663{
3664 struct fsf_qual_latency_info *lat_inf;
3665 struct latency_cont *lat;
3666 struct zfcp_unit *unit;
3667 unsigned long flags;
3668
3669 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
3670 unit = fsf_req->unit;
3671
3672 switch (fsf_req->qtcb->bottom.io.data_direction) {
3673 case FSF_DATADIR_READ:
3674 lat = &unit->latencies.read;
3675 break;
3676 case FSF_DATADIR_WRITE:
3677 lat = &unit->latencies.write;
3678 break;
3679 case FSF_DATADIR_CMND:
3680 lat = &unit->latencies.cmd;
3681 break;
3682 default:
3683 return;
3684 }
3685
3686 spin_lock_irqsave(&unit->latencies.lock, flags);
3687 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
3688 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
3689 lat->counter++;
3690 spin_unlock_irqrestore(&unit->latencies.lock, flags);
3691}
3692
1da177e4
LT
3693/*
3694 * function: zfcp_fsf_send_fcp_command_handler
3695 *
3696 * purpose: is called for finished Send FCP Command
3697 *
41fa2ada 3698 * returns:
1da177e4
LT
3699 */
3700static int
3701zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3702{
3703 int retval = -EINVAL;
3704 struct zfcp_unit *unit;
3705 struct fsf_qtcb_header *header;
3706 u16 subtable, rule, counter;
3707
3708 header = &fsf_req->qtcb->header;
3709
3710 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
059c97d0 3711 unit = (struct zfcp_unit *) fsf_req->data;
1da177e4 3712 else
059c97d0 3713 unit = fsf_req->unit;
1da177e4
LT
3714
3715 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3716 /* go directly to calls of special handlers */
3717 goto skip_fsfstatus;
3718 }
3719
3720 /* evaluate FSF status in QTCB */
3721 switch (header->fsf_status) {
3722
3723 case FSF_PORT_HANDLE_NOT_VALID:
1da177e4
LT
3724 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3725 "0x%016Lx on adapter %s invalid\n",
3726 unit->port->handle,
3727 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3728 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3729 (char *) &header->fsf_status_qual,
3730 sizeof (union fsf_status_qual));
1f6f7129 3731 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
1da177e4
LT
3732 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3733 break;
3734
3735 case FSF_LUN_HANDLE_NOT_VALID:
1da177e4
LT
3736 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3737 "0x%016Lx on port 0x%016Lx on adapter %s is "
3738 "invalid. This may happen occasionally.\n",
3739 unit->handle,
3740 unit->fcp_lun,
3741 unit->port->wwpn,
3742 zfcp_get_busid_by_unit(unit));
3743 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3744 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3745 (char *) &header->fsf_status_qual,
3746 sizeof (union fsf_status_qual));
1f6f7129 3747 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
1da177e4
LT
3748 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3749 break;
3750
3751 case FSF_HANDLE_MISMATCH:
1da177e4
LT
3752 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3753 "unexpectedly. (adapter %s, port 0x%016Lx, "
3754 "unit 0x%016Lx)\n",
3755 unit->port->handle,
3756 zfcp_get_busid_by_unit(unit),
3757 unit->port->wwpn,
3758 unit->fcp_lun);
3759 ZFCP_LOG_NORMAL("status qualifier:\n");
3760 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3761 (char *) &header->fsf_status_qual,
3762 sizeof (union fsf_status_qual));
1f6f7129 3763 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
1da177e4
LT
3764 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3765 break;
3766
3767 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
06506d00
AH
3768 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3769 "class %d.\n",
3770 zfcp_get_busid_by_unit(unit),
3771 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1da177e4 3772 /* stop operation for this adapter */
1f6f7129 3773 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
1da177e4
LT
3774 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3775 break;
3776
3777 case FSF_FCPLUN_NOT_VALID:
1da177e4
LT
3778 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3779 "adapter %s does not have correct unit "
3780 "handle 0x%x\n",
3781 unit->fcp_lun,
3782 unit->port->wwpn,
3783 zfcp_get_busid_by_unit(unit),
3784 unit->handle);
3785 ZFCP_LOG_DEBUG("status qualifier:\n");
3786 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3787 (char *) &header->fsf_status_qual,
3788 sizeof (union fsf_status_qual));
1f6f7129 3789 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
1da177e4
LT
3790 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3791 break;
3792
3793 case FSF_ACCESS_DENIED:
1da177e4
LT
3794 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3795 "unit 0x%016Lx on port 0x%016Lx on "
3796 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3797 zfcp_get_busid_by_unit(unit));
3798 for (counter = 0; counter < 2; counter++) {
3799 subtable = header->fsf_status_qual.halfword[counter * 2];
3800 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3801 switch (subtable) {
3802 case FSF_SQ_CFDC_SUBTABLE_OS:
3803 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3804 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3805 case FSF_SQ_CFDC_SUBTABLE_LUN:
3806 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3807 zfcp_act_subtable_type[subtable], rule);
3808 break;
3809 }
3810 }
1f6f7129 3811 zfcp_erp_unit_access_denied(unit, 61, fsf_req);
1da177e4
LT
3812 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3813 break;
3814
3815 case FSF_DIRECTION_INDICATOR_NOT_VALID:
1da177e4
LT
3816 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3817 "0x%016Lx on port 0x%016Lx on adapter %s "
3818 "(debug info %d)\n",
3819 unit->fcp_lun,
3820 unit->port->wwpn,
3821 zfcp_get_busid_by_unit(unit),
3822 fsf_req->qtcb->bottom.io.data_direction);
3823 /* stop operation for this adapter */
1f6f7129 3824 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
1da177e4
LT
3825 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3826 break;
3827
3828 case FSF_CMND_LENGTH_NOT_VALID:
1da177e4
LT
3829 ZFCP_LOG_NORMAL
3830 ("bug: An invalid control-data-block length field "
3831 "was found in a command for unit 0x%016Lx on port "
3832 "0x%016Lx on adapter %s " "(debug info %d)\n",
3833 unit->fcp_lun, unit->port->wwpn,
3834 zfcp_get_busid_by_unit(unit),
3835 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3836 /* stop operation for this adapter */
1f6f7129 3837 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
1da177e4
LT
3838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3839 break;
3840
3841 case FSF_PORT_BOXED:
1da177e4
LT
3842 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3843 "needs to be reopened\n",
3844 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1f6f7129 3845 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
1da177e4
LT
3846 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3847 ZFCP_STATUS_FSFREQ_RETRY;
3848 break;
3849
3850 case FSF_LUN_BOXED:
1da177e4
LT
3851 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3852 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3853 zfcp_get_busid_by_unit(unit),
3854 unit->port->wwpn, unit->fcp_lun);
1f6f7129 3855 zfcp_erp_unit_boxed(unit, 54, fsf_req);
1da177e4
LT
3856 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3857 | ZFCP_STATUS_FSFREQ_RETRY;
3858 break;
3859
3860 case FSF_ADAPTER_STATUS_AVAILABLE:
1da177e4
LT
3861 switch (header->fsf_status_qual.word[0]) {
3862 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1da177e4 3863 /* re-establish link to port */
65a8d4e1 3864 zfcp_test_link(unit->port);
1da177e4
LT
3865 break;
3866 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1da177e4
LT
3867 /* FIXME(hw) need proper specs for proper action */
3868 /* let scsi stack deal with retries and escalation */
1da177e4
LT
3869 break;
3870 default:
1da177e4 3871 ZFCP_LOG_NORMAL
516a4201 3872 ("Unknown status qualifier 0x%x arrived.\n",
1da177e4 3873 header->fsf_status_qual.word[0]);
1da177e4
LT
3874 break;
3875 }
516a4201 3876 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1da177e4
LT
3877 break;
3878
3879 case FSF_GOOD:
1da177e4
LT
3880 break;
3881
3882 case FSF_FCP_RSP_AVAILABLE:
1da177e4 3883 break;
1da177e4
LT
3884 }
3885
3886 skip_fsfstatus:
3887 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3888 retval =
3889 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3890 } else {
3891 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
059c97d0
AH
3892 fsf_req->unit = NULL;
3893 zfcp_unit_put(unit);
1da177e4
LT
3894 }
3895 return retval;
3896}
3897
3898/*
3899 * function: zfcp_fsf_send_fcp_command_task_handler
3900 *
3901 * purpose: evaluates FCP_RSP IU
3902 *
41fa2ada 3903 * returns:
1da177e4
LT
3904 */
3905static int
3906zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3907{
3908 int retval = 0;
3909 struct scsi_cmnd *scpnt;
3910 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3911 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3912 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3913 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3914 u32 sns_len;
3915 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3916 unsigned long flags;
059c97d0 3917 struct zfcp_unit *unit = fsf_req->unit;
1da177e4
LT
3918
3919 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
059c97d0 3920 scpnt = (struct scsi_cmnd *) fsf_req->data;
1da177e4
LT
3921 if (unlikely(!scpnt)) {
3922 ZFCP_LOG_DEBUG
3923 ("Command with fsf_req %p is not associated to "
3924 "a scsi command anymore. Aborted?\n", fsf_req);
3925 goto out;
3926 }
3927 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3928 /* FIXME: (design) mid-layer should handle DID_ABORT like
3929 * DID_SOFT_ERROR by retrying the request for devices
3930 * that allow retries.
3931 */
3932 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3933 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3934 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3935 goto skip_fsfstatus;
3936 }
3937
3938 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3939 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3940 set_host_byte(&scpnt->result, DID_ERROR);
3941 goto skip_fsfstatus;
3942 }
3943
3944 /* set message byte of result in SCSI command */
3945 scpnt->result |= COMMAND_COMPLETE << 8;
3946
3947 /*
3948 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3949 * of result in SCSI command
3950 */
3951 scpnt->result |= fcp_rsp_iu->scsi_status;
3952 if (unlikely(fcp_rsp_iu->scsi_status)) {
3953 /* DEBUG */
3954 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
3955 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3956 scpnt->cmnd, scpnt->cmd_len);
3957 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
3958 fcp_rsp_iu->scsi_status);
3959 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3960 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
3961 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3962 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
3963 fcp_rsp_iu->fcp_sns_len);
3964 }
3965
c9615858
CS
3966 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
3967 zfcp_fsf_req_latency(fsf_req);
3968
1da177e4
LT
3969 /* check FCP_RSP_INFO */
3970 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
3971 ZFCP_LOG_DEBUG("rsp_len is valid\n");
3972 switch (fcp_rsp_info[3]) {
3973 case RSP_CODE_GOOD:
1da177e4
LT
3974 /* ok, continue */
3975 ZFCP_LOG_TRACE("no failure or Task Management "
3976 "Function complete\n");
3977 set_host_byte(&scpnt->result, DID_OK);
3978 break;
3979 case RSP_CODE_LENGTH_MISMATCH:
1da177e4
LT
3980 /* hardware bug */
3981 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3982 "that the fibrechannel protocol data "
3983 "length differs from the burst length. "
3984 "The problem occured on unit 0x%016Lx "
3985 "on port 0x%016Lx on adapter %s",
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 case RSP_CODE_FIELD_INVALID:
1da177e4
LT
3996 /* driver or hardware bug */
3997 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3998 "that the fibrechannel protocol data "
3999 "fields were incorrectly set up. "
4000 "The problem occured on the unit "
4001 "0x%016Lx on port 0x%016Lx on "
4002 "adapter %s",
4003 unit->fcp_lun,
4004 unit->port->wwpn,
4005 zfcp_get_busid_by_unit(unit));
4006 /* dump SCSI CDB as prepared by zfcp */
4007 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4008 (char *) &fsf_req->qtcb->
4009 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4010 set_host_byte(&scpnt->result, DID_ERROR);
1da177e4
LT
4011 goto skip_fsfstatus;
4012 case RSP_CODE_RO_MISMATCH:
1da177e4
LT
4013 /* hardware bug */
4014 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4015 "that conflicting values for the "
4016 "fibrechannel payload offset from the "
4017 "header were found. "
4018 "The problem occured on unit 0x%016Lx "
4019 "on port 0x%016Lx on adapter %s.\n",
4020 unit->fcp_lun,
4021 unit->port->wwpn,
4022 zfcp_get_busid_by_unit(unit));
4023 /* dump SCSI CDB as prepared by zfcp */
4024 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4025 (char *) &fsf_req->qtcb->
4026 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
1da177e4
LT
4027 set_host_byte(&scpnt->result, DID_ERROR);
4028 goto skip_fsfstatus;
4029 default:
4030 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4031 "code was detected for a command. "
4032 "The problem occured on the unit "
4033 "0x%016Lx on port 0x%016Lx on "
4034 "adapter %s (debug info 0x%x)\n",
4035 unit->fcp_lun,
4036 unit->port->wwpn,
4037 zfcp_get_busid_by_unit(unit),
4038 fcp_rsp_info[3]);
4039 /* dump SCSI CDB as prepared by zfcp */
4040 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4041 (char *) &fsf_req->qtcb->
4042 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
1da177e4 4043 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9bc 4044 goto skip_fsfstatus;
1da177e4
LT
4045 }
4046 }
4047
4048 /* check for sense data */
4049 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4050 sns_len = FSF_FCP_RSP_SIZE -
4051 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4052 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4053 sns_len);
4054 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4055 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4056 SCSI_SENSE_BUFFERSIZE);
4057 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4058 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4059 scpnt->result);
4060 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
64a87b24 4061 scpnt->cmnd, scpnt->cmd_len);
1da177e4
LT
4062
4063 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4064 fcp_rsp_iu->fcp_sns_len);
9d058ecf 4065 memcpy(scpnt->sense_buffer,
1da177e4
LT
4066 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4067 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
9d058ecf 4068 (void *)scpnt->sense_buffer, sns_len);
1da177e4
LT
4069 }
4070
4071 /* check for overrun */
4072 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4073 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4074 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4075 "The response data length is "
4076 "%d, the original length was %d.\n",
4077 unit->fcp_lun,
4078 unit->port->wwpn,
4079 zfcp_get_busid_by_unit(unit),
4080 fcp_rsp_iu->fcp_resid,
4081 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4082 }
4083
4084 /* check for underrun */
4085 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4086 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4087 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4088 "The response data length is "
4089 "%d, the original length was %d.\n",
4090 unit->fcp_lun,
4091 unit->port->wwpn,
4092 zfcp_get_busid_by_unit(unit),
4093 fcp_rsp_iu->fcp_resid,
4094 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4095
7936a892
FT
4096 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4097 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4098 scpnt->underflow)
6f71d9bc 4099 set_host_byte(&scpnt->result, DID_ERROR);
1da177e4
LT
4100 }
4101
4102 skip_fsfstatus:
4103 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4104
8a36e453 4105 if (scpnt->result != 0)
ed829ad6 4106 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
8a36e453 4107 else if (scpnt->retries > 0)
ed829ad6 4108 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
8a36e453 4109 else
ed829ad6 4110 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
1da177e4
LT
4111
4112 /* cleanup pointer (need this especially for abort) */
4113 scpnt->host_scribble = NULL;
4114
1da177e4 4115 /* always call back */
1da177e4
LT
4116 (scpnt->scsi_done) (scpnt);
4117
4118 /*
4119 * We must hold this lock until scsi_done has been called.
4120 * Otherwise we may call scsi_done after abort regarding this
4121 * command has completed.
4122 * Note: scsi_done must not block!
4123 */
4124 out:
4125 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4126 return retval;
4127}
4128
4129/*
4130 * function: zfcp_fsf_send_fcp_command_task_management_handler
4131 *
4132 * purpose: evaluates FCP_RSP IU
4133 *
41fa2ada 4134 * returns:
1da177e4
LT
4135 */
4136static int
4137zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4138{
4139 int retval = 0;
4140 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4141 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4142 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
059c97d0 4143 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
1da177e4 4144
1da177e4
LT
4145 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4146 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4147 goto skip_fsfstatus;
4148 }
4149
4150 /* check FCP_RSP_INFO */
4151 switch (fcp_rsp_info[3]) {
4152 case RSP_CODE_GOOD:
1da177e4
LT
4153 /* ok, continue */
4154 ZFCP_LOG_DEBUG("no failure or Task Management "
4155 "Function complete\n");
4156 break;
4157 case RSP_CODE_TASKMAN_UNSUPP:
1da177e4
LT
4158 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4159 "is not supported on the target device "
4160 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4161 unit->fcp_lun,
4162 unit->port->wwpn,
4163 zfcp_get_busid_by_unit(unit));
4164 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4165 break;
4166 case RSP_CODE_TASKMAN_FAILED:
1da177e4
LT
4167 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4168 "failed to complete successfully. "
4169 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4170 unit->fcp_lun,
4171 unit->port->wwpn,
4172 zfcp_get_busid_by_unit(unit));
4173 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4174 break;
4175 default:
4176 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4177 "code was detected for a command. "
4178 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4179 "(debug info 0x%x)\n",
4180 unit->fcp_lun,
4181 unit->port->wwpn,
4182 zfcp_get_busid_by_unit(unit),
4183 fcp_rsp_info[3]);
4184 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4185 }
4186
4187 skip_fsfstatus:
4188 return retval;
4189}
4190
4191
4192/*
4193 * function: zfcp_fsf_control_file
4194 *
4195 * purpose: Initiator of the control file upload/download FSF requests
4196 *
4197 * returns: 0 - FSF request is successfuly created and queued
4198 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4199 * -EINVAL - Invalid direction specified
4200 * -ENOMEM - Insufficient memory
4201 * -EPERM - Cannot create FSF request or place it in QDIO queue
4202 */
4203int
4204zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4205 struct zfcp_fsf_req **fsf_req_ptr,
4206 u32 fsf_command,
4207 u32 option,
4208 struct zfcp_sg_list *sg_list)
4209{
4210 struct zfcp_fsf_req *fsf_req;
4211 struct fsf_qtcb_bottom_support *bottom;
4212 volatile struct qdio_buffer_element *sbale;
1da177e4
LT
4213 unsigned long lock_flags;
4214 int req_flags = 0;
4215 int direction;
4216 int retval = 0;
4217
aef4a983 4218 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
1da177e4
LT
4219 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4220 zfcp_get_busid_by_adapter(adapter));
4221 retval = -EOPNOTSUPP;
4222 goto out;
4223 }
4224
4225 switch (fsf_command) {
4226
4227 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4228 direction = SBAL_FLAGS0_TYPE_WRITE;
4229 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4230 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4231 req_flags = ZFCP_WAIT_FOR_SBAL;
4232 break;
4233
4234 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4235 direction = SBAL_FLAGS0_TYPE_READ;
4236 break;
4237
4238 default:
4239 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4240 retval = -EINVAL;
4241 goto out;
4242 }
4243
1da177e4
LT
4244 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4245 NULL, &lock_flags, &fsf_req);
4246 if (retval < 0) {
4247 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4248 "adapter %s\n",
4249 zfcp_get_busid_by_adapter(adapter));
4250 retval = -EPERM;
4251 goto unlock_queue_lock;
4252 }
4253
4254 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4255 sbale[0].flags |= direction;
4256
4257 bottom = &fsf_req->qtcb->bottom.support;
4258 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4259 bottom->option = option;
4260
4261 if (sg_list->count > 0) {
4262 int bytes;
4263
4264 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4265 sg_list->sg, sg_list->count,
4266 ZFCP_MAX_SBALS_PER_REQ);
4267 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4268 ZFCP_LOG_INFO(
4269 "error: Could not create sufficient number of "
4270 "SBALS for an FSF request to the adapter %s\n",
4271 zfcp_get_busid_by_adapter(adapter));
4272 retval = -ENOMEM;
4273 goto free_fsf_req;
4274 }
4275 } else
4276 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4277
2abbe866
AH
4278 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4279 retval = zfcp_fsf_req_send(fsf_req);
1da177e4
LT
4280 if (retval < 0) {
4281 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4282 "(adapter %s)\n",
4283 zfcp_get_busid_by_adapter(adapter));
4284 retval = -EPERM;
4285 goto free_fsf_req;
4286 }
4287 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4288
4289 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4290 "adapter %s\n",
4291 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4292 "download" : "upload",
4293 zfcp_get_busid_by_adapter(adapter));
4294
4295 wait_event(fsf_req->completion_wq,
4296 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4297
4298 *fsf_req_ptr = fsf_req;
2abbe866 4299 goto out;
1da177e4
LT
4300
4301 free_fsf_req:
4302 zfcp_fsf_req_free(fsf_req);
4303 unlock_queue_lock:
4304 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1da177e4
LT
4305 out:
4306 return retval;
4307}
4308
4309
4310/*
4311 * function: zfcp_fsf_control_file_handler
4312 *
4313 * purpose: Handler of the control file upload/download FSF requests
4314 *
4315 * returns: 0 - FSF request successfuly processed
4316 * -EAGAIN - Operation has to be repeated because of a temporary problem
4317 * -EACCES - There is no permission to execute an operation
4318 * -EPERM - The control file is not in a right format
4319 * -EIO - There is a problem with the FCP adapter
4320 * -EINVAL - Invalid operation
4321 * -EFAULT - User space memory I/O operation fault
4322 */
4323static int
4324zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4325{
4326 struct zfcp_adapter *adapter = fsf_req->adapter;
4327 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4328 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4329 int retval = 0;
4330
4331 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4332 retval = -EINVAL;
4333 goto skip_fsfstatus;
4334 }
4335
4336 switch (header->fsf_status) {
4337
4338 case FSF_GOOD:
1da177e4
LT
4339 ZFCP_LOG_NORMAL(
4340 "The FSF request has been successfully completed "
4341 "on the adapter %s\n",
4342 zfcp_get_busid_by_adapter(adapter));
4343 break;
4344
4345 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
1da177e4
LT
4346 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4347 switch (header->fsf_status_qual.word[0]) {
4348
6f71d9bc
JB
4349 case FSF_SQ_CFDC_HARDENED_ON_SE:
4350 ZFCP_LOG_NORMAL(
4351 "CFDC on the adapter %s has being "
4352 "hardened on primary and secondary SE\n",
4353 zfcp_get_busid_by_adapter(adapter));
4354 break;
4355
1da177e4
LT
4356 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4357 ZFCP_LOG_NORMAL(
4358 "CFDC of the adapter %s could not "
4359 "be saved on the SE\n",
4360 zfcp_get_busid_by_adapter(adapter));
4361 break;
4362
4363 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4364 ZFCP_LOG_NORMAL(
4365 "CFDC of the adapter %s could not "
4366 "be copied to the secondary SE\n",
4367 zfcp_get_busid_by_adapter(adapter));
4368 break;
4369
4370 default:
4371 ZFCP_LOG_NORMAL(
4372 "CFDC could not be hardened "
4373 "on the adapter %s\n",
4374 zfcp_get_busid_by_adapter(adapter));
4375 }
4376 }
4377 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4378 retval = -EAGAIN;
4379 break;
4380
4381 case FSF_AUTHORIZATION_FAILURE:
1da177e4
LT
4382 ZFCP_LOG_NORMAL(
4383 "Adapter %s does not accept privileged commands\n",
4384 zfcp_get_busid_by_adapter(adapter));
4385 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4386 retval = -EACCES;
4387 break;
4388
4389 case FSF_CFDC_ERROR_DETECTED:
1da177e4
LT
4390 ZFCP_LOG_NORMAL(
4391 "Error at position %d in the CFDC, "
4392 "CFDC is discarded by the adapter %s\n",
4393 header->fsf_status_qual.word[0],
4394 zfcp_get_busid_by_adapter(adapter));
4395 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4396 retval = -EPERM;
4397 break;
4398
4399 case FSF_CONTROL_FILE_UPDATE_ERROR:
1da177e4
LT
4400 ZFCP_LOG_NORMAL(
4401 "Adapter %s cannot harden the control file, "
4402 "file is discarded\n",
4403 zfcp_get_busid_by_adapter(adapter));
4404 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4405 retval = -EIO;
4406 break;
4407
4408 case FSF_CONTROL_FILE_TOO_LARGE:
1da177e4
LT
4409 ZFCP_LOG_NORMAL(
4410 "Control file is too large, file is discarded "
4411 "by the adapter %s\n",
4412 zfcp_get_busid_by_adapter(adapter));
4413 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4414 retval = -EIO;
4415 break;
4416
4417 case FSF_ACCESS_CONFLICT_DETECTED:
1da177e4
LT
4418 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4419 ZFCP_LOG_NORMAL(
4420 "CFDC has been discarded by the adapter %s, "
4421 "because activation would impact "
4422 "%d active connection(s)\n",
4423 zfcp_get_busid_by_adapter(adapter),
4424 header->fsf_status_qual.word[0]);
4425 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4426 retval = -EIO;
4427 break;
4428
4429 case FSF_CONFLICTS_OVERRULED:
1da177e4
LT
4430 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4431 ZFCP_LOG_NORMAL(
4432 "CFDC has been activated on the adapter %s, "
4433 "but activation has impacted "
4434 "%d active connection(s)\n",
4435 zfcp_get_busid_by_adapter(adapter),
4436 header->fsf_status_qual.word[0]);
4437 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4438 retval = -EIO;
4439 break;
4440
4441 case FSF_UNKNOWN_OP_SUBTYPE:
1da177e4
LT
4442 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4443 "op_subtype=0x%x)\n",
4444 zfcp_get_busid_by_adapter(adapter),
4445 bottom->operation_subtype);
4446 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4447 retval = -EINVAL;
4448 break;
4449
4450 case FSF_INVALID_COMMAND_OPTION:
1da177e4
LT
4451 ZFCP_LOG_NORMAL(
4452 "Invalid option 0x%x has been specified "
4453 "in QTCB bottom sent to the adapter %s\n",
4454 bottom->option,
4455 zfcp_get_busid_by_adapter(adapter));
4456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4457 retval = -EINVAL;
4458 break;
4459
4460 default:
4461 ZFCP_LOG_NORMAL(
4462 "bug: An unknown/unexpected FSF status 0x%08x "
4463 "was presented on the adapter %s\n",
4464 header->fsf_status,
4465 zfcp_get_busid_by_adapter(adapter));
1da177e4
LT
4466 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4467 retval = -EINVAL;
4468 break;
4469 }
4470
4471skip_fsfstatus:
4472 return retval;
4473}
4474
1da177e4
LT
4475static inline int
4476zfcp_fsf_req_sbal_check(unsigned long *flags,
4477 struct zfcp_qdio_queue *queue, int needed)
4478{
4479 write_lock_irqsave(&queue->queue_lock, *flags);
4480 if (likely(atomic_read(&queue->free_count) >= needed))
4481 return 1;
4482 write_unlock_irqrestore(&queue->queue_lock, *flags);
4483 return 0;
4484}
4485
4486/*
4487 * set qtcb pointer in fsf_req and initialize QTCB
4488 */
4d284cac 4489static void
8a36e453 4490zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
1da177e4
LT
4491{
4492 if (likely(fsf_req->qtcb != NULL)) {
fea9d6c7
VS
4493 fsf_req->qtcb->prefix.req_seq_no =
4494 fsf_req->adapter->fsf_req_seq_no;
4495 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
1da177e4 4496 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
fea9d6c7
VS
4497 fsf_req->qtcb->prefix.qtcb_type =
4498 fsf_qtcb_type[fsf_req->fsf_command];
1da177e4 4499 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
fea9d6c7 4500 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
8a36e453 4501 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
1da177e4
LT
4502 }
4503}
4504
4505/**
4506 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4507 * @adapter: adapter for which request queue is examined
4508 * @req_flags: flags indicating whether to wait for needed SBAL or not
4509 * @lock_flags: lock_flags if queue_lock is taken
4510 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4511 * Locks: lock adapter->request_queue->queue_lock on success
4512 */
4513static int
4514zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4515 unsigned long *lock_flags)
4516{
4517 long ret;
4518 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4519
4520 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4521 ret = wait_event_interruptible_timeout(adapter->request_wq,
4522 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4523 ZFCP_SBAL_TIMEOUT);
4524 if (ret < 0)
4525 return ret;
4526 if (!ret)
4527 return -EIO;
4528 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4529 return -EIO;
4530
4531 return 0;
4532}
4533
4534/*
4535 * function: zfcp_fsf_req_create
4536 *
4537 * purpose: create an FSF request at the specified adapter and
4538 * setup common fields
4539 *
4540 * returns: -ENOMEM if there was insufficient memory for a request
4541 * -EIO if no qdio buffers could be allocate to the request
4542 * -EINVAL/-EPERM on bug conditions in req_dequeue
4543 * 0 in success
4544 *
4545 * note: The created request is returned by reference.
4546 *
4547 * locks: lock of concerned request queue must not be held,
4548 * but is held on completion (write, irqsave)
4549 */
4550int
4551zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4552 mempool_t *pool, unsigned long *lock_flags,
4553 struct zfcp_fsf_req **fsf_req_p)
4554{
4555 volatile struct qdio_buffer_element *sbale;
4556 struct zfcp_fsf_req *fsf_req = NULL;
4557 int ret = 0;
4558 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4559
4560 /* allocate new FSF request */
4561 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4562 if (unlikely(NULL == fsf_req)) {
ceb3dfba 4563 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
1da177e4
LT
4564 "the outbound (send) queue.\n");
4565 ret = -ENOMEM;
4566 goto failed_fsf_req;
4567 }
4568
8a36e453
MS
4569 fsf_req->adapter = adapter;
4570 fsf_req->fsf_command = fsf_cmd;
fea9d6c7 4571 INIT_LIST_HEAD(&fsf_req->list);
2abbe866 4572 init_timer(&fsf_req->timer);
1da177e4 4573
41fa2ada 4574 /* initialize waitqueue which may be used to wait on
1da177e4
LT
4575 this request completion */
4576 init_waitqueue_head(&fsf_req->completion_wq);
4577
4578 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
801e0ced 4579 if (ret < 0)
1da177e4 4580 goto failed_sbals;
801e0ced
CS
4581
4582 /* this is serialized (we are holding req_queue-lock of adapter) */
4583 if (adapter->req_no == 0)
4584 adapter->req_no++;
4585 fsf_req->req_id = adapter->req_no++;
4586
4587 zfcp_fsf_req_qtcb_init(fsf_req);
1da177e4
LT
4588
4589 /*
4590 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4591 * if it is not set (see also *_open_qdio and *_close_qdio).
4592 */
4593
4594 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4595 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4596 ret = -EIO;
4597 goto failed_sbals;
4598 }
4599
8a36e453
MS
4600 if (fsf_req->qtcb) {
4601 fsf_req->seq_no = adapter->fsf_req_seq_no;
4602 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4603 }
1da177e4
LT
4604 fsf_req->sbal_number = 1;
4605 fsf_req->sbal_first = req_queue->free_index;
4606 fsf_req->sbal_curr = req_queue->free_index;
4607 fsf_req->sbale_curr = 1;
4608
4609 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4610 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4611 }
4612
4613 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4614
4615 /* setup common SBALE fields */
fea9d6c7 4616 sbale[0].addr = (void *) fsf_req->req_id;
1da177e4
LT
4617 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4618 if (likely(fsf_req->qtcb != NULL)) {
4619 sbale[1].addr = (void *) fsf_req->qtcb;
4620 sbale[1].length = sizeof(struct fsf_qtcb);
4621 }
4622
4623 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4624 fsf_req->sbal_number, fsf_req->sbal_first);
4625
4626 goto success;
4627
4628 failed_sbals:
4629/* dequeue new FSF request previously enqueued */
4630 zfcp_fsf_req_free(fsf_req);
4631 fsf_req = NULL;
4632
4633 failed_fsf_req:
4634 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4635 success:
4636 *fsf_req_p = fsf_req;
4637 return ret;
4638}
4639
4640/*
4641 * function: zfcp_fsf_req_send
4642 *
4643 * purpose: start transfer of FSF request via QDIO
4644 *
4645 * returns: 0 - request transfer succesfully started
4646 * !0 - start of request transfer failed
4647 */
2abbe866 4648static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
1da177e4
LT
4649{
4650 struct zfcp_adapter *adapter;
4651 struct zfcp_qdio_queue *req_queue;
4652 volatile struct qdio_buffer_element *sbale;
8a36e453 4653 int inc_seq_no;
1da177e4 4654 int new_distance_from_int;
1da177e4
LT
4655 int retval = 0;
4656
4657 adapter = fsf_req->adapter;
4658 req_queue = &adapter->request_queue,
4659
4660
4661 /* FIXME(debug): remove it later */
4662 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4663 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4664 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4665 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4666 sbale[1].length);
4667
fea9d6c7
VS
4668 /* put allocated FSF request into hash table */
4669 spin_lock(&adapter->req_list_lock);
4670 zfcp_reqlist_add(adapter, fsf_req);
4671 spin_unlock(&adapter->req_list_lock);
1da177e4 4672
8a36e453
MS
4673 inc_seq_no = (fsf_req->qtcb != NULL);
4674
1da177e4
LT
4675 ZFCP_LOG_TRACE("request queue of adapter %s: "
4676 "next free SBAL is %i, %i free SBALs\n",
4677 zfcp_get_busid_by_adapter(adapter),
4678 req_queue->free_index,
4679 atomic_read(&req_queue->free_count));
4680
4681 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4682 "index_in_queue=%i, count=%i, buffers=%p\n",
4683 zfcp_get_busid_by_adapter(adapter),
4684 QDIO_FLAG_SYNC_OUTPUT,
4685 0, fsf_req->sbal_first, fsf_req->sbal_number,
4686 &req_queue->buffer[fsf_req->sbal_first]);
4687
4688 /*
4689 * adjust the number of free SBALs in request queue as well as
4690 * position of first one
4691 */
4692 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4693 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4694 req_queue->free_index += fsf_req->sbal_number; /* increase */
4695 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4696 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4697
8a36e453
MS
4698 fsf_req->issued = get_clock();
4699
1da177e4
LT
4700 retval = do_QDIO(adapter->ccw_device,
4701 QDIO_FLAG_SYNC_OUTPUT,
4702 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4703
4704 if (unlikely(retval)) {
4705 /* Queues are down..... */
4706 retval = -EIO;
2abbe866 4707 del_timer(&fsf_req->timer);
fea9d6c7 4708 spin_lock(&adapter->req_list_lock);
ca2d02c2 4709 zfcp_reqlist_remove(adapter, fsf_req);
fea9d6c7
VS
4710 spin_unlock(&adapter->req_list_lock);
4711 /* undo changes in request queue made for this request */
1da177e4
LT
4712 zfcp_qdio_zero_sbals(req_queue->buffer,
4713 fsf_req->sbal_first, fsf_req->sbal_number);
4714 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
fea9d6c7 4715 req_queue->free_index -= fsf_req->sbal_number;
1da177e4
LT
4716 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4717 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
1f6f7129 4718 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
1da177e4
LT
4719 } else {
4720 req_queue->distance_from_int = new_distance_from_int;
4721 /*
4722 * increase FSF sequence counter -
4723 * this must only be done for request successfully enqueued to
4724 * QDIO this rejected requests may be cleaned up by calling
4725 * routines resulting in missing sequence counter values
4726 * otherwise,
4727 */
8a36e453 4728
1da177e4 4729 /* Don't increase for unsolicited status */
8a36e453 4730 if (inc_seq_no)
1da177e4 4731 adapter->fsf_req_seq_no++;
8a36e453 4732
1da177e4 4733 /* count FSF requests pending */
fea9d6c7 4734 atomic_inc(&adapter->reqs_active);
1da177e4
LT
4735 }
4736 return retval;
4737}
4738
1da177e4 4739#undef ZFCP_LOG_AREA