blob: ffdf99736a4c38d28a8b54e615e44170f4a7cdca [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);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100301 zfcp_erp_adapter_shutdown(adapter, 0, 117, (u64)fsf_req);
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);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100312 zfcp_erp_adapter_reopen(adapter, 0, 98, (u64)fsf_req);
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));
Martin Peschke9467a9b2008-03-27 14:22:03 +0100323 zfcp_erp_adapter_shutdown(adapter, 0, 118, (u64)fsf_req);
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));
Martin Peschke9467a9b2008-03-27 14:22:03 +0100340 zfcp_erp_adapter_shutdown(adapter, 0, 78, (u64)fsf_req);
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);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100347 /* FIXME: reopening adapter now? better wait for link up */
348 zfcp_erp_adapter_reopen(adapter, 0, 79, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
350 break;
351
352 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200353 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 "%s was re-plugged. "
355 "Re-starting operations on this adapter.\n",
356 zfcp_get_busid_by_adapter(adapter));
357 /* All ports should be marked as ready to run again */
Martin Peschke698ec0162008-03-27 14:22:02 +0100358 zfcp_erp_modify_adapter_status(adapter, 28,
359 0, ZFCP_STATUS_COMMON_RUNNING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 ZFCP_SET);
361 zfcp_erp_adapter_reopen(adapter,
362 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100363 | ZFCP_STATUS_COMMON_ERP_FAILED,
364 99, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
366 break;
367
368 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 ZFCP_LOG_NORMAL("error: The adapter %s "
370 "has entered the error state. "
371 "Restarting all operations on this "
372 "adapter.\n",
373 zfcp_get_busid_by_adapter(adapter));
Martin Peschke9467a9b2008-03-27 14:22:03 +0100374 zfcp_erp_adapter_reopen(adapter, 0, 100, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
376 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
377 break;
378
379 default:
380 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
381 "provided by the adapter %s "
382 "is not compatible with the device driver. "
383 "Stopping all operations on this adapter. "
384 "(debug info 0x%x).\n",
385 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200386 qtcb->prefix.prot_status);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100387 zfcp_erp_adapter_shutdown(adapter, 0, 119, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
389 }
390
391 skip_protstatus:
392 /*
393 * always call specific handlers to give them a chance to do
394 * something meaningful even in error cases
395 */
396 zfcp_fsf_fsfstatus_eval(fsf_req);
397 return retval;
398}
399
400/*
401 * function: zfcp_fsf_fsfstatus_eval
402 *
403 * purpose: evaluates FSF status of completed FSF request
404 * and acts accordingly
405 *
406 * returns:
407 */
408static int
409zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
410{
411 int retval = 0;
412
413 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
414 goto skip_fsfstatus;
415 }
416
417 /* evaluate FSF Status */
418 switch (fsf_req->qtcb->header.fsf_status) {
419 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
421 "not known by the adapter %s "
422 "Stopping all operations on this adapter. "
423 "(debug info 0x%x).\n",
424 zfcp_get_busid_by_adapter(fsf_req->adapter),
425 fsf_req->qtcb->header.fsf_command);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100426 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120,
427 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
429 break;
430
431 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
433 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 break;
435
436 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
438 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440
441 skip_fsfstatus:
442 /*
443 * always call specific handlers to give them a chance to do
444 * something meaningful even in error cases
445 */
446 zfcp_fsf_req_dispatch(fsf_req);
447
448 return retval;
449}
450
451/*
452 * function: zfcp_fsf_fsfstatus_qual_eval
453 *
454 * purpose: evaluates FSF status-qualifier of completed FSF request
455 * and acts accordingly
456 *
457 * returns:
458 */
459static int
460zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
461{
462 int retval = 0;
463
464 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
465 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 break;
467 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
470 break;
471 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
474 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
475 break;
476 case FSF_SQ_NO_RECOM:
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100477 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 "problem on the adapter %s "
479 "Stopping all operations on this adapter. ",
480 zfcp_get_busid_by_adapter(fsf_req->adapter));
Martin Peschke9467a9b2008-03-27 14:22:03 +0100481 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121,
482 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
484 break;
485 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
487 "(adapter %s)\n",
488 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
490 break;
491 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
492 case FSF_SQ_NO_RETRY_POSSIBLE:
493 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
494 /* dealt with in the respective functions */
495 break;
496 default:
497 ZFCP_LOG_NORMAL("bug: Additional status info could "
498 "not be interpreted properly.\n");
499 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
500 (char *) &fsf_req->qtcb->header.fsf_status_qual,
501 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
503 break;
504 }
505
506 return retval;
507}
508
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200509/**
510 * zfcp_fsf_link_down_info_eval - evaluate link down information block
511 */
512static void
Martin Peschke698ec0162008-03-27 14:22:02 +0100513zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200514 struct fsf_link_down_info *link_down)
515{
Martin Peschke698ec0162008-03-27 14:22:02 +0100516 struct zfcp_adapter *adapter = fsf_req->adapter;
517
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100518 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
519 &adapter->status))
520 return;
521
522 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
523
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100524 if (link_down == NULL)
525 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100526
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200527 switch (link_down->error_code) {
528 case FSF_PSQ_LINK_NO_LIGHT:
529 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
530 "(no light detected)\n",
531 zfcp_get_busid_by_adapter(adapter));
532 break;
533 case FSF_PSQ_LINK_WRAP_PLUG:
534 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
535 "(wrap plug detected)\n",
536 zfcp_get_busid_by_adapter(adapter));
537 break;
538 case FSF_PSQ_LINK_NO_FCP:
539 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
540 "(adjacent node on link does not support FCP)\n",
541 zfcp_get_busid_by_adapter(adapter));
542 break;
543 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
544 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
545 "(firmware update in progress)\n",
546 zfcp_get_busid_by_adapter(adapter));
547 break;
548 case FSF_PSQ_LINK_INVALID_WWPN:
549 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
550 "(duplicate or invalid WWPN detected)\n",
551 zfcp_get_busid_by_adapter(adapter));
552 break;
553 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
554 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
555 "(no support for NPIV by Fabric)\n",
556 zfcp_get_busid_by_adapter(adapter));
557 break;
558 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
559 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
560 "(out of resource in FCP daughtercard)\n",
561 zfcp_get_busid_by_adapter(adapter));
562 break;
563 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
564 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
565 "(out of resource in Fabric)\n",
566 zfcp_get_busid_by_adapter(adapter));
567 break;
568 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
569 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
570 "(unable to Fabric login)\n",
571 zfcp_get_busid_by_adapter(adapter));
572 break;
573 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
574 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
575 zfcp_get_busid_by_adapter(adapter));
576 break;
577 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
578 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
579 zfcp_get_busid_by_adapter(adapter));
580 break;
581 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
582 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
583 zfcp_get_busid_by_adapter(adapter));
584 break;
585 default:
586 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
587 "(warning: unknown reason code %d)\n",
588 zfcp_get_busid_by_adapter(adapter),
589 link_down->error_code);
590 }
591
592 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
593 ZFCP_LOG_DEBUG("Debug information to link down: "
594 "primary_status=0x%02x "
595 "ioerr_code=0x%02x "
596 "action_code=0x%02x "
597 "reason_code=0x%02x "
598 "explanation_code=0x%02x "
599 "vendor_specific_code=0x%02x\n",
600 link_down->primary_status,
601 link_down->ioerr_code,
602 link_down->action_code,
603 link_down->reason_code,
604 link_down->explanation_code,
605 link_down->vendor_specific_code);
606
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100607 out:
Martin Peschke698ec0162008-03-27 14:22:02 +0100608 zfcp_erp_adapter_failed(adapter, id, (u64)fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200609}
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611/*
612 * function: zfcp_fsf_req_dispatch
613 *
614 * purpose: calls the appropriate command specific handler
615 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200616 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 */
618static int
619zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
620{
621 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
622 struct zfcp_adapter *adapter = fsf_req->adapter;
623 int retval = 0;
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 switch (fsf_req->fsf_command) {
627
628 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 zfcp_fsf_send_fcp_command_handler(fsf_req);
630 break;
631
632 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 zfcp_fsf_abort_fcp_command_handler(fsf_req);
634 break;
635
636 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 zfcp_fsf_send_ct_handler(fsf_req);
638 break;
639
640 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 zfcp_fsf_open_port_handler(fsf_req);
642 break;
643
644 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 zfcp_fsf_open_unit_handler(fsf_req);
646 break;
647
648 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 zfcp_fsf_close_unit_handler(fsf_req);
650 break;
651
652 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 zfcp_fsf_close_port_handler(fsf_req);
654 break;
655
656 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 zfcp_fsf_close_physical_port_handler(fsf_req);
658 break;
659
660 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 zfcp_fsf_exchange_config_data_handler(fsf_req);
662 break;
663
664 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 zfcp_fsf_exchange_port_data_handler(fsf_req);
666 break;
667
668 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 zfcp_fsf_send_els_handler(fsf_req);
670 break;
671
672 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 zfcp_fsf_control_file_handler(fsf_req);
674 break;
675
676 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 zfcp_fsf_control_file_handler(fsf_req);
678 break;
679
680 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
682 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
683 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200684 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
686 ZFCP_LOG_NORMAL
687 ("bug: Command issued by the device driver differs "
688 "from the command returned by the adapter %s "
689 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200690 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 fsf_req->fsf_command,
692 fsf_req->qtcb->header.fsf_command);
693 }
694
695 if (!erp_action)
696 return retval;
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 zfcp_erp_async_handler(erp_action, 0);
699
700 return retval;
701}
702
703/*
704 * function: zfcp_fsf_status_read
705 *
706 * purpose: initiates a Status Read command at the specified adapter
707 *
708 * returns:
709 */
710int
711zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
712{
713 struct zfcp_fsf_req *fsf_req;
714 struct fsf_status_read_buffer *status_buffer;
715 unsigned long lock_flags;
716 volatile struct qdio_buffer_element *sbale;
717 int retval = 0;
718
719 /* setup new FSF request */
720 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
721 req_flags | ZFCP_REQ_NO_QTCB,
722 adapter->pool.fsf_req_status_read,
723 &lock_flags, &fsf_req);
724 if (retval < 0) {
725 ZFCP_LOG_INFO("error: Could not create unsolicited status "
726 "buffer for adapter %s.\n",
727 zfcp_get_busid_by_adapter(adapter));
728 goto failed_req_create;
729 }
730
731 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
732 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
733 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
734 fsf_req->sbale_curr = 2;
735
736 status_buffer =
737 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
738 if (!status_buffer) {
739 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
740 goto failed_buf;
741 }
742 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200743 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 /* insert pointer to respective buffer */
746 sbale = zfcp_qdio_sbale_curr(fsf_req);
747 sbale->addr = (void *) status_buffer;
748 sbale->length = sizeof(struct fsf_status_read_buffer);
749
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200750 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (retval) {
752 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
753 "environment.\n");
754 goto failed_req_send;
755 }
756
757 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
758 zfcp_get_busid_by_adapter(adapter));
759 goto out;
760
761 failed_req_send:
762 mempool_free(status_buffer, adapter->pool.data_status_read);
763
764 failed_buf:
765 zfcp_fsf_req_free(fsf_req);
766 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200767 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 out:
769 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
770 return retval;
771}
772
773static int
774zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
775{
776 struct fsf_status_read_buffer *status_buffer;
777 struct zfcp_adapter *adapter;
778 struct zfcp_port *port;
779 unsigned long flags;
780
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200781 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 adapter = fsf_req->adapter;
783
784 read_lock_irqsave(&zfcp_data.config_lock, flags);
785 list_for_each_entry(port, &adapter->port_list_head, list)
786 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
787 break;
788 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
789
790 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100791 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200792 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 "adapter %s. Ignored.\n",
794 status_buffer->d_id & ZFCP_DID_MASK,
795 zfcp_get_busid_by_adapter(adapter));
796 goto out;
797 }
798
799 switch (status_buffer->status_subtype) {
800
801 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
Martin Peschke9467a9b2008-03-27 14:22:03 +0100803 zfcp_erp_port_reopen(port, 0, 101, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 break;
805
806 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
Martin Peschke9467a9b2008-03-27 14:22:03 +0100808 zfcp_erp_port_shutdown(port, 0, 122, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 break;
810
811 default:
812 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
813 debug_exception(adapter->erp_dbf, 0,
814 &status_buffer->status_subtype, sizeof (u32));
815 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
816 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200817 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 "Ignored. (debug info 0x%x)\n",
819 status_buffer->d_id,
820 zfcp_get_busid_by_adapter(adapter),
821 status_buffer->status_subtype);
822 }
823 out:
824 return 0;
825}
826
827/*
828 * function: zfcp_fsf_status_read_handler
829 *
830 * purpose: is called for finished Open Port command
831 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200832 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 */
834static int
835zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
836{
837 int retval = 0;
838 struct zfcp_adapter *adapter = fsf_req->adapter;
839 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200840 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200841 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200844 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200846 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 goto out;
848 }
849
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200850 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 switch (status_buffer->status_type) {
853
854 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 zfcp_fsf_status_read_port_closed(fsf_req);
856 break;
857
858 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 zfcp_fsf_incoming_els(fsf_req);
860 break;
861
862 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
864 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 break;
866
867 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200868 fsf_bit_error = (struct fsf_bit_error_payload *)
869 status_buffer->payload;
870 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
871 "received (adapter %s, "
872 "link failures = %i, loss of sync errors = %i, "
873 "loss of signal errors = %i, "
874 "primitive sequence errors = %i, "
875 "invalid transmission word errors = %i, "
876 "CRC errors = %i)\n",
877 zfcp_get_busid_by_adapter(adapter),
878 fsf_bit_error->link_failure_error_count,
879 fsf_bit_error->loss_of_sync_error_count,
880 fsf_bit_error->loss_of_signal_error_count,
881 fsf_bit_error->primitive_sequence_error_count,
882 fsf_bit_error->invalid_transmission_word_error_count,
883 fsf_bit_error->crc_error_count);
884 ZFCP_LOG_INFO("Additional bit error threshold data "
885 "(adapter %s, "
886 "primitive sequence event time-outs = %i, "
887 "elastic buffer overrun errors = %i, "
888 "advertised receive buffer-to-buffer credit = %i, "
889 "current receice buffer-to-buffer credit = %i, "
890 "advertised transmit buffer-to-buffer credit = %i, "
891 "current transmit buffer-to-buffer credit = %i)\n",
892 zfcp_get_busid_by_adapter(adapter),
893 fsf_bit_error->primitive_sequence_event_timeout_count,
894 fsf_bit_error->elastic_buffer_overrun_error_count,
895 fsf_bit_error->advertised_receive_b2b_credit,
896 fsf_bit_error->current_receive_b2b_credit,
897 fsf_bit_error->advertised_transmit_b2b_credit,
898 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 break;
900
901 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200902 switch (status_buffer->status_subtype) {
903 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
904 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
905 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100906 zfcp_fsf_link_down_info_eval(fsf_req, 38,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100907 (struct fsf_link_down_info *)
908 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200909 break;
910 case FSF_STATUS_READ_SUB_FDISC_FAILED:
911 ZFCP_LOG_INFO("Local link to adapter %s is down "
912 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100913 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100914 zfcp_fsf_link_down_info_eval(fsf_req, 39,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100915 (struct fsf_link_down_info *)
916 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200917 break;
918 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
919 ZFCP_LOG_INFO("Local link to adapter %s is down "
920 "due to firmware update on adapter\n",
921 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100922 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200923 break;
924 default:
925 ZFCP_LOG_INFO("Local link to adapter %s is down "
926 "due to unknown reason\n",
927 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100928 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200929 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 break;
931
932 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200933 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100934 "Restarting operations on this adapter\n",
935 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 /* All ports should be marked as ready to run again */
Martin Peschke698ec0162008-03-27 14:22:02 +0100937 zfcp_erp_modify_adapter_status(adapter, 30, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 ZFCP_STATUS_COMMON_RUNNING,
939 ZFCP_SET);
940 zfcp_erp_adapter_reopen(adapter,
941 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100942 | ZFCP_STATUS_COMMON_ERP_FAILED,
943 102, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 break;
945
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100946 case FSF_STATUS_READ_NOTIFICATION_LOST:
947 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
948 "adapter %s%s%s%s%s%s%s%s%s\n",
949 zfcp_get_busid_by_adapter(adapter),
950 (status_buffer->status_subtype &
951 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
952 ", incoming ELS" : "",
953 (status_buffer->status_subtype &
954 FSF_STATUS_READ_SUB_SENSE_DATA) ?
955 ", sense data" : "",
956 (status_buffer->status_subtype &
957 FSF_STATUS_READ_SUB_LINK_STATUS) ?
958 ", link status change" : "",
959 (status_buffer->status_subtype &
960 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
961 ", port close" : "",
962 (status_buffer->status_subtype &
963 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
964 ", bit error exception" : "",
965 (status_buffer->status_subtype &
966 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
967 ", ACT update" : "",
968 (status_buffer->status_subtype &
969 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
970 ", ACT hardening" : "",
971 (status_buffer->status_subtype &
972 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
973 ", adapter feature change" : "");
974
975 if (status_buffer->status_subtype &
976 FSF_STATUS_READ_SUB_ACT_UPDATED)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100977 zfcp_erp_adapter_access_changed(adapter, 135,
978 (u64)fsf_req);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100979 break;
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200982 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 zfcp_get_busid_by_adapter(adapter));
Martin Peschke9467a9b2008-03-27 14:22:03 +0100984 zfcp_erp_adapter_access_changed(adapter, 136, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 break;
986
987 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 switch (status_buffer->status_subtype) {
989 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200990 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 zfcp_get_busid_by_adapter(adapter));
992 break;
993 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200994 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 "to the secondary SE\n",
996 zfcp_get_busid_by_adapter(adapter));
997 break;
998 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200999 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 zfcp_get_busid_by_adapter(adapter));
1001 }
1002 break;
1003
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001004 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1005 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1006 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1007 "been changed from 0x%08X to 0x%08X\n",
1008 zfcp_get_busid_by_adapter(adapter),
1009 *(u32*) (status_buffer->payload + 4),
1010 *(u32*) (status_buffer->payload));
1011 adapter->adapter_features = *(u32*) status_buffer->payload;
1012 break;
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001015 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 "type was received (debug info 0x%x)\n",
1017 status_buffer->status_type);
1018 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1019 status_buffer);
1020 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1021 (char *) status_buffer,
1022 sizeof (struct fsf_status_read_buffer));
1023 break;
1024 }
1025 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001026 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 /*
1028 * recycle buffer and start new request repeat until outbound
1029 * queue is empty or adapter shutdown is requested
1030 */
1031 /*
1032 * FIXME(qdio):
1033 * we may wait in the req_create for 5s during shutdown, so
1034 * qdio_cleanup will have to wait at least that long before returning
1035 * with failure to allow us a proper cleanup under all circumstances
1036 */
1037 /*
1038 * FIXME:
1039 * allocation failure possible? (Is this code needed?)
1040 */
1041 retval = zfcp_fsf_status_read(adapter, 0);
1042 if (retval < 0) {
1043 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1044 "request for the adapter %s.\n",
1045 zfcp_get_busid_by_adapter(adapter));
1046 /* temporary fix to avoid status read buffer shortage */
1047 adapter->status_read_failed++;
1048 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1049 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1050 ZFCP_LOG_INFO("restart adapter %s due to status read "
1051 "buffer shortage\n",
1052 zfcp_get_busid_by_adapter(adapter));
Martin Peschke9467a9b2008-03-27 14:22:03 +01001053 zfcp_erp_adapter_reopen(adapter, 0, 103, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 }
1056 out:
1057 return retval;
1058}
1059
1060/*
1061 * function: zfcp_fsf_abort_fcp_command
1062 *
1063 * purpose: tells FSF to abort a running SCSI command
1064 *
1065 * returns: address of initiated FSF request
1066 * NULL - request could not be initiated
1067 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001068 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 * FIXME(design) shouldn't this be modified to return an int
1070 * also...don't know how though
1071 */
1072struct zfcp_fsf_req *
1073zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1074 struct zfcp_adapter *adapter,
1075 struct zfcp_unit *unit, int req_flags)
1076{
1077 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001079 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 int retval = 0;
1081
1082 /* setup new FSF request */
1083 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1084 req_flags, adapter->pool.fsf_req_abort,
1085 &lock_flags, &fsf_req);
1086 if (retval < 0) {
1087 ZFCP_LOG_INFO("error: Failed to create an abort command "
1088 "request for lun 0x%016Lx on port 0x%016Lx "
1089 "on adapter %s.\n",
1090 unit->fcp_lun,
1091 unit->port->wwpn,
1092 zfcp_get_busid_by_adapter(adapter));
1093 goto out;
1094 }
1095
Christof Schmitt951f7462007-12-20 12:30:24 +01001096 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1097 &unit->status)))
1098 goto unit_blocked;
1099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1101 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1102 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1103
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001104 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 /* set handles of unit and its parent port in QTCB */
1107 fsf_req->qtcb->header.lun_handle = unit->handle;
1108 fsf_req->qtcb->header.port_handle = unit->port->handle;
1109
1110 /* set handle of request which should be aborted */
1111 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1112
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001113 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1114 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001115 if (!retval)
1116 goto out;
1117
1118 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 zfcp_fsf_req_free(fsf_req);
1120 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 out:
1123 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1124 return fsf_req;
1125}
1126
1127/*
1128 * function: zfcp_fsf_abort_fcp_command_handler
1129 *
1130 * purpose: is called for finished Abort FCP Command request
1131 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001132 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 */
1134static int
1135zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1136{
1137 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001138 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001139 union fsf_status_qual *fsf_stat_qual =
1140 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1143 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1144 goto skip_fsfstatus;
1145 }
1146
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001147 unit = (struct zfcp_unit *) new_fsf_req->data;
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 /* evaluate FSF status in QTCB */
1150 switch (new_fsf_req->qtcb->header.fsf_status) {
1151
1152 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001153 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1155 "fsf_s_phand_nv0");
1156 /*
1157 * In this case a command that was sent prior to a port
1158 * reopen was aborted (handles are different). This is
1159 * fine.
1160 */
1161 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1163 "port 0x%016Lx on adapter %s invalid. "
1164 "This may happen occasionally.\n",
1165 unit->port->handle,
1166 unit->port->wwpn,
1167 zfcp_get_busid_by_unit(unit));
1168 ZFCP_LOG_INFO("status qualifier:\n");
1169 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1170 (char *) &new_fsf_req->qtcb->header.
1171 fsf_status_qual,
1172 sizeof (union fsf_status_qual));
1173 /* Let's hope this sorts out the mess */
1174 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1175 "fsf_s_phand_nv1");
Martin Peschke9467a9b2008-03-27 14:22:03 +01001176 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
1177 (u64)new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1179 }
1180 break;
1181
1182 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001183 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1185 "fsf_s_lhand_nv0");
1186 /*
1187 * In this case a command that was sent prior to a unit
1188 * reopen was aborted (handles are different).
1189 * This is fine.
1190 */
1191 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 ZFCP_LOG_INFO
1193 ("Warning: Temporary LUN identifier 0x%x of LUN "
1194 "0x%016Lx on port 0x%016Lx on adapter %s is "
1195 "invalid. This may happen in rare cases. "
1196 "Trying to re-establish link.\n",
1197 unit->handle,
1198 unit->fcp_lun,
1199 unit->port->wwpn,
1200 zfcp_get_busid_by_unit(unit));
1201 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1202 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1203 (char *) &new_fsf_req->qtcb->header.
1204 fsf_status_qual,
1205 sizeof (union fsf_status_qual));
1206 /* Let's hope this sorts out the mess */
1207 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1208 "fsf_s_lhand_nv1");
Martin Peschke9467a9b2008-03-27 14:22:03 +01001209 zfcp_erp_port_reopen(unit->port, 0, 105,
1210 (u64)new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1212 }
1213 break;
1214
1215 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 retval = 0;
1217 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1218 "fsf_s_no_exist");
1219 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1220 break;
1221
1222 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1224 "be reopened\n", unit->port->wwpn,
1225 zfcp_get_busid_by_unit(unit));
1226 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1227 "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01001228 zfcp_erp_port_boxed(unit->port, 47, (u64)new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1230 | ZFCP_STATUS_FSFREQ_RETRY;
1231 break;
1232
1233 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 ZFCP_LOG_INFO(
1235 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1236 "to be reopened\n",
1237 unit->fcp_lun, unit->port->wwpn,
1238 zfcp_get_busid_by_unit(unit));
1239 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01001240 zfcp_erp_unit_boxed(unit, 48, (u64)new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1242 | ZFCP_STATUS_FSFREQ_RETRY;
1243 break;
1244
1245 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1247 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1249 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001250 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1252 break;
1253 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 /* SCSI stack will escalate */
1255 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1256 "fsf_sq_ulp");
1257 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1258 break;
1259 default:
1260 ZFCP_LOG_NORMAL
1261 ("bug: Wrong status qualifier 0x%x arrived.\n",
1262 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1263 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1264 "fsf_sq_inval:");
1265 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1266 &new_fsf_req->qtcb->header.
1267 fsf_status_qual.word[0], sizeof (u32));
1268 break;
1269 }
1270 break;
1271
1272 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 retval = 0;
1274 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1275 break;
1276
1277 default:
1278 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1279 "(debug info 0x%x)\n",
1280 new_fsf_req->qtcb->header.fsf_status);
1281 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1282 "fsf_s_inval:");
1283 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1284 &new_fsf_req->qtcb->header.fsf_status,
1285 sizeof (u32));
1286 break;
1287 }
1288 skip_fsfstatus:
1289 return retval;
1290}
1291
1292/**
1293 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1294 * one SBALE
1295 * Two scatter-gather lists are passed, one for the reqeust and one for the
1296 * response.
1297 */
1298static inline int
1299zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1300 struct scatterlist *resp, int resp_count)
1301{
1302 return ((req_count == 1) &&
1303 (resp_count == 1) &&
1304 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1305 PAGE_MASK) ==
1306 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1307 req[0].length - 1) & PAGE_MASK)) &&
1308 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1309 PAGE_MASK) ==
1310 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1311 resp[0].length - 1) & PAGE_MASK)));
1312}
1313
1314/**
1315 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1316 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1317 * the request
1318 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1319 * a struct zfcp_fsf_req
1320 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1321 * is sent within error recovery
1322 */
1323int
1324zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1325 struct zfcp_erp_action *erp_action)
1326{
1327 volatile struct qdio_buffer_element *sbale;
1328 struct zfcp_port *port;
1329 struct zfcp_adapter *adapter;
1330 struct zfcp_fsf_req *fsf_req;
1331 unsigned long lock_flags;
1332 int bytes;
1333 int ret = 0;
1334
1335 port = ct->port;
1336 adapter = port->adapter;
1337
1338 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1339 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1340 pool, &lock_flags, &fsf_req);
1341 if (ret < 0) {
1342 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1343 "adapter: %s\n",
1344 zfcp_get_busid_by_adapter(adapter));
1345 goto failed_req;
1346 }
1347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1349 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1350 ct->resp, ct->resp_count)){
1351 /* both request buffer and response buffer
1352 fit into one sbale each */
1353 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1354 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1355 sbale[2].length = ct->req[0].length;
1356 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1357 sbale[3].length = ct->resp[0].length;
1358 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001359 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1361 /* try to use chained SBALs */
1362 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1363 SBAL_FLAGS0_TYPE_WRITE_READ,
1364 ct->req, ct->req_count,
1365 ZFCP_MAX_SBALS_PER_CT_REQ);
1366 if (bytes <= 0) {
1367 ZFCP_LOG_INFO("error: creation of CT request failed "
1368 "on adapter %s\n",
1369 zfcp_get_busid_by_adapter(adapter));
1370 if (bytes == 0)
1371 ret = -ENOMEM;
1372 else
1373 ret = bytes;
1374
1375 goto failed_send;
1376 }
1377 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1378 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1379 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1380 SBAL_FLAGS0_TYPE_WRITE_READ,
1381 ct->resp, ct->resp_count,
1382 ZFCP_MAX_SBALS_PER_CT_REQ);
1383 if (bytes <= 0) {
1384 ZFCP_LOG_INFO("error: creation of CT request failed "
1385 "on adapter %s\n",
1386 zfcp_get_busid_by_adapter(adapter));
1387 if (bytes == 0)
1388 ret = -ENOMEM;
1389 else
1390 ret = bytes;
1391
1392 goto failed_send;
1393 }
1394 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1395 } else {
1396 /* reject send generic request */
1397 ZFCP_LOG_INFO(
1398 "error: microcode does not support chained SBALs,"
1399 "CT request too big (adapter %s)\n",
1400 zfcp_get_busid_by_adapter(adapter));
1401 ret = -EOPNOTSUPP;
1402 goto failed_send;
1403 }
1404
1405 /* settings in QTCB */
1406 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001407 fsf_req->qtcb->bottom.support.service_class =
1408 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001410 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001412 zfcp_san_dbf_event_ct_request(fsf_req);
1413
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001414 if (erp_action) {
1415 erp_action->fsf_req = fsf_req;
1416 fsf_req->erp_action = erp_action;
1417 zfcp_erp_start_timer(fsf_req);
1418 } else
1419 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1420
1421 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (ret) {
1423 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1424 "(adapter %s, port 0x%016Lx)\n",
1425 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1426 goto failed_send;
1427 }
1428
1429 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1430 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1431 goto out;
1432
1433 failed_send:
1434 zfcp_fsf_req_free(fsf_req);
1435 if (erp_action != NULL) {
1436 erp_action->fsf_req = NULL;
1437 }
1438 failed_req:
1439 out:
1440 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1441 lock_flags);
1442 return ret;
1443}
1444
1445/**
1446 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1447 * @fsf_req: pointer to struct zfcp_fsf_req
1448 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001449 * Data specific for the Generic Service request is passed using
1450 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1451 * Usually a specific handler for the CT request is called which is
1452 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 */
1454static int
1455zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1456{
1457 struct zfcp_port *port;
1458 struct zfcp_adapter *adapter;
1459 struct zfcp_send_ct *send_ct;
1460 struct fsf_qtcb_header *header;
1461 struct fsf_qtcb_bottom_support *bottom;
1462 int retval = -EINVAL;
1463 u16 subtable, rule, counter;
1464
1465 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001466 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 port = send_ct->port;
1468 header = &fsf_req->qtcb->header;
1469 bottom = &fsf_req->qtcb->bottom.support;
1470
1471 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1472 goto skip_fsfstatus;
1473
1474 /* evaluate FSF status in QTCB */
1475 switch (header->fsf_status) {
1476
1477 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001478 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 retval = 0;
1480 break;
1481
1482 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001483 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1484 "class %d.\n",
1485 zfcp_get_busid_by_port(port),
1486 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 /* stop operation for this adapter */
1488 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
Martin Peschke9467a9b2008-03-27 14:22:03 +01001489 zfcp_erp_adapter_shutdown(adapter, 0, 123, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1491 break;
1492
1493 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 switch (header->fsf_status_qual.word[0]){
1495 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 /* reopening link to port */
1497 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1498 zfcp_test_link(port);
1499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1500 break;
1501 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 /* ERP strategy will escalate */
1503 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1504 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1505 break;
1506 default:
1507 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1508 "arrived.\n",
1509 header->fsf_status_qual.word[0]);
1510 break;
1511 }
1512 break;
1513
1514 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001516 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 zfcp_get_busid_by_port(port), port->d_id);
1518 for (counter = 0; counter < 2; counter++) {
1519 subtable = header->fsf_status_qual.halfword[counter * 2];
1520 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1521 switch (subtable) {
1522 case FSF_SQ_CFDC_SUBTABLE_OS:
1523 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1524 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1525 case FSF_SQ_CFDC_SUBTABLE_LUN:
1526 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1527 zfcp_act_subtable_type[subtable], rule);
1528 break;
1529 }
1530 }
1531 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01001532 zfcp_erp_port_access_denied(port, 55, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1534 break;
1535
1536 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001538 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 zfcp_get_busid_by_port(port), port->d_id);
1540 ZFCP_LOG_INFO("status qualifier:\n");
1541 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1542 (char *) &header->fsf_status_qual,
1543 sizeof (union fsf_status_qual));
1544 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1545 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1546 break;
1547
1548 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1550 "0x%016Lx on adapter %s invalid. This may "
1551 "happen occasionally.\n", port->handle,
1552 port->wwpn, zfcp_get_busid_by_port(port));
1553 ZFCP_LOG_INFO("status qualifier:\n");
1554 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1555 (char *) &header->fsf_status_qual,
1556 sizeof (union fsf_status_qual));
1557 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01001558 zfcp_erp_adapter_reopen(adapter, 0, 106, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1560 break;
1561
1562 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001564 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 zfcp_get_busid_by_port(port), port->d_id);
1566 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01001567 zfcp_erp_port_boxed(port, 49, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1569 | ZFCP_STATUS_FSFREQ_RETRY;
1570 break;
1571
1572 /* following states should never occure, all cases avoided
1573 in zfcp_fsf_send_ct - but who knows ... */
1574 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1576 "req_buf_length=%d, resp_buf_length=%d)\n",
1577 zfcp_get_busid_by_adapter(adapter),
1578 bottom->req_buf_length, bottom->resp_buf_length);
1579 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1580 break;
1581 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1583 "req_buf_length=%d)\n",
1584 zfcp_get_busid_by_adapter(adapter),
1585 bottom->req_buf_length);
1586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1587 break;
1588 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1590 "resp_buf_length=%d)\n",
1591 zfcp_get_busid_by_adapter(adapter),
1592 bottom->resp_buf_length);
1593 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1594 break;
1595 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1597 "resp_buf_length=%d)\n",
1598 zfcp_get_busid_by_adapter(adapter),
1599 bottom->req_buf_length, bottom->resp_buf_length);
1600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1601 break;
1602
1603 default:
1604 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1605 "(debug info 0x%x)\n", header->fsf_status);
1606 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1607 debug_exception(adapter->erp_dbf, 0,
1608 &header->fsf_status_qual.word[0], sizeof (u32));
1609 break;
1610 }
1611
1612skip_fsfstatus:
1613 send_ct->status = retval;
1614
1615 if (send_ct->handler != NULL)
1616 send_ct->handler(send_ct->handler_data);
1617
1618 return retval;
1619}
1620
1621/**
1622 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1623 * @els: pointer to struct zfcp_send_els which contains all needed data for
1624 * the command.
1625 */
1626int
1627zfcp_fsf_send_els(struct zfcp_send_els *els)
1628{
1629 volatile struct qdio_buffer_element *sbale;
1630 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001631 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 struct zfcp_adapter *adapter;
1633 unsigned long lock_flags;
1634 int bytes;
1635 int ret = 0;
1636
1637 d_id = els->d_id;
1638 adapter = els->adapter;
1639
1640 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1641 ZFCP_REQ_AUTO_CLEANUP,
1642 NULL, &lock_flags, &fsf_req);
1643 if (ret < 0) {
1644 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001645 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 zfcp_get_busid_by_adapter(adapter), d_id);
1647 goto failed_req;
1648 }
1649
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001650 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1651 &els->port->status))) {
1652 ret = -EBUSY;
1653 goto port_blocked;
1654 }
1655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1657 if (zfcp_use_one_sbal(els->req, els->req_count,
1658 els->resp, els->resp_count)){
1659 /* both request buffer and response buffer
1660 fit into one sbale each */
1661 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1662 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1663 sbale[2].length = els->req[0].length;
1664 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1665 sbale[3].length = els->resp[0].length;
1666 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001667 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1669 /* try to use chained SBALs */
1670 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1671 SBAL_FLAGS0_TYPE_WRITE_READ,
1672 els->req, els->req_count,
1673 ZFCP_MAX_SBALS_PER_ELS_REQ);
1674 if (bytes <= 0) {
1675 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001676 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 zfcp_get_busid_by_adapter(adapter), d_id);
1678 if (bytes == 0) {
1679 ret = -ENOMEM;
1680 } else {
1681 ret = bytes;
1682 }
1683 goto failed_send;
1684 }
1685 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1686 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1687 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1688 SBAL_FLAGS0_TYPE_WRITE_READ,
1689 els->resp, els->resp_count,
1690 ZFCP_MAX_SBALS_PER_ELS_REQ);
1691 if (bytes <= 0) {
1692 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001693 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 zfcp_get_busid_by_adapter(adapter), d_id);
1695 if (bytes == 0) {
1696 ret = -ENOMEM;
1697 } else {
1698 ret = bytes;
1699 }
1700 goto failed_send;
1701 }
1702 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1703 } else {
1704 /* reject request */
1705 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1706 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001707 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 zfcp_get_busid_by_adapter(adapter), d_id);
1709 ret = -EOPNOTSUPP;
1710 goto failed_send;
1711 }
1712
1713 /* settings in QTCB */
1714 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001715 fsf_req->qtcb->bottom.support.service_class =
1716 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001718 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
1720 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1721
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001722 zfcp_san_dbf_event_els_request(fsf_req);
1723
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001724 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1725 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 if (ret) {
1727 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001728 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 zfcp_get_busid_by_adapter(adapter), d_id);
1730 goto failed_send;
1731 }
1732
1733 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001734 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 goto out;
1736
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001737 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 failed_send:
1739 zfcp_fsf_req_free(fsf_req);
1740
1741 failed_req:
1742 out:
1743 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1744 lock_flags);
1745
1746 return ret;
1747}
1748
1749/**
1750 * zfcp_fsf_send_els_handler - handler for ELS commands
1751 * @fsf_req: pointer to struct zfcp_fsf_req
1752 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001753 * Data specific for the ELS command is passed using
1754 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1755 * Usually a specific handler for the ELS command is called which is
1756 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 */
1758static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1759{
1760 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001762 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 struct fsf_qtcb_header *header;
1764 struct fsf_qtcb_bottom_support *bottom;
1765 struct zfcp_send_els *send_els;
1766 int retval = -EINVAL;
1767 u16 subtable, rule, counter;
1768
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001769 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001771 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 d_id = send_els->d_id;
1773 header = &fsf_req->qtcb->header;
1774 bottom = &fsf_req->qtcb->bottom.support;
1775
1776 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1777 goto skip_fsfstatus;
1778
1779 switch (header->fsf_status) {
1780
1781 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001782 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 retval = 0;
1784 break;
1785
1786 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001787 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1788 "class %d.\n",
1789 zfcp_get_busid_by_adapter(adapter),
1790 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 /* stop operation for this adapter */
1792 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
Martin Peschke9467a9b2008-03-27 14:22:03 +01001793 zfcp_erp_adapter_shutdown(adapter, 0, 124, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1795 break;
1796
1797 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 switch (header->fsf_status_qual.word[0]){
1799 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001801 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1802 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1804 break;
1805 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1808 retval =
1809 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1810 (struct zfcp_ls_rjt_par *)
1811 &header->fsf_status_qual.word[2]);
1812 break;
1813 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1816 break;
1817 default:
1818 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1819 header->fsf_status_qual.word[0]);
1820 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1821 (char*)header->fsf_status_qual.word, 16);
1822 }
1823 break;
1824
1825 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1827 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001828 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 zfcp_get_busid_by_adapter(adapter), d_id);
1830
1831 break;
1832
1833 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 ZFCP_LOG_INFO(
1835 "ELS request size and ELS response size must be either "
1836 "both 0, or both greater than 0 "
1837 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1838 zfcp_get_busid_by_adapter(adapter),
1839 bottom->req_buf_length,
1840 bottom->resp_buf_length);
1841 break;
1842
1843 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 ZFCP_LOG_INFO(
1845 "Length of the ELS request buffer, "
1846 "specified in QTCB bottom, "
1847 "exceeds the size of the buffers "
1848 "that have been allocated for ELS request data "
1849 "(adapter: %s, req_buf_length=%d)\n",
1850 zfcp_get_busid_by_adapter(adapter),
1851 bottom->req_buf_length);
1852 break;
1853
1854 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 ZFCP_LOG_INFO(
1856 "Length of the ELS response buffer, "
1857 "specified in QTCB bottom, "
1858 "exceeds the size of the buffers "
1859 "that have been allocated for ELS response data "
1860 "(adapter: %s, resp_buf_length=%d)\n",
1861 zfcp_get_busid_by_adapter(adapter),
1862 bottom->resp_buf_length);
1863 break;
1864
1865 case FSF_SBAL_MISMATCH:
1866 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1868 "resp_buf_length=%d)\n",
1869 zfcp_get_busid_by_adapter(adapter),
1870 bottom->req_buf_length, bottom->resp_buf_length);
1871 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1872 break;
1873
1874 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001876 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 zfcp_get_busid_by_adapter(adapter), d_id);
1878 for (counter = 0; counter < 2; counter++) {
1879 subtable = header->fsf_status_qual.halfword[counter * 2];
1880 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1881 switch (subtable) {
1882 case FSF_SQ_CFDC_SUBTABLE_OS:
1883 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1884 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1885 case FSF_SQ_CFDC_SUBTABLE_LUN:
1886 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1887 zfcp_act_subtable_type[subtable], rule);
1888 break;
1889 }
1890 }
1891 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 if (port != NULL)
Martin Peschke698ec0162008-03-27 14:22:02 +01001893 zfcp_erp_port_access_denied(port, 56, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1895 break;
1896
1897 default:
1898 ZFCP_LOG_NORMAL(
1899 "bug: An unknown FSF Status was presented "
1900 "(adapter: %s, fsf_status=0x%08x)\n",
1901 zfcp_get_busid_by_adapter(adapter),
1902 header->fsf_status);
1903 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1904 debug_exception(adapter->erp_dbf, 0,
1905 &header->fsf_status_qual.word[0], sizeof(u32));
1906 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1907 break;
1908 }
1909
1910skip_fsfstatus:
1911 send_els->status = retval;
1912
Heiko Carstensaa551da2007-07-18 10:55:10 +02001913 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 send_els->handler(send_els->handler_data);
1915
1916 return retval;
1917}
1918
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919int
1920zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1921{
1922 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001923 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001924 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001926 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
1928 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001929 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1931 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001932 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001933 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001934 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1936 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001937 zfcp_get_busid_by_adapter(adapter));
1938 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1939 lock_flags);
1940 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 }
1942
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001943 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001944 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1945 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001947 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001948 FSF_FEATURE_CFDC |
1949 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001950 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001951 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001952 fsf_req->erp_action = erp_action;
1953 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001955 zfcp_erp_start_timer(fsf_req);
1956 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001957 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1958 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001960 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1961 "data command on the adapter %s\n",
1962 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001963 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001965 }
1966 else
1967 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1968 "(adapter %s)\n",
1969 zfcp_get_busid_by_adapter(adapter));
1970
1971 return retval;
1972}
1973
1974int
1975zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1976 struct fsf_qtcb_bottom_config *data)
1977{
1978 volatile struct qdio_buffer_element *sbale;
1979 struct zfcp_fsf_req *fsf_req;
1980 unsigned long lock_flags;
1981 int retval;
1982
1983 /* setup new FSF request */
1984 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1985 0, NULL, &lock_flags, &fsf_req);
1986 if (retval) {
1987 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1988 "data request for adapter %s.\n",
1989 zfcp_get_busid_by_adapter(adapter));
1990 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1991 lock_flags);
1992 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 }
1994
Swen Schillig52ef11a2007-08-28 09:31:09 +02001995 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1996 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1997 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Swen Schillig52ef11a2007-08-28 09:31:09 +02001999 fsf_req->qtcb->bottom.config.feature_selection =
2000 FSF_FEATURE_CFDC |
2001 FSF_FEATURE_LUN_SHARING |
2002 FSF_FEATURE_NOTIFICATION_LOST |
2003 FSF_FEATURE_UPDATE_ALERT;
2004
2005 if (data)
2006 fsf_req->data = (unsigned long) data;
2007
2008 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2009 retval = zfcp_fsf_req_send(fsf_req);
2010 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002012 if (retval)
2013 ZFCP_LOG_INFO("error: Could not send exchange configuration "
2014 "data command on the adapter %s\n",
2015 zfcp_get_busid_by_adapter(adapter));
2016 else
2017 wait_event(fsf_req->completion_wq,
2018 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2019
2020 zfcp_fsf_req_free(fsf_req);
2021
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 return retval;
2023}
2024
2025/**
2026 * zfcp_fsf_exchange_config_evaluate
2027 * @fsf_req: fsf_req which belongs to xchg config data request
2028 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2029 *
2030 * returns: -EIO on error, 0 otherwise
2031 */
2032static int
2033zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2034{
2035 struct fsf_qtcb_bottom_config *bottom;
2036 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002037 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
2039 bottom = &fsf_req->qtcb->bottom.config;
2040 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2041 bottom->low_qtcb_version, bottom->high_qtcb_version);
2042 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002043 adapter->adapter_features = bottom->adapter_features;
2044 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05002045 adapter->peer_wwpn = 0;
2046 adapter->peer_wwnn = 0;
2047 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02002050
2051 if (fsf_req->data)
2052 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
2053 bottom, sizeof (struct fsf_qtcb_bottom_config));
2054
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002055 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2056 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2057 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2058 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002059 fc_host_supported_classes(shost) =
2060 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002062 if (fc_host_permanent_port_name(shost) == -1)
2063 fc_host_permanent_port_name(shost) =
2064 fc_host_port_name(shost);
2065 if (bottom->fc_topology == FSF_TOPO_P2P) {
2066 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2067 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2068 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2069 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2070 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2071 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2072 else if (bottom->fc_topology == FSF_TOPO_AL)
2073 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2074 else
2075 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002077 fc_host_node_name(shost) = 0;
2078 fc_host_port_name(shost) = 0;
2079 fc_host_port_id(shost) = 0;
2080 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002081 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 adapter->hydra_version = 0;
2083 }
2084
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002085 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002087 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2088 min(FC_SERIAL_NUMBER_SIZE, 17));
2089 EBCASC(fc_host_serial_number(shost),
2090 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 }
2092
Swen Schillig52ef11a2007-08-28 09:31:09 +02002093 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2094 "characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002095 "WWNN 0x%016Lx, "
2096 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002097 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002098 "adapter version 0x%x, "
2099 "LIC version 0x%x, "
2100 "FC link speed %d Gb/s\n",
2101 zfcp_get_busid_by_adapter(adapter),
2102 (wwn_t) fc_host_node_name(shost),
2103 (wwn_t) fc_host_port_name(shost),
2104 fc_host_port_id(shost),
2105 adapter->hydra_version,
2106 adapter->fsf_lic_version,
2107 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2109 ZFCP_LOG_NORMAL("error: the adapter %s "
2110 "only supports newer control block "
2111 "versions in comparison to this device "
2112 "driver (try updated device driver)\n",
2113 zfcp_get_busid_by_adapter(adapter));
2114 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
Martin Peschke9467a9b2008-03-27 14:22:03 +01002115 zfcp_erp_adapter_shutdown(adapter, 0, 125, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 return -EIO;
2117 }
2118 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2119 ZFCP_LOG_NORMAL("error: the adapter %s "
2120 "only supports older control block "
2121 "versions than this device driver uses"
2122 "(consider a microcode upgrade)\n",
2123 zfcp_get_busid_by_adapter(adapter));
2124 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
Martin Peschke9467a9b2008-03-27 14:22:03 +01002125 zfcp_erp_adapter_shutdown(adapter, 0, 126, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 return -EIO;
2127 }
2128 return 0;
2129}
2130
Swen Schillig52ef11a2007-08-28 09:31:09 +02002131/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 * function: zfcp_fsf_exchange_config_data_handler
2133 *
2134 * purpose: is called for finished Exchange Configuration Data command
2135 *
2136 * returns:
2137 */
2138static int
2139zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2140{
2141 struct fsf_qtcb_bottom_config *bottom;
2142 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002143 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
2145 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2146 return -EIO;
2147
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002148 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
2150 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2152 return -EIO;
2153
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002154 switch (fc_host_port_type(adapter->scsi_host)) {
2155 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002156 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2157 "configuration detected at adapter %s\n"
2158 "Peer WWNN 0x%016llx, "
2159 "peer WWPN 0x%016llx, "
2160 "peer d_id 0x%06x\n",
2161 zfcp_get_busid_by_adapter(adapter),
2162 adapter->peer_wwnn,
2163 adapter->peer_wwpn,
2164 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 debug_text_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002166 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002167 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002168 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2170 "topology detected at adapter %s "
2171 "unsupported, shutting down adapter\n",
2172 zfcp_get_busid_by_adapter(adapter));
2173 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2174 "top-al");
Martin Peschke9467a9b2008-03-27 14:22:03 +01002175 zfcp_erp_adapter_shutdown(adapter, 0, 127, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002177 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002178 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002179 "network detected at adapter %s.\n",
2180 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 break;
2182 default:
2183 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2184 "reported by the exchange "
2185 "configuration command for "
2186 "the adapter %s is not "
2187 "of a type known to the zfcp "
2188 "driver, shutting down adapter\n",
2189 zfcp_get_busid_by_adapter(adapter));
2190 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2191 "unknown-topo");
Martin Peschke9467a9b2008-03-27 14:22:03 +01002192 zfcp_erp_adapter_shutdown(adapter, 0, 128, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 return -EIO;
2194 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002195 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2197 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2198 "allowed by the adapter %s "
2199 "is lower than the minimum "
2200 "required by the driver (%ld bytes).\n",
2201 bottom->max_qtcb_size,
2202 zfcp_get_busid_by_adapter(adapter),
2203 sizeof(struct fsf_qtcb));
2204 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2205 "qtcb-size");
2206 debug_event(fsf_req->adapter->erp_dbf, 0,
2207 &bottom->max_qtcb_size, sizeof (u32));
Martin Peschke9467a9b2008-03-27 14:22:03 +01002208 zfcp_erp_adapter_shutdown(adapter, 0, 129, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 return -EIO;
2210 }
2211 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2212 &adapter->status);
2213 break;
2214 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2215 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2216
2217 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2218 return -EIO;
2219
Swen Schillig52ef11a2007-08-28 09:31:09 +02002220 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2221 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002222
Martin Peschke698ec0162008-03-27 14:22:02 +01002223 zfcp_fsf_link_down_info_eval(fsf_req, 42,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002224 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 break;
2226 default:
2227 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2228 debug_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002229 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
Martin Peschke9467a9b2008-03-27 14:22:03 +01002230 zfcp_erp_adapter_shutdown(adapter, 0, 130, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 return -EIO;
2232 }
2233 return 0;
2234}
2235
2236/**
2237 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002238 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 */
2240int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002241zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
2243 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002244 struct zfcp_fsf_req *fsf_req;
2245 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002246 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002247 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002249 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002251 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002253 return -EOPNOTSUPP;
2254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 /* setup new FSF request */
2257 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002258 ZFCP_REQ_AUTO_CLEANUP,
2259 adapter->pool.fsf_req_erp,
2260 &lock_flags, &fsf_req);
2261 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002263 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002264 "the adapter %s.\n",
2265 zfcp_get_busid_by_adapter(adapter));
2266 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2267 lock_flags);
2268 return retval;
2269 }
2270
2271 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2272 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2273 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2274
2275 erp_action->fsf_req = fsf_req;
2276 fsf_req->erp_action = erp_action;
2277 zfcp_erp_start_timer(fsf_req);
2278
2279 retval = zfcp_fsf_req_send(fsf_req);
2280 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2281
2282 if (retval) {
2283 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2284 "command on the adapter %s\n",
2285 zfcp_get_busid_by_adapter(adapter));
2286 zfcp_fsf_req_free(fsf_req);
2287 erp_action->fsf_req = NULL;
2288 }
2289 else
2290 ZFCP_LOG_DEBUG("exchange port data request initiated "
2291 "(adapter %s)\n",
2292 zfcp_get_busid_by_adapter(adapter));
2293 return retval;
2294}
2295
2296
2297/**
2298 * zfcp_fsf_exchange_port_data_sync - request information about local port
2299 * and wait until information is ready
2300 */
2301int
2302zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2303 struct fsf_qtcb_bottom_port *data)
2304{
2305 volatile struct qdio_buffer_element *sbale;
2306 struct zfcp_fsf_req *fsf_req;
2307 unsigned long lock_flags;
2308 int retval;
2309
2310 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2311 ZFCP_LOG_INFO("error: exchange port data "
2312 "command not supported by adapter %s\n",
2313 zfcp_get_busid_by_adapter(adapter));
2314 return -EOPNOTSUPP;
2315 }
2316
2317 /* setup new FSF request */
2318 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2319 0, NULL, &lock_flags, &fsf_req);
2320 if (retval) {
2321 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002322 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002323 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 zfcp_get_busid_by_adapter(adapter));
2325 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2326 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002327 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002328 }
2329
2330 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002331 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002332
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002334 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2335 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Swen Schillig52ef11a2007-08-28 09:31:09 +02002337 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002338 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002339 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
Swen Schillig52ef11a2007-08-28 09:31:09 +02002341 if (retval)
2342 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2343 "command on the adapter %s\n",
2344 zfcp_get_busid_by_adapter(adapter));
2345 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002346 wait_event(fsf_req->completion_wq,
2347 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002348
2349 zfcp_fsf_req_free(fsf_req);
2350
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 return retval;
2352}
2353
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002354/**
2355 * zfcp_fsf_exchange_port_evaluate
2356 * @fsf_req: fsf_req which belongs to xchg port data request
2357 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2358 */
2359static void
2360zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2361{
2362 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002363 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002364 struct Scsi_Host *shost;
2365
2366 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002367 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002368 shost = adapter->scsi_host;
2369
Swen Schillig52ef11a2007-08-28 09:31:09 +02002370 if (fsf_req->data)
2371 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2372 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002373
2374 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2375 fc_host_permanent_port_name(shost) = bottom->wwpn;
2376 else
2377 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2378 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2379 fc_host_supported_speeds(shost) = bottom->supported_speed;
2380}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382/**
2383 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2384 * @fsf_req: pointer to struct zfcp_fsf_req
2385 */
2386static void
2387zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2388{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002389 struct zfcp_adapter *adapter;
2390 struct fsf_qtcb *qtcb;
2391
2392 adapter = fsf_req->adapter;
2393 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2396 return;
2397
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002398 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002400 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002401 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002402 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002403 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002404 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002405 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Martin Peschke698ec0162008-03-27 14:22:02 +01002406 zfcp_fsf_link_down_info_eval(fsf_req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002407 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002410 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2411 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2413 }
2414}
2415
2416
2417/*
2418 * function: zfcp_fsf_open_port
2419 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002420 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 *
2422 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002423 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 */
2425int
2426zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2427{
2428 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002429 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 unsigned long lock_flags;
2431 int retval = 0;
2432
2433 /* setup new FSF request */
2434 retval = zfcp_fsf_req_create(erp_action->adapter,
2435 FSF_QTCB_OPEN_PORT_WITH_DID,
2436 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2437 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002438 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 if (retval < 0) {
2440 ZFCP_LOG_INFO("error: Could not create open port request "
2441 "for port 0x%016Lx on adapter %s.\n",
2442 erp_action->port->wwpn,
2443 zfcp_get_busid_by_adapter(erp_action->adapter));
2444 goto out;
2445 }
2446
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002447 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2449 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2450
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002451 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002453 fsf_req->data = (unsigned long) erp_action->port;
2454 fsf_req->erp_action = erp_action;
2455 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002457 zfcp_erp_start_timer(fsf_req);
2458 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 if (retval) {
2460 ZFCP_LOG_INFO("error: Could not send open port request for "
2461 "port 0x%016Lx on adapter %s.\n",
2462 erp_action->port->wwpn,
2463 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002464 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 erp_action->fsf_req = NULL;
2466 goto out;
2467 }
2468
2469 ZFCP_LOG_DEBUG("open port request initiated "
2470 "(adapter %s, port 0x%016Lx)\n",
2471 zfcp_get_busid_by_adapter(erp_action->adapter),
2472 erp_action->port->wwpn);
2473 out:
2474 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2475 lock_flags);
2476 return retval;
2477}
2478
2479/*
2480 * function: zfcp_fsf_open_port_handler
2481 *
2482 * purpose: is called for finished Open Port command
2483 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002484 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 */
2486static int
2487zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2488{
2489 int retval = -EINVAL;
2490 struct zfcp_port *port;
2491 struct fsf_plogi *plogi;
2492 struct fsf_qtcb_header *header;
2493 u16 subtable, rule, counter;
2494
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002495 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 header = &fsf_req->qtcb->header;
2497
2498 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2499 /* don't change port status in our bookkeeping */
2500 goto skip_fsfstatus;
2501 }
2502
2503 /* evaluate FSF status in QTCB */
2504 switch (header->fsf_status) {
2505
2506 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2508 "is already open.\n",
2509 port->wwpn, zfcp_get_busid_by_port(port));
2510 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2511 "fsf_s_popen");
2512 /*
2513 * This is a bug, however operation should continue normally
2514 * if it is simply ignored
2515 */
2516 break;
2517
2518 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2520 "on adapter %s\n",
2521 port->wwpn, zfcp_get_busid_by_port(port));
2522 for (counter = 0; counter < 2; counter++) {
2523 subtable = header->fsf_status_qual.halfword[counter * 2];
2524 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2525 switch (subtable) {
2526 case FSF_SQ_CFDC_SUBTABLE_OS:
2527 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2528 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2529 case FSF_SQ_CFDC_SUBTABLE_LUN:
2530 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2531 zfcp_act_subtable_type[subtable], rule);
2532 break;
2533 }
2534 }
2535 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01002536 zfcp_erp_port_access_denied(port, 57, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2538 break;
2539
2540 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2542 "The remote port 0x%016Lx on adapter %s "
2543 "could not be opened. Disabling it.\n",
2544 port->wwpn, zfcp_get_busid_by_port(port));
2545 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2546 "fsf_s_max_ports");
Martin Peschke698ec0162008-03-27 14:22:02 +01002547 zfcp_erp_port_failed(port, 31, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2549 break;
2550
2551 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 switch (header->fsf_status_qual.word[0]) {
2553 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2555 "fsf_sq_ltest");
2556 /* ERP strategy will escalate */
2557 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2558 break;
2559 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2560 /* ERP strategy will escalate */
2561 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2562 "fsf_sq_ulp");
2563 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2564 break;
2565 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2567 "adapter %s could not be opened. "
2568 "Disabling it.\n",
2569 port->wwpn,
2570 zfcp_get_busid_by_port(port));
2571 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2572 "fsf_sq_no_retry");
Martin Peschke698ec0162008-03-27 14:22:02 +01002573 zfcp_erp_port_failed(port, 32, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2575 break;
2576 default:
2577 ZFCP_LOG_NORMAL
2578 ("bug: Wrong status qualifier 0x%x arrived.\n",
2579 header->fsf_status_qual.word[0]);
2580 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2581 "fsf_sq_inval:");
2582 debug_exception(
2583 fsf_req->adapter->erp_dbf, 0,
2584 &header->fsf_status_qual.word[0],
2585 sizeof (u32));
2586 break;
2587 }
2588 break;
2589
2590 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 /* save port handle assigned by FSF */
2592 port->handle = header->port_handle;
2593 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2594 "was opened, it's port handle is 0x%x\n",
2595 port->wwpn, zfcp_get_busid_by_port(port),
2596 port->handle);
2597 /* mark port as open */
2598 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2599 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002600 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2601 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2602 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 retval = 0;
2604 /* check whether D_ID has changed during open */
2605 /*
2606 * FIXME: This check is not airtight, as the FCP channel does
2607 * not monitor closures of target port connections caused on
2608 * the remote side. Thus, they might miss out on invalidating
2609 * locally cached WWPNs (and other N_Port parameters) of gone
2610 * target ports. So, our heroic attempt to make things safe
2611 * could be undermined by 'open port' response data tagged with
2612 * obsolete WWPNs. Another reason to monitor potential
2613 * connection closures ourself at least (by interpreting
2614 * incoming ELS' and unsolicited status). It just crosses my
2615 * mind that one should be able to cross-check by means of
2616 * another GID_PN straight after a port has been opened.
2617 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2618 */
2619 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2620 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2621 {
2622 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002623 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 ZFCP_LOG_INFO(
2625 "warning: insufficient length of "
2626 "PLOGI payload (%i)\n",
2627 fsf_req->qtcb->bottom.support.els1_length);
2628 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2629 "fsf_s_short_plogi:");
2630 /* skip sanity check and assume wwpn is ok */
2631 } else {
2632 if (plogi->serv_param.wwpn != port->wwpn) {
2633 ZFCP_LOG_INFO("warning: d_id of port "
2634 "0x%016Lx changed during "
2635 "open\n", port->wwpn);
2636 debug_text_event(
2637 fsf_req->adapter->erp_dbf, 0,
2638 "fsf_s_did_change:");
2639 atomic_clear_mask(
2640 ZFCP_STATUS_PORT_DID_DID,
2641 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002642 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002644 zfcp_plogi_evaluate(port, plogi);
2645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 }
2647 }
2648 break;
2649
2650 case FSF_UNKNOWN_OP_SUBTYPE:
2651 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2653 "op_subtype=0x%x)\n",
2654 zfcp_get_busid_by_port(port),
2655 fsf_req->qtcb->bottom.support.operation_subtype);
2656 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2657 break;
2658
2659 default:
2660 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2661 "(debug info 0x%x)\n",
2662 header->fsf_status);
2663 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2664 debug_exception(fsf_req->adapter->erp_dbf, 0,
2665 &header->fsf_status, sizeof (u32));
2666 break;
2667 }
2668
2669 skip_fsfstatus:
2670 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2671 return retval;
2672}
2673
2674/*
2675 * function: zfcp_fsf_close_port
2676 *
2677 * purpose: submit FSF command "close port"
2678 *
2679 * returns: address of initiated FSF request
2680 * NULL - request could not be initiated
2681 */
2682int
2683zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2684{
2685 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002686 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 unsigned long lock_flags;
2688 int retval = 0;
2689
2690 /* setup new FSF request */
2691 retval = zfcp_fsf_req_create(erp_action->adapter,
2692 FSF_QTCB_CLOSE_PORT,
2693 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2694 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002695 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 if (retval < 0) {
2697 ZFCP_LOG_INFO("error: Could not create a close port request "
2698 "for port 0x%016Lx on adapter %s.\n",
2699 erp_action->port->wwpn,
2700 zfcp_get_busid_by_adapter(erp_action->adapter));
2701 goto out;
2702 }
2703
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002704 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2706 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2707
2708 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002709 fsf_req->data = (unsigned long) erp_action->port;
2710 fsf_req->erp_action = erp_action;
2711 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2712 fsf_req->erp_action = erp_action;
2713 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002715 zfcp_erp_start_timer(fsf_req);
2716 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (retval) {
2718 ZFCP_LOG_INFO("error: Could not send a close port request for "
2719 "port 0x%016Lx on adapter %s.\n",
2720 erp_action->port->wwpn,
2721 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002722 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 erp_action->fsf_req = NULL;
2724 goto out;
2725 }
2726
2727 ZFCP_LOG_TRACE("close port request initiated "
2728 "(adapter %s, port 0x%016Lx)\n",
2729 zfcp_get_busid_by_adapter(erp_action->adapter),
2730 erp_action->port->wwpn);
2731 out:
2732 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2733 lock_flags);
2734 return retval;
2735}
2736
2737/*
2738 * function: zfcp_fsf_close_port_handler
2739 *
2740 * purpose: is called for finished Close Port FSF command
2741 *
2742 * returns:
2743 */
2744static int
2745zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2746{
2747 int retval = -EINVAL;
2748 struct zfcp_port *port;
2749
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002750 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
2752 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2753 /* don't change port status in our bookkeeping */
2754 goto skip_fsfstatus;
2755 }
2756
2757 /* evaluate FSF status in QTCB */
2758 switch (fsf_req->qtcb->header.fsf_status) {
2759
2760 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2762 "0x%016Lx on adapter %s invalid. This may happen "
2763 "occasionally.\n", port->handle,
2764 port->wwpn, zfcp_get_busid_by_port(port));
2765 ZFCP_LOG_DEBUG("status qualifier:\n");
2766 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2767 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2768 sizeof (union fsf_status_qual));
2769 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2770 "fsf_s_phand_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01002771 zfcp_erp_adapter_reopen(port->adapter, 0, 107, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2773 break;
2774
2775 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 /* Note: FSF has actually closed the port in this case.
2777 * The status code is just daft. Fingers crossed for a change
2778 */
2779 retval = 0;
2780 break;
2781
2782 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2784 "port handle 0x%x\n", port->wwpn,
2785 zfcp_get_busid_by_port(port), port->handle);
Martin Peschke698ec0162008-03-27 14:22:02 +01002786 zfcp_erp_modify_port_status(port, 33, (u64)fsf_req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 ZFCP_STATUS_COMMON_OPEN,
2788 ZFCP_CLEAR);
2789 retval = 0;
2790 break;
2791
2792 default:
2793 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2794 "(debug info 0x%x)\n",
2795 fsf_req->qtcb->header.fsf_status);
2796 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2797 debug_exception(fsf_req->adapter->erp_dbf, 0,
2798 &fsf_req->qtcb->header.fsf_status,
2799 sizeof (u32));
2800 break;
2801 }
2802
2803 skip_fsfstatus:
2804 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2805 return retval;
2806}
2807
2808/*
2809 * function: zfcp_fsf_close_physical_port
2810 *
2811 * purpose: submit FSF command "close physical port"
2812 *
2813 * returns: address of initiated FSF request
2814 * NULL - request could not be initiated
2815 */
2816int
2817zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2818{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002820 struct zfcp_fsf_req *fsf_req;
2821 unsigned long lock_flags;
2822 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
2824 /* setup new FSF request */
2825 retval = zfcp_fsf_req_create(erp_action->adapter,
2826 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2827 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2828 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002829 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 if (retval < 0) {
2831 ZFCP_LOG_INFO("error: Could not create close physical port "
2832 "request (adapter %s, port 0x%016Lx)\n",
2833 zfcp_get_busid_by_adapter(erp_action->adapter),
2834 erp_action->port->wwpn);
2835
2836 goto out;
2837 }
2838
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002839 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2841 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2842
2843 /* mark port as being closed */
2844 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2845 &erp_action->port->status);
2846 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002847 fsf_req->data = (unsigned long) erp_action->port;
2848 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2849 fsf_req->erp_action = erp_action;
2850 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002852 zfcp_erp_start_timer(fsf_req);
2853 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 if (retval) {
2855 ZFCP_LOG_INFO("error: Could not send close physical port "
2856 "request (adapter %s, port 0x%016Lx)\n",
2857 zfcp_get_busid_by_adapter(erp_action->adapter),
2858 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002859 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 erp_action->fsf_req = NULL;
2861 goto out;
2862 }
2863
2864 ZFCP_LOG_TRACE("close physical port request initiated "
2865 "(adapter %s, port 0x%016Lx)\n",
2866 zfcp_get_busid_by_adapter(erp_action->adapter),
2867 erp_action->port->wwpn);
2868 out:
2869 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2870 lock_flags);
2871 return retval;
2872}
2873
2874/*
2875 * function: zfcp_fsf_close_physical_port_handler
2876 *
2877 * purpose: is called for finished Close Physical Port FSF command
2878 *
2879 * returns:
2880 */
2881static int
2882zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2883{
2884 int retval = -EINVAL;
2885 struct zfcp_port *port;
2886 struct zfcp_unit *unit;
2887 struct fsf_qtcb_header *header;
2888 u16 subtable, rule, counter;
2889
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002890 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 header = &fsf_req->qtcb->header;
2892
2893 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2894 /* don't change port status in our bookkeeping */
2895 goto skip_fsfstatus;
2896 }
2897
2898 /* evaluate FSF status in QTCB */
2899 switch (header->fsf_status) {
2900
2901 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2903 "(adapter %s, port 0x%016Lx). "
2904 "This may happen occasionally.\n",
2905 port->handle,
2906 zfcp_get_busid_by_port(port),
2907 port->wwpn);
2908 ZFCP_LOG_DEBUG("status qualifier:\n");
2909 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2910 (char *) &header->fsf_status_qual,
2911 sizeof (union fsf_status_qual));
2912 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2913 "fsf_s_phand_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01002914 zfcp_erp_adapter_reopen(port->adapter, 0, 108, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2916 break;
2917
2918 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 ZFCP_LOG_NORMAL("Access denied, cannot close "
2920 "physical port 0x%016Lx on adapter %s\n",
2921 port->wwpn, zfcp_get_busid_by_port(port));
2922 for (counter = 0; counter < 2; counter++) {
2923 subtable = header->fsf_status_qual.halfword[counter * 2];
2924 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2925 switch (subtable) {
2926 case FSF_SQ_CFDC_SUBTABLE_OS:
2927 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2928 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2929 case FSF_SQ_CFDC_SUBTABLE_LUN:
2930 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2931 zfcp_act_subtable_type[subtable], rule);
2932 break;
2933 }
2934 }
2935 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01002936 zfcp_erp_port_access_denied(port, 58, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2938 break;
2939
2940 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2942 "%s needs to be reopened but it was attempted "
2943 "to close it physically.\n",
2944 port->wwpn,
2945 zfcp_get_busid_by_port(port));
2946 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01002947 zfcp_erp_port_boxed(port, 50, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2949 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01002950
2951 /* can't use generic zfcp_erp_modify_port_status because
2952 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2953 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2954 list_for_each_entry(unit, &port->unit_list_head, list)
2955 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2956 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 break;
2958
2959 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 switch (header->fsf_status_qual.word[0]) {
2961 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2963 "fsf_sq_ltest");
2964 /* This will now be escalated by ERP */
2965 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2966 break;
2967 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 /* ERP strategy will escalate */
2969 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2970 "fsf_sq_ulp");
2971 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2972 break;
2973 default:
2974 ZFCP_LOG_NORMAL
2975 ("bug: Wrong status qualifier 0x%x arrived.\n",
2976 header->fsf_status_qual.word[0]);
2977 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2978 "fsf_sq_inval:");
2979 debug_exception(
2980 fsf_req->adapter->erp_dbf, 0,
2981 &header->fsf_status_qual.word[0], sizeof (u32));
2982 break;
2983 }
2984 break;
2985
2986 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2988 "physically closed, port handle 0x%x\n",
2989 port->wwpn,
2990 zfcp_get_busid_by_port(port), port->handle);
2991 /* can't use generic zfcp_erp_modify_port_status because
2992 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2993 */
2994 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2995 list_for_each_entry(unit, &port->unit_list_head, list)
2996 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2997 retval = 0;
2998 break;
2999
3000 default:
3001 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3002 "(debug info 0x%x)\n",
3003 header->fsf_status);
3004 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3005 debug_exception(fsf_req->adapter->erp_dbf, 0,
3006 &header->fsf_status, sizeof (u32));
3007 break;
3008 }
3009
3010 skip_fsfstatus:
3011 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
3012 return retval;
3013}
3014
3015/*
3016 * function: zfcp_fsf_open_unit
3017 *
3018 * purpose:
3019 *
3020 * returns:
3021 *
3022 * assumptions: This routine does not check whether the associated
3023 * remote port has already been opened. This should be
3024 * done by calling routines. Otherwise some status
3025 * may be presented by FSF
3026 */
3027int
3028zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3029{
3030 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003031 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 unsigned long lock_flags;
3033 int retval = 0;
3034
3035 /* setup new FSF request */
3036 retval = zfcp_fsf_req_create(erp_action->adapter,
3037 FSF_QTCB_OPEN_LUN,
3038 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3039 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003040 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 if (retval < 0) {
3042 ZFCP_LOG_INFO("error: Could not create open unit request for "
3043 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3044 erp_action->unit->fcp_lun,
3045 erp_action->unit->port->wwpn,
3046 zfcp_get_busid_by_adapter(erp_action->adapter));
3047 goto out;
3048 }
3049
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003050 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3052 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3053
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003054 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3055 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003056 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003057 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02003058 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003060 fsf_req->data = (unsigned long) erp_action->unit;
3061 fsf_req->erp_action = erp_action;
3062 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003064 zfcp_erp_start_timer(fsf_req);
3065 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 if (retval) {
3067 ZFCP_LOG_INFO("error: Could not send an open unit request "
3068 "on the adapter %s, port 0x%016Lx for "
3069 "unit 0x%016Lx\n",
3070 zfcp_get_busid_by_adapter(erp_action->adapter),
3071 erp_action->port->wwpn,
3072 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003073 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 erp_action->fsf_req = NULL;
3075 goto out;
3076 }
3077
3078 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3079 "port 0x%016Lx, unit 0x%016Lx)\n",
3080 zfcp_get_busid_by_adapter(erp_action->adapter),
3081 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3082 out:
3083 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3084 lock_flags);
3085 return retval;
3086}
3087
3088/*
3089 * function: zfcp_fsf_open_unit_handler
3090 *
3091 * purpose: is called for finished Open LUN command
3092 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003093 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 */
3095static int
3096zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3097{
3098 int retval = -EINVAL;
3099 struct zfcp_adapter *adapter;
3100 struct zfcp_unit *unit;
3101 struct fsf_qtcb_header *header;
3102 struct fsf_qtcb_bottom_support *bottom;
3103 struct fsf_queue_designator *queue_designator;
3104 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003105 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003107 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108
3109 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3110 /* don't change unit status in our bookkeeping */
3111 goto skip_fsfstatus;
3112 }
3113
3114 adapter = fsf_req->adapter;
3115 header = &fsf_req->qtcb->header;
3116 bottom = &fsf_req->qtcb->bottom.support;
3117 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3118
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02003120 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 ZFCP_STATUS_UNIT_SHARED |
3122 ZFCP_STATUS_UNIT_READONLY,
3123 &unit->status);
3124
3125 /* evaluate FSF status in QTCB */
3126 switch (header->fsf_status) {
3127
3128 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3130 "for port 0x%016Lx on adapter %s invalid "
3131 "This may happen occasionally\n",
3132 unit->port->handle,
3133 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3134 ZFCP_LOG_DEBUG("status qualifier:\n");
3135 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3136 (char *) &header->fsf_status_qual,
3137 sizeof (union fsf_status_qual));
3138 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003139 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109,
3140 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3142 break;
3143
3144 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3146 "remote port 0x%016Lx on adapter %s twice.\n",
3147 unit->fcp_lun,
3148 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3149 debug_text_exception(adapter->erp_dbf, 0,
3150 "fsf_s_uopen");
3151 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3152 break;
3153
3154 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3156 "remote port 0x%016Lx on adapter %s\n",
3157 unit->fcp_lun, unit->port->wwpn,
3158 zfcp_get_busid_by_unit(unit));
3159 for (counter = 0; counter < 2; counter++) {
3160 subtable = header->fsf_status_qual.halfword[counter * 2];
3161 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3162 switch (subtable) {
3163 case FSF_SQ_CFDC_SUBTABLE_OS:
3164 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3165 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3166 case FSF_SQ_CFDC_SUBTABLE_LUN:
3167 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3168 zfcp_act_subtable_type[subtable], rule);
3169 break;
3170 }
3171 }
3172 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01003173 zfcp_erp_unit_access_denied(unit, 59, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3175 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3176 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3177 break;
3178
3179 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3181 "needs to be reopened\n",
3182 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3183 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003184 zfcp_erp_port_boxed(unit->port, 51, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3186 ZFCP_STATUS_FSFREQ_RETRY;
3187 break;
3188
3189 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 if (header->fsf_status_qual.word[0] != 0) {
3191 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3192 "with WWPN 0x%Lx "
3193 "connected to the adapter %s "
3194 "is already in use in LPAR%d, CSS%d\n",
3195 unit->fcp_lun,
3196 unit->port->wwpn,
3197 zfcp_get_busid_by_unit(unit),
3198 queue_designator->hla,
3199 queue_designator->cssid);
3200 } else {
3201 subtable = header->fsf_status_qual.halfword[4];
3202 rule = header->fsf_status_qual.halfword[5];
3203 switch (subtable) {
3204 case FSF_SQ_CFDC_SUBTABLE_OS:
3205 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3206 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3207 case FSF_SQ_CFDC_SUBTABLE_LUN:
3208 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3209 "remote port with WWPN 0x%Lx "
3210 "connected to the adapter %s "
3211 "is denied (%s rule %d)\n",
3212 unit->fcp_lun,
3213 unit->port->wwpn,
3214 zfcp_get_busid_by_unit(unit),
3215 zfcp_act_subtable_type[subtable],
3216 rule);
3217 break;
3218 }
3219 }
3220 ZFCP_LOG_DEBUG("status qualifier:\n");
3221 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3222 (char *) &header->fsf_status_qual,
3223 sizeof (union fsf_status_qual));
3224 debug_text_event(adapter->erp_dbf, 2,
3225 "fsf_s_l_sh_vio");
Martin Peschke698ec0162008-03-27 14:22:02 +01003226 zfcp_erp_unit_access_denied(unit, 60, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3228 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3229 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3230 break;
3231
3232 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3234 "There is no handle (temporary port identifier) "
3235 "available for unit 0x%016Lx on port 0x%016Lx "
3236 "on adapter %s\n",
3237 unit->fcp_lun,
3238 unit->port->wwpn,
3239 zfcp_get_busid_by_unit(unit));
3240 debug_text_event(adapter->erp_dbf, 1,
3241 "fsf_s_max_units");
Martin Peschke698ec0162008-03-27 14:22:02 +01003242 zfcp_erp_unit_failed(unit, 34, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3244 break;
3245
3246 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 switch (header->fsf_status_qual.word[0]) {
3248 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 /* Re-establish link to port */
3250 debug_text_event(adapter->erp_dbf, 1,
3251 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003252 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3254 break;
3255 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 /* ERP strategy will escalate */
3257 debug_text_event(adapter->erp_dbf, 1,
3258 "fsf_sq_ulp");
3259 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3260 break;
3261 default:
3262 ZFCP_LOG_NORMAL
3263 ("bug: Wrong status qualifier 0x%x arrived.\n",
3264 header->fsf_status_qual.word[0]);
3265 debug_text_event(adapter->erp_dbf, 0,
3266 "fsf_sq_inval:");
3267 debug_exception(adapter->erp_dbf, 0,
3268 &header->fsf_status_qual.word[0],
3269 sizeof (u32));
3270 }
3271 break;
3272
3273 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 ZFCP_LOG_NORMAL(
3275 "Invalid option 0x%x has been specified "
3276 "in QTCB bottom sent to the adapter %s\n",
3277 bottom->option,
3278 zfcp_get_busid_by_adapter(adapter));
3279 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3280 retval = -EINVAL;
3281 break;
3282
3283 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 /* save LUN handle assigned by FSF */
3285 unit->handle = header->lun_handle;
3286 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3287 "adapter %s opened, port handle 0x%x\n",
3288 unit->fcp_lun,
3289 unit->port->wwpn,
3290 zfcp_get_busid_by_unit(unit),
3291 unit->handle);
3292 /* mark unit as open */
3293 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003294
3295 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3296 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3297 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3298 exclusive = (bottom->lun_access_info &
3299 FSF_UNIT_ACCESS_EXCLUSIVE);
3300 readwrite = (bottom->lun_access_info &
3301 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3302
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 if (!exclusive)
3304 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3305 &unit->status);
3306
3307 if (!readwrite) {
3308 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3309 &unit->status);
3310 ZFCP_LOG_NORMAL("read-only access for unit "
3311 "(adapter %s, wwpn=0x%016Lx, "
3312 "fcp_lun=0x%016Lx)\n",
3313 zfcp_get_busid_by_unit(unit),
3314 unit->port->wwpn,
3315 unit->fcp_lun);
3316 }
3317
3318 if (exclusive && !readwrite) {
3319 ZFCP_LOG_NORMAL("exclusive access of read-only "
3320 "unit not supported\n");
Martin Peschke698ec0162008-03-27 14:22:02 +01003321 zfcp_erp_unit_failed(unit, 35, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke9467a9b2008-03-27 14:22:03 +01003323 zfcp_erp_unit_shutdown(unit, 0, 80,
3324 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 } else if (!exclusive && readwrite) {
3326 ZFCP_LOG_NORMAL("shared access of read-write "
3327 "unit not supported\n");
Martin Peschke698ec0162008-03-27 14:22:02 +01003328 zfcp_erp_unit_failed(unit, 36, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke9467a9b2008-03-27 14:22:03 +01003330 zfcp_erp_unit_shutdown(unit, 0, 81,
3331 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 }
3333 }
3334
3335 retval = 0;
3336 break;
3337
3338 default:
3339 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3340 "(debug info 0x%x)\n",
3341 header->fsf_status);
3342 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3343 debug_exception(adapter->erp_dbf, 0,
3344 &header->fsf_status, sizeof (u32));
3345 break;
3346 }
3347
3348 skip_fsfstatus:
3349 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3350 return retval;
3351}
3352
3353/*
3354 * function: zfcp_fsf_close_unit
3355 *
3356 * purpose:
3357 *
3358 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003359 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 *
3361 * assumptions: This routine does not check whether the associated
3362 * remote port/lun has already been opened. This should be
3363 * done by calling routines. Otherwise some status
3364 * may be presented by FSF
3365 */
3366int
3367zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3368{
3369 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003370 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 unsigned long lock_flags;
3372 int retval = 0;
3373
3374 /* setup new FSF request */
3375 retval = zfcp_fsf_req_create(erp_action->adapter,
3376 FSF_QTCB_CLOSE_LUN,
3377 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3378 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003379 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 if (retval < 0) {
3381 ZFCP_LOG_INFO("error: Could not create close unit request for "
3382 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3383 erp_action->unit->fcp_lun,
3384 erp_action->port->wwpn,
3385 zfcp_get_busid_by_adapter(erp_action->adapter));
3386 goto out;
3387 }
3388
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003389 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3391 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3392
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003393 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3394 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003396 fsf_req->data = (unsigned long) erp_action->unit;
3397 fsf_req->erp_action = erp_action;
3398 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003400 zfcp_erp_start_timer(fsf_req);
3401 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 if (retval) {
3403 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3404 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3405 erp_action->unit->fcp_lun,
3406 erp_action->port->wwpn,
3407 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003408 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 erp_action->fsf_req = NULL;
3410 goto out;
3411 }
3412
3413 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3414 "port 0x%016Lx, unit 0x%016Lx)\n",
3415 zfcp_get_busid_by_adapter(erp_action->adapter),
3416 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3417 out:
3418 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3419 lock_flags);
3420 return retval;
3421}
3422
3423/*
3424 * function: zfcp_fsf_close_unit_handler
3425 *
3426 * purpose: is called for finished Close LUN FSF command
3427 *
3428 * returns:
3429 */
3430static int
3431zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3432{
3433 int retval = -EINVAL;
3434 struct zfcp_unit *unit;
3435
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003436 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
3438 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3439 /* don't change unit status in our bookkeeping */
3440 goto skip_fsfstatus;
3441 }
3442
3443 /* evaluate FSF status in QTCB */
3444 switch (fsf_req->qtcb->header.fsf_status) {
3445
3446 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3448 "0x%016Lx on adapter %s invalid. This may "
3449 "happen in rare circumstances\n",
3450 unit->port->handle,
3451 unit->port->wwpn,
3452 zfcp_get_busid_by_unit(unit));
3453 ZFCP_LOG_DEBUG("status qualifier:\n");
3454 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3455 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3456 sizeof (union fsf_status_qual));
3457 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3458 "fsf_s_phand_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003459 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110,
3460 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3462 break;
3463
3464 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3466 "0x%016Lx on port 0x%016Lx on adapter %s is "
3467 "invalid. This may happen occasionally.\n",
3468 unit->handle,
3469 unit->fcp_lun,
3470 unit->port->wwpn,
3471 zfcp_get_busid_by_unit(unit));
3472 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3473 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3474 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3475 sizeof (union fsf_status_qual));
3476 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3477 "fsf_s_lhand_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003478 zfcp_erp_port_reopen(unit->port, 0, 111, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3480 break;
3481
3482 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3484 "needs to be reopened\n",
3485 unit->port->wwpn,
3486 zfcp_get_busid_by_unit(unit));
3487 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003488 zfcp_erp_port_boxed(unit->port, 52, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3490 ZFCP_STATUS_FSFREQ_RETRY;
3491 break;
3492
3493 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3495 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 /* re-establish link to port */
3497 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3498 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003499 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3501 break;
3502 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 /* ERP strategy will escalate */
3504 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3505 "fsf_sq_ulp");
3506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3507 break;
3508 default:
3509 ZFCP_LOG_NORMAL
3510 ("bug: Wrong status qualifier 0x%x arrived.\n",
3511 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3512 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3513 "fsf_sq_inval:");
3514 debug_exception(
3515 fsf_req->adapter->erp_dbf, 0,
3516 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3517 sizeof (u32));
3518 break;
3519 }
3520 break;
3521
3522 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3524 "closed, port handle 0x%x\n",
3525 unit->fcp_lun,
3526 unit->port->wwpn,
3527 zfcp_get_busid_by_unit(unit),
3528 unit->handle);
3529 /* mark unit as closed */
3530 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3531 retval = 0;
3532 break;
3533
3534 default:
3535 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3536 "(debug info 0x%x)\n",
3537 fsf_req->qtcb->header.fsf_status);
3538 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3539 debug_exception(fsf_req->adapter->erp_dbf, 0,
3540 &fsf_req->qtcb->header.fsf_status,
3541 sizeof (u32));
3542 break;
3543 }
3544
3545 skip_fsfstatus:
3546 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3547 return retval;
3548}
3549
3550/**
3551 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3552 * @adapter: adapter where scsi command is issued
3553 * @unit: unit where command is sent to
3554 * @scsi_cmnd: scsi command to be sent
3555 * @timer: timer to be started when request is initiated
3556 * @req_flags: flags for fsf_request
3557 */
3558int
3559zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3560 struct zfcp_unit *unit,
3561 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003562 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563{
3564 struct zfcp_fsf_req *fsf_req = NULL;
3565 struct fcp_cmnd_iu *fcp_cmnd_iu;
3566 unsigned int sbtype;
3567 unsigned long lock_flags;
3568 int real_bytes = 0;
3569 int retval = 0;
3570 int mask;
3571
3572 /* setup new FSF request */
3573 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3574 adapter->pool.fsf_req_scsi,
3575 &lock_flags, &fsf_req);
3576 if (unlikely(retval < 0)) {
3577 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3578 "for unit 0x%016Lx on port 0x%016Lx on "
3579 "adapter %s\n",
3580 unit->fcp_lun,
3581 unit->port->wwpn,
3582 zfcp_get_busid_by_adapter(adapter));
3583 goto failed_req_create;
3584 }
3585
Christof Schmittba172422007-12-20 12:30:26 +01003586 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3587 &unit->status))) {
3588 retval = -EBUSY;
3589 goto unit_blocked;
3590 }
3591
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003592 zfcp_unit_get(unit);
3593 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003595 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003596 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003597
3598 /* associate SCSI command with FSF request */
3599 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600
3601 /* set handles of unit and its parent port in QTCB */
3602 fsf_req->qtcb->header.lun_handle = unit->handle;
3603 fsf_req->qtcb->header.port_handle = unit->port->handle;
3604
3605 /* FSF does not define the structure of the FCP_CMND IU */
3606 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3607 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3608
3609 /*
3610 * set depending on data direction:
3611 * data direction bits in SBALE (SB Type)
3612 * data direction bits in QTCB
3613 * data direction bits in FCP_CMND IU
3614 */
3615 switch (scsi_cmnd->sc_data_direction) {
3616 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3618 /*
3619 * FIXME(qdio):
3620 * what is the correct type for commands
3621 * without 'real' data buffers?
3622 */
3623 sbtype = SBAL_FLAGS0_TYPE_READ;
3624 break;
3625 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3627 sbtype = SBAL_FLAGS0_TYPE_READ;
3628 fcp_cmnd_iu->rddata = 1;
3629 break;
3630 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3632 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3633 fcp_cmnd_iu->wddata = 1;
3634 break;
3635 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 default:
3637 /*
3638 * dummy, catch this condition earlier
3639 * in zfcp_scsi_queuecommand
3640 */
3641 goto failed_scsi_cmnd;
3642 }
3643
3644 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003645 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646
3647 /* set FCP_LUN in FCP_CMND IU in QTCB */
3648 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3649
3650 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3651
3652 /* set task attributes in FCP_CMND IU in QTCB */
3653 if (likely((scsi_cmnd->device->simple_tags) ||
3654 (atomic_test_mask(mask, &unit->status))))
3655 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3656 else
3657 fcp_cmnd_iu->task_attribute = UNTAGGED;
3658
3659 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3660 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3661 fcp_cmnd_iu->add_fcp_cdb_length
3662 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3663 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3664 "additional FCP_CDB length is 0x%x "
3665 "(shifted right 2 bits)\n",
3666 scsi_cmnd->cmd_len,
3667 fcp_cmnd_iu->add_fcp_cdb_length);
3668 }
3669 /*
3670 * copy SCSI CDB (including additional length, if any) to
3671 * FCP_CDB in FCP_CMND IU in QTCB
3672 */
3673 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3674
3675 /* FCP CMND IU length in QTCB */
3676 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3677 sizeof (struct fcp_cmnd_iu) +
3678 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3679
3680 /* generate SBALEs from data buffer */
3681 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3682 if (unlikely(real_bytes < 0)) {
3683 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3684 ZFCP_LOG_DEBUG(
3685 "Data did not fit into available buffer(s), "
3686 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003687 retval = -EIO;
3688 } else {
3689 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3690 "required. Shutting down unit "
3691 "(adapter %s, port 0x%016Lx, "
3692 "unit 0x%016Lx)\n",
3693 zfcp_get_busid_by_unit(unit),
3694 unit->port->wwpn,
3695 unit->fcp_lun);
Martin Peschke9467a9b2008-03-27 14:22:03 +01003696 zfcp_erp_unit_shutdown(unit, 0, 131, (u64)fsf_req);
Christof Schmitt2282f652007-08-28 09:30:22 +02003697 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 }
3699 goto no_fit;
3700 }
3701
3702 /* set length of FCP data length in FCP_CMND IU in QTCB */
3703 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3704
3705 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3706 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3707 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3708
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003709 if (use_timer)
3710 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3711
3712 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 if (unlikely(retval < 0)) {
3714 ZFCP_LOG_INFO("error: Could not send FCP command request "
3715 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3716 zfcp_get_busid_by_adapter(adapter),
3717 unit->port->wwpn,
3718 unit->fcp_lun);
3719 goto send_failed;
3720 }
3721
3722 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3723 "port 0x%016Lx, unit 0x%016Lx)\n",
3724 zfcp_get_busid_by_adapter(adapter),
3725 unit->port->wwpn,
3726 unit->fcp_lun);
3727 goto success;
3728
3729 send_failed:
3730 no_fit:
3731 failed_scsi_cmnd:
Christof Schmittba172422007-12-20 12:30:26 +01003732 unit_blocked:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003733 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 zfcp_fsf_req_free(fsf_req);
3735 fsf_req = NULL;
3736 scsi_cmnd->host_scribble = NULL;
3737 success:
3738 failed_req_create:
3739 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3740 return retval;
3741}
3742
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743struct zfcp_fsf_req *
3744zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3745 struct zfcp_unit *unit,
3746 u8 tm_flags, int req_flags)
3747{
3748 struct zfcp_fsf_req *fsf_req = NULL;
3749 int retval = 0;
3750 struct fcp_cmnd_iu *fcp_cmnd_iu;
3751 unsigned long lock_flags;
3752 volatile struct qdio_buffer_element *sbale;
3753
3754 /* setup new FSF request */
3755 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3756 adapter->pool.fsf_req_scsi,
3757 &lock_flags, &fsf_req);
3758 if (retval < 0) {
3759 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3760 "management) request for adapter %s, port "
3761 " 0x%016Lx, unit 0x%016Lx.\n",
3762 zfcp_get_busid_by_adapter(adapter),
3763 unit->port->wwpn, unit->fcp_lun);
3764 goto out;
3765 }
3766
Christof Schmittfdf23452007-12-20 12:30:27 +01003767 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3768 &unit->status)))
3769 goto unit_blocked;
3770
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 /*
3772 * Used to decide on proper handler in the return path,
3773 * could be either zfcp_fsf_send_fcp_command_task_handler or
3774 * zfcp_fsf_send_fcp_command_task_management_handler */
3775
3776 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3777
3778 /*
3779 * hold a pointer to the unit being target of this
3780 * task management request
3781 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003782 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783
3784 /* set FSF related fields in QTCB */
3785 fsf_req->qtcb->header.lun_handle = unit->handle;
3786 fsf_req->qtcb->header.port_handle = unit->port->handle;
3787 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003788 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3790 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3791
3792 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3793 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3794 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3795
3796 /* set FCP related fields in FCP_CMND IU in QTCB */
3797 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3798 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3799 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3800 fcp_cmnd_iu->task_management_flags = tm_flags;
3801
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003802 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3803 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmittfdf23452007-12-20 12:30:27 +01003804 if (!retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
Christof Schmittfdf23452007-12-20 12:30:27 +01003807 unit_blocked:
3808 zfcp_fsf_req_free(fsf_req);
3809 fsf_req = NULL;
3810
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 out:
3812 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3813 return fsf_req;
3814}
3815
3816/*
3817 * function: zfcp_fsf_send_fcp_command_handler
3818 *
3819 * purpose: is called for finished Send FCP Command
3820 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003821 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 */
3823static int
3824zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3825{
3826 int retval = -EINVAL;
3827 struct zfcp_unit *unit;
3828 struct fsf_qtcb_header *header;
3829 u16 subtable, rule, counter;
3830
3831 header = &fsf_req->qtcb->header;
3832
3833 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003834 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003836 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837
3838 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3839 /* go directly to calls of special handlers */
3840 goto skip_fsfstatus;
3841 }
3842
3843 /* evaluate FSF status in QTCB */
3844 switch (header->fsf_status) {
3845
3846 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3848 "0x%016Lx on adapter %s invalid\n",
3849 unit->port->handle,
3850 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3851 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3852 (char *) &header->fsf_status_qual,
3853 sizeof (union fsf_status_qual));
3854 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3855 "fsf_s_phand_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003856 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112,
3857 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3859 break;
3860
3861 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3863 "0x%016Lx on port 0x%016Lx on adapter %s is "
3864 "invalid. This may happen occasionally.\n",
3865 unit->handle,
3866 unit->fcp_lun,
3867 unit->port->wwpn,
3868 zfcp_get_busid_by_unit(unit));
3869 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3870 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3871 (char *) &header->fsf_status_qual,
3872 sizeof (union fsf_status_qual));
3873 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3874 "fsf_s_uhand_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003875 zfcp_erp_port_reopen(unit->port, 0, 113, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3877 break;
3878
3879 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3881 "unexpectedly. (adapter %s, port 0x%016Lx, "
3882 "unit 0x%016Lx)\n",
3883 unit->port->handle,
3884 zfcp_get_busid_by_unit(unit),
3885 unit->port->wwpn,
3886 unit->fcp_lun);
3887 ZFCP_LOG_NORMAL("status qualifier:\n");
3888 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3889 (char *) &header->fsf_status_qual,
3890 sizeof (union fsf_status_qual));
3891 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3892 "fsf_s_hand_mis");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003893 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114,
3894 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3896 break;
3897
3898 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003899 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3900 "class %d.\n",
3901 zfcp_get_busid_by_unit(unit),
3902 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 /* stop operation for this adapter */
3904 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3905 "fsf_s_class_nsup");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003906 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132,
3907 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3909 break;
3910
3911 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3913 "adapter %s does not have correct unit "
3914 "handle 0x%x\n",
3915 unit->fcp_lun,
3916 unit->port->wwpn,
3917 zfcp_get_busid_by_unit(unit),
3918 unit->handle);
3919 ZFCP_LOG_DEBUG("status qualifier:\n");
3920 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3921 (char *) &header->fsf_status_qual,
3922 sizeof (union fsf_status_qual));
3923 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3924 "fsf_s_fcp_lun_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003925 zfcp_erp_port_reopen(unit->port, 0, 115, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3927 break;
3928
3929 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3931 "unit 0x%016Lx on port 0x%016Lx on "
3932 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3933 zfcp_get_busid_by_unit(unit));
3934 for (counter = 0; counter < 2; counter++) {
3935 subtable = header->fsf_status_qual.halfword[counter * 2];
3936 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3937 switch (subtable) {
3938 case FSF_SQ_CFDC_SUBTABLE_OS:
3939 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3940 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3941 case FSF_SQ_CFDC_SUBTABLE_LUN:
3942 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3943 zfcp_act_subtable_type[subtable], rule);
3944 break;
3945 }
3946 }
3947 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
Martin Peschke698ec0162008-03-27 14:22:02 +01003948 zfcp_erp_unit_access_denied(unit, 61, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3950 break;
3951
3952 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3954 "0x%016Lx on port 0x%016Lx on adapter %s "
3955 "(debug info %d)\n",
3956 unit->fcp_lun,
3957 unit->port->wwpn,
3958 zfcp_get_busid_by_unit(unit),
3959 fsf_req->qtcb->bottom.io.data_direction);
3960 /* stop operation for this adapter */
3961 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3962 "fsf_s_dir_ind_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003963 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133,
3964 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3966 break;
3967
3968 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 ZFCP_LOG_NORMAL
3970 ("bug: An invalid control-data-block length field "
3971 "was found in a command for unit 0x%016Lx on port "
3972 "0x%016Lx on adapter %s " "(debug info %d)\n",
3973 unit->fcp_lun, unit->port->wwpn,
3974 zfcp_get_busid_by_unit(unit),
3975 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3976 /* stop operation for this adapter */
3977 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3978 "fsf_s_cmd_len_nv");
Martin Peschke9467a9b2008-03-27 14:22:03 +01003979 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134,
3980 (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3982 break;
3983
3984 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3986 "needs to be reopened\n",
3987 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3988 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01003989 zfcp_erp_port_boxed(unit->port, 53, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3991 ZFCP_STATUS_FSFREQ_RETRY;
3992 break;
3993
3994 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3996 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3997 zfcp_get_busid_by_unit(unit),
3998 unit->port->wwpn, unit->fcp_lun);
3999 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Martin Peschke698ec0162008-03-27 14:22:02 +01004000 zfcp_erp_unit_boxed(unit, 54, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
4002 | ZFCP_STATUS_FSFREQ_RETRY;
4003 break;
4004
4005 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 switch (header->fsf_status_qual.word[0]) {
4007 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 /* re-establish link to port */
4009 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4010 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02004011 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 break;
4013 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 /* FIXME(hw) need proper specs for proper action */
4015 /* let scsi stack deal with retries and escalation */
4016 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4017 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 break;
4019 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02004021 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 header->fsf_status_qual.word[0]);
4023 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4024 "fsf_sq_inval:");
4025 debug_exception(fsf_req->adapter->erp_dbf, 0,
4026 &header->fsf_status_qual.word[0],
4027 sizeof(u32));
4028 break;
4029 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02004030 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 break;
4032
4033 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 break;
4035
4036 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 break;
4038
4039 default:
4040 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4041 debug_exception(fsf_req->adapter->erp_dbf, 0,
4042 &header->fsf_status, sizeof(u32));
4043 break;
4044 }
4045
4046 skip_fsfstatus:
4047 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4048 retval =
4049 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4050 } else {
4051 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004052 fsf_req->unit = NULL;
4053 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 }
4055 return retval;
4056}
4057
4058/*
4059 * function: zfcp_fsf_send_fcp_command_task_handler
4060 *
4061 * purpose: evaluates FCP_RSP IU
4062 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004063 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 */
4065static int
4066zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4067{
4068 int retval = 0;
4069 struct scsi_cmnd *scpnt;
4070 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4071 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4072 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4073 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4074 u32 sns_len;
4075 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4076 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004077 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078
4079 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004080 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 if (unlikely(!scpnt)) {
4082 ZFCP_LOG_DEBUG
4083 ("Command with fsf_req %p is not associated to "
4084 "a scsi command anymore. Aborted?\n", fsf_req);
4085 goto out;
4086 }
4087 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4088 /* FIXME: (design) mid-layer should handle DID_ABORT like
4089 * DID_SOFT_ERROR by retrying the request for devices
4090 * that allow retries.
4091 */
4092 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4093 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4094 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4095 goto skip_fsfstatus;
4096 }
4097
4098 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4099 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4100 set_host_byte(&scpnt->result, DID_ERROR);
4101 goto skip_fsfstatus;
4102 }
4103
4104 /* set message byte of result in SCSI command */
4105 scpnt->result |= COMMAND_COMPLETE << 8;
4106
4107 /*
4108 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4109 * of result in SCSI command
4110 */
4111 scpnt->result |= fcp_rsp_iu->scsi_status;
4112 if (unlikely(fcp_rsp_iu->scsi_status)) {
4113 /* DEBUG */
4114 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4115 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4116 scpnt->cmnd, scpnt->cmd_len);
4117 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4118 fcp_rsp_iu->scsi_status);
4119 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4120 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4121 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4122 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4123 fcp_rsp_iu->fcp_sns_len);
4124 }
4125
4126 /* check FCP_RSP_INFO */
4127 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4128 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4129 switch (fcp_rsp_info[3]) {
4130 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 /* ok, continue */
4132 ZFCP_LOG_TRACE("no failure or Task Management "
4133 "Function complete\n");
4134 set_host_byte(&scpnt->result, DID_OK);
4135 break;
4136 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 /* hardware bug */
4138 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4139 "that the fibrechannel protocol data "
4140 "length differs from the burst length. "
4141 "The problem occured on unit 0x%016Lx "
4142 "on port 0x%016Lx on 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 set_host_byte(&scpnt->result, DID_ERROR);
4151 goto skip_fsfstatus;
4152 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 /* driver or hardware bug */
4154 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4155 "that the fibrechannel protocol data "
4156 "fields were incorrectly set up. "
4157 "The problem occured on the unit "
4158 "0x%016Lx on port 0x%016Lx on "
4159 "adapter %s",
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);
4167 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 goto skip_fsfstatus;
4169 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 /* hardware bug */
4171 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4172 "that conflicting values for the "
4173 "fibrechannel payload offset from the "
4174 "header were found. "
4175 "The problem occured on unit 0x%016Lx "
4176 "on port 0x%016Lx on adapter %s.\n",
4177 unit->fcp_lun,
4178 unit->port->wwpn,
4179 zfcp_get_busid_by_unit(unit));
4180 /* dump SCSI CDB as prepared by zfcp */
4181 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4182 (char *) &fsf_req->qtcb->
4183 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 set_host_byte(&scpnt->result, DID_ERROR);
4185 goto skip_fsfstatus;
4186 default:
4187 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4188 "code was detected for a command. "
4189 "The problem occured on the unit "
4190 "0x%016Lx on port 0x%016Lx on "
4191 "adapter %s (debug info 0x%x)\n",
4192 unit->fcp_lun,
4193 unit->port->wwpn,
4194 zfcp_get_busid_by_unit(unit),
4195 fcp_rsp_info[3]);
4196 /* dump SCSI CDB as prepared by zfcp */
4197 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4198 (char *) &fsf_req->qtcb->
4199 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004201 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 }
4203 }
4204
4205 /* check for sense data */
4206 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4207 sns_len = FSF_FCP_RSP_SIZE -
4208 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4209 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4210 sns_len);
4211 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4212 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4213 SCSI_SENSE_BUFFERSIZE);
4214 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4215 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4216 scpnt->result);
4217 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4218 (void *) &scpnt->cmnd, scpnt->cmd_len);
4219
4220 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4221 fcp_rsp_iu->fcp_sns_len);
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004222 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4224 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004225 (void *)scpnt->sense_buffer, sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 }
4227
4228 /* check for overrun */
4229 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4230 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4231 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4232 "The response data length is "
4233 "%d, the original length was %d.\n",
4234 unit->fcp_lun,
4235 unit->port->wwpn,
4236 zfcp_get_busid_by_unit(unit),
4237 fcp_rsp_iu->fcp_resid,
4238 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4239 }
4240
4241 /* check for underrun */
4242 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4243 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4244 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4245 "The response data length is "
4246 "%d, the original length was %d.\n",
4247 unit->fcp_lun,
4248 unit->port->wwpn,
4249 zfcp_get_busid_by_unit(unit),
4250 fcp_rsp_iu->fcp_resid,
4251 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4252
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004253 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4254 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4255 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004256 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 }
4258
4259 skip_fsfstatus:
4260 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4261
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004262 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004263 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004264 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004265 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004266 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004267 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268
4269 /* cleanup pointer (need this especially for abort) */
4270 scpnt->host_scribble = NULL;
4271
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 (scpnt->scsi_done) (scpnt);
4274
4275 /*
4276 * We must hold this lock until scsi_done has been called.
4277 * Otherwise we may call scsi_done after abort regarding this
4278 * command has completed.
4279 * Note: scsi_done must not block!
4280 */
4281 out:
4282 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4283 return retval;
4284}
4285
4286/*
4287 * function: zfcp_fsf_send_fcp_command_task_management_handler
4288 *
4289 * purpose: evaluates FCP_RSP IU
4290 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004291 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 */
4293static int
4294zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4295{
4296 int retval = 0;
4297 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4298 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4299 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004300 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4303 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4304 goto skip_fsfstatus;
4305 }
4306
4307 /* check FCP_RSP_INFO */
4308 switch (fcp_rsp_info[3]) {
4309 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 /* ok, continue */
4311 ZFCP_LOG_DEBUG("no failure or Task Management "
4312 "Function complete\n");
4313 break;
4314 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4316 "is not supported on the target device "
4317 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4318 unit->fcp_lun,
4319 unit->port->wwpn,
4320 zfcp_get_busid_by_unit(unit));
4321 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4322 break;
4323 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4325 "failed to complete successfully. "
4326 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4327 unit->fcp_lun,
4328 unit->port->wwpn,
4329 zfcp_get_busid_by_unit(unit));
4330 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4331 break;
4332 default:
4333 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4334 "code was detected for a command. "
4335 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4336 "(debug info 0x%x)\n",
4337 unit->fcp_lun,
4338 unit->port->wwpn,
4339 zfcp_get_busid_by_unit(unit),
4340 fcp_rsp_info[3]);
4341 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4342 }
4343
4344 skip_fsfstatus:
4345 return retval;
4346}
4347
4348
4349/*
4350 * function: zfcp_fsf_control_file
4351 *
4352 * purpose: Initiator of the control file upload/download FSF requests
4353 *
4354 * returns: 0 - FSF request is successfuly created and queued
4355 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4356 * -EINVAL - Invalid direction specified
4357 * -ENOMEM - Insufficient memory
4358 * -EPERM - Cannot create FSF request or place it in QDIO queue
4359 */
4360int
4361zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4362 struct zfcp_fsf_req **fsf_req_ptr,
4363 u32 fsf_command,
4364 u32 option,
4365 struct zfcp_sg_list *sg_list)
4366{
4367 struct zfcp_fsf_req *fsf_req;
4368 struct fsf_qtcb_bottom_support *bottom;
4369 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 unsigned long lock_flags;
4371 int req_flags = 0;
4372 int direction;
4373 int retval = 0;
4374
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004375 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4377 zfcp_get_busid_by_adapter(adapter));
4378 retval = -EOPNOTSUPP;
4379 goto out;
4380 }
4381
4382 switch (fsf_command) {
4383
4384 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4385 direction = SBAL_FLAGS0_TYPE_WRITE;
4386 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4387 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4388 req_flags = ZFCP_WAIT_FOR_SBAL;
4389 break;
4390
4391 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4392 direction = SBAL_FLAGS0_TYPE_READ;
4393 break;
4394
4395 default:
4396 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4397 retval = -EINVAL;
4398 goto out;
4399 }
4400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4402 NULL, &lock_flags, &fsf_req);
4403 if (retval < 0) {
4404 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4405 "adapter %s\n",
4406 zfcp_get_busid_by_adapter(adapter));
4407 retval = -EPERM;
4408 goto unlock_queue_lock;
4409 }
4410
4411 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4412 sbale[0].flags |= direction;
4413
4414 bottom = &fsf_req->qtcb->bottom.support;
4415 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4416 bottom->option = option;
4417
4418 if (sg_list->count > 0) {
4419 int bytes;
4420
4421 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4422 sg_list->sg, sg_list->count,
4423 ZFCP_MAX_SBALS_PER_REQ);
4424 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4425 ZFCP_LOG_INFO(
4426 "error: Could not create sufficient number of "
4427 "SBALS for an FSF request to the adapter %s\n",
4428 zfcp_get_busid_by_adapter(adapter));
4429 retval = -ENOMEM;
4430 goto free_fsf_req;
4431 }
4432 } else
4433 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4434
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004435 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4436 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 if (retval < 0) {
4438 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4439 "(adapter %s)\n",
4440 zfcp_get_busid_by_adapter(adapter));
4441 retval = -EPERM;
4442 goto free_fsf_req;
4443 }
4444 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4445
4446 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4447 "adapter %s\n",
4448 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4449 "download" : "upload",
4450 zfcp_get_busid_by_adapter(adapter));
4451
4452 wait_event(fsf_req->completion_wq,
4453 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4454
4455 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004456 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457
4458 free_fsf_req:
4459 zfcp_fsf_req_free(fsf_req);
4460 unlock_queue_lock:
4461 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 out:
4463 return retval;
4464}
4465
4466
4467/*
4468 * function: zfcp_fsf_control_file_handler
4469 *
4470 * purpose: Handler of the control file upload/download FSF requests
4471 *
4472 * returns: 0 - FSF request successfuly processed
4473 * -EAGAIN - Operation has to be repeated because of a temporary problem
4474 * -EACCES - There is no permission to execute an operation
4475 * -EPERM - The control file is not in a right format
4476 * -EIO - There is a problem with the FCP adapter
4477 * -EINVAL - Invalid operation
4478 * -EFAULT - User space memory I/O operation fault
4479 */
4480static int
4481zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4482{
4483 struct zfcp_adapter *adapter = fsf_req->adapter;
4484 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4485 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4486 int retval = 0;
4487
4488 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4489 retval = -EINVAL;
4490 goto skip_fsfstatus;
4491 }
4492
4493 switch (header->fsf_status) {
4494
4495 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 ZFCP_LOG_NORMAL(
4497 "The FSF request has been successfully completed "
4498 "on the adapter %s\n",
4499 zfcp_get_busid_by_adapter(adapter));
4500 break;
4501
4502 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4504 switch (header->fsf_status_qual.word[0]) {
4505
6f71d9b2005-04-10 23:04:28 -05004506 case FSF_SQ_CFDC_HARDENED_ON_SE:
4507 ZFCP_LOG_NORMAL(
4508 "CFDC on the adapter %s has being "
4509 "hardened on primary and secondary SE\n",
4510 zfcp_get_busid_by_adapter(adapter));
4511 break;
4512
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4514 ZFCP_LOG_NORMAL(
4515 "CFDC of the adapter %s could not "
4516 "be saved on the SE\n",
4517 zfcp_get_busid_by_adapter(adapter));
4518 break;
4519
4520 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4521 ZFCP_LOG_NORMAL(
4522 "CFDC of the adapter %s could not "
4523 "be copied to the secondary SE\n",
4524 zfcp_get_busid_by_adapter(adapter));
4525 break;
4526
4527 default:
4528 ZFCP_LOG_NORMAL(
4529 "CFDC could not be hardened "
4530 "on the adapter %s\n",
4531 zfcp_get_busid_by_adapter(adapter));
4532 }
4533 }
4534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4535 retval = -EAGAIN;
4536 break;
4537
4538 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 ZFCP_LOG_NORMAL(
4540 "Adapter %s does not accept privileged commands\n",
4541 zfcp_get_busid_by_adapter(adapter));
4542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4543 retval = -EACCES;
4544 break;
4545
4546 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 ZFCP_LOG_NORMAL(
4548 "Error at position %d in the CFDC, "
4549 "CFDC is discarded by the adapter %s\n",
4550 header->fsf_status_qual.word[0],
4551 zfcp_get_busid_by_adapter(adapter));
4552 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4553 retval = -EPERM;
4554 break;
4555
4556 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 ZFCP_LOG_NORMAL(
4558 "Adapter %s cannot harden the control file, "
4559 "file is discarded\n",
4560 zfcp_get_busid_by_adapter(adapter));
4561 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4562 retval = -EIO;
4563 break;
4564
4565 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 ZFCP_LOG_NORMAL(
4567 "Control file is too large, file is discarded "
4568 "by the adapter %s\n",
4569 zfcp_get_busid_by_adapter(adapter));
4570 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4571 retval = -EIO;
4572 break;
4573
4574 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4576 ZFCP_LOG_NORMAL(
4577 "CFDC has been discarded by the adapter %s, "
4578 "because activation would impact "
4579 "%d active connection(s)\n",
4580 zfcp_get_busid_by_adapter(adapter),
4581 header->fsf_status_qual.word[0]);
4582 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4583 retval = -EIO;
4584 break;
4585
4586 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4588 ZFCP_LOG_NORMAL(
4589 "CFDC has been activated on the adapter %s, "
4590 "but activation has impacted "
4591 "%d active connection(s)\n",
4592 zfcp_get_busid_by_adapter(adapter),
4593 header->fsf_status_qual.word[0]);
4594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4595 retval = -EIO;
4596 break;
4597
4598 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4600 "op_subtype=0x%x)\n",
4601 zfcp_get_busid_by_adapter(adapter),
4602 bottom->operation_subtype);
4603 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4604 retval = -EINVAL;
4605 break;
4606
4607 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 ZFCP_LOG_NORMAL(
4609 "Invalid option 0x%x has been specified "
4610 "in QTCB bottom sent to the adapter %s\n",
4611 bottom->option,
4612 zfcp_get_busid_by_adapter(adapter));
4613 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4614 retval = -EINVAL;
4615 break;
4616
4617 default:
4618 ZFCP_LOG_NORMAL(
4619 "bug: An unknown/unexpected FSF status 0x%08x "
4620 "was presented on the adapter %s\n",
4621 header->fsf_status,
4622 zfcp_get_busid_by_adapter(adapter));
4623 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4624 debug_exception(fsf_req->adapter->erp_dbf, 0,
4625 &header->fsf_status_qual.word[0], sizeof(u32));
4626 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4627 retval = -EINVAL;
4628 break;
4629 }
4630
4631skip_fsfstatus:
4632 return retval;
4633}
4634
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635static inline int
4636zfcp_fsf_req_sbal_check(unsigned long *flags,
4637 struct zfcp_qdio_queue *queue, int needed)
4638{
4639 write_lock_irqsave(&queue->queue_lock, *flags);
4640 if (likely(atomic_read(&queue->free_count) >= needed))
4641 return 1;
4642 write_unlock_irqrestore(&queue->queue_lock, *flags);
4643 return 0;
4644}
4645
4646/*
4647 * set qtcb pointer in fsf_req and initialize QTCB
4648 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004649static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004650zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651{
4652 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004653 fsf_req->qtcb->prefix.req_seq_no =
4654 fsf_req->adapter->fsf_req_seq_no;
4655 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004657 fsf_req->qtcb->prefix.qtcb_type =
4658 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004660 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004661 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 }
4663}
4664
4665/**
4666 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4667 * @adapter: adapter for which request queue is examined
4668 * @req_flags: flags indicating whether to wait for needed SBAL or not
4669 * @lock_flags: lock_flags if queue_lock is taken
4670 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4671 * Locks: lock adapter->request_queue->queue_lock on success
4672 */
4673static int
4674zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4675 unsigned long *lock_flags)
4676{
4677 long ret;
4678 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4679
4680 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4681 ret = wait_event_interruptible_timeout(adapter->request_wq,
4682 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4683 ZFCP_SBAL_TIMEOUT);
4684 if (ret < 0)
4685 return ret;
4686 if (!ret)
4687 return -EIO;
4688 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4689 return -EIO;
4690
4691 return 0;
4692}
4693
4694/*
4695 * function: zfcp_fsf_req_create
4696 *
4697 * purpose: create an FSF request at the specified adapter and
4698 * setup common fields
4699 *
4700 * returns: -ENOMEM if there was insufficient memory for a request
4701 * -EIO if no qdio buffers could be allocate to the request
4702 * -EINVAL/-EPERM on bug conditions in req_dequeue
4703 * 0 in success
4704 *
4705 * note: The created request is returned by reference.
4706 *
4707 * locks: lock of concerned request queue must not be held,
4708 * but is held on completion (write, irqsave)
4709 */
4710int
4711zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4712 mempool_t *pool, unsigned long *lock_flags,
4713 struct zfcp_fsf_req **fsf_req_p)
4714{
4715 volatile struct qdio_buffer_element *sbale;
4716 struct zfcp_fsf_req *fsf_req = NULL;
4717 int ret = 0;
4718 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4719
4720 /* allocate new FSF request */
4721 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4722 if (unlikely(NULL == fsf_req)) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +01004723 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 "the outbound (send) queue.\n");
4725 ret = -ENOMEM;
4726 goto failed_fsf_req;
4727 }
4728
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004729 fsf_req->adapter = adapter;
4730 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004731 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004732 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004734 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 this request completion */
4736 init_waitqueue_head(&fsf_req->completion_wq);
4737
4738 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004739 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004741
4742 /* this is serialized (we are holding req_queue-lock of adapter) */
4743 if (adapter->req_no == 0)
4744 adapter->req_no++;
4745 fsf_req->req_id = adapter->req_no++;
4746
4747 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748
4749 /*
4750 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4751 * if it is not set (see also *_open_qdio and *_close_qdio).
4752 */
4753
4754 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4755 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4756 ret = -EIO;
4757 goto failed_sbals;
4758 }
4759
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004760 if (fsf_req->qtcb) {
4761 fsf_req->seq_no = adapter->fsf_req_seq_no;
4762 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 fsf_req->sbal_number = 1;
4765 fsf_req->sbal_first = req_queue->free_index;
4766 fsf_req->sbal_curr = req_queue->free_index;
4767 fsf_req->sbale_curr = 1;
4768
4769 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4770 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4771 }
4772
4773 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4774
4775 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004776 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4778 if (likely(fsf_req->qtcb != NULL)) {
4779 sbale[1].addr = (void *) fsf_req->qtcb;
4780 sbale[1].length = sizeof(struct fsf_qtcb);
4781 }
4782
4783 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4784 fsf_req->sbal_number, fsf_req->sbal_first);
4785
4786 goto success;
4787
4788 failed_sbals:
4789/* dequeue new FSF request previously enqueued */
4790 zfcp_fsf_req_free(fsf_req);
4791 fsf_req = NULL;
4792
4793 failed_fsf_req:
4794 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4795 success:
4796 *fsf_req_p = fsf_req;
4797 return ret;
4798}
4799
4800/*
4801 * function: zfcp_fsf_req_send
4802 *
4803 * purpose: start transfer of FSF request via QDIO
4804 *
4805 * returns: 0 - request transfer succesfully started
4806 * !0 - start of request transfer failed
4807 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004808static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809{
4810 struct zfcp_adapter *adapter;
4811 struct zfcp_qdio_queue *req_queue;
4812 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004813 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 int new_distance_from_int;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004815 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 int retval = 0;
4817
4818 adapter = fsf_req->adapter;
4819 req_queue = &adapter->request_queue,
4820
4821
4822 /* FIXME(debug): remove it later */
4823 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4824 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4825 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4826 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4827 sbale[1].length);
4828
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004829 /* put allocated FSF request into hash table */
4830 spin_lock(&adapter->req_list_lock);
4831 zfcp_reqlist_add(adapter, fsf_req);
4832 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004834 inc_seq_no = (fsf_req->qtcb != NULL);
4835
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 ZFCP_LOG_TRACE("request queue of adapter %s: "
4837 "next free SBAL is %i, %i free SBALs\n",
4838 zfcp_get_busid_by_adapter(adapter),
4839 req_queue->free_index,
4840 atomic_read(&req_queue->free_count));
4841
4842 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4843 "index_in_queue=%i, count=%i, buffers=%p\n",
4844 zfcp_get_busid_by_adapter(adapter),
4845 QDIO_FLAG_SYNC_OUTPUT,
4846 0, fsf_req->sbal_first, fsf_req->sbal_number,
4847 &req_queue->buffer[fsf_req->sbal_first]);
4848
4849 /*
4850 * adjust the number of free SBALs in request queue as well as
4851 * position of first one
4852 */
4853 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4854 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4855 req_queue->free_index += fsf_req->sbal_number; /* increase */
4856 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4857 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4858
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004859 fsf_req->issued = get_clock();
4860
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 retval = do_QDIO(adapter->ccw_device,
4862 QDIO_FLAG_SYNC_OUTPUT,
4863 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4864
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004865 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4866 dbg_tmp[1] = (u64) retval;
4867 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4868
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 if (unlikely(retval)) {
4870 /* Queues are down..... */
4871 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004872 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004873 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004874 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004875 spin_unlock(&adapter->req_list_lock);
4876 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 zfcp_qdio_zero_sbals(req_queue->buffer,
4878 fsf_req->sbal_first, fsf_req->sbal_number);
4879 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004880 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4882 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Martin Peschke9467a9b2008-03-27 14:22:03 +01004883 zfcp_erp_adapter_reopen(adapter, 0, 116, (u64)fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 } else {
4885 req_queue->distance_from_int = new_distance_from_int;
4886 /*
4887 * increase FSF sequence counter -
4888 * this must only be done for request successfully enqueued to
4889 * QDIO this rejected requests may be cleaned up by calling
4890 * routines resulting in missing sequence counter values
4891 * otherwise,
4892 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004893
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004895 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004897
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004899 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 }
4901 return retval;
4902}
4903
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904#undef ZFCP_LOG_AREA