blob: 2b7ddb78767c0eedf07b86bae0d400955ff8f9e1 [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 *);
Martin Peschke698ec0162008-03-27 14:22:02 +010049static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020050 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200288 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 break;
293
294 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 ZFCP_LOG_NORMAL("error: The adapter %s contains "
296 "microcode of version 0x%x, the device driver "
297 "only supports 0x%x. Aborting.\n",
298 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200299 prot_status_qual->version_error.fsf_version,
300 ZFCP_QTCB_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
303 break;
304
305 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
307 "driver (0x%x) and adapter %s (0x%x). "
308 "Restarting all operations on this adapter.\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200309 qtcb->prefix.req_seq_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200311 prot_status_qual->sequence_error.exp_req_seq_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
314 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
315 break;
316
317 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 ZFCP_LOG_NORMAL("error: Packet header type used by the "
319 "device driver is incompatible with "
320 "that used on adapter %s. "
321 "Stopping all operations on this adapter.\n",
322 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
325 break;
326
327 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
329 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
330 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 break;
332
333 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
335 "to the adapter %s is ambiguous. "
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200336 "Stopping all operations on this adapter.\n",
337 *(unsigned long long*)
338 (&qtcb->bottom.support.req_handle),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
342 break;
343
344 case FSF_PROT_LINK_DOWN:
Martin Peschke698ec0162008-03-27 14:22:02 +0100345 zfcp_fsf_link_down_info_eval(fsf_req, 37,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200346 &prot_status_qual->link_down_info);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100347 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
349 break;
350
351 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 "%s was re-plugged. "
354 "Re-starting operations on this adapter.\n",
355 zfcp_get_busid_by_adapter(adapter));
356 /* All ports should be marked as ready to run again */
Martin Peschke698ec0162008-03-27 14:22:02 +0100357 zfcp_erp_modify_adapter_status(adapter, 28,
358 0, ZFCP_STATUS_COMMON_RUNNING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 ZFCP_SET);
360 zfcp_erp_adapter_reopen(adapter,
361 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
362 | ZFCP_STATUS_COMMON_ERP_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
364 break;
365
366 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 ZFCP_LOG_NORMAL("error: The adapter %s "
368 "has entered the error state. "
369 "Restarting all operations on this "
370 "adapter.\n",
371 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
374 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
375 break;
376
377 default:
378 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
379 "provided by the adapter %s "
380 "is not compatible with the device driver. "
381 "Stopping all operations on this adapter. "
382 "(debug info 0x%x).\n",
383 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200384 qtcb->prefix.prot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 zfcp_erp_adapter_shutdown(adapter, 0);
386 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
387 }
388
389 skip_protstatus:
390 /*
391 * always call specific handlers to give them a chance to do
392 * something meaningful even in error cases
393 */
394 zfcp_fsf_fsfstatus_eval(fsf_req);
395 return retval;
396}
397
398/*
399 * function: zfcp_fsf_fsfstatus_eval
400 *
401 * purpose: evaluates FSF status of completed FSF request
402 * and acts accordingly
403 *
404 * returns:
405 */
406static int
407zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
408{
409 int retval = 0;
410
411 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
412 goto skip_fsfstatus;
413 }
414
415 /* evaluate FSF Status */
416 switch (fsf_req->qtcb->header.fsf_status) {
417 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
419 "not known by the adapter %s "
420 "Stopping all operations on this adapter. "
421 "(debug info 0x%x).\n",
422 zfcp_get_busid_by_adapter(fsf_req->adapter),
423 fsf_req->qtcb->header.fsf_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
426 break;
427
428 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
430 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 break;
432
433 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
435 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
438 skip_fsfstatus:
439 /*
440 * always call specific handlers to give them a chance to do
441 * something meaningful even in error cases
442 */
443 zfcp_fsf_req_dispatch(fsf_req);
444
445 return retval;
446}
447
448/*
449 * function: zfcp_fsf_fsfstatus_qual_eval
450 *
451 * purpose: evaluates FSF status-qualifier of completed FSF request
452 * and acts accordingly
453 *
454 * returns:
455 */
456static int
457zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
458{
459 int retval = 0;
460
461 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
462 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 break;
464 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
467 break;
468 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
471 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
472 break;
473 case FSF_SQ_NO_RECOM:
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100474 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 "problem on the adapter %s "
476 "Stopping all operations on this adapter. ",
477 zfcp_get_busid_by_adapter(fsf_req->adapter));
478 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
480 break;
481 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
483 "(adapter %s)\n",
484 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
486 break;
487 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
488 case FSF_SQ_NO_RETRY_POSSIBLE:
489 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
490 /* dealt with in the respective functions */
491 break;
492 default:
493 ZFCP_LOG_NORMAL("bug: Additional status info could "
494 "not be interpreted properly.\n");
495 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
496 (char *) &fsf_req->qtcb->header.fsf_status_qual,
497 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
499 break;
500 }
501
502 return retval;
503}
504
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200505/**
506 * zfcp_fsf_link_down_info_eval - evaluate link down information block
507 */
508static void
Martin Peschke698ec0162008-03-27 14:22:02 +0100509zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200510 struct fsf_link_down_info *link_down)
511{
Martin Peschke698ec0162008-03-27 14:22:02 +0100512 struct zfcp_adapter *adapter = fsf_req->adapter;
513
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100514 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
515 &adapter->status))
516 return;
517
518 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
519
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100520 if (link_down == NULL)
521 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100522
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200523 switch (link_down->error_code) {
524 case FSF_PSQ_LINK_NO_LIGHT:
525 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
526 "(no light detected)\n",
527 zfcp_get_busid_by_adapter(adapter));
528 break;
529 case FSF_PSQ_LINK_WRAP_PLUG:
530 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
531 "(wrap plug detected)\n",
532 zfcp_get_busid_by_adapter(adapter));
533 break;
534 case FSF_PSQ_LINK_NO_FCP:
535 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
536 "(adjacent node on link does not support FCP)\n",
537 zfcp_get_busid_by_adapter(adapter));
538 break;
539 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
540 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
541 "(firmware update in progress)\n",
542 zfcp_get_busid_by_adapter(adapter));
543 break;
544 case FSF_PSQ_LINK_INVALID_WWPN:
545 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
546 "(duplicate or invalid WWPN detected)\n",
547 zfcp_get_busid_by_adapter(adapter));
548 break;
549 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
550 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
551 "(no support for NPIV by Fabric)\n",
552 zfcp_get_busid_by_adapter(adapter));
553 break;
554 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
555 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
556 "(out of resource in FCP daughtercard)\n",
557 zfcp_get_busid_by_adapter(adapter));
558 break;
559 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
560 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
561 "(out of resource in Fabric)\n",
562 zfcp_get_busid_by_adapter(adapter));
563 break;
564 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
565 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
566 "(unable to Fabric login)\n",
567 zfcp_get_busid_by_adapter(adapter));
568 break;
569 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
570 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
571 zfcp_get_busid_by_adapter(adapter));
572 break;
573 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
574 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
575 zfcp_get_busid_by_adapter(adapter));
576 break;
577 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
578 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
579 zfcp_get_busid_by_adapter(adapter));
580 break;
581 default:
582 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
583 "(warning: unknown reason code %d)\n",
584 zfcp_get_busid_by_adapter(adapter),
585 link_down->error_code);
586 }
587
588 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
589 ZFCP_LOG_DEBUG("Debug information to link down: "
590 "primary_status=0x%02x "
591 "ioerr_code=0x%02x "
592 "action_code=0x%02x "
593 "reason_code=0x%02x "
594 "explanation_code=0x%02x "
595 "vendor_specific_code=0x%02x\n",
596 link_down->primary_status,
597 link_down->ioerr_code,
598 link_down->action_code,
599 link_down->reason_code,
600 link_down->explanation_code,
601 link_down->vendor_specific_code);
602
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100603 out:
Martin Peschke698ec0162008-03-27 14:22:02 +0100604 zfcp_erp_adapter_failed(adapter, id, (u64)fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200605}
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607/*
608 * function: zfcp_fsf_req_dispatch
609 *
610 * purpose: calls the appropriate command specific handler
611 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200612 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 */
614static int
615zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
616{
617 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
618 struct zfcp_adapter *adapter = fsf_req->adapter;
619 int retval = 0;
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 switch (fsf_req->fsf_command) {
623
624 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 zfcp_fsf_send_fcp_command_handler(fsf_req);
626 break;
627
628 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 zfcp_fsf_abort_fcp_command_handler(fsf_req);
630 break;
631
632 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 zfcp_fsf_send_ct_handler(fsf_req);
634 break;
635
636 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 zfcp_fsf_open_port_handler(fsf_req);
638 break;
639
640 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 zfcp_fsf_open_unit_handler(fsf_req);
642 break;
643
644 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 zfcp_fsf_close_unit_handler(fsf_req);
646 break;
647
648 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 zfcp_fsf_close_port_handler(fsf_req);
650 break;
651
652 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 zfcp_fsf_close_physical_port_handler(fsf_req);
654 break;
655
656 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 zfcp_fsf_exchange_config_data_handler(fsf_req);
658 break;
659
660 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 zfcp_fsf_exchange_port_data_handler(fsf_req);
662 break;
663
664 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 zfcp_fsf_send_els_handler(fsf_req);
666 break;
667
668 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 zfcp_fsf_control_file_handler(fsf_req);
670 break;
671
672 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 zfcp_fsf_control_file_handler(fsf_req);
674 break;
675
676 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
678 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
679 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200680 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
682 ZFCP_LOG_NORMAL
683 ("bug: Command issued by the device driver differs "
684 "from the command returned by the adapter %s "
685 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200686 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 fsf_req->fsf_command,
688 fsf_req->qtcb->header.fsf_command);
689 }
690
691 if (!erp_action)
692 return retval;
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 zfcp_erp_async_handler(erp_action, 0);
695
696 return retval;
697}
698
699/*
700 * function: zfcp_fsf_status_read
701 *
702 * purpose: initiates a Status Read command at the specified adapter
703 *
704 * returns:
705 */
706int
707zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
708{
709 struct zfcp_fsf_req *fsf_req;
710 struct fsf_status_read_buffer *status_buffer;
711 unsigned long lock_flags;
712 volatile struct qdio_buffer_element *sbale;
713 int retval = 0;
714
715 /* setup new FSF request */
716 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
717 req_flags | ZFCP_REQ_NO_QTCB,
718 adapter->pool.fsf_req_status_read,
719 &lock_flags, &fsf_req);
720 if (retval < 0) {
721 ZFCP_LOG_INFO("error: Could not create unsolicited status "
722 "buffer for adapter %s.\n",
723 zfcp_get_busid_by_adapter(adapter));
724 goto failed_req_create;
725 }
726
727 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
728 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
729 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
730 fsf_req->sbale_curr = 2;
731
732 status_buffer =
733 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
734 if (!status_buffer) {
735 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
736 goto failed_buf;
737 }
738 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200739 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 /* insert pointer to respective buffer */
742 sbale = zfcp_qdio_sbale_curr(fsf_req);
743 sbale->addr = (void *) status_buffer;
744 sbale->length = sizeof(struct fsf_status_read_buffer);
745
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200746 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 if (retval) {
748 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
749 "environment.\n");
750 goto failed_req_send;
751 }
752
753 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
754 zfcp_get_busid_by_adapter(adapter));
755 goto out;
756
757 failed_req_send:
758 mempool_free(status_buffer, adapter->pool.data_status_read);
759
760 failed_buf:
761 zfcp_fsf_req_free(fsf_req);
762 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200763 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 out:
765 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
766 return retval;
767}
768
769static int
770zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
771{
772 struct fsf_status_read_buffer *status_buffer;
773 struct zfcp_adapter *adapter;
774 struct zfcp_port *port;
775 unsigned long flags;
776
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200777 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 adapter = fsf_req->adapter;
779
780 read_lock_irqsave(&zfcp_data.config_lock, flags);
781 list_for_each_entry(port, &adapter->port_list_head, list)
782 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
783 break;
784 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
785
786 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100787 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200788 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 "adapter %s. Ignored.\n",
790 status_buffer->d_id & ZFCP_DID_MASK,
791 zfcp_get_busid_by_adapter(adapter));
792 goto out;
793 }
794
795 switch (status_buffer->status_subtype) {
796
797 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
799 zfcp_erp_port_reopen(port, 0);
800 break;
801
802 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
804 zfcp_erp_port_shutdown(port, 0);
805 break;
806
807 default:
808 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
809 debug_exception(adapter->erp_dbf, 0,
810 &status_buffer->status_subtype, sizeof (u32));
811 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
812 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200813 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 "Ignored. (debug info 0x%x)\n",
815 status_buffer->d_id,
816 zfcp_get_busid_by_adapter(adapter),
817 status_buffer->status_subtype);
818 }
819 out:
820 return 0;
821}
822
823/*
824 * function: zfcp_fsf_status_read_handler
825 *
826 * purpose: is called for finished Open Port command
827 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200828 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 */
830static int
831zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
832{
833 int retval = 0;
834 struct zfcp_adapter *adapter = fsf_req->adapter;
835 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200836 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200837 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200840 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200842 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 goto out;
844 }
845
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200846 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 switch (status_buffer->status_type) {
849
850 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 zfcp_fsf_status_read_port_closed(fsf_req);
852 break;
853
854 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 zfcp_fsf_incoming_els(fsf_req);
856 break;
857
858 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
860 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 break;
862
863 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200864 fsf_bit_error = (struct fsf_bit_error_payload *)
865 status_buffer->payload;
866 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
867 "received (adapter %s, "
868 "link failures = %i, loss of sync errors = %i, "
869 "loss of signal errors = %i, "
870 "primitive sequence errors = %i, "
871 "invalid transmission word errors = %i, "
872 "CRC errors = %i)\n",
873 zfcp_get_busid_by_adapter(adapter),
874 fsf_bit_error->link_failure_error_count,
875 fsf_bit_error->loss_of_sync_error_count,
876 fsf_bit_error->loss_of_signal_error_count,
877 fsf_bit_error->primitive_sequence_error_count,
878 fsf_bit_error->invalid_transmission_word_error_count,
879 fsf_bit_error->crc_error_count);
880 ZFCP_LOG_INFO("Additional bit error threshold data "
881 "(adapter %s, "
882 "primitive sequence event time-outs = %i, "
883 "elastic buffer overrun errors = %i, "
884 "advertised receive buffer-to-buffer credit = %i, "
885 "current receice buffer-to-buffer credit = %i, "
886 "advertised transmit buffer-to-buffer credit = %i, "
887 "current transmit buffer-to-buffer credit = %i)\n",
888 zfcp_get_busid_by_adapter(adapter),
889 fsf_bit_error->primitive_sequence_event_timeout_count,
890 fsf_bit_error->elastic_buffer_overrun_error_count,
891 fsf_bit_error->advertised_receive_b2b_credit,
892 fsf_bit_error->current_receive_b2b_credit,
893 fsf_bit_error->advertised_transmit_b2b_credit,
894 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 break;
896
897 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200898 switch (status_buffer->status_subtype) {
899 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
900 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
901 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100902 zfcp_fsf_link_down_info_eval(fsf_req, 38,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100903 (struct fsf_link_down_info *)
904 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200905 break;
906 case FSF_STATUS_READ_SUB_FDISC_FAILED:
907 ZFCP_LOG_INFO("Local link to adapter %s is down "
908 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100909 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100910 zfcp_fsf_link_down_info_eval(fsf_req, 39,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100911 (struct fsf_link_down_info *)
912 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200913 break;
914 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
915 ZFCP_LOG_INFO("Local link to adapter %s is down "
916 "due to firmware update on adapter\n",
917 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100918 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200919 break;
920 default:
921 ZFCP_LOG_INFO("Local link to adapter %s is down "
922 "due to unknown reason\n",
923 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100924 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200925 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 break;
927
928 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200929 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100930 "Restarting operations on this adapter\n",
931 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 /* All ports should be marked as ready to run again */
Martin Peschke698ec0162008-03-27 14:22:02 +0100933 zfcp_erp_modify_adapter_status(adapter, 30, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 ZFCP_STATUS_COMMON_RUNNING,
935 ZFCP_SET);
936 zfcp_erp_adapter_reopen(adapter,
937 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
938 | ZFCP_STATUS_COMMON_ERP_FAILED);
939 break;
940
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100941 case FSF_STATUS_READ_NOTIFICATION_LOST:
942 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
943 "adapter %s%s%s%s%s%s%s%s%s\n",
944 zfcp_get_busid_by_adapter(adapter),
945 (status_buffer->status_subtype &
946 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
947 ", incoming ELS" : "",
948 (status_buffer->status_subtype &
949 FSF_STATUS_READ_SUB_SENSE_DATA) ?
950 ", sense data" : "",
951 (status_buffer->status_subtype &
952 FSF_STATUS_READ_SUB_LINK_STATUS) ?
953 ", link status change" : "",
954 (status_buffer->status_subtype &
955 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
956 ", port close" : "",
957 (status_buffer->status_subtype &
958 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
959 ", bit error exception" : "",
960 (status_buffer->status_subtype &
961 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
962 ", ACT update" : "",
963 (status_buffer->status_subtype &
964 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
965 ", ACT hardening" : "",
966 (status_buffer->status_subtype &
967 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
968 ", adapter feature change" : "");
969
970 if (status_buffer->status_subtype &
971 FSF_STATUS_READ_SUB_ACT_UPDATED)
972 zfcp_erp_adapter_access_changed(adapter);
973 break;
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200976 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 zfcp_get_busid_by_adapter(adapter));
978 zfcp_erp_adapter_access_changed(adapter);
979 break;
980
981 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 switch (status_buffer->status_subtype) {
983 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200984 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 zfcp_get_busid_by_adapter(adapter));
986 break;
987 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200988 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 "to the secondary SE\n",
990 zfcp_get_busid_by_adapter(adapter));
991 break;
992 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200993 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 zfcp_get_busid_by_adapter(adapter));
995 }
996 break;
997
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200998 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
999 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1000 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1001 "been changed from 0x%08X to 0x%08X\n",
1002 zfcp_get_busid_by_adapter(adapter),
1003 *(u32*) (status_buffer->payload + 4),
1004 *(u32*) (status_buffer->payload));
1005 adapter->adapter_features = *(u32*) status_buffer->payload;
1006 break;
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001009 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 "type was received (debug info 0x%x)\n",
1011 status_buffer->status_type);
1012 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1013 status_buffer);
1014 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1015 (char *) status_buffer,
1016 sizeof (struct fsf_status_read_buffer));
1017 break;
1018 }
1019 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001020 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 /*
1022 * recycle buffer and start new request repeat until outbound
1023 * queue is empty or adapter shutdown is requested
1024 */
1025 /*
1026 * FIXME(qdio):
1027 * we may wait in the req_create for 5s during shutdown, so
1028 * qdio_cleanup will have to wait at least that long before returning
1029 * with failure to allow us a proper cleanup under all circumstances
1030 */
1031 /*
1032 * FIXME:
1033 * allocation failure possible? (Is this code needed?)
1034 */
1035 retval = zfcp_fsf_status_read(adapter, 0);
1036 if (retval < 0) {
1037 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1038 "request for the adapter %s.\n",
1039 zfcp_get_busid_by_adapter(adapter));
1040 /* temporary fix to avoid status read buffer shortage */
1041 adapter->status_read_failed++;
1042 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1043 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1044 ZFCP_LOG_INFO("restart adapter %s due to status read "
1045 "buffer shortage\n",
1046 zfcp_get_busid_by_adapter(adapter));
1047 zfcp_erp_adapter_reopen(adapter, 0);
1048 }
1049 }
1050 out:
1051 return retval;
1052}
1053
1054/*
1055 * function: zfcp_fsf_abort_fcp_command
1056 *
1057 * purpose: tells FSF to abort a running SCSI command
1058 *
1059 * returns: address of initiated FSF request
1060 * NULL - request could not be initiated
1061 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001062 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 * FIXME(design) shouldn't this be modified to return an int
1064 * also...don't know how though
1065 */
1066struct zfcp_fsf_req *
1067zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1068 struct zfcp_adapter *adapter,
1069 struct zfcp_unit *unit, int req_flags)
1070{
1071 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001073 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 int retval = 0;
1075
1076 /* setup new FSF request */
1077 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1078 req_flags, adapter->pool.fsf_req_abort,
1079 &lock_flags, &fsf_req);
1080 if (retval < 0) {
1081 ZFCP_LOG_INFO("error: Failed to create an abort command "
1082 "request for lun 0x%016Lx on port 0x%016Lx "
1083 "on adapter %s.\n",
1084 unit->fcp_lun,
1085 unit->port->wwpn,
1086 zfcp_get_busid_by_adapter(adapter));
1087 goto out;
1088 }
1089
Christof Schmitt951f7462007-12-20 12:30:24 +01001090 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1091 &unit->status)))
1092 goto unit_blocked;
1093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1095 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1096 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1097
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001098 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 /* set handles of unit and its parent port in QTCB */
1101 fsf_req->qtcb->header.lun_handle = unit->handle;
1102 fsf_req->qtcb->header.port_handle = unit->port->handle;
1103
1104 /* set handle of request which should be aborted */
1105 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1106
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001107 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1108 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001109 if (!retval)
1110 goto out;
1111
1112 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 zfcp_fsf_req_free(fsf_req);
1114 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 out:
1117 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1118 return fsf_req;
1119}
1120
1121/*
1122 * function: zfcp_fsf_abort_fcp_command_handler
1123 *
1124 * purpose: is called for finished Abort FCP Command request
1125 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001126 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 */
1128static int
1129zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1130{
1131 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001132 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001133 union fsf_status_qual *fsf_stat_qual =
1134 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1137 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1138 goto skip_fsfstatus;
1139 }
1140
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001141 unit = (struct zfcp_unit *) new_fsf_req->data;
1142
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 /* evaluate FSF status in QTCB */
1144 switch (new_fsf_req->qtcb->header.fsf_status) {
1145
1146 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001147 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1149 "fsf_s_phand_nv0");
1150 /*
1151 * In this case a command that was sent prior to a port
1152 * reopen was aborted (handles are different). This is
1153 * fine.
1154 */
1155 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1157 "port 0x%016Lx on adapter %s invalid. "
1158 "This may happen occasionally.\n",
1159 unit->port->handle,
1160 unit->port->wwpn,
1161 zfcp_get_busid_by_unit(unit));
1162 ZFCP_LOG_INFO("status qualifier:\n");
1163 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1164 (char *) &new_fsf_req->qtcb->header.
1165 fsf_status_qual,
1166 sizeof (union fsf_status_qual));
1167 /* Let's hope this sorts out the mess */
1168 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1169 "fsf_s_phand_nv1");
1170 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1171 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1172 }
1173 break;
1174
1175 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001176 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1178 "fsf_s_lhand_nv0");
1179 /*
1180 * In this case a command that was sent prior to a unit
1181 * reopen was aborted (handles are different).
1182 * This is fine.
1183 */
1184 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 ZFCP_LOG_INFO
1186 ("Warning: Temporary LUN identifier 0x%x of LUN "
1187 "0x%016Lx on port 0x%016Lx on adapter %s is "
1188 "invalid. This may happen in rare cases. "
1189 "Trying to re-establish link.\n",
1190 unit->handle,
1191 unit->fcp_lun,
1192 unit->port->wwpn,
1193 zfcp_get_busid_by_unit(unit));
1194 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1195 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1196 (char *) &new_fsf_req->qtcb->header.
1197 fsf_status_qual,
1198 sizeof (union fsf_status_qual));
1199 /* Let's hope this sorts out the mess */
1200 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1201 "fsf_s_lhand_nv1");
1202 zfcp_erp_port_reopen(unit->port, 0);
1203 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1204 }
1205 break;
1206
1207 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 retval = 0;
1209 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1210 "fsf_s_no_exist");
1211 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1212 break;
1213
1214 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1216 "be reopened\n", unit->port->wwpn,
1217 zfcp_get_busid_by_unit(unit));
1218 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1219 "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01001220 zfcp_erp_port_boxed(unit->port, 47, (u64)new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1222 | ZFCP_STATUS_FSFREQ_RETRY;
1223 break;
1224
1225 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 ZFCP_LOG_INFO(
1227 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1228 "to be reopened\n",
1229 unit->fcp_lun, unit->port->wwpn,
1230 zfcp_get_busid_by_unit(unit));
1231 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01001232 zfcp_erp_unit_boxed(unit, 48, (u64)new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1234 | ZFCP_STATUS_FSFREQ_RETRY;
1235 break;
1236
1237 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1239 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1241 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001242 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1244 break;
1245 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 /* SCSI stack will escalate */
1247 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1248 "fsf_sq_ulp");
1249 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1250 break;
1251 default:
1252 ZFCP_LOG_NORMAL
1253 ("bug: Wrong status qualifier 0x%x arrived.\n",
1254 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1255 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1256 "fsf_sq_inval:");
1257 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1258 &new_fsf_req->qtcb->header.
1259 fsf_status_qual.word[0], sizeof (u32));
1260 break;
1261 }
1262 break;
1263
1264 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 retval = 0;
1266 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1267 break;
1268
1269 default:
1270 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1271 "(debug info 0x%x)\n",
1272 new_fsf_req->qtcb->header.fsf_status);
1273 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1274 "fsf_s_inval:");
1275 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1276 &new_fsf_req->qtcb->header.fsf_status,
1277 sizeof (u32));
1278 break;
1279 }
1280 skip_fsfstatus:
1281 return retval;
1282}
1283
1284/**
1285 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1286 * one SBALE
1287 * Two scatter-gather lists are passed, one for the reqeust and one for the
1288 * response.
1289 */
1290static inline int
1291zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1292 struct scatterlist *resp, int resp_count)
1293{
1294 return ((req_count == 1) &&
1295 (resp_count == 1) &&
1296 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1297 PAGE_MASK) ==
1298 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1299 req[0].length - 1) & PAGE_MASK)) &&
1300 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1301 PAGE_MASK) ==
1302 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1303 resp[0].length - 1) & PAGE_MASK)));
1304}
1305
1306/**
1307 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1308 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1309 * the request
1310 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1311 * a struct zfcp_fsf_req
1312 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1313 * is sent within error recovery
1314 */
1315int
1316zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1317 struct zfcp_erp_action *erp_action)
1318{
1319 volatile struct qdio_buffer_element *sbale;
1320 struct zfcp_port *port;
1321 struct zfcp_adapter *adapter;
1322 struct zfcp_fsf_req *fsf_req;
1323 unsigned long lock_flags;
1324 int bytes;
1325 int ret = 0;
1326
1327 port = ct->port;
1328 adapter = port->adapter;
1329
1330 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1331 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1332 pool, &lock_flags, &fsf_req);
1333 if (ret < 0) {
1334 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1335 "adapter: %s\n",
1336 zfcp_get_busid_by_adapter(adapter));
1337 goto failed_req;
1338 }
1339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1341 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1342 ct->resp, ct->resp_count)){
1343 /* both request buffer and response buffer
1344 fit into one sbale each */
1345 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1346 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1347 sbale[2].length = ct->req[0].length;
1348 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1349 sbale[3].length = ct->resp[0].length;
1350 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001351 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1353 /* try to use chained SBALs */
1354 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1355 SBAL_FLAGS0_TYPE_WRITE_READ,
1356 ct->req, ct->req_count,
1357 ZFCP_MAX_SBALS_PER_CT_REQ);
1358 if (bytes <= 0) {
1359 ZFCP_LOG_INFO("error: creation of CT request failed "
1360 "on adapter %s\n",
1361 zfcp_get_busid_by_adapter(adapter));
1362 if (bytes == 0)
1363 ret = -ENOMEM;
1364 else
1365 ret = bytes;
1366
1367 goto failed_send;
1368 }
1369 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1370 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1371 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1372 SBAL_FLAGS0_TYPE_WRITE_READ,
1373 ct->resp, ct->resp_count,
1374 ZFCP_MAX_SBALS_PER_CT_REQ);
1375 if (bytes <= 0) {
1376 ZFCP_LOG_INFO("error: creation of CT request failed "
1377 "on adapter %s\n",
1378 zfcp_get_busid_by_adapter(adapter));
1379 if (bytes == 0)
1380 ret = -ENOMEM;
1381 else
1382 ret = bytes;
1383
1384 goto failed_send;
1385 }
1386 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1387 } else {
1388 /* reject send generic request */
1389 ZFCP_LOG_INFO(
1390 "error: microcode does not support chained SBALs,"
1391 "CT request too big (adapter %s)\n",
1392 zfcp_get_busid_by_adapter(adapter));
1393 ret = -EOPNOTSUPP;
1394 goto failed_send;
1395 }
1396
1397 /* settings in QTCB */
1398 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001399 fsf_req->qtcb->bottom.support.service_class =
1400 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001402 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001404 zfcp_san_dbf_event_ct_request(fsf_req);
1405
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001406 if (erp_action) {
1407 erp_action->fsf_req = fsf_req;
1408 fsf_req->erp_action = erp_action;
1409 zfcp_erp_start_timer(fsf_req);
1410 } else
1411 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1412
1413 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if (ret) {
1415 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1416 "(adapter %s, port 0x%016Lx)\n",
1417 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1418 goto failed_send;
1419 }
1420
1421 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1422 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1423 goto out;
1424
1425 failed_send:
1426 zfcp_fsf_req_free(fsf_req);
1427 if (erp_action != NULL) {
1428 erp_action->fsf_req = NULL;
1429 }
1430 failed_req:
1431 out:
1432 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1433 lock_flags);
1434 return ret;
1435}
1436
1437/**
1438 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1439 * @fsf_req: pointer to struct zfcp_fsf_req
1440 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001441 * Data specific for the Generic Service request is passed using
1442 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1443 * Usually a specific handler for the CT request is called which is
1444 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 */
1446static int
1447zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1448{
1449 struct zfcp_port *port;
1450 struct zfcp_adapter *adapter;
1451 struct zfcp_send_ct *send_ct;
1452 struct fsf_qtcb_header *header;
1453 struct fsf_qtcb_bottom_support *bottom;
1454 int retval = -EINVAL;
1455 u16 subtable, rule, counter;
1456
1457 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001458 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 port = send_ct->port;
1460 header = &fsf_req->qtcb->header;
1461 bottom = &fsf_req->qtcb->bottom.support;
1462
1463 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1464 goto skip_fsfstatus;
1465
1466 /* evaluate FSF status in QTCB */
1467 switch (header->fsf_status) {
1468
1469 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001470 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 retval = 0;
1472 break;
1473
1474 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001475 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1476 "class %d.\n",
1477 zfcp_get_busid_by_port(port),
1478 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 /* stop operation for this adapter */
1480 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1481 zfcp_erp_adapter_shutdown(adapter, 0);
1482 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1483 break;
1484
1485 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 switch (header->fsf_status_qual.word[0]){
1487 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 /* reopening link to port */
1489 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1490 zfcp_test_link(port);
1491 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1492 break;
1493 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 /* ERP strategy will escalate */
1495 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1497 break;
1498 default:
1499 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1500 "arrived.\n",
1501 header->fsf_status_qual.word[0]);
1502 break;
1503 }
1504 break;
1505
1506 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001508 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 zfcp_get_busid_by_port(port), port->d_id);
1510 for (counter = 0; counter < 2; counter++) {
1511 subtable = header->fsf_status_qual.halfword[counter * 2];
1512 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1513 switch (subtable) {
1514 case FSF_SQ_CFDC_SUBTABLE_OS:
1515 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1516 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1517 case FSF_SQ_CFDC_SUBTABLE_LUN:
1518 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1519 zfcp_act_subtable_type[subtable], rule);
1520 break;
1521 }
1522 }
1523 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01001524 zfcp_erp_port_access_denied(port, 55, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1526 break;
1527
1528 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001530 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 zfcp_get_busid_by_port(port), port->d_id);
1532 ZFCP_LOG_INFO("status qualifier:\n");
1533 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1534 (char *) &header->fsf_status_qual,
1535 sizeof (union fsf_status_qual));
1536 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1538 break;
1539
1540 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1542 "0x%016Lx on adapter %s invalid. This may "
1543 "happen occasionally.\n", port->handle,
1544 port->wwpn, zfcp_get_busid_by_port(port));
1545 ZFCP_LOG_INFO("status qualifier:\n");
1546 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1547 (char *) &header->fsf_status_qual,
1548 sizeof (union fsf_status_qual));
1549 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1550 zfcp_erp_adapter_reopen(adapter, 0);
1551 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1552 break;
1553
1554 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001556 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 zfcp_get_busid_by_port(port), port->d_id);
1558 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01001559 zfcp_erp_port_boxed(port, 49, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1561 | ZFCP_STATUS_FSFREQ_RETRY;
1562 break;
1563
1564 /* following states should never occure, all cases avoided
1565 in zfcp_fsf_send_ct - but who knows ... */
1566 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1568 "req_buf_length=%d, resp_buf_length=%d)\n",
1569 zfcp_get_busid_by_adapter(adapter),
1570 bottom->req_buf_length, bottom->resp_buf_length);
1571 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1572 break;
1573 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1575 "req_buf_length=%d)\n",
1576 zfcp_get_busid_by_adapter(adapter),
1577 bottom->req_buf_length);
1578 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1579 break;
1580 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1582 "resp_buf_length=%d)\n",
1583 zfcp_get_busid_by_adapter(adapter),
1584 bottom->resp_buf_length);
1585 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1586 break;
1587 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1589 "resp_buf_length=%d)\n",
1590 zfcp_get_busid_by_adapter(adapter),
1591 bottom->req_buf_length, bottom->resp_buf_length);
1592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1593 break;
1594
1595 default:
1596 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1597 "(debug info 0x%x)\n", header->fsf_status);
1598 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1599 debug_exception(adapter->erp_dbf, 0,
1600 &header->fsf_status_qual.word[0], sizeof (u32));
1601 break;
1602 }
1603
1604skip_fsfstatus:
1605 send_ct->status = retval;
1606
1607 if (send_ct->handler != NULL)
1608 send_ct->handler(send_ct->handler_data);
1609
1610 return retval;
1611}
1612
1613/**
1614 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1615 * @els: pointer to struct zfcp_send_els which contains all needed data for
1616 * the command.
1617 */
1618int
1619zfcp_fsf_send_els(struct zfcp_send_els *els)
1620{
1621 volatile struct qdio_buffer_element *sbale;
1622 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001623 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 struct zfcp_adapter *adapter;
1625 unsigned long lock_flags;
1626 int bytes;
1627 int ret = 0;
1628
1629 d_id = els->d_id;
1630 adapter = els->adapter;
1631
1632 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1633 ZFCP_REQ_AUTO_CLEANUP,
1634 NULL, &lock_flags, &fsf_req);
1635 if (ret < 0) {
1636 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001637 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 zfcp_get_busid_by_adapter(adapter), d_id);
1639 goto failed_req;
1640 }
1641
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001642 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1643 &els->port->status))) {
1644 ret = -EBUSY;
1645 goto port_blocked;
1646 }
1647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1649 if (zfcp_use_one_sbal(els->req, els->req_count,
1650 els->resp, els->resp_count)){
1651 /* both request buffer and response buffer
1652 fit into one sbale each */
1653 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1654 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1655 sbale[2].length = els->req[0].length;
1656 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1657 sbale[3].length = els->resp[0].length;
1658 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001659 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1661 /* try to use chained SBALs */
1662 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1663 SBAL_FLAGS0_TYPE_WRITE_READ,
1664 els->req, els->req_count,
1665 ZFCP_MAX_SBALS_PER_ELS_REQ);
1666 if (bytes <= 0) {
1667 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001668 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 zfcp_get_busid_by_adapter(adapter), d_id);
1670 if (bytes == 0) {
1671 ret = -ENOMEM;
1672 } else {
1673 ret = bytes;
1674 }
1675 goto failed_send;
1676 }
1677 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1678 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1679 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1680 SBAL_FLAGS0_TYPE_WRITE_READ,
1681 els->resp, els->resp_count,
1682 ZFCP_MAX_SBALS_PER_ELS_REQ);
1683 if (bytes <= 0) {
1684 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001685 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 zfcp_get_busid_by_adapter(adapter), d_id);
1687 if (bytes == 0) {
1688 ret = -ENOMEM;
1689 } else {
1690 ret = bytes;
1691 }
1692 goto failed_send;
1693 }
1694 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1695 } else {
1696 /* reject request */
1697 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1698 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001699 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 zfcp_get_busid_by_adapter(adapter), d_id);
1701 ret = -EOPNOTSUPP;
1702 goto failed_send;
1703 }
1704
1705 /* settings in QTCB */
1706 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001707 fsf_req->qtcb->bottom.support.service_class =
1708 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001710 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1713
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001714 zfcp_san_dbf_event_els_request(fsf_req);
1715
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001716 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1717 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 if (ret) {
1719 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001720 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 zfcp_get_busid_by_adapter(adapter), d_id);
1722 goto failed_send;
1723 }
1724
1725 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001726 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 goto out;
1728
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001729 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 failed_send:
1731 zfcp_fsf_req_free(fsf_req);
1732
1733 failed_req:
1734 out:
1735 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1736 lock_flags);
1737
1738 return ret;
1739}
1740
1741/**
1742 * zfcp_fsf_send_els_handler - handler for ELS commands
1743 * @fsf_req: pointer to struct zfcp_fsf_req
1744 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001745 * Data specific for the ELS command is passed using
1746 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1747 * Usually a specific handler for the ELS command is called which is
1748 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 */
1750static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1751{
1752 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001754 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 struct fsf_qtcb_header *header;
1756 struct fsf_qtcb_bottom_support *bottom;
1757 struct zfcp_send_els *send_els;
1758 int retval = -EINVAL;
1759 u16 subtable, rule, counter;
1760
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001761 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001763 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 d_id = send_els->d_id;
1765 header = &fsf_req->qtcb->header;
1766 bottom = &fsf_req->qtcb->bottom.support;
1767
1768 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1769 goto skip_fsfstatus;
1770
1771 switch (header->fsf_status) {
1772
1773 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001774 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 retval = 0;
1776 break;
1777
1778 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001779 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1780 "class %d.\n",
1781 zfcp_get_busid_by_adapter(adapter),
1782 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 /* stop operation for this adapter */
1784 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1785 zfcp_erp_adapter_shutdown(adapter, 0);
1786 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1787 break;
1788
1789 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 switch (header->fsf_status_qual.word[0]){
1791 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001793 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1794 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1796 break;
1797 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1799 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1800 retval =
1801 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1802 (struct zfcp_ls_rjt_par *)
1803 &header->fsf_status_qual.word[2]);
1804 break;
1805 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1808 break;
1809 default:
1810 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1811 header->fsf_status_qual.word[0]);
1812 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1813 (char*)header->fsf_status_qual.word, 16);
1814 }
1815 break;
1816
1817 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1819 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001820 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 zfcp_get_busid_by_adapter(adapter), d_id);
1822
1823 break;
1824
1825 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 ZFCP_LOG_INFO(
1827 "ELS request size and ELS response size must be either "
1828 "both 0, or both greater than 0 "
1829 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1830 zfcp_get_busid_by_adapter(adapter),
1831 bottom->req_buf_length,
1832 bottom->resp_buf_length);
1833 break;
1834
1835 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 ZFCP_LOG_INFO(
1837 "Length of the ELS request buffer, "
1838 "specified in QTCB bottom, "
1839 "exceeds the size of the buffers "
1840 "that have been allocated for ELS request data "
1841 "(adapter: %s, req_buf_length=%d)\n",
1842 zfcp_get_busid_by_adapter(adapter),
1843 bottom->req_buf_length);
1844 break;
1845
1846 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 ZFCP_LOG_INFO(
1848 "Length of the ELS response buffer, "
1849 "specified in QTCB bottom, "
1850 "exceeds the size of the buffers "
1851 "that have been allocated for ELS response data "
1852 "(adapter: %s, resp_buf_length=%d)\n",
1853 zfcp_get_busid_by_adapter(adapter),
1854 bottom->resp_buf_length);
1855 break;
1856
1857 case FSF_SBAL_MISMATCH:
1858 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1860 "resp_buf_length=%d)\n",
1861 zfcp_get_busid_by_adapter(adapter),
1862 bottom->req_buf_length, bottom->resp_buf_length);
1863 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1864 break;
1865
1866 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001868 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 zfcp_get_busid_by_adapter(adapter), d_id);
1870 for (counter = 0; counter < 2; counter++) {
1871 subtable = header->fsf_status_qual.halfword[counter * 2];
1872 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1873 switch (subtable) {
1874 case FSF_SQ_CFDC_SUBTABLE_OS:
1875 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1876 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1877 case FSF_SQ_CFDC_SUBTABLE_LUN:
1878 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1879 zfcp_act_subtable_type[subtable], rule);
1880 break;
1881 }
1882 }
1883 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 if (port != NULL)
Martin Peschke698ec0162008-03-27 14:22:02 +01001885 zfcp_erp_port_access_denied(port, 56, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1887 break;
1888
1889 default:
1890 ZFCP_LOG_NORMAL(
1891 "bug: An unknown FSF Status was presented "
1892 "(adapter: %s, fsf_status=0x%08x)\n",
1893 zfcp_get_busid_by_adapter(adapter),
1894 header->fsf_status);
1895 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1896 debug_exception(adapter->erp_dbf, 0,
1897 &header->fsf_status_qual.word[0], sizeof(u32));
1898 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1899 break;
1900 }
1901
1902skip_fsfstatus:
1903 send_els->status = retval;
1904
Heiko Carstensaa551da2007-07-18 10:55:10 +02001905 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 send_els->handler(send_els->handler_data);
1907
1908 return retval;
1909}
1910
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911int
1912zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1913{
1914 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001915 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001916 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001918 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001921 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1923 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001924 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001925 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001926 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1928 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001929 zfcp_get_busid_by_adapter(adapter));
1930 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1931 lock_flags);
1932 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 }
1934
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001935 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001936 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1937 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001939 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001940 FSF_FEATURE_CFDC |
1941 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001942 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001943 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001944 fsf_req->erp_action = erp_action;
1945 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001947 zfcp_erp_start_timer(fsf_req);
1948 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001949 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1950 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001952 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1953 "data command on the adapter %s\n",
1954 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001955 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001957 }
1958 else
1959 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1960 "(adapter %s)\n",
1961 zfcp_get_busid_by_adapter(adapter));
1962
1963 return retval;
1964}
1965
1966int
1967zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1968 struct fsf_qtcb_bottom_config *data)
1969{
1970 volatile struct qdio_buffer_element *sbale;
1971 struct zfcp_fsf_req *fsf_req;
1972 unsigned long lock_flags;
1973 int retval;
1974
1975 /* setup new FSF request */
1976 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1977 0, NULL, &lock_flags, &fsf_req);
1978 if (retval) {
1979 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1980 "data request for adapter %s.\n",
1981 zfcp_get_busid_by_adapter(adapter));
1982 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1983 lock_flags);
1984 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 }
1986
Swen Schillig52ef11a2007-08-28 09:31:09 +02001987 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1988 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1989 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Swen Schillig52ef11a2007-08-28 09:31:09 +02001991 fsf_req->qtcb->bottom.config.feature_selection =
1992 FSF_FEATURE_CFDC |
1993 FSF_FEATURE_LUN_SHARING |
1994 FSF_FEATURE_NOTIFICATION_LOST |
1995 FSF_FEATURE_UPDATE_ALERT;
1996
1997 if (data)
1998 fsf_req->data = (unsigned long) data;
1999
2000 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2001 retval = zfcp_fsf_req_send(fsf_req);
2002 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002004 if (retval)
2005 ZFCP_LOG_INFO("error: Could not send exchange configuration "
2006 "data command on the adapter %s\n",
2007 zfcp_get_busid_by_adapter(adapter));
2008 else
2009 wait_event(fsf_req->completion_wq,
2010 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2011
2012 zfcp_fsf_req_free(fsf_req);
2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 return retval;
2015}
2016
2017/**
2018 * zfcp_fsf_exchange_config_evaluate
2019 * @fsf_req: fsf_req which belongs to xchg config data request
2020 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2021 *
2022 * returns: -EIO on error, 0 otherwise
2023 */
2024static int
2025zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2026{
2027 struct fsf_qtcb_bottom_config *bottom;
2028 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002029 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
2031 bottom = &fsf_req->qtcb->bottom.config;
2032 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2033 bottom->low_qtcb_version, bottom->high_qtcb_version);
2034 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002035 adapter->adapter_features = bottom->adapter_features;
2036 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05002037 adapter->peer_wwpn = 0;
2038 adapter->peer_wwnn = 0;
2039 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02002042
2043 if (fsf_req->data)
2044 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
2045 bottom, sizeof (struct fsf_qtcb_bottom_config));
2046
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002047 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2048 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2049 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2050 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002051 fc_host_supported_classes(shost) =
2052 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002054 if (fc_host_permanent_port_name(shost) == -1)
2055 fc_host_permanent_port_name(shost) =
2056 fc_host_port_name(shost);
2057 if (bottom->fc_topology == FSF_TOPO_P2P) {
2058 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2059 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2060 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2061 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2062 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2063 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2064 else if (bottom->fc_topology == FSF_TOPO_AL)
2065 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2066 else
2067 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002069 fc_host_node_name(shost) = 0;
2070 fc_host_port_name(shost) = 0;
2071 fc_host_port_id(shost) = 0;
2072 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002073 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 adapter->hydra_version = 0;
2075 }
2076
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002077 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002079 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2080 min(FC_SERIAL_NUMBER_SIZE, 17));
2081 EBCASC(fc_host_serial_number(shost),
2082 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 }
2084
Swen Schillig52ef11a2007-08-28 09:31:09 +02002085 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2086 "characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002087 "WWNN 0x%016Lx, "
2088 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002089 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002090 "adapter version 0x%x, "
2091 "LIC version 0x%x, "
2092 "FC link speed %d Gb/s\n",
2093 zfcp_get_busid_by_adapter(adapter),
2094 (wwn_t) fc_host_node_name(shost),
2095 (wwn_t) fc_host_port_name(shost),
2096 fc_host_port_id(shost),
2097 adapter->hydra_version,
2098 adapter->fsf_lic_version,
2099 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2101 ZFCP_LOG_NORMAL("error: the adapter %s "
2102 "only supports newer control block "
2103 "versions in comparison to this device "
2104 "driver (try updated device driver)\n",
2105 zfcp_get_busid_by_adapter(adapter));
2106 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2107 zfcp_erp_adapter_shutdown(adapter, 0);
2108 return -EIO;
2109 }
2110 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2111 ZFCP_LOG_NORMAL("error: the adapter %s "
2112 "only supports older control block "
2113 "versions than this device driver uses"
2114 "(consider a microcode upgrade)\n",
2115 zfcp_get_busid_by_adapter(adapter));
2116 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2117 zfcp_erp_adapter_shutdown(adapter, 0);
2118 return -EIO;
2119 }
2120 return 0;
2121}
2122
Swen Schillig52ef11a2007-08-28 09:31:09 +02002123/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 * function: zfcp_fsf_exchange_config_data_handler
2125 *
2126 * purpose: is called for finished Exchange Configuration Data command
2127 *
2128 * returns:
2129 */
2130static int
2131zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2132{
2133 struct fsf_qtcb_bottom_config *bottom;
2134 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002135 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
2137 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2138 return -EIO;
2139
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002140 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2144 return -EIO;
2145
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002146 switch (fc_host_port_type(adapter->scsi_host)) {
2147 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002148 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2149 "configuration detected at adapter %s\n"
2150 "Peer WWNN 0x%016llx, "
2151 "peer WWPN 0x%016llx, "
2152 "peer d_id 0x%06x\n",
2153 zfcp_get_busid_by_adapter(adapter),
2154 adapter->peer_wwnn,
2155 adapter->peer_wwpn,
2156 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 debug_text_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002158 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002159 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002160 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2162 "topology detected at adapter %s "
2163 "unsupported, shutting down adapter\n",
2164 zfcp_get_busid_by_adapter(adapter));
2165 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2166 "top-al");
2167 zfcp_erp_adapter_shutdown(adapter, 0);
2168 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002169 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002170 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002171 "network detected at adapter %s.\n",
2172 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 break;
2174 default:
2175 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2176 "reported by the exchange "
2177 "configuration command for "
2178 "the adapter %s is not "
2179 "of a type known to the zfcp "
2180 "driver, shutting down adapter\n",
2181 zfcp_get_busid_by_adapter(adapter));
2182 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2183 "unknown-topo");
2184 zfcp_erp_adapter_shutdown(adapter, 0);
2185 return -EIO;
2186 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002187 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2189 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2190 "allowed by the adapter %s "
2191 "is lower than the minimum "
2192 "required by the driver (%ld bytes).\n",
2193 bottom->max_qtcb_size,
2194 zfcp_get_busid_by_adapter(adapter),
2195 sizeof(struct fsf_qtcb));
2196 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2197 "qtcb-size");
2198 debug_event(fsf_req->adapter->erp_dbf, 0,
2199 &bottom->max_qtcb_size, sizeof (u32));
2200 zfcp_erp_adapter_shutdown(adapter, 0);
2201 return -EIO;
2202 }
2203 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2204 &adapter->status);
2205 break;
2206 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2207 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2208
2209 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2210 return -EIO;
2211
Swen Schillig52ef11a2007-08-28 09:31:09 +02002212 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2213 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002214
Martin Peschke698ec0162008-03-27 14:22:02 +01002215 zfcp_fsf_link_down_info_eval(fsf_req, 42,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002216 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 break;
2218 default:
2219 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2220 debug_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002221 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 zfcp_erp_adapter_shutdown(adapter, 0);
2223 return -EIO;
2224 }
2225 return 0;
2226}
2227
2228/**
2229 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002230 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 */
2232int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002233zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
2235 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002236 struct zfcp_fsf_req *fsf_req;
2237 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002238 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002239 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002241 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002243 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002245 return -EOPNOTSUPP;
2246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 /* setup new FSF request */
2249 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002250 ZFCP_REQ_AUTO_CLEANUP,
2251 adapter->pool.fsf_req_erp,
2252 &lock_flags, &fsf_req);
2253 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002255 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002256 "the adapter %s.\n",
2257 zfcp_get_busid_by_adapter(adapter));
2258 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2259 lock_flags);
2260 return retval;
2261 }
2262
2263 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2264 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2265 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2266
2267 erp_action->fsf_req = fsf_req;
2268 fsf_req->erp_action = erp_action;
2269 zfcp_erp_start_timer(fsf_req);
2270
2271 retval = zfcp_fsf_req_send(fsf_req);
2272 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2273
2274 if (retval) {
2275 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2276 "command on the adapter %s\n",
2277 zfcp_get_busid_by_adapter(adapter));
2278 zfcp_fsf_req_free(fsf_req);
2279 erp_action->fsf_req = NULL;
2280 }
2281 else
2282 ZFCP_LOG_DEBUG("exchange port data request initiated "
2283 "(adapter %s)\n",
2284 zfcp_get_busid_by_adapter(adapter));
2285 return retval;
2286}
2287
2288
2289/**
2290 * zfcp_fsf_exchange_port_data_sync - request information about local port
2291 * and wait until information is ready
2292 */
2293int
2294zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2295 struct fsf_qtcb_bottom_port *data)
2296{
2297 volatile struct qdio_buffer_element *sbale;
2298 struct zfcp_fsf_req *fsf_req;
2299 unsigned long lock_flags;
2300 int retval;
2301
2302 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2303 ZFCP_LOG_INFO("error: exchange port data "
2304 "command not supported by adapter %s\n",
2305 zfcp_get_busid_by_adapter(adapter));
2306 return -EOPNOTSUPP;
2307 }
2308
2309 /* setup new FSF request */
2310 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2311 0, NULL, &lock_flags, &fsf_req);
2312 if (retval) {
2313 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002314 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002315 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 zfcp_get_busid_by_adapter(adapter));
2317 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2318 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002319 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002320 }
2321
2322 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002323 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002324
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002326 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2327 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Swen Schillig52ef11a2007-08-28 09:31:09 +02002329 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002330 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002331 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Swen Schillig52ef11a2007-08-28 09:31:09 +02002333 if (retval)
2334 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2335 "command on the adapter %s\n",
2336 zfcp_get_busid_by_adapter(adapter));
2337 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002338 wait_event(fsf_req->completion_wq,
2339 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002340
2341 zfcp_fsf_req_free(fsf_req);
2342
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 return retval;
2344}
2345
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002346/**
2347 * zfcp_fsf_exchange_port_evaluate
2348 * @fsf_req: fsf_req which belongs to xchg port data request
2349 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2350 */
2351static void
2352zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2353{
2354 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002355 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002356 struct Scsi_Host *shost;
2357
2358 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002359 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002360 shost = adapter->scsi_host;
2361
Swen Schillig52ef11a2007-08-28 09:31:09 +02002362 if (fsf_req->data)
2363 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2364 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002365
2366 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2367 fc_host_permanent_port_name(shost) = bottom->wwpn;
2368 else
2369 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2370 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2371 fc_host_supported_speeds(shost) = bottom->supported_speed;
2372}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
2374/**
2375 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2376 * @fsf_req: pointer to struct zfcp_fsf_req
2377 */
2378static void
2379zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2380{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002381 struct zfcp_adapter *adapter;
2382 struct fsf_qtcb *qtcb;
2383
2384 adapter = fsf_req->adapter;
2385 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
2387 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2388 return;
2389
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002390 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002392 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002393 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002394 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002395 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002396 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002397 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Martin Peschke698ec0162008-03-27 14:22:02 +01002398 zfcp_fsf_link_down_info_eval(fsf_req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002399 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002402 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2403 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2405 }
2406}
2407
2408
2409/*
2410 * function: zfcp_fsf_open_port
2411 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002412 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 *
2414 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002415 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 */
2417int
2418zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2419{
2420 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002421 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 unsigned long lock_flags;
2423 int retval = 0;
2424
2425 /* setup new FSF request */
2426 retval = zfcp_fsf_req_create(erp_action->adapter,
2427 FSF_QTCB_OPEN_PORT_WITH_DID,
2428 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2429 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002430 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 if (retval < 0) {
2432 ZFCP_LOG_INFO("error: Could not create open port request "
2433 "for port 0x%016Lx on adapter %s.\n",
2434 erp_action->port->wwpn,
2435 zfcp_get_busid_by_adapter(erp_action->adapter));
2436 goto out;
2437 }
2438
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002439 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2441 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2442
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002443 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002445 fsf_req->data = (unsigned long) erp_action->port;
2446 fsf_req->erp_action = erp_action;
2447 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002449 zfcp_erp_start_timer(fsf_req);
2450 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 if (retval) {
2452 ZFCP_LOG_INFO("error: Could not send open port request for "
2453 "port 0x%016Lx on adapter %s.\n",
2454 erp_action->port->wwpn,
2455 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002456 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 erp_action->fsf_req = NULL;
2458 goto out;
2459 }
2460
2461 ZFCP_LOG_DEBUG("open port request initiated "
2462 "(adapter %s, port 0x%016Lx)\n",
2463 zfcp_get_busid_by_adapter(erp_action->adapter),
2464 erp_action->port->wwpn);
2465 out:
2466 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2467 lock_flags);
2468 return retval;
2469}
2470
2471/*
2472 * function: zfcp_fsf_open_port_handler
2473 *
2474 * purpose: is called for finished Open Port command
2475 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002476 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 */
2478static int
2479zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2480{
2481 int retval = -EINVAL;
2482 struct zfcp_port *port;
2483 struct fsf_plogi *plogi;
2484 struct fsf_qtcb_header *header;
2485 u16 subtable, rule, counter;
2486
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002487 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 header = &fsf_req->qtcb->header;
2489
2490 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2491 /* don't change port status in our bookkeeping */
2492 goto skip_fsfstatus;
2493 }
2494
2495 /* evaluate FSF status in QTCB */
2496 switch (header->fsf_status) {
2497
2498 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2500 "is already open.\n",
2501 port->wwpn, zfcp_get_busid_by_port(port));
2502 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2503 "fsf_s_popen");
2504 /*
2505 * This is a bug, however operation should continue normally
2506 * if it is simply ignored
2507 */
2508 break;
2509
2510 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2512 "on adapter %s\n",
2513 port->wwpn, zfcp_get_busid_by_port(port));
2514 for (counter = 0; counter < 2; counter++) {
2515 subtable = header->fsf_status_qual.halfword[counter * 2];
2516 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2517 switch (subtable) {
2518 case FSF_SQ_CFDC_SUBTABLE_OS:
2519 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2520 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2521 case FSF_SQ_CFDC_SUBTABLE_LUN:
2522 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2523 zfcp_act_subtable_type[subtable], rule);
2524 break;
2525 }
2526 }
2527 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01002528 zfcp_erp_port_access_denied(port, 57, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2530 break;
2531
2532 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2534 "The remote port 0x%016Lx on adapter %s "
2535 "could not be opened. Disabling it.\n",
2536 port->wwpn, zfcp_get_busid_by_port(port));
2537 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2538 "fsf_s_max_ports");
Martin Peschke698ec0162008-03-27 14:22:02 +01002539 zfcp_erp_port_failed(port, 31, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2541 break;
2542
2543 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 switch (header->fsf_status_qual.word[0]) {
2545 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2547 "fsf_sq_ltest");
2548 /* ERP strategy will escalate */
2549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2550 break;
2551 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2552 /* ERP strategy will escalate */
2553 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2554 "fsf_sq_ulp");
2555 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2556 break;
2557 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2559 "adapter %s could not be opened. "
2560 "Disabling it.\n",
2561 port->wwpn,
2562 zfcp_get_busid_by_port(port));
2563 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2564 "fsf_sq_no_retry");
Martin Peschke698ec0162008-03-27 14:22:02 +01002565 zfcp_erp_port_failed(port, 32, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2567 break;
2568 default:
2569 ZFCP_LOG_NORMAL
2570 ("bug: Wrong status qualifier 0x%x arrived.\n",
2571 header->fsf_status_qual.word[0]);
2572 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2573 "fsf_sq_inval:");
2574 debug_exception(
2575 fsf_req->adapter->erp_dbf, 0,
2576 &header->fsf_status_qual.word[0],
2577 sizeof (u32));
2578 break;
2579 }
2580 break;
2581
2582 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 /* save port handle assigned by FSF */
2584 port->handle = header->port_handle;
2585 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2586 "was opened, it's port handle is 0x%x\n",
2587 port->wwpn, zfcp_get_busid_by_port(port),
2588 port->handle);
2589 /* mark port as open */
2590 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2591 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002592 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2593 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2594 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 retval = 0;
2596 /* check whether D_ID has changed during open */
2597 /*
2598 * FIXME: This check is not airtight, as the FCP channel does
2599 * not monitor closures of target port connections caused on
2600 * the remote side. Thus, they might miss out on invalidating
2601 * locally cached WWPNs (and other N_Port parameters) of gone
2602 * target ports. So, our heroic attempt to make things safe
2603 * could be undermined by 'open port' response data tagged with
2604 * obsolete WWPNs. Another reason to monitor potential
2605 * connection closures ourself at least (by interpreting
2606 * incoming ELS' and unsolicited status). It just crosses my
2607 * mind that one should be able to cross-check by means of
2608 * another GID_PN straight after a port has been opened.
2609 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2610 */
2611 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2612 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2613 {
2614 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002615 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 ZFCP_LOG_INFO(
2617 "warning: insufficient length of "
2618 "PLOGI payload (%i)\n",
2619 fsf_req->qtcb->bottom.support.els1_length);
2620 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2621 "fsf_s_short_plogi:");
2622 /* skip sanity check and assume wwpn is ok */
2623 } else {
2624 if (plogi->serv_param.wwpn != port->wwpn) {
2625 ZFCP_LOG_INFO("warning: d_id of port "
2626 "0x%016Lx changed during "
2627 "open\n", port->wwpn);
2628 debug_text_event(
2629 fsf_req->adapter->erp_dbf, 0,
2630 "fsf_s_did_change:");
2631 atomic_clear_mask(
2632 ZFCP_STATUS_PORT_DID_DID,
2633 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002634 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002636 zfcp_plogi_evaluate(port, plogi);
2637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 }
2639 }
2640 break;
2641
2642 case FSF_UNKNOWN_OP_SUBTYPE:
2643 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2645 "op_subtype=0x%x)\n",
2646 zfcp_get_busid_by_port(port),
2647 fsf_req->qtcb->bottom.support.operation_subtype);
2648 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2649 break;
2650
2651 default:
2652 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2653 "(debug info 0x%x)\n",
2654 header->fsf_status);
2655 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2656 debug_exception(fsf_req->adapter->erp_dbf, 0,
2657 &header->fsf_status, sizeof (u32));
2658 break;
2659 }
2660
2661 skip_fsfstatus:
2662 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2663 return retval;
2664}
2665
2666/*
2667 * function: zfcp_fsf_close_port
2668 *
2669 * purpose: submit FSF command "close port"
2670 *
2671 * returns: address of initiated FSF request
2672 * NULL - request could not be initiated
2673 */
2674int
2675zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2676{
2677 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002678 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 unsigned long lock_flags;
2680 int retval = 0;
2681
2682 /* setup new FSF request */
2683 retval = zfcp_fsf_req_create(erp_action->adapter,
2684 FSF_QTCB_CLOSE_PORT,
2685 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2686 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002687 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 if (retval < 0) {
2689 ZFCP_LOG_INFO("error: Could not create a close port request "
2690 "for port 0x%016Lx on adapter %s.\n",
2691 erp_action->port->wwpn,
2692 zfcp_get_busid_by_adapter(erp_action->adapter));
2693 goto out;
2694 }
2695
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002696 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2698 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2699
2700 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002701 fsf_req->data = (unsigned long) erp_action->port;
2702 fsf_req->erp_action = erp_action;
2703 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2704 fsf_req->erp_action = erp_action;
2705 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002707 zfcp_erp_start_timer(fsf_req);
2708 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 if (retval) {
2710 ZFCP_LOG_INFO("error: Could not send a close port request for "
2711 "port 0x%016Lx on adapter %s.\n",
2712 erp_action->port->wwpn,
2713 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002714 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 erp_action->fsf_req = NULL;
2716 goto out;
2717 }
2718
2719 ZFCP_LOG_TRACE("close port request initiated "
2720 "(adapter %s, port 0x%016Lx)\n",
2721 zfcp_get_busid_by_adapter(erp_action->adapter),
2722 erp_action->port->wwpn);
2723 out:
2724 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2725 lock_flags);
2726 return retval;
2727}
2728
2729/*
2730 * function: zfcp_fsf_close_port_handler
2731 *
2732 * purpose: is called for finished Close Port FSF command
2733 *
2734 * returns:
2735 */
2736static int
2737zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2738{
2739 int retval = -EINVAL;
2740 struct zfcp_port *port;
2741
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002742 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
2744 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2745 /* don't change port status in our bookkeeping */
2746 goto skip_fsfstatus;
2747 }
2748
2749 /* evaluate FSF status in QTCB */
2750 switch (fsf_req->qtcb->header.fsf_status) {
2751
2752 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2754 "0x%016Lx on adapter %s invalid. This may happen "
2755 "occasionally.\n", port->handle,
2756 port->wwpn, zfcp_get_busid_by_port(port));
2757 ZFCP_LOG_DEBUG("status qualifier:\n");
2758 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2759 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2760 sizeof (union fsf_status_qual));
2761 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2762 "fsf_s_phand_nv");
2763 zfcp_erp_adapter_reopen(port->adapter, 0);
2764 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2765 break;
2766
2767 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 /* Note: FSF has actually closed the port in this case.
2769 * The status code is just daft. Fingers crossed for a change
2770 */
2771 retval = 0;
2772 break;
2773
2774 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2776 "port handle 0x%x\n", port->wwpn,
2777 zfcp_get_busid_by_port(port), port->handle);
Martin Peschke698ec0162008-03-27 14:22:02 +01002778 zfcp_erp_modify_port_status(port, 33, (u64)fsf_req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 ZFCP_STATUS_COMMON_OPEN,
2780 ZFCP_CLEAR);
2781 retval = 0;
2782 break;
2783
2784 default:
2785 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2786 "(debug info 0x%x)\n",
2787 fsf_req->qtcb->header.fsf_status);
2788 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2789 debug_exception(fsf_req->adapter->erp_dbf, 0,
2790 &fsf_req->qtcb->header.fsf_status,
2791 sizeof (u32));
2792 break;
2793 }
2794
2795 skip_fsfstatus:
2796 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2797 return retval;
2798}
2799
2800/*
2801 * function: zfcp_fsf_close_physical_port
2802 *
2803 * purpose: submit FSF command "close physical port"
2804 *
2805 * returns: address of initiated FSF request
2806 * NULL - request could not be initiated
2807 */
2808int
2809zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2810{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002812 struct zfcp_fsf_req *fsf_req;
2813 unsigned long lock_flags;
2814 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815
2816 /* setup new FSF request */
2817 retval = zfcp_fsf_req_create(erp_action->adapter,
2818 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2819 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2820 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002821 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 if (retval < 0) {
2823 ZFCP_LOG_INFO("error: Could not create close physical port "
2824 "request (adapter %s, port 0x%016Lx)\n",
2825 zfcp_get_busid_by_adapter(erp_action->adapter),
2826 erp_action->port->wwpn);
2827
2828 goto out;
2829 }
2830
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002831 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2833 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2834
2835 /* mark port as being closed */
2836 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2837 &erp_action->port->status);
2838 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002839 fsf_req->data = (unsigned long) erp_action->port;
2840 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2841 fsf_req->erp_action = erp_action;
2842 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002844 zfcp_erp_start_timer(fsf_req);
2845 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 if (retval) {
2847 ZFCP_LOG_INFO("error: Could not send close physical port "
2848 "request (adapter %s, port 0x%016Lx)\n",
2849 zfcp_get_busid_by_adapter(erp_action->adapter),
2850 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002851 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 erp_action->fsf_req = NULL;
2853 goto out;
2854 }
2855
2856 ZFCP_LOG_TRACE("close physical port request initiated "
2857 "(adapter %s, port 0x%016Lx)\n",
2858 zfcp_get_busid_by_adapter(erp_action->adapter),
2859 erp_action->port->wwpn);
2860 out:
2861 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2862 lock_flags);
2863 return retval;
2864}
2865
2866/*
2867 * function: zfcp_fsf_close_physical_port_handler
2868 *
2869 * purpose: is called for finished Close Physical Port FSF command
2870 *
2871 * returns:
2872 */
2873static int
2874zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2875{
2876 int retval = -EINVAL;
2877 struct zfcp_port *port;
2878 struct zfcp_unit *unit;
2879 struct fsf_qtcb_header *header;
2880 u16 subtable, rule, counter;
2881
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002882 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 header = &fsf_req->qtcb->header;
2884
2885 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2886 /* don't change port status in our bookkeeping */
2887 goto skip_fsfstatus;
2888 }
2889
2890 /* evaluate FSF status in QTCB */
2891 switch (header->fsf_status) {
2892
2893 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2895 "(adapter %s, port 0x%016Lx). "
2896 "This may happen occasionally.\n",
2897 port->handle,
2898 zfcp_get_busid_by_port(port),
2899 port->wwpn);
2900 ZFCP_LOG_DEBUG("status qualifier:\n");
2901 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2902 (char *) &header->fsf_status_qual,
2903 sizeof (union fsf_status_qual));
2904 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2905 "fsf_s_phand_nv");
2906 zfcp_erp_adapter_reopen(port->adapter, 0);
2907 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2908 break;
2909
2910 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 ZFCP_LOG_NORMAL("Access denied, cannot close "
2912 "physical port 0x%016Lx on adapter %s\n",
2913 port->wwpn, zfcp_get_busid_by_port(port));
2914 for (counter = 0; counter < 2; counter++) {
2915 subtable = header->fsf_status_qual.halfword[counter * 2];
2916 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2917 switch (subtable) {
2918 case FSF_SQ_CFDC_SUBTABLE_OS:
2919 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2920 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2921 case FSF_SQ_CFDC_SUBTABLE_LUN:
2922 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2923 zfcp_act_subtable_type[subtable], rule);
2924 break;
2925 }
2926 }
2927 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01002928 zfcp_erp_port_access_denied(port, 58, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2930 break;
2931
2932 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2934 "%s needs to be reopened but it was attempted "
2935 "to close it physically.\n",
2936 port->wwpn,
2937 zfcp_get_busid_by_port(port));
2938 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01002939 zfcp_erp_port_boxed(port, 50, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2941 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01002942
2943 /* can't use generic zfcp_erp_modify_port_status because
2944 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2945 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2946 list_for_each_entry(unit, &port->unit_list_head, list)
2947 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2948 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 break;
2950
2951 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 switch (header->fsf_status_qual.word[0]) {
2953 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2955 "fsf_sq_ltest");
2956 /* This will now be escalated by ERP */
2957 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2958 break;
2959 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 /* ERP strategy will escalate */
2961 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2962 "fsf_sq_ulp");
2963 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2964 break;
2965 default:
2966 ZFCP_LOG_NORMAL
2967 ("bug: Wrong status qualifier 0x%x arrived.\n",
2968 header->fsf_status_qual.word[0]);
2969 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2970 "fsf_sq_inval:");
2971 debug_exception(
2972 fsf_req->adapter->erp_dbf, 0,
2973 &header->fsf_status_qual.word[0], sizeof (u32));
2974 break;
2975 }
2976 break;
2977
2978 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2980 "physically closed, port handle 0x%x\n",
2981 port->wwpn,
2982 zfcp_get_busid_by_port(port), port->handle);
2983 /* can't use generic zfcp_erp_modify_port_status because
2984 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2985 */
2986 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2987 list_for_each_entry(unit, &port->unit_list_head, list)
2988 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2989 retval = 0;
2990 break;
2991
2992 default:
2993 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2994 "(debug info 0x%x)\n",
2995 header->fsf_status);
2996 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2997 debug_exception(fsf_req->adapter->erp_dbf, 0,
2998 &header->fsf_status, sizeof (u32));
2999 break;
3000 }
3001
3002 skip_fsfstatus:
3003 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
3004 return retval;
3005}
3006
3007/*
3008 * function: zfcp_fsf_open_unit
3009 *
3010 * purpose:
3011 *
3012 * returns:
3013 *
3014 * assumptions: This routine does not check whether the associated
3015 * remote port has already been opened. This should be
3016 * done by calling routines. Otherwise some status
3017 * may be presented by FSF
3018 */
3019int
3020zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3021{
3022 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003023 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 unsigned long lock_flags;
3025 int retval = 0;
3026
3027 /* setup new FSF request */
3028 retval = zfcp_fsf_req_create(erp_action->adapter,
3029 FSF_QTCB_OPEN_LUN,
3030 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3031 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003032 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 if (retval < 0) {
3034 ZFCP_LOG_INFO("error: Could not create open unit request for "
3035 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3036 erp_action->unit->fcp_lun,
3037 erp_action->unit->port->wwpn,
3038 zfcp_get_busid_by_adapter(erp_action->adapter));
3039 goto out;
3040 }
3041
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003042 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3044 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3045
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003046 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3047 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003048 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003049 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02003050 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003052 fsf_req->data = (unsigned long) erp_action->unit;
3053 fsf_req->erp_action = erp_action;
3054 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003056 zfcp_erp_start_timer(fsf_req);
3057 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 if (retval) {
3059 ZFCP_LOG_INFO("error: Could not send an open unit request "
3060 "on the adapter %s, port 0x%016Lx for "
3061 "unit 0x%016Lx\n",
3062 zfcp_get_busid_by_adapter(erp_action->adapter),
3063 erp_action->port->wwpn,
3064 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003065 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 erp_action->fsf_req = NULL;
3067 goto out;
3068 }
3069
3070 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3071 "port 0x%016Lx, unit 0x%016Lx)\n",
3072 zfcp_get_busid_by_adapter(erp_action->adapter),
3073 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3074 out:
3075 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3076 lock_flags);
3077 return retval;
3078}
3079
3080/*
3081 * function: zfcp_fsf_open_unit_handler
3082 *
3083 * purpose: is called for finished Open LUN command
3084 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003085 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 */
3087static int
3088zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3089{
3090 int retval = -EINVAL;
3091 struct zfcp_adapter *adapter;
3092 struct zfcp_unit *unit;
3093 struct fsf_qtcb_header *header;
3094 struct fsf_qtcb_bottom_support *bottom;
3095 struct fsf_queue_designator *queue_designator;
3096 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003097 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003099 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100
3101 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3102 /* don't change unit status in our bookkeeping */
3103 goto skip_fsfstatus;
3104 }
3105
3106 adapter = fsf_req->adapter;
3107 header = &fsf_req->qtcb->header;
3108 bottom = &fsf_req->qtcb->bottom.support;
3109 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3110
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02003112 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 ZFCP_STATUS_UNIT_SHARED |
3114 ZFCP_STATUS_UNIT_READONLY,
3115 &unit->status);
3116
3117 /* evaluate FSF status in QTCB */
3118 switch (header->fsf_status) {
3119
3120 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3122 "for port 0x%016Lx on adapter %s invalid "
3123 "This may happen occasionally\n",
3124 unit->port->handle,
3125 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3126 ZFCP_LOG_DEBUG("status qualifier:\n");
3127 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3128 (char *) &header->fsf_status_qual,
3129 sizeof (union fsf_status_qual));
3130 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3131 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3132 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3133 break;
3134
3135 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3137 "remote port 0x%016Lx on adapter %s twice.\n",
3138 unit->fcp_lun,
3139 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3140 debug_text_exception(adapter->erp_dbf, 0,
3141 "fsf_s_uopen");
3142 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3143 break;
3144
3145 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3147 "remote port 0x%016Lx on adapter %s\n",
3148 unit->fcp_lun, unit->port->wwpn,
3149 zfcp_get_busid_by_unit(unit));
3150 for (counter = 0; counter < 2; counter++) {
3151 subtable = header->fsf_status_qual.halfword[counter * 2];
3152 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3153 switch (subtable) {
3154 case FSF_SQ_CFDC_SUBTABLE_OS:
3155 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3156 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3157 case FSF_SQ_CFDC_SUBTABLE_LUN:
3158 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3159 zfcp_act_subtable_type[subtable], rule);
3160 break;
3161 }
3162 }
3163 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01003164 zfcp_erp_unit_access_denied(unit, 59, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3166 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3167 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3168 break;
3169
3170 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3172 "needs to be reopened\n",
3173 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3174 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003175 zfcp_erp_port_boxed(unit->port, 51, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3177 ZFCP_STATUS_FSFREQ_RETRY;
3178 break;
3179
3180 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 if (header->fsf_status_qual.word[0] != 0) {
3182 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3183 "with WWPN 0x%Lx "
3184 "connected to the adapter %s "
3185 "is already in use in LPAR%d, CSS%d\n",
3186 unit->fcp_lun,
3187 unit->port->wwpn,
3188 zfcp_get_busid_by_unit(unit),
3189 queue_designator->hla,
3190 queue_designator->cssid);
3191 } else {
3192 subtable = header->fsf_status_qual.halfword[4];
3193 rule = header->fsf_status_qual.halfword[5];
3194 switch (subtable) {
3195 case FSF_SQ_CFDC_SUBTABLE_OS:
3196 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3197 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3198 case FSF_SQ_CFDC_SUBTABLE_LUN:
3199 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3200 "remote port with WWPN 0x%Lx "
3201 "connected to the adapter %s "
3202 "is denied (%s rule %d)\n",
3203 unit->fcp_lun,
3204 unit->port->wwpn,
3205 zfcp_get_busid_by_unit(unit),
3206 zfcp_act_subtable_type[subtable],
3207 rule);
3208 break;
3209 }
3210 }
3211 ZFCP_LOG_DEBUG("status qualifier:\n");
3212 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3213 (char *) &header->fsf_status_qual,
3214 sizeof (union fsf_status_qual));
3215 debug_text_event(adapter->erp_dbf, 2,
3216 "fsf_s_l_sh_vio");
Martin Peschke698ec0162008-03-27 14:22:02 +01003217 zfcp_erp_unit_access_denied(unit, 60, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3219 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3220 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3221 break;
3222
3223 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3225 "There is no handle (temporary port identifier) "
3226 "available for unit 0x%016Lx on port 0x%016Lx "
3227 "on adapter %s\n",
3228 unit->fcp_lun,
3229 unit->port->wwpn,
3230 zfcp_get_busid_by_unit(unit));
3231 debug_text_event(adapter->erp_dbf, 1,
3232 "fsf_s_max_units");
Martin Peschke698ec0162008-03-27 14:22:02 +01003233 zfcp_erp_unit_failed(unit, 34, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3235 break;
3236
3237 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 switch (header->fsf_status_qual.word[0]) {
3239 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 /* Re-establish link to port */
3241 debug_text_event(adapter->erp_dbf, 1,
3242 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003243 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3245 break;
3246 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 /* ERP strategy will escalate */
3248 debug_text_event(adapter->erp_dbf, 1,
3249 "fsf_sq_ulp");
3250 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3251 break;
3252 default:
3253 ZFCP_LOG_NORMAL
3254 ("bug: Wrong status qualifier 0x%x arrived.\n",
3255 header->fsf_status_qual.word[0]);
3256 debug_text_event(adapter->erp_dbf, 0,
3257 "fsf_sq_inval:");
3258 debug_exception(adapter->erp_dbf, 0,
3259 &header->fsf_status_qual.word[0],
3260 sizeof (u32));
3261 }
3262 break;
3263
3264 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 ZFCP_LOG_NORMAL(
3266 "Invalid option 0x%x has been specified "
3267 "in QTCB bottom sent to the adapter %s\n",
3268 bottom->option,
3269 zfcp_get_busid_by_adapter(adapter));
3270 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3271 retval = -EINVAL;
3272 break;
3273
3274 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 /* save LUN handle assigned by FSF */
3276 unit->handle = header->lun_handle;
3277 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3278 "adapter %s opened, port handle 0x%x\n",
3279 unit->fcp_lun,
3280 unit->port->wwpn,
3281 zfcp_get_busid_by_unit(unit),
3282 unit->handle);
3283 /* mark unit as open */
3284 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003285
3286 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3287 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3288 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3289 exclusive = (bottom->lun_access_info &
3290 FSF_UNIT_ACCESS_EXCLUSIVE);
3291 readwrite = (bottom->lun_access_info &
3292 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3293
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 if (!exclusive)
3295 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3296 &unit->status);
3297
3298 if (!readwrite) {
3299 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3300 &unit->status);
3301 ZFCP_LOG_NORMAL("read-only access for unit "
3302 "(adapter %s, wwpn=0x%016Lx, "
3303 "fcp_lun=0x%016Lx)\n",
3304 zfcp_get_busid_by_unit(unit),
3305 unit->port->wwpn,
3306 unit->fcp_lun);
3307 }
3308
3309 if (exclusive && !readwrite) {
3310 ZFCP_LOG_NORMAL("exclusive access of read-only "
3311 "unit not supported\n");
Martin Peschke698ec0162008-03-27 14:22:02 +01003312 zfcp_erp_unit_failed(unit, 35, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3314 zfcp_erp_unit_shutdown(unit, 0);
3315 } else if (!exclusive && readwrite) {
3316 ZFCP_LOG_NORMAL("shared access of read-write "
3317 "unit not supported\n");
Martin Peschke698ec0162008-03-27 14:22:02 +01003318 zfcp_erp_unit_failed(unit, 36, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3320 zfcp_erp_unit_shutdown(unit, 0);
3321 }
3322 }
3323
3324 retval = 0;
3325 break;
3326
3327 default:
3328 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3329 "(debug info 0x%x)\n",
3330 header->fsf_status);
3331 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3332 debug_exception(adapter->erp_dbf, 0,
3333 &header->fsf_status, sizeof (u32));
3334 break;
3335 }
3336
3337 skip_fsfstatus:
3338 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3339 return retval;
3340}
3341
3342/*
3343 * function: zfcp_fsf_close_unit
3344 *
3345 * purpose:
3346 *
3347 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003348 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 *
3350 * assumptions: This routine does not check whether the associated
3351 * remote port/lun has already been opened. This should be
3352 * done by calling routines. Otherwise some status
3353 * may be presented by FSF
3354 */
3355int
3356zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3357{
3358 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003359 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 unsigned long lock_flags;
3361 int retval = 0;
3362
3363 /* setup new FSF request */
3364 retval = zfcp_fsf_req_create(erp_action->adapter,
3365 FSF_QTCB_CLOSE_LUN,
3366 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3367 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003368 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 if (retval < 0) {
3370 ZFCP_LOG_INFO("error: Could not create close unit request for "
3371 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3372 erp_action->unit->fcp_lun,
3373 erp_action->port->wwpn,
3374 zfcp_get_busid_by_adapter(erp_action->adapter));
3375 goto out;
3376 }
3377
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003378 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3380 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3381
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003382 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3383 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003385 fsf_req->data = (unsigned long) erp_action->unit;
3386 fsf_req->erp_action = erp_action;
3387 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003389 zfcp_erp_start_timer(fsf_req);
3390 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 if (retval) {
3392 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3393 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3394 erp_action->unit->fcp_lun,
3395 erp_action->port->wwpn,
3396 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003397 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 erp_action->fsf_req = NULL;
3399 goto out;
3400 }
3401
3402 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3403 "port 0x%016Lx, unit 0x%016Lx)\n",
3404 zfcp_get_busid_by_adapter(erp_action->adapter),
3405 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3406 out:
3407 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3408 lock_flags);
3409 return retval;
3410}
3411
3412/*
3413 * function: zfcp_fsf_close_unit_handler
3414 *
3415 * purpose: is called for finished Close LUN FSF command
3416 *
3417 * returns:
3418 */
3419static int
3420zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3421{
3422 int retval = -EINVAL;
3423 struct zfcp_unit *unit;
3424
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003425 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
3427 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3428 /* don't change unit status in our bookkeeping */
3429 goto skip_fsfstatus;
3430 }
3431
3432 /* evaluate FSF status in QTCB */
3433 switch (fsf_req->qtcb->header.fsf_status) {
3434
3435 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3437 "0x%016Lx on adapter %s invalid. This may "
3438 "happen in rare circumstances\n",
3439 unit->port->handle,
3440 unit->port->wwpn,
3441 zfcp_get_busid_by_unit(unit));
3442 ZFCP_LOG_DEBUG("status qualifier:\n");
3443 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3444 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3445 sizeof (union fsf_status_qual));
3446 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3447 "fsf_s_phand_nv");
3448 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3450 break;
3451
3452 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3454 "0x%016Lx on port 0x%016Lx on adapter %s is "
3455 "invalid. This may happen occasionally.\n",
3456 unit->handle,
3457 unit->fcp_lun,
3458 unit->port->wwpn,
3459 zfcp_get_busid_by_unit(unit));
3460 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3461 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3462 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3463 sizeof (union fsf_status_qual));
3464 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3465 "fsf_s_lhand_nv");
3466 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3468 break;
3469
3470 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3472 "needs to be reopened\n",
3473 unit->port->wwpn,
3474 zfcp_get_busid_by_unit(unit));
3475 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003476 zfcp_erp_port_boxed(unit->port, 52, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3478 ZFCP_STATUS_FSFREQ_RETRY;
3479 break;
3480
3481 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3483 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 /* re-establish link to port */
3485 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3486 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003487 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3489 break;
3490 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 /* ERP strategy will escalate */
3492 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3493 "fsf_sq_ulp");
3494 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3495 break;
3496 default:
3497 ZFCP_LOG_NORMAL
3498 ("bug: Wrong status qualifier 0x%x arrived.\n",
3499 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3500 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3501 "fsf_sq_inval:");
3502 debug_exception(
3503 fsf_req->adapter->erp_dbf, 0,
3504 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3505 sizeof (u32));
3506 break;
3507 }
3508 break;
3509
3510 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3512 "closed, port handle 0x%x\n",
3513 unit->fcp_lun,
3514 unit->port->wwpn,
3515 zfcp_get_busid_by_unit(unit),
3516 unit->handle);
3517 /* mark unit as closed */
3518 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3519 retval = 0;
3520 break;
3521
3522 default:
3523 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3524 "(debug info 0x%x)\n",
3525 fsf_req->qtcb->header.fsf_status);
3526 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3527 debug_exception(fsf_req->adapter->erp_dbf, 0,
3528 &fsf_req->qtcb->header.fsf_status,
3529 sizeof (u32));
3530 break;
3531 }
3532
3533 skip_fsfstatus:
3534 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3535 return retval;
3536}
3537
3538/**
3539 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3540 * @adapter: adapter where scsi command is issued
3541 * @unit: unit where command is sent to
3542 * @scsi_cmnd: scsi command to be sent
3543 * @timer: timer to be started when request is initiated
3544 * @req_flags: flags for fsf_request
3545 */
3546int
3547zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3548 struct zfcp_unit *unit,
3549 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003550 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551{
3552 struct zfcp_fsf_req *fsf_req = NULL;
3553 struct fcp_cmnd_iu *fcp_cmnd_iu;
3554 unsigned int sbtype;
3555 unsigned long lock_flags;
3556 int real_bytes = 0;
3557 int retval = 0;
3558 int mask;
3559
3560 /* setup new FSF request */
3561 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3562 adapter->pool.fsf_req_scsi,
3563 &lock_flags, &fsf_req);
3564 if (unlikely(retval < 0)) {
3565 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3566 "for unit 0x%016Lx on port 0x%016Lx on "
3567 "adapter %s\n",
3568 unit->fcp_lun,
3569 unit->port->wwpn,
3570 zfcp_get_busid_by_adapter(adapter));
3571 goto failed_req_create;
3572 }
3573
Christof Schmittba172422007-12-20 12:30:26 +01003574 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3575 &unit->status))) {
3576 retval = -EBUSY;
3577 goto unit_blocked;
3578 }
3579
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003580 zfcp_unit_get(unit);
3581 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003583 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003584 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003585
3586 /* associate SCSI command with FSF request */
3587 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588
3589 /* set handles of unit and its parent port in QTCB */
3590 fsf_req->qtcb->header.lun_handle = unit->handle;
3591 fsf_req->qtcb->header.port_handle = unit->port->handle;
3592
3593 /* FSF does not define the structure of the FCP_CMND IU */
3594 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3595 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3596
3597 /*
3598 * set depending on data direction:
3599 * data direction bits in SBALE (SB Type)
3600 * data direction bits in QTCB
3601 * data direction bits in FCP_CMND IU
3602 */
3603 switch (scsi_cmnd->sc_data_direction) {
3604 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3606 /*
3607 * FIXME(qdio):
3608 * what is the correct type for commands
3609 * without 'real' data buffers?
3610 */
3611 sbtype = SBAL_FLAGS0_TYPE_READ;
3612 break;
3613 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3615 sbtype = SBAL_FLAGS0_TYPE_READ;
3616 fcp_cmnd_iu->rddata = 1;
3617 break;
3618 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3620 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3621 fcp_cmnd_iu->wddata = 1;
3622 break;
3623 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 default:
3625 /*
3626 * dummy, catch this condition earlier
3627 * in zfcp_scsi_queuecommand
3628 */
3629 goto failed_scsi_cmnd;
3630 }
3631
3632 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003633 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
3635 /* set FCP_LUN in FCP_CMND IU in QTCB */
3636 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3637
3638 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3639
3640 /* set task attributes in FCP_CMND IU in QTCB */
3641 if (likely((scsi_cmnd->device->simple_tags) ||
3642 (atomic_test_mask(mask, &unit->status))))
3643 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3644 else
3645 fcp_cmnd_iu->task_attribute = UNTAGGED;
3646
3647 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3648 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3649 fcp_cmnd_iu->add_fcp_cdb_length
3650 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3651 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3652 "additional FCP_CDB length is 0x%x "
3653 "(shifted right 2 bits)\n",
3654 scsi_cmnd->cmd_len,
3655 fcp_cmnd_iu->add_fcp_cdb_length);
3656 }
3657 /*
3658 * copy SCSI CDB (including additional length, if any) to
3659 * FCP_CDB in FCP_CMND IU in QTCB
3660 */
3661 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3662
3663 /* FCP CMND IU length in QTCB */
3664 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3665 sizeof (struct fcp_cmnd_iu) +
3666 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3667
3668 /* generate SBALEs from data buffer */
3669 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3670 if (unlikely(real_bytes < 0)) {
3671 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3672 ZFCP_LOG_DEBUG(
3673 "Data did not fit into available buffer(s), "
3674 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003675 retval = -EIO;
3676 } else {
3677 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3678 "required. Shutting down unit "
3679 "(adapter %s, port 0x%016Lx, "
3680 "unit 0x%016Lx)\n",
3681 zfcp_get_busid_by_unit(unit),
3682 unit->port->wwpn,
3683 unit->fcp_lun);
3684 zfcp_erp_unit_shutdown(unit, 0);
3685 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 }
3687 goto no_fit;
3688 }
3689
3690 /* set length of FCP data length in FCP_CMND IU in QTCB */
3691 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3692
3693 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3694 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3695 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3696
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003697 if (use_timer)
3698 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3699
3700 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 if (unlikely(retval < 0)) {
3702 ZFCP_LOG_INFO("error: Could not send FCP command request "
3703 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3704 zfcp_get_busid_by_adapter(adapter),
3705 unit->port->wwpn,
3706 unit->fcp_lun);
3707 goto send_failed;
3708 }
3709
3710 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3711 "port 0x%016Lx, unit 0x%016Lx)\n",
3712 zfcp_get_busid_by_adapter(adapter),
3713 unit->port->wwpn,
3714 unit->fcp_lun);
3715 goto success;
3716
3717 send_failed:
3718 no_fit:
3719 failed_scsi_cmnd:
Christof Schmittba172422007-12-20 12:30:26 +01003720 unit_blocked:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003721 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 zfcp_fsf_req_free(fsf_req);
3723 fsf_req = NULL;
3724 scsi_cmnd->host_scribble = NULL;
3725 success:
3726 failed_req_create:
3727 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3728 return retval;
3729}
3730
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731struct zfcp_fsf_req *
3732zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3733 struct zfcp_unit *unit,
3734 u8 tm_flags, int req_flags)
3735{
3736 struct zfcp_fsf_req *fsf_req = NULL;
3737 int retval = 0;
3738 struct fcp_cmnd_iu *fcp_cmnd_iu;
3739 unsigned long lock_flags;
3740 volatile struct qdio_buffer_element *sbale;
3741
3742 /* setup new FSF request */
3743 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3744 adapter->pool.fsf_req_scsi,
3745 &lock_flags, &fsf_req);
3746 if (retval < 0) {
3747 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3748 "management) request for adapter %s, port "
3749 " 0x%016Lx, unit 0x%016Lx.\n",
3750 zfcp_get_busid_by_adapter(adapter),
3751 unit->port->wwpn, unit->fcp_lun);
3752 goto out;
3753 }
3754
Christof Schmittfdf23452007-12-20 12:30:27 +01003755 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3756 &unit->status)))
3757 goto unit_blocked;
3758
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 /*
3760 * Used to decide on proper handler in the return path,
3761 * could be either zfcp_fsf_send_fcp_command_task_handler or
3762 * zfcp_fsf_send_fcp_command_task_management_handler */
3763
3764 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3765
3766 /*
3767 * hold a pointer to the unit being target of this
3768 * task management request
3769 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003770 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
3772 /* set FSF related fields in QTCB */
3773 fsf_req->qtcb->header.lun_handle = unit->handle;
3774 fsf_req->qtcb->header.port_handle = unit->port->handle;
3775 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003776 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3778 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3779
3780 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3781 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3782 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3783
3784 /* set FCP related fields in FCP_CMND IU in QTCB */
3785 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3786 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3787 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3788 fcp_cmnd_iu->task_management_flags = tm_flags;
3789
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003790 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3791 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmittfdf23452007-12-20 12:30:27 +01003792 if (!retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794
Christof Schmittfdf23452007-12-20 12:30:27 +01003795 unit_blocked:
3796 zfcp_fsf_req_free(fsf_req);
3797 fsf_req = NULL;
3798
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 out:
3800 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3801 return fsf_req;
3802}
3803
3804/*
3805 * function: zfcp_fsf_send_fcp_command_handler
3806 *
3807 * purpose: is called for finished Send FCP Command
3808 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003809 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 */
3811static int
3812zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3813{
3814 int retval = -EINVAL;
3815 struct zfcp_unit *unit;
3816 struct fsf_qtcb_header *header;
3817 u16 subtable, rule, counter;
3818
3819 header = &fsf_req->qtcb->header;
3820
3821 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003822 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003824 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
3826 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3827 /* go directly to calls of special handlers */
3828 goto skip_fsfstatus;
3829 }
3830
3831 /* evaluate FSF status in QTCB */
3832 switch (header->fsf_status) {
3833
3834 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3836 "0x%016Lx on adapter %s invalid\n",
3837 unit->port->handle,
3838 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3839 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3840 (char *) &header->fsf_status_qual,
3841 sizeof (union fsf_status_qual));
3842 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3843 "fsf_s_phand_nv");
3844 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3845 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3846 break;
3847
3848 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3850 "0x%016Lx on port 0x%016Lx on adapter %s is "
3851 "invalid. This may happen occasionally.\n",
3852 unit->handle,
3853 unit->fcp_lun,
3854 unit->port->wwpn,
3855 zfcp_get_busid_by_unit(unit));
3856 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3857 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3858 (char *) &header->fsf_status_qual,
3859 sizeof (union fsf_status_qual));
3860 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3861 "fsf_s_uhand_nv");
3862 zfcp_erp_port_reopen(unit->port, 0);
3863 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3864 break;
3865
3866 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3868 "unexpectedly. (adapter %s, port 0x%016Lx, "
3869 "unit 0x%016Lx)\n",
3870 unit->port->handle,
3871 zfcp_get_busid_by_unit(unit),
3872 unit->port->wwpn,
3873 unit->fcp_lun);
3874 ZFCP_LOG_NORMAL("status qualifier:\n");
3875 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3876 (char *) &header->fsf_status_qual,
3877 sizeof (union fsf_status_qual));
3878 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3879 "fsf_s_hand_mis");
3880 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3882 break;
3883
3884 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003885 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3886 "class %d.\n",
3887 zfcp_get_busid_by_unit(unit),
3888 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 /* stop operation for this adapter */
3890 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3891 "fsf_s_class_nsup");
3892 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3894 break;
3895
3896 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3898 "adapter %s does not have correct unit "
3899 "handle 0x%x\n",
3900 unit->fcp_lun,
3901 unit->port->wwpn,
3902 zfcp_get_busid_by_unit(unit),
3903 unit->handle);
3904 ZFCP_LOG_DEBUG("status qualifier:\n");
3905 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3906 (char *) &header->fsf_status_qual,
3907 sizeof (union fsf_status_qual));
3908 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3909 "fsf_s_fcp_lun_nv");
3910 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3912 break;
3913
3914 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3916 "unit 0x%016Lx on port 0x%016Lx on "
3917 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3918 zfcp_get_busid_by_unit(unit));
3919 for (counter = 0; counter < 2; counter++) {
3920 subtable = header->fsf_status_qual.halfword[counter * 2];
3921 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3922 switch (subtable) {
3923 case FSF_SQ_CFDC_SUBTABLE_OS:
3924 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3925 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3926 case FSF_SQ_CFDC_SUBTABLE_LUN:
3927 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3928 zfcp_act_subtable_type[subtable], rule);
3929 break;
3930 }
3931 }
3932 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01003933 zfcp_erp_unit_access_denied(unit, 61, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3935 break;
3936
3937 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3939 "0x%016Lx on port 0x%016Lx on adapter %s "
3940 "(debug info %d)\n",
3941 unit->fcp_lun,
3942 unit->port->wwpn,
3943 zfcp_get_busid_by_unit(unit),
3944 fsf_req->qtcb->bottom.io.data_direction);
3945 /* stop operation for this adapter */
3946 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3947 "fsf_s_dir_ind_nv");
3948 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3950 break;
3951
3952 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 ZFCP_LOG_NORMAL
3954 ("bug: An invalid control-data-block length field "
3955 "was found in a command for unit 0x%016Lx on port "
3956 "0x%016Lx on adapter %s " "(debug info %d)\n",
3957 unit->fcp_lun, unit->port->wwpn,
3958 zfcp_get_busid_by_unit(unit),
3959 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3960 /* stop operation for this adapter */
3961 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3962 "fsf_s_cmd_len_nv");
3963 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3965 break;
3966
3967 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3969 "needs to be reopened\n",
3970 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3971 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003972 zfcp_erp_port_boxed(unit->port, 53, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3974 ZFCP_STATUS_FSFREQ_RETRY;
3975 break;
3976
3977 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3979 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3980 zfcp_get_busid_by_unit(unit),
3981 unit->port->wwpn, unit->fcp_lun);
3982 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003983 zfcp_erp_unit_boxed(unit, 54, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3985 | ZFCP_STATUS_FSFREQ_RETRY;
3986 break;
3987
3988 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 switch (header->fsf_status_qual.word[0]) {
3990 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 /* re-establish link to port */
3992 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3993 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003994 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 break;
3996 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 /* FIXME(hw) need proper specs for proper action */
3998 /* let scsi stack deal with retries and escalation */
3999 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4000 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 break;
4002 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02004004 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 header->fsf_status_qual.word[0]);
4006 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4007 "fsf_sq_inval:");
4008 debug_exception(fsf_req->adapter->erp_dbf, 0,
4009 &header->fsf_status_qual.word[0],
4010 sizeof(u32));
4011 break;
4012 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02004013 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 break;
4015
4016 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 break;
4018
4019 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 break;
4021
4022 default:
4023 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4024 debug_exception(fsf_req->adapter->erp_dbf, 0,
4025 &header->fsf_status, sizeof(u32));
4026 break;
4027 }
4028
4029 skip_fsfstatus:
4030 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4031 retval =
4032 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4033 } else {
4034 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004035 fsf_req->unit = NULL;
4036 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 }
4038 return retval;
4039}
4040
4041/*
4042 * function: zfcp_fsf_send_fcp_command_task_handler
4043 *
4044 * purpose: evaluates FCP_RSP IU
4045 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004046 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 */
4048static int
4049zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4050{
4051 int retval = 0;
4052 struct scsi_cmnd *scpnt;
4053 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4054 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4055 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4056 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4057 u32 sns_len;
4058 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4059 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004060 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061
4062 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004063 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 if (unlikely(!scpnt)) {
4065 ZFCP_LOG_DEBUG
4066 ("Command with fsf_req %p is not associated to "
4067 "a scsi command anymore. Aborted?\n", fsf_req);
4068 goto out;
4069 }
4070 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4071 /* FIXME: (design) mid-layer should handle DID_ABORT like
4072 * DID_SOFT_ERROR by retrying the request for devices
4073 * that allow retries.
4074 */
4075 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4076 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4077 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4078 goto skip_fsfstatus;
4079 }
4080
4081 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4082 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4083 set_host_byte(&scpnt->result, DID_ERROR);
4084 goto skip_fsfstatus;
4085 }
4086
4087 /* set message byte of result in SCSI command */
4088 scpnt->result |= COMMAND_COMPLETE << 8;
4089
4090 /*
4091 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4092 * of result in SCSI command
4093 */
4094 scpnt->result |= fcp_rsp_iu->scsi_status;
4095 if (unlikely(fcp_rsp_iu->scsi_status)) {
4096 /* DEBUG */
4097 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4098 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4099 scpnt->cmnd, scpnt->cmd_len);
4100 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4101 fcp_rsp_iu->scsi_status);
4102 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4103 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4104 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4105 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4106 fcp_rsp_iu->fcp_sns_len);
4107 }
4108
4109 /* check FCP_RSP_INFO */
4110 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4111 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4112 switch (fcp_rsp_info[3]) {
4113 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 /* ok, continue */
4115 ZFCP_LOG_TRACE("no failure or Task Management "
4116 "Function complete\n");
4117 set_host_byte(&scpnt->result, DID_OK);
4118 break;
4119 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 /* hardware bug */
4121 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4122 "that the fibrechannel protocol data "
4123 "length differs from the burst length. "
4124 "The problem occured on unit 0x%016Lx "
4125 "on port 0x%016Lx on adapter %s",
4126 unit->fcp_lun,
4127 unit->port->wwpn,
4128 zfcp_get_busid_by_unit(unit));
4129 /* dump SCSI CDB as prepared by zfcp */
4130 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4131 (char *) &fsf_req->qtcb->
4132 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 set_host_byte(&scpnt->result, DID_ERROR);
4134 goto skip_fsfstatus;
4135 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 /* driver or hardware bug */
4137 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4138 "that the fibrechannel protocol data "
4139 "fields were incorrectly set up. "
4140 "The problem occured on the unit "
4141 "0x%016Lx on port 0x%016Lx on "
4142 "adapter %s",
4143 unit->fcp_lun,
4144 unit->port->wwpn,
4145 zfcp_get_busid_by_unit(unit));
4146 /* dump SCSI CDB as prepared by zfcp */
4147 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4148 (char *) &fsf_req->qtcb->
4149 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4150 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 goto skip_fsfstatus;
4152 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 /* hardware bug */
4154 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4155 "that conflicting values for the "
4156 "fibrechannel payload offset from the "
4157 "header were found. "
4158 "The problem occured on unit 0x%016Lx "
4159 "on port 0x%016Lx on adapter %s.\n",
4160 unit->fcp_lun,
4161 unit->port->wwpn,
4162 zfcp_get_busid_by_unit(unit));
4163 /* dump SCSI CDB as prepared by zfcp */
4164 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4165 (char *) &fsf_req->qtcb->
4166 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 set_host_byte(&scpnt->result, DID_ERROR);
4168 goto skip_fsfstatus;
4169 default:
4170 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4171 "code was detected for a command. "
4172 "The problem occured on the unit "
4173 "0x%016Lx on port 0x%016Lx on "
4174 "adapter %s (debug info 0x%x)\n",
4175 unit->fcp_lun,
4176 unit->port->wwpn,
4177 zfcp_get_busid_by_unit(unit),
4178 fcp_rsp_info[3]);
4179 /* dump SCSI CDB as prepared by zfcp */
4180 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4181 (char *) &fsf_req->qtcb->
4182 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004184 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 }
4186 }
4187
4188 /* check for sense data */
4189 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4190 sns_len = FSF_FCP_RSP_SIZE -
4191 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4192 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4193 sns_len);
4194 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4195 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4196 SCSI_SENSE_BUFFERSIZE);
4197 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4198 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4199 scpnt->result);
4200 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4201 (void *) &scpnt->cmnd, scpnt->cmd_len);
4202
4203 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4204 fcp_rsp_iu->fcp_sns_len);
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004205 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4207 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004208 (void *)scpnt->sense_buffer, sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 }
4210
4211 /* check for overrun */
4212 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4213 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4214 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4215 "The response data length is "
4216 "%d, the original length was %d.\n",
4217 unit->fcp_lun,
4218 unit->port->wwpn,
4219 zfcp_get_busid_by_unit(unit),
4220 fcp_rsp_iu->fcp_resid,
4221 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4222 }
4223
4224 /* check for underrun */
4225 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4226 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4227 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4228 "The response data length is "
4229 "%d, the original length was %d.\n",
4230 unit->fcp_lun,
4231 unit->port->wwpn,
4232 zfcp_get_busid_by_unit(unit),
4233 fcp_rsp_iu->fcp_resid,
4234 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4235
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004236 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4237 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4238 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004239 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 }
4241
4242 skip_fsfstatus:
4243 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4244
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004245 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004246 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004247 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004248 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004249 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004250 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251
4252 /* cleanup pointer (need this especially for abort) */
4253 scpnt->host_scribble = NULL;
4254
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 (scpnt->scsi_done) (scpnt);
4257
4258 /*
4259 * We must hold this lock until scsi_done has been called.
4260 * Otherwise we may call scsi_done after abort regarding this
4261 * command has completed.
4262 * Note: scsi_done must not block!
4263 */
4264 out:
4265 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4266 return retval;
4267}
4268
4269/*
4270 * function: zfcp_fsf_send_fcp_command_task_management_handler
4271 *
4272 * purpose: evaluates FCP_RSP IU
4273 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004274 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 */
4276static int
4277zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4278{
4279 int retval = 0;
4280 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4281 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4282 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004283 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4286 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4287 goto skip_fsfstatus;
4288 }
4289
4290 /* check FCP_RSP_INFO */
4291 switch (fcp_rsp_info[3]) {
4292 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 /* ok, continue */
4294 ZFCP_LOG_DEBUG("no failure or Task Management "
4295 "Function complete\n");
4296 break;
4297 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4299 "is not supported on the target device "
4300 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4301 unit->fcp_lun,
4302 unit->port->wwpn,
4303 zfcp_get_busid_by_unit(unit));
4304 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4305 break;
4306 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4308 "failed to complete successfully. "
4309 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4310 unit->fcp_lun,
4311 unit->port->wwpn,
4312 zfcp_get_busid_by_unit(unit));
4313 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4314 break;
4315 default:
4316 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4317 "code was detected for a command. "
4318 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4319 "(debug info 0x%x)\n",
4320 unit->fcp_lun,
4321 unit->port->wwpn,
4322 zfcp_get_busid_by_unit(unit),
4323 fcp_rsp_info[3]);
4324 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4325 }
4326
4327 skip_fsfstatus:
4328 return retval;
4329}
4330
4331
4332/*
4333 * function: zfcp_fsf_control_file
4334 *
4335 * purpose: Initiator of the control file upload/download FSF requests
4336 *
4337 * returns: 0 - FSF request is successfuly created and queued
4338 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4339 * -EINVAL - Invalid direction specified
4340 * -ENOMEM - Insufficient memory
4341 * -EPERM - Cannot create FSF request or place it in QDIO queue
4342 */
4343int
4344zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4345 struct zfcp_fsf_req **fsf_req_ptr,
4346 u32 fsf_command,
4347 u32 option,
4348 struct zfcp_sg_list *sg_list)
4349{
4350 struct zfcp_fsf_req *fsf_req;
4351 struct fsf_qtcb_bottom_support *bottom;
4352 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 unsigned long lock_flags;
4354 int req_flags = 0;
4355 int direction;
4356 int retval = 0;
4357
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004358 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4360 zfcp_get_busid_by_adapter(adapter));
4361 retval = -EOPNOTSUPP;
4362 goto out;
4363 }
4364
4365 switch (fsf_command) {
4366
4367 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4368 direction = SBAL_FLAGS0_TYPE_WRITE;
4369 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4370 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4371 req_flags = ZFCP_WAIT_FOR_SBAL;
4372 break;
4373
4374 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4375 direction = SBAL_FLAGS0_TYPE_READ;
4376 break;
4377
4378 default:
4379 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4380 retval = -EINVAL;
4381 goto out;
4382 }
4383
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4385 NULL, &lock_flags, &fsf_req);
4386 if (retval < 0) {
4387 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4388 "adapter %s\n",
4389 zfcp_get_busid_by_adapter(adapter));
4390 retval = -EPERM;
4391 goto unlock_queue_lock;
4392 }
4393
4394 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4395 sbale[0].flags |= direction;
4396
4397 bottom = &fsf_req->qtcb->bottom.support;
4398 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4399 bottom->option = option;
4400
4401 if (sg_list->count > 0) {
4402 int bytes;
4403
4404 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4405 sg_list->sg, sg_list->count,
4406 ZFCP_MAX_SBALS_PER_REQ);
4407 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4408 ZFCP_LOG_INFO(
4409 "error: Could not create sufficient number of "
4410 "SBALS for an FSF request to the adapter %s\n",
4411 zfcp_get_busid_by_adapter(adapter));
4412 retval = -ENOMEM;
4413 goto free_fsf_req;
4414 }
4415 } else
4416 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4417
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004418 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4419 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 if (retval < 0) {
4421 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4422 "(adapter %s)\n",
4423 zfcp_get_busid_by_adapter(adapter));
4424 retval = -EPERM;
4425 goto free_fsf_req;
4426 }
4427 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4428
4429 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4430 "adapter %s\n",
4431 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4432 "download" : "upload",
4433 zfcp_get_busid_by_adapter(adapter));
4434
4435 wait_event(fsf_req->completion_wq,
4436 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4437
4438 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004439 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
4441 free_fsf_req:
4442 zfcp_fsf_req_free(fsf_req);
4443 unlock_queue_lock:
4444 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 out:
4446 return retval;
4447}
4448
4449
4450/*
4451 * function: zfcp_fsf_control_file_handler
4452 *
4453 * purpose: Handler of the control file upload/download FSF requests
4454 *
4455 * returns: 0 - FSF request successfuly processed
4456 * -EAGAIN - Operation has to be repeated because of a temporary problem
4457 * -EACCES - There is no permission to execute an operation
4458 * -EPERM - The control file is not in a right format
4459 * -EIO - There is a problem with the FCP adapter
4460 * -EINVAL - Invalid operation
4461 * -EFAULT - User space memory I/O operation fault
4462 */
4463static int
4464zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4465{
4466 struct zfcp_adapter *adapter = fsf_req->adapter;
4467 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4468 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4469 int retval = 0;
4470
4471 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4472 retval = -EINVAL;
4473 goto skip_fsfstatus;
4474 }
4475
4476 switch (header->fsf_status) {
4477
4478 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 ZFCP_LOG_NORMAL(
4480 "The FSF request has been successfully completed "
4481 "on the adapter %s\n",
4482 zfcp_get_busid_by_adapter(adapter));
4483 break;
4484
4485 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4487 switch (header->fsf_status_qual.word[0]) {
4488
6f71d9b2005-04-10 23:04:28 -05004489 case FSF_SQ_CFDC_HARDENED_ON_SE:
4490 ZFCP_LOG_NORMAL(
4491 "CFDC on the adapter %s has being "
4492 "hardened on primary and secondary SE\n",
4493 zfcp_get_busid_by_adapter(adapter));
4494 break;
4495
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4497 ZFCP_LOG_NORMAL(
4498 "CFDC of the adapter %s could not "
4499 "be saved on the SE\n",
4500 zfcp_get_busid_by_adapter(adapter));
4501 break;
4502
4503 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4504 ZFCP_LOG_NORMAL(
4505 "CFDC of the adapter %s could not "
4506 "be copied to the secondary SE\n",
4507 zfcp_get_busid_by_adapter(adapter));
4508 break;
4509
4510 default:
4511 ZFCP_LOG_NORMAL(
4512 "CFDC could not be hardened "
4513 "on the adapter %s\n",
4514 zfcp_get_busid_by_adapter(adapter));
4515 }
4516 }
4517 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4518 retval = -EAGAIN;
4519 break;
4520
4521 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 ZFCP_LOG_NORMAL(
4523 "Adapter %s does not accept privileged commands\n",
4524 zfcp_get_busid_by_adapter(adapter));
4525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4526 retval = -EACCES;
4527 break;
4528
4529 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 ZFCP_LOG_NORMAL(
4531 "Error at position %d in the CFDC, "
4532 "CFDC is discarded by the adapter %s\n",
4533 header->fsf_status_qual.word[0],
4534 zfcp_get_busid_by_adapter(adapter));
4535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4536 retval = -EPERM;
4537 break;
4538
4539 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 ZFCP_LOG_NORMAL(
4541 "Adapter %s cannot harden the control file, "
4542 "file is discarded\n",
4543 zfcp_get_busid_by_adapter(adapter));
4544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4545 retval = -EIO;
4546 break;
4547
4548 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 ZFCP_LOG_NORMAL(
4550 "Control file is too large, file is discarded "
4551 "by the adapter %s\n",
4552 zfcp_get_busid_by_adapter(adapter));
4553 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4554 retval = -EIO;
4555 break;
4556
4557 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4559 ZFCP_LOG_NORMAL(
4560 "CFDC has been discarded by the adapter %s, "
4561 "because activation would impact "
4562 "%d active connection(s)\n",
4563 zfcp_get_busid_by_adapter(adapter),
4564 header->fsf_status_qual.word[0]);
4565 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4566 retval = -EIO;
4567 break;
4568
4569 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4571 ZFCP_LOG_NORMAL(
4572 "CFDC has been activated on the adapter %s, "
4573 "but activation has impacted "
4574 "%d active connection(s)\n",
4575 zfcp_get_busid_by_adapter(adapter),
4576 header->fsf_status_qual.word[0]);
4577 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4578 retval = -EIO;
4579 break;
4580
4581 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4583 "op_subtype=0x%x)\n",
4584 zfcp_get_busid_by_adapter(adapter),
4585 bottom->operation_subtype);
4586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4587 retval = -EINVAL;
4588 break;
4589
4590 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 ZFCP_LOG_NORMAL(
4592 "Invalid option 0x%x has been specified "
4593 "in QTCB bottom sent to the adapter %s\n",
4594 bottom->option,
4595 zfcp_get_busid_by_adapter(adapter));
4596 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4597 retval = -EINVAL;
4598 break;
4599
4600 default:
4601 ZFCP_LOG_NORMAL(
4602 "bug: An unknown/unexpected FSF status 0x%08x "
4603 "was presented on the adapter %s\n",
4604 header->fsf_status,
4605 zfcp_get_busid_by_adapter(adapter));
4606 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4607 debug_exception(fsf_req->adapter->erp_dbf, 0,
4608 &header->fsf_status_qual.word[0], sizeof(u32));
4609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4610 retval = -EINVAL;
4611 break;
4612 }
4613
4614skip_fsfstatus:
4615 return retval;
4616}
4617
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618static inline int
4619zfcp_fsf_req_sbal_check(unsigned long *flags,
4620 struct zfcp_qdio_queue *queue, int needed)
4621{
4622 write_lock_irqsave(&queue->queue_lock, *flags);
4623 if (likely(atomic_read(&queue->free_count) >= needed))
4624 return 1;
4625 write_unlock_irqrestore(&queue->queue_lock, *flags);
4626 return 0;
4627}
4628
4629/*
4630 * set qtcb pointer in fsf_req and initialize QTCB
4631 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004632static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004633zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634{
4635 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004636 fsf_req->qtcb->prefix.req_seq_no =
4637 fsf_req->adapter->fsf_req_seq_no;
4638 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004640 fsf_req->qtcb->prefix.qtcb_type =
4641 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004643 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004644 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 }
4646}
4647
4648/**
4649 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4650 * @adapter: adapter for which request queue is examined
4651 * @req_flags: flags indicating whether to wait for needed SBAL or not
4652 * @lock_flags: lock_flags if queue_lock is taken
4653 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4654 * Locks: lock adapter->request_queue->queue_lock on success
4655 */
4656static int
4657zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4658 unsigned long *lock_flags)
4659{
4660 long ret;
4661 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4662
4663 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4664 ret = wait_event_interruptible_timeout(adapter->request_wq,
4665 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4666 ZFCP_SBAL_TIMEOUT);
4667 if (ret < 0)
4668 return ret;
4669 if (!ret)
4670 return -EIO;
4671 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4672 return -EIO;
4673
4674 return 0;
4675}
4676
4677/*
4678 * function: zfcp_fsf_req_create
4679 *
4680 * purpose: create an FSF request at the specified adapter and
4681 * setup common fields
4682 *
4683 * returns: -ENOMEM if there was insufficient memory for a request
4684 * -EIO if no qdio buffers could be allocate to the request
4685 * -EINVAL/-EPERM on bug conditions in req_dequeue
4686 * 0 in success
4687 *
4688 * note: The created request is returned by reference.
4689 *
4690 * locks: lock of concerned request queue must not be held,
4691 * but is held on completion (write, irqsave)
4692 */
4693int
4694zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4695 mempool_t *pool, unsigned long *lock_flags,
4696 struct zfcp_fsf_req **fsf_req_p)
4697{
4698 volatile struct qdio_buffer_element *sbale;
4699 struct zfcp_fsf_req *fsf_req = NULL;
4700 int ret = 0;
4701 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4702
4703 /* allocate new FSF request */
4704 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4705 if (unlikely(NULL == fsf_req)) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +01004706 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 "the outbound (send) queue.\n");
4708 ret = -ENOMEM;
4709 goto failed_fsf_req;
4710 }
4711
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004712 fsf_req->adapter = adapter;
4713 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004714 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004715 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004717 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 this request completion */
4719 init_waitqueue_head(&fsf_req->completion_wq);
4720
4721 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004722 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004724
4725 /* this is serialized (we are holding req_queue-lock of adapter) */
4726 if (adapter->req_no == 0)
4727 adapter->req_no++;
4728 fsf_req->req_id = adapter->req_no++;
4729
4730 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731
4732 /*
4733 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4734 * if it is not set (see also *_open_qdio and *_close_qdio).
4735 */
4736
4737 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4738 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4739 ret = -EIO;
4740 goto failed_sbals;
4741 }
4742
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004743 if (fsf_req->qtcb) {
4744 fsf_req->seq_no = adapter->fsf_req_seq_no;
4745 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 fsf_req->sbal_number = 1;
4748 fsf_req->sbal_first = req_queue->free_index;
4749 fsf_req->sbal_curr = req_queue->free_index;
4750 fsf_req->sbale_curr = 1;
4751
4752 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4753 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4754 }
4755
4756 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4757
4758 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004759 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4761 if (likely(fsf_req->qtcb != NULL)) {
4762 sbale[1].addr = (void *) fsf_req->qtcb;
4763 sbale[1].length = sizeof(struct fsf_qtcb);
4764 }
4765
4766 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4767 fsf_req->sbal_number, fsf_req->sbal_first);
4768
4769 goto success;
4770
4771 failed_sbals:
4772/* dequeue new FSF request previously enqueued */
4773 zfcp_fsf_req_free(fsf_req);
4774 fsf_req = NULL;
4775
4776 failed_fsf_req:
4777 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4778 success:
4779 *fsf_req_p = fsf_req;
4780 return ret;
4781}
4782
4783/*
4784 * function: zfcp_fsf_req_send
4785 *
4786 * purpose: start transfer of FSF request via QDIO
4787 *
4788 * returns: 0 - request transfer succesfully started
4789 * !0 - start of request transfer failed
4790 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004791static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792{
4793 struct zfcp_adapter *adapter;
4794 struct zfcp_qdio_queue *req_queue;
4795 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004796 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 int new_distance_from_int;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004798 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 int retval = 0;
4800
4801 adapter = fsf_req->adapter;
4802 req_queue = &adapter->request_queue,
4803
4804
4805 /* FIXME(debug): remove it later */
4806 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4807 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4808 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4809 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4810 sbale[1].length);
4811
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004812 /* put allocated FSF request into hash table */
4813 spin_lock(&adapter->req_list_lock);
4814 zfcp_reqlist_add(adapter, fsf_req);
4815 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004817 inc_seq_no = (fsf_req->qtcb != NULL);
4818
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819 ZFCP_LOG_TRACE("request queue of adapter %s: "
4820 "next free SBAL is %i, %i free SBALs\n",
4821 zfcp_get_busid_by_adapter(adapter),
4822 req_queue->free_index,
4823 atomic_read(&req_queue->free_count));
4824
4825 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4826 "index_in_queue=%i, count=%i, buffers=%p\n",
4827 zfcp_get_busid_by_adapter(adapter),
4828 QDIO_FLAG_SYNC_OUTPUT,
4829 0, fsf_req->sbal_first, fsf_req->sbal_number,
4830 &req_queue->buffer[fsf_req->sbal_first]);
4831
4832 /*
4833 * adjust the number of free SBALs in request queue as well as
4834 * position of first one
4835 */
4836 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4837 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4838 req_queue->free_index += fsf_req->sbal_number; /* increase */
4839 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4840 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4841
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004842 fsf_req->issued = get_clock();
4843
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 retval = do_QDIO(adapter->ccw_device,
4845 QDIO_FLAG_SYNC_OUTPUT,
4846 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4847
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004848 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4849 dbg_tmp[1] = (u64) retval;
4850 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4851
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852 if (unlikely(retval)) {
4853 /* Queues are down..... */
4854 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004855 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004856 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004857 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004858 spin_unlock(&adapter->req_list_lock);
4859 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 zfcp_qdio_zero_sbals(req_queue->buffer,
4861 fsf_req->sbal_first, fsf_req->sbal_number);
4862 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004863 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4865 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004866 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 } else {
4868 req_queue->distance_from_int = new_distance_from_int;
4869 /*
4870 * increase FSF sequence counter -
4871 * this must only be done for request successfully enqueued to
4872 * QDIO this rejected requests may be cleaned up by calling
4873 * routines resulting in missing sequence counter values
4874 * otherwise,
4875 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004876
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004878 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004880
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004882 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 }
4884 return retval;
4885}
4886
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887#undef ZFCP_LOG_AREA