blob: f994f453e2d2514b5a3551843139d218eaf2e50c [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 Herrmannd736a27b2005-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 Herrmannd736a27b2005-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 Herrmannd736a27b2005-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;
1620 fc_id_t d_id;
1621 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 Herrmann64b29a132005-06-13 13:18:56 +02001743 fc_id_t 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;
1981
1982 bottom = &fsf_req->qtcb->bottom.config;
1983 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1984 bottom->low_qtcb_version, bottom->high_qtcb_version);
1985 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001986 adapter->adapter_features = bottom->adapter_features;
1987 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05001988 adapter->peer_wwpn = 0;
1989 adapter->peer_wwnn = 0;
1990 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
1992 if (xchg_ok) {
1993 adapter->wwnn = bottom->nport_serv_param.wwnn;
1994 adapter->wwpn = bottom->nport_serv_param.wwpn;
1995 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
1996 adapter->fc_topology = bottom->fc_topology;
1997 adapter->fc_link_speed = bottom->fc_link_speed;
1998 adapter->hydra_version = bottom->adapter_type;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001999 if (adapter->physical_wwpn == 0)
2000 adapter->physical_wwpn = adapter->wwpn;
2001 if (adapter->physical_s_id == 0)
2002 adapter->physical_s_id = adapter->s_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 } else {
2004 adapter->wwnn = 0;
2005 adapter->wwpn = 0;
2006 adapter->s_id = 0;
2007 adapter->fc_topology = 0;
2008 adapter->fc_link_speed = 0;
2009 adapter->hydra_version = 0;
2010 }
2011
6f71d9b2005-04-10 23:04:28 -05002012 if (adapter->fc_topology == FSF_TOPO_P2P) {
2013 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2014 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2015 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2016 }
2017
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002018 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 adapter->hardware_version = bottom->hardware_version;
2020 memcpy(adapter->serial_number, bottom->serial_number, 17);
2021 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2022 }
2023
6f71d9b2005-04-10 23:04:28 -05002024 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 "WWNN 0x%016Lx, "
2026 "WWPN 0x%016Lx, "
2027 "S_ID 0x%08x,\n"
2028 "adapter version 0x%x, "
2029 "LIC version 0x%x, "
2030 "FC link speed %d Gb/s\n",
2031 zfcp_get_busid_by_adapter(adapter),
2032 adapter->wwnn,
2033 adapter->wwpn,
2034 (unsigned int) adapter->s_id,
2035 adapter->hydra_version,
2036 adapter->fsf_lic_version,
2037 adapter->fc_link_speed);
2038 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2039 ZFCP_LOG_NORMAL("error: the adapter %s "
2040 "only supports newer control block "
2041 "versions in comparison to this device "
2042 "driver (try updated device driver)\n",
2043 zfcp_get_busid_by_adapter(adapter));
2044 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2045 zfcp_erp_adapter_shutdown(adapter, 0);
2046 return -EIO;
2047 }
2048 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2049 ZFCP_LOG_NORMAL("error: the adapter %s "
2050 "only supports older control block "
2051 "versions than this device driver uses"
2052 "(consider a microcode upgrade)\n",
2053 zfcp_get_busid_by_adapter(adapter));
2054 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2055 zfcp_erp_adapter_shutdown(adapter, 0);
2056 return -EIO;
2057 }
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002058 zfcp_set_fc_host_attrs(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 return 0;
2060}
2061
2062/*
2063 * function: zfcp_fsf_exchange_config_data_handler
2064 *
2065 * purpose: is called for finished Exchange Configuration Data command
2066 *
2067 * returns:
2068 */
2069static int
2070zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2071{
2072 struct fsf_qtcb_bottom_config *bottom;
2073 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002074 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
2076 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2077 return -EIO;
2078
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002079 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2083 return -EIO;
2084
2085 switch (adapter->fc_topology) {
2086 case FSF_TOPO_P2P:
6f71d9b2005-04-10 23:04:28 -05002087 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2088 "configuration detected at adapter %s\n"
2089 "Peer WWNN 0x%016llx, "
2090 "peer WWPN 0x%016llx, "
2091 "peer d_id 0x%06x\n",
2092 zfcp_get_busid_by_adapter(adapter),
2093 adapter->peer_wwnn,
2094 adapter->peer_wwpn,
2095 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2097 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002098 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 case FSF_TOPO_AL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2101 "topology detected at adapter %s "
2102 "unsupported, shutting down adapter\n",
2103 zfcp_get_busid_by_adapter(adapter));
2104 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2105 "top-al");
2106 zfcp_erp_adapter_shutdown(adapter, 0);
2107 return -EIO;
2108 case FSF_TOPO_FABRIC:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002109 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 "network detected at adapter %s.\n",
2111 zfcp_get_busid_by_adapter(adapter));
2112 break;
2113 default:
2114 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2115 "reported by the exchange "
2116 "configuration command for "
2117 "the adapter %s is not "
2118 "of a type known to the zfcp "
2119 "driver, shutting down adapter\n",
2120 zfcp_get_busid_by_adapter(adapter));
6f71d9b2005-04-10 23:04:28 -05002121 adapter->fc_topology = FSF_TOPO_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2123 "unknown-topo");
2124 zfcp_erp_adapter_shutdown(adapter, 0);
2125 return -EIO;
2126 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002127 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2129 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2130 "allowed by the adapter %s "
2131 "is lower than the minimum "
2132 "required by the driver (%ld bytes).\n",
2133 bottom->max_qtcb_size,
2134 zfcp_get_busid_by_adapter(adapter),
2135 sizeof(struct fsf_qtcb));
2136 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2137 "qtcb-size");
2138 debug_event(fsf_req->adapter->erp_dbf, 0,
2139 &bottom->max_qtcb_size, sizeof (u32));
2140 zfcp_erp_adapter_shutdown(adapter, 0);
2141 return -EIO;
2142 }
2143 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2144 &adapter->status);
2145 break;
2146 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2147 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2148
2149 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2150 return -EIO;
2151
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002152 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2153
2154 zfcp_fsf_link_down_info_eval(adapter,
2155 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 break;
2157 default:
2158 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2159 debug_event(fsf_req->adapter->erp_dbf, 0,
2160 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2161 zfcp_erp_adapter_shutdown(adapter, 0);
2162 return -EIO;
2163 }
2164 return 0;
2165}
2166
2167/**
2168 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002169 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 * @adapter: for which port data is requested
2171 * @data: response to exchange port data request
2172 */
2173int
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002174zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2175 struct zfcp_adapter *adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct fsf_qtcb_bottom_port *data)
2177{
2178 volatile struct qdio_buffer_element *sbale;
2179 int retval = 0;
2180 unsigned long lock_flags;
2181 struct zfcp_fsf_req *fsf_req;
2182 struct timer_list *timer;
2183
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002184 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 ZFCP_LOG_INFO("error: exchange port data "
2186 "command not supported by adapter %s\n",
2187 zfcp_get_busid_by_adapter(adapter));
2188 return -EOPNOTSUPP;
2189 }
2190
2191 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2192 if (!timer)
2193 return -ENOMEM;
2194
2195 /* setup new FSF request */
2196 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2197 0, 0, &lock_flags, &fsf_req);
2198 if (retval < 0) {
2199 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2200 "exchange port data request for"
2201 "the adapter %s.\n",
2202 zfcp_get_busid_by_adapter(adapter));
2203 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2204 lock_flags);
2205 goto out;
2206 }
2207
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002208 if (erp_action) {
2209 erp_action->fsf_req = fsf_req;
2210 fsf_req->erp_action = erp_action;
2211 }
2212
2213 if (data)
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002214 fsf_req->data = (unsigned long) data;
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2217 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2218 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2219
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 init_timer(timer);
2221 timer->function = zfcp_fsf_request_timeout_handler;
2222 timer->data = (unsigned long) adapter;
2223 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2224
2225 retval = zfcp_fsf_req_send(fsf_req, timer);
2226 if (retval) {
2227 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2228 "command on the adapter %s\n",
2229 zfcp_get_busid_by_adapter(adapter));
2230 zfcp_fsf_req_free(fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002231 if (erp_action)
2232 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2234 lock_flags);
2235 goto out;
2236 }
2237
2238 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2239 zfcp_get_busid_by_adapter(adapter));
2240
2241 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2242 lock_flags);
2243
2244 wait_event(fsf_req->completion_wq,
2245 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2246 del_timer_sync(timer);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02002247 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 out:
2249 kfree(timer);
2250 return retval;
2251}
2252
2253
2254/**
2255 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2256 * @fsf_req: pointer to struct zfcp_fsf_req
2257 */
2258static void
2259zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2260{
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002261 struct zfcp_adapter *adapter = fsf_req->adapter;
2262 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2263 struct fsf_qtcb_bottom_port *bottom, *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
2265 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2266 return;
2267
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002268 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 case FSF_GOOD:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002270 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2271
2272 bottom = &qtcb->bottom.port;
2273 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2274 if (data)
2275 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2276 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
2277 adapter->physical_wwpn = bottom->wwpn;
2278 adapter->physical_s_id = bottom->fc_port_id;
2279 } else {
2280 adapter->physical_wwpn = adapter->wwpn;
2281 adapter->physical_s_id = adapter->s_id;
2282 }
2283 break;
2284
2285 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2286 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2287
2288 zfcp_fsf_link_down_info_eval(adapter,
2289 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 break;
2291
2292 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002293 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2294 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2296 }
2297}
2298
2299
2300/*
2301 * function: zfcp_fsf_open_port
2302 *
2303 * purpose:
2304 *
2305 * returns: address of initiated FSF request
2306 * NULL - request could not be initiated
2307 */
2308int
2309zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2310{
2311 volatile struct qdio_buffer_element *sbale;
2312 unsigned long lock_flags;
2313 int retval = 0;
2314
2315 /* setup new FSF request */
2316 retval = zfcp_fsf_req_create(erp_action->adapter,
2317 FSF_QTCB_OPEN_PORT_WITH_DID,
2318 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2319 erp_action->adapter->pool.fsf_req_erp,
2320 &lock_flags, &(erp_action->fsf_req));
2321 if (retval < 0) {
2322 ZFCP_LOG_INFO("error: Could not create open port request "
2323 "for port 0x%016Lx on adapter %s.\n",
2324 erp_action->port->wwpn,
2325 zfcp_get_busid_by_adapter(erp_action->adapter));
2326 goto out;
2327 }
2328
2329 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2330 erp_action->fsf_req->sbal_curr, 0);
2331 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2332 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2333
2334 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2335 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002336 erp_action->fsf_req->data = (unsigned long) erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 erp_action->fsf_req->erp_action = erp_action;
2338
2339 /* start QDIO request for this FSF request */
2340 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2341 if (retval) {
2342 ZFCP_LOG_INFO("error: Could not send open port request for "
2343 "port 0x%016Lx on adapter %s.\n",
2344 erp_action->port->wwpn,
2345 zfcp_get_busid_by_adapter(erp_action->adapter));
2346 zfcp_fsf_req_free(erp_action->fsf_req);
2347 erp_action->fsf_req = NULL;
2348 goto out;
2349 }
2350
2351 ZFCP_LOG_DEBUG("open port request initiated "
2352 "(adapter %s, port 0x%016Lx)\n",
2353 zfcp_get_busid_by_adapter(erp_action->adapter),
2354 erp_action->port->wwpn);
2355 out:
2356 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2357 lock_flags);
2358 return retval;
2359}
2360
2361/*
2362 * function: zfcp_fsf_open_port_handler
2363 *
2364 * purpose: is called for finished Open Port command
2365 *
2366 * returns:
2367 */
2368static int
2369zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2370{
2371 int retval = -EINVAL;
2372 struct zfcp_port *port;
2373 struct fsf_plogi *plogi;
2374 struct fsf_qtcb_header *header;
2375 u16 subtable, rule, counter;
2376
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002377 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 header = &fsf_req->qtcb->header;
2379
2380 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2381 /* don't change port status in our bookkeeping */
2382 goto skip_fsfstatus;
2383 }
2384
2385 /* evaluate FSF status in QTCB */
2386 switch (header->fsf_status) {
2387
2388 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2390 "is already open.\n",
2391 port->wwpn, zfcp_get_busid_by_port(port));
2392 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2393 "fsf_s_popen");
2394 /*
2395 * This is a bug, however operation should continue normally
2396 * if it is simply ignored
2397 */
2398 break;
2399
2400 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2402 "on adapter %s\n",
2403 port->wwpn, zfcp_get_busid_by_port(port));
2404 for (counter = 0; counter < 2; counter++) {
2405 subtable = header->fsf_status_qual.halfword[counter * 2];
2406 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2407 switch (subtable) {
2408 case FSF_SQ_CFDC_SUBTABLE_OS:
2409 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2410 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2411 case FSF_SQ_CFDC_SUBTABLE_LUN:
2412 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2413 zfcp_act_subtable_type[subtable], rule);
2414 break;
2415 }
2416 }
2417 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2418 zfcp_erp_port_access_denied(port);
2419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2420 break;
2421
2422 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2424 "The remote port 0x%016Lx on adapter %s "
2425 "could not be opened. Disabling it.\n",
2426 port->wwpn, zfcp_get_busid_by_port(port));
2427 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2428 "fsf_s_max_ports");
2429 zfcp_erp_port_failed(port);
2430 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2431 break;
2432
2433 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 switch (header->fsf_status_qual.word[0]) {
2435 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2437 "fsf_sq_ltest");
2438 /* ERP strategy will escalate */
2439 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2440 break;
2441 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2442 /* ERP strategy will escalate */
2443 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2444 "fsf_sq_ulp");
2445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2446 break;
2447 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2449 "adapter %s could not be opened. "
2450 "Disabling it.\n",
2451 port->wwpn,
2452 zfcp_get_busid_by_port(port));
2453 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2454 "fsf_sq_no_retry");
2455 zfcp_erp_port_failed(port);
2456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2457 break;
2458 default:
2459 ZFCP_LOG_NORMAL
2460 ("bug: Wrong status qualifier 0x%x arrived.\n",
2461 header->fsf_status_qual.word[0]);
2462 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2463 "fsf_sq_inval:");
2464 debug_exception(
2465 fsf_req->adapter->erp_dbf, 0,
2466 &header->fsf_status_qual.word[0],
2467 sizeof (u32));
2468 break;
2469 }
2470 break;
2471
2472 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 /* save port handle assigned by FSF */
2474 port->handle = header->port_handle;
2475 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2476 "was opened, it's port handle is 0x%x\n",
2477 port->wwpn, zfcp_get_busid_by_port(port),
2478 port->handle);
2479 /* mark port as open */
2480 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2481 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002482 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2483 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2484 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 retval = 0;
2486 /* check whether D_ID has changed during open */
2487 /*
2488 * FIXME: This check is not airtight, as the FCP channel does
2489 * not monitor closures of target port connections caused on
2490 * the remote side. Thus, they might miss out on invalidating
2491 * locally cached WWPNs (and other N_Port parameters) of gone
2492 * target ports. So, our heroic attempt to make things safe
2493 * could be undermined by 'open port' response data tagged with
2494 * obsolete WWPNs. Another reason to monitor potential
2495 * connection closures ourself at least (by interpreting
2496 * incoming ELS' and unsolicited status). It just crosses my
2497 * mind that one should be able to cross-check by means of
2498 * another GID_PN straight after a port has been opened.
2499 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2500 */
2501 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2502 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2503 {
2504 if (fsf_req->qtcb->bottom.support.els1_length <
2505 ((((unsigned long) &plogi->serv_param.wwpn) -
2506 ((unsigned long) plogi)) + sizeof (u64))) {
2507 ZFCP_LOG_INFO(
2508 "warning: insufficient length of "
2509 "PLOGI payload (%i)\n",
2510 fsf_req->qtcb->bottom.support.els1_length);
2511 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2512 "fsf_s_short_plogi:");
2513 /* skip sanity check and assume wwpn is ok */
2514 } else {
2515 if (plogi->serv_param.wwpn != port->wwpn) {
2516 ZFCP_LOG_INFO("warning: d_id of port "
2517 "0x%016Lx changed during "
2518 "open\n", port->wwpn);
2519 debug_text_event(
2520 fsf_req->adapter->erp_dbf, 0,
2521 "fsf_s_did_change:");
2522 atomic_clear_mask(
2523 ZFCP_STATUS_PORT_DID_DID,
2524 &port->status);
2525 } else
2526 port->wwnn = plogi->serv_param.wwnn;
2527 }
2528 }
2529 break;
2530
2531 case FSF_UNKNOWN_OP_SUBTYPE:
2532 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2534 "op_subtype=0x%x)\n",
2535 zfcp_get_busid_by_port(port),
2536 fsf_req->qtcb->bottom.support.operation_subtype);
2537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2538 break;
2539
2540 default:
2541 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2542 "(debug info 0x%x)\n",
2543 header->fsf_status);
2544 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2545 debug_exception(fsf_req->adapter->erp_dbf, 0,
2546 &header->fsf_status, sizeof (u32));
2547 break;
2548 }
2549
2550 skip_fsfstatus:
2551 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2552 return retval;
2553}
2554
2555/*
2556 * function: zfcp_fsf_close_port
2557 *
2558 * purpose: submit FSF command "close port"
2559 *
2560 * returns: address of initiated FSF request
2561 * NULL - request could not be initiated
2562 */
2563int
2564zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2565{
2566 volatile struct qdio_buffer_element *sbale;
2567 unsigned long lock_flags;
2568 int retval = 0;
2569
2570 /* setup new FSF request */
2571 retval = zfcp_fsf_req_create(erp_action->adapter,
2572 FSF_QTCB_CLOSE_PORT,
2573 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2574 erp_action->adapter->pool.fsf_req_erp,
2575 &lock_flags, &(erp_action->fsf_req));
2576 if (retval < 0) {
2577 ZFCP_LOG_INFO("error: Could not create a close port request "
2578 "for port 0x%016Lx on adapter %s.\n",
2579 erp_action->port->wwpn,
2580 zfcp_get_busid_by_adapter(erp_action->adapter));
2581 goto out;
2582 }
2583
2584 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2585 erp_action->fsf_req->sbal_curr, 0);
2586 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2587 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2588
2589 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002590 erp_action->fsf_req->data = (unsigned long) erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 erp_action->fsf_req->erp_action = erp_action;
2592 erp_action->fsf_req->qtcb->header.port_handle =
2593 erp_action->port->handle;
2594
2595 /* start QDIO request for this FSF request */
2596 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2597 if (retval) {
2598 ZFCP_LOG_INFO("error: Could not send a close port request for "
2599 "port 0x%016Lx on adapter %s.\n",
2600 erp_action->port->wwpn,
2601 zfcp_get_busid_by_adapter(erp_action->adapter));
2602 zfcp_fsf_req_free(erp_action->fsf_req);
2603 erp_action->fsf_req = NULL;
2604 goto out;
2605 }
2606
2607 ZFCP_LOG_TRACE("close port request initiated "
2608 "(adapter %s, port 0x%016Lx)\n",
2609 zfcp_get_busid_by_adapter(erp_action->adapter),
2610 erp_action->port->wwpn);
2611 out:
2612 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2613 lock_flags);
2614 return retval;
2615}
2616
2617/*
2618 * function: zfcp_fsf_close_port_handler
2619 *
2620 * purpose: is called for finished Close Port FSF command
2621 *
2622 * returns:
2623 */
2624static int
2625zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2626{
2627 int retval = -EINVAL;
2628 struct zfcp_port *port;
2629
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002630 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
2632 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2633 /* don't change port status in our bookkeeping */
2634 goto skip_fsfstatus;
2635 }
2636
2637 /* evaluate FSF status in QTCB */
2638 switch (fsf_req->qtcb->header.fsf_status) {
2639
2640 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2642 "0x%016Lx on adapter %s invalid. This may happen "
2643 "occasionally.\n", port->handle,
2644 port->wwpn, zfcp_get_busid_by_port(port));
2645 ZFCP_LOG_DEBUG("status qualifier:\n");
2646 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2647 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2648 sizeof (union fsf_status_qual));
2649 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2650 "fsf_s_phand_nv");
2651 zfcp_erp_adapter_reopen(port->adapter, 0);
2652 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2653 break;
2654
2655 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 /* Note: FSF has actually closed the port in this case.
2657 * The status code is just daft. Fingers crossed for a change
2658 */
2659 retval = 0;
2660 break;
2661
2662 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2664 "port handle 0x%x\n", port->wwpn,
2665 zfcp_get_busid_by_port(port), port->handle);
2666 zfcp_erp_modify_port_status(port,
2667 ZFCP_STATUS_COMMON_OPEN,
2668 ZFCP_CLEAR);
2669 retval = 0;
2670 break;
2671
2672 default:
2673 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2674 "(debug info 0x%x)\n",
2675 fsf_req->qtcb->header.fsf_status);
2676 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2677 debug_exception(fsf_req->adapter->erp_dbf, 0,
2678 &fsf_req->qtcb->header.fsf_status,
2679 sizeof (u32));
2680 break;
2681 }
2682
2683 skip_fsfstatus:
2684 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2685 return retval;
2686}
2687
2688/*
2689 * function: zfcp_fsf_close_physical_port
2690 *
2691 * purpose: submit FSF command "close physical port"
2692 *
2693 * returns: address of initiated FSF request
2694 * NULL - request could not be initiated
2695 */
2696int
2697zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2698{
2699 int retval = 0;
2700 unsigned long lock_flags;
2701 volatile struct qdio_buffer_element *sbale;
2702
2703 /* setup new FSF request */
2704 retval = zfcp_fsf_req_create(erp_action->adapter,
2705 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2706 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2707 erp_action->adapter->pool.fsf_req_erp,
2708 &lock_flags, &erp_action->fsf_req);
2709 if (retval < 0) {
2710 ZFCP_LOG_INFO("error: Could not create close physical port "
2711 "request (adapter %s, port 0x%016Lx)\n",
2712 zfcp_get_busid_by_adapter(erp_action->adapter),
2713 erp_action->port->wwpn);
2714
2715 goto out;
2716 }
2717
2718 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2719 erp_action->fsf_req->sbal_curr, 0);
2720 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2721 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2722
2723 /* mark port as being closed */
2724 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2725 &erp_action->port->status);
2726 /* save a pointer to this port */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002727 erp_action->fsf_req->data = (unsigned long) erp_action->port;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002728 /* port to be closed */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 erp_action->fsf_req->qtcb->header.port_handle =
2730 erp_action->port->handle;
2731 erp_action->fsf_req->erp_action = erp_action;
2732
2733 /* start QDIO request for this FSF request */
2734 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2735 if (retval) {
2736 ZFCP_LOG_INFO("error: Could not send close physical port "
2737 "request (adapter %s, port 0x%016Lx)\n",
2738 zfcp_get_busid_by_adapter(erp_action->adapter),
2739 erp_action->port->wwpn);
2740 zfcp_fsf_req_free(erp_action->fsf_req);
2741 erp_action->fsf_req = NULL;
2742 goto out;
2743 }
2744
2745 ZFCP_LOG_TRACE("close physical port request initiated "
2746 "(adapter %s, port 0x%016Lx)\n",
2747 zfcp_get_busid_by_adapter(erp_action->adapter),
2748 erp_action->port->wwpn);
2749 out:
2750 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2751 lock_flags);
2752 return retval;
2753}
2754
2755/*
2756 * function: zfcp_fsf_close_physical_port_handler
2757 *
2758 * purpose: is called for finished Close Physical Port FSF command
2759 *
2760 * returns:
2761 */
2762static int
2763zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2764{
2765 int retval = -EINVAL;
2766 struct zfcp_port *port;
2767 struct zfcp_unit *unit;
2768 struct fsf_qtcb_header *header;
2769 u16 subtable, rule, counter;
2770
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002771 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 header = &fsf_req->qtcb->header;
2773
2774 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2775 /* don't change port status in our bookkeeping */
2776 goto skip_fsfstatus;
2777 }
2778
2779 /* evaluate FSF status in QTCB */
2780 switch (header->fsf_status) {
2781
2782 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2784 "(adapter %s, port 0x%016Lx). "
2785 "This may happen occasionally.\n",
2786 port->handle,
2787 zfcp_get_busid_by_port(port),
2788 port->wwpn);
2789 ZFCP_LOG_DEBUG("status qualifier:\n");
2790 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2791 (char *) &header->fsf_status_qual,
2792 sizeof (union fsf_status_qual));
2793 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2794 "fsf_s_phand_nv");
2795 zfcp_erp_adapter_reopen(port->adapter, 0);
2796 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2797 break;
2798
2799 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 ZFCP_LOG_NORMAL("Access denied, cannot close "
2801 "physical port 0x%016Lx on adapter %s\n",
2802 port->wwpn, zfcp_get_busid_by_port(port));
2803 for (counter = 0; counter < 2; counter++) {
2804 subtable = header->fsf_status_qual.halfword[counter * 2];
2805 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2806 switch (subtable) {
2807 case FSF_SQ_CFDC_SUBTABLE_OS:
2808 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2809 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2810 case FSF_SQ_CFDC_SUBTABLE_LUN:
2811 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2812 zfcp_act_subtable_type[subtable], rule);
2813 break;
2814 }
2815 }
2816 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2817 zfcp_erp_port_access_denied(port);
2818 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2819 break;
2820
2821 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2823 "%s needs to be reopened but it was attempted "
2824 "to close it physically.\n",
2825 port->wwpn,
2826 zfcp_get_busid_by_port(port));
2827 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002828 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2830 ZFCP_STATUS_FSFREQ_RETRY;
2831 break;
2832
2833 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 switch (header->fsf_status_qual.word[0]) {
2835 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2837 "fsf_sq_ltest");
2838 /* This will now be escalated by ERP */
2839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2840 break;
2841 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 /* ERP strategy will escalate */
2843 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2844 "fsf_sq_ulp");
2845 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2846 break;
2847 default:
2848 ZFCP_LOG_NORMAL
2849 ("bug: Wrong status qualifier 0x%x arrived.\n",
2850 header->fsf_status_qual.word[0]);
2851 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2852 "fsf_sq_inval:");
2853 debug_exception(
2854 fsf_req->adapter->erp_dbf, 0,
2855 &header->fsf_status_qual.word[0], sizeof (u32));
2856 break;
2857 }
2858 break;
2859
2860 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2862 "physically closed, port handle 0x%x\n",
2863 port->wwpn,
2864 zfcp_get_busid_by_port(port), port->handle);
2865 /* can't use generic zfcp_erp_modify_port_status because
2866 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2867 */
2868 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2869 list_for_each_entry(unit, &port->unit_list_head, list)
2870 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2871 retval = 0;
2872 break;
2873
2874 default:
2875 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2876 "(debug info 0x%x)\n",
2877 header->fsf_status);
2878 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2879 debug_exception(fsf_req->adapter->erp_dbf, 0,
2880 &header->fsf_status, sizeof (u32));
2881 break;
2882 }
2883
2884 skip_fsfstatus:
2885 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2886 return retval;
2887}
2888
2889/*
2890 * function: zfcp_fsf_open_unit
2891 *
2892 * purpose:
2893 *
2894 * returns:
2895 *
2896 * assumptions: This routine does not check whether the associated
2897 * remote port has already been opened. This should be
2898 * done by calling routines. Otherwise some status
2899 * may be presented by FSF
2900 */
2901int
2902zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2903{
2904 volatile struct qdio_buffer_element *sbale;
2905 unsigned long lock_flags;
2906 int retval = 0;
2907
2908 /* setup new FSF request */
2909 retval = zfcp_fsf_req_create(erp_action->adapter,
2910 FSF_QTCB_OPEN_LUN,
2911 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2912 erp_action->adapter->pool.fsf_req_erp,
2913 &lock_flags, &(erp_action->fsf_req));
2914 if (retval < 0) {
2915 ZFCP_LOG_INFO("error: Could not create open unit request for "
2916 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2917 erp_action->unit->fcp_lun,
2918 erp_action->unit->port->wwpn,
2919 zfcp_get_busid_by_adapter(erp_action->adapter));
2920 goto out;
2921 }
2922
2923 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2924 erp_action->fsf_req->sbal_curr, 0);
2925 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2926 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2927
2928 erp_action->fsf_req->qtcb->header.port_handle =
2929 erp_action->port->handle;
2930 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2931 erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002932 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 erp_action->fsf_req->qtcb->bottom.support.option =
2934 FSF_OPEN_LUN_SUPPRESS_BOXING;
2935 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002936 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 erp_action->fsf_req->erp_action = erp_action;
2938
2939 /* start QDIO request for this FSF request */
2940 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2941 if (retval) {
2942 ZFCP_LOG_INFO("error: Could not send an open unit request "
2943 "on the adapter %s, port 0x%016Lx for "
2944 "unit 0x%016Lx\n",
2945 zfcp_get_busid_by_adapter(erp_action->adapter),
2946 erp_action->port->wwpn,
2947 erp_action->unit->fcp_lun);
2948 zfcp_fsf_req_free(erp_action->fsf_req);
2949 erp_action->fsf_req = NULL;
2950 goto out;
2951 }
2952
2953 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2954 "port 0x%016Lx, unit 0x%016Lx)\n",
2955 zfcp_get_busid_by_adapter(erp_action->adapter),
2956 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2957 out:
2958 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2959 lock_flags);
2960 return retval;
2961}
2962
2963/*
2964 * function: zfcp_fsf_open_unit_handler
2965 *
2966 * purpose: is called for finished Open LUN command
2967 *
2968 * returns:
2969 */
2970static int
2971zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2972{
2973 int retval = -EINVAL;
2974 struct zfcp_adapter *adapter;
2975 struct zfcp_unit *unit;
2976 struct fsf_qtcb_header *header;
2977 struct fsf_qtcb_bottom_support *bottom;
2978 struct fsf_queue_designator *queue_designator;
2979 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002980 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002982 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
2984 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2985 /* don't change unit status in our bookkeeping */
2986 goto skip_fsfstatus;
2987 }
2988
2989 adapter = fsf_req->adapter;
2990 header = &fsf_req->qtcb->header;
2991 bottom = &fsf_req->qtcb->bottom.support;
2992 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2993
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2995 ZFCP_STATUS_UNIT_SHARED |
2996 ZFCP_STATUS_UNIT_READONLY,
2997 &unit->status);
2998
2999 /* evaluate FSF status in QTCB */
3000 switch (header->fsf_status) {
3001
3002 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3004 "for port 0x%016Lx on adapter %s invalid "
3005 "This may happen occasionally\n",
3006 unit->port->handle,
3007 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3008 ZFCP_LOG_DEBUG("status qualifier:\n");
3009 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3010 (char *) &header->fsf_status_qual,
3011 sizeof (union fsf_status_qual));
3012 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3013 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3014 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3015 break;
3016
3017 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3019 "remote port 0x%016Lx on adapter %s twice.\n",
3020 unit->fcp_lun,
3021 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3022 debug_text_exception(adapter->erp_dbf, 0,
3023 "fsf_s_uopen");
3024 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3025 break;
3026
3027 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3029 "remote port 0x%016Lx on adapter %s\n",
3030 unit->fcp_lun, unit->port->wwpn,
3031 zfcp_get_busid_by_unit(unit));
3032 for (counter = 0; counter < 2; counter++) {
3033 subtable = header->fsf_status_qual.halfword[counter * 2];
3034 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3035 switch (subtable) {
3036 case FSF_SQ_CFDC_SUBTABLE_OS:
3037 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3038 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3039 case FSF_SQ_CFDC_SUBTABLE_LUN:
3040 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3041 zfcp_act_subtable_type[subtable], rule);
3042 break;
3043 }
3044 }
3045 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3046 zfcp_erp_unit_access_denied(unit);
3047 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3048 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3049 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3050 break;
3051
3052 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3054 "needs to be reopened\n",
3055 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3056 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003057 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3059 ZFCP_STATUS_FSFREQ_RETRY;
3060 break;
3061
3062 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 if (header->fsf_status_qual.word[0] != 0) {
3064 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3065 "with WWPN 0x%Lx "
3066 "connected to the adapter %s "
3067 "is already in use in LPAR%d, CSS%d\n",
3068 unit->fcp_lun,
3069 unit->port->wwpn,
3070 zfcp_get_busid_by_unit(unit),
3071 queue_designator->hla,
3072 queue_designator->cssid);
3073 } else {
3074 subtable = header->fsf_status_qual.halfword[4];
3075 rule = header->fsf_status_qual.halfword[5];
3076 switch (subtable) {
3077 case FSF_SQ_CFDC_SUBTABLE_OS:
3078 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3079 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3080 case FSF_SQ_CFDC_SUBTABLE_LUN:
3081 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3082 "remote port with WWPN 0x%Lx "
3083 "connected to the adapter %s "
3084 "is denied (%s rule %d)\n",
3085 unit->fcp_lun,
3086 unit->port->wwpn,
3087 zfcp_get_busid_by_unit(unit),
3088 zfcp_act_subtable_type[subtable],
3089 rule);
3090 break;
3091 }
3092 }
3093 ZFCP_LOG_DEBUG("status qualifier:\n");
3094 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3095 (char *) &header->fsf_status_qual,
3096 sizeof (union fsf_status_qual));
3097 debug_text_event(adapter->erp_dbf, 2,
3098 "fsf_s_l_sh_vio");
3099 zfcp_erp_unit_access_denied(unit);
3100 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3101 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3102 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3103 break;
3104
3105 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3107 "There is no handle (temporary port identifier) "
3108 "available for unit 0x%016Lx on port 0x%016Lx "
3109 "on adapter %s\n",
3110 unit->fcp_lun,
3111 unit->port->wwpn,
3112 zfcp_get_busid_by_unit(unit));
3113 debug_text_event(adapter->erp_dbf, 1,
3114 "fsf_s_max_units");
3115 zfcp_erp_unit_failed(unit);
3116 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3117 break;
3118
3119 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 switch (header->fsf_status_qual.word[0]) {
3121 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 /* Re-establish link to port */
3123 debug_text_event(adapter->erp_dbf, 1,
3124 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003125 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3127 break;
3128 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 /* ERP strategy will escalate */
3130 debug_text_event(adapter->erp_dbf, 1,
3131 "fsf_sq_ulp");
3132 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3133 break;
3134 default:
3135 ZFCP_LOG_NORMAL
3136 ("bug: Wrong status qualifier 0x%x arrived.\n",
3137 header->fsf_status_qual.word[0]);
3138 debug_text_event(adapter->erp_dbf, 0,
3139 "fsf_sq_inval:");
3140 debug_exception(adapter->erp_dbf, 0,
3141 &header->fsf_status_qual.word[0],
3142 sizeof (u32));
3143 }
3144 break;
3145
3146 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 ZFCP_LOG_NORMAL(
3148 "Invalid option 0x%x has been specified "
3149 "in QTCB bottom sent to the adapter %s\n",
3150 bottom->option,
3151 zfcp_get_busid_by_adapter(adapter));
3152 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3153 retval = -EINVAL;
3154 break;
3155
3156 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 /* save LUN handle assigned by FSF */
3158 unit->handle = header->lun_handle;
3159 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3160 "adapter %s opened, port handle 0x%x\n",
3161 unit->fcp_lun,
3162 unit->port->wwpn,
3163 zfcp_get_busid_by_unit(unit),
3164 unit->handle);
3165 /* mark unit as open */
3166 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003167
3168 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3169 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3170 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3171 exclusive = (bottom->lun_access_info &
3172 FSF_UNIT_ACCESS_EXCLUSIVE);
3173 readwrite = (bottom->lun_access_info &
3174 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3175
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 if (!exclusive)
3177 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3178 &unit->status);
3179
3180 if (!readwrite) {
3181 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3182 &unit->status);
3183 ZFCP_LOG_NORMAL("read-only access for unit "
3184 "(adapter %s, wwpn=0x%016Lx, "
3185 "fcp_lun=0x%016Lx)\n",
3186 zfcp_get_busid_by_unit(unit),
3187 unit->port->wwpn,
3188 unit->fcp_lun);
3189 }
3190
3191 if (exclusive && !readwrite) {
3192 ZFCP_LOG_NORMAL("exclusive access of read-only "
3193 "unit not supported\n");
3194 zfcp_erp_unit_failed(unit);
3195 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3196 zfcp_erp_unit_shutdown(unit, 0);
3197 } else if (!exclusive && readwrite) {
3198 ZFCP_LOG_NORMAL("shared access of read-write "
3199 "unit not supported\n");
3200 zfcp_erp_unit_failed(unit);
3201 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3202 zfcp_erp_unit_shutdown(unit, 0);
3203 }
3204 }
3205
3206 retval = 0;
3207 break;
3208
3209 default:
3210 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3211 "(debug info 0x%x)\n",
3212 header->fsf_status);
3213 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3214 debug_exception(adapter->erp_dbf, 0,
3215 &header->fsf_status, sizeof (u32));
3216 break;
3217 }
3218
3219 skip_fsfstatus:
3220 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3221 return retval;
3222}
3223
3224/*
3225 * function: zfcp_fsf_close_unit
3226 *
3227 * purpose:
3228 *
3229 * returns: address of fsf_req - request successfully initiated
3230 * NULL -
3231 *
3232 * assumptions: This routine does not check whether the associated
3233 * remote port/lun has already been opened. This should be
3234 * done by calling routines. Otherwise some status
3235 * may be presented by FSF
3236 */
3237int
3238zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3239{
3240 volatile struct qdio_buffer_element *sbale;
3241 unsigned long lock_flags;
3242 int retval = 0;
3243
3244 /* setup new FSF request */
3245 retval = zfcp_fsf_req_create(erp_action->adapter,
3246 FSF_QTCB_CLOSE_LUN,
3247 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3248 erp_action->adapter->pool.fsf_req_erp,
3249 &lock_flags, &(erp_action->fsf_req));
3250 if (retval < 0) {
3251 ZFCP_LOG_INFO("error: Could not create close unit request for "
3252 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3253 erp_action->unit->fcp_lun,
3254 erp_action->port->wwpn,
3255 zfcp_get_busid_by_adapter(erp_action->adapter));
3256 goto out;
3257 }
3258
3259 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3260 erp_action->fsf_req->sbal_curr, 0);
3261 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3262 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3263
3264 erp_action->fsf_req->qtcb->header.port_handle =
3265 erp_action->port->handle;
3266 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3267 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003268 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 erp_action->fsf_req->erp_action = erp_action;
3270
3271 /* start QDIO request for this FSF request */
3272 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3273 if (retval) {
3274 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3275 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3276 erp_action->unit->fcp_lun,
3277 erp_action->port->wwpn,
3278 zfcp_get_busid_by_adapter(erp_action->adapter));
3279 zfcp_fsf_req_free(erp_action->fsf_req);
3280 erp_action->fsf_req = NULL;
3281 goto out;
3282 }
3283
3284 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3285 "port 0x%016Lx, unit 0x%016Lx)\n",
3286 zfcp_get_busid_by_adapter(erp_action->adapter),
3287 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3288 out:
3289 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3290 lock_flags);
3291 return retval;
3292}
3293
3294/*
3295 * function: zfcp_fsf_close_unit_handler
3296 *
3297 * purpose: is called for finished Close LUN FSF command
3298 *
3299 * returns:
3300 */
3301static int
3302zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3303{
3304 int retval = -EINVAL;
3305 struct zfcp_unit *unit;
3306
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003307 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
3309 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3310 /* don't change unit status in our bookkeeping */
3311 goto skip_fsfstatus;
3312 }
3313
3314 /* evaluate FSF status in QTCB */
3315 switch (fsf_req->qtcb->header.fsf_status) {
3316
3317 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3319 "0x%016Lx on adapter %s invalid. This may "
3320 "happen in rare circumstances\n",
3321 unit->port->handle,
3322 unit->port->wwpn,
3323 zfcp_get_busid_by_unit(unit));
3324 ZFCP_LOG_DEBUG("status qualifier:\n");
3325 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3326 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3327 sizeof (union fsf_status_qual));
3328 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3329 "fsf_s_phand_nv");
3330 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3332 break;
3333
3334 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3336 "0x%016Lx on port 0x%016Lx on adapter %s is "
3337 "invalid. This may happen occasionally.\n",
3338 unit->handle,
3339 unit->fcp_lun,
3340 unit->port->wwpn,
3341 zfcp_get_busid_by_unit(unit));
3342 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3343 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3344 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3345 sizeof (union fsf_status_qual));
3346 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3347 "fsf_s_lhand_nv");
3348 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3350 break;
3351
3352 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3354 "needs to be reopened\n",
3355 unit->port->wwpn,
3356 zfcp_get_busid_by_unit(unit));
3357 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003358 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3360 ZFCP_STATUS_FSFREQ_RETRY;
3361 break;
3362
3363 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3365 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 /* re-establish link to port */
3367 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3368 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003369 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3371 break;
3372 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 /* ERP strategy will escalate */
3374 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3375 "fsf_sq_ulp");
3376 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3377 break;
3378 default:
3379 ZFCP_LOG_NORMAL
3380 ("bug: Wrong status qualifier 0x%x arrived.\n",
3381 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3382 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3383 "fsf_sq_inval:");
3384 debug_exception(
3385 fsf_req->adapter->erp_dbf, 0,
3386 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3387 sizeof (u32));
3388 break;
3389 }
3390 break;
3391
3392 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3394 "closed, port handle 0x%x\n",
3395 unit->fcp_lun,
3396 unit->port->wwpn,
3397 zfcp_get_busid_by_unit(unit),
3398 unit->handle);
3399 /* mark unit as closed */
3400 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3401 retval = 0;
3402 break;
3403
3404 default:
3405 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3406 "(debug info 0x%x)\n",
3407 fsf_req->qtcb->header.fsf_status);
3408 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3409 debug_exception(fsf_req->adapter->erp_dbf, 0,
3410 &fsf_req->qtcb->header.fsf_status,
3411 sizeof (u32));
3412 break;
3413 }
3414
3415 skip_fsfstatus:
3416 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3417 return retval;
3418}
3419
3420/**
3421 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3422 * @adapter: adapter where scsi command is issued
3423 * @unit: unit where command is sent to
3424 * @scsi_cmnd: scsi command to be sent
3425 * @timer: timer to be started when request is initiated
3426 * @req_flags: flags for fsf_request
3427 */
3428int
3429zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3430 struct zfcp_unit *unit,
3431 struct scsi_cmnd * scsi_cmnd,
3432 struct timer_list *timer, int req_flags)
3433{
3434 struct zfcp_fsf_req *fsf_req = NULL;
3435 struct fcp_cmnd_iu *fcp_cmnd_iu;
3436 unsigned int sbtype;
3437 unsigned long lock_flags;
3438 int real_bytes = 0;
3439 int retval = 0;
3440 int mask;
3441
3442 /* setup new FSF request */
3443 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3444 adapter->pool.fsf_req_scsi,
3445 &lock_flags, &fsf_req);
3446 if (unlikely(retval < 0)) {
3447 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3448 "for unit 0x%016Lx on port 0x%016Lx on "
3449 "adapter %s\n",
3450 unit->fcp_lun,
3451 unit->port->wwpn,
3452 zfcp_get_busid_by_adapter(adapter));
3453 goto failed_req_create;
3454 }
3455
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003456 zfcp_unit_get(unit);
3457 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003459 /* associate FSF request with SCSI request (for look up on abort) */
3460 scsi_cmnd->host_scribble = (char *) fsf_req;
3461
3462 /* associate SCSI command with FSF request */
3463 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
3465 /* set handles of unit and its parent port in QTCB */
3466 fsf_req->qtcb->header.lun_handle = unit->handle;
3467 fsf_req->qtcb->header.port_handle = unit->port->handle;
3468
3469 /* FSF does not define the structure of the FCP_CMND IU */
3470 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3471 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3472
3473 /*
3474 * set depending on data direction:
3475 * data direction bits in SBALE (SB Type)
3476 * data direction bits in QTCB
3477 * data direction bits in FCP_CMND IU
3478 */
3479 switch (scsi_cmnd->sc_data_direction) {
3480 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3482 /*
3483 * FIXME(qdio):
3484 * what is the correct type for commands
3485 * without 'real' data buffers?
3486 */
3487 sbtype = SBAL_FLAGS0_TYPE_READ;
3488 break;
3489 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3491 sbtype = SBAL_FLAGS0_TYPE_READ;
3492 fcp_cmnd_iu->rddata = 1;
3493 break;
3494 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3496 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3497 fcp_cmnd_iu->wddata = 1;
3498 break;
3499 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 default:
3501 /*
3502 * dummy, catch this condition earlier
3503 * in zfcp_scsi_queuecommand
3504 */
3505 goto failed_scsi_cmnd;
3506 }
3507
3508 /* set FC service class in QTCB (3 per default) */
3509 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3510
3511 /* set FCP_LUN in FCP_CMND IU in QTCB */
3512 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3513
3514 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3515
3516 /* set task attributes in FCP_CMND IU in QTCB */
3517 if (likely((scsi_cmnd->device->simple_tags) ||
3518 (atomic_test_mask(mask, &unit->status))))
3519 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3520 else
3521 fcp_cmnd_iu->task_attribute = UNTAGGED;
3522
3523 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3524 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3525 fcp_cmnd_iu->add_fcp_cdb_length
3526 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3527 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3528 "additional FCP_CDB length is 0x%x "
3529 "(shifted right 2 bits)\n",
3530 scsi_cmnd->cmd_len,
3531 fcp_cmnd_iu->add_fcp_cdb_length);
3532 }
3533 /*
3534 * copy SCSI CDB (including additional length, if any) to
3535 * FCP_CDB in FCP_CMND IU in QTCB
3536 */
3537 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3538
3539 /* FCP CMND IU length in QTCB */
3540 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3541 sizeof (struct fcp_cmnd_iu) +
3542 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3543
3544 /* generate SBALEs from data buffer */
3545 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3546 if (unlikely(real_bytes < 0)) {
3547 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3548 ZFCP_LOG_DEBUG(
3549 "Data did not fit into available buffer(s), "
3550 "waiting for more...\n");
3551 retval = -EIO;
3552 } else {
3553 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3554 "required. Shutting down unit "
3555 "(adapter %s, port 0x%016Lx, "
3556 "unit 0x%016Lx)\n",
3557 zfcp_get_busid_by_unit(unit),
3558 unit->port->wwpn,
3559 unit->fcp_lun);
3560 zfcp_erp_unit_shutdown(unit, 0);
3561 retval = -EINVAL;
3562 }
3563 goto no_fit;
3564 }
3565
3566 /* set length of FCP data length in FCP_CMND IU in QTCB */
3567 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3568
3569 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3570 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3571 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3572
3573 /*
3574 * start QDIO request for this FSF request
3575 * covered by an SBALE)
3576 */
3577 retval = zfcp_fsf_req_send(fsf_req, timer);
3578 if (unlikely(retval < 0)) {
3579 ZFCP_LOG_INFO("error: Could not send FCP command request "
3580 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3581 zfcp_get_busid_by_adapter(adapter),
3582 unit->port->wwpn,
3583 unit->fcp_lun);
3584 goto send_failed;
3585 }
3586
3587 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3588 "port 0x%016Lx, unit 0x%016Lx)\n",
3589 zfcp_get_busid_by_adapter(adapter),
3590 unit->port->wwpn,
3591 unit->fcp_lun);
3592 goto success;
3593
3594 send_failed:
3595 no_fit:
3596 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003597 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 zfcp_fsf_req_free(fsf_req);
3599 fsf_req = NULL;
3600 scsi_cmnd->host_scribble = NULL;
3601 success:
3602 failed_req_create:
3603 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3604 return retval;
3605}
3606
3607/*
3608 * function: zfcp_fsf_send_fcp_command_task_management
3609 *
3610 * purpose:
3611 *
3612 * returns:
3613 *
3614 * FIXME(design): should be watched by a timeout!!!
3615 * FIXME(design) shouldn't this be modified to return an int
3616 * also...don't know how though
3617 *
3618 */
3619struct zfcp_fsf_req *
3620zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3621 struct zfcp_unit *unit,
3622 u8 tm_flags, int req_flags)
3623{
3624 struct zfcp_fsf_req *fsf_req = NULL;
3625 int retval = 0;
3626 struct fcp_cmnd_iu *fcp_cmnd_iu;
3627 unsigned long lock_flags;
3628 volatile struct qdio_buffer_element *sbale;
3629
3630 /* setup new FSF request */
3631 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3632 adapter->pool.fsf_req_scsi,
3633 &lock_flags, &fsf_req);
3634 if (retval < 0) {
3635 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3636 "management) request for adapter %s, port "
3637 " 0x%016Lx, unit 0x%016Lx.\n",
3638 zfcp_get_busid_by_adapter(adapter),
3639 unit->port->wwpn, unit->fcp_lun);
3640 goto out;
3641 }
3642
3643 /*
3644 * Used to decide on proper handler in the return path,
3645 * could be either zfcp_fsf_send_fcp_command_task_handler or
3646 * zfcp_fsf_send_fcp_command_task_management_handler */
3647
3648 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3649
3650 /*
3651 * hold a pointer to the unit being target of this
3652 * task management request
3653 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003654 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
3656 /* set FSF related fields in QTCB */
3657 fsf_req->qtcb->header.lun_handle = unit->handle;
3658 fsf_req->qtcb->header.port_handle = unit->port->handle;
3659 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3660 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3661 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3662 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3663
3664 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3665 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3666 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3667
3668 /* set FCP related fields in FCP_CMND IU in QTCB */
3669 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3670 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3671 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3672 fcp_cmnd_iu->task_management_flags = tm_flags;
3673
3674 /* start QDIO request for this FSF request */
3675 zfcp_fsf_start_scsi_er_timer(adapter);
3676 retval = zfcp_fsf_req_send(fsf_req, NULL);
3677 if (retval) {
3678 del_timer(&adapter->scsi_er_timer);
3679 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3680 "management) on adapter %s, port 0x%016Lx for "
3681 "unit LUN 0x%016Lx\n",
3682 zfcp_get_busid_by_adapter(adapter),
3683 unit->port->wwpn,
3684 unit->fcp_lun);
3685 zfcp_fsf_req_free(fsf_req);
3686 fsf_req = NULL;
3687 goto out;
3688 }
3689
3690 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3691 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3692 "tm_flags=0x%x)\n",
3693 zfcp_get_busid_by_adapter(adapter),
3694 unit->port->wwpn,
3695 unit->fcp_lun,
3696 tm_flags);
3697 out:
3698 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3699 return fsf_req;
3700}
3701
3702/*
3703 * function: zfcp_fsf_send_fcp_command_handler
3704 *
3705 * purpose: is called for finished Send FCP Command
3706 *
3707 * returns:
3708 */
3709static int
3710zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3711{
3712 int retval = -EINVAL;
3713 struct zfcp_unit *unit;
3714 struct fsf_qtcb_header *header;
3715 u16 subtable, rule, counter;
3716
3717 header = &fsf_req->qtcb->header;
3718
3719 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003720 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003722 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723
3724 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3725 /* go directly to calls of special handlers */
3726 goto skip_fsfstatus;
3727 }
3728
3729 /* evaluate FSF status in QTCB */
3730 switch (header->fsf_status) {
3731
3732 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3734 "0x%016Lx on adapter %s invalid\n",
3735 unit->port->handle,
3736 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3737 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3738 (char *) &header->fsf_status_qual,
3739 sizeof (union fsf_status_qual));
3740 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3741 "fsf_s_phand_nv");
3742 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3743 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3744 break;
3745
3746 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3748 "0x%016Lx on port 0x%016Lx on adapter %s is "
3749 "invalid. This may happen occasionally.\n",
3750 unit->handle,
3751 unit->fcp_lun,
3752 unit->port->wwpn,
3753 zfcp_get_busid_by_unit(unit));
3754 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3755 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3756 (char *) &header->fsf_status_qual,
3757 sizeof (union fsf_status_qual));
3758 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3759 "fsf_s_uhand_nv");
3760 zfcp_erp_port_reopen(unit->port, 0);
3761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3762 break;
3763
3764 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3766 "unexpectedly. (adapter %s, port 0x%016Lx, "
3767 "unit 0x%016Lx)\n",
3768 unit->port->handle,
3769 zfcp_get_busid_by_unit(unit),
3770 unit->port->wwpn,
3771 unit->fcp_lun);
3772 ZFCP_LOG_NORMAL("status qualifier:\n");
3773 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3774 (char *) &header->fsf_status_qual,
3775 sizeof (union fsf_status_qual));
3776 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3777 "fsf_s_hand_mis");
3778 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3780 break;
3781
3782 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 if (fsf_req->adapter->fc_service_class <= 3) {
3784 ZFCP_LOG_NORMAL("error: The adapter %s does "
3785 "not support fibrechannel class %d.\n",
3786 zfcp_get_busid_by_unit(unit),
3787 fsf_req->adapter->fc_service_class);
3788 } else {
3789 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3790 "adapter %s is invalid. "
3791 "(debug info %d)\n",
3792 zfcp_get_busid_by_unit(unit),
3793 fsf_req->adapter->fc_service_class);
3794 }
3795 /* stop operation for this adapter */
3796 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3797 "fsf_s_class_nsup");
3798 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3800 break;
3801
3802 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3804 "adapter %s does not have correct unit "
3805 "handle 0x%x\n",
3806 unit->fcp_lun,
3807 unit->port->wwpn,
3808 zfcp_get_busid_by_unit(unit),
3809 unit->handle);
3810 ZFCP_LOG_DEBUG("status qualifier:\n");
3811 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3812 (char *) &header->fsf_status_qual,
3813 sizeof (union fsf_status_qual));
3814 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3815 "fsf_s_fcp_lun_nv");
3816 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3818 break;
3819
3820 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3822 "unit 0x%016Lx on port 0x%016Lx on "
3823 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3824 zfcp_get_busid_by_unit(unit));
3825 for (counter = 0; counter < 2; counter++) {
3826 subtable = header->fsf_status_qual.halfword[counter * 2];
3827 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3828 switch (subtable) {
3829 case FSF_SQ_CFDC_SUBTABLE_OS:
3830 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3831 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3832 case FSF_SQ_CFDC_SUBTABLE_LUN:
3833 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3834 zfcp_act_subtable_type[subtable], rule);
3835 break;
3836 }
3837 }
3838 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3839 zfcp_erp_unit_access_denied(unit);
3840 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3841 break;
3842
3843 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3845 "0x%016Lx on port 0x%016Lx on adapter %s "
3846 "(debug info %d)\n",
3847 unit->fcp_lun,
3848 unit->port->wwpn,
3849 zfcp_get_busid_by_unit(unit),
3850 fsf_req->qtcb->bottom.io.data_direction);
3851 /* stop operation for this adapter */
3852 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3853 "fsf_s_dir_ind_nv");
3854 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3856 break;
3857
3858 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 ZFCP_LOG_NORMAL
3860 ("bug: An invalid control-data-block length field "
3861 "was found in a command for unit 0x%016Lx on port "
3862 "0x%016Lx on adapter %s " "(debug info %d)\n",
3863 unit->fcp_lun, unit->port->wwpn,
3864 zfcp_get_busid_by_unit(unit),
3865 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3866 /* stop operation for this adapter */
3867 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3868 "fsf_s_cmd_len_nv");
3869 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3871 break;
3872
3873 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3875 "needs to be reopened\n",
3876 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3877 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003878 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3880 ZFCP_STATUS_FSFREQ_RETRY;
3881 break;
3882
3883 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3885 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3886 zfcp_get_busid_by_unit(unit),
3887 unit->port->wwpn, unit->fcp_lun);
3888 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003889 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3891 | ZFCP_STATUS_FSFREQ_RETRY;
3892 break;
3893
3894 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 switch (header->fsf_status_qual.word[0]) {
3896 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 /* re-establish link to port */
3898 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3899 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003900 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 break;
3902 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 /* FIXME(hw) need proper specs for proper action */
3904 /* let scsi stack deal with retries and escalation */
3905 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3906 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 break;
3908 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003910 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 header->fsf_status_qual.word[0]);
3912 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3913 "fsf_sq_inval:");
3914 debug_exception(fsf_req->adapter->erp_dbf, 0,
3915 &header->fsf_status_qual.word[0],
3916 sizeof(u32));
3917 break;
3918 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003919 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 break;
3921
3922 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 break;
3924
3925 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 break;
3927
3928 default:
3929 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3930 debug_exception(fsf_req->adapter->erp_dbf, 0,
3931 &header->fsf_status, sizeof(u32));
3932 break;
3933 }
3934
3935 skip_fsfstatus:
3936 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3937 retval =
3938 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3939 } else {
3940 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003941 fsf_req->unit = NULL;
3942 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 }
3944 return retval;
3945}
3946
3947/*
3948 * function: zfcp_fsf_send_fcp_command_task_handler
3949 *
3950 * purpose: evaluates FCP_RSP IU
3951 *
3952 * returns:
3953 */
3954static int
3955zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3956{
3957 int retval = 0;
3958 struct scsi_cmnd *scpnt;
3959 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3960 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3961 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3962 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3963 u32 sns_len;
3964 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3965 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003966 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
3968 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003969 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 if (unlikely(!scpnt)) {
3971 ZFCP_LOG_DEBUG
3972 ("Command with fsf_req %p is not associated to "
3973 "a scsi command anymore. Aborted?\n", fsf_req);
3974 goto out;
3975 }
3976 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3977 /* FIXME: (design) mid-layer should handle DID_ABORT like
3978 * DID_SOFT_ERROR by retrying the request for devices
3979 * that allow retries.
3980 */
3981 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3982 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3983 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3984 goto skip_fsfstatus;
3985 }
3986
3987 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3988 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3989 set_host_byte(&scpnt->result, DID_ERROR);
3990 goto skip_fsfstatus;
3991 }
3992
3993 /* set message byte of result in SCSI command */
3994 scpnt->result |= COMMAND_COMPLETE << 8;
3995
3996 /*
3997 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3998 * of result in SCSI command
3999 */
4000 scpnt->result |= fcp_rsp_iu->scsi_status;
4001 if (unlikely(fcp_rsp_iu->scsi_status)) {
4002 /* DEBUG */
4003 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4004 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4005 scpnt->cmnd, scpnt->cmd_len);
4006 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4007 fcp_rsp_iu->scsi_status);
4008 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4009 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4010 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4011 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4012 fcp_rsp_iu->fcp_sns_len);
4013 }
4014
4015 /* check FCP_RSP_INFO */
4016 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4017 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4018 switch (fcp_rsp_info[3]) {
4019 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 /* ok, continue */
4021 ZFCP_LOG_TRACE("no failure or Task Management "
4022 "Function complete\n");
4023 set_host_byte(&scpnt->result, DID_OK);
4024 break;
4025 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 /* hardware bug */
4027 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4028 "that the fibrechannel protocol data "
4029 "length differs from the burst length. "
4030 "The problem occured on unit 0x%016Lx "
4031 "on port 0x%016Lx on adapter %s",
4032 unit->fcp_lun,
4033 unit->port->wwpn,
4034 zfcp_get_busid_by_unit(unit));
4035 /* dump SCSI CDB as prepared by zfcp */
4036 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4037 (char *) &fsf_req->qtcb->
4038 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 set_host_byte(&scpnt->result, DID_ERROR);
4040 goto skip_fsfstatus;
4041 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 /* driver or hardware bug */
4043 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4044 "that the fibrechannel protocol data "
4045 "fields were incorrectly set up. "
4046 "The problem occured on the unit "
4047 "0x%016Lx on port 0x%016Lx on "
4048 "adapter %s",
4049 unit->fcp_lun,
4050 unit->port->wwpn,
4051 zfcp_get_busid_by_unit(unit));
4052 /* dump SCSI CDB as prepared by zfcp */
4053 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4054 (char *) &fsf_req->qtcb->
4055 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4056 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 goto skip_fsfstatus;
4058 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 /* hardware bug */
4060 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4061 "that conflicting values for the "
4062 "fibrechannel payload offset from the "
4063 "header were found. "
4064 "The problem occured on unit 0x%016Lx "
4065 "on port 0x%016Lx on adapter %s.\n",
4066 unit->fcp_lun,
4067 unit->port->wwpn,
4068 zfcp_get_busid_by_unit(unit));
4069 /* dump SCSI CDB as prepared by zfcp */
4070 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4071 (char *) &fsf_req->qtcb->
4072 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 set_host_byte(&scpnt->result, DID_ERROR);
4074 goto skip_fsfstatus;
4075 default:
4076 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4077 "code was detected for a command. "
4078 "The problem occured on the unit "
4079 "0x%016Lx on port 0x%016Lx on "
4080 "adapter %s (debug info 0x%x)\n",
4081 unit->fcp_lun,
4082 unit->port->wwpn,
4083 zfcp_get_busid_by_unit(unit),
4084 fcp_rsp_info[3]);
4085 /* dump SCSI CDB as prepared by zfcp */
4086 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4087 (char *) &fsf_req->qtcb->
4088 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004090 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 }
4092 }
4093
4094 /* check for sense data */
4095 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4096 sns_len = FSF_FCP_RSP_SIZE -
4097 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4098 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4099 sns_len);
4100 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4101 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4102 SCSI_SENSE_BUFFERSIZE);
4103 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4104 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4105 scpnt->result);
4106 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4107 (void *) &scpnt->cmnd, scpnt->cmd_len);
4108
4109 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4110 fcp_rsp_iu->fcp_sns_len);
4111 memcpy(&scpnt->sense_buffer,
4112 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4113 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4114 (void *) &scpnt->sense_buffer, sns_len);
4115 }
4116
4117 /* check for overrun */
4118 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4119 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4120 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4121 "The response data length is "
4122 "%d, the original length was %d.\n",
4123 unit->fcp_lun,
4124 unit->port->wwpn,
4125 zfcp_get_busid_by_unit(unit),
4126 fcp_rsp_iu->fcp_resid,
4127 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4128 }
4129
4130 /* check for underrun */
4131 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4132 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4133 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4134 "The response data length is "
4135 "%d, the original length was %d.\n",
4136 unit->fcp_lun,
4137 unit->port->wwpn,
4138 zfcp_get_busid_by_unit(unit),
4139 fcp_rsp_iu->fcp_resid,
4140 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4141
4142 scpnt->resid = fcp_rsp_iu->fcp_resid;
4143 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004144 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 }
4146
4147 skip_fsfstatus:
4148 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4149
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004150 if (scpnt->result != 0)
4151 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt);
4152 else if (scpnt->retries > 0)
4153 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt);
4154 else
4155 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
4157 /* cleanup pointer (need this especially for abort) */
4158 scpnt->host_scribble = NULL;
4159
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 (scpnt->scsi_done) (scpnt);
4162
4163 /*
4164 * We must hold this lock until scsi_done has been called.
4165 * Otherwise we may call scsi_done after abort regarding this
4166 * command has completed.
4167 * Note: scsi_done must not block!
4168 */
4169 out:
4170 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4171 return retval;
4172}
4173
4174/*
4175 * function: zfcp_fsf_send_fcp_command_task_management_handler
4176 *
4177 * purpose: evaluates FCP_RSP IU
4178 *
4179 * returns:
4180 */
4181static int
4182zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4183{
4184 int retval = 0;
4185 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4186 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4187 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004188 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189
4190 del_timer(&fsf_req->adapter->scsi_er_timer);
4191 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4192 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4193 goto skip_fsfstatus;
4194 }
4195
4196 /* check FCP_RSP_INFO */
4197 switch (fcp_rsp_info[3]) {
4198 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 /* ok, continue */
4200 ZFCP_LOG_DEBUG("no failure or Task Management "
4201 "Function complete\n");
4202 break;
4203 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4205 "is not supported on the target device "
4206 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4207 unit->fcp_lun,
4208 unit->port->wwpn,
4209 zfcp_get_busid_by_unit(unit));
4210 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4211 break;
4212 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4214 "failed to complete successfully. "
4215 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4216 unit->fcp_lun,
4217 unit->port->wwpn,
4218 zfcp_get_busid_by_unit(unit));
4219 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4220 break;
4221 default:
4222 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4223 "code was detected for a command. "
4224 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4225 "(debug info 0x%x)\n",
4226 unit->fcp_lun,
4227 unit->port->wwpn,
4228 zfcp_get_busid_by_unit(unit),
4229 fcp_rsp_info[3]);
4230 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4231 }
4232
4233 skip_fsfstatus:
4234 return retval;
4235}
4236
4237
4238/*
4239 * function: zfcp_fsf_control_file
4240 *
4241 * purpose: Initiator of the control file upload/download FSF requests
4242 *
4243 * returns: 0 - FSF request is successfuly created and queued
4244 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4245 * -EINVAL - Invalid direction specified
4246 * -ENOMEM - Insufficient memory
4247 * -EPERM - Cannot create FSF request or place it in QDIO queue
4248 */
4249int
4250zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4251 struct zfcp_fsf_req **fsf_req_ptr,
4252 u32 fsf_command,
4253 u32 option,
4254 struct zfcp_sg_list *sg_list)
4255{
4256 struct zfcp_fsf_req *fsf_req;
4257 struct fsf_qtcb_bottom_support *bottom;
4258 volatile struct qdio_buffer_element *sbale;
4259 struct timer_list *timer;
4260 unsigned long lock_flags;
4261 int req_flags = 0;
4262 int direction;
4263 int retval = 0;
4264
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004265 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4267 zfcp_get_busid_by_adapter(adapter));
4268 retval = -EOPNOTSUPP;
4269 goto out;
4270 }
4271
4272 switch (fsf_command) {
4273
4274 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4275 direction = SBAL_FLAGS0_TYPE_WRITE;
4276 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4277 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4278 req_flags = ZFCP_WAIT_FOR_SBAL;
4279 break;
4280
4281 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4282 direction = SBAL_FLAGS0_TYPE_READ;
4283 break;
4284
4285 default:
4286 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4287 retval = -EINVAL;
4288 goto out;
4289 }
4290
4291 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4292 if (!timer) {
4293 retval = -ENOMEM;
4294 goto out;
4295 }
4296
4297 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4298 NULL, &lock_flags, &fsf_req);
4299 if (retval < 0) {
4300 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4301 "adapter %s\n",
4302 zfcp_get_busid_by_adapter(adapter));
4303 retval = -EPERM;
4304 goto unlock_queue_lock;
4305 }
4306
4307 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4308 sbale[0].flags |= direction;
4309
4310 bottom = &fsf_req->qtcb->bottom.support;
4311 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4312 bottom->option = option;
4313
4314 if (sg_list->count > 0) {
4315 int bytes;
4316
4317 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4318 sg_list->sg, sg_list->count,
4319 ZFCP_MAX_SBALS_PER_REQ);
4320 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4321 ZFCP_LOG_INFO(
4322 "error: Could not create sufficient number of "
4323 "SBALS for an FSF request to the adapter %s\n",
4324 zfcp_get_busid_by_adapter(adapter));
4325 retval = -ENOMEM;
4326 goto free_fsf_req;
4327 }
4328 } else
4329 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4330
4331 init_timer(timer);
4332 timer->function = zfcp_fsf_request_timeout_handler;
4333 timer->data = (unsigned long) adapter;
4334 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4335
4336 retval = zfcp_fsf_req_send(fsf_req, timer);
4337 if (retval < 0) {
4338 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4339 "(adapter %s)\n",
4340 zfcp_get_busid_by_adapter(adapter));
4341 retval = -EPERM;
4342 goto free_fsf_req;
4343 }
4344 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4345
4346 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4347 "adapter %s\n",
4348 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4349 "download" : "upload",
4350 zfcp_get_busid_by_adapter(adapter));
4351
4352 wait_event(fsf_req->completion_wq,
4353 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4354
4355 *fsf_req_ptr = fsf_req;
4356 del_timer_sync(timer);
4357 goto free_timer;
4358
4359 free_fsf_req:
4360 zfcp_fsf_req_free(fsf_req);
4361 unlock_queue_lock:
4362 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4363 free_timer:
4364 kfree(timer);
4365 out:
4366 return retval;
4367}
4368
4369
4370/*
4371 * function: zfcp_fsf_control_file_handler
4372 *
4373 * purpose: Handler of the control file upload/download FSF requests
4374 *
4375 * returns: 0 - FSF request successfuly processed
4376 * -EAGAIN - Operation has to be repeated because of a temporary problem
4377 * -EACCES - There is no permission to execute an operation
4378 * -EPERM - The control file is not in a right format
4379 * -EIO - There is a problem with the FCP adapter
4380 * -EINVAL - Invalid operation
4381 * -EFAULT - User space memory I/O operation fault
4382 */
4383static int
4384zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4385{
4386 struct zfcp_adapter *adapter = fsf_req->adapter;
4387 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4388 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4389 int retval = 0;
4390
4391 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4392 retval = -EINVAL;
4393 goto skip_fsfstatus;
4394 }
4395
4396 switch (header->fsf_status) {
4397
4398 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 ZFCP_LOG_NORMAL(
4400 "The FSF request has been successfully completed "
4401 "on the adapter %s\n",
4402 zfcp_get_busid_by_adapter(adapter));
4403 break;
4404
4405 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4407 switch (header->fsf_status_qual.word[0]) {
4408
6f71d9b2005-04-10 23:04:28 -05004409 case FSF_SQ_CFDC_HARDENED_ON_SE:
4410 ZFCP_LOG_NORMAL(
4411 "CFDC on the adapter %s has being "
4412 "hardened on primary and secondary SE\n",
4413 zfcp_get_busid_by_adapter(adapter));
4414 break;
4415
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4417 ZFCP_LOG_NORMAL(
4418 "CFDC of the adapter %s could not "
4419 "be saved on the SE\n",
4420 zfcp_get_busid_by_adapter(adapter));
4421 break;
4422
4423 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4424 ZFCP_LOG_NORMAL(
4425 "CFDC of the adapter %s could not "
4426 "be copied to the secondary SE\n",
4427 zfcp_get_busid_by_adapter(adapter));
4428 break;
4429
4430 default:
4431 ZFCP_LOG_NORMAL(
4432 "CFDC could not be hardened "
4433 "on the adapter %s\n",
4434 zfcp_get_busid_by_adapter(adapter));
4435 }
4436 }
4437 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4438 retval = -EAGAIN;
4439 break;
4440
4441 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 ZFCP_LOG_NORMAL(
4443 "Adapter %s does not accept privileged commands\n",
4444 zfcp_get_busid_by_adapter(adapter));
4445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4446 retval = -EACCES;
4447 break;
4448
4449 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 ZFCP_LOG_NORMAL(
4451 "Error at position %d in the CFDC, "
4452 "CFDC is discarded by the adapter %s\n",
4453 header->fsf_status_qual.word[0],
4454 zfcp_get_busid_by_adapter(adapter));
4455 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4456 retval = -EPERM;
4457 break;
4458
4459 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 ZFCP_LOG_NORMAL(
4461 "Adapter %s cannot harden the control file, "
4462 "file is discarded\n",
4463 zfcp_get_busid_by_adapter(adapter));
4464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4465 retval = -EIO;
4466 break;
4467
4468 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 ZFCP_LOG_NORMAL(
4470 "Control file is too large, file is discarded "
4471 "by the adapter %s\n",
4472 zfcp_get_busid_by_adapter(adapter));
4473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4474 retval = -EIO;
4475 break;
4476
4477 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4479 ZFCP_LOG_NORMAL(
4480 "CFDC has been discarded by the adapter %s, "
4481 "because activation would impact "
4482 "%d active connection(s)\n",
4483 zfcp_get_busid_by_adapter(adapter),
4484 header->fsf_status_qual.word[0]);
4485 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4486 retval = -EIO;
4487 break;
4488
4489 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4491 ZFCP_LOG_NORMAL(
4492 "CFDC has been activated on the adapter %s, "
4493 "but activation has impacted "
4494 "%d active connection(s)\n",
4495 zfcp_get_busid_by_adapter(adapter),
4496 header->fsf_status_qual.word[0]);
4497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4498 retval = -EIO;
4499 break;
4500
4501 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4503 "op_subtype=0x%x)\n",
4504 zfcp_get_busid_by_adapter(adapter),
4505 bottom->operation_subtype);
4506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4507 retval = -EINVAL;
4508 break;
4509
4510 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 ZFCP_LOG_NORMAL(
4512 "Invalid option 0x%x has been specified "
4513 "in QTCB bottom sent to the adapter %s\n",
4514 bottom->option,
4515 zfcp_get_busid_by_adapter(adapter));
4516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4517 retval = -EINVAL;
4518 break;
4519
4520 default:
4521 ZFCP_LOG_NORMAL(
4522 "bug: An unknown/unexpected FSF status 0x%08x "
4523 "was presented on the adapter %s\n",
4524 header->fsf_status,
4525 zfcp_get_busid_by_adapter(adapter));
4526 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4527 debug_exception(fsf_req->adapter->erp_dbf, 0,
4528 &header->fsf_status_qual.word[0], sizeof(u32));
4529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4530 retval = -EINVAL;
4531 break;
4532 }
4533
4534skip_fsfstatus:
4535 return retval;
4536}
4537
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538static inline int
4539zfcp_fsf_req_sbal_check(unsigned long *flags,
4540 struct zfcp_qdio_queue *queue, int needed)
4541{
4542 write_lock_irqsave(&queue->queue_lock, *flags);
4543 if (likely(atomic_read(&queue->free_count) >= needed))
4544 return 1;
4545 write_unlock_irqrestore(&queue->queue_lock, *flags);
4546 return 0;
4547}
4548
4549/*
4550 * set qtcb pointer in fsf_req and initialize QTCB
4551 */
4552static inline void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004553zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554{
4555 if (likely(fsf_req->qtcb != NULL)) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004556 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4558 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004559 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4561 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004562 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 }
4564}
4565
4566/**
4567 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4568 * @adapter: adapter for which request queue is examined
4569 * @req_flags: flags indicating whether to wait for needed SBAL or not
4570 * @lock_flags: lock_flags if queue_lock is taken
4571 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4572 * Locks: lock adapter->request_queue->queue_lock on success
4573 */
4574static int
4575zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4576 unsigned long *lock_flags)
4577{
4578 long ret;
4579 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4580
4581 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4582 ret = wait_event_interruptible_timeout(adapter->request_wq,
4583 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4584 ZFCP_SBAL_TIMEOUT);
4585 if (ret < 0)
4586 return ret;
4587 if (!ret)
4588 return -EIO;
4589 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4590 return -EIO;
4591
4592 return 0;
4593}
4594
4595/*
4596 * function: zfcp_fsf_req_create
4597 *
4598 * purpose: create an FSF request at the specified adapter and
4599 * setup common fields
4600 *
4601 * returns: -ENOMEM if there was insufficient memory for a request
4602 * -EIO if no qdio buffers could be allocate to the request
4603 * -EINVAL/-EPERM on bug conditions in req_dequeue
4604 * 0 in success
4605 *
4606 * note: The created request is returned by reference.
4607 *
4608 * locks: lock of concerned request queue must not be held,
4609 * but is held on completion (write, irqsave)
4610 */
4611int
4612zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4613 mempool_t *pool, unsigned long *lock_flags,
4614 struct zfcp_fsf_req **fsf_req_p)
4615{
4616 volatile struct qdio_buffer_element *sbale;
4617 struct zfcp_fsf_req *fsf_req = NULL;
4618 int ret = 0;
4619 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4620
4621 /* allocate new FSF request */
4622 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4623 if (unlikely(NULL == fsf_req)) {
4624 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4625 "the outbound (send) queue.\n");
4626 ret = -ENOMEM;
4627 goto failed_fsf_req;
4628 }
4629
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004630 fsf_req->adapter = adapter;
4631 fsf_req->fsf_command = fsf_cmd;
4632
4633 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634
4635 /* initialize waitqueue which may be used to wait on
4636 this request completion */
4637 init_waitqueue_head(&fsf_req->completion_wq);
4638
4639 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4640 if(ret < 0) {
4641 goto failed_sbals;
4642 }
4643
4644 /*
4645 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4646 * if it is not set (see also *_open_qdio and *_close_qdio).
4647 */
4648
4649 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4650 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4651 ret = -EIO;
4652 goto failed_sbals;
4653 }
4654
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004655 if (fsf_req->qtcb) {
4656 fsf_req->seq_no = adapter->fsf_req_seq_no;
4657 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 fsf_req->sbal_number = 1;
4660 fsf_req->sbal_first = req_queue->free_index;
4661 fsf_req->sbal_curr = req_queue->free_index;
4662 fsf_req->sbale_curr = 1;
4663
4664 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4665 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4666 }
4667
4668 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4669
4670 /* setup common SBALE fields */
4671 sbale[0].addr = fsf_req;
4672 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4673 if (likely(fsf_req->qtcb != NULL)) {
4674 sbale[1].addr = (void *) fsf_req->qtcb;
4675 sbale[1].length = sizeof(struct fsf_qtcb);
4676 }
4677
4678 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4679 fsf_req->sbal_number, fsf_req->sbal_first);
4680
4681 goto success;
4682
4683 failed_sbals:
4684/* dequeue new FSF request previously enqueued */
4685 zfcp_fsf_req_free(fsf_req);
4686 fsf_req = NULL;
4687
4688 failed_fsf_req:
4689 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4690 success:
4691 *fsf_req_p = fsf_req;
4692 return ret;
4693}
4694
4695/*
4696 * function: zfcp_fsf_req_send
4697 *
4698 * purpose: start transfer of FSF request via QDIO
4699 *
4700 * returns: 0 - request transfer succesfully started
4701 * !0 - start of request transfer failed
4702 */
4703static int
4704zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4705{
4706 struct zfcp_adapter *adapter;
4707 struct zfcp_qdio_queue *req_queue;
4708 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004709 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710 int new_distance_from_int;
4711 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 int retval = 0;
4713
4714 adapter = fsf_req->adapter;
4715 req_queue = &adapter->request_queue,
4716
4717
4718 /* FIXME(debug): remove it later */
4719 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4720 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4721 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4722 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4723 sbale[1].length);
4724
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 /* put allocated FSF request at list tail */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004726 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004728 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004730 inc_seq_no = (fsf_req->qtcb != NULL);
4731
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 /* figure out expiration time of timeout and start timeout */
4733 if (unlikely(timer)) {
4734 timer->expires += jiffies;
4735 add_timer(timer);
4736 }
4737
4738 ZFCP_LOG_TRACE("request queue of adapter %s: "
4739 "next free SBAL is %i, %i free SBALs\n",
4740 zfcp_get_busid_by_adapter(adapter),
4741 req_queue->free_index,
4742 atomic_read(&req_queue->free_count));
4743
4744 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4745 "index_in_queue=%i, count=%i, buffers=%p\n",
4746 zfcp_get_busid_by_adapter(adapter),
4747 QDIO_FLAG_SYNC_OUTPUT,
4748 0, fsf_req->sbal_first, fsf_req->sbal_number,
4749 &req_queue->buffer[fsf_req->sbal_first]);
4750
4751 /*
4752 * adjust the number of free SBALs in request queue as well as
4753 * position of first one
4754 */
4755 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4756 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4757 req_queue->free_index += fsf_req->sbal_number; /* increase */
4758 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4759 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4760
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004761 fsf_req->issued = get_clock();
4762
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 retval = do_QDIO(adapter->ccw_device,
4764 QDIO_FLAG_SYNC_OUTPUT,
4765 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4766
4767 if (unlikely(retval)) {
4768 /* Queues are down..... */
4769 retval = -EIO;
4770 /*
4771 * FIXME(potential race):
4772 * timer might be expired (absolutely unlikely)
4773 */
4774 if (timer)
4775 del_timer(timer);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004776 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 list_del(&fsf_req->list);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004778 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 /*
4780 * adjust the number of free SBALs in request queue as well as
4781 * position of first one
4782 */
4783 zfcp_qdio_zero_sbals(req_queue->buffer,
4784 fsf_req->sbal_first, fsf_req->sbal_number);
4785 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4786 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4787 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4788 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4789 ZFCP_LOG_DEBUG
4790 ("error: do_QDIO failed. Buffers could not be enqueued "
4791 "to request queue.\n");
4792 } else {
4793 req_queue->distance_from_int = new_distance_from_int;
4794 /*
4795 * increase FSF sequence counter -
4796 * this must only be done for request successfully enqueued to
4797 * QDIO this rejected requests may be cleaned up by calling
4798 * routines resulting in missing sequence counter values
4799 * otherwise,
4800 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004801
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004803 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004805
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 /* count FSF requests pending */
4807 atomic_inc(&adapter->fsf_reqs_active);
4808 }
4809 return retval;
4810}
4811
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812#undef ZFCP_LOG_AREA