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