blob: e697b1cb6d27d228e1ba30b46ce02b716dcb179a [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
1119 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1120 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1121 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1122
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001123 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 /* set handles of unit and its parent port in QTCB */
1126 fsf_req->qtcb->header.lun_handle = unit->handle;
1127 fsf_req->qtcb->header.port_handle = unit->port->handle;
1128
1129 /* set handle of request which should be aborted */
1130 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1131
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001132 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1133 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 ZFCP_LOG_INFO("error: Failed to send abort command request "
1136 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1137 zfcp_get_busid_by_adapter(adapter),
1138 unit->port->wwpn, unit->fcp_lun);
1139 zfcp_fsf_req_free(fsf_req);
1140 fsf_req = NULL;
1141 goto out;
1142 }
1143
1144 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001145 "(adapter%s, port d_id=0x%06x, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 "unit x%016Lx, old_req_id=0x%lx)\n",
1147 zfcp_get_busid_by_adapter(adapter),
1148 unit->port->d_id,
1149 unit->fcp_lun, old_req_id);
1150 out:
1151 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1152 return fsf_req;
1153}
1154
1155/*
1156 * function: zfcp_fsf_abort_fcp_command_handler
1157 *
1158 * purpose: is called for finished Abort FCP Command request
1159 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001160 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 */
1162static int
1163zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1164{
1165 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001166 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001167 union fsf_status_qual *fsf_stat_qual =
1168 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1171 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1172 goto skip_fsfstatus;
1173 }
1174
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001175 unit = (struct zfcp_unit *) new_fsf_req->data;
1176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 /* evaluate FSF status in QTCB */
1178 switch (new_fsf_req->qtcb->header.fsf_status) {
1179
1180 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001181 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1183 "fsf_s_phand_nv0");
1184 /*
1185 * In this case a command that was sent prior to a port
1186 * reopen was aborted (handles are different). This is
1187 * fine.
1188 */
1189 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1191 "port 0x%016Lx on adapter %s invalid. "
1192 "This may happen occasionally.\n",
1193 unit->port->handle,
1194 unit->port->wwpn,
1195 zfcp_get_busid_by_unit(unit));
1196 ZFCP_LOG_INFO("status qualifier:\n");
1197 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1198 (char *) &new_fsf_req->qtcb->header.
1199 fsf_status_qual,
1200 sizeof (union fsf_status_qual));
1201 /* Let's hope this sorts out the mess */
1202 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1203 "fsf_s_phand_nv1");
1204 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1205 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1206 }
1207 break;
1208
1209 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001210 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1212 "fsf_s_lhand_nv0");
1213 /*
1214 * In this case a command that was sent prior to a unit
1215 * reopen was aborted (handles are different).
1216 * This is fine.
1217 */
1218 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 ZFCP_LOG_INFO
1220 ("Warning: Temporary LUN identifier 0x%x of LUN "
1221 "0x%016Lx on port 0x%016Lx on adapter %s is "
1222 "invalid. This may happen in rare cases. "
1223 "Trying to re-establish link.\n",
1224 unit->handle,
1225 unit->fcp_lun,
1226 unit->port->wwpn,
1227 zfcp_get_busid_by_unit(unit));
1228 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1229 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1230 (char *) &new_fsf_req->qtcb->header.
1231 fsf_status_qual,
1232 sizeof (union fsf_status_qual));
1233 /* Let's hope this sorts out the mess */
1234 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1235 "fsf_s_lhand_nv1");
1236 zfcp_erp_port_reopen(unit->port, 0);
1237 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1238 }
1239 break;
1240
1241 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 retval = 0;
1243 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1244 "fsf_s_no_exist");
1245 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1246 break;
1247
1248 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1250 "be reopened\n", unit->port->wwpn,
1251 zfcp_get_busid_by_unit(unit));
1252 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1253 "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001254 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1256 | ZFCP_STATUS_FSFREQ_RETRY;
1257 break;
1258
1259 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 ZFCP_LOG_INFO(
1261 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1262 "to be reopened\n",
1263 unit->fcp_lun, unit->port->wwpn,
1264 zfcp_get_busid_by_unit(unit));
1265 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001266 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1268 | ZFCP_STATUS_FSFREQ_RETRY;
1269 break;
1270
1271 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1273 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1275 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001276 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1278 break;
1279 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 /* SCSI stack will escalate */
1281 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1282 "fsf_sq_ulp");
1283 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1284 break;
1285 default:
1286 ZFCP_LOG_NORMAL
1287 ("bug: Wrong status qualifier 0x%x arrived.\n",
1288 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1289 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1290 "fsf_sq_inval:");
1291 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1292 &new_fsf_req->qtcb->header.
1293 fsf_status_qual.word[0], sizeof (u32));
1294 break;
1295 }
1296 break;
1297
1298 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 retval = 0;
1300 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1301 break;
1302
1303 default:
1304 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1305 "(debug info 0x%x)\n",
1306 new_fsf_req->qtcb->header.fsf_status);
1307 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1308 "fsf_s_inval:");
1309 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1310 &new_fsf_req->qtcb->header.fsf_status,
1311 sizeof (u32));
1312 break;
1313 }
1314 skip_fsfstatus:
1315 return retval;
1316}
1317
1318/**
1319 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1320 * one SBALE
1321 * Two scatter-gather lists are passed, one for the reqeust and one for the
1322 * response.
1323 */
1324static inline int
1325zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1326 struct scatterlist *resp, int resp_count)
1327{
1328 return ((req_count == 1) &&
1329 (resp_count == 1) &&
1330 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1331 PAGE_MASK) ==
1332 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1333 req[0].length - 1) & PAGE_MASK)) &&
1334 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1335 PAGE_MASK) ==
1336 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1337 resp[0].length - 1) & PAGE_MASK)));
1338}
1339
1340/**
1341 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1342 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1343 * the request
1344 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1345 * a struct zfcp_fsf_req
1346 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1347 * is sent within error recovery
1348 */
1349int
1350zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1351 struct zfcp_erp_action *erp_action)
1352{
1353 volatile struct qdio_buffer_element *sbale;
1354 struct zfcp_port *port;
1355 struct zfcp_adapter *adapter;
1356 struct zfcp_fsf_req *fsf_req;
1357 unsigned long lock_flags;
1358 int bytes;
1359 int ret = 0;
1360
1361 port = ct->port;
1362 adapter = port->adapter;
1363
1364 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1365 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1366 pool, &lock_flags, &fsf_req);
1367 if (ret < 0) {
1368 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1369 "adapter: %s\n",
1370 zfcp_get_busid_by_adapter(adapter));
1371 goto failed_req;
1372 }
1373
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1375 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1376 ct->resp, ct->resp_count)){
1377 /* both request buffer and response buffer
1378 fit into one sbale each */
1379 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1380 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1381 sbale[2].length = ct->req[0].length;
1382 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1383 sbale[3].length = ct->resp[0].length;
1384 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001385 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1387 /* try to use chained SBALs */
1388 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1389 SBAL_FLAGS0_TYPE_WRITE_READ,
1390 ct->req, ct->req_count,
1391 ZFCP_MAX_SBALS_PER_CT_REQ);
1392 if (bytes <= 0) {
1393 ZFCP_LOG_INFO("error: creation of CT request failed "
1394 "on adapter %s\n",
1395 zfcp_get_busid_by_adapter(adapter));
1396 if (bytes == 0)
1397 ret = -ENOMEM;
1398 else
1399 ret = bytes;
1400
1401 goto failed_send;
1402 }
1403 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1404 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1405 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1406 SBAL_FLAGS0_TYPE_WRITE_READ,
1407 ct->resp, ct->resp_count,
1408 ZFCP_MAX_SBALS_PER_CT_REQ);
1409 if (bytes <= 0) {
1410 ZFCP_LOG_INFO("error: creation of CT request failed "
1411 "on adapter %s\n",
1412 zfcp_get_busid_by_adapter(adapter));
1413 if (bytes == 0)
1414 ret = -ENOMEM;
1415 else
1416 ret = bytes;
1417
1418 goto failed_send;
1419 }
1420 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1421 } else {
1422 /* reject send generic request */
1423 ZFCP_LOG_INFO(
1424 "error: microcode does not support chained SBALs,"
1425 "CT request too big (adapter %s)\n",
1426 zfcp_get_busid_by_adapter(adapter));
1427 ret = -EOPNOTSUPP;
1428 goto failed_send;
1429 }
1430
1431 /* settings in QTCB */
1432 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001433 fsf_req->qtcb->bottom.support.service_class =
1434 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001436 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001438 zfcp_san_dbf_event_ct_request(fsf_req);
1439
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001440 if (erp_action) {
1441 erp_action->fsf_req = fsf_req;
1442 fsf_req->erp_action = erp_action;
1443 zfcp_erp_start_timer(fsf_req);
1444 } else
1445 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1446
1447 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 if (ret) {
1449 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1450 "(adapter %s, port 0x%016Lx)\n",
1451 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1452 goto failed_send;
1453 }
1454
1455 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1456 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1457 goto out;
1458
1459 failed_send:
1460 zfcp_fsf_req_free(fsf_req);
1461 if (erp_action != NULL) {
1462 erp_action->fsf_req = NULL;
1463 }
1464 failed_req:
1465 out:
1466 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1467 lock_flags);
1468 return ret;
1469}
1470
1471/**
1472 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1473 * @fsf_req: pointer to struct zfcp_fsf_req
1474 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001475 * Data specific for the Generic Service request is passed using
1476 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1477 * Usually a specific handler for the CT request is called which is
1478 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 */
1480static int
1481zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1482{
1483 struct zfcp_port *port;
1484 struct zfcp_adapter *adapter;
1485 struct zfcp_send_ct *send_ct;
1486 struct fsf_qtcb_header *header;
1487 struct fsf_qtcb_bottom_support *bottom;
1488 int retval = -EINVAL;
1489 u16 subtable, rule, counter;
1490
1491 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001492 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 port = send_ct->port;
1494 header = &fsf_req->qtcb->header;
1495 bottom = &fsf_req->qtcb->bottom.support;
1496
1497 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1498 goto skip_fsfstatus;
1499
1500 /* evaluate FSF status in QTCB */
1501 switch (header->fsf_status) {
1502
1503 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001504 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 retval = 0;
1506 break;
1507
1508 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001509 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1510 "class %d.\n",
1511 zfcp_get_busid_by_port(port),
1512 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 /* stop operation for this adapter */
1514 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1515 zfcp_erp_adapter_shutdown(adapter, 0);
1516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1517 break;
1518
1519 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 switch (header->fsf_status_qual.word[0]){
1521 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 /* reopening link to port */
1523 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1524 zfcp_test_link(port);
1525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1526 break;
1527 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 /* ERP strategy will escalate */
1529 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1530 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1531 break;
1532 default:
1533 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1534 "arrived.\n",
1535 header->fsf_status_qual.word[0]);
1536 break;
1537 }
1538 break;
1539
1540 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001542 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 zfcp_get_busid_by_port(port), port->d_id);
1544 for (counter = 0; counter < 2; counter++) {
1545 subtable = header->fsf_status_qual.halfword[counter * 2];
1546 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1547 switch (subtable) {
1548 case FSF_SQ_CFDC_SUBTABLE_OS:
1549 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1550 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1551 case FSF_SQ_CFDC_SUBTABLE_LUN:
1552 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1553 zfcp_act_subtable_type[subtable], rule);
1554 break;
1555 }
1556 }
1557 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1558 zfcp_erp_port_access_denied(port);
1559 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1560 break;
1561
1562 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001564 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 zfcp_get_busid_by_port(port), port->d_id);
1566 ZFCP_LOG_INFO("status qualifier:\n");
1567 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1568 (char *) &header->fsf_status_qual,
1569 sizeof (union fsf_status_qual));
1570 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1571 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1572 break;
1573
1574 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1576 "0x%016Lx on adapter %s invalid. This may "
1577 "happen occasionally.\n", port->handle,
1578 port->wwpn, zfcp_get_busid_by_port(port));
1579 ZFCP_LOG_INFO("status qualifier:\n");
1580 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1581 (char *) &header->fsf_status_qual,
1582 sizeof (union fsf_status_qual));
1583 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1584 zfcp_erp_adapter_reopen(adapter, 0);
1585 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1586 break;
1587
1588 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001590 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 zfcp_get_busid_by_port(port), port->d_id);
1592 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001593 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1595 | ZFCP_STATUS_FSFREQ_RETRY;
1596 break;
1597
1598 /* following states should never occure, all cases avoided
1599 in zfcp_fsf_send_ct - but who knows ... */
1600 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1602 "req_buf_length=%d, resp_buf_length=%d)\n",
1603 zfcp_get_busid_by_adapter(adapter),
1604 bottom->req_buf_length, bottom->resp_buf_length);
1605 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1606 break;
1607 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1609 "req_buf_length=%d)\n",
1610 zfcp_get_busid_by_adapter(adapter),
1611 bottom->req_buf_length);
1612 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1613 break;
1614 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1616 "resp_buf_length=%d)\n",
1617 zfcp_get_busid_by_adapter(adapter),
1618 bottom->resp_buf_length);
1619 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1620 break;
1621 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1623 "resp_buf_length=%d)\n",
1624 zfcp_get_busid_by_adapter(adapter),
1625 bottom->req_buf_length, bottom->resp_buf_length);
1626 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1627 break;
1628
1629 default:
1630 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1631 "(debug info 0x%x)\n", header->fsf_status);
1632 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1633 debug_exception(adapter->erp_dbf, 0,
1634 &header->fsf_status_qual.word[0], sizeof (u32));
1635 break;
1636 }
1637
1638skip_fsfstatus:
1639 send_ct->status = retval;
1640
1641 if (send_ct->handler != NULL)
1642 send_ct->handler(send_ct->handler_data);
1643
1644 return retval;
1645}
1646
1647/**
1648 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1649 * @els: pointer to struct zfcp_send_els which contains all needed data for
1650 * the command.
1651 */
1652int
1653zfcp_fsf_send_els(struct zfcp_send_els *els)
1654{
1655 volatile struct qdio_buffer_element *sbale;
1656 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001657 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 struct zfcp_adapter *adapter;
1659 unsigned long lock_flags;
1660 int bytes;
1661 int ret = 0;
1662
1663 d_id = els->d_id;
1664 adapter = els->adapter;
1665
1666 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1667 ZFCP_REQ_AUTO_CLEANUP,
1668 NULL, &lock_flags, &fsf_req);
1669 if (ret < 0) {
1670 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001671 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 zfcp_get_busid_by_adapter(adapter), d_id);
1673 goto failed_req;
1674 }
1675
1676 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1677 if (zfcp_use_one_sbal(els->req, els->req_count,
1678 els->resp, els->resp_count)){
1679 /* both request buffer and response buffer
1680 fit into one sbale each */
1681 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1682 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1683 sbale[2].length = els->req[0].length;
1684 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1685 sbale[3].length = els->resp[0].length;
1686 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001687 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1689 /* try to use chained SBALs */
1690 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1691 SBAL_FLAGS0_TYPE_WRITE_READ,
1692 els->req, els->req_count,
1693 ZFCP_MAX_SBALS_PER_ELS_REQ);
1694 if (bytes <= 0) {
1695 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001696 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 zfcp_get_busid_by_adapter(adapter), d_id);
1698 if (bytes == 0) {
1699 ret = -ENOMEM;
1700 } else {
1701 ret = bytes;
1702 }
1703 goto failed_send;
1704 }
1705 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1706 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1707 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1708 SBAL_FLAGS0_TYPE_WRITE_READ,
1709 els->resp, els->resp_count,
1710 ZFCP_MAX_SBALS_PER_ELS_REQ);
1711 if (bytes <= 0) {
1712 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001713 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 zfcp_get_busid_by_adapter(adapter), d_id);
1715 if (bytes == 0) {
1716 ret = -ENOMEM;
1717 } else {
1718 ret = bytes;
1719 }
1720 goto failed_send;
1721 }
1722 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1723 } else {
1724 /* reject request */
1725 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1726 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001727 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 zfcp_get_busid_by_adapter(adapter), d_id);
1729 ret = -EOPNOTSUPP;
1730 goto failed_send;
1731 }
1732
1733 /* settings in QTCB */
1734 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001735 fsf_req->qtcb->bottom.support.service_class =
1736 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001738 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1741
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001742 zfcp_san_dbf_event_els_request(fsf_req);
1743
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001744 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1745 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 if (ret) {
1747 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001748 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 zfcp_get_busid_by_adapter(adapter), d_id);
1750 goto failed_send;
1751 }
1752
1753 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001754 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 goto out;
1756
1757 failed_send:
1758 zfcp_fsf_req_free(fsf_req);
1759
1760 failed_req:
1761 out:
1762 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1763 lock_flags);
1764
1765 return ret;
1766}
1767
1768/**
1769 * zfcp_fsf_send_els_handler - handler for ELS commands
1770 * @fsf_req: pointer to struct zfcp_fsf_req
1771 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001772 * Data specific for the ELS command is passed using
1773 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1774 * Usually a specific handler for the ELS command is called which is
1775 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 */
1777static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1778{
1779 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001781 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 struct fsf_qtcb_header *header;
1783 struct fsf_qtcb_bottom_support *bottom;
1784 struct zfcp_send_els *send_els;
1785 int retval = -EINVAL;
1786 u16 subtable, rule, counter;
1787
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001788 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001790 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 d_id = send_els->d_id;
1792 header = &fsf_req->qtcb->header;
1793 bottom = &fsf_req->qtcb->bottom.support;
1794
1795 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1796 goto skip_fsfstatus;
1797
1798 switch (header->fsf_status) {
1799
1800 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001801 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 retval = 0;
1803 break;
1804
1805 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001806 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1807 "class %d.\n",
1808 zfcp_get_busid_by_adapter(adapter),
1809 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 /* stop operation for this adapter */
1811 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1812 zfcp_erp_adapter_shutdown(adapter, 0);
1813 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1814 break;
1815
1816 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 switch (header->fsf_status_qual.word[0]){
1818 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001820 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1821 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1823 break;
1824 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1826 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1827 retval =
1828 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1829 (struct zfcp_ls_rjt_par *)
1830 &header->fsf_status_qual.word[2]);
1831 break;
1832 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1834 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1835 break;
1836 default:
1837 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1838 header->fsf_status_qual.word[0]);
1839 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1840 (char*)header->fsf_status_qual.word, 16);
1841 }
1842 break;
1843
1844 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1846 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001847 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 zfcp_get_busid_by_adapter(adapter), d_id);
1849
1850 break;
1851
1852 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 ZFCP_LOG_INFO(
1854 "ELS request size and ELS response size must be either "
1855 "both 0, or both greater than 0 "
1856 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1857 zfcp_get_busid_by_adapter(adapter),
1858 bottom->req_buf_length,
1859 bottom->resp_buf_length);
1860 break;
1861
1862 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 ZFCP_LOG_INFO(
1864 "Length of the ELS request buffer, "
1865 "specified in QTCB bottom, "
1866 "exceeds the size of the buffers "
1867 "that have been allocated for ELS request data "
1868 "(adapter: %s, req_buf_length=%d)\n",
1869 zfcp_get_busid_by_adapter(adapter),
1870 bottom->req_buf_length);
1871 break;
1872
1873 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 ZFCP_LOG_INFO(
1875 "Length of the ELS response buffer, "
1876 "specified in QTCB bottom, "
1877 "exceeds the size of the buffers "
1878 "that have been allocated for ELS response data "
1879 "(adapter: %s, resp_buf_length=%d)\n",
1880 zfcp_get_busid_by_adapter(adapter),
1881 bottom->resp_buf_length);
1882 break;
1883
1884 case FSF_SBAL_MISMATCH:
1885 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1887 "resp_buf_length=%d)\n",
1888 zfcp_get_busid_by_adapter(adapter),
1889 bottom->req_buf_length, bottom->resp_buf_length);
1890 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1891 break;
1892
1893 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001895 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 zfcp_get_busid_by_adapter(adapter), d_id);
1897 for (counter = 0; counter < 2; counter++) {
1898 subtable = header->fsf_status_qual.halfword[counter * 2];
1899 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1900 switch (subtable) {
1901 case FSF_SQ_CFDC_SUBTABLE_OS:
1902 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1903 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1904 case FSF_SQ_CFDC_SUBTABLE_LUN:
1905 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1906 zfcp_act_subtable_type[subtable], rule);
1907 break;
1908 }
1909 }
1910 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 if (port != NULL)
1912 zfcp_erp_port_access_denied(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1914 break;
1915
1916 default:
1917 ZFCP_LOG_NORMAL(
1918 "bug: An unknown FSF Status was presented "
1919 "(adapter: %s, fsf_status=0x%08x)\n",
1920 zfcp_get_busid_by_adapter(adapter),
1921 header->fsf_status);
1922 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1923 debug_exception(adapter->erp_dbf, 0,
1924 &header->fsf_status_qual.word[0], sizeof(u32));
1925 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1926 break;
1927 }
1928
1929skip_fsfstatus:
1930 send_els->status = retval;
1931
Heiko Carstensaa551da2007-07-18 10:55:10 +02001932 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 send_els->handler(send_els->handler_data);
1934
1935 return retval;
1936}
1937
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938int
1939zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1940{
1941 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001942 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001943 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001945 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
1947 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001948 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1950 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001951 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001952 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001953 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1955 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001956 zfcp_get_busid_by_adapter(adapter));
1957 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1958 lock_flags);
1959 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 }
1961
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001962 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001963 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1964 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001966 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001967 FSF_FEATURE_CFDC |
1968 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001969 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001970 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001971 fsf_req->erp_action = erp_action;
1972 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001974 zfcp_erp_start_timer(fsf_req);
1975 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001976 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1977 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001979 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1980 "data command on the adapter %s\n",
1981 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001982 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001984 }
1985 else
1986 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1987 "(adapter %s)\n",
1988 zfcp_get_busid_by_adapter(adapter));
1989
1990 return retval;
1991}
1992
1993int
1994zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1995 struct fsf_qtcb_bottom_config *data)
1996{
1997 volatile struct qdio_buffer_element *sbale;
1998 struct zfcp_fsf_req *fsf_req;
1999 unsigned long lock_flags;
2000 int retval;
2001
2002 /* setup new FSF request */
2003 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
2004 0, NULL, &lock_flags, &fsf_req);
2005 if (retval) {
2006 ZFCP_LOG_INFO("error: Could not create exchange configuration "
2007 "data request for adapter %s.\n",
2008 zfcp_get_busid_by_adapter(adapter));
2009 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2010 lock_flags);
2011 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 }
2013
Swen Schillig52ef11a2007-08-28 09:31:09 +02002014 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2015 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2016 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Swen Schillig52ef11a2007-08-28 09:31:09 +02002018 fsf_req->qtcb->bottom.config.feature_selection =
2019 FSF_FEATURE_CFDC |
2020 FSF_FEATURE_LUN_SHARING |
2021 FSF_FEATURE_NOTIFICATION_LOST |
2022 FSF_FEATURE_UPDATE_ALERT;
2023
2024 if (data)
2025 fsf_req->data = (unsigned long) data;
2026
2027 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2028 retval = zfcp_fsf_req_send(fsf_req);
2029 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002031 if (retval)
2032 ZFCP_LOG_INFO("error: Could not send exchange configuration "
2033 "data command on the adapter %s\n",
2034 zfcp_get_busid_by_adapter(adapter));
2035 else
2036 wait_event(fsf_req->completion_wq,
2037 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2038
2039 zfcp_fsf_req_free(fsf_req);
2040
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 return retval;
2042}
2043
2044/**
2045 * zfcp_fsf_exchange_config_evaluate
2046 * @fsf_req: fsf_req which belongs to xchg config data request
2047 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2048 *
2049 * returns: -EIO on error, 0 otherwise
2050 */
2051static int
2052zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2053{
2054 struct fsf_qtcb_bottom_config *bottom;
2055 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002056 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
2058 bottom = &fsf_req->qtcb->bottom.config;
2059 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2060 bottom->low_qtcb_version, bottom->high_qtcb_version);
2061 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002062 adapter->adapter_features = bottom->adapter_features;
2063 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05002064 adapter->peer_wwpn = 0;
2065 adapter->peer_wwnn = 0;
2066 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02002069
2070 if (fsf_req->data)
2071 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
2072 bottom, sizeof (struct fsf_qtcb_bottom_config));
2073
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002074 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2075 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2076 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2077 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002078 fc_host_supported_classes(shost) =
2079 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002081 if (fc_host_permanent_port_name(shost) == -1)
2082 fc_host_permanent_port_name(shost) =
2083 fc_host_port_name(shost);
2084 if (bottom->fc_topology == FSF_TOPO_P2P) {
2085 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2086 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2087 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2088 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2089 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2090 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2091 else if (bottom->fc_topology == FSF_TOPO_AL)
2092 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2093 else
2094 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002096 fc_host_node_name(shost) = 0;
2097 fc_host_port_name(shost) = 0;
2098 fc_host_port_id(shost) = 0;
2099 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002100 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 adapter->hydra_version = 0;
2102 }
2103
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002104 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002106 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2107 min(FC_SERIAL_NUMBER_SIZE, 17));
2108 EBCASC(fc_host_serial_number(shost),
2109 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 }
2111
Swen Schillig52ef11a2007-08-28 09:31:09 +02002112 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2113 "characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002114 "WWNN 0x%016Lx, "
2115 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002116 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002117 "adapter version 0x%x, "
2118 "LIC version 0x%x, "
2119 "FC link speed %d Gb/s\n",
2120 zfcp_get_busid_by_adapter(adapter),
2121 (wwn_t) fc_host_node_name(shost),
2122 (wwn_t) fc_host_port_name(shost),
2123 fc_host_port_id(shost),
2124 adapter->hydra_version,
2125 adapter->fsf_lic_version,
2126 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2128 ZFCP_LOG_NORMAL("error: the adapter %s "
2129 "only supports newer control block "
2130 "versions in comparison to this device "
2131 "driver (try updated device driver)\n",
2132 zfcp_get_busid_by_adapter(adapter));
2133 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2134 zfcp_erp_adapter_shutdown(adapter, 0);
2135 return -EIO;
2136 }
2137 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2138 ZFCP_LOG_NORMAL("error: the adapter %s "
2139 "only supports older control block "
2140 "versions than this device driver uses"
2141 "(consider a microcode upgrade)\n",
2142 zfcp_get_busid_by_adapter(adapter));
2143 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2144 zfcp_erp_adapter_shutdown(adapter, 0);
2145 return -EIO;
2146 }
2147 return 0;
2148}
2149
Swen Schillig52ef11a2007-08-28 09:31:09 +02002150/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 * function: zfcp_fsf_exchange_config_data_handler
2152 *
2153 * purpose: is called for finished Exchange Configuration Data command
2154 *
2155 * returns:
2156 */
2157static int
2158zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2159{
2160 struct fsf_qtcb_bottom_config *bottom;
2161 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002162 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2165 return -EIO;
2166
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002167 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2171 return -EIO;
2172
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002173 switch (fc_host_port_type(adapter->scsi_host)) {
2174 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002175 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2176 "configuration detected at adapter %s\n"
2177 "Peer WWNN 0x%016llx, "
2178 "peer WWPN 0x%016llx, "
2179 "peer d_id 0x%06x\n",
2180 zfcp_get_busid_by_adapter(adapter),
2181 adapter->peer_wwnn,
2182 adapter->peer_wwpn,
2183 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 debug_text_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002185 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002186 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002187 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2189 "topology detected at adapter %s "
2190 "unsupported, shutting down adapter\n",
2191 zfcp_get_busid_by_adapter(adapter));
2192 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2193 "top-al");
2194 zfcp_erp_adapter_shutdown(adapter, 0);
2195 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002196 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002197 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002198 "network detected at adapter %s.\n",
2199 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 break;
2201 default:
2202 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2203 "reported by the exchange "
2204 "configuration command for "
2205 "the adapter %s is not "
2206 "of a type known to the zfcp "
2207 "driver, shutting down adapter\n",
2208 zfcp_get_busid_by_adapter(adapter));
2209 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2210 "unknown-topo");
2211 zfcp_erp_adapter_shutdown(adapter, 0);
2212 return -EIO;
2213 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002214 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2216 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2217 "allowed by the adapter %s "
2218 "is lower than the minimum "
2219 "required by the driver (%ld bytes).\n",
2220 bottom->max_qtcb_size,
2221 zfcp_get_busid_by_adapter(adapter),
2222 sizeof(struct fsf_qtcb));
2223 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2224 "qtcb-size");
2225 debug_event(fsf_req->adapter->erp_dbf, 0,
2226 &bottom->max_qtcb_size, sizeof (u32));
2227 zfcp_erp_adapter_shutdown(adapter, 0);
2228 return -EIO;
2229 }
2230 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2231 &adapter->status);
2232 break;
2233 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2234 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2235
2236 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2237 return -EIO;
2238
Swen Schillig52ef11a2007-08-28 09:31:09 +02002239 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2240 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002241
2242 zfcp_fsf_link_down_info_eval(adapter,
2243 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 break;
2245 default:
2246 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2247 debug_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002248 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 zfcp_erp_adapter_shutdown(adapter, 0);
2250 return -EIO;
2251 }
2252 return 0;
2253}
2254
2255/**
2256 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002257 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 */
2259int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002260zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261{
2262 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002263 struct zfcp_fsf_req *fsf_req;
2264 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002265 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002266 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002268 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002270 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002272 return -EOPNOTSUPP;
2273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 /* setup new FSF request */
2276 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002277 ZFCP_REQ_AUTO_CLEANUP,
2278 adapter->pool.fsf_req_erp,
2279 &lock_flags, &fsf_req);
2280 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002282 "exchange port data request for"
2283 "the adapter %s.\n",
2284 zfcp_get_busid_by_adapter(adapter));
2285 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2286 lock_flags);
2287 return retval;
2288 }
2289
2290 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2291 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2292 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2293
2294 erp_action->fsf_req = fsf_req;
2295 fsf_req->erp_action = erp_action;
2296 zfcp_erp_start_timer(fsf_req);
2297
2298 retval = zfcp_fsf_req_send(fsf_req);
2299 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2300
2301 if (retval) {
2302 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2303 "command on the adapter %s\n",
2304 zfcp_get_busid_by_adapter(adapter));
2305 zfcp_fsf_req_free(fsf_req);
2306 erp_action->fsf_req = NULL;
2307 }
2308 else
2309 ZFCP_LOG_DEBUG("exchange port data request initiated "
2310 "(adapter %s)\n",
2311 zfcp_get_busid_by_adapter(adapter));
2312 return retval;
2313}
2314
2315
2316/**
2317 * zfcp_fsf_exchange_port_data_sync - request information about local port
2318 * and wait until information is ready
2319 */
2320int
2321zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2322 struct fsf_qtcb_bottom_port *data)
2323{
2324 volatile struct qdio_buffer_element *sbale;
2325 struct zfcp_fsf_req *fsf_req;
2326 unsigned long lock_flags;
2327 int retval;
2328
2329 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2330 ZFCP_LOG_INFO("error: exchange port data "
2331 "command not supported by adapter %s\n",
2332 zfcp_get_busid_by_adapter(adapter));
2333 return -EOPNOTSUPP;
2334 }
2335
2336 /* setup new FSF request */
2337 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2338 0, NULL, &lock_flags, &fsf_req);
2339 if (retval) {
2340 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2341 "exchange port data request for"
2342 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 zfcp_get_busid_by_adapter(adapter));
2344 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2345 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002346 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002347 }
2348
2349 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002350 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002353 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2354 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Swen Schillig52ef11a2007-08-28 09:31:09 +02002356 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002357 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002358 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
Swen Schillig52ef11a2007-08-28 09:31:09 +02002360 if (retval)
2361 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2362 "command on the adapter %s\n",
2363 zfcp_get_busid_by_adapter(adapter));
2364 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002365 wait_event(fsf_req->completion_wq,
2366 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002367
2368 zfcp_fsf_req_free(fsf_req);
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 return retval;
2371}
2372
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002373/**
2374 * zfcp_fsf_exchange_port_evaluate
2375 * @fsf_req: fsf_req which belongs to xchg port data request
2376 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2377 */
2378static void
2379zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2380{
2381 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002382 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002383 struct Scsi_Host *shost;
2384
2385 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002386 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002387 shost = adapter->scsi_host;
2388
Swen Schillig52ef11a2007-08-28 09:31:09 +02002389 if (fsf_req->data)
2390 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2391 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002392
2393 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2394 fc_host_permanent_port_name(shost) = bottom->wwpn;
2395 else
2396 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2397 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2398 fc_host_supported_speeds(shost) = bottom->supported_speed;
2399}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401/**
2402 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2403 * @fsf_req: pointer to struct zfcp_fsf_req
2404 */
2405static void
2406zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2407{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002408 struct zfcp_adapter *adapter;
2409 struct fsf_qtcb *qtcb;
2410
2411 adapter = fsf_req->adapter;
2412 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
2414 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2415 return;
2416
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002417 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002419 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002420 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002421 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002422 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002423 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002424 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002425 zfcp_fsf_link_down_info_eval(adapter,
2426 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002429 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2430 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2432 }
2433}
2434
2435
2436/*
2437 * function: zfcp_fsf_open_port
2438 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002439 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 *
2441 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002442 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 */
2444int
2445zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2446{
2447 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002448 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 unsigned long lock_flags;
2450 int retval = 0;
2451
2452 /* setup new FSF request */
2453 retval = zfcp_fsf_req_create(erp_action->adapter,
2454 FSF_QTCB_OPEN_PORT_WITH_DID,
2455 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2456 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002457 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 if (retval < 0) {
2459 ZFCP_LOG_INFO("error: Could not create open port request "
2460 "for port 0x%016Lx on adapter %s.\n",
2461 erp_action->port->wwpn,
2462 zfcp_get_busid_by_adapter(erp_action->adapter));
2463 goto out;
2464 }
2465
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002466 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2468 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2469
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002470 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002472 fsf_req->data = (unsigned long) erp_action->port;
2473 fsf_req->erp_action = erp_action;
2474 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002476 zfcp_erp_start_timer(fsf_req);
2477 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 if (retval) {
2479 ZFCP_LOG_INFO("error: Could not send open port request for "
2480 "port 0x%016Lx on adapter %s.\n",
2481 erp_action->port->wwpn,
2482 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002483 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 erp_action->fsf_req = NULL;
2485 goto out;
2486 }
2487
2488 ZFCP_LOG_DEBUG("open port request initiated "
2489 "(adapter %s, port 0x%016Lx)\n",
2490 zfcp_get_busid_by_adapter(erp_action->adapter),
2491 erp_action->port->wwpn);
2492 out:
2493 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2494 lock_flags);
2495 return retval;
2496}
2497
2498/*
2499 * function: zfcp_fsf_open_port_handler
2500 *
2501 * purpose: is called for finished Open Port command
2502 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002503 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 */
2505static int
2506zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2507{
2508 int retval = -EINVAL;
2509 struct zfcp_port *port;
2510 struct fsf_plogi *plogi;
2511 struct fsf_qtcb_header *header;
2512 u16 subtable, rule, counter;
2513
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002514 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 header = &fsf_req->qtcb->header;
2516
2517 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2518 /* don't change port status in our bookkeeping */
2519 goto skip_fsfstatus;
2520 }
2521
2522 /* evaluate FSF status in QTCB */
2523 switch (header->fsf_status) {
2524
2525 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2527 "is already open.\n",
2528 port->wwpn, zfcp_get_busid_by_port(port));
2529 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2530 "fsf_s_popen");
2531 /*
2532 * This is a bug, however operation should continue normally
2533 * if it is simply ignored
2534 */
2535 break;
2536
2537 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2539 "on adapter %s\n",
2540 port->wwpn, zfcp_get_busid_by_port(port));
2541 for (counter = 0; counter < 2; counter++) {
2542 subtable = header->fsf_status_qual.halfword[counter * 2];
2543 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2544 switch (subtable) {
2545 case FSF_SQ_CFDC_SUBTABLE_OS:
2546 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2547 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2548 case FSF_SQ_CFDC_SUBTABLE_LUN:
2549 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2550 zfcp_act_subtable_type[subtable], rule);
2551 break;
2552 }
2553 }
2554 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2555 zfcp_erp_port_access_denied(port);
2556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2557 break;
2558
2559 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2561 "The remote port 0x%016Lx on adapter %s "
2562 "could not be opened. Disabling it.\n",
2563 port->wwpn, zfcp_get_busid_by_port(port));
2564 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2565 "fsf_s_max_ports");
2566 zfcp_erp_port_failed(port);
2567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2568 break;
2569
2570 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 switch (header->fsf_status_qual.word[0]) {
2572 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2574 "fsf_sq_ltest");
2575 /* ERP strategy will escalate */
2576 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2577 break;
2578 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2579 /* ERP strategy will escalate */
2580 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2581 "fsf_sq_ulp");
2582 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2583 break;
2584 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2586 "adapter %s could not be opened. "
2587 "Disabling it.\n",
2588 port->wwpn,
2589 zfcp_get_busid_by_port(port));
2590 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2591 "fsf_sq_no_retry");
2592 zfcp_erp_port_failed(port);
2593 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2594 break;
2595 default:
2596 ZFCP_LOG_NORMAL
2597 ("bug: Wrong status qualifier 0x%x arrived.\n",
2598 header->fsf_status_qual.word[0]);
2599 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2600 "fsf_sq_inval:");
2601 debug_exception(
2602 fsf_req->adapter->erp_dbf, 0,
2603 &header->fsf_status_qual.word[0],
2604 sizeof (u32));
2605 break;
2606 }
2607 break;
2608
2609 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 /* save port handle assigned by FSF */
2611 port->handle = header->port_handle;
2612 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2613 "was opened, it's port handle is 0x%x\n",
2614 port->wwpn, zfcp_get_busid_by_port(port),
2615 port->handle);
2616 /* mark port as open */
2617 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2618 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002619 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2620 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2621 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 retval = 0;
2623 /* check whether D_ID has changed during open */
2624 /*
2625 * FIXME: This check is not airtight, as the FCP channel does
2626 * not monitor closures of target port connections caused on
2627 * the remote side. Thus, they might miss out on invalidating
2628 * locally cached WWPNs (and other N_Port parameters) of gone
2629 * target ports. So, our heroic attempt to make things safe
2630 * could be undermined by 'open port' response data tagged with
2631 * obsolete WWPNs. Another reason to monitor potential
2632 * connection closures ourself at least (by interpreting
2633 * incoming ELS' and unsolicited status). It just crosses my
2634 * mind that one should be able to cross-check by means of
2635 * another GID_PN straight after a port has been opened.
2636 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2637 */
2638 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2639 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2640 {
2641 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002642 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 ZFCP_LOG_INFO(
2644 "warning: insufficient length of "
2645 "PLOGI payload (%i)\n",
2646 fsf_req->qtcb->bottom.support.els1_length);
2647 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2648 "fsf_s_short_plogi:");
2649 /* skip sanity check and assume wwpn is ok */
2650 } else {
2651 if (plogi->serv_param.wwpn != port->wwpn) {
2652 ZFCP_LOG_INFO("warning: d_id of port "
2653 "0x%016Lx changed during "
2654 "open\n", port->wwpn);
2655 debug_text_event(
2656 fsf_req->adapter->erp_dbf, 0,
2657 "fsf_s_did_change:");
2658 atomic_clear_mask(
2659 ZFCP_STATUS_PORT_DID_DID,
2660 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002661 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002663 zfcp_plogi_evaluate(port, plogi);
2664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
2666 }
2667 break;
2668
2669 case FSF_UNKNOWN_OP_SUBTYPE:
2670 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2672 "op_subtype=0x%x)\n",
2673 zfcp_get_busid_by_port(port),
2674 fsf_req->qtcb->bottom.support.operation_subtype);
2675 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2676 break;
2677
2678 default:
2679 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2680 "(debug info 0x%x)\n",
2681 header->fsf_status);
2682 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2683 debug_exception(fsf_req->adapter->erp_dbf, 0,
2684 &header->fsf_status, sizeof (u32));
2685 break;
2686 }
2687
2688 skip_fsfstatus:
2689 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2690 return retval;
2691}
2692
2693/*
2694 * function: zfcp_fsf_close_port
2695 *
2696 * purpose: submit FSF command "close port"
2697 *
2698 * returns: address of initiated FSF request
2699 * NULL - request could not be initiated
2700 */
2701int
2702zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2703{
2704 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002705 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 unsigned long lock_flags;
2707 int retval = 0;
2708
2709 /* setup new FSF request */
2710 retval = zfcp_fsf_req_create(erp_action->adapter,
2711 FSF_QTCB_CLOSE_PORT,
2712 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2713 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002714 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 if (retval < 0) {
2716 ZFCP_LOG_INFO("error: Could not create a close port request "
2717 "for port 0x%016Lx on adapter %s.\n",
2718 erp_action->port->wwpn,
2719 zfcp_get_busid_by_adapter(erp_action->adapter));
2720 goto out;
2721 }
2722
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002723 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2725 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2726
2727 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002728 fsf_req->data = (unsigned long) erp_action->port;
2729 fsf_req->erp_action = erp_action;
2730 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2731 fsf_req->erp_action = erp_action;
2732 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002734 zfcp_erp_start_timer(fsf_req);
2735 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 if (retval) {
2737 ZFCP_LOG_INFO("error: Could not send a close port request for "
2738 "port 0x%016Lx on adapter %s.\n",
2739 erp_action->port->wwpn,
2740 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002741 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 erp_action->fsf_req = NULL;
2743 goto out;
2744 }
2745
2746 ZFCP_LOG_TRACE("close port request initiated "
2747 "(adapter %s, port 0x%016Lx)\n",
2748 zfcp_get_busid_by_adapter(erp_action->adapter),
2749 erp_action->port->wwpn);
2750 out:
2751 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2752 lock_flags);
2753 return retval;
2754}
2755
2756/*
2757 * function: zfcp_fsf_close_port_handler
2758 *
2759 * purpose: is called for finished Close Port FSF command
2760 *
2761 * returns:
2762 */
2763static int
2764zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2765{
2766 int retval = -EINVAL;
2767 struct zfcp_port *port;
2768
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002769 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
2771 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2772 /* don't change port status in our bookkeeping */
2773 goto skip_fsfstatus;
2774 }
2775
2776 /* evaluate FSF status in QTCB */
2777 switch (fsf_req->qtcb->header.fsf_status) {
2778
2779 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2781 "0x%016Lx on adapter %s invalid. This may happen "
2782 "occasionally.\n", port->handle,
2783 port->wwpn, zfcp_get_busid_by_port(port));
2784 ZFCP_LOG_DEBUG("status qualifier:\n");
2785 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2786 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2787 sizeof (union fsf_status_qual));
2788 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2789 "fsf_s_phand_nv");
2790 zfcp_erp_adapter_reopen(port->adapter, 0);
2791 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2792 break;
2793
2794 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 /* Note: FSF has actually closed the port in this case.
2796 * The status code is just daft. Fingers crossed for a change
2797 */
2798 retval = 0;
2799 break;
2800
2801 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2803 "port handle 0x%x\n", port->wwpn,
2804 zfcp_get_busid_by_port(port), port->handle);
2805 zfcp_erp_modify_port_status(port,
2806 ZFCP_STATUS_COMMON_OPEN,
2807 ZFCP_CLEAR);
2808 retval = 0;
2809 break;
2810
2811 default:
2812 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2813 "(debug info 0x%x)\n",
2814 fsf_req->qtcb->header.fsf_status);
2815 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2816 debug_exception(fsf_req->adapter->erp_dbf, 0,
2817 &fsf_req->qtcb->header.fsf_status,
2818 sizeof (u32));
2819 break;
2820 }
2821
2822 skip_fsfstatus:
2823 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2824 return retval;
2825}
2826
2827/*
2828 * function: zfcp_fsf_close_physical_port
2829 *
2830 * purpose: submit FSF command "close physical port"
2831 *
2832 * returns: address of initiated FSF request
2833 * NULL - request could not be initiated
2834 */
2835int
2836zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2837{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002839 struct zfcp_fsf_req *fsf_req;
2840 unsigned long lock_flags;
2841 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842
2843 /* setup new FSF request */
2844 retval = zfcp_fsf_req_create(erp_action->adapter,
2845 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2846 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2847 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002848 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 if (retval < 0) {
2850 ZFCP_LOG_INFO("error: Could not create close physical port "
2851 "request (adapter %s, port 0x%016Lx)\n",
2852 zfcp_get_busid_by_adapter(erp_action->adapter),
2853 erp_action->port->wwpn);
2854
2855 goto out;
2856 }
2857
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002858 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2860 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2861
2862 /* mark port as being closed */
2863 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2864 &erp_action->port->status);
2865 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002866 fsf_req->data = (unsigned long) erp_action->port;
2867 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2868 fsf_req->erp_action = erp_action;
2869 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002871 zfcp_erp_start_timer(fsf_req);
2872 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 if (retval) {
2874 ZFCP_LOG_INFO("error: Could not send close physical port "
2875 "request (adapter %s, port 0x%016Lx)\n",
2876 zfcp_get_busid_by_adapter(erp_action->adapter),
2877 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002878 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 erp_action->fsf_req = NULL;
2880 goto out;
2881 }
2882
2883 ZFCP_LOG_TRACE("close physical port request initiated "
2884 "(adapter %s, port 0x%016Lx)\n",
2885 zfcp_get_busid_by_adapter(erp_action->adapter),
2886 erp_action->port->wwpn);
2887 out:
2888 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2889 lock_flags);
2890 return retval;
2891}
2892
2893/*
2894 * function: zfcp_fsf_close_physical_port_handler
2895 *
2896 * purpose: is called for finished Close Physical Port FSF command
2897 *
2898 * returns:
2899 */
2900static int
2901zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2902{
2903 int retval = -EINVAL;
2904 struct zfcp_port *port;
2905 struct zfcp_unit *unit;
2906 struct fsf_qtcb_header *header;
2907 u16 subtable, rule, counter;
2908
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002909 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 header = &fsf_req->qtcb->header;
2911
2912 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2913 /* don't change port status in our bookkeeping */
2914 goto skip_fsfstatus;
2915 }
2916
2917 /* evaluate FSF status in QTCB */
2918 switch (header->fsf_status) {
2919
2920 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2922 "(adapter %s, port 0x%016Lx). "
2923 "This may happen occasionally.\n",
2924 port->handle,
2925 zfcp_get_busid_by_port(port),
2926 port->wwpn);
2927 ZFCP_LOG_DEBUG("status qualifier:\n");
2928 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2929 (char *) &header->fsf_status_qual,
2930 sizeof (union fsf_status_qual));
2931 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2932 "fsf_s_phand_nv");
2933 zfcp_erp_adapter_reopen(port->adapter, 0);
2934 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2935 break;
2936
2937 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 ZFCP_LOG_NORMAL("Access denied, cannot close "
2939 "physical port 0x%016Lx on adapter %s\n",
2940 port->wwpn, zfcp_get_busid_by_port(port));
2941 for (counter = 0; counter < 2; counter++) {
2942 subtable = header->fsf_status_qual.halfword[counter * 2];
2943 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2944 switch (subtable) {
2945 case FSF_SQ_CFDC_SUBTABLE_OS:
2946 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2947 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2948 case FSF_SQ_CFDC_SUBTABLE_LUN:
2949 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2950 zfcp_act_subtable_type[subtable], rule);
2951 break;
2952 }
2953 }
2954 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2955 zfcp_erp_port_access_denied(port);
2956 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2957 break;
2958
2959 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2961 "%s needs to be reopened but it was attempted "
2962 "to close it physically.\n",
2963 port->wwpn,
2964 zfcp_get_busid_by_port(port));
2965 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02002966 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2968 ZFCP_STATUS_FSFREQ_RETRY;
2969 break;
2970
2971 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 switch (header->fsf_status_qual.word[0]) {
2973 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2975 "fsf_sq_ltest");
2976 /* This will now be escalated by ERP */
2977 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2978 break;
2979 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 /* ERP strategy will escalate */
2981 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2982 "fsf_sq_ulp");
2983 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2984 break;
2985 default:
2986 ZFCP_LOG_NORMAL
2987 ("bug: Wrong status qualifier 0x%x arrived.\n",
2988 header->fsf_status_qual.word[0]);
2989 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2990 "fsf_sq_inval:");
2991 debug_exception(
2992 fsf_req->adapter->erp_dbf, 0,
2993 &header->fsf_status_qual.word[0], sizeof (u32));
2994 break;
2995 }
2996 break;
2997
2998 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
3000 "physically closed, port handle 0x%x\n",
3001 port->wwpn,
3002 zfcp_get_busid_by_port(port), port->handle);
3003 /* can't use generic zfcp_erp_modify_port_status because
3004 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
3005 */
3006 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
3007 list_for_each_entry(unit, &port->unit_list_head, list)
3008 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3009 retval = 0;
3010 break;
3011
3012 default:
3013 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3014 "(debug info 0x%x)\n",
3015 header->fsf_status);
3016 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3017 debug_exception(fsf_req->adapter->erp_dbf, 0,
3018 &header->fsf_status, sizeof (u32));
3019 break;
3020 }
3021
3022 skip_fsfstatus:
3023 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
3024 return retval;
3025}
3026
3027/*
3028 * function: zfcp_fsf_open_unit
3029 *
3030 * purpose:
3031 *
3032 * returns:
3033 *
3034 * assumptions: This routine does not check whether the associated
3035 * remote port has already been opened. This should be
3036 * done by calling routines. Otherwise some status
3037 * may be presented by FSF
3038 */
3039int
3040zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3041{
3042 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003043 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 unsigned long lock_flags;
3045 int retval = 0;
3046
3047 /* setup new FSF request */
3048 retval = zfcp_fsf_req_create(erp_action->adapter,
3049 FSF_QTCB_OPEN_LUN,
3050 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3051 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003052 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 if (retval < 0) {
3054 ZFCP_LOG_INFO("error: Could not create open unit request for "
3055 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3056 erp_action->unit->fcp_lun,
3057 erp_action->unit->port->wwpn,
3058 zfcp_get_busid_by_adapter(erp_action->adapter));
3059 goto out;
3060 }
3061
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003062 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3064 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3065
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003066 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3067 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003068 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003069 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02003070 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003072 fsf_req->data = (unsigned long) erp_action->unit;
3073 fsf_req->erp_action = erp_action;
3074 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003076 zfcp_erp_start_timer(fsf_req);
3077 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 if (retval) {
3079 ZFCP_LOG_INFO("error: Could not send an open unit request "
3080 "on the adapter %s, port 0x%016Lx for "
3081 "unit 0x%016Lx\n",
3082 zfcp_get_busid_by_adapter(erp_action->adapter),
3083 erp_action->port->wwpn,
3084 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003085 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 erp_action->fsf_req = NULL;
3087 goto out;
3088 }
3089
3090 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3091 "port 0x%016Lx, unit 0x%016Lx)\n",
3092 zfcp_get_busid_by_adapter(erp_action->adapter),
3093 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3094 out:
3095 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3096 lock_flags);
3097 return retval;
3098}
3099
3100/*
3101 * function: zfcp_fsf_open_unit_handler
3102 *
3103 * purpose: is called for finished Open LUN command
3104 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003105 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 */
3107static int
3108zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3109{
3110 int retval = -EINVAL;
3111 struct zfcp_adapter *adapter;
3112 struct zfcp_unit *unit;
3113 struct fsf_qtcb_header *header;
3114 struct fsf_qtcb_bottom_support *bottom;
3115 struct fsf_queue_designator *queue_designator;
3116 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003117 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003119 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3122 /* don't change unit status in our bookkeeping */
3123 goto skip_fsfstatus;
3124 }
3125
3126 adapter = fsf_req->adapter;
3127 header = &fsf_req->qtcb->header;
3128 bottom = &fsf_req->qtcb->bottom.support;
3129 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3130
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02003132 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 ZFCP_STATUS_UNIT_SHARED |
3134 ZFCP_STATUS_UNIT_READONLY,
3135 &unit->status);
3136
3137 /* evaluate FSF status in QTCB */
3138 switch (header->fsf_status) {
3139
3140 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3142 "for port 0x%016Lx on adapter %s invalid "
3143 "This may happen occasionally\n",
3144 unit->port->handle,
3145 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3146 ZFCP_LOG_DEBUG("status qualifier:\n");
3147 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3148 (char *) &header->fsf_status_qual,
3149 sizeof (union fsf_status_qual));
3150 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3151 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3152 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3153 break;
3154
3155 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3157 "remote port 0x%016Lx on adapter %s twice.\n",
3158 unit->fcp_lun,
3159 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3160 debug_text_exception(adapter->erp_dbf, 0,
3161 "fsf_s_uopen");
3162 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3163 break;
3164
3165 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3167 "remote port 0x%016Lx on adapter %s\n",
3168 unit->fcp_lun, unit->port->wwpn,
3169 zfcp_get_busid_by_unit(unit));
3170 for (counter = 0; counter < 2; counter++) {
3171 subtable = header->fsf_status_qual.halfword[counter * 2];
3172 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3173 switch (subtable) {
3174 case FSF_SQ_CFDC_SUBTABLE_OS:
3175 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3176 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3177 case FSF_SQ_CFDC_SUBTABLE_LUN:
3178 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3179 zfcp_act_subtable_type[subtable], rule);
3180 break;
3181 }
3182 }
3183 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3184 zfcp_erp_unit_access_denied(unit);
3185 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3186 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3187 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3188 break;
3189
3190 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3192 "needs to be reopened\n",
3193 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3194 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003195 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3197 ZFCP_STATUS_FSFREQ_RETRY;
3198 break;
3199
3200 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 if (header->fsf_status_qual.word[0] != 0) {
3202 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3203 "with WWPN 0x%Lx "
3204 "connected to the adapter %s "
3205 "is already in use in LPAR%d, CSS%d\n",
3206 unit->fcp_lun,
3207 unit->port->wwpn,
3208 zfcp_get_busid_by_unit(unit),
3209 queue_designator->hla,
3210 queue_designator->cssid);
3211 } else {
3212 subtable = header->fsf_status_qual.halfword[4];
3213 rule = header->fsf_status_qual.halfword[5];
3214 switch (subtable) {
3215 case FSF_SQ_CFDC_SUBTABLE_OS:
3216 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3217 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3218 case FSF_SQ_CFDC_SUBTABLE_LUN:
3219 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3220 "remote port with WWPN 0x%Lx "
3221 "connected to the adapter %s "
3222 "is denied (%s rule %d)\n",
3223 unit->fcp_lun,
3224 unit->port->wwpn,
3225 zfcp_get_busid_by_unit(unit),
3226 zfcp_act_subtable_type[subtable],
3227 rule);
3228 break;
3229 }
3230 }
3231 ZFCP_LOG_DEBUG("status qualifier:\n");
3232 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3233 (char *) &header->fsf_status_qual,
3234 sizeof (union fsf_status_qual));
3235 debug_text_event(adapter->erp_dbf, 2,
3236 "fsf_s_l_sh_vio");
3237 zfcp_erp_unit_access_denied(unit);
3238 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3239 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3240 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3241 break;
3242
3243 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3245 "There is no handle (temporary port identifier) "
3246 "available for unit 0x%016Lx on port 0x%016Lx "
3247 "on adapter %s\n",
3248 unit->fcp_lun,
3249 unit->port->wwpn,
3250 zfcp_get_busid_by_unit(unit));
3251 debug_text_event(adapter->erp_dbf, 1,
3252 "fsf_s_max_units");
3253 zfcp_erp_unit_failed(unit);
3254 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3255 break;
3256
3257 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 switch (header->fsf_status_qual.word[0]) {
3259 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 /* Re-establish link to port */
3261 debug_text_event(adapter->erp_dbf, 1,
3262 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003263 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3265 break;
3266 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 /* ERP strategy will escalate */
3268 debug_text_event(adapter->erp_dbf, 1,
3269 "fsf_sq_ulp");
3270 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3271 break;
3272 default:
3273 ZFCP_LOG_NORMAL
3274 ("bug: Wrong status qualifier 0x%x arrived.\n",
3275 header->fsf_status_qual.word[0]);
3276 debug_text_event(adapter->erp_dbf, 0,
3277 "fsf_sq_inval:");
3278 debug_exception(adapter->erp_dbf, 0,
3279 &header->fsf_status_qual.word[0],
3280 sizeof (u32));
3281 }
3282 break;
3283
3284 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 ZFCP_LOG_NORMAL(
3286 "Invalid option 0x%x has been specified "
3287 "in QTCB bottom sent to the adapter %s\n",
3288 bottom->option,
3289 zfcp_get_busid_by_adapter(adapter));
3290 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3291 retval = -EINVAL;
3292 break;
3293
3294 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 /* save LUN handle assigned by FSF */
3296 unit->handle = header->lun_handle;
3297 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3298 "adapter %s opened, port handle 0x%x\n",
3299 unit->fcp_lun,
3300 unit->port->wwpn,
3301 zfcp_get_busid_by_unit(unit),
3302 unit->handle);
3303 /* mark unit as open */
3304 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003305
3306 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3307 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3308 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3309 exclusive = (bottom->lun_access_info &
3310 FSF_UNIT_ACCESS_EXCLUSIVE);
3311 readwrite = (bottom->lun_access_info &
3312 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3313
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 if (!exclusive)
3315 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3316 &unit->status);
3317
3318 if (!readwrite) {
3319 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3320 &unit->status);
3321 ZFCP_LOG_NORMAL("read-only access for unit "
3322 "(adapter %s, wwpn=0x%016Lx, "
3323 "fcp_lun=0x%016Lx)\n",
3324 zfcp_get_busid_by_unit(unit),
3325 unit->port->wwpn,
3326 unit->fcp_lun);
3327 }
3328
3329 if (exclusive && !readwrite) {
3330 ZFCP_LOG_NORMAL("exclusive access of read-only "
3331 "unit not supported\n");
3332 zfcp_erp_unit_failed(unit);
3333 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3334 zfcp_erp_unit_shutdown(unit, 0);
3335 } else if (!exclusive && readwrite) {
3336 ZFCP_LOG_NORMAL("shared access of read-write "
3337 "unit not supported\n");
3338 zfcp_erp_unit_failed(unit);
3339 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3340 zfcp_erp_unit_shutdown(unit, 0);
3341 }
3342 }
3343
3344 retval = 0;
3345 break;
3346
3347 default:
3348 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3349 "(debug info 0x%x)\n",
3350 header->fsf_status);
3351 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3352 debug_exception(adapter->erp_dbf, 0,
3353 &header->fsf_status, sizeof (u32));
3354 break;
3355 }
3356
3357 skip_fsfstatus:
3358 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3359 return retval;
3360}
3361
3362/*
3363 * function: zfcp_fsf_close_unit
3364 *
3365 * purpose:
3366 *
3367 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003368 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 *
3370 * assumptions: This routine does not check whether the associated
3371 * remote port/lun has already been opened. This should be
3372 * done by calling routines. Otherwise some status
3373 * may be presented by FSF
3374 */
3375int
3376zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3377{
3378 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003379 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 unsigned long lock_flags;
3381 int retval = 0;
3382
3383 /* setup new FSF request */
3384 retval = zfcp_fsf_req_create(erp_action->adapter,
3385 FSF_QTCB_CLOSE_LUN,
3386 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3387 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003388 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 if (retval < 0) {
3390 ZFCP_LOG_INFO("error: Could not create close unit request for "
3391 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3392 erp_action->unit->fcp_lun,
3393 erp_action->port->wwpn,
3394 zfcp_get_busid_by_adapter(erp_action->adapter));
3395 goto out;
3396 }
3397
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003398 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3400 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3401
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003402 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3403 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003405 fsf_req->data = (unsigned long) erp_action->unit;
3406 fsf_req->erp_action = erp_action;
3407 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003409 zfcp_erp_start_timer(fsf_req);
3410 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 if (retval) {
3412 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3413 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3414 erp_action->unit->fcp_lun,
3415 erp_action->port->wwpn,
3416 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003417 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 erp_action->fsf_req = NULL;
3419 goto out;
3420 }
3421
3422 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3423 "port 0x%016Lx, unit 0x%016Lx)\n",
3424 zfcp_get_busid_by_adapter(erp_action->adapter),
3425 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3426 out:
3427 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3428 lock_flags);
3429 return retval;
3430}
3431
3432/*
3433 * function: zfcp_fsf_close_unit_handler
3434 *
3435 * purpose: is called for finished Close LUN FSF command
3436 *
3437 * returns:
3438 */
3439static int
3440zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3441{
3442 int retval = -EINVAL;
3443 struct zfcp_unit *unit;
3444
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003445 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3448 /* don't change unit status in our bookkeeping */
3449 goto skip_fsfstatus;
3450 }
3451
3452 /* evaluate FSF status in QTCB */
3453 switch (fsf_req->qtcb->header.fsf_status) {
3454
3455 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3457 "0x%016Lx on adapter %s invalid. This may "
3458 "happen in rare circumstances\n",
3459 unit->port->handle,
3460 unit->port->wwpn,
3461 zfcp_get_busid_by_unit(unit));
3462 ZFCP_LOG_DEBUG("status qualifier:\n");
3463 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3464 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3465 sizeof (union fsf_status_qual));
3466 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3467 "fsf_s_phand_nv");
3468 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3470 break;
3471
3472 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3474 "0x%016Lx on port 0x%016Lx on adapter %s is "
3475 "invalid. This may happen occasionally.\n",
3476 unit->handle,
3477 unit->fcp_lun,
3478 unit->port->wwpn,
3479 zfcp_get_busid_by_unit(unit));
3480 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3481 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3482 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3483 sizeof (union fsf_status_qual));
3484 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3485 "fsf_s_lhand_nv");
3486 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3488 break;
3489
3490 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3492 "needs to be reopened\n",
3493 unit->port->wwpn,
3494 zfcp_get_busid_by_unit(unit));
3495 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003496 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3498 ZFCP_STATUS_FSFREQ_RETRY;
3499 break;
3500
3501 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3503 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 /* re-establish link to port */
3505 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3506 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003507 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3509 break;
3510 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 /* ERP strategy will escalate */
3512 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3513 "fsf_sq_ulp");
3514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3515 break;
3516 default:
3517 ZFCP_LOG_NORMAL
3518 ("bug: Wrong status qualifier 0x%x arrived.\n",
3519 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3520 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3521 "fsf_sq_inval:");
3522 debug_exception(
3523 fsf_req->adapter->erp_dbf, 0,
3524 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3525 sizeof (u32));
3526 break;
3527 }
3528 break;
3529
3530 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3532 "closed, port handle 0x%x\n",
3533 unit->fcp_lun,
3534 unit->port->wwpn,
3535 zfcp_get_busid_by_unit(unit),
3536 unit->handle);
3537 /* mark unit as closed */
3538 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3539 retval = 0;
3540 break;
3541
3542 default:
3543 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3544 "(debug info 0x%x)\n",
3545 fsf_req->qtcb->header.fsf_status);
3546 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3547 debug_exception(fsf_req->adapter->erp_dbf, 0,
3548 &fsf_req->qtcb->header.fsf_status,
3549 sizeof (u32));
3550 break;
3551 }
3552
3553 skip_fsfstatus:
3554 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3555 return retval;
3556}
3557
3558/**
3559 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3560 * @adapter: adapter where scsi command is issued
3561 * @unit: unit where command is sent to
3562 * @scsi_cmnd: scsi command to be sent
3563 * @timer: timer to be started when request is initiated
3564 * @req_flags: flags for fsf_request
3565 */
3566int
3567zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3568 struct zfcp_unit *unit,
3569 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003570 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571{
3572 struct zfcp_fsf_req *fsf_req = NULL;
3573 struct fcp_cmnd_iu *fcp_cmnd_iu;
3574 unsigned int sbtype;
3575 unsigned long lock_flags;
3576 int real_bytes = 0;
3577 int retval = 0;
3578 int mask;
3579
3580 /* setup new FSF request */
3581 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3582 adapter->pool.fsf_req_scsi,
3583 &lock_flags, &fsf_req);
3584 if (unlikely(retval < 0)) {
3585 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3586 "for unit 0x%016Lx on port 0x%016Lx on "
3587 "adapter %s\n",
3588 unit->fcp_lun,
3589 unit->port->wwpn,
3590 zfcp_get_busid_by_adapter(adapter));
3591 goto failed_req_create;
3592 }
3593
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003594 zfcp_unit_get(unit);
3595 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003597 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003598 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003599
3600 /* associate SCSI command with FSF request */
3601 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
3603 /* set handles of unit and its parent port in QTCB */
3604 fsf_req->qtcb->header.lun_handle = unit->handle;
3605 fsf_req->qtcb->header.port_handle = unit->port->handle;
3606
3607 /* FSF does not define the structure of the FCP_CMND IU */
3608 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3609 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3610
3611 /*
3612 * set depending on data direction:
3613 * data direction bits in SBALE (SB Type)
3614 * data direction bits in QTCB
3615 * data direction bits in FCP_CMND IU
3616 */
3617 switch (scsi_cmnd->sc_data_direction) {
3618 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3620 /*
3621 * FIXME(qdio):
3622 * what is the correct type for commands
3623 * without 'real' data buffers?
3624 */
3625 sbtype = SBAL_FLAGS0_TYPE_READ;
3626 break;
3627 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3629 sbtype = SBAL_FLAGS0_TYPE_READ;
3630 fcp_cmnd_iu->rddata = 1;
3631 break;
3632 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3634 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3635 fcp_cmnd_iu->wddata = 1;
3636 break;
3637 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 default:
3639 /*
3640 * dummy, catch this condition earlier
3641 * in zfcp_scsi_queuecommand
3642 */
3643 goto failed_scsi_cmnd;
3644 }
3645
3646 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003647 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648
3649 /* set FCP_LUN in FCP_CMND IU in QTCB */
3650 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3651
3652 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3653
3654 /* set task attributes in FCP_CMND IU in QTCB */
3655 if (likely((scsi_cmnd->device->simple_tags) ||
3656 (atomic_test_mask(mask, &unit->status))))
3657 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3658 else
3659 fcp_cmnd_iu->task_attribute = UNTAGGED;
3660
3661 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3662 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3663 fcp_cmnd_iu->add_fcp_cdb_length
3664 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3665 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3666 "additional FCP_CDB length is 0x%x "
3667 "(shifted right 2 bits)\n",
3668 scsi_cmnd->cmd_len,
3669 fcp_cmnd_iu->add_fcp_cdb_length);
3670 }
3671 /*
3672 * copy SCSI CDB (including additional length, if any) to
3673 * FCP_CDB in FCP_CMND IU in QTCB
3674 */
3675 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3676
3677 /* FCP CMND IU length in QTCB */
3678 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3679 sizeof (struct fcp_cmnd_iu) +
3680 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3681
3682 /* generate SBALEs from data buffer */
3683 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3684 if (unlikely(real_bytes < 0)) {
3685 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3686 ZFCP_LOG_DEBUG(
3687 "Data did not fit into available buffer(s), "
3688 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003689 retval = -EIO;
3690 } else {
3691 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3692 "required. Shutting down unit "
3693 "(adapter %s, port 0x%016Lx, "
3694 "unit 0x%016Lx)\n",
3695 zfcp_get_busid_by_unit(unit),
3696 unit->port->wwpn,
3697 unit->fcp_lun);
3698 zfcp_erp_unit_shutdown(unit, 0);
3699 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 }
3701 goto no_fit;
3702 }
3703
3704 /* set length of FCP data length in FCP_CMND IU in QTCB */
3705 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3706
3707 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3708 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3709 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3710
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003711 if (use_timer)
3712 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3713
3714 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 if (unlikely(retval < 0)) {
3716 ZFCP_LOG_INFO("error: Could not send FCP command request "
3717 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3718 zfcp_get_busid_by_adapter(adapter),
3719 unit->port->wwpn,
3720 unit->fcp_lun);
3721 goto send_failed;
3722 }
3723
3724 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3725 "port 0x%016Lx, unit 0x%016Lx)\n",
3726 zfcp_get_busid_by_adapter(adapter),
3727 unit->port->wwpn,
3728 unit->fcp_lun);
3729 goto success;
3730
3731 send_failed:
3732 no_fit:
3733 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003734 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 zfcp_fsf_req_free(fsf_req);
3736 fsf_req = NULL;
3737 scsi_cmnd->host_scribble = NULL;
3738 success:
3739 failed_req_create:
3740 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3741 return retval;
3742}
3743
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744struct zfcp_fsf_req *
3745zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3746 struct zfcp_unit *unit,
3747 u8 tm_flags, int req_flags)
3748{
3749 struct zfcp_fsf_req *fsf_req = NULL;
3750 int retval = 0;
3751 struct fcp_cmnd_iu *fcp_cmnd_iu;
3752 unsigned long lock_flags;
3753 volatile struct qdio_buffer_element *sbale;
3754
3755 /* setup new FSF request */
3756 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3757 adapter->pool.fsf_req_scsi,
3758 &lock_flags, &fsf_req);
3759 if (retval < 0) {
3760 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3761 "management) request for adapter %s, port "
3762 " 0x%016Lx, unit 0x%016Lx.\n",
3763 zfcp_get_busid_by_adapter(adapter),
3764 unit->port->wwpn, unit->fcp_lun);
3765 goto out;
3766 }
3767
3768 /*
3769 * Used to decide on proper handler in the return path,
3770 * could be either zfcp_fsf_send_fcp_command_task_handler or
3771 * zfcp_fsf_send_fcp_command_task_management_handler */
3772
3773 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3774
3775 /*
3776 * hold a pointer to the unit being target of this
3777 * task management request
3778 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003779 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780
3781 /* set FSF related fields in QTCB */
3782 fsf_req->qtcb->header.lun_handle = unit->handle;
3783 fsf_req->qtcb->header.port_handle = unit->port->handle;
3784 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003785 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3787 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3788
3789 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3790 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3791 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3792
3793 /* set FCP related fields in FCP_CMND IU in QTCB */
3794 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3795 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3796 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3797 fcp_cmnd_iu->task_management_flags = tm_flags;
3798
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003799 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3800 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3803 "management) on adapter %s, port 0x%016Lx for "
3804 "unit LUN 0x%016Lx\n",
3805 zfcp_get_busid_by_adapter(adapter),
3806 unit->port->wwpn,
3807 unit->fcp_lun);
3808 zfcp_fsf_req_free(fsf_req);
3809 fsf_req = NULL;
3810 goto out;
3811 }
3812
3813 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3814 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3815 "tm_flags=0x%x)\n",
3816 zfcp_get_busid_by_adapter(adapter),
3817 unit->port->wwpn,
3818 unit->fcp_lun,
3819 tm_flags);
3820 out:
3821 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3822 return fsf_req;
3823}
3824
3825/*
3826 * function: zfcp_fsf_send_fcp_command_handler
3827 *
3828 * purpose: is called for finished Send FCP Command
3829 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003830 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 */
3832static int
3833zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3834{
3835 int retval = -EINVAL;
3836 struct zfcp_unit *unit;
3837 struct fsf_qtcb_header *header;
3838 u16 subtable, rule, counter;
3839
3840 header = &fsf_req->qtcb->header;
3841
3842 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003843 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003845 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
3847 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3848 /* go directly to calls of special handlers */
3849 goto skip_fsfstatus;
3850 }
3851
3852 /* evaluate FSF status in QTCB */
3853 switch (header->fsf_status) {
3854
3855 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3857 "0x%016Lx on adapter %s invalid\n",
3858 unit->port->handle,
3859 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3860 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3861 (char *) &header->fsf_status_qual,
3862 sizeof (union fsf_status_qual));
3863 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3864 "fsf_s_phand_nv");
3865 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3866 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3867 break;
3868
3869 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3871 "0x%016Lx on port 0x%016Lx on adapter %s is "
3872 "invalid. This may happen occasionally.\n",
3873 unit->handle,
3874 unit->fcp_lun,
3875 unit->port->wwpn,
3876 zfcp_get_busid_by_unit(unit));
3877 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3878 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3879 (char *) &header->fsf_status_qual,
3880 sizeof (union fsf_status_qual));
3881 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3882 "fsf_s_uhand_nv");
3883 zfcp_erp_port_reopen(unit->port, 0);
3884 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3885 break;
3886
3887 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3889 "unexpectedly. (adapter %s, port 0x%016Lx, "
3890 "unit 0x%016Lx)\n",
3891 unit->port->handle,
3892 zfcp_get_busid_by_unit(unit),
3893 unit->port->wwpn,
3894 unit->fcp_lun);
3895 ZFCP_LOG_NORMAL("status qualifier:\n");
3896 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3897 (char *) &header->fsf_status_qual,
3898 sizeof (union fsf_status_qual));
3899 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3900 "fsf_s_hand_mis");
3901 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3903 break;
3904
3905 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003906 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3907 "class %d.\n",
3908 zfcp_get_busid_by_unit(unit),
3909 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 /* stop operation for this adapter */
3911 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3912 "fsf_s_class_nsup");
3913 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3915 break;
3916
3917 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3919 "adapter %s does not have correct unit "
3920 "handle 0x%x\n",
3921 unit->fcp_lun,
3922 unit->port->wwpn,
3923 zfcp_get_busid_by_unit(unit),
3924 unit->handle);
3925 ZFCP_LOG_DEBUG("status qualifier:\n");
3926 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3927 (char *) &header->fsf_status_qual,
3928 sizeof (union fsf_status_qual));
3929 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3930 "fsf_s_fcp_lun_nv");
3931 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3933 break;
3934
3935 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3937 "unit 0x%016Lx on port 0x%016Lx on "
3938 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3939 zfcp_get_busid_by_unit(unit));
3940 for (counter = 0; counter < 2; counter++) {
3941 subtable = header->fsf_status_qual.halfword[counter * 2];
3942 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3943 switch (subtable) {
3944 case FSF_SQ_CFDC_SUBTABLE_OS:
3945 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3946 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3947 case FSF_SQ_CFDC_SUBTABLE_LUN:
3948 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3949 zfcp_act_subtable_type[subtable], rule);
3950 break;
3951 }
3952 }
3953 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3954 zfcp_erp_unit_access_denied(unit);
3955 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3956 break;
3957
3958 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3960 "0x%016Lx on port 0x%016Lx on adapter %s "
3961 "(debug info %d)\n",
3962 unit->fcp_lun,
3963 unit->port->wwpn,
3964 zfcp_get_busid_by_unit(unit),
3965 fsf_req->qtcb->bottom.io.data_direction);
3966 /* stop operation for this adapter */
3967 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3968 "fsf_s_dir_ind_nv");
3969 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3971 break;
3972
3973 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 ZFCP_LOG_NORMAL
3975 ("bug: An invalid control-data-block length field "
3976 "was found in a command for unit 0x%016Lx on port "
3977 "0x%016Lx on adapter %s " "(debug info %d)\n",
3978 unit->fcp_lun, unit->port->wwpn,
3979 zfcp_get_busid_by_unit(unit),
3980 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3981 /* stop operation for this adapter */
3982 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3983 "fsf_s_cmd_len_nv");
3984 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3986 break;
3987
3988 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3990 "needs to be reopened\n",
3991 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3992 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003993 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3995 ZFCP_STATUS_FSFREQ_RETRY;
3996 break;
3997
3998 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
4000 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
4001 zfcp_get_busid_by_unit(unit),
4002 unit->port->wwpn, unit->fcp_lun);
4003 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02004004 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
4006 | ZFCP_STATUS_FSFREQ_RETRY;
4007 break;
4008
4009 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 switch (header->fsf_status_qual.word[0]) {
4011 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 /* re-establish link to port */
4013 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4014 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02004015 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 break;
4017 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 /* FIXME(hw) need proper specs for proper action */
4019 /* let scsi stack deal with retries and escalation */
4020 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4021 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 break;
4023 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02004025 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 header->fsf_status_qual.word[0]);
4027 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4028 "fsf_sq_inval:");
4029 debug_exception(fsf_req->adapter->erp_dbf, 0,
4030 &header->fsf_status_qual.word[0],
4031 sizeof(u32));
4032 break;
4033 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02004034 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 break;
4036
4037 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 break;
4039
4040 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 break;
4042
4043 default:
4044 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4045 debug_exception(fsf_req->adapter->erp_dbf, 0,
4046 &header->fsf_status, sizeof(u32));
4047 break;
4048 }
4049
4050 skip_fsfstatus:
4051 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4052 retval =
4053 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4054 } else {
4055 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004056 fsf_req->unit = NULL;
4057 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 }
4059 return retval;
4060}
4061
4062/*
4063 * function: zfcp_fsf_send_fcp_command_task_handler
4064 *
4065 * purpose: evaluates FCP_RSP IU
4066 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004067 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 */
4069static int
4070zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4071{
4072 int retval = 0;
4073 struct scsi_cmnd *scpnt;
4074 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4075 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4076 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4077 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4078 u32 sns_len;
4079 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4080 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004081 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082
4083 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004084 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 if (unlikely(!scpnt)) {
4086 ZFCP_LOG_DEBUG
4087 ("Command with fsf_req %p is not associated to "
4088 "a scsi command anymore. Aborted?\n", fsf_req);
4089 goto out;
4090 }
4091 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4092 /* FIXME: (design) mid-layer should handle DID_ABORT like
4093 * DID_SOFT_ERROR by retrying the request for devices
4094 * that allow retries.
4095 */
4096 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4097 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4098 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4099 goto skip_fsfstatus;
4100 }
4101
4102 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4103 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4104 set_host_byte(&scpnt->result, DID_ERROR);
4105 goto skip_fsfstatus;
4106 }
4107
4108 /* set message byte of result in SCSI command */
4109 scpnt->result |= COMMAND_COMPLETE << 8;
4110
4111 /*
4112 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4113 * of result in SCSI command
4114 */
4115 scpnt->result |= fcp_rsp_iu->scsi_status;
4116 if (unlikely(fcp_rsp_iu->scsi_status)) {
4117 /* DEBUG */
4118 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4119 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4120 scpnt->cmnd, scpnt->cmd_len);
4121 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4122 fcp_rsp_iu->scsi_status);
4123 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4124 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4125 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4126 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4127 fcp_rsp_iu->fcp_sns_len);
4128 }
4129
4130 /* check FCP_RSP_INFO */
4131 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4132 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4133 switch (fcp_rsp_info[3]) {
4134 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 /* ok, continue */
4136 ZFCP_LOG_TRACE("no failure or Task Management "
4137 "Function complete\n");
4138 set_host_byte(&scpnt->result, DID_OK);
4139 break;
4140 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 /* hardware bug */
4142 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4143 "that the fibrechannel protocol data "
4144 "length differs from the burst length. "
4145 "The problem occured on unit 0x%016Lx "
4146 "on port 0x%016Lx on adapter %s",
4147 unit->fcp_lun,
4148 unit->port->wwpn,
4149 zfcp_get_busid_by_unit(unit));
4150 /* dump SCSI CDB as prepared by zfcp */
4151 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4152 (char *) &fsf_req->qtcb->
4153 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 set_host_byte(&scpnt->result, DID_ERROR);
4155 goto skip_fsfstatus;
4156 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 /* driver or hardware bug */
4158 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4159 "that the fibrechannel protocol data "
4160 "fields were incorrectly set up. "
4161 "The problem occured on the unit "
4162 "0x%016Lx on port 0x%016Lx on "
4163 "adapter %s",
4164 unit->fcp_lun,
4165 unit->port->wwpn,
4166 zfcp_get_busid_by_unit(unit));
4167 /* dump SCSI CDB as prepared by zfcp */
4168 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4169 (char *) &fsf_req->qtcb->
4170 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4171 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 goto skip_fsfstatus;
4173 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 /* hardware bug */
4175 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4176 "that conflicting values for the "
4177 "fibrechannel payload offset from the "
4178 "header were found. "
4179 "The problem occured on unit 0x%016Lx "
4180 "on port 0x%016Lx on adapter %s.\n",
4181 unit->fcp_lun,
4182 unit->port->wwpn,
4183 zfcp_get_busid_by_unit(unit));
4184 /* dump SCSI CDB as prepared by zfcp */
4185 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4186 (char *) &fsf_req->qtcb->
4187 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 set_host_byte(&scpnt->result, DID_ERROR);
4189 goto skip_fsfstatus;
4190 default:
4191 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4192 "code was detected for a command. "
4193 "The problem occured on the unit "
4194 "0x%016Lx on port 0x%016Lx on "
4195 "adapter %s (debug info 0x%x)\n",
4196 unit->fcp_lun,
4197 unit->port->wwpn,
4198 zfcp_get_busid_by_unit(unit),
4199 fcp_rsp_info[3]);
4200 /* dump SCSI CDB as prepared by zfcp */
4201 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4202 (char *) &fsf_req->qtcb->
4203 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004205 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 }
4207 }
4208
4209 /* check for sense data */
4210 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4211 sns_len = FSF_FCP_RSP_SIZE -
4212 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4213 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4214 sns_len);
4215 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4216 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4217 SCSI_SENSE_BUFFERSIZE);
4218 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4219 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4220 scpnt->result);
4221 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4222 (void *) &scpnt->cmnd, scpnt->cmd_len);
4223
4224 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4225 fcp_rsp_iu->fcp_sns_len);
4226 memcpy(&scpnt->sense_buffer,
4227 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4228 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4229 (void *) &scpnt->sense_buffer, sns_len);
4230 }
4231
4232 /* check for overrun */
4233 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4234 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4235 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4236 "The response data length is "
4237 "%d, the original length was %d.\n",
4238 unit->fcp_lun,
4239 unit->port->wwpn,
4240 zfcp_get_busid_by_unit(unit),
4241 fcp_rsp_iu->fcp_resid,
4242 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4243 }
4244
4245 /* check for underrun */
4246 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4247 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4248 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4249 "The response data length is "
4250 "%d, the original length was %d.\n",
4251 unit->fcp_lun,
4252 unit->port->wwpn,
4253 zfcp_get_busid_by_unit(unit),
4254 fcp_rsp_iu->fcp_resid,
4255 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4256
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004257 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4258 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4259 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004260 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 }
4262
4263 skip_fsfstatus:
4264 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4265
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004266 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004267 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004268 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004269 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004270 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004271 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272
4273 /* cleanup pointer (need this especially for abort) */
4274 scpnt->host_scribble = NULL;
4275
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 (scpnt->scsi_done) (scpnt);
4278
4279 /*
4280 * We must hold this lock until scsi_done has been called.
4281 * Otherwise we may call scsi_done after abort regarding this
4282 * command has completed.
4283 * Note: scsi_done must not block!
4284 */
4285 out:
4286 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4287 return retval;
4288}
4289
4290/*
4291 * function: zfcp_fsf_send_fcp_command_task_management_handler
4292 *
4293 * purpose: evaluates FCP_RSP IU
4294 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004295 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 */
4297static int
4298zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4299{
4300 int retval = 0;
4301 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4302 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4303 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004304 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4307 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4308 goto skip_fsfstatus;
4309 }
4310
4311 /* check FCP_RSP_INFO */
4312 switch (fcp_rsp_info[3]) {
4313 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 /* ok, continue */
4315 ZFCP_LOG_DEBUG("no failure or Task Management "
4316 "Function complete\n");
4317 break;
4318 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4320 "is not supported on the target device "
4321 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4322 unit->fcp_lun,
4323 unit->port->wwpn,
4324 zfcp_get_busid_by_unit(unit));
4325 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4326 break;
4327 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4329 "failed to complete successfully. "
4330 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4331 unit->fcp_lun,
4332 unit->port->wwpn,
4333 zfcp_get_busid_by_unit(unit));
4334 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4335 break;
4336 default:
4337 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4338 "code was detected for a command. "
4339 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4340 "(debug info 0x%x)\n",
4341 unit->fcp_lun,
4342 unit->port->wwpn,
4343 zfcp_get_busid_by_unit(unit),
4344 fcp_rsp_info[3]);
4345 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4346 }
4347
4348 skip_fsfstatus:
4349 return retval;
4350}
4351
4352
4353/*
4354 * function: zfcp_fsf_control_file
4355 *
4356 * purpose: Initiator of the control file upload/download FSF requests
4357 *
4358 * returns: 0 - FSF request is successfuly created and queued
4359 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4360 * -EINVAL - Invalid direction specified
4361 * -ENOMEM - Insufficient memory
4362 * -EPERM - Cannot create FSF request or place it in QDIO queue
4363 */
4364int
4365zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4366 struct zfcp_fsf_req **fsf_req_ptr,
4367 u32 fsf_command,
4368 u32 option,
4369 struct zfcp_sg_list *sg_list)
4370{
4371 struct zfcp_fsf_req *fsf_req;
4372 struct fsf_qtcb_bottom_support *bottom;
4373 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 unsigned long lock_flags;
4375 int req_flags = 0;
4376 int direction;
4377 int retval = 0;
4378
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004379 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4381 zfcp_get_busid_by_adapter(adapter));
4382 retval = -EOPNOTSUPP;
4383 goto out;
4384 }
4385
4386 switch (fsf_command) {
4387
4388 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4389 direction = SBAL_FLAGS0_TYPE_WRITE;
4390 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4391 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4392 req_flags = ZFCP_WAIT_FOR_SBAL;
4393 break;
4394
4395 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4396 direction = SBAL_FLAGS0_TYPE_READ;
4397 break;
4398
4399 default:
4400 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4401 retval = -EINVAL;
4402 goto out;
4403 }
4404
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4406 NULL, &lock_flags, &fsf_req);
4407 if (retval < 0) {
4408 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4409 "adapter %s\n",
4410 zfcp_get_busid_by_adapter(adapter));
4411 retval = -EPERM;
4412 goto unlock_queue_lock;
4413 }
4414
4415 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4416 sbale[0].flags |= direction;
4417
4418 bottom = &fsf_req->qtcb->bottom.support;
4419 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4420 bottom->option = option;
4421
4422 if (sg_list->count > 0) {
4423 int bytes;
4424
4425 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4426 sg_list->sg, sg_list->count,
4427 ZFCP_MAX_SBALS_PER_REQ);
4428 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4429 ZFCP_LOG_INFO(
4430 "error: Could not create sufficient number of "
4431 "SBALS for an FSF request to the adapter %s\n",
4432 zfcp_get_busid_by_adapter(adapter));
4433 retval = -ENOMEM;
4434 goto free_fsf_req;
4435 }
4436 } else
4437 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4438
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004439 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4440 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 if (retval < 0) {
4442 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4443 "(adapter %s)\n",
4444 zfcp_get_busid_by_adapter(adapter));
4445 retval = -EPERM;
4446 goto free_fsf_req;
4447 }
4448 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4449
4450 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4451 "adapter %s\n",
4452 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4453 "download" : "upload",
4454 zfcp_get_busid_by_adapter(adapter));
4455
4456 wait_event(fsf_req->completion_wq,
4457 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4458
4459 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004460 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461
4462 free_fsf_req:
4463 zfcp_fsf_req_free(fsf_req);
4464 unlock_queue_lock:
4465 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 out:
4467 return retval;
4468}
4469
4470
4471/*
4472 * function: zfcp_fsf_control_file_handler
4473 *
4474 * purpose: Handler of the control file upload/download FSF requests
4475 *
4476 * returns: 0 - FSF request successfuly processed
4477 * -EAGAIN - Operation has to be repeated because of a temporary problem
4478 * -EACCES - There is no permission to execute an operation
4479 * -EPERM - The control file is not in a right format
4480 * -EIO - There is a problem with the FCP adapter
4481 * -EINVAL - Invalid operation
4482 * -EFAULT - User space memory I/O operation fault
4483 */
4484static int
4485zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4486{
4487 struct zfcp_adapter *adapter = fsf_req->adapter;
4488 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4489 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4490 int retval = 0;
4491
4492 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4493 retval = -EINVAL;
4494 goto skip_fsfstatus;
4495 }
4496
4497 switch (header->fsf_status) {
4498
4499 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500 ZFCP_LOG_NORMAL(
4501 "The FSF request has been successfully completed "
4502 "on the adapter %s\n",
4503 zfcp_get_busid_by_adapter(adapter));
4504 break;
4505
4506 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4508 switch (header->fsf_status_qual.word[0]) {
4509
6f71d9b2005-04-10 23:04:28 -05004510 case FSF_SQ_CFDC_HARDENED_ON_SE:
4511 ZFCP_LOG_NORMAL(
4512 "CFDC on the adapter %s has being "
4513 "hardened on primary and secondary SE\n",
4514 zfcp_get_busid_by_adapter(adapter));
4515 break;
4516
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4518 ZFCP_LOG_NORMAL(
4519 "CFDC of the adapter %s could not "
4520 "be saved on the SE\n",
4521 zfcp_get_busid_by_adapter(adapter));
4522 break;
4523
4524 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4525 ZFCP_LOG_NORMAL(
4526 "CFDC of the adapter %s could not "
4527 "be copied to the secondary SE\n",
4528 zfcp_get_busid_by_adapter(adapter));
4529 break;
4530
4531 default:
4532 ZFCP_LOG_NORMAL(
4533 "CFDC could not be hardened "
4534 "on the adapter %s\n",
4535 zfcp_get_busid_by_adapter(adapter));
4536 }
4537 }
4538 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4539 retval = -EAGAIN;
4540 break;
4541
4542 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 ZFCP_LOG_NORMAL(
4544 "Adapter %s does not accept privileged commands\n",
4545 zfcp_get_busid_by_adapter(adapter));
4546 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4547 retval = -EACCES;
4548 break;
4549
4550 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 ZFCP_LOG_NORMAL(
4552 "Error at position %d in the CFDC, "
4553 "CFDC is discarded by the adapter %s\n",
4554 header->fsf_status_qual.word[0],
4555 zfcp_get_busid_by_adapter(adapter));
4556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4557 retval = -EPERM;
4558 break;
4559
4560 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 ZFCP_LOG_NORMAL(
4562 "Adapter %s cannot harden the control file, "
4563 "file is discarded\n",
4564 zfcp_get_busid_by_adapter(adapter));
4565 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4566 retval = -EIO;
4567 break;
4568
4569 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 ZFCP_LOG_NORMAL(
4571 "Control file is too large, file is discarded "
4572 "by the adapter %s\n",
4573 zfcp_get_busid_by_adapter(adapter));
4574 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4575 retval = -EIO;
4576 break;
4577
4578 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4580 ZFCP_LOG_NORMAL(
4581 "CFDC has been discarded by the adapter %s, "
4582 "because activation would impact "
4583 "%d active connection(s)\n",
4584 zfcp_get_busid_by_adapter(adapter),
4585 header->fsf_status_qual.word[0]);
4586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4587 retval = -EIO;
4588 break;
4589
4590 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4592 ZFCP_LOG_NORMAL(
4593 "CFDC has been activated on the adapter %s, "
4594 "but activation has impacted "
4595 "%d active connection(s)\n",
4596 zfcp_get_busid_by_adapter(adapter),
4597 header->fsf_status_qual.word[0]);
4598 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4599 retval = -EIO;
4600 break;
4601
4602 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4604 "op_subtype=0x%x)\n",
4605 zfcp_get_busid_by_adapter(adapter),
4606 bottom->operation_subtype);
4607 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4608 retval = -EINVAL;
4609 break;
4610
4611 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 ZFCP_LOG_NORMAL(
4613 "Invalid option 0x%x has been specified "
4614 "in QTCB bottom sent to the adapter %s\n",
4615 bottom->option,
4616 zfcp_get_busid_by_adapter(adapter));
4617 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4618 retval = -EINVAL;
4619 break;
4620
4621 default:
4622 ZFCP_LOG_NORMAL(
4623 "bug: An unknown/unexpected FSF status 0x%08x "
4624 "was presented on the adapter %s\n",
4625 header->fsf_status,
4626 zfcp_get_busid_by_adapter(adapter));
4627 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4628 debug_exception(fsf_req->adapter->erp_dbf, 0,
4629 &header->fsf_status_qual.word[0], sizeof(u32));
4630 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4631 retval = -EINVAL;
4632 break;
4633 }
4634
4635skip_fsfstatus:
4636 return retval;
4637}
4638
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639static inline int
4640zfcp_fsf_req_sbal_check(unsigned long *flags,
4641 struct zfcp_qdio_queue *queue, int needed)
4642{
4643 write_lock_irqsave(&queue->queue_lock, *flags);
4644 if (likely(atomic_read(&queue->free_count) >= needed))
4645 return 1;
4646 write_unlock_irqrestore(&queue->queue_lock, *flags);
4647 return 0;
4648}
4649
4650/*
4651 * set qtcb pointer in fsf_req and initialize QTCB
4652 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004653static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004654zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655{
4656 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004657 fsf_req->qtcb->prefix.req_seq_no =
4658 fsf_req->adapter->fsf_req_seq_no;
4659 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004661 fsf_req->qtcb->prefix.qtcb_type =
4662 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004664 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004665 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 }
4667}
4668
4669/**
4670 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4671 * @adapter: adapter for which request queue is examined
4672 * @req_flags: flags indicating whether to wait for needed SBAL or not
4673 * @lock_flags: lock_flags if queue_lock is taken
4674 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4675 * Locks: lock adapter->request_queue->queue_lock on success
4676 */
4677static int
4678zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4679 unsigned long *lock_flags)
4680{
4681 long ret;
4682 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4683
4684 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4685 ret = wait_event_interruptible_timeout(adapter->request_wq,
4686 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4687 ZFCP_SBAL_TIMEOUT);
4688 if (ret < 0)
4689 return ret;
4690 if (!ret)
4691 return -EIO;
4692 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4693 return -EIO;
4694
4695 return 0;
4696}
4697
4698/*
4699 * function: zfcp_fsf_req_create
4700 *
4701 * purpose: create an FSF request at the specified adapter and
4702 * setup common fields
4703 *
4704 * returns: -ENOMEM if there was insufficient memory for a request
4705 * -EIO if no qdio buffers could be allocate to the request
4706 * -EINVAL/-EPERM on bug conditions in req_dequeue
4707 * 0 in success
4708 *
4709 * note: The created request is returned by reference.
4710 *
4711 * locks: lock of concerned request queue must not be held,
4712 * but is held on completion (write, irqsave)
4713 */
4714int
4715zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4716 mempool_t *pool, unsigned long *lock_flags,
4717 struct zfcp_fsf_req **fsf_req_p)
4718{
4719 volatile struct qdio_buffer_element *sbale;
4720 struct zfcp_fsf_req *fsf_req = NULL;
4721 int ret = 0;
4722 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4723
4724 /* allocate new FSF request */
4725 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4726 if (unlikely(NULL == fsf_req)) {
4727 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4728 "the outbound (send) queue.\n");
4729 ret = -ENOMEM;
4730 goto failed_fsf_req;
4731 }
4732
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004733 fsf_req->adapter = adapter;
4734 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004735 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004736 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004738 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 this request completion */
4740 init_waitqueue_head(&fsf_req->completion_wq);
4741
4742 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004743 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004745
4746 /* this is serialized (we are holding req_queue-lock of adapter) */
4747 if (adapter->req_no == 0)
4748 adapter->req_no++;
4749 fsf_req->req_id = adapter->req_no++;
4750
4751 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752
4753 /*
4754 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4755 * if it is not set (see also *_open_qdio and *_close_qdio).
4756 */
4757
4758 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4759 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4760 ret = -EIO;
4761 goto failed_sbals;
4762 }
4763
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004764 if (fsf_req->qtcb) {
4765 fsf_req->seq_no = adapter->fsf_req_seq_no;
4766 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 fsf_req->sbal_number = 1;
4769 fsf_req->sbal_first = req_queue->free_index;
4770 fsf_req->sbal_curr = req_queue->free_index;
4771 fsf_req->sbale_curr = 1;
4772
4773 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4774 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4775 }
4776
4777 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4778
4779 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004780 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4782 if (likely(fsf_req->qtcb != NULL)) {
4783 sbale[1].addr = (void *) fsf_req->qtcb;
4784 sbale[1].length = sizeof(struct fsf_qtcb);
4785 }
4786
4787 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4788 fsf_req->sbal_number, fsf_req->sbal_first);
4789
4790 goto success;
4791
4792 failed_sbals:
4793/* dequeue new FSF request previously enqueued */
4794 zfcp_fsf_req_free(fsf_req);
4795 fsf_req = NULL;
4796
4797 failed_fsf_req:
4798 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4799 success:
4800 *fsf_req_p = fsf_req;
4801 return ret;
4802}
4803
4804/*
4805 * function: zfcp_fsf_req_send
4806 *
4807 * purpose: start transfer of FSF request via QDIO
4808 *
4809 * returns: 0 - request transfer succesfully started
4810 * !0 - start of request transfer failed
4811 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004812static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813{
4814 struct zfcp_adapter *adapter;
4815 struct zfcp_qdio_queue *req_queue;
4816 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004817 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 int new_distance_from_int;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004819 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 int retval = 0;
4821
4822 adapter = fsf_req->adapter;
4823 req_queue = &adapter->request_queue,
4824
4825
4826 /* FIXME(debug): remove it later */
4827 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4828 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4829 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4830 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4831 sbale[1].length);
4832
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004833 /* put allocated FSF request into hash table */
4834 spin_lock(&adapter->req_list_lock);
4835 zfcp_reqlist_add(adapter, fsf_req);
4836 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004838 inc_seq_no = (fsf_req->qtcb != NULL);
4839
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 ZFCP_LOG_TRACE("request queue of adapter %s: "
4841 "next free SBAL is %i, %i free SBALs\n",
4842 zfcp_get_busid_by_adapter(adapter),
4843 req_queue->free_index,
4844 atomic_read(&req_queue->free_count));
4845
4846 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4847 "index_in_queue=%i, count=%i, buffers=%p\n",
4848 zfcp_get_busid_by_adapter(adapter),
4849 QDIO_FLAG_SYNC_OUTPUT,
4850 0, fsf_req->sbal_first, fsf_req->sbal_number,
4851 &req_queue->buffer[fsf_req->sbal_first]);
4852
4853 /*
4854 * adjust the number of free SBALs in request queue as well as
4855 * position of first one
4856 */
4857 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4858 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4859 req_queue->free_index += fsf_req->sbal_number; /* increase */
4860 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4861 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4862
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004863 fsf_req->issued = get_clock();
4864
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 retval = do_QDIO(adapter->ccw_device,
4866 QDIO_FLAG_SYNC_OUTPUT,
4867 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4868
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004869 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4870 dbg_tmp[1] = (u64) retval;
4871 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4872
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 if (unlikely(retval)) {
4874 /* Queues are down..... */
4875 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004876 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004877 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004878 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004879 spin_unlock(&adapter->req_list_lock);
4880 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 zfcp_qdio_zero_sbals(req_queue->buffer,
4882 fsf_req->sbal_first, fsf_req->sbal_number);
4883 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004884 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4886 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004887 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 } else {
4889 req_queue->distance_from_int = new_distance_from_int;
4890 /*
4891 * increase FSF sequence counter -
4892 * this must only be done for request successfully enqueued to
4893 * QDIO this rejected requests may be cleaned up by calling
4894 * routines resulting in missing sequence counter values
4895 * otherwise,
4896 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004897
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004899 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004901
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004903 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 }
4905 return retval;
4906}
4907
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908#undef ZFCP_LOG_AREA