blob: 83b68e3043c86c644bb33f2def4ee6aecf785e88 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02002 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02005 * (C) Copyright IBM Corp. 2002, 2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "zfcp_ext.h"
23
24static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
25static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
26static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
27static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
28static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
29static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
30static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
31static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
32static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
33static int zfcp_fsf_send_fcp_command_task_management_handler(
34 struct zfcp_fsf_req *);
35static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
36static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
37static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
38static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
39static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
40static inline int zfcp_fsf_req_sbal_check(
41 unsigned long *, struct zfcp_qdio_queue *, int);
42static inline int zfcp_use_one_sbal(
43 struct scatterlist *, int, struct scatterlist *, int);
44static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
45static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
46static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
47static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
48static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020049static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
50 struct fsf_link_down_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
52static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/* association between FSF command and FSF QTCB type */
55static u32 fsf_qtcb_type[] = {
56 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
57 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
62 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
65 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
66 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
67 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
68 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
69};
70
71static const char zfcp_act_subtable_type[5][8] = {
72 "unknown", "OS", "WWPN", "DID", "LUN"
73};
74
75/****************************************************************/
76/*************** FSF related Functions *************************/
77/****************************************************************/
78
79#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
80
81/*
82 * function: zfcp_fsf_req_alloc
83 *
84 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
85 * unsolicited requests) via helper functions
86 * Does some initial fsf request set-up.
87 *
88 * returns: pointer to allocated fsf_req if successfull
89 * NULL otherwise
90 *
91 * locks: none
92 *
93 */
94static struct zfcp_fsf_req *
95zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
96{
97 size_t size;
98 void *ptr;
99 struct zfcp_fsf_req *fsf_req = NULL;
100
101 if (req_flags & ZFCP_REQ_NO_QTCB)
102 size = sizeof(struct zfcp_fsf_req);
103 else
104 size = sizeof(struct zfcp_fsf_req_pool_element);
105
106 if (likely(pool != NULL))
107 ptr = mempool_alloc(pool, GFP_ATOMIC);
108 else
109 ptr = kmalloc(size, GFP_ATOMIC);
110
111 if (unlikely(NULL == ptr))
112 goto out;
113
114 memset(ptr, 0, size);
115
116 if (req_flags & ZFCP_REQ_NO_QTCB) {
117 fsf_req = (struct zfcp_fsf_req *) ptr;
118 } else {
119 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
120 fsf_req->qtcb =
121 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
122 }
123
124 fsf_req->pool = pool;
125
126 out:
127 return fsf_req;
128}
129
130/*
131 * function: zfcp_fsf_req_free
132 *
133 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
134 * returns it into the pool via helper functions.
135 *
136 * returns: sod all
137 *
138 * locks: none
139 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200140void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
142{
143 if (likely(fsf_req->pool != NULL))
144 mempool_free(fsf_req, fsf_req->pool);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200145 else
146 kfree(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149/*
150 * function:
151 *
152 * purpose:
153 *
154 * returns:
155 *
156 * note: qdio queues shall be down (no ongoing inbound processing)
157 */
158int
159zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
160{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 struct zfcp_fsf_req *fsf_req, *tmp;
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200162 unsigned long flags;
163 LIST_HEAD(remove_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200165 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
166 list_splice_init(&adapter->fsf_req_list_head, &remove_queue);
167 atomic_set(&adapter->fsf_reqs_active, 0);
168 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
169
170 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
171 list_del(&fsf_req->list);
172 zfcp_fsf_req_dismiss(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200175 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178/*
179 * function:
180 *
181 * purpose:
182 *
183 * returns:
184 */
185static void
186zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
187{
188 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
189 zfcp_fsf_req_complete(fsf_req);
190}
191
192/*
193 * function: zfcp_fsf_req_complete
194 *
195 * purpose: Updates active counts and timers for openfcp-reqs
196 * May cleanup request after req_eval returns
197 *
198 * returns: 0 - success
199 * !0 - failure
200 *
201 * context:
202 */
203int
204zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
205{
206 int retval = 0;
207 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
210 ZFCP_LOG_DEBUG("Status read response received\n");
211 /*
212 * Note: all cleanup handling is done in the callchain of
213 * the function call-chain below.
214 */
215 zfcp_fsf_status_read_handler(fsf_req);
216 goto out;
217 } else
218 zfcp_fsf_protstatus_eval(fsf_req);
219
220 /*
221 * fsf_req may be deleted due to waking up functions, so
222 * cleanup is saved here and used later
223 */
224 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
225 cleanup = 1;
226 else
227 cleanup = 0;
228
229 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
230
231 /* cleanup request if requested by initiator */
232 if (likely(cleanup)) {
233 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
234 /*
235 * lock must not be held here since it will be
236 * grabed by the called routine, too
237 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200238 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 } else {
240 /* notify initiator waiting for the requests completion */
241 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
242 /*
243 * FIXME: Race! We must not access fsf_req here as it might have been
244 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
245 * flag. It's an improbable case. But, we have the same paranoia for
246 * the cleanup flag already.
247 * Might better be handled using complete()?
248 * (setting the flag and doing wakeup ought to be atomic
249 * with regard to checking the flag as long as waitqueue is
250 * part of the to be released structure)
251 */
252 wake_up(&fsf_req->completion_wq);
253 }
254
255 out:
256 return retval;
257}
258
259/*
260 * function: zfcp_fsf_protstatus_eval
261 *
262 * purpose: evaluates the QTCB of the finished FSF request
263 * and initiates appropriate actions
264 * (usually calling FSF command specific handlers)
265 *
266 * returns:
267 *
268 * context:
269 *
270 * locks:
271 */
272static int
273zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
274{
275 int retval = 0;
276 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200277 struct fsf_qtcb *qtcb = fsf_req->qtcb;
278 union fsf_prot_status_qual *prot_status_qual =
279 &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200281 zfcp_hba_dbf_event_fsf_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
284 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
285 (unsigned long) fsf_req);
286 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
287 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 goto skip_protstatus;
289 }
290
291 /* log additional information provided by FSF (if any) */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200292 if (unlikely(qtcb->header.log_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 /* do not trust them ;-) */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200294 if (qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 ZFCP_LOG_NORMAL
296 ("bug: ULP (FSF logging) log data starts "
297 "beyond end of packet header. Ignored. "
298 "(start=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200299 qtcb->header.log_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 sizeof(struct fsf_qtcb));
301 goto forget_log;
302 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200303 if ((size_t) (qtcb->header.log_start + qtcb->header.log_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 > sizeof(struct fsf_qtcb)) {
305 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
306 "beyond end of packet header. Ignored. "
307 "(start=%i, length=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200308 qtcb->header.log_start,
309 qtcb->header.log_length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 sizeof(struct fsf_qtcb));
311 goto forget_log;
312 }
313 ZFCP_LOG_TRACE("ULP log data: \n");
314 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200315 (char *) qtcb + qtcb->header.log_start,
316 qtcb->header.log_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
318 forget_log:
319
320 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200321 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 break;
326
327 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 ZFCP_LOG_NORMAL("error: The adapter %s contains "
329 "microcode of version 0x%x, the device driver "
330 "only supports 0x%x. Aborting.\n",
331 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200332 prot_status_qual->version_error.fsf_version,
333 ZFCP_QTCB_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
336 break;
337
338 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
340 "driver (0x%x) and adapter %s (0x%x). "
341 "Restarting all operations on this adapter.\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200342 qtcb->prefix.req_seq_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200344 prot_status_qual->sequence_error.exp_req_seq_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
347 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
348 break;
349
350 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 ZFCP_LOG_NORMAL("error: Packet header type used by the "
352 "device driver is incompatible with "
353 "that used on adapter %s. "
354 "Stopping all operations on this adapter.\n",
355 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
358 break;
359
360 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
362 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
363 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 break;
365
366 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
368 "to the adapter %s is ambiguous. "
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200369 "Stopping all operations on this adapter.\n",
370 *(unsigned long long*)
371 (&qtcb->bottom.support.req_handle),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
375 break;
376
377 case FSF_PROT_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200378 zfcp_fsf_link_down_info_eval(adapter,
379 &prot_status_qual->link_down_info);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100380 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
382 break;
383
384 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200385 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 "%s was re-plugged. "
387 "Re-starting operations on this adapter.\n",
388 zfcp_get_busid_by_adapter(adapter));
389 /* All ports should be marked as ready to run again */
390 zfcp_erp_modify_adapter_status(adapter,
391 ZFCP_STATUS_COMMON_RUNNING,
392 ZFCP_SET);
393 zfcp_erp_adapter_reopen(adapter,
394 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
395 | ZFCP_STATUS_COMMON_ERP_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
397 break;
398
399 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 ZFCP_LOG_NORMAL("error: The adapter %s "
401 "has entered the error state. "
402 "Restarting all operations on this "
403 "adapter.\n",
404 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
407 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
408 break;
409
410 default:
411 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
412 "provided by the adapter %s "
413 "is not compatible with the device driver. "
414 "Stopping all operations on this adapter. "
415 "(debug info 0x%x).\n",
416 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200417 qtcb->prefix.prot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 zfcp_erp_adapter_shutdown(adapter, 0);
419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
420 }
421
422 skip_protstatus:
423 /*
424 * always call specific handlers to give them a chance to do
425 * something meaningful even in error cases
426 */
427 zfcp_fsf_fsfstatus_eval(fsf_req);
428 return retval;
429}
430
431/*
432 * function: zfcp_fsf_fsfstatus_eval
433 *
434 * purpose: evaluates FSF status of completed FSF request
435 * and acts accordingly
436 *
437 * returns:
438 */
439static int
440zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
441{
442 int retval = 0;
443
444 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
445 goto skip_fsfstatus;
446 }
447
448 /* evaluate FSF Status */
449 switch (fsf_req->qtcb->header.fsf_status) {
450 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
452 "not known by the adapter %s "
453 "Stopping all operations on this adapter. "
454 "(debug info 0x%x).\n",
455 zfcp_get_busid_by_adapter(fsf_req->adapter),
456 fsf_req->qtcb->header.fsf_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
459 break;
460
461 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
463 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
465
466 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
468 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470
471 skip_fsfstatus:
472 /*
473 * always call specific handlers to give them a chance to do
474 * something meaningful even in error cases
475 */
476 zfcp_fsf_req_dispatch(fsf_req);
477
478 return retval;
479}
480
481/*
482 * function: zfcp_fsf_fsfstatus_qual_eval
483 *
484 * purpose: evaluates FSF status-qualifier of completed FSF request
485 * and acts accordingly
486 *
487 * returns:
488 */
489static int
490zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
491{
492 int retval = 0;
493
494 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
495 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
497 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
500 break;
501 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
504 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
505 break;
506 case FSF_SQ_NO_RECOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
508 "problem on the adapter %s "
509 "Stopping all operations on this adapter. ",
510 zfcp_get_busid_by_adapter(fsf_req->adapter));
511 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
513 break;
514 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
516 "(adapter %s)\n",
517 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
519 break;
520 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
521 case FSF_SQ_NO_RETRY_POSSIBLE:
522 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
523 /* dealt with in the respective functions */
524 break;
525 default:
526 ZFCP_LOG_NORMAL("bug: Additional status info could "
527 "not be interpreted properly.\n");
528 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
529 (char *) &fsf_req->qtcb->header.fsf_status_qual,
530 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
532 break;
533 }
534
535 return retval;
536}
537
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200538/**
539 * zfcp_fsf_link_down_info_eval - evaluate link down information block
540 */
541static void
542zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
543 struct fsf_link_down_info *link_down)
544{
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100545 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
546 &adapter->status))
547 return;
548
549 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
550
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100551 if (link_down == NULL)
552 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100553
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200554 switch (link_down->error_code) {
555 case FSF_PSQ_LINK_NO_LIGHT:
556 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
557 "(no light detected)\n",
558 zfcp_get_busid_by_adapter(adapter));
559 break;
560 case FSF_PSQ_LINK_WRAP_PLUG:
561 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
562 "(wrap plug detected)\n",
563 zfcp_get_busid_by_adapter(adapter));
564 break;
565 case FSF_PSQ_LINK_NO_FCP:
566 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
567 "(adjacent node on link does not support FCP)\n",
568 zfcp_get_busid_by_adapter(adapter));
569 break;
570 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
571 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
572 "(firmware update in progress)\n",
573 zfcp_get_busid_by_adapter(adapter));
574 break;
575 case FSF_PSQ_LINK_INVALID_WWPN:
576 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
577 "(duplicate or invalid WWPN detected)\n",
578 zfcp_get_busid_by_adapter(adapter));
579 break;
580 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
581 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
582 "(no support for NPIV by Fabric)\n",
583 zfcp_get_busid_by_adapter(adapter));
584 break;
585 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
586 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
587 "(out of resource in FCP daughtercard)\n",
588 zfcp_get_busid_by_adapter(adapter));
589 break;
590 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
591 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
592 "(out of resource in Fabric)\n",
593 zfcp_get_busid_by_adapter(adapter));
594 break;
595 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
596 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
597 "(unable to Fabric login)\n",
598 zfcp_get_busid_by_adapter(adapter));
599 break;
600 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
601 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
602 zfcp_get_busid_by_adapter(adapter));
603 break;
604 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
605 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
606 zfcp_get_busid_by_adapter(adapter));
607 break;
608 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
609 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
610 zfcp_get_busid_by_adapter(adapter));
611 break;
612 default:
613 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
614 "(warning: unknown reason code %d)\n",
615 zfcp_get_busid_by_adapter(adapter),
616 link_down->error_code);
617 }
618
619 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
620 ZFCP_LOG_DEBUG("Debug information to link down: "
621 "primary_status=0x%02x "
622 "ioerr_code=0x%02x "
623 "action_code=0x%02x "
624 "reason_code=0x%02x "
625 "explanation_code=0x%02x "
626 "vendor_specific_code=0x%02x\n",
627 link_down->primary_status,
628 link_down->ioerr_code,
629 link_down->action_code,
630 link_down->reason_code,
631 link_down->explanation_code,
632 link_down->vendor_specific_code);
633
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100634 out:
635 zfcp_erp_adapter_failed(adapter);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200636}
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638/*
639 * function: zfcp_fsf_req_dispatch
640 *
641 * purpose: calls the appropriate command specific handler
642 *
643 * returns:
644 */
645static int
646zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
647{
648 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
649 struct zfcp_adapter *adapter = fsf_req->adapter;
650 int retval = 0;
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 switch (fsf_req->fsf_command) {
654
655 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 zfcp_fsf_send_fcp_command_handler(fsf_req);
657 break;
658
659 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 zfcp_fsf_abort_fcp_command_handler(fsf_req);
661 break;
662
663 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 zfcp_fsf_send_ct_handler(fsf_req);
665 break;
666
667 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 zfcp_fsf_open_port_handler(fsf_req);
669 break;
670
671 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 zfcp_fsf_open_unit_handler(fsf_req);
673 break;
674
675 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 zfcp_fsf_close_unit_handler(fsf_req);
677 break;
678
679 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 zfcp_fsf_close_port_handler(fsf_req);
681 break;
682
683 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 zfcp_fsf_close_physical_port_handler(fsf_req);
685 break;
686
687 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 zfcp_fsf_exchange_config_data_handler(fsf_req);
689 break;
690
691 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 zfcp_fsf_exchange_port_data_handler(fsf_req);
693 break;
694
695 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 zfcp_fsf_send_els_handler(fsf_req);
697 break;
698
699 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 zfcp_fsf_control_file_handler(fsf_req);
701 break;
702
703 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 zfcp_fsf_control_file_handler(fsf_req);
705 break;
706
707 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
709 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
710 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200711 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
713 ZFCP_LOG_NORMAL
714 ("bug: Command issued by the device driver differs "
715 "from the command returned by the adapter %s "
716 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200717 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 fsf_req->fsf_command,
719 fsf_req->qtcb->header.fsf_command);
720 }
721
722 if (!erp_action)
723 return retval;
724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 zfcp_erp_async_handler(erp_action, 0);
726
727 return retval;
728}
729
730/*
731 * function: zfcp_fsf_status_read
732 *
733 * purpose: initiates a Status Read command at the specified adapter
734 *
735 * returns:
736 */
737int
738zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
739{
740 struct zfcp_fsf_req *fsf_req;
741 struct fsf_status_read_buffer *status_buffer;
742 unsigned long lock_flags;
743 volatile struct qdio_buffer_element *sbale;
744 int retval = 0;
745
746 /* setup new FSF request */
747 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
748 req_flags | ZFCP_REQ_NO_QTCB,
749 adapter->pool.fsf_req_status_read,
750 &lock_flags, &fsf_req);
751 if (retval < 0) {
752 ZFCP_LOG_INFO("error: Could not create unsolicited status "
753 "buffer for adapter %s.\n",
754 zfcp_get_busid_by_adapter(adapter));
755 goto failed_req_create;
756 }
757
758 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
759 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
760 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
761 fsf_req->sbale_curr = 2;
762
763 status_buffer =
764 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
765 if (!status_buffer) {
766 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
767 goto failed_buf;
768 }
769 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200770 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 /* insert pointer to respective buffer */
773 sbale = zfcp_qdio_sbale_curr(fsf_req);
774 sbale->addr = (void *) status_buffer;
775 sbale->length = sizeof(struct fsf_status_read_buffer);
776
777 /* start QDIO request for this FSF request */
778 retval = zfcp_fsf_req_send(fsf_req, NULL);
779 if (retval) {
780 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
781 "environment.\n");
782 goto failed_req_send;
783 }
784
785 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
786 zfcp_get_busid_by_adapter(adapter));
787 goto out;
788
789 failed_req_send:
790 mempool_free(status_buffer, adapter->pool.data_status_read);
791
792 failed_buf:
793 zfcp_fsf_req_free(fsf_req);
794 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200795 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 out:
797 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
798 return retval;
799}
800
801static int
802zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
803{
804 struct fsf_status_read_buffer *status_buffer;
805 struct zfcp_adapter *adapter;
806 struct zfcp_port *port;
807 unsigned long flags;
808
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200809 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 adapter = fsf_req->adapter;
811
812 read_lock_irqsave(&zfcp_data.config_lock, flags);
813 list_for_each_entry(port, &adapter->port_list_head, list)
814 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
815 break;
816 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
817
818 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
819 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
820 "nonexisting port with d_id 0x%08x on "
821 "adapter %s. Ignored.\n",
822 status_buffer->d_id & ZFCP_DID_MASK,
823 zfcp_get_busid_by_adapter(adapter));
824 goto out;
825 }
826
827 switch (status_buffer->status_subtype) {
828
829 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
831 zfcp_erp_port_reopen(port, 0);
832 break;
833
834 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
836 zfcp_erp_port_shutdown(port, 0);
837 break;
838
839 default:
840 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
841 debug_exception(adapter->erp_dbf, 0,
842 &status_buffer->status_subtype, sizeof (u32));
843 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
844 "for a reopen indication on port with "
845 "d_id 0x%08x on the adapter %s. "
846 "Ignored. (debug info 0x%x)\n",
847 status_buffer->d_id,
848 zfcp_get_busid_by_adapter(adapter),
849 status_buffer->status_subtype);
850 }
851 out:
852 return 0;
853}
854
855/*
856 * function: zfcp_fsf_status_read_handler
857 *
858 * purpose: is called for finished Open Port command
859 *
860 * returns:
861 */
862static int
863zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
864{
865 int retval = 0;
866 struct zfcp_adapter *adapter = fsf_req->adapter;
867 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200868 (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200871 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200873 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 goto out;
875 }
876
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200877 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 switch (status_buffer->status_type) {
880
881 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 zfcp_fsf_status_read_port_closed(fsf_req);
883 break;
884
885 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 zfcp_fsf_incoming_els(fsf_req);
887 break;
888
889 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
891 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 break;
893
894 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
896 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
897 (char *) status_buffer,
898 sizeof (struct fsf_status_read_buffer));
899 break;
900
901 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200902 switch (status_buffer->status_subtype) {
903 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
904 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
905 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100906 zfcp_fsf_link_down_info_eval(adapter,
907 (struct fsf_link_down_info *)
908 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200909 break;
910 case FSF_STATUS_READ_SUB_FDISC_FAILED:
911 ZFCP_LOG_INFO("Local link to adapter %s is down "
912 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100913 zfcp_get_busid_by_adapter(adapter));
914 zfcp_fsf_link_down_info_eval(adapter,
915 (struct fsf_link_down_info *)
916 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200917 break;
918 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
919 ZFCP_LOG_INFO("Local link to adapter %s is down "
920 "due to firmware update on adapter\n",
921 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100922 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200923 break;
924 default:
925 ZFCP_LOG_INFO("Local link to adapter %s is down "
926 "due to unknown reason\n",
927 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100928 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200929 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 break;
931
932 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200933 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100934 "Restarting operations on this adapter\n",
935 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 /* All ports should be marked as ready to run again */
937 zfcp_erp_modify_adapter_status(adapter,
938 ZFCP_STATUS_COMMON_RUNNING,
939 ZFCP_SET);
940 zfcp_erp_adapter_reopen(adapter,
941 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
942 | ZFCP_STATUS_COMMON_ERP_FAILED);
943 break;
944
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100945 case FSF_STATUS_READ_NOTIFICATION_LOST:
946 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
947 "adapter %s%s%s%s%s%s%s%s%s\n",
948 zfcp_get_busid_by_adapter(adapter),
949 (status_buffer->status_subtype &
950 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
951 ", incoming ELS" : "",
952 (status_buffer->status_subtype &
953 FSF_STATUS_READ_SUB_SENSE_DATA) ?
954 ", sense data" : "",
955 (status_buffer->status_subtype &
956 FSF_STATUS_READ_SUB_LINK_STATUS) ?
957 ", link status change" : "",
958 (status_buffer->status_subtype &
959 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
960 ", port close" : "",
961 (status_buffer->status_subtype &
962 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
963 ", bit error exception" : "",
964 (status_buffer->status_subtype &
965 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
966 ", ACT update" : "",
967 (status_buffer->status_subtype &
968 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
969 ", ACT hardening" : "",
970 (status_buffer->status_subtype &
971 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
972 ", adapter feature change" : "");
973
974 if (status_buffer->status_subtype &
975 FSF_STATUS_READ_SUB_ACT_UPDATED)
976 zfcp_erp_adapter_access_changed(adapter);
977 break;
978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200980 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 zfcp_get_busid_by_adapter(adapter));
982 zfcp_erp_adapter_access_changed(adapter);
983 break;
984
985 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 switch (status_buffer->status_subtype) {
987 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200988 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 zfcp_get_busid_by_adapter(adapter));
990 break;
991 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200992 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 "to the secondary SE\n",
994 zfcp_get_busid_by_adapter(adapter));
995 break;
996 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200997 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 zfcp_get_busid_by_adapter(adapter));
999 }
1000 break;
1001
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001002 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1003 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1004 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1005 "been changed from 0x%08X to 0x%08X\n",
1006 zfcp_get_busid_by_adapter(adapter),
1007 *(u32*) (status_buffer->payload + 4),
1008 *(u32*) (status_buffer->payload));
1009 adapter->adapter_features = *(u32*) status_buffer->payload;
1010 break;
1011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001013 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 "type was received (debug info 0x%x)\n",
1015 status_buffer->status_type);
1016 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1017 status_buffer);
1018 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1019 (char *) status_buffer,
1020 sizeof (struct fsf_status_read_buffer));
1021 break;
1022 }
1023 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001024 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 /*
1026 * recycle buffer and start new request repeat until outbound
1027 * queue is empty or adapter shutdown is requested
1028 */
1029 /*
1030 * FIXME(qdio):
1031 * we may wait in the req_create for 5s during shutdown, so
1032 * qdio_cleanup will have to wait at least that long before returning
1033 * with failure to allow us a proper cleanup under all circumstances
1034 */
1035 /*
1036 * FIXME:
1037 * allocation failure possible? (Is this code needed?)
1038 */
1039 retval = zfcp_fsf_status_read(adapter, 0);
1040 if (retval < 0) {
1041 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1042 "request for the adapter %s.\n",
1043 zfcp_get_busid_by_adapter(adapter));
1044 /* temporary fix to avoid status read buffer shortage */
1045 adapter->status_read_failed++;
1046 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1047 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1048 ZFCP_LOG_INFO("restart adapter %s due to status read "
1049 "buffer shortage\n",
1050 zfcp_get_busid_by_adapter(adapter));
1051 zfcp_erp_adapter_reopen(adapter, 0);
1052 }
1053 }
1054 out:
1055 return retval;
1056}
1057
1058/*
1059 * function: zfcp_fsf_abort_fcp_command
1060 *
1061 * purpose: tells FSF to abort a running SCSI command
1062 *
1063 * returns: address of initiated FSF request
1064 * NULL - request could not be initiated
1065 *
1066 * FIXME(design): should be watched by a timeout !!!
1067 * FIXME(design) shouldn't this be modified to return an int
1068 * also...don't know how though
1069 */
1070struct zfcp_fsf_req *
1071zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1072 struct zfcp_adapter *adapter,
1073 struct zfcp_unit *unit, int req_flags)
1074{
1075 volatile struct qdio_buffer_element *sbale;
1076 unsigned long lock_flags;
1077 struct zfcp_fsf_req *fsf_req = NULL;
1078 int retval = 0;
1079
1080 /* setup new FSF request */
1081 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1082 req_flags, adapter->pool.fsf_req_abort,
1083 &lock_flags, &fsf_req);
1084 if (retval < 0) {
1085 ZFCP_LOG_INFO("error: Failed to create an abort command "
1086 "request for lun 0x%016Lx on port 0x%016Lx "
1087 "on adapter %s.\n",
1088 unit->fcp_lun,
1089 unit->port->wwpn,
1090 zfcp_get_busid_by_adapter(adapter));
1091 goto out;
1092 }
1093
1094 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1095 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1096 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1097
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001098 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 /* set handles of unit and its parent port in QTCB */
1101 fsf_req->qtcb->header.lun_handle = unit->handle;
1102 fsf_req->qtcb->header.port_handle = unit->port->handle;
1103
1104 /* set handle of request which should be aborted */
1105 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1106
1107 /* start QDIO request for this FSF request */
1108
1109 zfcp_fsf_start_scsi_er_timer(adapter);
1110 retval = zfcp_fsf_req_send(fsf_req, NULL);
1111 if (retval) {
1112 del_timer(&adapter->scsi_er_timer);
1113 ZFCP_LOG_INFO("error: Failed to send abort command request "
1114 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1115 zfcp_get_busid_by_adapter(adapter),
1116 unit->port->wwpn, unit->fcp_lun);
1117 zfcp_fsf_req_free(fsf_req);
1118 fsf_req = NULL;
1119 goto out;
1120 }
1121
1122 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1123 "(adapter%s, port d_id=0x%08x, "
1124 "unit x%016Lx, old_req_id=0x%lx)\n",
1125 zfcp_get_busid_by_adapter(adapter),
1126 unit->port->d_id,
1127 unit->fcp_lun, old_req_id);
1128 out:
1129 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1130 return fsf_req;
1131}
1132
1133/*
1134 * function: zfcp_fsf_abort_fcp_command_handler
1135 *
1136 * purpose: is called for finished Abort FCP Command request
1137 *
1138 * returns:
1139 */
1140static int
1141zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1142{
1143 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001144 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 unsigned char status_qual =
1146 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1147
1148 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1149
1150 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1151 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1152 goto skip_fsfstatus;
1153 }
1154
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001155 unit = (struct zfcp_unit *) new_fsf_req->data;
1156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 /* evaluate FSF status in QTCB */
1158 switch (new_fsf_req->qtcb->header.fsf_status) {
1159
1160 case FSF_PORT_HANDLE_NOT_VALID:
1161 if (status_qual >> 4 != status_qual % 0xf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1163 "fsf_s_phand_nv0");
1164 /*
1165 * In this case a command that was sent prior to a port
1166 * reopen was aborted (handles are different). This is
1167 * fine.
1168 */
1169 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1171 "port 0x%016Lx on adapter %s invalid. "
1172 "This may happen occasionally.\n",
1173 unit->port->handle,
1174 unit->port->wwpn,
1175 zfcp_get_busid_by_unit(unit));
1176 ZFCP_LOG_INFO("status qualifier:\n");
1177 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1178 (char *) &new_fsf_req->qtcb->header.
1179 fsf_status_qual,
1180 sizeof (union fsf_status_qual));
1181 /* Let's hope this sorts out the mess */
1182 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1183 "fsf_s_phand_nv1");
1184 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1185 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1186 }
1187 break;
1188
1189 case FSF_LUN_HANDLE_NOT_VALID:
1190 if (status_qual >> 4 != status_qual % 0xf) {
1191 /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1193 "fsf_s_lhand_nv0");
1194 /*
1195 * In this case a command that was sent prior to a unit
1196 * reopen was aborted (handles are different).
1197 * This is fine.
1198 */
1199 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 ZFCP_LOG_INFO
1201 ("Warning: Temporary LUN identifier 0x%x of LUN "
1202 "0x%016Lx on port 0x%016Lx on adapter %s is "
1203 "invalid. This may happen in rare cases. "
1204 "Trying to re-establish link.\n",
1205 unit->handle,
1206 unit->fcp_lun,
1207 unit->port->wwpn,
1208 zfcp_get_busid_by_unit(unit));
1209 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1210 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1211 (char *) &new_fsf_req->qtcb->header.
1212 fsf_status_qual,
1213 sizeof (union fsf_status_qual));
1214 /* Let's hope this sorts out the mess */
1215 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1216 "fsf_s_lhand_nv1");
1217 zfcp_erp_port_reopen(unit->port, 0);
1218 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1219 }
1220 break;
1221
1222 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 retval = 0;
1224 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1225 "fsf_s_no_exist");
1226 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1227 break;
1228
1229 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1231 "be reopened\n", unit->port->wwpn,
1232 zfcp_get_busid_by_unit(unit));
1233 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1234 "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001235 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1237 | ZFCP_STATUS_FSFREQ_RETRY;
1238 break;
1239
1240 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 ZFCP_LOG_INFO(
1242 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1243 "to be reopened\n",
1244 unit->fcp_lun, unit->port->wwpn,
1245 zfcp_get_busid_by_unit(unit));
1246 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001247 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1249 | ZFCP_STATUS_FSFREQ_RETRY;
1250 break;
1251
1252 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1254 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1256 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001257 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1259 break;
1260 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 /* SCSI stack will escalate */
1262 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1263 "fsf_sq_ulp");
1264 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1265 break;
1266 default:
1267 ZFCP_LOG_NORMAL
1268 ("bug: Wrong status qualifier 0x%x arrived.\n",
1269 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1270 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1271 "fsf_sq_inval:");
1272 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1273 &new_fsf_req->qtcb->header.
1274 fsf_status_qual.word[0], sizeof (u32));
1275 break;
1276 }
1277 break;
1278
1279 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 retval = 0;
1281 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1282 break;
1283
1284 default:
1285 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1286 "(debug info 0x%x)\n",
1287 new_fsf_req->qtcb->header.fsf_status);
1288 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1289 "fsf_s_inval:");
1290 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1291 &new_fsf_req->qtcb->header.fsf_status,
1292 sizeof (u32));
1293 break;
1294 }
1295 skip_fsfstatus:
1296 return retval;
1297}
1298
1299/**
1300 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1301 * one SBALE
1302 * Two scatter-gather lists are passed, one for the reqeust and one for the
1303 * response.
1304 */
1305static inline int
1306zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1307 struct scatterlist *resp, int resp_count)
1308{
1309 return ((req_count == 1) &&
1310 (resp_count == 1) &&
1311 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1312 PAGE_MASK) ==
1313 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1314 req[0].length - 1) & PAGE_MASK)) &&
1315 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1316 PAGE_MASK) ==
1317 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1318 resp[0].length - 1) & PAGE_MASK)));
1319}
1320
1321/**
1322 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1323 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1324 * the request
1325 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1326 * a struct zfcp_fsf_req
1327 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1328 * is sent within error recovery
1329 */
1330int
1331zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1332 struct zfcp_erp_action *erp_action)
1333{
1334 volatile struct qdio_buffer_element *sbale;
1335 struct zfcp_port *port;
1336 struct zfcp_adapter *adapter;
1337 struct zfcp_fsf_req *fsf_req;
1338 unsigned long lock_flags;
1339 int bytes;
1340 int ret = 0;
1341
1342 port = ct->port;
1343 adapter = port->adapter;
1344
1345 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1346 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1347 pool, &lock_flags, &fsf_req);
1348 if (ret < 0) {
1349 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1350 "adapter: %s\n",
1351 zfcp_get_busid_by_adapter(adapter));
1352 goto failed_req;
1353 }
1354
1355 if (erp_action != NULL) {
1356 erp_action->fsf_req = fsf_req;
1357 fsf_req->erp_action = erp_action;
1358 }
1359
1360 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1361 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1362 ct->resp, ct->resp_count)){
1363 /* both request buffer and response buffer
1364 fit into one sbale each */
1365 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1366 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1367 sbale[2].length = ct->req[0].length;
1368 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1369 sbale[3].length = ct->resp[0].length;
1370 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001371 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1373 /* try to use chained SBALs */
1374 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1375 SBAL_FLAGS0_TYPE_WRITE_READ,
1376 ct->req, ct->req_count,
1377 ZFCP_MAX_SBALS_PER_CT_REQ);
1378 if (bytes <= 0) {
1379 ZFCP_LOG_INFO("error: creation of CT request failed "
1380 "on adapter %s\n",
1381 zfcp_get_busid_by_adapter(adapter));
1382 if (bytes == 0)
1383 ret = -ENOMEM;
1384 else
1385 ret = bytes;
1386
1387 goto failed_send;
1388 }
1389 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1390 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1391 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1392 SBAL_FLAGS0_TYPE_WRITE_READ,
1393 ct->resp, ct->resp_count,
1394 ZFCP_MAX_SBALS_PER_CT_REQ);
1395 if (bytes <= 0) {
1396 ZFCP_LOG_INFO("error: creation of CT request failed "
1397 "on adapter %s\n",
1398 zfcp_get_busid_by_adapter(adapter));
1399 if (bytes == 0)
1400 ret = -ENOMEM;
1401 else
1402 ret = bytes;
1403
1404 goto failed_send;
1405 }
1406 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1407 } else {
1408 /* reject send generic request */
1409 ZFCP_LOG_INFO(
1410 "error: microcode does not support chained SBALs,"
1411 "CT request too big (adapter %s)\n",
1412 zfcp_get_busid_by_adapter(adapter));
1413 ret = -EOPNOTSUPP;
1414 goto failed_send;
1415 }
1416
1417 /* settings in QTCB */
1418 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001419 fsf_req->qtcb->bottom.support.service_class =
1420 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001422 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001424 zfcp_san_dbf_event_ct_request(fsf_req);
1425
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 /* start QDIO request for this FSF request */
1427 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1428 if (ret) {
1429 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1430 "(adapter %s, port 0x%016Lx)\n",
1431 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1432 goto failed_send;
1433 }
1434
1435 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1436 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1437 goto out;
1438
1439 failed_send:
1440 zfcp_fsf_req_free(fsf_req);
1441 if (erp_action != NULL) {
1442 erp_action->fsf_req = NULL;
1443 }
1444 failed_req:
1445 out:
1446 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1447 lock_flags);
1448 return ret;
1449}
1450
1451/**
1452 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1453 * @fsf_req: pointer to struct zfcp_fsf_req
1454 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001455 * Data specific for the Generic Service request is passed using
1456 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1457 * Usually a specific handler for the CT request is called which is
1458 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 */
1460static int
1461zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1462{
1463 struct zfcp_port *port;
1464 struct zfcp_adapter *adapter;
1465 struct zfcp_send_ct *send_ct;
1466 struct fsf_qtcb_header *header;
1467 struct fsf_qtcb_bottom_support *bottom;
1468 int retval = -EINVAL;
1469 u16 subtable, rule, counter;
1470
1471 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001472 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 port = send_ct->port;
1474 header = &fsf_req->qtcb->header;
1475 bottom = &fsf_req->qtcb->bottom.support;
1476
1477 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1478 goto skip_fsfstatus;
1479
1480 /* evaluate FSF status in QTCB */
1481 switch (header->fsf_status) {
1482
1483 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001484 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 retval = 0;
1486 break;
1487
1488 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001489 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1490 "class %d.\n",
1491 zfcp_get_busid_by_port(port),
1492 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 /* stop operation for this adapter */
1494 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1495 zfcp_erp_adapter_shutdown(adapter, 0);
1496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1497 break;
1498
1499 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 switch (header->fsf_status_qual.word[0]){
1501 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 /* reopening link to port */
1503 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1504 zfcp_test_link(port);
1505 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1506 break;
1507 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 /* ERP strategy will escalate */
1509 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1511 break;
1512 default:
1513 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1514 "arrived.\n",
1515 header->fsf_status_qual.word[0]);
1516 break;
1517 }
1518 break;
1519
1520 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1522 "command (adapter %s, port d_id=0x%08x)\n",
1523 zfcp_get_busid_by_port(port), port->d_id);
1524 for (counter = 0; counter < 2; counter++) {
1525 subtable = header->fsf_status_qual.halfword[counter * 2];
1526 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1527 switch (subtable) {
1528 case FSF_SQ_CFDC_SUBTABLE_OS:
1529 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1530 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1531 case FSF_SQ_CFDC_SUBTABLE_LUN:
1532 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1533 zfcp_act_subtable_type[subtable], rule);
1534 break;
1535 }
1536 }
1537 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1538 zfcp_erp_port_access_denied(port);
1539 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1540 break;
1541
1542 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 ZFCP_LOG_INFO("generic service command rejected "
1544 "(adapter %s, port d_id=0x%08x)\n",
1545 zfcp_get_busid_by_port(port), port->d_id);
1546 ZFCP_LOG_INFO("status qualifier:\n");
1547 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1548 (char *) &header->fsf_status_qual,
1549 sizeof (union fsf_status_qual));
1550 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1551 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1552 break;
1553
1554 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1556 "0x%016Lx on adapter %s invalid. This may "
1557 "happen occasionally.\n", port->handle,
1558 port->wwpn, zfcp_get_busid_by_port(port));
1559 ZFCP_LOG_INFO("status qualifier:\n");
1560 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1561 (char *) &header->fsf_status_qual,
1562 sizeof (union fsf_status_qual));
1563 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1564 zfcp_erp_adapter_reopen(adapter, 0);
1565 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1566 break;
1567
1568 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 ZFCP_LOG_INFO("port needs to be reopened "
1570 "(adapter %s, port d_id=0x%08x)\n",
1571 zfcp_get_busid_by_port(port), port->d_id);
1572 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001573 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1575 | ZFCP_STATUS_FSFREQ_RETRY;
1576 break;
1577
1578 /* following states should never occure, all cases avoided
1579 in zfcp_fsf_send_ct - but who knows ... */
1580 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1582 "req_buf_length=%d, resp_buf_length=%d)\n",
1583 zfcp_get_busid_by_adapter(adapter),
1584 bottom->req_buf_length, bottom->resp_buf_length);
1585 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1586 break;
1587 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1589 "req_buf_length=%d)\n",
1590 zfcp_get_busid_by_adapter(adapter),
1591 bottom->req_buf_length);
1592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1593 break;
1594 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1596 "resp_buf_length=%d)\n",
1597 zfcp_get_busid_by_adapter(adapter),
1598 bottom->resp_buf_length);
1599 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1600 break;
1601 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1603 "resp_buf_length=%d)\n",
1604 zfcp_get_busid_by_adapter(adapter),
1605 bottom->req_buf_length, bottom->resp_buf_length);
1606 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1607 break;
1608
1609 default:
1610 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1611 "(debug info 0x%x)\n", header->fsf_status);
1612 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1613 debug_exception(adapter->erp_dbf, 0,
1614 &header->fsf_status_qual.word[0], sizeof (u32));
1615 break;
1616 }
1617
1618skip_fsfstatus:
1619 send_ct->status = retval;
1620
1621 if (send_ct->handler != NULL)
1622 send_ct->handler(send_ct->handler_data);
1623
1624 return retval;
1625}
1626
1627/**
1628 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1629 * @els: pointer to struct zfcp_send_els which contains all needed data for
1630 * the command.
1631 */
1632int
1633zfcp_fsf_send_els(struct zfcp_send_els *els)
1634{
1635 volatile struct qdio_buffer_element *sbale;
1636 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001637 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 struct zfcp_adapter *adapter;
1639 unsigned long lock_flags;
1640 int bytes;
1641 int ret = 0;
1642
1643 d_id = els->d_id;
1644 adapter = els->adapter;
1645
1646 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1647 ZFCP_REQ_AUTO_CLEANUP,
1648 NULL, &lock_flags, &fsf_req);
1649 if (ret < 0) {
1650 ZFCP_LOG_INFO("error: creation of ELS request failed "
1651 "(adapter %s, port d_id: 0x%08x)\n",
1652 zfcp_get_busid_by_adapter(adapter), d_id);
1653 goto failed_req;
1654 }
1655
1656 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1657 if (zfcp_use_one_sbal(els->req, els->req_count,
1658 els->resp, els->resp_count)){
1659 /* both request buffer and response buffer
1660 fit into one sbale each */
1661 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1662 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1663 sbale[2].length = els->req[0].length;
1664 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1665 sbale[3].length = els->resp[0].length;
1666 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001667 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1669 /* try to use chained SBALs */
1670 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1671 SBAL_FLAGS0_TYPE_WRITE_READ,
1672 els->req, els->req_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.req_buf_length = bytes;
1686 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1687 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1688 SBAL_FLAGS0_TYPE_WRITE_READ,
1689 els->resp, els->resp_count,
1690 ZFCP_MAX_SBALS_PER_ELS_REQ);
1691 if (bytes <= 0) {
1692 ZFCP_LOG_INFO("error: creation of ELS request failed "
1693 "(adapter %s, port d_id: 0x%08x)\n",
1694 zfcp_get_busid_by_adapter(adapter), d_id);
1695 if (bytes == 0) {
1696 ret = -ENOMEM;
1697 } else {
1698 ret = bytes;
1699 }
1700 goto failed_send;
1701 }
1702 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1703 } else {
1704 /* reject request */
1705 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1706 ", ELS request too big (adapter %s, "
1707 "port d_id: 0x%08x)\n",
1708 zfcp_get_busid_by_adapter(adapter), d_id);
1709 ret = -EOPNOTSUPP;
1710 goto failed_send;
1711 }
1712
1713 /* settings in QTCB */
1714 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001715 fsf_req->qtcb->bottom.support.service_class =
1716 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001718 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
1720 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1721
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001722 zfcp_san_dbf_event_els_request(fsf_req);
1723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 /* start QDIO request for this FSF request */
1725 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1726 if (ret) {
1727 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1728 "(adapter %s, port d_id: 0x%08x)\n",
1729 zfcp_get_busid_by_adapter(adapter), d_id);
1730 goto failed_send;
1731 }
1732
1733 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1734 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1735 goto out;
1736
1737 failed_send:
1738 zfcp_fsf_req_free(fsf_req);
1739
1740 failed_req:
1741 out:
1742 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1743 lock_flags);
1744
1745 return ret;
1746}
1747
1748/**
1749 * zfcp_fsf_send_els_handler - handler for ELS commands
1750 * @fsf_req: pointer to struct zfcp_fsf_req
1751 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001752 * Data specific for the ELS command is passed using
1753 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1754 * Usually a specific handler for the ELS command is called which is
1755 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 */
1757static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1758{
1759 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001761 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 struct fsf_qtcb_header *header;
1763 struct fsf_qtcb_bottom_support *bottom;
1764 struct zfcp_send_els *send_els;
1765 int retval = -EINVAL;
1766 u16 subtable, rule, counter;
1767
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001768 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001770 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 d_id = send_els->d_id;
1772 header = &fsf_req->qtcb->header;
1773 bottom = &fsf_req->qtcb->bottom.support;
1774
1775 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1776 goto skip_fsfstatus;
1777
1778 switch (header->fsf_status) {
1779
1780 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001781 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 retval = 0;
1783 break;
1784
1785 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001786 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1787 "class %d.\n",
1788 zfcp_get_busid_by_adapter(adapter),
1789 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 /* stop operation for this adapter */
1791 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1792 zfcp_erp_adapter_shutdown(adapter, 0);
1793 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1794 break;
1795
1796 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 switch (header->fsf_status_qual.word[0]){
1798 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001800 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1801 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1803 break;
1804 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1806 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1807 retval =
1808 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1809 (struct zfcp_ls_rjt_par *)
1810 &header->fsf_status_qual.word[2]);
1811 break;
1812 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1814 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1815 break;
1816 default:
1817 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1818 header->fsf_status_qual.word[0]);
1819 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1820 (char*)header->fsf_status_qual.word, 16);
1821 }
1822 break;
1823
1824 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1826 "prohibited sending "
1827 "(adapter: %s, port d_id: 0x%08x)\n",
1828 zfcp_get_busid_by_adapter(adapter), d_id);
1829
1830 break;
1831
1832 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 ZFCP_LOG_INFO(
1834 "ELS request size and ELS response size must be either "
1835 "both 0, or both greater than 0 "
1836 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1837 zfcp_get_busid_by_adapter(adapter),
1838 bottom->req_buf_length,
1839 bottom->resp_buf_length);
1840 break;
1841
1842 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 ZFCP_LOG_INFO(
1844 "Length of the ELS request buffer, "
1845 "specified in QTCB bottom, "
1846 "exceeds the size of the buffers "
1847 "that have been allocated for ELS request data "
1848 "(adapter: %s, req_buf_length=%d)\n",
1849 zfcp_get_busid_by_adapter(adapter),
1850 bottom->req_buf_length);
1851 break;
1852
1853 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 ZFCP_LOG_INFO(
1855 "Length of the ELS response buffer, "
1856 "specified in QTCB bottom, "
1857 "exceeds the size of the buffers "
1858 "that have been allocated for ELS response data "
1859 "(adapter: %s, resp_buf_length=%d)\n",
1860 zfcp_get_busid_by_adapter(adapter),
1861 bottom->resp_buf_length);
1862 break;
1863
1864 case FSF_SBAL_MISMATCH:
1865 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1867 "resp_buf_length=%d)\n",
1868 zfcp_get_busid_by_adapter(adapter),
1869 bottom->req_buf_length, bottom->resp_buf_length);
1870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1871 break;
1872
1873 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1875 "(adapter %s, port d_id=0x%08x)\n",
1876 zfcp_get_busid_by_adapter(adapter), d_id);
1877 for (counter = 0; counter < 2; counter++) {
1878 subtable = header->fsf_status_qual.halfword[counter * 2];
1879 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1880 switch (subtable) {
1881 case FSF_SQ_CFDC_SUBTABLE_OS:
1882 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1883 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1884 case FSF_SQ_CFDC_SUBTABLE_LUN:
1885 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1886 zfcp_act_subtable_type[subtable], rule);
1887 break;
1888 }
1889 }
1890 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 if (port != NULL)
1892 zfcp_erp_port_access_denied(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1894 break;
1895
1896 default:
1897 ZFCP_LOG_NORMAL(
1898 "bug: An unknown FSF Status was presented "
1899 "(adapter: %s, fsf_status=0x%08x)\n",
1900 zfcp_get_busid_by_adapter(adapter),
1901 header->fsf_status);
1902 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1903 debug_exception(adapter->erp_dbf, 0,
1904 &header->fsf_status_qual.word[0], sizeof(u32));
1905 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1906 break;
1907 }
1908
1909skip_fsfstatus:
1910 send_els->status = retval;
1911
1912 if (send_els->handler != 0)
1913 send_els->handler(send_els->handler_data);
1914
1915 return retval;
1916}
1917
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918int
1919zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1920{
1921 volatile struct qdio_buffer_element *sbale;
1922 unsigned long lock_flags;
1923 int retval = 0;
1924
1925 /* setup new FSF request */
1926 retval = zfcp_fsf_req_create(erp_action->adapter,
1927 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1928 ZFCP_REQ_AUTO_CLEANUP,
1929 erp_action->adapter->pool.fsf_req_erp,
1930 &lock_flags, &(erp_action->fsf_req));
1931 if (retval < 0) {
1932 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1933 "data request for adapter %s.\n",
1934 zfcp_get_busid_by_adapter(erp_action->adapter));
1935 goto out;
1936 }
1937
1938 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1939 erp_action->fsf_req->sbal_curr, 0);
1940 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1941 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1942
1943 erp_action->fsf_req->erp_action = erp_action;
1944 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001945 FSF_FEATURE_CFDC |
1946 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001947 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001948 FSF_FEATURE_UPDATE_ALERT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
1950 /* start QDIO request for this FSF request */
1951 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1952 if (retval) {
1953 ZFCP_LOG_INFO
1954 ("error: Could not send exchange configuration data "
1955 "command on the adapter %s\n",
1956 zfcp_get_busid_by_adapter(erp_action->adapter));
1957 zfcp_fsf_req_free(erp_action->fsf_req);
1958 erp_action->fsf_req = NULL;
1959 goto out;
1960 }
1961
1962 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1963 "(adapter %s)\n",
1964 zfcp_get_busid_by_adapter(erp_action->adapter));
1965
1966 out:
1967 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
1968 lock_flags);
1969 return retval;
1970}
1971
1972/**
1973 * zfcp_fsf_exchange_config_evaluate
1974 * @fsf_req: fsf_req which belongs to xchg config data request
1975 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1976 *
1977 * returns: -EIO on error, 0 otherwise
1978 */
1979static int
1980zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1981{
1982 struct fsf_qtcb_bottom_config *bottom;
1983 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001984 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
1986 bottom = &fsf_req->qtcb->bottom.config;
1987 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1988 bottom->low_qtcb_version, bottom->high_qtcb_version);
1989 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001990 adapter->adapter_features = bottom->adapter_features;
1991 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05001992 adapter->peer_wwpn = 0;
1993 adapter->peer_wwnn = 0;
1994 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 if (xchg_ok) {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001997 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
1998 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
1999 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2000 fc_host_speed(shost) = bottom->fc_link_speed;
2001 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002003 if (fc_host_permanent_port_name(shost) == -1)
2004 fc_host_permanent_port_name(shost) =
2005 fc_host_port_name(shost);
2006 if (bottom->fc_topology == FSF_TOPO_P2P) {
2007 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2008 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2009 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2010 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2011 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2012 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2013 else if (bottom->fc_topology == FSF_TOPO_AL)
2014 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2015 else
2016 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002018 fc_host_node_name(shost) = 0;
2019 fc_host_port_name(shost) = 0;
2020 fc_host_port_id(shost) = 0;
2021 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002022 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 adapter->hydra_version = 0;
2024 }
2025
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002026 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002028 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2029 min(FC_SERIAL_NUMBER_SIZE, 17));
2030 EBCASC(fc_host_serial_number(shost),
2031 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 }
2033
6f71d9b2005-04-10 23:04:28 -05002034 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002035 "WWNN 0x%016Lx, "
2036 "WWPN 0x%016Lx, "
2037 "S_ID 0x%08x,\n"
2038 "adapter version 0x%x, "
2039 "LIC version 0x%x, "
2040 "FC link speed %d Gb/s\n",
2041 zfcp_get_busid_by_adapter(adapter),
2042 (wwn_t) fc_host_node_name(shost),
2043 (wwn_t) fc_host_port_name(shost),
2044 fc_host_port_id(shost),
2045 adapter->hydra_version,
2046 adapter->fsf_lic_version,
2047 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2049 ZFCP_LOG_NORMAL("error: the adapter %s "
2050 "only supports newer control block "
2051 "versions in comparison to this device "
2052 "driver (try updated device driver)\n",
2053 zfcp_get_busid_by_adapter(adapter));
2054 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2055 zfcp_erp_adapter_shutdown(adapter, 0);
2056 return -EIO;
2057 }
2058 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2059 ZFCP_LOG_NORMAL("error: the adapter %s "
2060 "only supports older control block "
2061 "versions than this device driver uses"
2062 "(consider a microcode upgrade)\n",
2063 zfcp_get_busid_by_adapter(adapter));
2064 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2065 zfcp_erp_adapter_shutdown(adapter, 0);
2066 return -EIO;
2067 }
2068 return 0;
2069}
2070
2071/*
2072 * function: zfcp_fsf_exchange_config_data_handler
2073 *
2074 * purpose: is called for finished Exchange Configuration Data command
2075 *
2076 * returns:
2077 */
2078static int
2079zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2080{
2081 struct fsf_qtcb_bottom_config *bottom;
2082 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002083 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2086 return -EIO;
2087
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002088 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2092 return -EIO;
2093
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002094 switch (fc_host_port_type(adapter->scsi_host)) {
2095 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002096 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2097 "configuration detected at adapter %s\n"
2098 "Peer WWNN 0x%016llx, "
2099 "peer WWPN 0x%016llx, "
2100 "peer d_id 0x%06x\n",
2101 zfcp_get_busid_by_adapter(adapter),
2102 adapter->peer_wwnn,
2103 adapter->peer_wwpn,
2104 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2106 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002107 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002108 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2110 "topology detected at adapter %s "
2111 "unsupported, shutting down adapter\n",
2112 zfcp_get_busid_by_adapter(adapter));
2113 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2114 "top-al");
2115 zfcp_erp_adapter_shutdown(adapter, 0);
2116 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002117 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002118 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 "network detected at adapter %s.\n",
2120 zfcp_get_busid_by_adapter(adapter));
2121 break;
2122 default:
2123 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2124 "reported by the exchange "
2125 "configuration command for "
2126 "the adapter %s is not "
2127 "of a type known to the zfcp "
2128 "driver, shutting down adapter\n",
2129 zfcp_get_busid_by_adapter(adapter));
2130 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2131 "unknown-topo");
2132 zfcp_erp_adapter_shutdown(adapter, 0);
2133 return -EIO;
2134 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002135 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2137 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2138 "allowed by the adapter %s "
2139 "is lower than the minimum "
2140 "required by the driver (%ld bytes).\n",
2141 bottom->max_qtcb_size,
2142 zfcp_get_busid_by_adapter(adapter),
2143 sizeof(struct fsf_qtcb));
2144 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2145 "qtcb-size");
2146 debug_event(fsf_req->adapter->erp_dbf, 0,
2147 &bottom->max_qtcb_size, sizeof (u32));
2148 zfcp_erp_adapter_shutdown(adapter, 0);
2149 return -EIO;
2150 }
2151 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2152 &adapter->status);
2153 break;
2154 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2155 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2156
2157 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2158 return -EIO;
2159
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002160 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2161
2162 zfcp_fsf_link_down_info_eval(adapter,
2163 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 break;
2165 default:
2166 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2167 debug_event(fsf_req->adapter->erp_dbf, 0,
2168 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2169 zfcp_erp_adapter_shutdown(adapter, 0);
2170 return -EIO;
2171 }
2172 return 0;
2173}
2174
2175/**
2176 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002177 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 * @adapter: for which port data is requested
2179 * @data: response to exchange port data request
2180 */
2181int
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002182zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2183 struct zfcp_adapter *adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct fsf_qtcb_bottom_port *data)
2185{
2186 volatile struct qdio_buffer_element *sbale;
2187 int retval = 0;
2188 unsigned long lock_flags;
2189 struct zfcp_fsf_req *fsf_req;
2190 struct timer_list *timer;
2191
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002192 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 ZFCP_LOG_INFO("error: exchange port data "
2194 "command not supported by adapter %s\n",
2195 zfcp_get_busid_by_adapter(adapter));
2196 return -EOPNOTSUPP;
2197 }
2198
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 /* setup new FSF request */
2200 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Andreas Herrmann2448c452005-12-01 02:50:36 +01002201 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2202 0, &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 if (retval < 0) {
2204 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2205 "exchange port data request for"
2206 "the adapter %s.\n",
2207 zfcp_get_busid_by_adapter(adapter));
2208 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2209 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002210 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002211 }
2212
2213 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002214 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002215
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
Andreas Herrmann2448c452005-12-01 02:50:36 +01002220 if (erp_action) {
2221 erp_action->fsf_req = fsf_req;
2222 fsf_req->erp_action = erp_action;
2223 timer = &erp_action->timer;
2224 } else {
2225 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
2226 if (!timer) {
2227 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2228 lock_flags);
2229 zfcp_fsf_req_free(fsf_req);
2230 return -ENOMEM;
2231 }
2232 init_timer(timer);
2233 timer->function = zfcp_fsf_request_timeout_handler;
2234 timer->data = (unsigned long) adapter;
2235 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
2238 retval = zfcp_fsf_req_send(fsf_req, timer);
2239 if (retval) {
2240 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2241 "command on the adapter %s\n",
2242 zfcp_get_busid_by_adapter(adapter));
2243 zfcp_fsf_req_free(fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002244 if (erp_action)
2245 erp_action->fsf_req = NULL;
Andreas Herrmann2448c452005-12-01 02:50:36 +01002246 else
2247 kfree(timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2249 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002250 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 }
2252
Andreas Herrmann2448c452005-12-01 02:50:36 +01002253 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Andreas Herrmann2448c452005-12-01 02:50:36 +01002255 if (!erp_action) {
2256 wait_event(fsf_req->completion_wq,
2257 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2258 del_timer_sync(timer);
2259 zfcp_fsf_req_free(fsf_req);
2260 kfree(timer);
2261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return retval;
2263}
2264
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002265/**
2266 * zfcp_fsf_exchange_port_evaluate
2267 * @fsf_req: fsf_req which belongs to xchg port data request
2268 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2269 */
2270static void
2271zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2272{
2273 struct zfcp_adapter *adapter;
2274 struct fsf_qtcb *qtcb;
2275 struct fsf_qtcb_bottom_port *bottom, *data;
2276 struct Scsi_Host *shost;
2277
2278 adapter = fsf_req->adapter;
2279 qtcb = fsf_req->qtcb;
2280 bottom = &qtcb->bottom.port;
2281 shost = adapter->scsi_host;
2282
2283 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2284 if (data)
2285 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2286
2287 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2288 fc_host_permanent_port_name(shost) = bottom->wwpn;
2289 else
2290 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2291 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2292 fc_host_supported_speeds(shost) = bottom->supported_speed;
2293}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295/**
2296 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2297 * @fsf_req: pointer to struct zfcp_fsf_req
2298 */
2299static void
2300zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2301{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002302 struct zfcp_adapter *adapter;
2303 struct fsf_qtcb *qtcb;
2304
2305 adapter = fsf_req->adapter;
2306 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2309 return;
2310
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002311 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002313 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002314 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002315 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002316 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002317 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002318 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002319 zfcp_fsf_link_down_info_eval(adapter,
2320 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002323 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2324 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2326 }
2327}
2328
2329
2330/*
2331 * function: zfcp_fsf_open_port
2332 *
2333 * purpose:
2334 *
2335 * returns: address of initiated FSF request
2336 * NULL - request could not be initiated
2337 */
2338int
2339zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2340{
2341 volatile struct qdio_buffer_element *sbale;
2342 unsigned long lock_flags;
2343 int retval = 0;
2344
2345 /* setup new FSF request */
2346 retval = zfcp_fsf_req_create(erp_action->adapter,
2347 FSF_QTCB_OPEN_PORT_WITH_DID,
2348 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2349 erp_action->adapter->pool.fsf_req_erp,
2350 &lock_flags, &(erp_action->fsf_req));
2351 if (retval < 0) {
2352 ZFCP_LOG_INFO("error: Could not create open port request "
2353 "for port 0x%016Lx on adapter %s.\n",
2354 erp_action->port->wwpn,
2355 zfcp_get_busid_by_adapter(erp_action->adapter));
2356 goto out;
2357 }
2358
2359 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2360 erp_action->fsf_req->sbal_curr, 0);
2361 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2362 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2363
2364 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2365 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002366 erp_action->fsf_req->data = (unsigned long) erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 erp_action->fsf_req->erp_action = erp_action;
2368
2369 /* start QDIO request for this FSF request */
2370 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2371 if (retval) {
2372 ZFCP_LOG_INFO("error: Could not send open port request for "
2373 "port 0x%016Lx on adapter %s.\n",
2374 erp_action->port->wwpn,
2375 zfcp_get_busid_by_adapter(erp_action->adapter));
2376 zfcp_fsf_req_free(erp_action->fsf_req);
2377 erp_action->fsf_req = NULL;
2378 goto out;
2379 }
2380
2381 ZFCP_LOG_DEBUG("open port request initiated "
2382 "(adapter %s, port 0x%016Lx)\n",
2383 zfcp_get_busid_by_adapter(erp_action->adapter),
2384 erp_action->port->wwpn);
2385 out:
2386 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2387 lock_flags);
2388 return retval;
2389}
2390
2391/*
2392 * function: zfcp_fsf_open_port_handler
2393 *
2394 * purpose: is called for finished Open Port command
2395 *
2396 * returns:
2397 */
2398static int
2399zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2400{
2401 int retval = -EINVAL;
2402 struct zfcp_port *port;
2403 struct fsf_plogi *plogi;
2404 struct fsf_qtcb_header *header;
2405 u16 subtable, rule, counter;
2406
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002407 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 header = &fsf_req->qtcb->header;
2409
2410 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2411 /* don't change port status in our bookkeeping */
2412 goto skip_fsfstatus;
2413 }
2414
2415 /* evaluate FSF status in QTCB */
2416 switch (header->fsf_status) {
2417
2418 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2420 "is already open.\n",
2421 port->wwpn, zfcp_get_busid_by_port(port));
2422 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2423 "fsf_s_popen");
2424 /*
2425 * This is a bug, however operation should continue normally
2426 * if it is simply ignored
2427 */
2428 break;
2429
2430 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2432 "on adapter %s\n",
2433 port->wwpn, zfcp_get_busid_by_port(port));
2434 for (counter = 0; counter < 2; counter++) {
2435 subtable = header->fsf_status_qual.halfword[counter * 2];
2436 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2437 switch (subtable) {
2438 case FSF_SQ_CFDC_SUBTABLE_OS:
2439 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2440 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2441 case FSF_SQ_CFDC_SUBTABLE_LUN:
2442 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2443 zfcp_act_subtable_type[subtable], rule);
2444 break;
2445 }
2446 }
2447 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2448 zfcp_erp_port_access_denied(port);
2449 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2450 break;
2451
2452 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2454 "The remote port 0x%016Lx on adapter %s "
2455 "could not be opened. Disabling it.\n",
2456 port->wwpn, zfcp_get_busid_by_port(port));
2457 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2458 "fsf_s_max_ports");
2459 zfcp_erp_port_failed(port);
2460 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2461 break;
2462
2463 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 switch (header->fsf_status_qual.word[0]) {
2465 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2467 "fsf_sq_ltest");
2468 /* ERP strategy will escalate */
2469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2470 break;
2471 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2472 /* ERP strategy will escalate */
2473 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2474 "fsf_sq_ulp");
2475 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2476 break;
2477 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2479 "adapter %s could not be opened. "
2480 "Disabling it.\n",
2481 port->wwpn,
2482 zfcp_get_busid_by_port(port));
2483 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2484 "fsf_sq_no_retry");
2485 zfcp_erp_port_failed(port);
2486 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2487 break;
2488 default:
2489 ZFCP_LOG_NORMAL
2490 ("bug: Wrong status qualifier 0x%x arrived.\n",
2491 header->fsf_status_qual.word[0]);
2492 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2493 "fsf_sq_inval:");
2494 debug_exception(
2495 fsf_req->adapter->erp_dbf, 0,
2496 &header->fsf_status_qual.word[0],
2497 sizeof (u32));
2498 break;
2499 }
2500 break;
2501
2502 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 /* save port handle assigned by FSF */
2504 port->handle = header->port_handle;
2505 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2506 "was opened, it's port handle is 0x%x\n",
2507 port->wwpn, zfcp_get_busid_by_port(port),
2508 port->handle);
2509 /* mark port as open */
2510 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2511 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002512 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2513 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2514 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 retval = 0;
2516 /* check whether D_ID has changed during open */
2517 /*
2518 * FIXME: This check is not airtight, as the FCP channel does
2519 * not monitor closures of target port connections caused on
2520 * the remote side. Thus, they might miss out on invalidating
2521 * locally cached WWPNs (and other N_Port parameters) of gone
2522 * target ports. So, our heroic attempt to make things safe
2523 * could be undermined by 'open port' response data tagged with
2524 * obsolete WWPNs. Another reason to monitor potential
2525 * connection closures ourself at least (by interpreting
2526 * incoming ELS' and unsolicited status). It just crosses my
2527 * mind that one should be able to cross-check by means of
2528 * another GID_PN straight after a port has been opened.
2529 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2530 */
2531 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2532 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2533 {
2534 if (fsf_req->qtcb->bottom.support.els1_length <
2535 ((((unsigned long) &plogi->serv_param.wwpn) -
2536 ((unsigned long) plogi)) + sizeof (u64))) {
2537 ZFCP_LOG_INFO(
2538 "warning: insufficient length of "
2539 "PLOGI payload (%i)\n",
2540 fsf_req->qtcb->bottom.support.els1_length);
2541 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2542 "fsf_s_short_plogi:");
2543 /* skip sanity check and assume wwpn is ok */
2544 } else {
2545 if (plogi->serv_param.wwpn != port->wwpn) {
2546 ZFCP_LOG_INFO("warning: d_id of port "
2547 "0x%016Lx changed during "
2548 "open\n", port->wwpn);
2549 debug_text_event(
2550 fsf_req->adapter->erp_dbf, 0,
2551 "fsf_s_did_change:");
2552 atomic_clear_mask(
2553 ZFCP_STATUS_PORT_DID_DID,
2554 &port->status);
2555 } else
2556 port->wwnn = plogi->serv_param.wwnn;
2557 }
2558 }
2559 break;
2560
2561 case FSF_UNKNOWN_OP_SUBTYPE:
2562 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2564 "op_subtype=0x%x)\n",
2565 zfcp_get_busid_by_port(port),
2566 fsf_req->qtcb->bottom.support.operation_subtype);
2567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2568 break;
2569
2570 default:
2571 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2572 "(debug info 0x%x)\n",
2573 header->fsf_status);
2574 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2575 debug_exception(fsf_req->adapter->erp_dbf, 0,
2576 &header->fsf_status, sizeof (u32));
2577 break;
2578 }
2579
2580 skip_fsfstatus:
2581 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2582 return retval;
2583}
2584
2585/*
2586 * function: zfcp_fsf_close_port
2587 *
2588 * purpose: submit FSF command "close port"
2589 *
2590 * returns: address of initiated FSF request
2591 * NULL - request could not be initiated
2592 */
2593int
2594zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2595{
2596 volatile struct qdio_buffer_element *sbale;
2597 unsigned long lock_flags;
2598 int retval = 0;
2599
2600 /* setup new FSF request */
2601 retval = zfcp_fsf_req_create(erp_action->adapter,
2602 FSF_QTCB_CLOSE_PORT,
2603 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2604 erp_action->adapter->pool.fsf_req_erp,
2605 &lock_flags, &(erp_action->fsf_req));
2606 if (retval < 0) {
2607 ZFCP_LOG_INFO("error: Could not create a close port request "
2608 "for port 0x%016Lx on adapter %s.\n",
2609 erp_action->port->wwpn,
2610 zfcp_get_busid_by_adapter(erp_action->adapter));
2611 goto out;
2612 }
2613
2614 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2615 erp_action->fsf_req->sbal_curr, 0);
2616 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2617 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2618
2619 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002620 erp_action->fsf_req->data = (unsigned long) erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 erp_action->fsf_req->erp_action = erp_action;
2622 erp_action->fsf_req->qtcb->header.port_handle =
2623 erp_action->port->handle;
2624
2625 /* start QDIO request for this FSF request */
2626 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2627 if (retval) {
2628 ZFCP_LOG_INFO("error: Could not send a close port request for "
2629 "port 0x%016Lx on adapter %s.\n",
2630 erp_action->port->wwpn,
2631 zfcp_get_busid_by_adapter(erp_action->adapter));
2632 zfcp_fsf_req_free(erp_action->fsf_req);
2633 erp_action->fsf_req = NULL;
2634 goto out;
2635 }
2636
2637 ZFCP_LOG_TRACE("close port request initiated "
2638 "(adapter %s, port 0x%016Lx)\n",
2639 zfcp_get_busid_by_adapter(erp_action->adapter),
2640 erp_action->port->wwpn);
2641 out:
2642 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2643 lock_flags);
2644 return retval;
2645}
2646
2647/*
2648 * function: zfcp_fsf_close_port_handler
2649 *
2650 * purpose: is called for finished Close Port FSF command
2651 *
2652 * returns:
2653 */
2654static int
2655zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2656{
2657 int retval = -EINVAL;
2658 struct zfcp_port *port;
2659
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002660 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
2662 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2663 /* don't change port status in our bookkeeping */
2664 goto skip_fsfstatus;
2665 }
2666
2667 /* evaluate FSF status in QTCB */
2668 switch (fsf_req->qtcb->header.fsf_status) {
2669
2670 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2672 "0x%016Lx on adapter %s invalid. This may happen "
2673 "occasionally.\n", port->handle,
2674 port->wwpn, zfcp_get_busid_by_port(port));
2675 ZFCP_LOG_DEBUG("status qualifier:\n");
2676 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2677 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2678 sizeof (union fsf_status_qual));
2679 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2680 "fsf_s_phand_nv");
2681 zfcp_erp_adapter_reopen(port->adapter, 0);
2682 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2683 break;
2684
2685 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 /* Note: FSF has actually closed the port in this case.
2687 * The status code is just daft. Fingers crossed for a change
2688 */
2689 retval = 0;
2690 break;
2691
2692 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2694 "port handle 0x%x\n", port->wwpn,
2695 zfcp_get_busid_by_port(port), port->handle);
2696 zfcp_erp_modify_port_status(port,
2697 ZFCP_STATUS_COMMON_OPEN,
2698 ZFCP_CLEAR);
2699 retval = 0;
2700 break;
2701
2702 default:
2703 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2704 "(debug info 0x%x)\n",
2705 fsf_req->qtcb->header.fsf_status);
2706 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2707 debug_exception(fsf_req->adapter->erp_dbf, 0,
2708 &fsf_req->qtcb->header.fsf_status,
2709 sizeof (u32));
2710 break;
2711 }
2712
2713 skip_fsfstatus:
2714 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2715 return retval;
2716}
2717
2718/*
2719 * function: zfcp_fsf_close_physical_port
2720 *
2721 * purpose: submit FSF command "close physical port"
2722 *
2723 * returns: address of initiated FSF request
2724 * NULL - request could not be initiated
2725 */
2726int
2727zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2728{
2729 int retval = 0;
2730 unsigned long lock_flags;
2731 volatile struct qdio_buffer_element *sbale;
2732
2733 /* setup new FSF request */
2734 retval = zfcp_fsf_req_create(erp_action->adapter,
2735 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2736 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2737 erp_action->adapter->pool.fsf_req_erp,
2738 &lock_flags, &erp_action->fsf_req);
2739 if (retval < 0) {
2740 ZFCP_LOG_INFO("error: Could not create close physical port "
2741 "request (adapter %s, port 0x%016Lx)\n",
2742 zfcp_get_busid_by_adapter(erp_action->adapter),
2743 erp_action->port->wwpn);
2744
2745 goto out;
2746 }
2747
2748 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2749 erp_action->fsf_req->sbal_curr, 0);
2750 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2751 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2752
2753 /* mark port as being closed */
2754 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2755 &erp_action->port->status);
2756 /* save a pointer to this port */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002757 erp_action->fsf_req->data = (unsigned long) erp_action->port;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002758 /* port to be closed */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 erp_action->fsf_req->qtcb->header.port_handle =
2760 erp_action->port->handle;
2761 erp_action->fsf_req->erp_action = erp_action;
2762
2763 /* start QDIO request for this FSF request */
2764 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2765 if (retval) {
2766 ZFCP_LOG_INFO("error: Could not send close physical port "
2767 "request (adapter %s, port 0x%016Lx)\n",
2768 zfcp_get_busid_by_adapter(erp_action->adapter),
2769 erp_action->port->wwpn);
2770 zfcp_fsf_req_free(erp_action->fsf_req);
2771 erp_action->fsf_req = NULL;
2772 goto out;
2773 }
2774
2775 ZFCP_LOG_TRACE("close physical port request initiated "
2776 "(adapter %s, port 0x%016Lx)\n",
2777 zfcp_get_busid_by_adapter(erp_action->adapter),
2778 erp_action->port->wwpn);
2779 out:
2780 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2781 lock_flags);
2782 return retval;
2783}
2784
2785/*
2786 * function: zfcp_fsf_close_physical_port_handler
2787 *
2788 * purpose: is called for finished Close Physical Port FSF command
2789 *
2790 * returns:
2791 */
2792static int
2793zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2794{
2795 int retval = -EINVAL;
2796 struct zfcp_port *port;
2797 struct zfcp_unit *unit;
2798 struct fsf_qtcb_header *header;
2799 u16 subtable, rule, counter;
2800
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002801 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 header = &fsf_req->qtcb->header;
2803
2804 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2805 /* don't change port status in our bookkeeping */
2806 goto skip_fsfstatus;
2807 }
2808
2809 /* evaluate FSF status in QTCB */
2810 switch (header->fsf_status) {
2811
2812 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2814 "(adapter %s, port 0x%016Lx). "
2815 "This may happen occasionally.\n",
2816 port->handle,
2817 zfcp_get_busid_by_port(port),
2818 port->wwpn);
2819 ZFCP_LOG_DEBUG("status qualifier:\n");
2820 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2821 (char *) &header->fsf_status_qual,
2822 sizeof (union fsf_status_qual));
2823 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2824 "fsf_s_phand_nv");
2825 zfcp_erp_adapter_reopen(port->adapter, 0);
2826 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2827 break;
2828
2829 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 ZFCP_LOG_NORMAL("Access denied, cannot close "
2831 "physical port 0x%016Lx on adapter %s\n",
2832 port->wwpn, zfcp_get_busid_by_port(port));
2833 for (counter = 0; counter < 2; counter++) {
2834 subtable = header->fsf_status_qual.halfword[counter * 2];
2835 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2836 switch (subtable) {
2837 case FSF_SQ_CFDC_SUBTABLE_OS:
2838 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2839 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2840 case FSF_SQ_CFDC_SUBTABLE_LUN:
2841 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2842 zfcp_act_subtable_type[subtable], rule);
2843 break;
2844 }
2845 }
2846 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2847 zfcp_erp_port_access_denied(port);
2848 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2849 break;
2850
2851 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2853 "%s needs to be reopened but it was attempted "
2854 "to close it physically.\n",
2855 port->wwpn,
2856 zfcp_get_busid_by_port(port));
2857 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02002858 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2860 ZFCP_STATUS_FSFREQ_RETRY;
2861 break;
2862
2863 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 switch (header->fsf_status_qual.word[0]) {
2865 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2867 "fsf_sq_ltest");
2868 /* This will now be escalated by ERP */
2869 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2870 break;
2871 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 /* ERP strategy will escalate */
2873 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2874 "fsf_sq_ulp");
2875 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2876 break;
2877 default:
2878 ZFCP_LOG_NORMAL
2879 ("bug: Wrong status qualifier 0x%x arrived.\n",
2880 header->fsf_status_qual.word[0]);
2881 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2882 "fsf_sq_inval:");
2883 debug_exception(
2884 fsf_req->adapter->erp_dbf, 0,
2885 &header->fsf_status_qual.word[0], sizeof (u32));
2886 break;
2887 }
2888 break;
2889
2890 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2892 "physically closed, port handle 0x%x\n",
2893 port->wwpn,
2894 zfcp_get_busid_by_port(port), port->handle);
2895 /* can't use generic zfcp_erp_modify_port_status because
2896 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2897 */
2898 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2899 list_for_each_entry(unit, &port->unit_list_head, list)
2900 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2901 retval = 0;
2902 break;
2903
2904 default:
2905 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2906 "(debug info 0x%x)\n",
2907 header->fsf_status);
2908 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2909 debug_exception(fsf_req->adapter->erp_dbf, 0,
2910 &header->fsf_status, sizeof (u32));
2911 break;
2912 }
2913
2914 skip_fsfstatus:
2915 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2916 return retval;
2917}
2918
2919/*
2920 * function: zfcp_fsf_open_unit
2921 *
2922 * purpose:
2923 *
2924 * returns:
2925 *
2926 * assumptions: This routine does not check whether the associated
2927 * remote port has already been opened. This should be
2928 * done by calling routines. Otherwise some status
2929 * may be presented by FSF
2930 */
2931int
2932zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2933{
2934 volatile struct qdio_buffer_element *sbale;
2935 unsigned long lock_flags;
2936 int retval = 0;
2937
2938 /* setup new FSF request */
2939 retval = zfcp_fsf_req_create(erp_action->adapter,
2940 FSF_QTCB_OPEN_LUN,
2941 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2942 erp_action->adapter->pool.fsf_req_erp,
2943 &lock_flags, &(erp_action->fsf_req));
2944 if (retval < 0) {
2945 ZFCP_LOG_INFO("error: Could not create open unit request for "
2946 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2947 erp_action->unit->fcp_lun,
2948 erp_action->unit->port->wwpn,
2949 zfcp_get_busid_by_adapter(erp_action->adapter));
2950 goto out;
2951 }
2952
2953 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2954 erp_action->fsf_req->sbal_curr, 0);
2955 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2956 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2957
2958 erp_action->fsf_req->qtcb->header.port_handle =
2959 erp_action->port->handle;
2960 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2961 erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002962 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann06506d02006-05-22 18:18:19 +02002963 erp_action->fsf_req->qtcb->bottom.support.option =
2964 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002966 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 erp_action->fsf_req->erp_action = erp_action;
2968
2969 /* start QDIO request for this FSF request */
2970 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2971 if (retval) {
2972 ZFCP_LOG_INFO("error: Could not send an open unit request "
2973 "on the adapter %s, port 0x%016Lx for "
2974 "unit 0x%016Lx\n",
2975 zfcp_get_busid_by_adapter(erp_action->adapter),
2976 erp_action->port->wwpn,
2977 erp_action->unit->fcp_lun);
2978 zfcp_fsf_req_free(erp_action->fsf_req);
2979 erp_action->fsf_req = NULL;
2980 goto out;
2981 }
2982
2983 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2984 "port 0x%016Lx, unit 0x%016Lx)\n",
2985 zfcp_get_busid_by_adapter(erp_action->adapter),
2986 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2987 out:
2988 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2989 lock_flags);
2990 return retval;
2991}
2992
2993/*
2994 * function: zfcp_fsf_open_unit_handler
2995 *
2996 * purpose: is called for finished Open LUN command
2997 *
2998 * returns:
2999 */
3000static int
3001zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3002{
3003 int retval = -EINVAL;
3004 struct zfcp_adapter *adapter;
3005 struct zfcp_unit *unit;
3006 struct fsf_qtcb_header *header;
3007 struct fsf_qtcb_bottom_support *bottom;
3008 struct fsf_queue_designator *queue_designator;
3009 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003010 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003012 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
3014 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3015 /* don't change unit status in our bookkeeping */
3016 goto skip_fsfstatus;
3017 }
3018
3019 adapter = fsf_req->adapter;
3020 header = &fsf_req->qtcb->header;
3021 bottom = &fsf_req->qtcb->bottom.support;
3022 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3023
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3025 ZFCP_STATUS_UNIT_SHARED |
3026 ZFCP_STATUS_UNIT_READONLY,
3027 &unit->status);
3028
3029 /* evaluate FSF status in QTCB */
3030 switch (header->fsf_status) {
3031
3032 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3034 "for port 0x%016Lx on adapter %s invalid "
3035 "This may happen occasionally\n",
3036 unit->port->handle,
3037 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3038 ZFCP_LOG_DEBUG("status qualifier:\n");
3039 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3040 (char *) &header->fsf_status_qual,
3041 sizeof (union fsf_status_qual));
3042 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3043 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3044 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3045 break;
3046
3047 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3049 "remote port 0x%016Lx on adapter %s twice.\n",
3050 unit->fcp_lun,
3051 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3052 debug_text_exception(adapter->erp_dbf, 0,
3053 "fsf_s_uopen");
3054 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3055 break;
3056
3057 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3059 "remote port 0x%016Lx on adapter %s\n",
3060 unit->fcp_lun, unit->port->wwpn,
3061 zfcp_get_busid_by_unit(unit));
3062 for (counter = 0; counter < 2; counter++) {
3063 subtable = header->fsf_status_qual.halfword[counter * 2];
3064 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3065 switch (subtable) {
3066 case FSF_SQ_CFDC_SUBTABLE_OS:
3067 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3068 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3069 case FSF_SQ_CFDC_SUBTABLE_LUN:
3070 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3071 zfcp_act_subtable_type[subtable], rule);
3072 break;
3073 }
3074 }
3075 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3076 zfcp_erp_unit_access_denied(unit);
3077 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3078 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3079 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3080 break;
3081
3082 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3084 "needs to be reopened\n",
3085 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3086 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003087 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3089 ZFCP_STATUS_FSFREQ_RETRY;
3090 break;
3091
3092 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 if (header->fsf_status_qual.word[0] != 0) {
3094 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3095 "with WWPN 0x%Lx "
3096 "connected to the adapter %s "
3097 "is already in use in LPAR%d, CSS%d\n",
3098 unit->fcp_lun,
3099 unit->port->wwpn,
3100 zfcp_get_busid_by_unit(unit),
3101 queue_designator->hla,
3102 queue_designator->cssid);
3103 } else {
3104 subtable = header->fsf_status_qual.halfword[4];
3105 rule = header->fsf_status_qual.halfword[5];
3106 switch (subtable) {
3107 case FSF_SQ_CFDC_SUBTABLE_OS:
3108 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3109 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3110 case FSF_SQ_CFDC_SUBTABLE_LUN:
3111 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3112 "remote port with WWPN 0x%Lx "
3113 "connected to the adapter %s "
3114 "is denied (%s rule %d)\n",
3115 unit->fcp_lun,
3116 unit->port->wwpn,
3117 zfcp_get_busid_by_unit(unit),
3118 zfcp_act_subtable_type[subtable],
3119 rule);
3120 break;
3121 }
3122 }
3123 ZFCP_LOG_DEBUG("status qualifier:\n");
3124 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3125 (char *) &header->fsf_status_qual,
3126 sizeof (union fsf_status_qual));
3127 debug_text_event(adapter->erp_dbf, 2,
3128 "fsf_s_l_sh_vio");
3129 zfcp_erp_unit_access_denied(unit);
3130 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3131 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3132 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3133 break;
3134
3135 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3137 "There is no handle (temporary port identifier) "
3138 "available for unit 0x%016Lx on port 0x%016Lx "
3139 "on adapter %s\n",
3140 unit->fcp_lun,
3141 unit->port->wwpn,
3142 zfcp_get_busid_by_unit(unit));
3143 debug_text_event(adapter->erp_dbf, 1,
3144 "fsf_s_max_units");
3145 zfcp_erp_unit_failed(unit);
3146 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3147 break;
3148
3149 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 switch (header->fsf_status_qual.word[0]) {
3151 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 /* Re-establish link to port */
3153 debug_text_event(adapter->erp_dbf, 1,
3154 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003155 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3157 break;
3158 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 /* ERP strategy will escalate */
3160 debug_text_event(adapter->erp_dbf, 1,
3161 "fsf_sq_ulp");
3162 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3163 break;
3164 default:
3165 ZFCP_LOG_NORMAL
3166 ("bug: Wrong status qualifier 0x%x arrived.\n",
3167 header->fsf_status_qual.word[0]);
3168 debug_text_event(adapter->erp_dbf, 0,
3169 "fsf_sq_inval:");
3170 debug_exception(adapter->erp_dbf, 0,
3171 &header->fsf_status_qual.word[0],
3172 sizeof (u32));
3173 }
3174 break;
3175
3176 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 ZFCP_LOG_NORMAL(
3178 "Invalid option 0x%x has been specified "
3179 "in QTCB bottom sent to the adapter %s\n",
3180 bottom->option,
3181 zfcp_get_busid_by_adapter(adapter));
3182 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3183 retval = -EINVAL;
3184 break;
3185
3186 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 /* save LUN handle assigned by FSF */
3188 unit->handle = header->lun_handle;
3189 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3190 "adapter %s opened, port handle 0x%x\n",
3191 unit->fcp_lun,
3192 unit->port->wwpn,
3193 zfcp_get_busid_by_unit(unit),
3194 unit->handle);
3195 /* mark unit as open */
3196 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003197
3198 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3199 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3200 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3201 exclusive = (bottom->lun_access_info &
3202 FSF_UNIT_ACCESS_EXCLUSIVE);
3203 readwrite = (bottom->lun_access_info &
3204 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3205
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 if (!exclusive)
3207 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3208 &unit->status);
3209
3210 if (!readwrite) {
3211 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3212 &unit->status);
3213 ZFCP_LOG_NORMAL("read-only access for unit "
3214 "(adapter %s, wwpn=0x%016Lx, "
3215 "fcp_lun=0x%016Lx)\n",
3216 zfcp_get_busid_by_unit(unit),
3217 unit->port->wwpn,
3218 unit->fcp_lun);
3219 }
3220
3221 if (exclusive && !readwrite) {
3222 ZFCP_LOG_NORMAL("exclusive access of read-only "
3223 "unit not supported\n");
3224 zfcp_erp_unit_failed(unit);
3225 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3226 zfcp_erp_unit_shutdown(unit, 0);
3227 } else if (!exclusive && readwrite) {
3228 ZFCP_LOG_NORMAL("shared access of read-write "
3229 "unit not supported\n");
3230 zfcp_erp_unit_failed(unit);
3231 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3232 zfcp_erp_unit_shutdown(unit, 0);
3233 }
3234 }
3235
3236 retval = 0;
3237 break;
3238
3239 default:
3240 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3241 "(debug info 0x%x)\n",
3242 header->fsf_status);
3243 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3244 debug_exception(adapter->erp_dbf, 0,
3245 &header->fsf_status, sizeof (u32));
3246 break;
3247 }
3248
3249 skip_fsfstatus:
3250 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3251 return retval;
3252}
3253
3254/*
3255 * function: zfcp_fsf_close_unit
3256 *
3257 * purpose:
3258 *
3259 * returns: address of fsf_req - request successfully initiated
3260 * NULL -
3261 *
3262 * assumptions: This routine does not check whether the associated
3263 * remote port/lun has already been opened. This should be
3264 * done by calling routines. Otherwise some status
3265 * may be presented by FSF
3266 */
3267int
3268zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3269{
3270 volatile struct qdio_buffer_element *sbale;
3271 unsigned long lock_flags;
3272 int retval = 0;
3273
3274 /* setup new FSF request */
3275 retval = zfcp_fsf_req_create(erp_action->adapter,
3276 FSF_QTCB_CLOSE_LUN,
3277 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3278 erp_action->adapter->pool.fsf_req_erp,
3279 &lock_flags, &(erp_action->fsf_req));
3280 if (retval < 0) {
3281 ZFCP_LOG_INFO("error: Could not create close unit request for "
3282 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3283 erp_action->unit->fcp_lun,
3284 erp_action->port->wwpn,
3285 zfcp_get_busid_by_adapter(erp_action->adapter));
3286 goto out;
3287 }
3288
3289 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3290 erp_action->fsf_req->sbal_curr, 0);
3291 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3292 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3293
3294 erp_action->fsf_req->qtcb->header.port_handle =
3295 erp_action->port->handle;
3296 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3297 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003298 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 erp_action->fsf_req->erp_action = erp_action;
3300
3301 /* start QDIO request for this FSF request */
3302 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3303 if (retval) {
3304 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3305 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3306 erp_action->unit->fcp_lun,
3307 erp_action->port->wwpn,
3308 zfcp_get_busid_by_adapter(erp_action->adapter));
3309 zfcp_fsf_req_free(erp_action->fsf_req);
3310 erp_action->fsf_req = NULL;
3311 goto out;
3312 }
3313
3314 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3315 "port 0x%016Lx, unit 0x%016Lx)\n",
3316 zfcp_get_busid_by_adapter(erp_action->adapter),
3317 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3318 out:
3319 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3320 lock_flags);
3321 return retval;
3322}
3323
3324/*
3325 * function: zfcp_fsf_close_unit_handler
3326 *
3327 * purpose: is called for finished Close LUN FSF command
3328 *
3329 * returns:
3330 */
3331static int
3332zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3333{
3334 int retval = -EINVAL;
3335 struct zfcp_unit *unit;
3336
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003337 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338
3339 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3340 /* don't change unit status in our bookkeeping */
3341 goto skip_fsfstatus;
3342 }
3343
3344 /* evaluate FSF status in QTCB */
3345 switch (fsf_req->qtcb->header.fsf_status) {
3346
3347 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3349 "0x%016Lx on adapter %s invalid. This may "
3350 "happen in rare circumstances\n",
3351 unit->port->handle,
3352 unit->port->wwpn,
3353 zfcp_get_busid_by_unit(unit));
3354 ZFCP_LOG_DEBUG("status qualifier:\n");
3355 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3356 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3357 sizeof (union fsf_status_qual));
3358 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3359 "fsf_s_phand_nv");
3360 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3362 break;
3363
3364 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3366 "0x%016Lx on port 0x%016Lx on adapter %s is "
3367 "invalid. This may happen occasionally.\n",
3368 unit->handle,
3369 unit->fcp_lun,
3370 unit->port->wwpn,
3371 zfcp_get_busid_by_unit(unit));
3372 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3373 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3374 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3375 sizeof (union fsf_status_qual));
3376 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3377 "fsf_s_lhand_nv");
3378 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3380 break;
3381
3382 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3384 "needs to be reopened\n",
3385 unit->port->wwpn,
3386 zfcp_get_busid_by_unit(unit));
3387 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003388 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3390 ZFCP_STATUS_FSFREQ_RETRY;
3391 break;
3392
3393 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3395 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 /* re-establish link to port */
3397 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3398 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003399 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3401 break;
3402 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 /* ERP strategy will escalate */
3404 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3405 "fsf_sq_ulp");
3406 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3407 break;
3408 default:
3409 ZFCP_LOG_NORMAL
3410 ("bug: Wrong status qualifier 0x%x arrived.\n",
3411 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3412 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3413 "fsf_sq_inval:");
3414 debug_exception(
3415 fsf_req->adapter->erp_dbf, 0,
3416 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3417 sizeof (u32));
3418 break;
3419 }
3420 break;
3421
3422 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3424 "closed, port handle 0x%x\n",
3425 unit->fcp_lun,
3426 unit->port->wwpn,
3427 zfcp_get_busid_by_unit(unit),
3428 unit->handle);
3429 /* mark unit as closed */
3430 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3431 retval = 0;
3432 break;
3433
3434 default:
3435 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3436 "(debug info 0x%x)\n",
3437 fsf_req->qtcb->header.fsf_status);
3438 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3439 debug_exception(fsf_req->adapter->erp_dbf, 0,
3440 &fsf_req->qtcb->header.fsf_status,
3441 sizeof (u32));
3442 break;
3443 }
3444
3445 skip_fsfstatus:
3446 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3447 return retval;
3448}
3449
3450/**
3451 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3452 * @adapter: adapter where scsi command is issued
3453 * @unit: unit where command is sent to
3454 * @scsi_cmnd: scsi command to be sent
3455 * @timer: timer to be started when request is initiated
3456 * @req_flags: flags for fsf_request
3457 */
3458int
3459zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3460 struct zfcp_unit *unit,
3461 struct scsi_cmnd * scsi_cmnd,
3462 struct timer_list *timer, int req_flags)
3463{
3464 struct zfcp_fsf_req *fsf_req = NULL;
3465 struct fcp_cmnd_iu *fcp_cmnd_iu;
3466 unsigned int sbtype;
3467 unsigned long lock_flags;
3468 int real_bytes = 0;
3469 int retval = 0;
3470 int mask;
3471
3472 /* setup new FSF request */
3473 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3474 adapter->pool.fsf_req_scsi,
3475 &lock_flags, &fsf_req);
3476 if (unlikely(retval < 0)) {
3477 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3478 "for unit 0x%016Lx on port 0x%016Lx on "
3479 "adapter %s\n",
3480 unit->fcp_lun,
3481 unit->port->wwpn,
3482 zfcp_get_busid_by_adapter(adapter));
3483 goto failed_req_create;
3484 }
3485
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003486 zfcp_unit_get(unit);
3487 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003489 /* associate FSF request with SCSI request (for look up on abort) */
3490 scsi_cmnd->host_scribble = (char *) fsf_req;
3491
3492 /* associate SCSI command with FSF request */
3493 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494
3495 /* set handles of unit and its parent port in QTCB */
3496 fsf_req->qtcb->header.lun_handle = unit->handle;
3497 fsf_req->qtcb->header.port_handle = unit->port->handle;
3498
3499 /* FSF does not define the structure of the FCP_CMND IU */
3500 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3501 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3502
3503 /*
3504 * set depending on data direction:
3505 * data direction bits in SBALE (SB Type)
3506 * data direction bits in QTCB
3507 * data direction bits in FCP_CMND IU
3508 */
3509 switch (scsi_cmnd->sc_data_direction) {
3510 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3512 /*
3513 * FIXME(qdio):
3514 * what is the correct type for commands
3515 * without 'real' data buffers?
3516 */
3517 sbtype = SBAL_FLAGS0_TYPE_READ;
3518 break;
3519 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3521 sbtype = SBAL_FLAGS0_TYPE_READ;
3522 fcp_cmnd_iu->rddata = 1;
3523 break;
3524 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3526 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3527 fcp_cmnd_iu->wddata = 1;
3528 break;
3529 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 default:
3531 /*
3532 * dummy, catch this condition earlier
3533 * in zfcp_scsi_queuecommand
3534 */
3535 goto failed_scsi_cmnd;
3536 }
3537
3538 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003539 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
3541 /* set FCP_LUN in FCP_CMND IU in QTCB */
3542 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3543
3544 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3545
3546 /* set task attributes in FCP_CMND IU in QTCB */
3547 if (likely((scsi_cmnd->device->simple_tags) ||
3548 (atomic_test_mask(mask, &unit->status))))
3549 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3550 else
3551 fcp_cmnd_iu->task_attribute = UNTAGGED;
3552
3553 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3554 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3555 fcp_cmnd_iu->add_fcp_cdb_length
3556 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3557 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3558 "additional FCP_CDB length is 0x%x "
3559 "(shifted right 2 bits)\n",
3560 scsi_cmnd->cmd_len,
3561 fcp_cmnd_iu->add_fcp_cdb_length);
3562 }
3563 /*
3564 * copy SCSI CDB (including additional length, if any) to
3565 * FCP_CDB in FCP_CMND IU in QTCB
3566 */
3567 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3568
3569 /* FCP CMND IU length in QTCB */
3570 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3571 sizeof (struct fcp_cmnd_iu) +
3572 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3573
3574 /* generate SBALEs from data buffer */
3575 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3576 if (unlikely(real_bytes < 0)) {
3577 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3578 ZFCP_LOG_DEBUG(
3579 "Data did not fit into available buffer(s), "
3580 "waiting for more...\n");
3581 retval = -EIO;
3582 } else {
3583 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3584 "required. Shutting down unit "
3585 "(adapter %s, port 0x%016Lx, "
3586 "unit 0x%016Lx)\n",
3587 zfcp_get_busid_by_unit(unit),
3588 unit->port->wwpn,
3589 unit->fcp_lun);
3590 zfcp_erp_unit_shutdown(unit, 0);
3591 retval = -EINVAL;
3592 }
3593 goto no_fit;
3594 }
3595
3596 /* set length of FCP data length in FCP_CMND IU in QTCB */
3597 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3598
3599 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3600 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3601 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3602
3603 /*
3604 * start QDIO request for this FSF request
3605 * covered by an SBALE)
3606 */
3607 retval = zfcp_fsf_req_send(fsf_req, timer);
3608 if (unlikely(retval < 0)) {
3609 ZFCP_LOG_INFO("error: Could not send FCP command request "
3610 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3611 zfcp_get_busid_by_adapter(adapter),
3612 unit->port->wwpn,
3613 unit->fcp_lun);
3614 goto send_failed;
3615 }
3616
3617 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3618 "port 0x%016Lx, unit 0x%016Lx)\n",
3619 zfcp_get_busid_by_adapter(adapter),
3620 unit->port->wwpn,
3621 unit->fcp_lun);
3622 goto success;
3623
3624 send_failed:
3625 no_fit:
3626 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003627 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 zfcp_fsf_req_free(fsf_req);
3629 fsf_req = NULL;
3630 scsi_cmnd->host_scribble = NULL;
3631 success:
3632 failed_req_create:
3633 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3634 return retval;
3635}
3636
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637struct zfcp_fsf_req *
3638zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3639 struct zfcp_unit *unit,
3640 u8 tm_flags, int req_flags)
3641{
3642 struct zfcp_fsf_req *fsf_req = NULL;
3643 int retval = 0;
3644 struct fcp_cmnd_iu *fcp_cmnd_iu;
3645 unsigned long lock_flags;
3646 volatile struct qdio_buffer_element *sbale;
3647
3648 /* setup new FSF request */
3649 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3650 adapter->pool.fsf_req_scsi,
3651 &lock_flags, &fsf_req);
3652 if (retval < 0) {
3653 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3654 "management) request for adapter %s, port "
3655 " 0x%016Lx, unit 0x%016Lx.\n",
3656 zfcp_get_busid_by_adapter(adapter),
3657 unit->port->wwpn, unit->fcp_lun);
3658 goto out;
3659 }
3660
3661 /*
3662 * Used to decide on proper handler in the return path,
3663 * could be either zfcp_fsf_send_fcp_command_task_handler or
3664 * zfcp_fsf_send_fcp_command_task_management_handler */
3665
3666 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3667
3668 /*
3669 * hold a pointer to the unit being target of this
3670 * task management request
3671 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003672 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
3674 /* set FSF related fields in QTCB */
3675 fsf_req->qtcb->header.lun_handle = unit->handle;
3676 fsf_req->qtcb->header.port_handle = unit->port->handle;
3677 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003678 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3680 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3681
3682 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3683 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3684 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3685
3686 /* set FCP related fields in FCP_CMND IU in QTCB */
3687 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3688 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3689 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3690 fcp_cmnd_iu->task_management_flags = tm_flags;
3691
3692 /* start QDIO request for this FSF request */
3693 zfcp_fsf_start_scsi_er_timer(adapter);
3694 retval = zfcp_fsf_req_send(fsf_req, NULL);
3695 if (retval) {
3696 del_timer(&adapter->scsi_er_timer);
3697 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3698 "management) on adapter %s, port 0x%016Lx for "
3699 "unit LUN 0x%016Lx\n",
3700 zfcp_get_busid_by_adapter(adapter),
3701 unit->port->wwpn,
3702 unit->fcp_lun);
3703 zfcp_fsf_req_free(fsf_req);
3704 fsf_req = NULL;
3705 goto out;
3706 }
3707
3708 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3709 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3710 "tm_flags=0x%x)\n",
3711 zfcp_get_busid_by_adapter(adapter),
3712 unit->port->wwpn,
3713 unit->fcp_lun,
3714 tm_flags);
3715 out:
3716 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3717 return fsf_req;
3718}
3719
3720/*
3721 * function: zfcp_fsf_send_fcp_command_handler
3722 *
3723 * purpose: is called for finished Send FCP Command
3724 *
3725 * returns:
3726 */
3727static int
3728zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3729{
3730 int retval = -EINVAL;
3731 struct zfcp_unit *unit;
3732 struct fsf_qtcb_header *header;
3733 u16 subtable, rule, counter;
3734
3735 header = &fsf_req->qtcb->header;
3736
3737 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003738 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003740 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741
3742 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3743 /* go directly to calls of special handlers */
3744 goto skip_fsfstatus;
3745 }
3746
3747 /* evaluate FSF status in QTCB */
3748 switch (header->fsf_status) {
3749
3750 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3752 "0x%016Lx on adapter %s invalid\n",
3753 unit->port->handle,
3754 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3755 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
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_phand_nv");
3760 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3762 break;
3763
3764 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3766 "0x%016Lx on port 0x%016Lx on adapter %s is "
3767 "invalid. This may happen occasionally.\n",
3768 unit->handle,
3769 unit->fcp_lun,
3770 unit->port->wwpn,
3771 zfcp_get_busid_by_unit(unit));
3772 ZFCP_LOG_NORMAL("Status qualifier data:\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_uhand_nv");
3778 zfcp_erp_port_reopen(unit->port, 0);
3779 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3780 break;
3781
3782 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3784 "unexpectedly. (adapter %s, port 0x%016Lx, "
3785 "unit 0x%016Lx)\n",
3786 unit->port->handle,
3787 zfcp_get_busid_by_unit(unit),
3788 unit->port->wwpn,
3789 unit->fcp_lun);
3790 ZFCP_LOG_NORMAL("status qualifier:\n");
3791 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3792 (char *) &header->fsf_status_qual,
3793 sizeof (union fsf_status_qual));
3794 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3795 "fsf_s_hand_mis");
3796 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3798 break;
3799
3800 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003801 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3802 "class %d.\n",
3803 zfcp_get_busid_by_unit(unit),
3804 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 /* stop operation for this adapter */
3806 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3807 "fsf_s_class_nsup");
3808 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3810 break;
3811
3812 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3814 "adapter %s does not have correct unit "
3815 "handle 0x%x\n",
3816 unit->fcp_lun,
3817 unit->port->wwpn,
3818 zfcp_get_busid_by_unit(unit),
3819 unit->handle);
3820 ZFCP_LOG_DEBUG("status qualifier:\n");
3821 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3822 (char *) &header->fsf_status_qual,
3823 sizeof (union fsf_status_qual));
3824 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3825 "fsf_s_fcp_lun_nv");
3826 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3828 break;
3829
3830 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3832 "unit 0x%016Lx on port 0x%016Lx on "
3833 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3834 zfcp_get_busid_by_unit(unit));
3835 for (counter = 0; counter < 2; counter++) {
3836 subtable = header->fsf_status_qual.halfword[counter * 2];
3837 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3838 switch (subtable) {
3839 case FSF_SQ_CFDC_SUBTABLE_OS:
3840 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3841 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3842 case FSF_SQ_CFDC_SUBTABLE_LUN:
3843 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3844 zfcp_act_subtable_type[subtable], rule);
3845 break;
3846 }
3847 }
3848 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3849 zfcp_erp_unit_access_denied(unit);
3850 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3851 break;
3852
3853 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3855 "0x%016Lx on port 0x%016Lx on adapter %s "
3856 "(debug info %d)\n",
3857 unit->fcp_lun,
3858 unit->port->wwpn,
3859 zfcp_get_busid_by_unit(unit),
3860 fsf_req->qtcb->bottom.io.data_direction);
3861 /* stop operation for this adapter */
3862 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3863 "fsf_s_dir_ind_nv");
3864 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3866 break;
3867
3868 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 ZFCP_LOG_NORMAL
3870 ("bug: An invalid control-data-block length field "
3871 "was found in a command for unit 0x%016Lx on port "
3872 "0x%016Lx on adapter %s " "(debug info %d)\n",
3873 unit->fcp_lun, unit->port->wwpn,
3874 zfcp_get_busid_by_unit(unit),
3875 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3876 /* stop operation for this adapter */
3877 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3878 "fsf_s_cmd_len_nv");
3879 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3881 break;
3882
3883 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3885 "needs to be reopened\n",
3886 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3887 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003888 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3890 ZFCP_STATUS_FSFREQ_RETRY;
3891 break;
3892
3893 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3895 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3896 zfcp_get_busid_by_unit(unit),
3897 unit->port->wwpn, unit->fcp_lun);
3898 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003899 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3901 | ZFCP_STATUS_FSFREQ_RETRY;
3902 break;
3903
3904 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 switch (header->fsf_status_qual.word[0]) {
3906 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 /* re-establish link to port */
3908 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3909 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003910 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 break;
3912 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 /* FIXME(hw) need proper specs for proper action */
3914 /* let scsi stack deal with retries and escalation */
3915 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3916 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 break;
3918 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003920 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 header->fsf_status_qual.word[0]);
3922 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3923 "fsf_sq_inval:");
3924 debug_exception(fsf_req->adapter->erp_dbf, 0,
3925 &header->fsf_status_qual.word[0],
3926 sizeof(u32));
3927 break;
3928 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003929 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 break;
3931
3932 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 break;
3934
3935 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 break;
3937
3938 default:
3939 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3940 debug_exception(fsf_req->adapter->erp_dbf, 0,
3941 &header->fsf_status, sizeof(u32));
3942 break;
3943 }
3944
3945 skip_fsfstatus:
3946 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3947 retval =
3948 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3949 } else {
3950 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003951 fsf_req->unit = NULL;
3952 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 }
3954 return retval;
3955}
3956
3957/*
3958 * function: zfcp_fsf_send_fcp_command_task_handler
3959 *
3960 * purpose: evaluates FCP_RSP IU
3961 *
3962 * returns:
3963 */
3964static int
3965zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3966{
3967 int retval = 0;
3968 struct scsi_cmnd *scpnt;
3969 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3970 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3971 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3972 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3973 u32 sns_len;
3974 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3975 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003976 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
3978 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003979 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 if (unlikely(!scpnt)) {
3981 ZFCP_LOG_DEBUG
3982 ("Command with fsf_req %p is not associated to "
3983 "a scsi command anymore. Aborted?\n", fsf_req);
3984 goto out;
3985 }
3986 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3987 /* FIXME: (design) mid-layer should handle DID_ABORT like
3988 * DID_SOFT_ERROR by retrying the request for devices
3989 * that allow retries.
3990 */
3991 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3992 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3993 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3994 goto skip_fsfstatus;
3995 }
3996
3997 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3998 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3999 set_host_byte(&scpnt->result, DID_ERROR);
4000 goto skip_fsfstatus;
4001 }
4002
4003 /* set message byte of result in SCSI command */
4004 scpnt->result |= COMMAND_COMPLETE << 8;
4005
4006 /*
4007 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4008 * of result in SCSI command
4009 */
4010 scpnt->result |= fcp_rsp_iu->scsi_status;
4011 if (unlikely(fcp_rsp_iu->scsi_status)) {
4012 /* DEBUG */
4013 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4014 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4015 scpnt->cmnd, scpnt->cmd_len);
4016 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4017 fcp_rsp_iu->scsi_status);
4018 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4019 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4020 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4021 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4022 fcp_rsp_iu->fcp_sns_len);
4023 }
4024
4025 /* check FCP_RSP_INFO */
4026 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4027 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4028 switch (fcp_rsp_info[3]) {
4029 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 /* ok, continue */
4031 ZFCP_LOG_TRACE("no failure or Task Management "
4032 "Function complete\n");
4033 set_host_byte(&scpnt->result, DID_OK);
4034 break;
4035 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 /* hardware bug */
4037 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4038 "that the fibrechannel protocol data "
4039 "length differs from the burst length. "
4040 "The problem occured on unit 0x%016Lx "
4041 "on port 0x%016Lx on adapter %s",
4042 unit->fcp_lun,
4043 unit->port->wwpn,
4044 zfcp_get_busid_by_unit(unit));
4045 /* dump SCSI CDB as prepared by zfcp */
4046 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4047 (char *) &fsf_req->qtcb->
4048 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 set_host_byte(&scpnt->result, DID_ERROR);
4050 goto skip_fsfstatus;
4051 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 /* driver or hardware bug */
4053 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4054 "that the fibrechannel protocol data "
4055 "fields were incorrectly set up. "
4056 "The problem occured on the unit "
4057 "0x%016Lx on port 0x%016Lx on "
4058 "adapter %s",
4059 unit->fcp_lun,
4060 unit->port->wwpn,
4061 zfcp_get_busid_by_unit(unit));
4062 /* dump SCSI CDB as prepared by zfcp */
4063 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4064 (char *) &fsf_req->qtcb->
4065 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4066 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 goto skip_fsfstatus;
4068 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 /* hardware bug */
4070 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4071 "that conflicting values for the "
4072 "fibrechannel payload offset from the "
4073 "header were found. "
4074 "The problem occured on unit 0x%016Lx "
4075 "on port 0x%016Lx on adapter %s.\n",
4076 unit->fcp_lun,
4077 unit->port->wwpn,
4078 zfcp_get_busid_by_unit(unit));
4079 /* dump SCSI CDB as prepared by zfcp */
4080 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4081 (char *) &fsf_req->qtcb->
4082 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 set_host_byte(&scpnt->result, DID_ERROR);
4084 goto skip_fsfstatus;
4085 default:
4086 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4087 "code was detected for a command. "
4088 "The problem occured on the unit "
4089 "0x%016Lx on port 0x%016Lx on "
4090 "adapter %s (debug info 0x%x)\n",
4091 unit->fcp_lun,
4092 unit->port->wwpn,
4093 zfcp_get_busid_by_unit(unit),
4094 fcp_rsp_info[3]);
4095 /* dump SCSI CDB as prepared by zfcp */
4096 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4097 (char *) &fsf_req->qtcb->
4098 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004100 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 }
4102 }
4103
4104 /* check for sense data */
4105 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4106 sns_len = FSF_FCP_RSP_SIZE -
4107 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4108 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4109 sns_len);
4110 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4111 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4112 SCSI_SENSE_BUFFERSIZE);
4113 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4114 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4115 scpnt->result);
4116 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4117 (void *) &scpnt->cmnd, scpnt->cmd_len);
4118
4119 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4120 fcp_rsp_iu->fcp_sns_len);
4121 memcpy(&scpnt->sense_buffer,
4122 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4123 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4124 (void *) &scpnt->sense_buffer, sns_len);
4125 }
4126
4127 /* check for overrun */
4128 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4129 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4130 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4131 "The response data length is "
4132 "%d, the original length was %d.\n",
4133 unit->fcp_lun,
4134 unit->port->wwpn,
4135 zfcp_get_busid_by_unit(unit),
4136 fcp_rsp_iu->fcp_resid,
4137 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4138 }
4139
4140 /* check for underrun */
4141 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4142 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4143 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4144 "The response data length is "
4145 "%d, the original length was %d.\n",
4146 unit->fcp_lun,
4147 unit->port->wwpn,
4148 zfcp_get_busid_by_unit(unit),
4149 fcp_rsp_iu->fcp_resid,
4150 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4151
4152 scpnt->resid = fcp_rsp_iu->fcp_resid;
4153 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004154 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 }
4156
4157 skip_fsfstatus:
4158 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4159
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004160 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004161 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004162 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004163 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004164 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004165 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
4167 /* cleanup pointer (need this especially for abort) */
4168 scpnt->host_scribble = NULL;
4169
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 (scpnt->scsi_done) (scpnt);
4172
4173 /*
4174 * We must hold this lock until scsi_done has been called.
4175 * Otherwise we may call scsi_done after abort regarding this
4176 * command has completed.
4177 * Note: scsi_done must not block!
4178 */
4179 out:
4180 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4181 return retval;
4182}
4183
4184/*
4185 * function: zfcp_fsf_send_fcp_command_task_management_handler
4186 *
4187 * purpose: evaluates FCP_RSP IU
4188 *
4189 * returns:
4190 */
4191static int
4192zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4193{
4194 int retval = 0;
4195 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4196 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4197 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004198 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199
4200 del_timer(&fsf_req->adapter->scsi_er_timer);
4201 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4202 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4203 goto skip_fsfstatus;
4204 }
4205
4206 /* check FCP_RSP_INFO */
4207 switch (fcp_rsp_info[3]) {
4208 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 /* ok, continue */
4210 ZFCP_LOG_DEBUG("no failure or Task Management "
4211 "Function complete\n");
4212 break;
4213 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4215 "is not supported on the target device "
4216 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4217 unit->fcp_lun,
4218 unit->port->wwpn,
4219 zfcp_get_busid_by_unit(unit));
4220 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4221 break;
4222 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4224 "failed to complete successfully. "
4225 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4226 unit->fcp_lun,
4227 unit->port->wwpn,
4228 zfcp_get_busid_by_unit(unit));
4229 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4230 break;
4231 default:
4232 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4233 "code was detected for a command. "
4234 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4235 "(debug info 0x%x)\n",
4236 unit->fcp_lun,
4237 unit->port->wwpn,
4238 zfcp_get_busid_by_unit(unit),
4239 fcp_rsp_info[3]);
4240 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4241 }
4242
4243 skip_fsfstatus:
4244 return retval;
4245}
4246
4247
4248/*
4249 * function: zfcp_fsf_control_file
4250 *
4251 * purpose: Initiator of the control file upload/download FSF requests
4252 *
4253 * returns: 0 - FSF request is successfuly created and queued
4254 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4255 * -EINVAL - Invalid direction specified
4256 * -ENOMEM - Insufficient memory
4257 * -EPERM - Cannot create FSF request or place it in QDIO queue
4258 */
4259int
4260zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4261 struct zfcp_fsf_req **fsf_req_ptr,
4262 u32 fsf_command,
4263 u32 option,
4264 struct zfcp_sg_list *sg_list)
4265{
4266 struct zfcp_fsf_req *fsf_req;
4267 struct fsf_qtcb_bottom_support *bottom;
4268 volatile struct qdio_buffer_element *sbale;
4269 struct timer_list *timer;
4270 unsigned long lock_flags;
4271 int req_flags = 0;
4272 int direction;
4273 int retval = 0;
4274
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004275 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4277 zfcp_get_busid_by_adapter(adapter));
4278 retval = -EOPNOTSUPP;
4279 goto out;
4280 }
4281
4282 switch (fsf_command) {
4283
4284 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4285 direction = SBAL_FLAGS0_TYPE_WRITE;
4286 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4287 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4288 req_flags = ZFCP_WAIT_FOR_SBAL;
4289 break;
4290
4291 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4292 direction = SBAL_FLAGS0_TYPE_READ;
4293 break;
4294
4295 default:
4296 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4297 retval = -EINVAL;
4298 goto out;
4299 }
4300
4301 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4302 if (!timer) {
4303 retval = -ENOMEM;
4304 goto out;
4305 }
4306
4307 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4308 NULL, &lock_flags, &fsf_req);
4309 if (retval < 0) {
4310 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4311 "adapter %s\n",
4312 zfcp_get_busid_by_adapter(adapter));
4313 retval = -EPERM;
4314 goto unlock_queue_lock;
4315 }
4316
4317 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4318 sbale[0].flags |= direction;
4319
4320 bottom = &fsf_req->qtcb->bottom.support;
4321 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4322 bottom->option = option;
4323
4324 if (sg_list->count > 0) {
4325 int bytes;
4326
4327 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4328 sg_list->sg, sg_list->count,
4329 ZFCP_MAX_SBALS_PER_REQ);
4330 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4331 ZFCP_LOG_INFO(
4332 "error: Could not create sufficient number of "
4333 "SBALS for an FSF request to the adapter %s\n",
4334 zfcp_get_busid_by_adapter(adapter));
4335 retval = -ENOMEM;
4336 goto free_fsf_req;
4337 }
4338 } else
4339 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4340
4341 init_timer(timer);
4342 timer->function = zfcp_fsf_request_timeout_handler;
4343 timer->data = (unsigned long) adapter;
4344 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4345
4346 retval = zfcp_fsf_req_send(fsf_req, timer);
4347 if (retval < 0) {
4348 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4349 "(adapter %s)\n",
4350 zfcp_get_busid_by_adapter(adapter));
4351 retval = -EPERM;
4352 goto free_fsf_req;
4353 }
4354 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4355
4356 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4357 "adapter %s\n",
4358 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4359 "download" : "upload",
4360 zfcp_get_busid_by_adapter(adapter));
4361
4362 wait_event(fsf_req->completion_wq,
4363 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4364
4365 *fsf_req_ptr = fsf_req;
4366 del_timer_sync(timer);
4367 goto free_timer;
4368
4369 free_fsf_req:
4370 zfcp_fsf_req_free(fsf_req);
4371 unlock_queue_lock:
4372 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4373 free_timer:
4374 kfree(timer);
4375 out:
4376 return retval;
4377}
4378
4379
4380/*
4381 * function: zfcp_fsf_control_file_handler
4382 *
4383 * purpose: Handler of the control file upload/download FSF requests
4384 *
4385 * returns: 0 - FSF request successfuly processed
4386 * -EAGAIN - Operation has to be repeated because of a temporary problem
4387 * -EACCES - There is no permission to execute an operation
4388 * -EPERM - The control file is not in a right format
4389 * -EIO - There is a problem with the FCP adapter
4390 * -EINVAL - Invalid operation
4391 * -EFAULT - User space memory I/O operation fault
4392 */
4393static int
4394zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4395{
4396 struct zfcp_adapter *adapter = fsf_req->adapter;
4397 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4398 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4399 int retval = 0;
4400
4401 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4402 retval = -EINVAL;
4403 goto skip_fsfstatus;
4404 }
4405
4406 switch (header->fsf_status) {
4407
4408 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 ZFCP_LOG_NORMAL(
4410 "The FSF request has been successfully completed "
4411 "on the adapter %s\n",
4412 zfcp_get_busid_by_adapter(adapter));
4413 break;
4414
4415 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4417 switch (header->fsf_status_qual.word[0]) {
4418
6f71d9b2005-04-10 23:04:28 -05004419 case FSF_SQ_CFDC_HARDENED_ON_SE:
4420 ZFCP_LOG_NORMAL(
4421 "CFDC on the adapter %s has being "
4422 "hardened on primary and secondary SE\n",
4423 zfcp_get_busid_by_adapter(adapter));
4424 break;
4425
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4427 ZFCP_LOG_NORMAL(
4428 "CFDC of the adapter %s could not "
4429 "be saved on the SE\n",
4430 zfcp_get_busid_by_adapter(adapter));
4431 break;
4432
4433 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4434 ZFCP_LOG_NORMAL(
4435 "CFDC of the adapter %s could not "
4436 "be copied to the secondary SE\n",
4437 zfcp_get_busid_by_adapter(adapter));
4438 break;
4439
4440 default:
4441 ZFCP_LOG_NORMAL(
4442 "CFDC could not be hardened "
4443 "on the adapter %s\n",
4444 zfcp_get_busid_by_adapter(adapter));
4445 }
4446 }
4447 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4448 retval = -EAGAIN;
4449 break;
4450
4451 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452 ZFCP_LOG_NORMAL(
4453 "Adapter %s does not accept privileged commands\n",
4454 zfcp_get_busid_by_adapter(adapter));
4455 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4456 retval = -EACCES;
4457 break;
4458
4459 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 ZFCP_LOG_NORMAL(
4461 "Error at position %d in the CFDC, "
4462 "CFDC is discarded by the adapter %s\n",
4463 header->fsf_status_qual.word[0],
4464 zfcp_get_busid_by_adapter(adapter));
4465 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4466 retval = -EPERM;
4467 break;
4468
4469 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 ZFCP_LOG_NORMAL(
4471 "Adapter %s cannot harden the control file, "
4472 "file is discarded\n",
4473 zfcp_get_busid_by_adapter(adapter));
4474 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4475 retval = -EIO;
4476 break;
4477
4478 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 ZFCP_LOG_NORMAL(
4480 "Control file is too large, file is discarded "
4481 "by the adapter %s\n",
4482 zfcp_get_busid_by_adapter(adapter));
4483 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4484 retval = -EIO;
4485 break;
4486
4487 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4489 ZFCP_LOG_NORMAL(
4490 "CFDC has been discarded by the adapter %s, "
4491 "because activation would impact "
4492 "%d active connection(s)\n",
4493 zfcp_get_busid_by_adapter(adapter),
4494 header->fsf_status_qual.word[0]);
4495 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4496 retval = -EIO;
4497 break;
4498
4499 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4501 ZFCP_LOG_NORMAL(
4502 "CFDC has been activated on the adapter %s, "
4503 "but activation has impacted "
4504 "%d active connection(s)\n",
4505 zfcp_get_busid_by_adapter(adapter),
4506 header->fsf_status_qual.word[0]);
4507 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4508 retval = -EIO;
4509 break;
4510
4511 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4513 "op_subtype=0x%x)\n",
4514 zfcp_get_busid_by_adapter(adapter),
4515 bottom->operation_subtype);
4516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4517 retval = -EINVAL;
4518 break;
4519
4520 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 ZFCP_LOG_NORMAL(
4522 "Invalid option 0x%x has been specified "
4523 "in QTCB bottom sent to the adapter %s\n",
4524 bottom->option,
4525 zfcp_get_busid_by_adapter(adapter));
4526 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4527 retval = -EINVAL;
4528 break;
4529
4530 default:
4531 ZFCP_LOG_NORMAL(
4532 "bug: An unknown/unexpected FSF status 0x%08x "
4533 "was presented on the adapter %s\n",
4534 header->fsf_status,
4535 zfcp_get_busid_by_adapter(adapter));
4536 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4537 debug_exception(fsf_req->adapter->erp_dbf, 0,
4538 &header->fsf_status_qual.word[0], sizeof(u32));
4539 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4540 retval = -EINVAL;
4541 break;
4542 }
4543
4544skip_fsfstatus:
4545 return retval;
4546}
4547
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548static inline int
4549zfcp_fsf_req_sbal_check(unsigned long *flags,
4550 struct zfcp_qdio_queue *queue, int needed)
4551{
4552 write_lock_irqsave(&queue->queue_lock, *flags);
4553 if (likely(atomic_read(&queue->free_count) >= needed))
4554 return 1;
4555 write_unlock_irqrestore(&queue->queue_lock, *flags);
4556 return 0;
4557}
4558
4559/*
4560 * set qtcb pointer in fsf_req and initialize QTCB
4561 */
4562static inline void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004563zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564{
4565 if (likely(fsf_req->qtcb != NULL)) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004566 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4568 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004569 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4571 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004572 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 }
4574}
4575
4576/**
4577 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4578 * @adapter: adapter for which request queue is examined
4579 * @req_flags: flags indicating whether to wait for needed SBAL or not
4580 * @lock_flags: lock_flags if queue_lock is taken
4581 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4582 * Locks: lock adapter->request_queue->queue_lock on success
4583 */
4584static int
4585zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4586 unsigned long *lock_flags)
4587{
4588 long ret;
4589 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4590
4591 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4592 ret = wait_event_interruptible_timeout(adapter->request_wq,
4593 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4594 ZFCP_SBAL_TIMEOUT);
4595 if (ret < 0)
4596 return ret;
4597 if (!ret)
4598 return -EIO;
4599 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4600 return -EIO;
4601
4602 return 0;
4603}
4604
4605/*
4606 * function: zfcp_fsf_req_create
4607 *
4608 * purpose: create an FSF request at the specified adapter and
4609 * setup common fields
4610 *
4611 * returns: -ENOMEM if there was insufficient memory for a request
4612 * -EIO if no qdio buffers could be allocate to the request
4613 * -EINVAL/-EPERM on bug conditions in req_dequeue
4614 * 0 in success
4615 *
4616 * note: The created request is returned by reference.
4617 *
4618 * locks: lock of concerned request queue must not be held,
4619 * but is held on completion (write, irqsave)
4620 */
4621int
4622zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4623 mempool_t *pool, unsigned long *lock_flags,
4624 struct zfcp_fsf_req **fsf_req_p)
4625{
4626 volatile struct qdio_buffer_element *sbale;
4627 struct zfcp_fsf_req *fsf_req = NULL;
4628 int ret = 0;
4629 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4630
4631 /* allocate new FSF request */
4632 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4633 if (unlikely(NULL == fsf_req)) {
4634 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4635 "the outbound (send) queue.\n");
4636 ret = -ENOMEM;
4637 goto failed_fsf_req;
4638 }
4639
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004640 fsf_req->adapter = adapter;
4641 fsf_req->fsf_command = fsf_cmd;
4642
4643 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644
4645 /* initialize waitqueue which may be used to wait on
4646 this request completion */
4647 init_waitqueue_head(&fsf_req->completion_wq);
4648
4649 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4650 if(ret < 0) {
4651 goto failed_sbals;
4652 }
4653
4654 /*
4655 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4656 * if it is not set (see also *_open_qdio and *_close_qdio).
4657 */
4658
4659 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4660 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4661 ret = -EIO;
4662 goto failed_sbals;
4663 }
4664
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004665 if (fsf_req->qtcb) {
4666 fsf_req->seq_no = adapter->fsf_req_seq_no;
4667 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 fsf_req->sbal_number = 1;
4670 fsf_req->sbal_first = req_queue->free_index;
4671 fsf_req->sbal_curr = req_queue->free_index;
4672 fsf_req->sbale_curr = 1;
4673
4674 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4675 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4676 }
4677
4678 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4679
4680 /* setup common SBALE fields */
4681 sbale[0].addr = fsf_req;
4682 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4683 if (likely(fsf_req->qtcb != NULL)) {
4684 sbale[1].addr = (void *) fsf_req->qtcb;
4685 sbale[1].length = sizeof(struct fsf_qtcb);
4686 }
4687
4688 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4689 fsf_req->sbal_number, fsf_req->sbal_first);
4690
4691 goto success;
4692
4693 failed_sbals:
4694/* dequeue new FSF request previously enqueued */
4695 zfcp_fsf_req_free(fsf_req);
4696 fsf_req = NULL;
4697
4698 failed_fsf_req:
4699 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4700 success:
4701 *fsf_req_p = fsf_req;
4702 return ret;
4703}
4704
4705/*
4706 * function: zfcp_fsf_req_send
4707 *
4708 * purpose: start transfer of FSF request via QDIO
4709 *
4710 * returns: 0 - request transfer succesfully started
4711 * !0 - start of request transfer failed
4712 */
4713static int
4714zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4715{
4716 struct zfcp_adapter *adapter;
4717 struct zfcp_qdio_queue *req_queue;
4718 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004719 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 int new_distance_from_int;
4721 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 int retval = 0;
4723
4724 adapter = fsf_req->adapter;
4725 req_queue = &adapter->request_queue,
4726
4727
4728 /* FIXME(debug): remove it later */
4729 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4730 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4731 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4732 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4733 sbale[1].length);
4734
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 /* put allocated FSF request at list tail */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004736 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004738 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004740 inc_seq_no = (fsf_req->qtcb != NULL);
4741
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 /* figure out expiration time of timeout and start timeout */
4743 if (unlikely(timer)) {
4744 timer->expires += jiffies;
4745 add_timer(timer);
4746 }
4747
4748 ZFCP_LOG_TRACE("request queue of adapter %s: "
4749 "next free SBAL is %i, %i free SBALs\n",
4750 zfcp_get_busid_by_adapter(adapter),
4751 req_queue->free_index,
4752 atomic_read(&req_queue->free_count));
4753
4754 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4755 "index_in_queue=%i, count=%i, buffers=%p\n",
4756 zfcp_get_busid_by_adapter(adapter),
4757 QDIO_FLAG_SYNC_OUTPUT,
4758 0, fsf_req->sbal_first, fsf_req->sbal_number,
4759 &req_queue->buffer[fsf_req->sbal_first]);
4760
4761 /*
4762 * adjust the number of free SBALs in request queue as well as
4763 * position of first one
4764 */
4765 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4766 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4767 req_queue->free_index += fsf_req->sbal_number; /* increase */
4768 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4769 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4770
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004771 fsf_req->issued = get_clock();
4772
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 retval = do_QDIO(adapter->ccw_device,
4774 QDIO_FLAG_SYNC_OUTPUT,
4775 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4776
4777 if (unlikely(retval)) {
4778 /* Queues are down..... */
4779 retval = -EIO;
4780 /*
4781 * FIXME(potential race):
4782 * timer might be expired (absolutely unlikely)
4783 */
4784 if (timer)
4785 del_timer(timer);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004786 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 list_del(&fsf_req->list);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02004788 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 /*
4790 * adjust the number of free SBALs in request queue as well as
4791 * position of first one
4792 */
4793 zfcp_qdio_zero_sbals(req_queue->buffer,
4794 fsf_req->sbal_first, fsf_req->sbal_number);
4795 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4796 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4797 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4798 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4799 ZFCP_LOG_DEBUG
4800 ("error: do_QDIO failed. Buffers could not be enqueued "
4801 "to request queue.\n");
4802 } else {
4803 req_queue->distance_from_int = new_distance_from_int;
4804 /*
4805 * increase FSF sequence counter -
4806 * this must only be done for request successfully enqueued to
4807 * QDIO this rejected requests may be cleaned up by calling
4808 * routines resulting in missing sequence counter values
4809 * otherwise,
4810 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004811
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004813 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004815
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 /* count FSF requests pending */
4817 atomic_inc(&adapter->fsf_reqs_active);
4818 }
4819 return retval;
4820}
4821
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822#undef ZFCP_LOG_AREA