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