blob: 908e8b2107c1cb1b8adcb2a5ec874b305d68869b [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);
Andreas Herrmann2abbe862006-09-18 22:29:56 +020045static int zfcp_fsf_req_send(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static 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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/* association between FSF command and FSF QTCB type */
54static u32 fsf_qtcb_type[] = {
55 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
56 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
62 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
65 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
66 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
67 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
68};
69
70static const char zfcp_act_subtable_type[5][8] = {
71 "unknown", "OS", "WWPN", "DID", "LUN"
72};
73
74/****************************************************************/
75/*************** FSF related Functions *************************/
76/****************************************************************/
77
78#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
79
80/*
81 * function: zfcp_fsf_req_alloc
82 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +020083 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 * unsolicited requests) via helper functions
85 * Does some initial fsf request set-up.
Swen Schillig41fa2ad2007-09-07 09:15:31 +020086 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 * returns: pointer to allocated fsf_req if successfull
88 * NULL otherwise
89 *
90 * locks: none
91 *
92 */
93static struct zfcp_fsf_req *
94zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
95{
96 size_t size;
97 void *ptr;
98 struct zfcp_fsf_req *fsf_req = NULL;
99
100 if (req_flags & ZFCP_REQ_NO_QTCB)
101 size = sizeof(struct zfcp_fsf_req);
102 else
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200103 size = sizeof(struct zfcp_fsf_req_qtcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200105 if (likely(pool))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 ptr = mempool_alloc(pool, GFP_ATOMIC);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200107 else {
108 if (req_flags & ZFCP_REQ_NO_QTCB)
109 ptr = kmalloc(size, GFP_ATOMIC);
110 else
111 ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
Christoph Lameter54e6ecb2006-12-06 20:33:16 -0800112 GFP_ATOMIC);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200115 if (unlikely(!ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 goto out;
117
118 memset(ptr, 0, size);
119
120 if (req_flags & ZFCP_REQ_NO_QTCB) {
121 fsf_req = (struct zfcp_fsf_req *) ptr;
122 } else {
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200123 fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
124 fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126
127 fsf_req->pool = pool;
128
129 out:
130 return fsf_req;
131}
132
133/*
134 * function: zfcp_fsf_req_free
135 *
136 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
137 * returns it into the pool via helper functions.
138 *
139 * returns: sod all
140 *
141 * locks: none
142 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200143void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
145{
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200146 if (likely(fsf_req->pool)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 mempool_free(fsf_req, fsf_req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200148 return;
149 }
150
151 if (fsf_req->qtcb) {
152 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
153 return;
154 }
155
156 kfree(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
Martin Peschke869b2b42007-05-09 11:01:20 +0200159/*
160 * Never ever call this without shutting down the adapter first.
161 * Otherwise the adapter would continue using and corrupting s390 storage.
162 * Included BUG_ON() call to ensure this is done.
163 * ERP is supposed to be the only user of this function.
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200164 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100165void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200166{
Martin Peschke869b2b42007-05-09 11:01:20 +0200167 struct zfcp_fsf_req *fsf_req, *tmp;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200168 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100169 LIST_HEAD(remove_queue);
Martin Peschke869b2b42007-05-09 11:01:20 +0200170 unsigned int i;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200171
Martin Peschke869b2b42007-05-09 11:01:20 +0200172 BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status));
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200173 spin_lock_irqsave(&adapter->req_list_lock, flags);
174 atomic_set(&adapter->reqs_active, 0);
Martin Peschke869b2b42007-05-09 11:01:20 +0200175 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100176 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200177 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
178
Martin Peschke869b2b42007-05-09 11:01:20 +0200179 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
180 list_del(&fsf_req->list);
181 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
182 zfcp_fsf_req_complete(fsf_req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100183 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200184}
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/*
187 * function: zfcp_fsf_req_complete
188 *
189 * purpose: Updates active counts and timers for openfcp-reqs
190 * May cleanup request after req_eval returns
191 *
192 * returns: 0 - success
193 * !0 - failure
194 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200195 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 */
197int
198zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
199{
200 int retval = 0;
201 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
204 ZFCP_LOG_DEBUG("Status read response received\n");
205 /*
206 * Note: all cleanup handling is done in the callchain of
207 * the function call-chain below.
208 */
209 zfcp_fsf_status_read_handler(fsf_req);
210 goto out;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200211 } else {
212 del_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 zfcp_fsf_protstatus_eval(fsf_req);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200217 * fsf_req may be deleted due to waking up functions, so
218 * cleanup is saved here and used later
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 */
220 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
221 cleanup = 1;
222 else
223 cleanup = 0;
224
225 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
226
227 /* cleanup request if requested by initiator */
228 if (likely(cleanup)) {
229 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
230 /*
231 * lock must not be held here since it will be
232 * grabed by the called routine, too
233 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200234 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 } else {
236 /* notify initiator waiting for the requests completion */
237 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
238 /*
239 * FIXME: Race! We must not access fsf_req here as it might have been
240 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
241 * flag. It's an improbable case. But, we have the same paranoia for
242 * the cleanup flag already.
243 * Might better be handled using complete()?
244 * (setting the flag and doing wakeup ought to be atomic
245 * with regard to checking the flag as long as waitqueue is
246 * part of the to be released structure)
247 */
248 wake_up(&fsf_req->completion_wq);
249 }
250
251 out:
252 return retval;
253}
254
255/*
256 * function: zfcp_fsf_protstatus_eval
257 *
258 * purpose: evaluates the QTCB of the finished FSF request
259 * and initiates appropriate actions
260 * (usually calling FSF command specific handlers)
261 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200262 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200264 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 *
266 * locks:
267 */
268static int
269zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
270{
271 int retval = 0;
272 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200273 struct fsf_qtcb *qtcb = fsf_req->qtcb;
274 union fsf_prot_status_qual *prot_status_qual =
275 &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200277 zfcp_hba_dbf_event_fsf_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
280 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
281 (unsigned long) fsf_req);
282 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
283 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 goto skip_protstatus;
285 }
286
287 /* log additional information provided by FSF (if any) */
Heiko Carstens862794f2007-02-21 09:28:00 +0100288 if (likely(qtcb->header.log_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* do not trust them ;-) */
Heiko Carstens862794f2007-02-21 09:28:00 +0100290 if (unlikely(qtcb->header.log_start >
291 sizeof(struct fsf_qtcb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 ZFCP_LOG_NORMAL
293 ("bug: ULP (FSF logging) log data starts "
294 "beyond end of packet header. Ignored. "
295 "(start=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200296 qtcb->header.log_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 sizeof(struct fsf_qtcb));
298 goto forget_log;
299 }
Heiko Carstens862794f2007-02-21 09:28:00 +0100300 if (unlikely((size_t) (qtcb->header.log_start +
301 qtcb->header.log_length) >
302 sizeof(struct fsf_qtcb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
304 "beyond end of packet header. Ignored. "
305 "(start=%i, length=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200306 qtcb->header.log_start,
307 qtcb->header.log_length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 sizeof(struct fsf_qtcb));
309 goto forget_log;
310 }
311 ZFCP_LOG_TRACE("ULP log data: \n");
312 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200313 (char *) qtcb + qtcb->header.log_start,
314 qtcb->header.log_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316 forget_log:
317
318 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200319 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 break;
324
325 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 ZFCP_LOG_NORMAL("error: The adapter %s contains "
327 "microcode of version 0x%x, the device driver "
328 "only supports 0x%x. Aborting.\n",
329 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200330 prot_status_qual->version_error.fsf_version,
331 ZFCP_QTCB_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
334 break;
335
336 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
338 "driver (0x%x) and adapter %s (0x%x). "
339 "Restarting all operations on this adapter.\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200340 qtcb->prefix.req_seq_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200342 prot_status_qual->sequence_error.exp_req_seq_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
345 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
346 break;
347
348 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 ZFCP_LOG_NORMAL("error: Packet header type used by the "
350 "device driver is incompatible with "
351 "that used on adapter %s. "
352 "Stopping all operations on this adapter.\n",
353 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
356 break;
357
358 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
360 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
361 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 break;
363
364 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
366 "to the adapter %s is ambiguous. "
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200367 "Stopping all operations on this adapter.\n",
368 *(unsigned long long*)
369 (&qtcb->bottom.support.req_handle),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
373 break;
374
375 case FSF_PROT_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200376 zfcp_fsf_link_down_info_eval(adapter,
377 &prot_status_qual->link_down_info);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100378 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
380 break;
381
382 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200383 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 "%s was re-plugged. "
385 "Re-starting operations on this adapter.\n",
386 zfcp_get_busid_by_adapter(adapter));
387 /* All ports should be marked as ready to run again */
388 zfcp_erp_modify_adapter_status(adapter,
389 ZFCP_STATUS_COMMON_RUNNING,
390 ZFCP_SET);
391 zfcp_erp_adapter_reopen(adapter,
392 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
393 | ZFCP_STATUS_COMMON_ERP_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
395 break;
396
397 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 ZFCP_LOG_NORMAL("error: The adapter %s "
399 "has entered the error state. "
400 "Restarting all operations on this "
401 "adapter.\n",
402 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
405 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
406 break;
407
408 default:
409 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
410 "provided by the adapter %s "
411 "is not compatible with the device driver. "
412 "Stopping all operations on this adapter. "
413 "(debug info 0x%x).\n",
414 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200415 qtcb->prefix.prot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 zfcp_erp_adapter_shutdown(adapter, 0);
417 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
418 }
419
420 skip_protstatus:
421 /*
422 * always call specific handlers to give them a chance to do
423 * something meaningful even in error cases
424 */
425 zfcp_fsf_fsfstatus_eval(fsf_req);
426 return retval;
427}
428
429/*
430 * function: zfcp_fsf_fsfstatus_eval
431 *
432 * purpose: evaluates FSF status of completed FSF request
433 * and acts accordingly
434 *
435 * returns:
436 */
437static int
438zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
439{
440 int retval = 0;
441
442 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
443 goto skip_fsfstatus;
444 }
445
446 /* evaluate FSF Status */
447 switch (fsf_req->qtcb->header.fsf_status) {
448 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
450 "not known by the adapter %s "
451 "Stopping all operations on this adapter. "
452 "(debug info 0x%x).\n",
453 zfcp_get_busid_by_adapter(fsf_req->adapter),
454 fsf_req->qtcb->header.fsf_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
457 break;
458
459 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
461 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 break;
463
464 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
466 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
469 skip_fsfstatus:
470 /*
471 * always call specific handlers to give them a chance to do
472 * something meaningful even in error cases
473 */
474 zfcp_fsf_req_dispatch(fsf_req);
475
476 return retval;
477}
478
479/*
480 * function: zfcp_fsf_fsfstatus_qual_eval
481 *
482 * purpose: evaluates FSF status-qualifier of completed FSF request
483 * and acts accordingly
484 *
485 * returns:
486 */
487static int
488zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
489{
490 int retval = 0;
491
492 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
493 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 break;
495 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
498 break;
499 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
503 break;
504 case FSF_SQ_NO_RECOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
506 "problem on the adapter %s "
507 "Stopping all operations on this adapter. ",
508 zfcp_get_busid_by_adapter(fsf_req->adapter));
509 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
511 break;
512 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
514 "(adapter %s)\n",
515 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
517 break;
518 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
519 case FSF_SQ_NO_RETRY_POSSIBLE:
520 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
521 /* dealt with in the respective functions */
522 break;
523 default:
524 ZFCP_LOG_NORMAL("bug: Additional status info could "
525 "not be interpreted properly.\n");
526 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
527 (char *) &fsf_req->qtcb->header.fsf_status_qual,
528 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
530 break;
531 }
532
533 return retval;
534}
535
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200536/**
537 * zfcp_fsf_link_down_info_eval - evaluate link down information block
538 */
539static void
540zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
541 struct fsf_link_down_info *link_down)
542{
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100543 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
544 &adapter->status))
545 return;
546
547 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
548
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100549 if (link_down == NULL)
550 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100551
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200552 switch (link_down->error_code) {
553 case FSF_PSQ_LINK_NO_LIGHT:
554 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
555 "(no light detected)\n",
556 zfcp_get_busid_by_adapter(adapter));
557 break;
558 case FSF_PSQ_LINK_WRAP_PLUG:
559 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
560 "(wrap plug detected)\n",
561 zfcp_get_busid_by_adapter(adapter));
562 break;
563 case FSF_PSQ_LINK_NO_FCP:
564 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
565 "(adjacent node on link does not support FCP)\n",
566 zfcp_get_busid_by_adapter(adapter));
567 break;
568 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
569 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
570 "(firmware update in progress)\n",
571 zfcp_get_busid_by_adapter(adapter));
572 break;
573 case FSF_PSQ_LINK_INVALID_WWPN:
574 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
575 "(duplicate or invalid WWPN detected)\n",
576 zfcp_get_busid_by_adapter(adapter));
577 break;
578 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
579 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
580 "(no support for NPIV by Fabric)\n",
581 zfcp_get_busid_by_adapter(adapter));
582 break;
583 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(out of resource in FCP daughtercard)\n",
586 zfcp_get_busid_by_adapter(adapter));
587 break;
588 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
589 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
590 "(out of resource in Fabric)\n",
591 zfcp_get_busid_by_adapter(adapter));
592 break;
593 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
594 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
595 "(unable to Fabric login)\n",
596 zfcp_get_busid_by_adapter(adapter));
597 break;
598 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
599 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
600 zfcp_get_busid_by_adapter(adapter));
601 break;
602 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
603 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
604 zfcp_get_busid_by_adapter(adapter));
605 break;
606 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
607 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
608 zfcp_get_busid_by_adapter(adapter));
609 break;
610 default:
611 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
612 "(warning: unknown reason code %d)\n",
613 zfcp_get_busid_by_adapter(adapter),
614 link_down->error_code);
615 }
616
617 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
618 ZFCP_LOG_DEBUG("Debug information to link down: "
619 "primary_status=0x%02x "
620 "ioerr_code=0x%02x "
621 "action_code=0x%02x "
622 "reason_code=0x%02x "
623 "explanation_code=0x%02x "
624 "vendor_specific_code=0x%02x\n",
625 link_down->primary_status,
626 link_down->ioerr_code,
627 link_down->action_code,
628 link_down->reason_code,
629 link_down->explanation_code,
630 link_down->vendor_specific_code);
631
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100632 out:
633 zfcp_erp_adapter_failed(adapter);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634}
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636/*
637 * function: zfcp_fsf_req_dispatch
638 *
639 * purpose: calls the appropriate command specific handler
640 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200641 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 */
643static int
644zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
645{
646 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
647 struct zfcp_adapter *adapter = fsf_req->adapter;
648 int retval = 0;
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 switch (fsf_req->fsf_command) {
652
653 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 zfcp_fsf_send_fcp_command_handler(fsf_req);
655 break;
656
657 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 zfcp_fsf_abort_fcp_command_handler(fsf_req);
659 break;
660
661 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 zfcp_fsf_send_ct_handler(fsf_req);
663 break;
664
665 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 zfcp_fsf_open_port_handler(fsf_req);
667 break;
668
669 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 zfcp_fsf_open_unit_handler(fsf_req);
671 break;
672
673 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 zfcp_fsf_close_unit_handler(fsf_req);
675 break;
676
677 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 zfcp_fsf_close_port_handler(fsf_req);
679 break;
680
681 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 zfcp_fsf_close_physical_port_handler(fsf_req);
683 break;
684
685 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 zfcp_fsf_exchange_config_data_handler(fsf_req);
687 break;
688
689 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 zfcp_fsf_exchange_port_data_handler(fsf_req);
691 break;
692
693 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 zfcp_fsf_send_els_handler(fsf_req);
695 break;
696
697 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 zfcp_fsf_control_file_handler(fsf_req);
699 break;
700
701 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 zfcp_fsf_control_file_handler(fsf_req);
703 break;
704
705 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
707 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
708 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200709 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
711 ZFCP_LOG_NORMAL
712 ("bug: Command issued by the device driver differs "
713 "from the command returned by the adapter %s "
714 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200715 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 fsf_req->fsf_command,
717 fsf_req->qtcb->header.fsf_command);
718 }
719
720 if (!erp_action)
721 return retval;
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 zfcp_erp_async_handler(erp_action, 0);
724
725 return retval;
726}
727
728/*
729 * function: zfcp_fsf_status_read
730 *
731 * purpose: initiates a Status Read command at the specified adapter
732 *
733 * returns:
734 */
735int
736zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
737{
738 struct zfcp_fsf_req *fsf_req;
739 struct fsf_status_read_buffer *status_buffer;
740 unsigned long lock_flags;
741 volatile struct qdio_buffer_element *sbale;
742 int retval = 0;
743
744 /* setup new FSF request */
745 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
746 req_flags | ZFCP_REQ_NO_QTCB,
747 adapter->pool.fsf_req_status_read,
748 &lock_flags, &fsf_req);
749 if (retval < 0) {
750 ZFCP_LOG_INFO("error: Could not create unsolicited status "
751 "buffer for adapter %s.\n",
752 zfcp_get_busid_by_adapter(adapter));
753 goto failed_req_create;
754 }
755
756 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
757 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
758 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
759 fsf_req->sbale_curr = 2;
760
761 status_buffer =
762 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
763 if (!status_buffer) {
764 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
765 goto failed_buf;
766 }
767 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200768 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 /* insert pointer to respective buffer */
771 sbale = zfcp_qdio_sbale_curr(fsf_req);
772 sbale->addr = (void *) status_buffer;
773 sbale->length = sizeof(struct fsf_status_read_buffer);
774
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200775 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (retval) {
777 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
778 "environment.\n");
779 goto failed_req_send;
780 }
781
782 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
783 zfcp_get_busid_by_adapter(adapter));
784 goto out;
785
786 failed_req_send:
787 mempool_free(status_buffer, adapter->pool.data_status_read);
788
789 failed_buf:
790 zfcp_fsf_req_free(fsf_req);
791 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200792 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 out:
794 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
795 return retval;
796}
797
798static int
799zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
800{
801 struct fsf_status_read_buffer *status_buffer;
802 struct zfcp_adapter *adapter;
803 struct zfcp_port *port;
804 unsigned long flags;
805
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200806 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 adapter = fsf_req->adapter;
808
809 read_lock_irqsave(&zfcp_data.config_lock, flags);
810 list_for_each_entry(port, &adapter->port_list_head, list)
811 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
812 break;
813 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
814
815 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
816 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200817 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 "adapter %s. Ignored.\n",
819 status_buffer->d_id & ZFCP_DID_MASK,
820 zfcp_get_busid_by_adapter(adapter));
821 goto out;
822 }
823
824 switch (status_buffer->status_subtype) {
825
826 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
828 zfcp_erp_port_reopen(port, 0);
829 break;
830
831 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
833 zfcp_erp_port_shutdown(port, 0);
834 break;
835
836 default:
837 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
838 debug_exception(adapter->erp_dbf, 0,
839 &status_buffer->status_subtype, sizeof (u32));
840 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
841 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200842 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 "Ignored. (debug info 0x%x)\n",
844 status_buffer->d_id,
845 zfcp_get_busid_by_adapter(adapter),
846 status_buffer->status_subtype);
847 }
848 out:
849 return 0;
850}
851
852/*
853 * function: zfcp_fsf_status_read_handler
854 *
855 * purpose: is called for finished Open Port command
856 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200857 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 */
859static int
860zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
861{
862 int retval = 0;
863 struct zfcp_adapter *adapter = fsf_req->adapter;
864 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200865 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200866 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200869 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200871 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 goto out;
873 }
874
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200875 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 switch (status_buffer->status_type) {
878
879 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 zfcp_fsf_status_read_port_closed(fsf_req);
881 break;
882
883 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 zfcp_fsf_incoming_els(fsf_req);
885 break;
886
887 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
889 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 break;
891
892 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200893 fsf_bit_error = (struct fsf_bit_error_payload *)
894 status_buffer->payload;
895 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
896 "received (adapter %s, "
897 "link failures = %i, loss of sync errors = %i, "
898 "loss of signal errors = %i, "
899 "primitive sequence errors = %i, "
900 "invalid transmission word errors = %i, "
901 "CRC errors = %i)\n",
902 zfcp_get_busid_by_adapter(adapter),
903 fsf_bit_error->link_failure_error_count,
904 fsf_bit_error->loss_of_sync_error_count,
905 fsf_bit_error->loss_of_signal_error_count,
906 fsf_bit_error->primitive_sequence_error_count,
907 fsf_bit_error->invalid_transmission_word_error_count,
908 fsf_bit_error->crc_error_count);
909 ZFCP_LOG_INFO("Additional bit error threshold data "
910 "(adapter %s, "
911 "primitive sequence event time-outs = %i, "
912 "elastic buffer overrun errors = %i, "
913 "advertised receive buffer-to-buffer credit = %i, "
914 "current receice buffer-to-buffer credit = %i, "
915 "advertised transmit buffer-to-buffer credit = %i, "
916 "current transmit buffer-to-buffer credit = %i)\n",
917 zfcp_get_busid_by_adapter(adapter),
918 fsf_bit_error->primitive_sequence_event_timeout_count,
919 fsf_bit_error->elastic_buffer_overrun_error_count,
920 fsf_bit_error->advertised_receive_b2b_credit,
921 fsf_bit_error->current_receive_b2b_credit,
922 fsf_bit_error->advertised_transmit_b2b_credit,
923 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 break;
925
926 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200927 switch (status_buffer->status_subtype) {
928 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
929 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
930 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100931 zfcp_fsf_link_down_info_eval(adapter,
932 (struct fsf_link_down_info *)
933 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200934 break;
935 case FSF_STATUS_READ_SUB_FDISC_FAILED:
936 ZFCP_LOG_INFO("Local link to adapter %s is down "
937 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100938 zfcp_get_busid_by_adapter(adapter));
939 zfcp_fsf_link_down_info_eval(adapter,
940 (struct fsf_link_down_info *)
941 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200942 break;
943 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
944 ZFCP_LOG_INFO("Local link to adapter %s is down "
945 "due to firmware update on adapter\n",
946 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100947 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200948 break;
949 default:
950 ZFCP_LOG_INFO("Local link to adapter %s is down "
951 "due to unknown reason\n",
952 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100953 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200954 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 break;
956
957 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200958 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100959 "Restarting operations on this adapter\n",
960 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 /* All ports should be marked as ready to run again */
962 zfcp_erp_modify_adapter_status(adapter,
963 ZFCP_STATUS_COMMON_RUNNING,
964 ZFCP_SET);
965 zfcp_erp_adapter_reopen(adapter,
966 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
967 | ZFCP_STATUS_COMMON_ERP_FAILED);
968 break;
969
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100970 case FSF_STATUS_READ_NOTIFICATION_LOST:
971 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
972 "adapter %s%s%s%s%s%s%s%s%s\n",
973 zfcp_get_busid_by_adapter(adapter),
974 (status_buffer->status_subtype &
975 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
976 ", incoming ELS" : "",
977 (status_buffer->status_subtype &
978 FSF_STATUS_READ_SUB_SENSE_DATA) ?
979 ", sense data" : "",
980 (status_buffer->status_subtype &
981 FSF_STATUS_READ_SUB_LINK_STATUS) ?
982 ", link status change" : "",
983 (status_buffer->status_subtype &
984 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
985 ", port close" : "",
986 (status_buffer->status_subtype &
987 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
988 ", bit error exception" : "",
989 (status_buffer->status_subtype &
990 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
991 ", ACT update" : "",
992 (status_buffer->status_subtype &
993 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
994 ", ACT hardening" : "",
995 (status_buffer->status_subtype &
996 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
997 ", adapter feature change" : "");
998
999 if (status_buffer->status_subtype &
1000 FSF_STATUS_READ_SUB_ACT_UPDATED)
1001 zfcp_erp_adapter_access_changed(adapter);
1002 break;
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001005 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 zfcp_get_busid_by_adapter(adapter));
1007 zfcp_erp_adapter_access_changed(adapter);
1008 break;
1009
1010 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 switch (status_buffer->status_subtype) {
1012 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001013 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 zfcp_get_busid_by_adapter(adapter));
1015 break;
1016 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 "to the secondary SE\n",
1019 zfcp_get_busid_by_adapter(adapter));
1020 break;
1021 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001022 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 zfcp_get_busid_by_adapter(adapter));
1024 }
1025 break;
1026
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001027 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1028 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1029 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1030 "been changed from 0x%08X to 0x%08X\n",
1031 zfcp_get_busid_by_adapter(adapter),
1032 *(u32*) (status_buffer->payload + 4),
1033 *(u32*) (status_buffer->payload));
1034 adapter->adapter_features = *(u32*) status_buffer->payload;
1035 break;
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001038 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 "type was received (debug info 0x%x)\n",
1040 status_buffer->status_type);
1041 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1042 status_buffer);
1043 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1044 (char *) status_buffer,
1045 sizeof (struct fsf_status_read_buffer));
1046 break;
1047 }
1048 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001049 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 /*
1051 * recycle buffer and start new request repeat until outbound
1052 * queue is empty or adapter shutdown is requested
1053 */
1054 /*
1055 * FIXME(qdio):
1056 * we may wait in the req_create for 5s during shutdown, so
1057 * qdio_cleanup will have to wait at least that long before returning
1058 * with failure to allow us a proper cleanup under all circumstances
1059 */
1060 /*
1061 * FIXME:
1062 * allocation failure possible? (Is this code needed?)
1063 */
1064 retval = zfcp_fsf_status_read(adapter, 0);
1065 if (retval < 0) {
1066 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1067 "request for the adapter %s.\n",
1068 zfcp_get_busid_by_adapter(adapter));
1069 /* temporary fix to avoid status read buffer shortage */
1070 adapter->status_read_failed++;
1071 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1072 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1073 ZFCP_LOG_INFO("restart adapter %s due to status read "
1074 "buffer shortage\n",
1075 zfcp_get_busid_by_adapter(adapter));
1076 zfcp_erp_adapter_reopen(adapter, 0);
1077 }
1078 }
1079 out:
1080 return retval;
1081}
1082
1083/*
1084 * function: zfcp_fsf_abort_fcp_command
1085 *
1086 * purpose: tells FSF to abort a running SCSI command
1087 *
1088 * returns: address of initiated FSF request
1089 * NULL - request could not be initiated
1090 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001091 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 * FIXME(design) shouldn't this be modified to return an int
1093 * also...don't know how though
1094 */
1095struct zfcp_fsf_req *
1096zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1097 struct zfcp_adapter *adapter,
1098 struct zfcp_unit *unit, int req_flags)
1099{
1100 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001102 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 int retval = 0;
1104
1105 /* setup new FSF request */
1106 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1107 req_flags, adapter->pool.fsf_req_abort,
1108 &lock_flags, &fsf_req);
1109 if (retval < 0) {
1110 ZFCP_LOG_INFO("error: Failed to create an abort command "
1111 "request for lun 0x%016Lx on port 0x%016Lx "
1112 "on adapter %s.\n",
1113 unit->fcp_lun,
1114 unit->port->wwpn,
1115 zfcp_get_busid_by_adapter(adapter));
1116 goto out;
1117 }
1118
Christof Schmitt951f7462007-12-20 12:30:24 +01001119 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1120 &unit->status)))
1121 goto unit_blocked;
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1124 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1125 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1126
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001127 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 /* set handles of unit and its parent port in QTCB */
1130 fsf_req->qtcb->header.lun_handle = unit->handle;
1131 fsf_req->qtcb->header.port_handle = unit->port->handle;
1132
1133 /* set handle of request which should be aborted */
1134 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1135
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001136 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1137 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001138 if (!retval)
1139 goto out;
1140
1141 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 zfcp_fsf_req_free(fsf_req);
1143 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 out:
1146 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1147 return fsf_req;
1148}
1149
1150/*
1151 * function: zfcp_fsf_abort_fcp_command_handler
1152 *
1153 * purpose: is called for finished Abort FCP Command request
1154 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001155 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 */
1157static int
1158zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1159{
1160 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001161 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001162 union fsf_status_qual *fsf_stat_qual =
1163 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1166 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1167 goto skip_fsfstatus;
1168 }
1169
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001170 unit = (struct zfcp_unit *) new_fsf_req->data;
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* evaluate FSF status in QTCB */
1173 switch (new_fsf_req->qtcb->header.fsf_status) {
1174
1175 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001176 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1178 "fsf_s_phand_nv0");
1179 /*
1180 * In this case a command that was sent prior to a port
1181 * reopen was aborted (handles are different). This is
1182 * fine.
1183 */
1184 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1186 "port 0x%016Lx on adapter %s invalid. "
1187 "This may happen occasionally.\n",
1188 unit->port->handle,
1189 unit->port->wwpn,
1190 zfcp_get_busid_by_unit(unit));
1191 ZFCP_LOG_INFO("status qualifier:\n");
1192 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1193 (char *) &new_fsf_req->qtcb->header.
1194 fsf_status_qual,
1195 sizeof (union fsf_status_qual));
1196 /* Let's hope this sorts out the mess */
1197 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1198 "fsf_s_phand_nv1");
1199 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1200 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1201 }
1202 break;
1203
1204 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001205 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1207 "fsf_s_lhand_nv0");
1208 /*
1209 * In this case a command that was sent prior to a unit
1210 * reopen was aborted (handles are different).
1211 * This is fine.
1212 */
1213 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 ZFCP_LOG_INFO
1215 ("Warning: Temporary LUN identifier 0x%x of LUN "
1216 "0x%016Lx on port 0x%016Lx on adapter %s is "
1217 "invalid. This may happen in rare cases. "
1218 "Trying to re-establish link.\n",
1219 unit->handle,
1220 unit->fcp_lun,
1221 unit->port->wwpn,
1222 zfcp_get_busid_by_unit(unit));
1223 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1224 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1225 (char *) &new_fsf_req->qtcb->header.
1226 fsf_status_qual,
1227 sizeof (union fsf_status_qual));
1228 /* Let's hope this sorts out the mess */
1229 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1230 "fsf_s_lhand_nv1");
1231 zfcp_erp_port_reopen(unit->port, 0);
1232 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1233 }
1234 break;
1235
1236 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 retval = 0;
1238 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1239 "fsf_s_no_exist");
1240 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1241 break;
1242
1243 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1245 "be reopened\n", unit->port->wwpn,
1246 zfcp_get_busid_by_unit(unit));
1247 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1248 "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001249 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1251 | ZFCP_STATUS_FSFREQ_RETRY;
1252 break;
1253
1254 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 ZFCP_LOG_INFO(
1256 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1257 "to be reopened\n",
1258 unit->fcp_lun, unit->port->wwpn,
1259 zfcp_get_busid_by_unit(unit));
1260 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001261 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1263 | ZFCP_STATUS_FSFREQ_RETRY;
1264 break;
1265
1266 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1268 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1270 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001271 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1273 break;
1274 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 /* SCSI stack will escalate */
1276 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1277 "fsf_sq_ulp");
1278 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1279 break;
1280 default:
1281 ZFCP_LOG_NORMAL
1282 ("bug: Wrong status qualifier 0x%x arrived.\n",
1283 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1284 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1285 "fsf_sq_inval:");
1286 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1287 &new_fsf_req->qtcb->header.
1288 fsf_status_qual.word[0], sizeof (u32));
1289 break;
1290 }
1291 break;
1292
1293 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 retval = 0;
1295 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1296 break;
1297
1298 default:
1299 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1300 "(debug info 0x%x)\n",
1301 new_fsf_req->qtcb->header.fsf_status);
1302 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1303 "fsf_s_inval:");
1304 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1305 &new_fsf_req->qtcb->header.fsf_status,
1306 sizeof (u32));
1307 break;
1308 }
1309 skip_fsfstatus:
1310 return retval;
1311}
1312
1313/**
1314 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1315 * one SBALE
1316 * Two scatter-gather lists are passed, one for the reqeust and one for the
1317 * response.
1318 */
1319static inline int
1320zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1321 struct scatterlist *resp, int resp_count)
1322{
1323 return ((req_count == 1) &&
1324 (resp_count == 1) &&
1325 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1326 PAGE_MASK) ==
1327 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1328 req[0].length - 1) & PAGE_MASK)) &&
1329 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1330 PAGE_MASK) ==
1331 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1332 resp[0].length - 1) & PAGE_MASK)));
1333}
1334
1335/**
1336 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1337 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1338 * the request
1339 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1340 * a struct zfcp_fsf_req
1341 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1342 * is sent within error recovery
1343 */
1344int
1345zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1346 struct zfcp_erp_action *erp_action)
1347{
1348 volatile struct qdio_buffer_element *sbale;
1349 struct zfcp_port *port;
1350 struct zfcp_adapter *adapter;
1351 struct zfcp_fsf_req *fsf_req;
1352 unsigned long lock_flags;
1353 int bytes;
1354 int ret = 0;
1355
1356 port = ct->port;
1357 adapter = port->adapter;
1358
1359 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1360 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1361 pool, &lock_flags, &fsf_req);
1362 if (ret < 0) {
1363 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1364 "adapter: %s\n",
1365 zfcp_get_busid_by_adapter(adapter));
1366 goto failed_req;
1367 }
1368
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1370 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1371 ct->resp, ct->resp_count)){
1372 /* both request buffer and response buffer
1373 fit into one sbale each */
1374 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1375 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1376 sbale[2].length = ct->req[0].length;
1377 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1378 sbale[3].length = ct->resp[0].length;
1379 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001380 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1382 /* try to use chained SBALs */
1383 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1384 SBAL_FLAGS0_TYPE_WRITE_READ,
1385 ct->req, ct->req_count,
1386 ZFCP_MAX_SBALS_PER_CT_REQ);
1387 if (bytes <= 0) {
1388 ZFCP_LOG_INFO("error: creation of CT request failed "
1389 "on adapter %s\n",
1390 zfcp_get_busid_by_adapter(adapter));
1391 if (bytes == 0)
1392 ret = -ENOMEM;
1393 else
1394 ret = bytes;
1395
1396 goto failed_send;
1397 }
1398 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1399 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1400 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1401 SBAL_FLAGS0_TYPE_WRITE_READ,
1402 ct->resp, ct->resp_count,
1403 ZFCP_MAX_SBALS_PER_CT_REQ);
1404 if (bytes <= 0) {
1405 ZFCP_LOG_INFO("error: creation of CT request failed "
1406 "on adapter %s\n",
1407 zfcp_get_busid_by_adapter(adapter));
1408 if (bytes == 0)
1409 ret = -ENOMEM;
1410 else
1411 ret = bytes;
1412
1413 goto failed_send;
1414 }
1415 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1416 } else {
1417 /* reject send generic request */
1418 ZFCP_LOG_INFO(
1419 "error: microcode does not support chained SBALs,"
1420 "CT request too big (adapter %s)\n",
1421 zfcp_get_busid_by_adapter(adapter));
1422 ret = -EOPNOTSUPP;
1423 goto failed_send;
1424 }
1425
1426 /* settings in QTCB */
1427 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001428 fsf_req->qtcb->bottom.support.service_class =
1429 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001431 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001433 zfcp_san_dbf_event_ct_request(fsf_req);
1434
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001435 if (erp_action) {
1436 erp_action->fsf_req = fsf_req;
1437 fsf_req->erp_action = erp_action;
1438 zfcp_erp_start_timer(fsf_req);
1439 } else
1440 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1441
1442 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 if (ret) {
1444 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1445 "(adapter %s, port 0x%016Lx)\n",
1446 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1447 goto failed_send;
1448 }
1449
1450 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1451 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1452 goto out;
1453
1454 failed_send:
1455 zfcp_fsf_req_free(fsf_req);
1456 if (erp_action != NULL) {
1457 erp_action->fsf_req = NULL;
1458 }
1459 failed_req:
1460 out:
1461 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1462 lock_flags);
1463 return ret;
1464}
1465
1466/**
1467 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1468 * @fsf_req: pointer to struct zfcp_fsf_req
1469 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001470 * Data specific for the Generic Service request is passed using
1471 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1472 * Usually a specific handler for the CT request is called which is
1473 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 */
1475static int
1476zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1477{
1478 struct zfcp_port *port;
1479 struct zfcp_adapter *adapter;
1480 struct zfcp_send_ct *send_ct;
1481 struct fsf_qtcb_header *header;
1482 struct fsf_qtcb_bottom_support *bottom;
1483 int retval = -EINVAL;
1484 u16 subtable, rule, counter;
1485
1486 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001487 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 port = send_ct->port;
1489 header = &fsf_req->qtcb->header;
1490 bottom = &fsf_req->qtcb->bottom.support;
1491
1492 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1493 goto skip_fsfstatus;
1494
1495 /* evaluate FSF status in QTCB */
1496 switch (header->fsf_status) {
1497
1498 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001499 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 retval = 0;
1501 break;
1502
1503 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001504 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1505 "class %d.\n",
1506 zfcp_get_busid_by_port(port),
1507 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 /* stop operation for this adapter */
1509 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1510 zfcp_erp_adapter_shutdown(adapter, 0);
1511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1512 break;
1513
1514 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 switch (header->fsf_status_qual.word[0]){
1516 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 /* reopening link to port */
1518 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1519 zfcp_test_link(port);
1520 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1521 break;
1522 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 /* ERP strategy will escalate */
1524 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1526 break;
1527 default:
1528 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1529 "arrived.\n",
1530 header->fsf_status_qual.word[0]);
1531 break;
1532 }
1533 break;
1534
1535 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001537 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 zfcp_get_busid_by_port(port), port->d_id);
1539 for (counter = 0; counter < 2; counter++) {
1540 subtable = header->fsf_status_qual.halfword[counter * 2];
1541 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1542 switch (subtable) {
1543 case FSF_SQ_CFDC_SUBTABLE_OS:
1544 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1545 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1546 case FSF_SQ_CFDC_SUBTABLE_LUN:
1547 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1548 zfcp_act_subtable_type[subtable], rule);
1549 break;
1550 }
1551 }
1552 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1553 zfcp_erp_port_access_denied(port);
1554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1555 break;
1556
1557 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001559 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 zfcp_get_busid_by_port(port), port->d_id);
1561 ZFCP_LOG_INFO("status qualifier:\n");
1562 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1563 (char *) &header->fsf_status_qual,
1564 sizeof (union fsf_status_qual));
1565 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1566 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1567 break;
1568
1569 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1571 "0x%016Lx on adapter %s invalid. This may "
1572 "happen occasionally.\n", port->handle,
1573 port->wwpn, zfcp_get_busid_by_port(port));
1574 ZFCP_LOG_INFO("status qualifier:\n");
1575 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1576 (char *) &header->fsf_status_qual,
1577 sizeof (union fsf_status_qual));
1578 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1579 zfcp_erp_adapter_reopen(adapter, 0);
1580 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1581 break;
1582
1583 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001585 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 zfcp_get_busid_by_port(port), port->d_id);
1587 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001588 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1590 | ZFCP_STATUS_FSFREQ_RETRY;
1591 break;
1592
1593 /* following states should never occure, all cases avoided
1594 in zfcp_fsf_send_ct - but who knows ... */
1595 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1597 "req_buf_length=%d, resp_buf_length=%d)\n",
1598 zfcp_get_busid_by_adapter(adapter),
1599 bottom->req_buf_length, bottom->resp_buf_length);
1600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1601 break;
1602 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1604 "req_buf_length=%d)\n",
1605 zfcp_get_busid_by_adapter(adapter),
1606 bottom->req_buf_length);
1607 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1608 break;
1609 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1611 "resp_buf_length=%d)\n",
1612 zfcp_get_busid_by_adapter(adapter),
1613 bottom->resp_buf_length);
1614 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1615 break;
1616 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1618 "resp_buf_length=%d)\n",
1619 zfcp_get_busid_by_adapter(adapter),
1620 bottom->req_buf_length, bottom->resp_buf_length);
1621 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1622 break;
1623
1624 default:
1625 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1626 "(debug info 0x%x)\n", header->fsf_status);
1627 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1628 debug_exception(adapter->erp_dbf, 0,
1629 &header->fsf_status_qual.word[0], sizeof (u32));
1630 break;
1631 }
1632
1633skip_fsfstatus:
1634 send_ct->status = retval;
1635
1636 if (send_ct->handler != NULL)
1637 send_ct->handler(send_ct->handler_data);
1638
1639 return retval;
1640}
1641
1642/**
1643 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1644 * @els: pointer to struct zfcp_send_els which contains all needed data for
1645 * the command.
1646 */
1647int
1648zfcp_fsf_send_els(struct zfcp_send_els *els)
1649{
1650 volatile struct qdio_buffer_element *sbale;
1651 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001652 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 struct zfcp_adapter *adapter;
1654 unsigned long lock_flags;
1655 int bytes;
1656 int ret = 0;
1657
1658 d_id = els->d_id;
1659 adapter = els->adapter;
1660
1661 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1662 ZFCP_REQ_AUTO_CLEANUP,
1663 NULL, &lock_flags, &fsf_req);
1664 if (ret < 0) {
1665 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001666 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 zfcp_get_busid_by_adapter(adapter), d_id);
1668 goto failed_req;
1669 }
1670
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001671 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1672 &els->port->status))) {
1673 ret = -EBUSY;
1674 goto port_blocked;
1675 }
1676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1678 if (zfcp_use_one_sbal(els->req, els->req_count,
1679 els->resp, els->resp_count)){
1680 /* both request buffer and response buffer
1681 fit into one sbale each */
1682 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1683 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1684 sbale[2].length = els->req[0].length;
1685 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1686 sbale[3].length = els->resp[0].length;
1687 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001688 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1690 /* try to use chained SBALs */
1691 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1692 SBAL_FLAGS0_TYPE_WRITE_READ,
1693 els->req, els->req_count,
1694 ZFCP_MAX_SBALS_PER_ELS_REQ);
1695 if (bytes <= 0) {
1696 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001697 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 zfcp_get_busid_by_adapter(adapter), d_id);
1699 if (bytes == 0) {
1700 ret = -ENOMEM;
1701 } else {
1702 ret = bytes;
1703 }
1704 goto failed_send;
1705 }
1706 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1707 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1708 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1709 SBAL_FLAGS0_TYPE_WRITE_READ,
1710 els->resp, els->resp_count,
1711 ZFCP_MAX_SBALS_PER_ELS_REQ);
1712 if (bytes <= 0) {
1713 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001714 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 zfcp_get_busid_by_adapter(adapter), d_id);
1716 if (bytes == 0) {
1717 ret = -ENOMEM;
1718 } else {
1719 ret = bytes;
1720 }
1721 goto failed_send;
1722 }
1723 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1724 } else {
1725 /* reject request */
1726 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1727 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001728 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 zfcp_get_busid_by_adapter(adapter), d_id);
1730 ret = -EOPNOTSUPP;
1731 goto failed_send;
1732 }
1733
1734 /* settings in QTCB */
1735 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001736 fsf_req->qtcb->bottom.support.service_class =
1737 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001739 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1742
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001743 zfcp_san_dbf_event_els_request(fsf_req);
1744
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001745 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1746 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 if (ret) {
1748 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001749 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 zfcp_get_busid_by_adapter(adapter), d_id);
1751 goto failed_send;
1752 }
1753
1754 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001755 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 goto out;
1757
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001758 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 failed_send:
1760 zfcp_fsf_req_free(fsf_req);
1761
1762 failed_req:
1763 out:
1764 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1765 lock_flags);
1766
1767 return ret;
1768}
1769
1770/**
1771 * zfcp_fsf_send_els_handler - handler for ELS commands
1772 * @fsf_req: pointer to struct zfcp_fsf_req
1773 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001774 * Data specific for the ELS command is passed using
1775 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1776 * Usually a specific handler for the ELS command is called which is
1777 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 */
1779static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1780{
1781 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001783 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 struct fsf_qtcb_header *header;
1785 struct fsf_qtcb_bottom_support *bottom;
1786 struct zfcp_send_els *send_els;
1787 int retval = -EINVAL;
1788 u16 subtable, rule, counter;
1789
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001790 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001792 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 d_id = send_els->d_id;
1794 header = &fsf_req->qtcb->header;
1795 bottom = &fsf_req->qtcb->bottom.support;
1796
1797 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1798 goto skip_fsfstatus;
1799
1800 switch (header->fsf_status) {
1801
1802 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001803 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 retval = 0;
1805 break;
1806
1807 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001808 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1809 "class %d.\n",
1810 zfcp_get_busid_by_adapter(adapter),
1811 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 /* stop operation for this adapter */
1813 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1814 zfcp_erp_adapter_shutdown(adapter, 0);
1815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1816 break;
1817
1818 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 switch (header->fsf_status_qual.word[0]){
1820 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001822 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1823 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1825 break;
1826 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 retval =
1830 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1831 (struct zfcp_ls_rjt_par *)
1832 &header->fsf_status_qual.word[2]);
1833 break;
1834 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1836 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1837 break;
1838 default:
1839 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1840 header->fsf_status_qual.word[0]);
1841 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1842 (char*)header->fsf_status_qual.word, 16);
1843 }
1844 break;
1845
1846 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1848 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001849 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 zfcp_get_busid_by_adapter(adapter), d_id);
1851
1852 break;
1853
1854 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 ZFCP_LOG_INFO(
1856 "ELS request size and ELS response size must be either "
1857 "both 0, or both greater than 0 "
1858 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1859 zfcp_get_busid_by_adapter(adapter),
1860 bottom->req_buf_length,
1861 bottom->resp_buf_length);
1862 break;
1863
1864 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 ZFCP_LOG_INFO(
1866 "Length of the ELS request buffer, "
1867 "specified in QTCB bottom, "
1868 "exceeds the size of the buffers "
1869 "that have been allocated for ELS request data "
1870 "(adapter: %s, req_buf_length=%d)\n",
1871 zfcp_get_busid_by_adapter(adapter),
1872 bottom->req_buf_length);
1873 break;
1874
1875 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 ZFCP_LOG_INFO(
1877 "Length of the ELS response buffer, "
1878 "specified in QTCB bottom, "
1879 "exceeds the size of the buffers "
1880 "that have been allocated for ELS response data "
1881 "(adapter: %s, resp_buf_length=%d)\n",
1882 zfcp_get_busid_by_adapter(adapter),
1883 bottom->resp_buf_length);
1884 break;
1885
1886 case FSF_SBAL_MISMATCH:
1887 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1889 "resp_buf_length=%d)\n",
1890 zfcp_get_busid_by_adapter(adapter),
1891 bottom->req_buf_length, bottom->resp_buf_length);
1892 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1893 break;
1894
1895 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001897 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 zfcp_get_busid_by_adapter(adapter), d_id);
1899 for (counter = 0; counter < 2; counter++) {
1900 subtable = header->fsf_status_qual.halfword[counter * 2];
1901 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1902 switch (subtable) {
1903 case FSF_SQ_CFDC_SUBTABLE_OS:
1904 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1905 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1906 case FSF_SQ_CFDC_SUBTABLE_LUN:
1907 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1908 zfcp_act_subtable_type[subtable], rule);
1909 break;
1910 }
1911 }
1912 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 if (port != NULL)
1914 zfcp_erp_port_access_denied(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1916 break;
1917
1918 default:
1919 ZFCP_LOG_NORMAL(
1920 "bug: An unknown FSF Status was presented "
1921 "(adapter: %s, fsf_status=0x%08x)\n",
1922 zfcp_get_busid_by_adapter(adapter),
1923 header->fsf_status);
1924 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1925 debug_exception(adapter->erp_dbf, 0,
1926 &header->fsf_status_qual.word[0], sizeof(u32));
1927 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1928 break;
1929 }
1930
1931skip_fsfstatus:
1932 send_els->status = retval;
1933
Heiko Carstensaa551da2007-07-18 10:55:10 +02001934 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 send_els->handler(send_els->handler_data);
1936
1937 return retval;
1938}
1939
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940int
1941zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1942{
1943 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001944 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001945 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001947 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001950 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1952 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001953 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001954 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001955 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1957 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001958 zfcp_get_busid_by_adapter(adapter));
1959 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1960 lock_flags);
1961 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 }
1963
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001964 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001965 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1966 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001968 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001969 FSF_FEATURE_CFDC |
1970 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001971 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001972 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001973 fsf_req->erp_action = erp_action;
1974 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001976 zfcp_erp_start_timer(fsf_req);
1977 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001978 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1979 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001981 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1982 "data command on the adapter %s\n",
1983 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001984 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001986 }
1987 else
1988 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1989 "(adapter %s)\n",
1990 zfcp_get_busid_by_adapter(adapter));
1991
1992 return retval;
1993}
1994
1995int
1996zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1997 struct fsf_qtcb_bottom_config *data)
1998{
1999 volatile struct qdio_buffer_element *sbale;
2000 struct zfcp_fsf_req *fsf_req;
2001 unsigned long lock_flags;
2002 int retval;
2003
2004 /* setup new FSF request */
2005 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
2006 0, NULL, &lock_flags, &fsf_req);
2007 if (retval) {
2008 ZFCP_LOG_INFO("error: Could not create exchange configuration "
2009 "data request for adapter %s.\n",
2010 zfcp_get_busid_by_adapter(adapter));
2011 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2012 lock_flags);
2013 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 }
2015
Swen Schillig52ef11a2007-08-28 09:31:09 +02002016 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2017 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2018 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Swen Schillig52ef11a2007-08-28 09:31:09 +02002020 fsf_req->qtcb->bottom.config.feature_selection =
2021 FSF_FEATURE_CFDC |
2022 FSF_FEATURE_LUN_SHARING |
2023 FSF_FEATURE_NOTIFICATION_LOST |
2024 FSF_FEATURE_UPDATE_ALERT;
2025
2026 if (data)
2027 fsf_req->data = (unsigned long) data;
2028
2029 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2030 retval = zfcp_fsf_req_send(fsf_req);
2031 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002033 if (retval)
2034 ZFCP_LOG_INFO("error: Could not send exchange configuration "
2035 "data command on the adapter %s\n",
2036 zfcp_get_busid_by_adapter(adapter));
2037 else
2038 wait_event(fsf_req->completion_wq,
2039 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2040
2041 zfcp_fsf_req_free(fsf_req);
2042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 return retval;
2044}
2045
2046/**
2047 * zfcp_fsf_exchange_config_evaluate
2048 * @fsf_req: fsf_req which belongs to xchg config data request
2049 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2050 *
2051 * returns: -EIO on error, 0 otherwise
2052 */
2053static int
2054zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2055{
2056 struct fsf_qtcb_bottom_config *bottom;
2057 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002058 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
2060 bottom = &fsf_req->qtcb->bottom.config;
2061 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2062 bottom->low_qtcb_version, bottom->high_qtcb_version);
2063 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002064 adapter->adapter_features = bottom->adapter_features;
2065 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05002066 adapter->peer_wwpn = 0;
2067 adapter->peer_wwnn = 0;
2068 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
2070 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02002071
2072 if (fsf_req->data)
2073 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
2074 bottom, sizeof (struct fsf_qtcb_bottom_config));
2075
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002076 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2077 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2078 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2079 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002080 fc_host_supported_classes(shost) =
2081 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002083 if (fc_host_permanent_port_name(shost) == -1)
2084 fc_host_permanent_port_name(shost) =
2085 fc_host_port_name(shost);
2086 if (bottom->fc_topology == FSF_TOPO_P2P) {
2087 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2088 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2089 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2090 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2091 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2092 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2093 else if (bottom->fc_topology == FSF_TOPO_AL)
2094 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2095 else
2096 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002098 fc_host_node_name(shost) = 0;
2099 fc_host_port_name(shost) = 0;
2100 fc_host_port_id(shost) = 0;
2101 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002102 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 adapter->hydra_version = 0;
2104 }
2105
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002106 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002108 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2109 min(FC_SERIAL_NUMBER_SIZE, 17));
2110 EBCASC(fc_host_serial_number(shost),
2111 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 }
2113
Swen Schillig52ef11a2007-08-28 09:31:09 +02002114 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2115 "characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002116 "WWNN 0x%016Lx, "
2117 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002118 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002119 "adapter version 0x%x, "
2120 "LIC version 0x%x, "
2121 "FC link speed %d Gb/s\n",
2122 zfcp_get_busid_by_adapter(adapter),
2123 (wwn_t) fc_host_node_name(shost),
2124 (wwn_t) fc_host_port_name(shost),
2125 fc_host_port_id(shost),
2126 adapter->hydra_version,
2127 adapter->fsf_lic_version,
2128 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2130 ZFCP_LOG_NORMAL("error: the adapter %s "
2131 "only supports newer control block "
2132 "versions in comparison to this device "
2133 "driver (try updated device driver)\n",
2134 zfcp_get_busid_by_adapter(adapter));
2135 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2136 zfcp_erp_adapter_shutdown(adapter, 0);
2137 return -EIO;
2138 }
2139 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2140 ZFCP_LOG_NORMAL("error: the adapter %s "
2141 "only supports older control block "
2142 "versions than this device driver uses"
2143 "(consider a microcode upgrade)\n",
2144 zfcp_get_busid_by_adapter(adapter));
2145 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2146 zfcp_erp_adapter_shutdown(adapter, 0);
2147 return -EIO;
2148 }
2149 return 0;
2150}
2151
Swen Schillig52ef11a2007-08-28 09:31:09 +02002152/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 * function: zfcp_fsf_exchange_config_data_handler
2154 *
2155 * purpose: is called for finished Exchange Configuration Data command
2156 *
2157 * returns:
2158 */
2159static int
2160zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2161{
2162 struct fsf_qtcb_bottom_config *bottom;
2163 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002164 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
2166 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2167 return -EIO;
2168
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002169 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
2171 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2173 return -EIO;
2174
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002175 switch (fc_host_port_type(adapter->scsi_host)) {
2176 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002177 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2178 "configuration detected at adapter %s\n"
2179 "Peer WWNN 0x%016llx, "
2180 "peer WWPN 0x%016llx, "
2181 "peer d_id 0x%06x\n",
2182 zfcp_get_busid_by_adapter(adapter),
2183 adapter->peer_wwnn,
2184 adapter->peer_wwpn,
2185 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 debug_text_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002187 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002188 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002189 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2191 "topology detected at adapter %s "
2192 "unsupported, shutting down adapter\n",
2193 zfcp_get_busid_by_adapter(adapter));
2194 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2195 "top-al");
2196 zfcp_erp_adapter_shutdown(adapter, 0);
2197 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002198 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002199 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002200 "network detected at adapter %s.\n",
2201 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 break;
2203 default:
2204 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2205 "reported by the exchange "
2206 "configuration command for "
2207 "the adapter %s is not "
2208 "of a type known to the zfcp "
2209 "driver, shutting down adapter\n",
2210 zfcp_get_busid_by_adapter(adapter));
2211 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2212 "unknown-topo");
2213 zfcp_erp_adapter_shutdown(adapter, 0);
2214 return -EIO;
2215 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002216 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2218 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2219 "allowed by the adapter %s "
2220 "is lower than the minimum "
2221 "required by the driver (%ld bytes).\n",
2222 bottom->max_qtcb_size,
2223 zfcp_get_busid_by_adapter(adapter),
2224 sizeof(struct fsf_qtcb));
2225 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2226 "qtcb-size");
2227 debug_event(fsf_req->adapter->erp_dbf, 0,
2228 &bottom->max_qtcb_size, sizeof (u32));
2229 zfcp_erp_adapter_shutdown(adapter, 0);
2230 return -EIO;
2231 }
2232 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2233 &adapter->status);
2234 break;
2235 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2236 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2237
2238 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2239 return -EIO;
2240
Swen Schillig52ef11a2007-08-28 09:31:09 +02002241 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2242 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002243
2244 zfcp_fsf_link_down_info_eval(adapter,
2245 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 break;
2247 default:
2248 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2249 debug_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002250 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 zfcp_erp_adapter_shutdown(adapter, 0);
2252 return -EIO;
2253 }
2254 return 0;
2255}
2256
2257/**
2258 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002259 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 */
2261int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002262zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263{
2264 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002265 struct zfcp_fsf_req *fsf_req;
2266 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002267 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002268 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002270 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002272 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002274 return -EOPNOTSUPP;
2275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 /* setup new FSF request */
2278 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002279 ZFCP_REQ_AUTO_CLEANUP,
2280 adapter->pool.fsf_req_erp,
2281 &lock_flags, &fsf_req);
2282 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002284 "exchange port data request for"
2285 "the adapter %s.\n",
2286 zfcp_get_busid_by_adapter(adapter));
2287 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2288 lock_flags);
2289 return retval;
2290 }
2291
2292 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2293 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2294 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2295
2296 erp_action->fsf_req = fsf_req;
2297 fsf_req->erp_action = erp_action;
2298 zfcp_erp_start_timer(fsf_req);
2299
2300 retval = zfcp_fsf_req_send(fsf_req);
2301 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2302
2303 if (retval) {
2304 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2305 "command on the adapter %s\n",
2306 zfcp_get_busid_by_adapter(adapter));
2307 zfcp_fsf_req_free(fsf_req);
2308 erp_action->fsf_req = NULL;
2309 }
2310 else
2311 ZFCP_LOG_DEBUG("exchange port data request initiated "
2312 "(adapter %s)\n",
2313 zfcp_get_busid_by_adapter(adapter));
2314 return retval;
2315}
2316
2317
2318/**
2319 * zfcp_fsf_exchange_port_data_sync - request information about local port
2320 * and wait until information is ready
2321 */
2322int
2323zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2324 struct fsf_qtcb_bottom_port *data)
2325{
2326 volatile struct qdio_buffer_element *sbale;
2327 struct zfcp_fsf_req *fsf_req;
2328 unsigned long lock_flags;
2329 int retval;
2330
2331 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2332 ZFCP_LOG_INFO("error: exchange port data "
2333 "command not supported by adapter %s\n",
2334 zfcp_get_busid_by_adapter(adapter));
2335 return -EOPNOTSUPP;
2336 }
2337
2338 /* setup new FSF request */
2339 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2340 0, NULL, &lock_flags, &fsf_req);
2341 if (retval) {
2342 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2343 "exchange port data request for"
2344 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 zfcp_get_busid_by_adapter(adapter));
2346 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2347 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002348 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002349 }
2350
2351 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002352 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002355 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2356 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Swen Schillig52ef11a2007-08-28 09:31:09 +02002358 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002359 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002360 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Swen Schillig52ef11a2007-08-28 09:31:09 +02002362 if (retval)
2363 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2364 "command on the adapter %s\n",
2365 zfcp_get_busid_by_adapter(adapter));
2366 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002367 wait_event(fsf_req->completion_wq,
2368 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002369
2370 zfcp_fsf_req_free(fsf_req);
2371
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 return retval;
2373}
2374
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002375/**
2376 * zfcp_fsf_exchange_port_evaluate
2377 * @fsf_req: fsf_req which belongs to xchg port data request
2378 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2379 */
2380static void
2381zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2382{
2383 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002384 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002385 struct Scsi_Host *shost;
2386
2387 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002388 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002389 shost = adapter->scsi_host;
2390
Swen Schillig52ef11a2007-08-28 09:31:09 +02002391 if (fsf_req->data)
2392 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2393 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002394
2395 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2396 fc_host_permanent_port_name(shost) = bottom->wwpn;
2397 else
2398 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2399 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2400 fc_host_supported_speeds(shost) = bottom->supported_speed;
2401}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
2403/**
2404 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2405 * @fsf_req: pointer to struct zfcp_fsf_req
2406 */
2407static void
2408zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2409{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002410 struct zfcp_adapter *adapter;
2411 struct fsf_qtcb *qtcb;
2412
2413 adapter = fsf_req->adapter;
2414 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
2416 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2417 return;
2418
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002419 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002421 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002422 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002423 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002424 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002425 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002426 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002427 zfcp_fsf_link_down_info_eval(adapter,
2428 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002431 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2432 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2434 }
2435}
2436
2437
2438/*
2439 * function: zfcp_fsf_open_port
2440 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002441 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 *
2443 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002444 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 */
2446int
2447zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2448{
2449 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002450 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 unsigned long lock_flags;
2452 int retval = 0;
2453
2454 /* setup new FSF request */
2455 retval = zfcp_fsf_req_create(erp_action->adapter,
2456 FSF_QTCB_OPEN_PORT_WITH_DID,
2457 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2458 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002459 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 if (retval < 0) {
2461 ZFCP_LOG_INFO("error: Could not create open port request "
2462 "for port 0x%016Lx on adapter %s.\n",
2463 erp_action->port->wwpn,
2464 zfcp_get_busid_by_adapter(erp_action->adapter));
2465 goto out;
2466 }
2467
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002468 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2470 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2471
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002472 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002474 fsf_req->data = (unsigned long) erp_action->port;
2475 fsf_req->erp_action = erp_action;
2476 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002478 zfcp_erp_start_timer(fsf_req);
2479 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 if (retval) {
2481 ZFCP_LOG_INFO("error: Could not send open port request for "
2482 "port 0x%016Lx on adapter %s.\n",
2483 erp_action->port->wwpn,
2484 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002485 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 erp_action->fsf_req = NULL;
2487 goto out;
2488 }
2489
2490 ZFCP_LOG_DEBUG("open port request initiated "
2491 "(adapter %s, port 0x%016Lx)\n",
2492 zfcp_get_busid_by_adapter(erp_action->adapter),
2493 erp_action->port->wwpn);
2494 out:
2495 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2496 lock_flags);
2497 return retval;
2498}
2499
2500/*
2501 * function: zfcp_fsf_open_port_handler
2502 *
2503 * purpose: is called for finished Open Port command
2504 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002505 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 */
2507static int
2508zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2509{
2510 int retval = -EINVAL;
2511 struct zfcp_port *port;
2512 struct fsf_plogi *plogi;
2513 struct fsf_qtcb_header *header;
2514 u16 subtable, rule, counter;
2515
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002516 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 header = &fsf_req->qtcb->header;
2518
2519 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2520 /* don't change port status in our bookkeeping */
2521 goto skip_fsfstatus;
2522 }
2523
2524 /* evaluate FSF status in QTCB */
2525 switch (header->fsf_status) {
2526
2527 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2529 "is already open.\n",
2530 port->wwpn, zfcp_get_busid_by_port(port));
2531 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2532 "fsf_s_popen");
2533 /*
2534 * This is a bug, however operation should continue normally
2535 * if it is simply ignored
2536 */
2537 break;
2538
2539 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2541 "on adapter %s\n",
2542 port->wwpn, zfcp_get_busid_by_port(port));
2543 for (counter = 0; counter < 2; counter++) {
2544 subtable = header->fsf_status_qual.halfword[counter * 2];
2545 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2546 switch (subtable) {
2547 case FSF_SQ_CFDC_SUBTABLE_OS:
2548 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2549 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2550 case FSF_SQ_CFDC_SUBTABLE_LUN:
2551 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2552 zfcp_act_subtable_type[subtable], rule);
2553 break;
2554 }
2555 }
2556 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2557 zfcp_erp_port_access_denied(port);
2558 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2559 break;
2560
2561 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2563 "The remote port 0x%016Lx on adapter %s "
2564 "could not be opened. Disabling it.\n",
2565 port->wwpn, zfcp_get_busid_by_port(port));
2566 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2567 "fsf_s_max_ports");
2568 zfcp_erp_port_failed(port);
2569 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2570 break;
2571
2572 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 switch (header->fsf_status_qual.word[0]) {
2574 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2576 "fsf_sq_ltest");
2577 /* ERP strategy will escalate */
2578 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2579 break;
2580 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2581 /* ERP strategy will escalate */
2582 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2583 "fsf_sq_ulp");
2584 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2585 break;
2586 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2588 "adapter %s could not be opened. "
2589 "Disabling it.\n",
2590 port->wwpn,
2591 zfcp_get_busid_by_port(port));
2592 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2593 "fsf_sq_no_retry");
2594 zfcp_erp_port_failed(port);
2595 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2596 break;
2597 default:
2598 ZFCP_LOG_NORMAL
2599 ("bug: Wrong status qualifier 0x%x arrived.\n",
2600 header->fsf_status_qual.word[0]);
2601 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2602 "fsf_sq_inval:");
2603 debug_exception(
2604 fsf_req->adapter->erp_dbf, 0,
2605 &header->fsf_status_qual.word[0],
2606 sizeof (u32));
2607 break;
2608 }
2609 break;
2610
2611 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 /* save port handle assigned by FSF */
2613 port->handle = header->port_handle;
2614 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2615 "was opened, it's port handle is 0x%x\n",
2616 port->wwpn, zfcp_get_busid_by_port(port),
2617 port->handle);
2618 /* mark port as open */
2619 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2620 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002621 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2622 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2623 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 retval = 0;
2625 /* check whether D_ID has changed during open */
2626 /*
2627 * FIXME: This check is not airtight, as the FCP channel does
2628 * not monitor closures of target port connections caused on
2629 * the remote side. Thus, they might miss out on invalidating
2630 * locally cached WWPNs (and other N_Port parameters) of gone
2631 * target ports. So, our heroic attempt to make things safe
2632 * could be undermined by 'open port' response data tagged with
2633 * obsolete WWPNs. Another reason to monitor potential
2634 * connection closures ourself at least (by interpreting
2635 * incoming ELS' and unsolicited status). It just crosses my
2636 * mind that one should be able to cross-check by means of
2637 * another GID_PN straight after a port has been opened.
2638 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2639 */
2640 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2641 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2642 {
2643 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002644 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 ZFCP_LOG_INFO(
2646 "warning: insufficient length of "
2647 "PLOGI payload (%i)\n",
2648 fsf_req->qtcb->bottom.support.els1_length);
2649 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2650 "fsf_s_short_plogi:");
2651 /* skip sanity check and assume wwpn is ok */
2652 } else {
2653 if (plogi->serv_param.wwpn != port->wwpn) {
2654 ZFCP_LOG_INFO("warning: d_id of port "
2655 "0x%016Lx changed during "
2656 "open\n", port->wwpn);
2657 debug_text_event(
2658 fsf_req->adapter->erp_dbf, 0,
2659 "fsf_s_did_change:");
2660 atomic_clear_mask(
2661 ZFCP_STATUS_PORT_DID_DID,
2662 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002663 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002665 zfcp_plogi_evaluate(port, plogi);
2666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 }
2668 }
2669 break;
2670
2671 case FSF_UNKNOWN_OP_SUBTYPE:
2672 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2674 "op_subtype=0x%x)\n",
2675 zfcp_get_busid_by_port(port),
2676 fsf_req->qtcb->bottom.support.operation_subtype);
2677 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2678 break;
2679
2680 default:
2681 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2682 "(debug info 0x%x)\n",
2683 header->fsf_status);
2684 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2685 debug_exception(fsf_req->adapter->erp_dbf, 0,
2686 &header->fsf_status, sizeof (u32));
2687 break;
2688 }
2689
2690 skip_fsfstatus:
2691 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2692 return retval;
2693}
2694
2695/*
2696 * function: zfcp_fsf_close_port
2697 *
2698 * purpose: submit FSF command "close port"
2699 *
2700 * returns: address of initiated FSF request
2701 * NULL - request could not be initiated
2702 */
2703int
2704zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2705{
2706 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002707 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 unsigned long lock_flags;
2709 int retval = 0;
2710
2711 /* setup new FSF request */
2712 retval = zfcp_fsf_req_create(erp_action->adapter,
2713 FSF_QTCB_CLOSE_PORT,
2714 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2715 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002716 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (retval < 0) {
2718 ZFCP_LOG_INFO("error: Could not create a close port request "
2719 "for port 0x%016Lx on adapter %s.\n",
2720 erp_action->port->wwpn,
2721 zfcp_get_busid_by_adapter(erp_action->adapter));
2722 goto out;
2723 }
2724
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002725 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2727 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2728
2729 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002730 fsf_req->data = (unsigned long) erp_action->port;
2731 fsf_req->erp_action = erp_action;
2732 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2733 fsf_req->erp_action = erp_action;
2734 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002736 zfcp_erp_start_timer(fsf_req);
2737 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 if (retval) {
2739 ZFCP_LOG_INFO("error: Could not send a close port request for "
2740 "port 0x%016Lx on adapter %s.\n",
2741 erp_action->port->wwpn,
2742 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002743 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 erp_action->fsf_req = NULL;
2745 goto out;
2746 }
2747
2748 ZFCP_LOG_TRACE("close port request initiated "
2749 "(adapter %s, port 0x%016Lx)\n",
2750 zfcp_get_busid_by_adapter(erp_action->adapter),
2751 erp_action->port->wwpn);
2752 out:
2753 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2754 lock_flags);
2755 return retval;
2756}
2757
2758/*
2759 * function: zfcp_fsf_close_port_handler
2760 *
2761 * purpose: is called for finished Close Port FSF command
2762 *
2763 * returns:
2764 */
2765static int
2766zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2767{
2768 int retval = -EINVAL;
2769 struct zfcp_port *port;
2770
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002771 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
2773 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2774 /* don't change port status in our bookkeeping */
2775 goto skip_fsfstatus;
2776 }
2777
2778 /* evaluate FSF status in QTCB */
2779 switch (fsf_req->qtcb->header.fsf_status) {
2780
2781 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2783 "0x%016Lx on adapter %s invalid. This may happen "
2784 "occasionally.\n", port->handle,
2785 port->wwpn, zfcp_get_busid_by_port(port));
2786 ZFCP_LOG_DEBUG("status qualifier:\n");
2787 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2788 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2789 sizeof (union fsf_status_qual));
2790 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2791 "fsf_s_phand_nv");
2792 zfcp_erp_adapter_reopen(port->adapter, 0);
2793 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2794 break;
2795
2796 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 /* Note: FSF has actually closed the port in this case.
2798 * The status code is just daft. Fingers crossed for a change
2799 */
2800 retval = 0;
2801 break;
2802
2803 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2805 "port handle 0x%x\n", port->wwpn,
2806 zfcp_get_busid_by_port(port), port->handle);
2807 zfcp_erp_modify_port_status(port,
2808 ZFCP_STATUS_COMMON_OPEN,
2809 ZFCP_CLEAR);
2810 retval = 0;
2811 break;
2812
2813 default:
2814 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2815 "(debug info 0x%x)\n",
2816 fsf_req->qtcb->header.fsf_status);
2817 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2818 debug_exception(fsf_req->adapter->erp_dbf, 0,
2819 &fsf_req->qtcb->header.fsf_status,
2820 sizeof (u32));
2821 break;
2822 }
2823
2824 skip_fsfstatus:
2825 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2826 return retval;
2827}
2828
2829/*
2830 * function: zfcp_fsf_close_physical_port
2831 *
2832 * purpose: submit FSF command "close physical port"
2833 *
2834 * returns: address of initiated FSF request
2835 * NULL - request could not be initiated
2836 */
2837int
2838zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2839{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002841 struct zfcp_fsf_req *fsf_req;
2842 unsigned long lock_flags;
2843 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845 /* setup new FSF request */
2846 retval = zfcp_fsf_req_create(erp_action->adapter,
2847 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2848 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2849 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002850 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 if (retval < 0) {
2852 ZFCP_LOG_INFO("error: Could not create close physical port "
2853 "request (adapter %s, port 0x%016Lx)\n",
2854 zfcp_get_busid_by_adapter(erp_action->adapter),
2855 erp_action->port->wwpn);
2856
2857 goto out;
2858 }
2859
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002860 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2862 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2863
2864 /* mark port as being closed */
2865 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2866 &erp_action->port->status);
2867 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002868 fsf_req->data = (unsigned long) erp_action->port;
2869 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2870 fsf_req->erp_action = erp_action;
2871 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002873 zfcp_erp_start_timer(fsf_req);
2874 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 if (retval) {
2876 ZFCP_LOG_INFO("error: Could not send close physical port "
2877 "request (adapter %s, port 0x%016Lx)\n",
2878 zfcp_get_busid_by_adapter(erp_action->adapter),
2879 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002880 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 erp_action->fsf_req = NULL;
2882 goto out;
2883 }
2884
2885 ZFCP_LOG_TRACE("close physical port request initiated "
2886 "(adapter %s, port 0x%016Lx)\n",
2887 zfcp_get_busid_by_adapter(erp_action->adapter),
2888 erp_action->port->wwpn);
2889 out:
2890 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2891 lock_flags);
2892 return retval;
2893}
2894
2895/*
2896 * function: zfcp_fsf_close_physical_port_handler
2897 *
2898 * purpose: is called for finished Close Physical Port FSF command
2899 *
2900 * returns:
2901 */
2902static int
2903zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2904{
2905 int retval = -EINVAL;
2906 struct zfcp_port *port;
2907 struct zfcp_unit *unit;
2908 struct fsf_qtcb_header *header;
2909 u16 subtable, rule, counter;
2910
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002911 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 header = &fsf_req->qtcb->header;
2913
2914 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2915 /* don't change port status in our bookkeeping */
2916 goto skip_fsfstatus;
2917 }
2918
2919 /* evaluate FSF status in QTCB */
2920 switch (header->fsf_status) {
2921
2922 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2924 "(adapter %s, port 0x%016Lx). "
2925 "This may happen occasionally.\n",
2926 port->handle,
2927 zfcp_get_busid_by_port(port),
2928 port->wwpn);
2929 ZFCP_LOG_DEBUG("status qualifier:\n");
2930 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2931 (char *) &header->fsf_status_qual,
2932 sizeof (union fsf_status_qual));
2933 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2934 "fsf_s_phand_nv");
2935 zfcp_erp_adapter_reopen(port->adapter, 0);
2936 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2937 break;
2938
2939 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 ZFCP_LOG_NORMAL("Access denied, cannot close "
2941 "physical port 0x%016Lx on adapter %s\n",
2942 port->wwpn, zfcp_get_busid_by_port(port));
2943 for (counter = 0; counter < 2; counter++) {
2944 subtable = header->fsf_status_qual.halfword[counter * 2];
2945 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2946 switch (subtable) {
2947 case FSF_SQ_CFDC_SUBTABLE_OS:
2948 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2949 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2950 case FSF_SQ_CFDC_SUBTABLE_LUN:
2951 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2952 zfcp_act_subtable_type[subtable], rule);
2953 break;
2954 }
2955 }
2956 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2957 zfcp_erp_port_access_denied(port);
2958 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2959 break;
2960
2961 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2963 "%s needs to be reopened but it was attempted "
2964 "to close it physically.\n",
2965 port->wwpn,
2966 zfcp_get_busid_by_port(port));
2967 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02002968 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2970 ZFCP_STATUS_FSFREQ_RETRY;
2971 break;
2972
2973 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 switch (header->fsf_status_qual.word[0]) {
2975 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2977 "fsf_sq_ltest");
2978 /* This will now be escalated by ERP */
2979 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2980 break;
2981 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 /* ERP strategy will escalate */
2983 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2984 "fsf_sq_ulp");
2985 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2986 break;
2987 default:
2988 ZFCP_LOG_NORMAL
2989 ("bug: Wrong status qualifier 0x%x arrived.\n",
2990 header->fsf_status_qual.word[0]);
2991 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2992 "fsf_sq_inval:");
2993 debug_exception(
2994 fsf_req->adapter->erp_dbf, 0,
2995 &header->fsf_status_qual.word[0], sizeof (u32));
2996 break;
2997 }
2998 break;
2999
3000 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
3002 "physically closed, port handle 0x%x\n",
3003 port->wwpn,
3004 zfcp_get_busid_by_port(port), port->handle);
3005 /* can't use generic zfcp_erp_modify_port_status because
3006 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
3007 */
3008 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
3009 list_for_each_entry(unit, &port->unit_list_head, list)
3010 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3011 retval = 0;
3012 break;
3013
3014 default:
3015 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3016 "(debug info 0x%x)\n",
3017 header->fsf_status);
3018 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3019 debug_exception(fsf_req->adapter->erp_dbf, 0,
3020 &header->fsf_status, sizeof (u32));
3021 break;
3022 }
3023
3024 skip_fsfstatus:
3025 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
3026 return retval;
3027}
3028
3029/*
3030 * function: zfcp_fsf_open_unit
3031 *
3032 * purpose:
3033 *
3034 * returns:
3035 *
3036 * assumptions: This routine does not check whether the associated
3037 * remote port has already been opened. This should be
3038 * done by calling routines. Otherwise some status
3039 * may be presented by FSF
3040 */
3041int
3042zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3043{
3044 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003045 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 unsigned long lock_flags;
3047 int retval = 0;
3048
3049 /* setup new FSF request */
3050 retval = zfcp_fsf_req_create(erp_action->adapter,
3051 FSF_QTCB_OPEN_LUN,
3052 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3053 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003054 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 if (retval < 0) {
3056 ZFCP_LOG_INFO("error: Could not create open unit request for "
3057 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3058 erp_action->unit->fcp_lun,
3059 erp_action->unit->port->wwpn,
3060 zfcp_get_busid_by_adapter(erp_action->adapter));
3061 goto out;
3062 }
3063
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003064 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3066 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3067
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003068 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3069 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003070 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003071 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02003072 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003074 fsf_req->data = (unsigned long) erp_action->unit;
3075 fsf_req->erp_action = erp_action;
3076 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003078 zfcp_erp_start_timer(fsf_req);
3079 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 if (retval) {
3081 ZFCP_LOG_INFO("error: Could not send an open unit request "
3082 "on the adapter %s, port 0x%016Lx for "
3083 "unit 0x%016Lx\n",
3084 zfcp_get_busid_by_adapter(erp_action->adapter),
3085 erp_action->port->wwpn,
3086 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003087 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 erp_action->fsf_req = NULL;
3089 goto out;
3090 }
3091
3092 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3093 "port 0x%016Lx, unit 0x%016Lx)\n",
3094 zfcp_get_busid_by_adapter(erp_action->adapter),
3095 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3096 out:
3097 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3098 lock_flags);
3099 return retval;
3100}
3101
3102/*
3103 * function: zfcp_fsf_open_unit_handler
3104 *
3105 * purpose: is called for finished Open LUN command
3106 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003107 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 */
3109static int
3110zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3111{
3112 int retval = -EINVAL;
3113 struct zfcp_adapter *adapter;
3114 struct zfcp_unit *unit;
3115 struct fsf_qtcb_header *header;
3116 struct fsf_qtcb_bottom_support *bottom;
3117 struct fsf_queue_designator *queue_designator;
3118 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003119 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003121 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
3123 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3124 /* don't change unit status in our bookkeeping */
3125 goto skip_fsfstatus;
3126 }
3127
3128 adapter = fsf_req->adapter;
3129 header = &fsf_req->qtcb->header;
3130 bottom = &fsf_req->qtcb->bottom.support;
3131 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3132
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02003134 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 ZFCP_STATUS_UNIT_SHARED |
3136 ZFCP_STATUS_UNIT_READONLY,
3137 &unit->status);
3138
3139 /* evaluate FSF status in QTCB */
3140 switch (header->fsf_status) {
3141
3142 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3144 "for port 0x%016Lx on adapter %s invalid "
3145 "This may happen occasionally\n",
3146 unit->port->handle,
3147 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3148 ZFCP_LOG_DEBUG("status qualifier:\n");
3149 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3150 (char *) &header->fsf_status_qual,
3151 sizeof (union fsf_status_qual));
3152 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3153 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3155 break;
3156
3157 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3159 "remote port 0x%016Lx on adapter %s twice.\n",
3160 unit->fcp_lun,
3161 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3162 debug_text_exception(adapter->erp_dbf, 0,
3163 "fsf_s_uopen");
3164 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3165 break;
3166
3167 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3169 "remote port 0x%016Lx on adapter %s\n",
3170 unit->fcp_lun, unit->port->wwpn,
3171 zfcp_get_busid_by_unit(unit));
3172 for (counter = 0; counter < 2; counter++) {
3173 subtable = header->fsf_status_qual.halfword[counter * 2];
3174 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3175 switch (subtable) {
3176 case FSF_SQ_CFDC_SUBTABLE_OS:
3177 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3178 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3179 case FSF_SQ_CFDC_SUBTABLE_LUN:
3180 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3181 zfcp_act_subtable_type[subtable], rule);
3182 break;
3183 }
3184 }
3185 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3186 zfcp_erp_unit_access_denied(unit);
3187 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3188 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3189 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3190 break;
3191
3192 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3194 "needs to be reopened\n",
3195 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3196 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003197 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3199 ZFCP_STATUS_FSFREQ_RETRY;
3200 break;
3201
3202 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 if (header->fsf_status_qual.word[0] != 0) {
3204 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3205 "with WWPN 0x%Lx "
3206 "connected to the adapter %s "
3207 "is already in use in LPAR%d, CSS%d\n",
3208 unit->fcp_lun,
3209 unit->port->wwpn,
3210 zfcp_get_busid_by_unit(unit),
3211 queue_designator->hla,
3212 queue_designator->cssid);
3213 } else {
3214 subtable = header->fsf_status_qual.halfword[4];
3215 rule = header->fsf_status_qual.halfword[5];
3216 switch (subtable) {
3217 case FSF_SQ_CFDC_SUBTABLE_OS:
3218 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3219 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3220 case FSF_SQ_CFDC_SUBTABLE_LUN:
3221 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3222 "remote port with WWPN 0x%Lx "
3223 "connected to the adapter %s "
3224 "is denied (%s rule %d)\n",
3225 unit->fcp_lun,
3226 unit->port->wwpn,
3227 zfcp_get_busid_by_unit(unit),
3228 zfcp_act_subtable_type[subtable],
3229 rule);
3230 break;
3231 }
3232 }
3233 ZFCP_LOG_DEBUG("status qualifier:\n");
3234 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3235 (char *) &header->fsf_status_qual,
3236 sizeof (union fsf_status_qual));
3237 debug_text_event(adapter->erp_dbf, 2,
3238 "fsf_s_l_sh_vio");
3239 zfcp_erp_unit_access_denied(unit);
3240 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3241 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3242 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3243 break;
3244
3245 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3247 "There is no handle (temporary port identifier) "
3248 "available for unit 0x%016Lx on port 0x%016Lx "
3249 "on adapter %s\n",
3250 unit->fcp_lun,
3251 unit->port->wwpn,
3252 zfcp_get_busid_by_unit(unit));
3253 debug_text_event(adapter->erp_dbf, 1,
3254 "fsf_s_max_units");
3255 zfcp_erp_unit_failed(unit);
3256 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3257 break;
3258
3259 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 switch (header->fsf_status_qual.word[0]) {
3261 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 /* Re-establish link to port */
3263 debug_text_event(adapter->erp_dbf, 1,
3264 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003265 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3267 break;
3268 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 /* ERP strategy will escalate */
3270 debug_text_event(adapter->erp_dbf, 1,
3271 "fsf_sq_ulp");
3272 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3273 break;
3274 default:
3275 ZFCP_LOG_NORMAL
3276 ("bug: Wrong status qualifier 0x%x arrived.\n",
3277 header->fsf_status_qual.word[0]);
3278 debug_text_event(adapter->erp_dbf, 0,
3279 "fsf_sq_inval:");
3280 debug_exception(adapter->erp_dbf, 0,
3281 &header->fsf_status_qual.word[0],
3282 sizeof (u32));
3283 }
3284 break;
3285
3286 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 ZFCP_LOG_NORMAL(
3288 "Invalid option 0x%x has been specified "
3289 "in QTCB bottom sent to the adapter %s\n",
3290 bottom->option,
3291 zfcp_get_busid_by_adapter(adapter));
3292 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3293 retval = -EINVAL;
3294 break;
3295
3296 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 /* save LUN handle assigned by FSF */
3298 unit->handle = header->lun_handle;
3299 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3300 "adapter %s opened, port handle 0x%x\n",
3301 unit->fcp_lun,
3302 unit->port->wwpn,
3303 zfcp_get_busid_by_unit(unit),
3304 unit->handle);
3305 /* mark unit as open */
3306 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003307
3308 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3309 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3310 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3311 exclusive = (bottom->lun_access_info &
3312 FSF_UNIT_ACCESS_EXCLUSIVE);
3313 readwrite = (bottom->lun_access_info &
3314 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3315
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 if (!exclusive)
3317 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3318 &unit->status);
3319
3320 if (!readwrite) {
3321 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3322 &unit->status);
3323 ZFCP_LOG_NORMAL("read-only access for unit "
3324 "(adapter %s, wwpn=0x%016Lx, "
3325 "fcp_lun=0x%016Lx)\n",
3326 zfcp_get_busid_by_unit(unit),
3327 unit->port->wwpn,
3328 unit->fcp_lun);
3329 }
3330
3331 if (exclusive && !readwrite) {
3332 ZFCP_LOG_NORMAL("exclusive access of read-only "
3333 "unit not supported\n");
3334 zfcp_erp_unit_failed(unit);
3335 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3336 zfcp_erp_unit_shutdown(unit, 0);
3337 } else if (!exclusive && readwrite) {
3338 ZFCP_LOG_NORMAL("shared access of read-write "
3339 "unit not supported\n");
3340 zfcp_erp_unit_failed(unit);
3341 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3342 zfcp_erp_unit_shutdown(unit, 0);
3343 }
3344 }
3345
3346 retval = 0;
3347 break;
3348
3349 default:
3350 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3351 "(debug info 0x%x)\n",
3352 header->fsf_status);
3353 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3354 debug_exception(adapter->erp_dbf, 0,
3355 &header->fsf_status, sizeof (u32));
3356 break;
3357 }
3358
3359 skip_fsfstatus:
3360 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3361 return retval;
3362}
3363
3364/*
3365 * function: zfcp_fsf_close_unit
3366 *
3367 * purpose:
3368 *
3369 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003370 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 *
3372 * assumptions: This routine does not check whether the associated
3373 * remote port/lun has already been opened. This should be
3374 * done by calling routines. Otherwise some status
3375 * may be presented by FSF
3376 */
3377int
3378zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3379{
3380 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003381 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 unsigned long lock_flags;
3383 int retval = 0;
3384
3385 /* setup new FSF request */
3386 retval = zfcp_fsf_req_create(erp_action->adapter,
3387 FSF_QTCB_CLOSE_LUN,
3388 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3389 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003390 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 if (retval < 0) {
3392 ZFCP_LOG_INFO("error: Could not create close unit request for "
3393 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3394 erp_action->unit->fcp_lun,
3395 erp_action->port->wwpn,
3396 zfcp_get_busid_by_adapter(erp_action->adapter));
3397 goto out;
3398 }
3399
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003400 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3402 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3403
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003404 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3405 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003407 fsf_req->data = (unsigned long) erp_action->unit;
3408 fsf_req->erp_action = erp_action;
3409 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003411 zfcp_erp_start_timer(fsf_req);
3412 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 if (retval) {
3414 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3415 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3416 erp_action->unit->fcp_lun,
3417 erp_action->port->wwpn,
3418 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003419 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 erp_action->fsf_req = NULL;
3421 goto out;
3422 }
3423
3424 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3425 "port 0x%016Lx, unit 0x%016Lx)\n",
3426 zfcp_get_busid_by_adapter(erp_action->adapter),
3427 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3428 out:
3429 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3430 lock_flags);
3431 return retval;
3432}
3433
3434/*
3435 * function: zfcp_fsf_close_unit_handler
3436 *
3437 * purpose: is called for finished Close LUN FSF command
3438 *
3439 * returns:
3440 */
3441static int
3442zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3443{
3444 int retval = -EINVAL;
3445 struct zfcp_unit *unit;
3446
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003447 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448
3449 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3450 /* don't change unit status in our bookkeeping */
3451 goto skip_fsfstatus;
3452 }
3453
3454 /* evaluate FSF status in QTCB */
3455 switch (fsf_req->qtcb->header.fsf_status) {
3456
3457 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3459 "0x%016Lx on adapter %s invalid. This may "
3460 "happen in rare circumstances\n",
3461 unit->port->handle,
3462 unit->port->wwpn,
3463 zfcp_get_busid_by_unit(unit));
3464 ZFCP_LOG_DEBUG("status qualifier:\n");
3465 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3466 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3467 sizeof (union fsf_status_qual));
3468 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3469 "fsf_s_phand_nv");
3470 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3472 break;
3473
3474 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3476 "0x%016Lx on port 0x%016Lx on adapter %s is "
3477 "invalid. This may happen occasionally.\n",
3478 unit->handle,
3479 unit->fcp_lun,
3480 unit->port->wwpn,
3481 zfcp_get_busid_by_unit(unit));
3482 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3483 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3484 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3485 sizeof (union fsf_status_qual));
3486 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3487 "fsf_s_lhand_nv");
3488 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3490 break;
3491
3492 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3494 "needs to be reopened\n",
3495 unit->port->wwpn,
3496 zfcp_get_busid_by_unit(unit));
3497 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003498 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3500 ZFCP_STATUS_FSFREQ_RETRY;
3501 break;
3502
3503 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3505 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 /* re-establish link to port */
3507 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3508 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003509 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3511 break;
3512 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 /* ERP strategy will escalate */
3514 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3515 "fsf_sq_ulp");
3516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3517 break;
3518 default:
3519 ZFCP_LOG_NORMAL
3520 ("bug: Wrong status qualifier 0x%x arrived.\n",
3521 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3522 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3523 "fsf_sq_inval:");
3524 debug_exception(
3525 fsf_req->adapter->erp_dbf, 0,
3526 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3527 sizeof (u32));
3528 break;
3529 }
3530 break;
3531
3532 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3534 "closed, port handle 0x%x\n",
3535 unit->fcp_lun,
3536 unit->port->wwpn,
3537 zfcp_get_busid_by_unit(unit),
3538 unit->handle);
3539 /* mark unit as closed */
3540 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3541 retval = 0;
3542 break;
3543
3544 default:
3545 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3546 "(debug info 0x%x)\n",
3547 fsf_req->qtcb->header.fsf_status);
3548 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3549 debug_exception(fsf_req->adapter->erp_dbf, 0,
3550 &fsf_req->qtcb->header.fsf_status,
3551 sizeof (u32));
3552 break;
3553 }
3554
3555 skip_fsfstatus:
3556 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3557 return retval;
3558}
3559
3560/**
3561 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3562 * @adapter: adapter where scsi command is issued
3563 * @unit: unit where command is sent to
3564 * @scsi_cmnd: scsi command to be sent
3565 * @timer: timer to be started when request is initiated
3566 * @req_flags: flags for fsf_request
3567 */
3568int
3569zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3570 struct zfcp_unit *unit,
3571 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003572 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573{
3574 struct zfcp_fsf_req *fsf_req = NULL;
3575 struct fcp_cmnd_iu *fcp_cmnd_iu;
3576 unsigned int sbtype;
3577 unsigned long lock_flags;
3578 int real_bytes = 0;
3579 int retval = 0;
3580 int mask;
3581
3582 /* setup new FSF request */
3583 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3584 adapter->pool.fsf_req_scsi,
3585 &lock_flags, &fsf_req);
3586 if (unlikely(retval < 0)) {
3587 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3588 "for unit 0x%016Lx on port 0x%016Lx on "
3589 "adapter %s\n",
3590 unit->fcp_lun,
3591 unit->port->wwpn,
3592 zfcp_get_busid_by_adapter(adapter));
3593 goto failed_req_create;
3594 }
3595
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003596 zfcp_unit_get(unit);
3597 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003599 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003600 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003601
3602 /* associate SCSI command with FSF request */
3603 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604
3605 /* set handles of unit and its parent port in QTCB */
3606 fsf_req->qtcb->header.lun_handle = unit->handle;
3607 fsf_req->qtcb->header.port_handle = unit->port->handle;
3608
3609 /* FSF does not define the structure of the FCP_CMND IU */
3610 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3611 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3612
3613 /*
3614 * set depending on data direction:
3615 * data direction bits in SBALE (SB Type)
3616 * data direction bits in QTCB
3617 * data direction bits in FCP_CMND IU
3618 */
3619 switch (scsi_cmnd->sc_data_direction) {
3620 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3622 /*
3623 * FIXME(qdio):
3624 * what is the correct type for commands
3625 * without 'real' data buffers?
3626 */
3627 sbtype = SBAL_FLAGS0_TYPE_READ;
3628 break;
3629 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3631 sbtype = SBAL_FLAGS0_TYPE_READ;
3632 fcp_cmnd_iu->rddata = 1;
3633 break;
3634 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3636 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3637 fcp_cmnd_iu->wddata = 1;
3638 break;
3639 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 default:
3641 /*
3642 * dummy, catch this condition earlier
3643 * in zfcp_scsi_queuecommand
3644 */
3645 goto failed_scsi_cmnd;
3646 }
3647
3648 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003649 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650
3651 /* set FCP_LUN in FCP_CMND IU in QTCB */
3652 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3653
3654 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3655
3656 /* set task attributes in FCP_CMND IU in QTCB */
3657 if (likely((scsi_cmnd->device->simple_tags) ||
3658 (atomic_test_mask(mask, &unit->status))))
3659 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3660 else
3661 fcp_cmnd_iu->task_attribute = UNTAGGED;
3662
3663 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3664 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3665 fcp_cmnd_iu->add_fcp_cdb_length
3666 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3667 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3668 "additional FCP_CDB length is 0x%x "
3669 "(shifted right 2 bits)\n",
3670 scsi_cmnd->cmd_len,
3671 fcp_cmnd_iu->add_fcp_cdb_length);
3672 }
3673 /*
3674 * copy SCSI CDB (including additional length, if any) to
3675 * FCP_CDB in FCP_CMND IU in QTCB
3676 */
3677 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3678
3679 /* FCP CMND IU length in QTCB */
3680 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3681 sizeof (struct fcp_cmnd_iu) +
3682 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3683
3684 /* generate SBALEs from data buffer */
3685 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3686 if (unlikely(real_bytes < 0)) {
3687 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3688 ZFCP_LOG_DEBUG(
3689 "Data did not fit into available buffer(s), "
3690 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003691 retval = -EIO;
3692 } else {
3693 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3694 "required. Shutting down unit "
3695 "(adapter %s, port 0x%016Lx, "
3696 "unit 0x%016Lx)\n",
3697 zfcp_get_busid_by_unit(unit),
3698 unit->port->wwpn,
3699 unit->fcp_lun);
3700 zfcp_erp_unit_shutdown(unit, 0);
3701 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 }
3703 goto no_fit;
3704 }
3705
3706 /* set length of FCP data length in FCP_CMND IU in QTCB */
3707 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3708
3709 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3710 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3711 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3712
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003713 if (use_timer)
3714 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3715
3716 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 if (unlikely(retval < 0)) {
3718 ZFCP_LOG_INFO("error: Could not send FCP command request "
3719 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3720 zfcp_get_busid_by_adapter(adapter),
3721 unit->port->wwpn,
3722 unit->fcp_lun);
3723 goto send_failed;
3724 }
3725
3726 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3727 "port 0x%016Lx, unit 0x%016Lx)\n",
3728 zfcp_get_busid_by_adapter(adapter),
3729 unit->port->wwpn,
3730 unit->fcp_lun);
3731 goto success;
3732
3733 send_failed:
3734 no_fit:
3735 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003736 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 zfcp_fsf_req_free(fsf_req);
3738 fsf_req = NULL;
3739 scsi_cmnd->host_scribble = NULL;
3740 success:
3741 failed_req_create:
3742 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3743 return retval;
3744}
3745
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746struct zfcp_fsf_req *
3747zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3748 struct zfcp_unit *unit,
3749 u8 tm_flags, int req_flags)
3750{
3751 struct zfcp_fsf_req *fsf_req = NULL;
3752 int retval = 0;
3753 struct fcp_cmnd_iu *fcp_cmnd_iu;
3754 unsigned long lock_flags;
3755 volatile struct qdio_buffer_element *sbale;
3756
3757 /* setup new FSF request */
3758 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3759 adapter->pool.fsf_req_scsi,
3760 &lock_flags, &fsf_req);
3761 if (retval < 0) {
3762 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3763 "management) request for adapter %s, port "
3764 " 0x%016Lx, unit 0x%016Lx.\n",
3765 zfcp_get_busid_by_adapter(adapter),
3766 unit->port->wwpn, unit->fcp_lun);
3767 goto out;
3768 }
3769
3770 /*
3771 * Used to decide on proper handler in the return path,
3772 * could be either zfcp_fsf_send_fcp_command_task_handler or
3773 * zfcp_fsf_send_fcp_command_task_management_handler */
3774
3775 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3776
3777 /*
3778 * hold a pointer to the unit being target of this
3779 * task management request
3780 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003781 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
3783 /* set FSF related fields in QTCB */
3784 fsf_req->qtcb->header.lun_handle = unit->handle;
3785 fsf_req->qtcb->header.port_handle = unit->port->handle;
3786 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003787 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3789 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3790
3791 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3792 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3793 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3794
3795 /* set FCP related fields in FCP_CMND IU in QTCB */
3796 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3797 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3798 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3799 fcp_cmnd_iu->task_management_flags = tm_flags;
3800
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003801 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3802 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3805 "management) on adapter %s, port 0x%016Lx for "
3806 "unit LUN 0x%016Lx\n",
3807 zfcp_get_busid_by_adapter(adapter),
3808 unit->port->wwpn,
3809 unit->fcp_lun);
3810 zfcp_fsf_req_free(fsf_req);
3811 fsf_req = NULL;
3812 goto out;
3813 }
3814
3815 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3816 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3817 "tm_flags=0x%x)\n",
3818 zfcp_get_busid_by_adapter(adapter),
3819 unit->port->wwpn,
3820 unit->fcp_lun,
3821 tm_flags);
3822 out:
3823 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3824 return fsf_req;
3825}
3826
3827/*
3828 * function: zfcp_fsf_send_fcp_command_handler
3829 *
3830 * purpose: is called for finished Send FCP Command
3831 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003832 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 */
3834static int
3835zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3836{
3837 int retval = -EINVAL;
3838 struct zfcp_unit *unit;
3839 struct fsf_qtcb_header *header;
3840 u16 subtable, rule, counter;
3841
3842 header = &fsf_req->qtcb->header;
3843
3844 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003845 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003847 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848
3849 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3850 /* go directly to calls of special handlers */
3851 goto skip_fsfstatus;
3852 }
3853
3854 /* evaluate FSF status in QTCB */
3855 switch (header->fsf_status) {
3856
3857 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3859 "0x%016Lx on adapter %s invalid\n",
3860 unit->port->handle,
3861 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3862 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3863 (char *) &header->fsf_status_qual,
3864 sizeof (union fsf_status_qual));
3865 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3866 "fsf_s_phand_nv");
3867 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3868 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3869 break;
3870
3871 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3873 "0x%016Lx on port 0x%016Lx on adapter %s is "
3874 "invalid. This may happen occasionally.\n",
3875 unit->handle,
3876 unit->fcp_lun,
3877 unit->port->wwpn,
3878 zfcp_get_busid_by_unit(unit));
3879 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3880 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3881 (char *) &header->fsf_status_qual,
3882 sizeof (union fsf_status_qual));
3883 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3884 "fsf_s_uhand_nv");
3885 zfcp_erp_port_reopen(unit->port, 0);
3886 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3887 break;
3888
3889 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3891 "unexpectedly. (adapter %s, port 0x%016Lx, "
3892 "unit 0x%016Lx)\n",
3893 unit->port->handle,
3894 zfcp_get_busid_by_unit(unit),
3895 unit->port->wwpn,
3896 unit->fcp_lun);
3897 ZFCP_LOG_NORMAL("status qualifier:\n");
3898 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3899 (char *) &header->fsf_status_qual,
3900 sizeof (union fsf_status_qual));
3901 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3902 "fsf_s_hand_mis");
3903 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3905 break;
3906
3907 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003908 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3909 "class %d.\n",
3910 zfcp_get_busid_by_unit(unit),
3911 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 /* stop operation for this adapter */
3913 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3914 "fsf_s_class_nsup");
3915 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3917 break;
3918
3919 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3921 "adapter %s does not have correct unit "
3922 "handle 0x%x\n",
3923 unit->fcp_lun,
3924 unit->port->wwpn,
3925 zfcp_get_busid_by_unit(unit),
3926 unit->handle);
3927 ZFCP_LOG_DEBUG("status qualifier:\n");
3928 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3929 (char *) &header->fsf_status_qual,
3930 sizeof (union fsf_status_qual));
3931 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3932 "fsf_s_fcp_lun_nv");
3933 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3935 break;
3936
3937 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3939 "unit 0x%016Lx on port 0x%016Lx on "
3940 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3941 zfcp_get_busid_by_unit(unit));
3942 for (counter = 0; counter < 2; counter++) {
3943 subtable = header->fsf_status_qual.halfword[counter * 2];
3944 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3945 switch (subtable) {
3946 case FSF_SQ_CFDC_SUBTABLE_OS:
3947 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3948 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3949 case FSF_SQ_CFDC_SUBTABLE_LUN:
3950 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3951 zfcp_act_subtable_type[subtable], rule);
3952 break;
3953 }
3954 }
3955 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3956 zfcp_erp_unit_access_denied(unit);
3957 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3958 break;
3959
3960 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3962 "0x%016Lx on port 0x%016Lx on adapter %s "
3963 "(debug info %d)\n",
3964 unit->fcp_lun,
3965 unit->port->wwpn,
3966 zfcp_get_busid_by_unit(unit),
3967 fsf_req->qtcb->bottom.io.data_direction);
3968 /* stop operation for this adapter */
3969 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3970 "fsf_s_dir_ind_nv");
3971 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3973 break;
3974
3975 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 ZFCP_LOG_NORMAL
3977 ("bug: An invalid control-data-block length field "
3978 "was found in a command for unit 0x%016Lx on port "
3979 "0x%016Lx on adapter %s " "(debug info %d)\n",
3980 unit->fcp_lun, unit->port->wwpn,
3981 zfcp_get_busid_by_unit(unit),
3982 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3983 /* stop operation for this adapter */
3984 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3985 "fsf_s_cmd_len_nv");
3986 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3988 break;
3989
3990 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3992 "needs to be reopened\n",
3993 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3994 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003995 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3997 ZFCP_STATUS_FSFREQ_RETRY;
3998 break;
3999
4000 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
4002 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
4003 zfcp_get_busid_by_unit(unit),
4004 unit->port->wwpn, unit->fcp_lun);
4005 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02004006 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
4008 | ZFCP_STATUS_FSFREQ_RETRY;
4009 break;
4010
4011 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 switch (header->fsf_status_qual.word[0]) {
4013 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 /* re-establish link to port */
4015 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4016 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02004017 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 break;
4019 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 /* FIXME(hw) need proper specs for proper action */
4021 /* let scsi stack deal with retries and escalation */
4022 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4023 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 break;
4025 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02004027 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 header->fsf_status_qual.word[0]);
4029 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4030 "fsf_sq_inval:");
4031 debug_exception(fsf_req->adapter->erp_dbf, 0,
4032 &header->fsf_status_qual.word[0],
4033 sizeof(u32));
4034 break;
4035 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02004036 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 break;
4038
4039 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 break;
4041
4042 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 break;
4044
4045 default:
4046 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4047 debug_exception(fsf_req->adapter->erp_dbf, 0,
4048 &header->fsf_status, sizeof(u32));
4049 break;
4050 }
4051
4052 skip_fsfstatus:
4053 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4054 retval =
4055 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4056 } else {
4057 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004058 fsf_req->unit = NULL;
4059 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 }
4061 return retval;
4062}
4063
4064/*
4065 * function: zfcp_fsf_send_fcp_command_task_handler
4066 *
4067 * purpose: evaluates FCP_RSP IU
4068 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004069 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 */
4071static int
4072zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4073{
4074 int retval = 0;
4075 struct scsi_cmnd *scpnt;
4076 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4077 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4078 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4079 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4080 u32 sns_len;
4081 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4082 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004083 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084
4085 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004086 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 if (unlikely(!scpnt)) {
4088 ZFCP_LOG_DEBUG
4089 ("Command with fsf_req %p is not associated to "
4090 "a scsi command anymore. Aborted?\n", fsf_req);
4091 goto out;
4092 }
4093 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4094 /* FIXME: (design) mid-layer should handle DID_ABORT like
4095 * DID_SOFT_ERROR by retrying the request for devices
4096 * that allow retries.
4097 */
4098 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4099 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4100 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4101 goto skip_fsfstatus;
4102 }
4103
4104 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4105 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4106 set_host_byte(&scpnt->result, DID_ERROR);
4107 goto skip_fsfstatus;
4108 }
4109
4110 /* set message byte of result in SCSI command */
4111 scpnt->result |= COMMAND_COMPLETE << 8;
4112
4113 /*
4114 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4115 * of result in SCSI command
4116 */
4117 scpnt->result |= fcp_rsp_iu->scsi_status;
4118 if (unlikely(fcp_rsp_iu->scsi_status)) {
4119 /* DEBUG */
4120 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4121 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4122 scpnt->cmnd, scpnt->cmd_len);
4123 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4124 fcp_rsp_iu->scsi_status);
4125 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4126 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4127 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4128 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4129 fcp_rsp_iu->fcp_sns_len);
4130 }
4131
4132 /* check FCP_RSP_INFO */
4133 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4134 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4135 switch (fcp_rsp_info[3]) {
4136 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 /* ok, continue */
4138 ZFCP_LOG_TRACE("no failure or Task Management "
4139 "Function complete\n");
4140 set_host_byte(&scpnt->result, DID_OK);
4141 break;
4142 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 /* hardware bug */
4144 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4145 "that the fibrechannel protocol data "
4146 "length differs from the burst length. "
4147 "The problem occured on unit 0x%016Lx "
4148 "on port 0x%016Lx on adapter %s",
4149 unit->fcp_lun,
4150 unit->port->wwpn,
4151 zfcp_get_busid_by_unit(unit));
4152 /* dump SCSI CDB as prepared by zfcp */
4153 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4154 (char *) &fsf_req->qtcb->
4155 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 set_host_byte(&scpnt->result, DID_ERROR);
4157 goto skip_fsfstatus;
4158 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 /* driver or hardware bug */
4160 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4161 "that the fibrechannel protocol data "
4162 "fields were incorrectly set up. "
4163 "The problem occured on the unit "
4164 "0x%016Lx on port 0x%016Lx on "
4165 "adapter %s",
4166 unit->fcp_lun,
4167 unit->port->wwpn,
4168 zfcp_get_busid_by_unit(unit));
4169 /* dump SCSI CDB as prepared by zfcp */
4170 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4171 (char *) &fsf_req->qtcb->
4172 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4173 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 goto skip_fsfstatus;
4175 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 /* hardware bug */
4177 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4178 "that conflicting values for the "
4179 "fibrechannel payload offset from the "
4180 "header were found. "
4181 "The problem occured on unit 0x%016Lx "
4182 "on port 0x%016Lx on adapter %s.\n",
4183 unit->fcp_lun,
4184 unit->port->wwpn,
4185 zfcp_get_busid_by_unit(unit));
4186 /* dump SCSI CDB as prepared by zfcp */
4187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4188 (char *) &fsf_req->qtcb->
4189 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 set_host_byte(&scpnt->result, DID_ERROR);
4191 goto skip_fsfstatus;
4192 default:
4193 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4194 "code was detected for a command. "
4195 "The problem occured on the unit "
4196 "0x%016Lx on port 0x%016Lx on "
4197 "adapter %s (debug info 0x%x)\n",
4198 unit->fcp_lun,
4199 unit->port->wwpn,
4200 zfcp_get_busid_by_unit(unit),
4201 fcp_rsp_info[3]);
4202 /* dump SCSI CDB as prepared by zfcp */
4203 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4204 (char *) &fsf_req->qtcb->
4205 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004207 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 }
4209 }
4210
4211 /* check for sense data */
4212 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4213 sns_len = FSF_FCP_RSP_SIZE -
4214 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4215 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4216 sns_len);
4217 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4218 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4219 SCSI_SENSE_BUFFERSIZE);
4220 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4221 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4222 scpnt->result);
4223 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4224 (void *) &scpnt->cmnd, scpnt->cmd_len);
4225
4226 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4227 fcp_rsp_iu->fcp_sns_len);
4228 memcpy(&scpnt->sense_buffer,
4229 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4230 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4231 (void *) &scpnt->sense_buffer, sns_len);
4232 }
4233
4234 /* check for overrun */
4235 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4236 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4237 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4238 "The response data length is "
4239 "%d, the original length was %d.\n",
4240 unit->fcp_lun,
4241 unit->port->wwpn,
4242 zfcp_get_busid_by_unit(unit),
4243 fcp_rsp_iu->fcp_resid,
4244 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4245 }
4246
4247 /* check for underrun */
4248 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4249 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4250 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4251 "The response data length is "
4252 "%d, the original length was %d.\n",
4253 unit->fcp_lun,
4254 unit->port->wwpn,
4255 zfcp_get_busid_by_unit(unit),
4256 fcp_rsp_iu->fcp_resid,
4257 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4258
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004259 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4260 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4261 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004262 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 }
4264
4265 skip_fsfstatus:
4266 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4267
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004268 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004269 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004270 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004271 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004272 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004273 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274
4275 /* cleanup pointer (need this especially for abort) */
4276 scpnt->host_scribble = NULL;
4277
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 (scpnt->scsi_done) (scpnt);
4280
4281 /*
4282 * We must hold this lock until scsi_done has been called.
4283 * Otherwise we may call scsi_done after abort regarding this
4284 * command has completed.
4285 * Note: scsi_done must not block!
4286 */
4287 out:
4288 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4289 return retval;
4290}
4291
4292/*
4293 * function: zfcp_fsf_send_fcp_command_task_management_handler
4294 *
4295 * purpose: evaluates FCP_RSP IU
4296 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004297 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 */
4299static int
4300zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4301{
4302 int retval = 0;
4303 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4304 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4305 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004306 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4309 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4310 goto skip_fsfstatus;
4311 }
4312
4313 /* check FCP_RSP_INFO */
4314 switch (fcp_rsp_info[3]) {
4315 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 /* ok, continue */
4317 ZFCP_LOG_DEBUG("no failure or Task Management "
4318 "Function complete\n");
4319 break;
4320 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4322 "is not supported on the target device "
4323 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4324 unit->fcp_lun,
4325 unit->port->wwpn,
4326 zfcp_get_busid_by_unit(unit));
4327 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4328 break;
4329 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4331 "failed to complete successfully. "
4332 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4333 unit->fcp_lun,
4334 unit->port->wwpn,
4335 zfcp_get_busid_by_unit(unit));
4336 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4337 break;
4338 default:
4339 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4340 "code was detected for a command. "
4341 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4342 "(debug info 0x%x)\n",
4343 unit->fcp_lun,
4344 unit->port->wwpn,
4345 zfcp_get_busid_by_unit(unit),
4346 fcp_rsp_info[3]);
4347 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4348 }
4349
4350 skip_fsfstatus:
4351 return retval;
4352}
4353
4354
4355/*
4356 * function: zfcp_fsf_control_file
4357 *
4358 * purpose: Initiator of the control file upload/download FSF requests
4359 *
4360 * returns: 0 - FSF request is successfuly created and queued
4361 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4362 * -EINVAL - Invalid direction specified
4363 * -ENOMEM - Insufficient memory
4364 * -EPERM - Cannot create FSF request or place it in QDIO queue
4365 */
4366int
4367zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4368 struct zfcp_fsf_req **fsf_req_ptr,
4369 u32 fsf_command,
4370 u32 option,
4371 struct zfcp_sg_list *sg_list)
4372{
4373 struct zfcp_fsf_req *fsf_req;
4374 struct fsf_qtcb_bottom_support *bottom;
4375 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 unsigned long lock_flags;
4377 int req_flags = 0;
4378 int direction;
4379 int retval = 0;
4380
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004381 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4383 zfcp_get_busid_by_adapter(adapter));
4384 retval = -EOPNOTSUPP;
4385 goto out;
4386 }
4387
4388 switch (fsf_command) {
4389
4390 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4391 direction = SBAL_FLAGS0_TYPE_WRITE;
4392 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4393 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4394 req_flags = ZFCP_WAIT_FOR_SBAL;
4395 break;
4396
4397 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4398 direction = SBAL_FLAGS0_TYPE_READ;
4399 break;
4400
4401 default:
4402 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4403 retval = -EINVAL;
4404 goto out;
4405 }
4406
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4408 NULL, &lock_flags, &fsf_req);
4409 if (retval < 0) {
4410 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4411 "adapter %s\n",
4412 zfcp_get_busid_by_adapter(adapter));
4413 retval = -EPERM;
4414 goto unlock_queue_lock;
4415 }
4416
4417 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4418 sbale[0].flags |= direction;
4419
4420 bottom = &fsf_req->qtcb->bottom.support;
4421 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4422 bottom->option = option;
4423
4424 if (sg_list->count > 0) {
4425 int bytes;
4426
4427 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4428 sg_list->sg, sg_list->count,
4429 ZFCP_MAX_SBALS_PER_REQ);
4430 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4431 ZFCP_LOG_INFO(
4432 "error: Could not create sufficient number of "
4433 "SBALS for an FSF request to the adapter %s\n",
4434 zfcp_get_busid_by_adapter(adapter));
4435 retval = -ENOMEM;
4436 goto free_fsf_req;
4437 }
4438 } else
4439 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4440
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004441 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4442 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 if (retval < 0) {
4444 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4445 "(adapter %s)\n",
4446 zfcp_get_busid_by_adapter(adapter));
4447 retval = -EPERM;
4448 goto free_fsf_req;
4449 }
4450 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4451
4452 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4453 "adapter %s\n",
4454 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4455 "download" : "upload",
4456 zfcp_get_busid_by_adapter(adapter));
4457
4458 wait_event(fsf_req->completion_wq,
4459 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4460
4461 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004462 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463
4464 free_fsf_req:
4465 zfcp_fsf_req_free(fsf_req);
4466 unlock_queue_lock:
4467 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 out:
4469 return retval;
4470}
4471
4472
4473/*
4474 * function: zfcp_fsf_control_file_handler
4475 *
4476 * purpose: Handler of the control file upload/download FSF requests
4477 *
4478 * returns: 0 - FSF request successfuly processed
4479 * -EAGAIN - Operation has to be repeated because of a temporary problem
4480 * -EACCES - There is no permission to execute an operation
4481 * -EPERM - The control file is not in a right format
4482 * -EIO - There is a problem with the FCP adapter
4483 * -EINVAL - Invalid operation
4484 * -EFAULT - User space memory I/O operation fault
4485 */
4486static int
4487zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4488{
4489 struct zfcp_adapter *adapter = fsf_req->adapter;
4490 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4491 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4492 int retval = 0;
4493
4494 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4495 retval = -EINVAL;
4496 goto skip_fsfstatus;
4497 }
4498
4499 switch (header->fsf_status) {
4500
4501 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 ZFCP_LOG_NORMAL(
4503 "The FSF request has been successfully completed "
4504 "on the adapter %s\n",
4505 zfcp_get_busid_by_adapter(adapter));
4506 break;
4507
4508 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4510 switch (header->fsf_status_qual.word[0]) {
4511
6f71d9b2005-04-10 23:04:28 -05004512 case FSF_SQ_CFDC_HARDENED_ON_SE:
4513 ZFCP_LOG_NORMAL(
4514 "CFDC on the adapter %s has being "
4515 "hardened on primary and secondary SE\n",
4516 zfcp_get_busid_by_adapter(adapter));
4517 break;
4518
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4520 ZFCP_LOG_NORMAL(
4521 "CFDC of the adapter %s could not "
4522 "be saved on the SE\n",
4523 zfcp_get_busid_by_adapter(adapter));
4524 break;
4525
4526 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4527 ZFCP_LOG_NORMAL(
4528 "CFDC of the adapter %s could not "
4529 "be copied to the secondary SE\n",
4530 zfcp_get_busid_by_adapter(adapter));
4531 break;
4532
4533 default:
4534 ZFCP_LOG_NORMAL(
4535 "CFDC could not be hardened "
4536 "on the adapter %s\n",
4537 zfcp_get_busid_by_adapter(adapter));
4538 }
4539 }
4540 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4541 retval = -EAGAIN;
4542 break;
4543
4544 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 ZFCP_LOG_NORMAL(
4546 "Adapter %s does not accept privileged commands\n",
4547 zfcp_get_busid_by_adapter(adapter));
4548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4549 retval = -EACCES;
4550 break;
4551
4552 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 ZFCP_LOG_NORMAL(
4554 "Error at position %d in the CFDC, "
4555 "CFDC is discarded by the adapter %s\n",
4556 header->fsf_status_qual.word[0],
4557 zfcp_get_busid_by_adapter(adapter));
4558 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4559 retval = -EPERM;
4560 break;
4561
4562 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 ZFCP_LOG_NORMAL(
4564 "Adapter %s cannot harden the control file, "
4565 "file is discarded\n",
4566 zfcp_get_busid_by_adapter(adapter));
4567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4568 retval = -EIO;
4569 break;
4570
4571 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 ZFCP_LOG_NORMAL(
4573 "Control file is too large, file is discarded "
4574 "by the adapter %s\n",
4575 zfcp_get_busid_by_adapter(adapter));
4576 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4577 retval = -EIO;
4578 break;
4579
4580 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4582 ZFCP_LOG_NORMAL(
4583 "CFDC has been discarded by the adapter %s, "
4584 "because activation would impact "
4585 "%d active connection(s)\n",
4586 zfcp_get_busid_by_adapter(adapter),
4587 header->fsf_status_qual.word[0]);
4588 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4589 retval = -EIO;
4590 break;
4591
4592 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4594 ZFCP_LOG_NORMAL(
4595 "CFDC has been activated on the adapter %s, "
4596 "but activation has impacted "
4597 "%d active connection(s)\n",
4598 zfcp_get_busid_by_adapter(adapter),
4599 header->fsf_status_qual.word[0]);
4600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4601 retval = -EIO;
4602 break;
4603
4604 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4606 "op_subtype=0x%x)\n",
4607 zfcp_get_busid_by_adapter(adapter),
4608 bottom->operation_subtype);
4609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4610 retval = -EINVAL;
4611 break;
4612
4613 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614 ZFCP_LOG_NORMAL(
4615 "Invalid option 0x%x has been specified "
4616 "in QTCB bottom sent to the adapter %s\n",
4617 bottom->option,
4618 zfcp_get_busid_by_adapter(adapter));
4619 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4620 retval = -EINVAL;
4621 break;
4622
4623 default:
4624 ZFCP_LOG_NORMAL(
4625 "bug: An unknown/unexpected FSF status 0x%08x "
4626 "was presented on the adapter %s\n",
4627 header->fsf_status,
4628 zfcp_get_busid_by_adapter(adapter));
4629 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4630 debug_exception(fsf_req->adapter->erp_dbf, 0,
4631 &header->fsf_status_qual.word[0], sizeof(u32));
4632 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4633 retval = -EINVAL;
4634 break;
4635 }
4636
4637skip_fsfstatus:
4638 return retval;
4639}
4640
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641static inline int
4642zfcp_fsf_req_sbal_check(unsigned long *flags,
4643 struct zfcp_qdio_queue *queue, int needed)
4644{
4645 write_lock_irqsave(&queue->queue_lock, *flags);
4646 if (likely(atomic_read(&queue->free_count) >= needed))
4647 return 1;
4648 write_unlock_irqrestore(&queue->queue_lock, *flags);
4649 return 0;
4650}
4651
4652/*
4653 * set qtcb pointer in fsf_req and initialize QTCB
4654 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004655static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004656zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657{
4658 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004659 fsf_req->qtcb->prefix.req_seq_no =
4660 fsf_req->adapter->fsf_req_seq_no;
4661 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004663 fsf_req->qtcb->prefix.qtcb_type =
4664 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004666 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004667 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 }
4669}
4670
4671/**
4672 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4673 * @adapter: adapter for which request queue is examined
4674 * @req_flags: flags indicating whether to wait for needed SBAL or not
4675 * @lock_flags: lock_flags if queue_lock is taken
4676 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4677 * Locks: lock adapter->request_queue->queue_lock on success
4678 */
4679static int
4680zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4681 unsigned long *lock_flags)
4682{
4683 long ret;
4684 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4685
4686 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4687 ret = wait_event_interruptible_timeout(adapter->request_wq,
4688 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4689 ZFCP_SBAL_TIMEOUT);
4690 if (ret < 0)
4691 return ret;
4692 if (!ret)
4693 return -EIO;
4694 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4695 return -EIO;
4696
4697 return 0;
4698}
4699
4700/*
4701 * function: zfcp_fsf_req_create
4702 *
4703 * purpose: create an FSF request at the specified adapter and
4704 * setup common fields
4705 *
4706 * returns: -ENOMEM if there was insufficient memory for a request
4707 * -EIO if no qdio buffers could be allocate to the request
4708 * -EINVAL/-EPERM on bug conditions in req_dequeue
4709 * 0 in success
4710 *
4711 * note: The created request is returned by reference.
4712 *
4713 * locks: lock of concerned request queue must not be held,
4714 * but is held on completion (write, irqsave)
4715 */
4716int
4717zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4718 mempool_t *pool, unsigned long *lock_flags,
4719 struct zfcp_fsf_req **fsf_req_p)
4720{
4721 volatile struct qdio_buffer_element *sbale;
4722 struct zfcp_fsf_req *fsf_req = NULL;
4723 int ret = 0;
4724 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4725
4726 /* allocate new FSF request */
4727 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4728 if (unlikely(NULL == fsf_req)) {
4729 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4730 "the outbound (send) queue.\n");
4731 ret = -ENOMEM;
4732 goto failed_fsf_req;
4733 }
4734
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004735 fsf_req->adapter = adapter;
4736 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004737 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004738 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004740 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 this request completion */
4742 init_waitqueue_head(&fsf_req->completion_wq);
4743
4744 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004745 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004747
4748 /* this is serialized (we are holding req_queue-lock of adapter) */
4749 if (adapter->req_no == 0)
4750 adapter->req_no++;
4751 fsf_req->req_id = adapter->req_no++;
4752
4753 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754
4755 /*
4756 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4757 * if it is not set (see also *_open_qdio and *_close_qdio).
4758 */
4759
4760 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4761 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4762 ret = -EIO;
4763 goto failed_sbals;
4764 }
4765
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004766 if (fsf_req->qtcb) {
4767 fsf_req->seq_no = adapter->fsf_req_seq_no;
4768 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 fsf_req->sbal_number = 1;
4771 fsf_req->sbal_first = req_queue->free_index;
4772 fsf_req->sbal_curr = req_queue->free_index;
4773 fsf_req->sbale_curr = 1;
4774
4775 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4776 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4777 }
4778
4779 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4780
4781 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004782 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4784 if (likely(fsf_req->qtcb != NULL)) {
4785 sbale[1].addr = (void *) fsf_req->qtcb;
4786 sbale[1].length = sizeof(struct fsf_qtcb);
4787 }
4788
4789 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4790 fsf_req->sbal_number, fsf_req->sbal_first);
4791
4792 goto success;
4793
4794 failed_sbals:
4795/* dequeue new FSF request previously enqueued */
4796 zfcp_fsf_req_free(fsf_req);
4797 fsf_req = NULL;
4798
4799 failed_fsf_req:
4800 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4801 success:
4802 *fsf_req_p = fsf_req;
4803 return ret;
4804}
4805
4806/*
4807 * function: zfcp_fsf_req_send
4808 *
4809 * purpose: start transfer of FSF request via QDIO
4810 *
4811 * returns: 0 - request transfer succesfully started
4812 * !0 - start of request transfer failed
4813 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004814static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815{
4816 struct zfcp_adapter *adapter;
4817 struct zfcp_qdio_queue *req_queue;
4818 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004819 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 int new_distance_from_int;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004821 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 int retval = 0;
4823
4824 adapter = fsf_req->adapter;
4825 req_queue = &adapter->request_queue,
4826
4827
4828 /* FIXME(debug): remove it later */
4829 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4830 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4831 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4832 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4833 sbale[1].length);
4834
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004835 /* put allocated FSF request into hash table */
4836 spin_lock(&adapter->req_list_lock);
4837 zfcp_reqlist_add(adapter, fsf_req);
4838 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004840 inc_seq_no = (fsf_req->qtcb != NULL);
4841
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 ZFCP_LOG_TRACE("request queue of adapter %s: "
4843 "next free SBAL is %i, %i free SBALs\n",
4844 zfcp_get_busid_by_adapter(adapter),
4845 req_queue->free_index,
4846 atomic_read(&req_queue->free_count));
4847
4848 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4849 "index_in_queue=%i, count=%i, buffers=%p\n",
4850 zfcp_get_busid_by_adapter(adapter),
4851 QDIO_FLAG_SYNC_OUTPUT,
4852 0, fsf_req->sbal_first, fsf_req->sbal_number,
4853 &req_queue->buffer[fsf_req->sbal_first]);
4854
4855 /*
4856 * adjust the number of free SBALs in request queue as well as
4857 * position of first one
4858 */
4859 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4860 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4861 req_queue->free_index += fsf_req->sbal_number; /* increase */
4862 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4863 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4864
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004865 fsf_req->issued = get_clock();
4866
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 retval = do_QDIO(adapter->ccw_device,
4868 QDIO_FLAG_SYNC_OUTPUT,
4869 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4870
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004871 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4872 dbg_tmp[1] = (u64) retval;
4873 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4874
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 if (unlikely(retval)) {
4876 /* Queues are down..... */
4877 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004878 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004879 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004880 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004881 spin_unlock(&adapter->req_list_lock);
4882 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 zfcp_qdio_zero_sbals(req_queue->buffer,
4884 fsf_req->sbal_first, fsf_req->sbal_number);
4885 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004886 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4888 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004889 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 } else {
4891 req_queue->distance_from_int = new_distance_from_int;
4892 /*
4893 * increase FSF sequence counter -
4894 * this must only be done for request successfully enqueued to
4895 * QDIO this rejected requests may be cleaned up by calling
4896 * routines resulting in missing sequence counter values
4897 * otherwise,
4898 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004899
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004901 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004903
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004905 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 }
4907 return retval;
4908}
4909
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910#undef ZFCP_LOG_AREA