blob: 2f27d03e61c22ed880548e512dc9e41f923ed885 [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 Peschke1f6f7122008-04-18 12:51:55 +0200301 zfcp_erp_adapter_shutdown(adapter, 0, 117, 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 Peschke1f6f7122008-04-18 12:51:55 +0200312 zfcp_erp_adapter_reopen(adapter, 0, 98, 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 Peschke1f6f7122008-04-18 12:51:55 +0200323 zfcp_erp_adapter_shutdown(adapter, 0, 118, 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 Peschke1f6f7122008-04-18 12:51:55 +0200340 zfcp_erp_adapter_shutdown(adapter, 0, 78, 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 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200348 zfcp_erp_adapter_reopen(adapter, 0, 79, 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 Peschke1f6f7122008-04-18 12:51:55 +0200358 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
359 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,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200364 99, 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 Peschke1f6f7122008-04-18 12:51:55 +0200374 zfcp_erp_adapter_reopen(adapter, 0, 100, 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 Peschke1f6f7122008-04-18 12:51:55 +0200387 zfcp_erp_adapter_shutdown(adapter, 0, 119, 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 Peschke1f6f7122008-04-18 12:51:55 +0200426 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
428 break;
429
430 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
432 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 break;
434
435 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
437 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439
440 skip_fsfstatus:
441 /*
442 * always call specific handlers to give them a chance to do
443 * something meaningful even in error cases
444 */
445 zfcp_fsf_req_dispatch(fsf_req);
446
447 return retval;
448}
449
450/*
451 * function: zfcp_fsf_fsfstatus_qual_eval
452 *
453 * purpose: evaluates FSF status-qualifier of completed FSF request
454 * and acts accordingly
455 *
456 * returns:
457 */
458static int
459zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
460{
461 int retval = 0;
462
463 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
464 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 break;
466 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
469 break;
470 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
474 break;
475 case FSF_SQ_NO_RECOM:
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100476 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 "problem on the adapter %s "
478 "Stopping all operations on this adapter. ",
479 zfcp_get_busid_by_adapter(fsf_req->adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200480 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
482 break;
483 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
485 "(adapter %s)\n",
486 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
488 break;
489 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
490 case FSF_SQ_NO_RETRY_POSSIBLE:
491 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
492 /* dealt with in the respective functions */
493 break;
494 default:
495 ZFCP_LOG_NORMAL("bug: Additional status info could "
496 "not be interpreted properly.\n");
497 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
498 (char *) &fsf_req->qtcb->header.fsf_status_qual,
499 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
501 break;
502 }
503
504 return retval;
505}
506
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200507/**
508 * zfcp_fsf_link_down_info_eval - evaluate link down information block
509 */
510static void
Martin Peschke698ec0162008-03-27 14:22:02 +0100511zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200512 struct fsf_link_down_info *link_down)
513{
Martin Peschke698ec0162008-03-27 14:22:02 +0100514 struct zfcp_adapter *adapter = fsf_req->adapter;
515
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100516 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
517 &adapter->status))
518 return;
519
520 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
521
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100522 if (link_down == NULL)
523 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100524
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200525 switch (link_down->error_code) {
526 case FSF_PSQ_LINK_NO_LIGHT:
527 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
528 "(no light detected)\n",
529 zfcp_get_busid_by_adapter(adapter));
530 break;
531 case FSF_PSQ_LINK_WRAP_PLUG:
532 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
533 "(wrap plug detected)\n",
534 zfcp_get_busid_by_adapter(adapter));
535 break;
536 case FSF_PSQ_LINK_NO_FCP:
537 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
538 "(adjacent node on link does not support FCP)\n",
539 zfcp_get_busid_by_adapter(adapter));
540 break;
541 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
542 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
543 "(firmware update in progress)\n",
544 zfcp_get_busid_by_adapter(adapter));
545 break;
546 case FSF_PSQ_LINK_INVALID_WWPN:
547 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
548 "(duplicate or invalid WWPN detected)\n",
549 zfcp_get_busid_by_adapter(adapter));
550 break;
551 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
552 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
553 "(no support for NPIV by Fabric)\n",
554 zfcp_get_busid_by_adapter(adapter));
555 break;
556 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
557 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
558 "(out of resource in FCP daughtercard)\n",
559 zfcp_get_busid_by_adapter(adapter));
560 break;
561 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
562 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
563 "(out of resource in Fabric)\n",
564 zfcp_get_busid_by_adapter(adapter));
565 break;
566 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
567 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
568 "(unable to Fabric login)\n",
569 zfcp_get_busid_by_adapter(adapter));
570 break;
571 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
572 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
573 zfcp_get_busid_by_adapter(adapter));
574 break;
575 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
576 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
577 zfcp_get_busid_by_adapter(adapter));
578 break;
579 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
580 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
581 zfcp_get_busid_by_adapter(adapter));
582 break;
583 default:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(warning: unknown reason code %d)\n",
586 zfcp_get_busid_by_adapter(adapter),
587 link_down->error_code);
588 }
589
590 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
591 ZFCP_LOG_DEBUG("Debug information to link down: "
592 "primary_status=0x%02x "
593 "ioerr_code=0x%02x "
594 "action_code=0x%02x "
595 "reason_code=0x%02x "
596 "explanation_code=0x%02x "
597 "vendor_specific_code=0x%02x\n",
598 link_down->primary_status,
599 link_down->ioerr_code,
600 link_down->action_code,
601 link_down->reason_code,
602 link_down->explanation_code,
603 link_down->vendor_specific_code);
604
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100605 out:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200606 zfcp_erp_adapter_failed(adapter, id, fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200607}
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609/*
610 * function: zfcp_fsf_req_dispatch
611 *
612 * purpose: calls the appropriate command specific handler
613 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200614 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 */
616static int
617zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
618{
619 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
620 struct zfcp_adapter *adapter = fsf_req->adapter;
621 int retval = 0;
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 switch (fsf_req->fsf_command) {
625
626 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 zfcp_fsf_send_fcp_command_handler(fsf_req);
628 break;
629
630 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 zfcp_fsf_abort_fcp_command_handler(fsf_req);
632 break;
633
634 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 zfcp_fsf_send_ct_handler(fsf_req);
636 break;
637
638 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 zfcp_fsf_open_port_handler(fsf_req);
640 break;
641
642 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 zfcp_fsf_open_unit_handler(fsf_req);
644 break;
645
646 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 zfcp_fsf_close_unit_handler(fsf_req);
648 break;
649
650 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 zfcp_fsf_close_port_handler(fsf_req);
652 break;
653
654 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 zfcp_fsf_close_physical_port_handler(fsf_req);
656 break;
657
658 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 zfcp_fsf_exchange_config_data_handler(fsf_req);
660 break;
661
662 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 zfcp_fsf_exchange_port_data_handler(fsf_req);
664 break;
665
666 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 zfcp_fsf_send_els_handler(fsf_req);
668 break;
669
670 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 zfcp_fsf_control_file_handler(fsf_req);
672 break;
673
674 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 zfcp_fsf_control_file_handler(fsf_req);
676 break;
677
678 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
680 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
681 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200682 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
684 ZFCP_LOG_NORMAL
685 ("bug: Command issued by the device driver differs "
686 "from the command returned by the adapter %s "
687 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200688 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 fsf_req->fsf_command,
690 fsf_req->qtcb->header.fsf_command);
691 }
692
693 if (!erp_action)
694 return retval;
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 zfcp_erp_async_handler(erp_action, 0);
697
698 return retval;
699}
700
701/*
702 * function: zfcp_fsf_status_read
703 *
704 * purpose: initiates a Status Read command at the specified adapter
705 *
706 * returns:
707 */
708int
709zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
710{
711 struct zfcp_fsf_req *fsf_req;
712 struct fsf_status_read_buffer *status_buffer;
713 unsigned long lock_flags;
714 volatile struct qdio_buffer_element *sbale;
Heiko Carstensb2141782008-05-19 12:17:39 +0200715 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 /* setup new FSF request */
718 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
719 req_flags | ZFCP_REQ_NO_QTCB,
720 adapter->pool.fsf_req_status_read,
721 &lock_flags, &fsf_req);
722 if (retval < 0) {
723 ZFCP_LOG_INFO("error: Could not create unsolicited status "
724 "buffer for adapter %s.\n",
725 zfcp_get_busid_by_adapter(adapter));
726 goto failed_req_create;
727 }
728
729 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
730 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
731 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
732 fsf_req->sbale_curr = 2;
733
Heiko Carstensb2141782008-05-19 12:17:39 +0200734 retval = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 status_buffer =
736 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
Heiko Carstensb2141782008-05-19 12:17:39 +0200737 if (!status_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 goto failed_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200740 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /* insert pointer to respective buffer */
743 sbale = zfcp_qdio_sbale_curr(fsf_req);
744 sbale->addr = (void *) status_buffer;
745 sbale->length = sizeof(struct fsf_status_read_buffer);
746
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200747 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 if (retval) {
749 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
750 "environment.\n");
751 goto failed_req_send;
752 }
753
754 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
755 zfcp_get_busid_by_adapter(adapter));
756 goto out;
757
758 failed_req_send:
759 mempool_free(status_buffer, adapter->pool.data_status_read);
760
761 failed_buf:
762 zfcp_fsf_req_free(fsf_req);
763 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200764 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 out:
766 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
767 return retval;
768}
769
770static int
771zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
772{
773 struct fsf_status_read_buffer *status_buffer;
774 struct zfcp_adapter *adapter;
775 struct zfcp_port *port;
776 unsigned long flags;
777
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200778 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 adapter = fsf_req->adapter;
780
781 read_lock_irqsave(&zfcp_data.config_lock, flags);
782 list_for_each_entry(port, &adapter->port_list_head, list)
783 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
784 break;
785 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
786
787 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100788 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200789 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 "adapter %s. Ignored.\n",
791 status_buffer->d_id & ZFCP_DID_MASK,
792 zfcp_get_busid_by_adapter(adapter));
793 goto out;
794 }
795
796 switch (status_buffer->status_subtype) {
797
798 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200799 zfcp_erp_port_reopen(port, 0, 101, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 break;
801
802 case FSF_STATUS_READ_SUB_ERROR_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200803 zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 break;
805
806 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
808 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200809 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 "Ignored. (debug info 0x%x)\n",
811 status_buffer->d_id,
812 zfcp_get_busid_by_adapter(adapter),
813 status_buffer->status_subtype);
814 }
815 out:
816 return 0;
817}
818
819/*
820 * function: zfcp_fsf_status_read_handler
821 *
822 * purpose: is called for finished Open Port command
823 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200824 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 */
826static int
827zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
828{
829 int retval = 0;
830 struct zfcp_adapter *adapter = fsf_req->adapter;
831 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200832 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200833 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200836 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200838 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 goto out;
840 }
841
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200842 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 switch (status_buffer->status_type) {
845
846 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 zfcp_fsf_status_read_port_closed(fsf_req);
848 break;
849
850 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 zfcp_fsf_incoming_els(fsf_req);
852 break;
853
854 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
856 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 break;
858
859 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200860 fsf_bit_error = (struct fsf_bit_error_payload *)
861 status_buffer->payload;
862 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
863 "received (adapter %s, "
864 "link failures = %i, loss of sync errors = %i, "
865 "loss of signal errors = %i, "
866 "primitive sequence errors = %i, "
867 "invalid transmission word errors = %i, "
868 "CRC errors = %i)\n",
869 zfcp_get_busid_by_adapter(adapter),
870 fsf_bit_error->link_failure_error_count,
871 fsf_bit_error->loss_of_sync_error_count,
872 fsf_bit_error->loss_of_signal_error_count,
873 fsf_bit_error->primitive_sequence_error_count,
874 fsf_bit_error->invalid_transmission_word_error_count,
875 fsf_bit_error->crc_error_count);
876 ZFCP_LOG_INFO("Additional bit error threshold data "
877 "(adapter %s, "
878 "primitive sequence event time-outs = %i, "
879 "elastic buffer overrun errors = %i, "
880 "advertised receive buffer-to-buffer credit = %i, "
881 "current receice buffer-to-buffer credit = %i, "
882 "advertised transmit buffer-to-buffer credit = %i, "
883 "current transmit buffer-to-buffer credit = %i)\n",
884 zfcp_get_busid_by_adapter(adapter),
885 fsf_bit_error->primitive_sequence_event_timeout_count,
886 fsf_bit_error->elastic_buffer_overrun_error_count,
887 fsf_bit_error->advertised_receive_b2b_credit,
888 fsf_bit_error->current_receive_b2b_credit,
889 fsf_bit_error->advertised_transmit_b2b_credit,
890 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 break;
892
893 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200894 switch (status_buffer->status_subtype) {
895 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
896 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
897 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100898 zfcp_fsf_link_down_info_eval(fsf_req, 38,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100899 (struct fsf_link_down_info *)
900 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200901 break;
902 case FSF_STATUS_READ_SUB_FDISC_FAILED:
903 ZFCP_LOG_INFO("Local link to adapter %s is down "
904 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100905 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100906 zfcp_fsf_link_down_info_eval(fsf_req, 39,
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_FIRMWARE_UPDATE:
911 ZFCP_LOG_INFO("Local link to adapter %s is down "
912 "due to firmware update on adapter\n",
913 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100914 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200915 break;
916 default:
917 ZFCP_LOG_INFO("Local link to adapter %s is down "
918 "due to unknown reason\n",
919 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100920 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200921 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 break;
923
924 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200925 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100926 "Restarting operations on this adapter\n",
927 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200929 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 ZFCP_STATUS_COMMON_RUNNING,
931 ZFCP_SET);
932 zfcp_erp_adapter_reopen(adapter,
933 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100934 | ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200935 102, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 break;
937
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100938 case FSF_STATUS_READ_NOTIFICATION_LOST:
939 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
940 "adapter %s%s%s%s%s%s%s%s%s\n",
941 zfcp_get_busid_by_adapter(adapter),
942 (status_buffer->status_subtype &
943 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
944 ", incoming ELS" : "",
945 (status_buffer->status_subtype &
946 FSF_STATUS_READ_SUB_SENSE_DATA) ?
947 ", sense data" : "",
948 (status_buffer->status_subtype &
949 FSF_STATUS_READ_SUB_LINK_STATUS) ?
950 ", link status change" : "",
951 (status_buffer->status_subtype &
952 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
953 ", port close" : "",
954 (status_buffer->status_subtype &
955 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
956 ", bit error exception" : "",
957 (status_buffer->status_subtype &
958 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
959 ", ACT update" : "",
960 (status_buffer->status_subtype &
961 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
962 ", ACT hardening" : "",
963 (status_buffer->status_subtype &
964 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
965 ", adapter feature change" : "");
966
967 if (status_buffer->status_subtype &
968 FSF_STATUS_READ_SUB_ACT_UPDATED)
Martin Peschke1f6f7122008-04-18 12:51:55 +0200969 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100970 break;
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200973 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200975 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 break;
977
978 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 switch (status_buffer->status_subtype) {
980 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200981 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 zfcp_get_busid_by_adapter(adapter));
983 break;
984 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200985 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 "to the secondary SE\n",
987 zfcp_get_busid_by_adapter(adapter));
988 break;
989 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200990 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 zfcp_get_busid_by_adapter(adapter));
992 }
993 break;
994
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200995 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200996 ZFCP_LOG_INFO("List of supported features on adapter %s has "
997 "been changed from 0x%08X to 0x%08X\n",
998 zfcp_get_busid_by_adapter(adapter),
999 *(u32*) (status_buffer->payload + 4),
1000 *(u32*) (status_buffer->payload));
1001 adapter->adapter_features = *(u32*) status_buffer->payload;
1002 break;
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001005 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 "type was received (debug info 0x%x)\n",
1007 status_buffer->status_type);
1008 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1009 status_buffer);
1010 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1011 (char *) status_buffer,
1012 sizeof (struct fsf_status_read_buffer));
1013 break;
1014 }
1015 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001016 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 /*
1018 * recycle buffer and start new request repeat until outbound
1019 * queue is empty or adapter shutdown is requested
1020 */
1021 /*
1022 * FIXME(qdio):
1023 * we may wait in the req_create for 5s during shutdown, so
1024 * qdio_cleanup will have to wait at least that long before returning
1025 * with failure to allow us a proper cleanup under all circumstances
1026 */
1027 /*
1028 * FIXME:
1029 * allocation failure possible? (Is this code needed?)
1030 */
Swen Schilligd26ab062008-05-19 12:17:37 +02001031
1032 atomic_inc(&adapter->stat_miss);
1033 schedule_work(&adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 out:
1035 return retval;
1036}
1037
1038/*
1039 * function: zfcp_fsf_abort_fcp_command
1040 *
1041 * purpose: tells FSF to abort a running SCSI command
1042 *
1043 * returns: address of initiated FSF request
1044 * NULL - request could not be initiated
1045 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001046 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 * FIXME(design) shouldn't this be modified to return an int
1048 * also...don't know how though
1049 */
1050struct zfcp_fsf_req *
1051zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1052 struct zfcp_adapter *adapter,
1053 struct zfcp_unit *unit, int req_flags)
1054{
1055 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001057 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 int retval = 0;
1059
1060 /* setup new FSF request */
1061 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1062 req_flags, adapter->pool.fsf_req_abort,
1063 &lock_flags, &fsf_req);
1064 if (retval < 0) {
1065 ZFCP_LOG_INFO("error: Failed to create an abort command "
1066 "request for lun 0x%016Lx on port 0x%016Lx "
1067 "on adapter %s.\n",
1068 unit->fcp_lun,
1069 unit->port->wwpn,
1070 zfcp_get_busid_by_adapter(adapter));
1071 goto out;
1072 }
1073
Christof Schmitt951f7462007-12-20 12:30:24 +01001074 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1075 &unit->status)))
1076 goto unit_blocked;
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1079 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1080 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1081
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001082 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 /* set handles of unit and its parent port in QTCB */
1085 fsf_req->qtcb->header.lun_handle = unit->handle;
1086 fsf_req->qtcb->header.port_handle = unit->port->handle;
1087
1088 /* set handle of request which should be aborted */
1089 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1090
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001091 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1092 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001093 if (!retval)
1094 goto out;
1095
1096 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 zfcp_fsf_req_free(fsf_req);
1098 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 out:
1101 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1102 return fsf_req;
1103}
1104
1105/*
1106 * function: zfcp_fsf_abort_fcp_command_handler
1107 *
1108 * purpose: is called for finished Abort FCP Command request
1109 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001110 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 */
1112static int
1113zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1114{
1115 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001116 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001117 union fsf_status_qual *fsf_stat_qual =
1118 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1121 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1122 goto skip_fsfstatus;
1123 }
1124
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001125 unit = (struct zfcp_unit *) new_fsf_req->data;
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 /* evaluate FSF status in QTCB */
1128 switch (new_fsf_req->qtcb->header.fsf_status) {
1129
1130 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001131 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 /*
1133 * In this case a command that was sent prior to a port
1134 * reopen was aborted (handles are different). This is
1135 * fine.
1136 */
1137 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1139 "port 0x%016Lx on adapter %s invalid. "
1140 "This may happen occasionally.\n",
1141 unit->port->handle,
1142 unit->port->wwpn,
1143 zfcp_get_busid_by_unit(unit));
1144 ZFCP_LOG_INFO("status qualifier:\n");
1145 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1146 (char *) &new_fsf_req->qtcb->header.
1147 fsf_status_qual,
1148 sizeof (union fsf_status_qual));
1149 /* Let's hope this sorts out the mess */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001150 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001151 new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1153 }
1154 break;
1155
1156 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001157 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /*
1159 * In this case a command that was sent prior to a unit
1160 * reopen was aborted (handles are different).
1161 * This is fine.
1162 */
1163 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 ZFCP_LOG_INFO
1165 ("Warning: Temporary LUN identifier 0x%x of LUN "
1166 "0x%016Lx on port 0x%016Lx on adapter %s is "
1167 "invalid. This may happen in rare cases. "
1168 "Trying to re-establish link.\n",
1169 unit->handle,
1170 unit->fcp_lun,
1171 unit->port->wwpn,
1172 zfcp_get_busid_by_unit(unit));
1173 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1174 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1175 (char *) &new_fsf_req->qtcb->header.
1176 fsf_status_qual,
1177 sizeof (union fsf_status_qual));
1178 /* Let's hope this sorts out the mess */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001179 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1181 }
1182 break;
1183
1184 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1187 break;
1188
1189 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1191 "be reopened\n", unit->port->wwpn,
1192 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001193 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1195 | ZFCP_STATUS_FSFREQ_RETRY;
1196 break;
1197
1198 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 ZFCP_LOG_INFO(
1200 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1201 "to be reopened\n",
1202 unit->fcp_lun, unit->port->wwpn,
1203 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001204 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1206 | ZFCP_STATUS_FSFREQ_RETRY;
1207 break;
1208
1209 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1211 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001212 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1214 break;
1215 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 /* SCSI stack will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1218 break;
1219 default:
1220 ZFCP_LOG_NORMAL
1221 ("bug: Wrong status qualifier 0x%x arrived.\n",
1222 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 break;
1224 }
1225 break;
1226
1227 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 retval = 0;
1229 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1230 break;
1231
1232 default:
1233 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1234 "(debug info 0x%x)\n",
1235 new_fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 break;
1237 }
1238 skip_fsfstatus:
1239 return retval;
1240}
1241
1242/**
1243 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1244 * one SBALE
1245 * Two scatter-gather lists are passed, one for the reqeust and one for the
1246 * response.
1247 */
1248static inline int
1249zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1250 struct scatterlist *resp, int resp_count)
1251{
1252 return ((req_count == 1) &&
1253 (resp_count == 1) &&
1254 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1255 PAGE_MASK) ==
1256 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1257 req[0].length - 1) & PAGE_MASK)) &&
1258 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1259 PAGE_MASK) ==
1260 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1261 resp[0].length - 1) & PAGE_MASK)));
1262}
1263
1264/**
1265 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1266 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1267 * the request
1268 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1269 * a struct zfcp_fsf_req
1270 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1271 * is sent within error recovery
1272 */
1273int
1274zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1275 struct zfcp_erp_action *erp_action)
1276{
1277 volatile struct qdio_buffer_element *sbale;
1278 struct zfcp_port *port;
1279 struct zfcp_adapter *adapter;
1280 struct zfcp_fsf_req *fsf_req;
1281 unsigned long lock_flags;
1282 int bytes;
1283 int ret = 0;
1284
1285 port = ct->port;
1286 adapter = port->adapter;
1287
1288 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1289 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1290 pool, &lock_flags, &fsf_req);
1291 if (ret < 0) {
1292 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1293 "adapter: %s\n",
1294 zfcp_get_busid_by_adapter(adapter));
1295 goto failed_req;
1296 }
1297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1299 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1300 ct->resp, ct->resp_count)){
1301 /* both request buffer and response buffer
1302 fit into one sbale each */
1303 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1304 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1305 sbale[2].length = ct->req[0].length;
1306 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1307 sbale[3].length = ct->resp[0].length;
1308 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001309 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1311 /* try to use chained SBALs */
1312 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1313 SBAL_FLAGS0_TYPE_WRITE_READ,
1314 ct->req, ct->req_count,
1315 ZFCP_MAX_SBALS_PER_CT_REQ);
1316 if (bytes <= 0) {
1317 ZFCP_LOG_INFO("error: creation of CT request failed "
1318 "on adapter %s\n",
1319 zfcp_get_busid_by_adapter(adapter));
1320 if (bytes == 0)
1321 ret = -ENOMEM;
1322 else
1323 ret = bytes;
1324
1325 goto failed_send;
1326 }
1327 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1328 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1329 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1330 SBAL_FLAGS0_TYPE_WRITE_READ,
1331 ct->resp, ct->resp_count,
1332 ZFCP_MAX_SBALS_PER_CT_REQ);
1333 if (bytes <= 0) {
1334 ZFCP_LOG_INFO("error: creation of CT request failed "
1335 "on adapter %s\n",
1336 zfcp_get_busid_by_adapter(adapter));
1337 if (bytes == 0)
1338 ret = -ENOMEM;
1339 else
1340 ret = bytes;
1341
1342 goto failed_send;
1343 }
1344 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1345 } else {
1346 /* reject send generic request */
1347 ZFCP_LOG_INFO(
1348 "error: microcode does not support chained SBALs,"
1349 "CT request too big (adapter %s)\n",
1350 zfcp_get_busid_by_adapter(adapter));
1351 ret = -EOPNOTSUPP;
1352 goto failed_send;
1353 }
1354
1355 /* settings in QTCB */
1356 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001357 fsf_req->qtcb->bottom.support.service_class =
1358 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001360 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001362 zfcp_san_dbf_event_ct_request(fsf_req);
1363
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001364 if (erp_action) {
1365 erp_action->fsf_req = fsf_req;
1366 fsf_req->erp_action = erp_action;
1367 zfcp_erp_start_timer(fsf_req);
1368 } else
1369 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1370
1371 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 if (ret) {
1373 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1374 "(adapter %s, port 0x%016Lx)\n",
1375 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1376 goto failed_send;
1377 }
1378
1379 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1380 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1381 goto out;
1382
1383 failed_send:
1384 zfcp_fsf_req_free(fsf_req);
1385 if (erp_action != NULL) {
1386 erp_action->fsf_req = NULL;
1387 }
1388 failed_req:
1389 out:
1390 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1391 lock_flags);
1392 return ret;
1393}
1394
1395/**
1396 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1397 * @fsf_req: pointer to struct zfcp_fsf_req
1398 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001399 * Data specific for the Generic Service request is passed using
1400 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1401 * Usually a specific handler for the CT request is called which is
1402 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 */
1404static int
1405zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1406{
1407 struct zfcp_port *port;
1408 struct zfcp_adapter *adapter;
1409 struct zfcp_send_ct *send_ct;
1410 struct fsf_qtcb_header *header;
1411 struct fsf_qtcb_bottom_support *bottom;
1412 int retval = -EINVAL;
1413 u16 subtable, rule, counter;
1414
1415 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001416 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 port = send_ct->port;
1418 header = &fsf_req->qtcb->header;
1419 bottom = &fsf_req->qtcb->bottom.support;
1420
1421 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1422 goto skip_fsfstatus;
1423
1424 /* evaluate FSF status in QTCB */
1425 switch (header->fsf_status) {
1426
1427 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001428 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 retval = 0;
1430 break;
1431
1432 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001433 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1434 "class %d.\n",
1435 zfcp_get_busid_by_port(port),
1436 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001438 zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1440 break;
1441
1442 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 switch (header->fsf_status_qual.word[0]){
1444 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 /* reopening link to port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 zfcp_test_link(port);
1447 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1448 break;
1449 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1452 break;
1453 default:
1454 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1455 "arrived.\n",
1456 header->fsf_status_qual.word[0]);
1457 break;
1458 }
1459 break;
1460
1461 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001463 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 zfcp_get_busid_by_port(port), port->d_id);
1465 for (counter = 0; counter < 2; counter++) {
1466 subtable = header->fsf_status_qual.halfword[counter * 2];
1467 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1468 switch (subtable) {
1469 case FSF_SQ_CFDC_SUBTABLE_OS:
1470 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1471 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1472 case FSF_SQ_CFDC_SUBTABLE_LUN:
1473 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1474 zfcp_act_subtable_type[subtable], rule);
1475 break;
1476 }
1477 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02001478 zfcp_erp_port_access_denied(port, 55, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1480 break;
1481
1482 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001484 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 zfcp_get_busid_by_port(port), port->d_id);
1486 ZFCP_LOG_INFO("status qualifier:\n");
1487 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1488 (char *) &header->fsf_status_qual,
1489 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1491 break;
1492
1493 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1495 "0x%016Lx on adapter %s invalid. This may "
1496 "happen occasionally.\n", port->handle,
1497 port->wwpn, zfcp_get_busid_by_port(port));
1498 ZFCP_LOG_INFO("status qualifier:\n");
1499 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1500 (char *) &header->fsf_status_qual,
1501 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001502 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1504 break;
1505
1506 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001508 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 zfcp_get_busid_by_port(port), port->d_id);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001510 zfcp_erp_port_boxed(port, 49, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1512 | ZFCP_STATUS_FSFREQ_RETRY;
1513 break;
1514
1515 /* following states should never occure, all cases avoided
1516 in zfcp_fsf_send_ct - but who knows ... */
1517 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1519 "req_buf_length=%d, resp_buf_length=%d)\n",
1520 zfcp_get_busid_by_adapter(adapter),
1521 bottom->req_buf_length, bottom->resp_buf_length);
1522 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1523 break;
1524 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1526 "req_buf_length=%d)\n",
1527 zfcp_get_busid_by_adapter(adapter),
1528 bottom->req_buf_length);
1529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1530 break;
1531 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1533 "resp_buf_length=%d)\n",
1534 zfcp_get_busid_by_adapter(adapter),
1535 bottom->resp_buf_length);
1536 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1537 break;
1538 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1540 "resp_buf_length=%d)\n",
1541 zfcp_get_busid_by_adapter(adapter),
1542 bottom->req_buf_length, bottom->resp_buf_length);
1543 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1544 break;
1545
1546 default:
1547 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1548 "(debug info 0x%x)\n", header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 break;
1550 }
1551
1552skip_fsfstatus:
1553 send_ct->status = retval;
1554
1555 if (send_ct->handler != NULL)
1556 send_ct->handler(send_ct->handler_data);
1557
1558 return retval;
1559}
1560
1561/**
1562 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1563 * @els: pointer to struct zfcp_send_els which contains all needed data for
1564 * the command.
1565 */
1566int
1567zfcp_fsf_send_els(struct zfcp_send_els *els)
1568{
1569 volatile struct qdio_buffer_element *sbale;
1570 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001571 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 struct zfcp_adapter *adapter;
1573 unsigned long lock_flags;
1574 int bytes;
1575 int ret = 0;
1576
1577 d_id = els->d_id;
1578 adapter = els->adapter;
1579
1580 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1581 ZFCP_REQ_AUTO_CLEANUP,
1582 NULL, &lock_flags, &fsf_req);
1583 if (ret < 0) {
1584 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001585 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 zfcp_get_busid_by_adapter(adapter), d_id);
1587 goto failed_req;
1588 }
1589
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001590 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1591 &els->port->status))) {
1592 ret = -EBUSY;
1593 goto port_blocked;
1594 }
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1597 if (zfcp_use_one_sbal(els->req, els->req_count,
1598 els->resp, els->resp_count)){
1599 /* both request buffer and response buffer
1600 fit into one sbale each */
1601 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1602 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1603 sbale[2].length = els->req[0].length;
1604 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1605 sbale[3].length = els->resp[0].length;
1606 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001607 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1609 /* try to use chained SBALs */
1610 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1611 SBAL_FLAGS0_TYPE_WRITE_READ,
1612 els->req, els->req_count,
1613 ZFCP_MAX_SBALS_PER_ELS_REQ);
1614 if (bytes <= 0) {
1615 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001616 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 zfcp_get_busid_by_adapter(adapter), d_id);
1618 if (bytes == 0) {
1619 ret = -ENOMEM;
1620 } else {
1621 ret = bytes;
1622 }
1623 goto failed_send;
1624 }
1625 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1626 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1627 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1628 SBAL_FLAGS0_TYPE_WRITE_READ,
1629 els->resp, els->resp_count,
1630 ZFCP_MAX_SBALS_PER_ELS_REQ);
1631 if (bytes <= 0) {
1632 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001633 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 zfcp_get_busid_by_adapter(adapter), d_id);
1635 if (bytes == 0) {
1636 ret = -ENOMEM;
1637 } else {
1638 ret = bytes;
1639 }
1640 goto failed_send;
1641 }
1642 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1643 } else {
1644 /* reject request */
1645 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1646 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001647 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 zfcp_get_busid_by_adapter(adapter), d_id);
1649 ret = -EOPNOTSUPP;
1650 goto failed_send;
1651 }
1652
1653 /* settings in QTCB */
1654 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001655 fsf_req->qtcb->bottom.support.service_class =
1656 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001658 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
1660 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1661
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001662 zfcp_san_dbf_event_els_request(fsf_req);
1663
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001664 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1665 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 if (ret) {
1667 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001668 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 zfcp_get_busid_by_adapter(adapter), d_id);
1670 goto failed_send;
1671 }
1672
1673 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001674 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 goto out;
1676
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001677 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 failed_send:
1679 zfcp_fsf_req_free(fsf_req);
1680
1681 failed_req:
1682 out:
1683 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1684 lock_flags);
1685
1686 return ret;
1687}
1688
1689/**
1690 * zfcp_fsf_send_els_handler - handler for ELS commands
1691 * @fsf_req: pointer to struct zfcp_fsf_req
1692 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001693 * Data specific for the ELS command is passed using
1694 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1695 * Usually a specific handler for the ELS command is called which is
1696 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 */
1698static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1699{
1700 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001702 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 struct fsf_qtcb_header *header;
1704 struct fsf_qtcb_bottom_support *bottom;
1705 struct zfcp_send_els *send_els;
1706 int retval = -EINVAL;
1707 u16 subtable, rule, counter;
1708
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001709 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001711 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 d_id = send_els->d_id;
1713 header = &fsf_req->qtcb->header;
1714 bottom = &fsf_req->qtcb->bottom.support;
1715
1716 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1717 goto skip_fsfstatus;
1718
1719 switch (header->fsf_status) {
1720
1721 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001722 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 retval = 0;
1724 break;
1725
1726 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001727 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1728 "class %d.\n",
1729 zfcp_get_busid_by_adapter(adapter),
1730 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001732 zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1734 break;
1735
1736 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 switch (header->fsf_status_qual.word[0]){
1738 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001739 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1740 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1742 break;
1743 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1745 retval =
1746 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1747 (struct zfcp_ls_rjt_par *)
1748 &header->fsf_status_qual.word[2]);
1749 break;
1750 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1752 break;
1753 default:
1754 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1755 header->fsf_status_qual.word[0]);
1756 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1757 (char*)header->fsf_status_qual.word, 16);
1758 }
1759 break;
1760
1761 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1763 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001764 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 zfcp_get_busid_by_adapter(adapter), d_id);
1766
1767 break;
1768
1769 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 ZFCP_LOG_INFO(
1771 "ELS request size and ELS response size must be either "
1772 "both 0, or both greater than 0 "
1773 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1774 zfcp_get_busid_by_adapter(adapter),
1775 bottom->req_buf_length,
1776 bottom->resp_buf_length);
1777 break;
1778
1779 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 ZFCP_LOG_INFO(
1781 "Length of the ELS request buffer, "
1782 "specified in QTCB bottom, "
1783 "exceeds the size of the buffers "
1784 "that have been allocated for ELS request data "
1785 "(adapter: %s, req_buf_length=%d)\n",
1786 zfcp_get_busid_by_adapter(adapter),
1787 bottom->req_buf_length);
1788 break;
1789
1790 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 ZFCP_LOG_INFO(
1792 "Length of the ELS response buffer, "
1793 "specified in QTCB bottom, "
1794 "exceeds the size of the buffers "
1795 "that have been allocated for ELS response data "
1796 "(adapter: %s, resp_buf_length=%d)\n",
1797 zfcp_get_busid_by_adapter(adapter),
1798 bottom->resp_buf_length);
1799 break;
1800
1801 case FSF_SBAL_MISMATCH:
1802 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1804 "resp_buf_length=%d)\n",
1805 zfcp_get_busid_by_adapter(adapter),
1806 bottom->req_buf_length, bottom->resp_buf_length);
1807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1808 break;
1809
1810 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001812 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 zfcp_get_busid_by_adapter(adapter), d_id);
1814 for (counter = 0; counter < 2; counter++) {
1815 subtable = header->fsf_status_qual.halfword[counter * 2];
1816 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1817 switch (subtable) {
1818 case FSF_SQ_CFDC_SUBTABLE_OS:
1819 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1820 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1821 case FSF_SQ_CFDC_SUBTABLE_LUN:
1822 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1823 zfcp_act_subtable_type[subtable], rule);
1824 break;
1825 }
1826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 if (port != NULL)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001828 zfcp_erp_port_access_denied(port, 56, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1830 break;
1831
1832 default:
1833 ZFCP_LOG_NORMAL(
1834 "bug: An unknown FSF Status was presented "
1835 "(adapter: %s, fsf_status=0x%08x)\n",
1836 zfcp_get_busid_by_adapter(adapter),
1837 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1839 break;
1840 }
1841
1842skip_fsfstatus:
1843 send_els->status = retval;
1844
Heiko Carstensaa551da2007-07-18 10:55:10 +02001845 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 send_els->handler(send_els->handler_data);
1847
1848 return retval;
1849}
1850
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851int
1852zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1853{
1854 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001855 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001856 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001858 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
1860 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001861 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1863 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001864 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001865 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001866 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1868 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001869 zfcp_get_busid_by_adapter(adapter));
1870 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1871 lock_flags);
1872 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 }
1874
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001875 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001876 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1877 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001879 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001880 FSF_FEATURE_CFDC |
1881 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001882 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001883 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001884 fsf_req->erp_action = erp_action;
1885 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001887 zfcp_erp_start_timer(fsf_req);
1888 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001889 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1890 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001892 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1893 "data command on the adapter %s\n",
1894 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001895 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001897 }
1898 else
1899 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1900 "(adapter %s)\n",
1901 zfcp_get_busid_by_adapter(adapter));
1902
1903 return retval;
1904}
1905
1906int
1907zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1908 struct fsf_qtcb_bottom_config *data)
1909{
1910 volatile struct qdio_buffer_element *sbale;
1911 struct zfcp_fsf_req *fsf_req;
1912 unsigned long lock_flags;
1913 int retval;
1914
1915 /* setup new FSF request */
1916 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Swen Schilligaee6ef12008-04-24 19:35:52 +02001917 ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
1918 &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001919 if (retval) {
1920 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1921 "data request for adapter %s.\n",
1922 zfcp_get_busid_by_adapter(adapter));
1923 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1924 lock_flags);
1925 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
1927
Swen Schillig52ef11a2007-08-28 09:31:09 +02001928 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1929 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1930 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
Swen Schillig52ef11a2007-08-28 09:31:09 +02001932 fsf_req->qtcb->bottom.config.feature_selection =
1933 FSF_FEATURE_CFDC |
1934 FSF_FEATURE_LUN_SHARING |
1935 FSF_FEATURE_NOTIFICATION_LOST |
1936 FSF_FEATURE_UPDATE_ALERT;
1937
1938 if (data)
1939 fsf_req->data = (unsigned long) data;
1940
1941 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1942 retval = zfcp_fsf_req_send(fsf_req);
1943 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001945 if (retval)
1946 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1947 "data command on the adapter %s\n",
1948 zfcp_get_busid_by_adapter(adapter));
1949 else
1950 wait_event(fsf_req->completion_wq,
1951 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1952
1953 zfcp_fsf_req_free(fsf_req);
1954
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 return retval;
1956}
1957
1958/**
1959 * zfcp_fsf_exchange_config_evaluate
1960 * @fsf_req: fsf_req which belongs to xchg config data request
1961 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1962 *
1963 * returns: -EIO on error, 0 otherwise
1964 */
1965static int
1966zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1967{
1968 struct fsf_qtcb_bottom_config *bottom;
1969 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001970 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
1972 bottom = &fsf_req->qtcb->bottom.config;
1973 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1974 bottom->low_qtcb_version, bottom->high_qtcb_version);
1975 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001976 adapter->adapter_features = bottom->adapter_features;
1977 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05001978 adapter->peer_wwpn = 0;
1979 adapter->peer_wwnn = 0;
1980 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
1982 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001983
1984 if (fsf_req->data)
1985 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1986 bottom, sizeof (struct fsf_qtcb_bottom_config));
1987
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001988 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
1989 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
1990 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
1991 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001992 fc_host_supported_classes(shost) =
1993 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 adapter->hydra_version = bottom->adapter_type;
Christof Schmittc9615852008-05-06 11:00:05 +02001995 adapter->timer_ticks = bottom->timer_interval;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001996 if (fc_host_permanent_port_name(shost) == -1)
1997 fc_host_permanent_port_name(shost) =
1998 fc_host_port_name(shost);
1999 if (bottom->fc_topology == FSF_TOPO_P2P) {
2000 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2001 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2002 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2003 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2004 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2005 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2006 else if (bottom->fc_topology == FSF_TOPO_AL)
2007 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2008 else
2009 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002011 fc_host_node_name(shost) = 0;
2012 fc_host_port_name(shost) = 0;
2013 fc_host_port_id(shost) = 0;
2014 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002015 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 adapter->hydra_version = 0;
2017 }
2018
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002019 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002021 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2022 min(FC_SERIAL_NUMBER_SIZE, 17));
2023 EBCASC(fc_host_serial_number(shost),
2024 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 }
2026
Swen Schilligec258fe2008-04-24 19:35:53 +02002027 if (fsf_req->erp_action)
2028 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2029 "characteristics:\n"
2030 "WWNN 0x%016Lx, WWPN 0x%016Lx, "
2031 "S_ID 0x%06x,\n"
2032 "adapter version 0x%x, "
2033 "LIC version 0x%x, "
2034 "FC link speed %d Gb/s\n",
2035 zfcp_get_busid_by_adapter(adapter),
2036 (wwn_t) fc_host_node_name(shost),
2037 (wwn_t) fc_host_port_name(shost),
2038 fc_host_port_id(shost),
2039 adapter->hydra_version,
2040 adapter->fsf_lic_version,
2041 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2043 ZFCP_LOG_NORMAL("error: the adapter %s "
2044 "only supports newer control block "
2045 "versions in comparison to this device "
2046 "driver (try updated device driver)\n",
2047 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002048 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return -EIO;
2050 }
2051 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2052 ZFCP_LOG_NORMAL("error: the adapter %s "
2053 "only supports older control block "
2054 "versions than this device driver uses"
2055 "(consider a microcode upgrade)\n",
2056 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002057 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 return -EIO;
2059 }
2060 return 0;
2061}
2062
Swen Schillig52ef11a2007-08-28 09:31:09 +02002063/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 * function: zfcp_fsf_exchange_config_data_handler
2065 *
2066 * purpose: is called for finished Exchange Configuration Data command
2067 *
2068 * returns:
2069 */
2070static int
2071zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2072{
2073 struct fsf_qtcb_bottom_config *bottom;
2074 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002075 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2078 return -EIO;
2079
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002080 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2084 return -EIO;
2085
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002086 switch (fc_host_port_type(adapter->scsi_host)) {
2087 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002088 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2089 "configuration detected at adapter %s\n"
2090 "Peer WWNN 0x%016llx, "
2091 "peer WWPN 0x%016llx, "
2092 "peer d_id 0x%06x\n",
2093 zfcp_get_busid_by_adapter(adapter),
2094 adapter->peer_wwnn,
2095 adapter->peer_wwpn,
2096 adapter->peer_d_id);
6f71d9b2005-04-10 23:04:28 -05002097 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002098 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2100 "topology detected at adapter %s "
2101 "unsupported, shutting down adapter\n",
2102 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002103 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002105 case FC_PORTTYPE_NPORT:
Swen Schilligec258fe2008-04-24 19:35:53 +02002106 if (fsf_req->erp_action)
2107 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2108 "network detected at adapter "
2109 "%s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02002110 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 break;
2112 default:
2113 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2114 "reported by the exchange "
2115 "configuration command for "
2116 "the adapter %s is not "
2117 "of a type known to the zfcp "
2118 "driver, shutting down adapter\n",
2119 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002120 zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 return -EIO;
2122 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002123 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2125 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2126 "allowed by the adapter %s "
2127 "is lower than the minimum "
2128 "required by the driver (%ld bytes).\n",
2129 bottom->max_qtcb_size,
2130 zfcp_get_busid_by_adapter(adapter),
2131 sizeof(struct fsf_qtcb));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002132 zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 return -EIO;
2134 }
2135 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2136 &adapter->status);
2137 break;
2138 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2140 return -EIO;
2141
Swen Schillig52ef11a2007-08-28 09:31:09 +02002142 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2143 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002144
Martin Peschke698ec0162008-03-27 14:22:02 +01002145 zfcp_fsf_link_down_info_eval(fsf_req, 42,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002146 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 break;
2148 default:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002149 zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 return -EIO;
2151 }
2152 return 0;
2153}
2154
2155/**
2156 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002157 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 */
2159int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002160zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
2162 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002163 struct zfcp_fsf_req *fsf_req;
2164 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002165 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002166 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002168 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002170 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002172 return -EOPNOTSUPP;
2173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 /* setup new FSF request */
2176 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002177 ZFCP_REQ_AUTO_CLEANUP,
2178 adapter->pool.fsf_req_erp,
2179 &lock_flags, &fsf_req);
2180 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002182 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002183 "the adapter %s.\n",
2184 zfcp_get_busid_by_adapter(adapter));
2185 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2186 lock_flags);
2187 return retval;
2188 }
2189
2190 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2191 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2192 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2193
2194 erp_action->fsf_req = fsf_req;
2195 fsf_req->erp_action = erp_action;
2196 zfcp_erp_start_timer(fsf_req);
2197
2198 retval = zfcp_fsf_req_send(fsf_req);
2199 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2200
2201 if (retval) {
2202 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2203 "command on the adapter %s\n",
2204 zfcp_get_busid_by_adapter(adapter));
2205 zfcp_fsf_req_free(fsf_req);
2206 erp_action->fsf_req = NULL;
2207 }
2208 else
2209 ZFCP_LOG_DEBUG("exchange port data request initiated "
2210 "(adapter %s)\n",
2211 zfcp_get_busid_by_adapter(adapter));
2212 return retval;
2213}
2214
2215
2216/**
2217 * zfcp_fsf_exchange_port_data_sync - request information about local port
2218 * and wait until information is ready
2219 */
2220int
2221zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2222 struct fsf_qtcb_bottom_port *data)
2223{
2224 volatile struct qdio_buffer_element *sbale;
2225 struct zfcp_fsf_req *fsf_req;
2226 unsigned long lock_flags;
2227 int retval;
2228
2229 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2230 ZFCP_LOG_INFO("error: exchange port data "
2231 "command not supported by adapter %s\n",
2232 zfcp_get_busid_by_adapter(adapter));
2233 return -EOPNOTSUPP;
2234 }
2235
2236 /* setup new FSF request */
2237 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2238 0, NULL, &lock_flags, &fsf_req);
2239 if (retval) {
2240 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002241 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002242 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 zfcp_get_busid_by_adapter(adapter));
2244 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2245 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002246 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002247 }
2248
2249 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002250 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002251
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002253 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2254 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Swen Schillig52ef11a2007-08-28 09:31:09 +02002256 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002257 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002258 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Swen Schillig52ef11a2007-08-28 09:31:09 +02002260 if (retval)
2261 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2262 "command on the adapter %s\n",
2263 zfcp_get_busid_by_adapter(adapter));
2264 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002265 wait_event(fsf_req->completion_wq,
2266 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002267
2268 zfcp_fsf_req_free(fsf_req);
2269
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 return retval;
2271}
2272
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002273/**
2274 * zfcp_fsf_exchange_port_evaluate
2275 * @fsf_req: fsf_req which belongs to xchg port data request
2276 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2277 */
2278static void
2279zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2280{
2281 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002282 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002283 struct Scsi_Host *shost;
2284
2285 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002286 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002287 shost = adapter->scsi_host;
2288
Swen Schillig52ef11a2007-08-28 09:31:09 +02002289 if (fsf_req->data)
2290 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2291 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002292
2293 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2294 fc_host_permanent_port_name(shost) = bottom->wwpn;
2295 else
2296 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2297 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2298 fc_host_supported_speeds(shost) = bottom->supported_speed;
2299}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301/**
2302 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2303 * @fsf_req: pointer to struct zfcp_fsf_req
2304 */
2305static void
2306zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2307{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002308 struct zfcp_adapter *adapter;
2309 struct fsf_qtcb *qtcb;
2310
2311 adapter = fsf_req->adapter;
2312 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
2314 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2315 return;
2316
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002317 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002319 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002320 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002321 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002322 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002323 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002324 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Martin Peschke698ec0162008-03-27 14:22:02 +01002325 zfcp_fsf_link_down_info_eval(fsf_req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002326 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329}
2330
2331
2332/*
2333 * function: zfcp_fsf_open_port
2334 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002335 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 *
2337 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002338 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 */
2340int
2341zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2342{
2343 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002344 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 unsigned long lock_flags;
2346 int retval = 0;
2347
2348 /* setup new FSF request */
2349 retval = zfcp_fsf_req_create(erp_action->adapter,
2350 FSF_QTCB_OPEN_PORT_WITH_DID,
2351 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2352 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002353 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 if (retval < 0) {
2355 ZFCP_LOG_INFO("error: Could not create open port request "
2356 "for port 0x%016Lx on adapter %s.\n",
2357 erp_action->port->wwpn,
2358 zfcp_get_busid_by_adapter(erp_action->adapter));
2359 goto out;
2360 }
2361
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002362 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2364 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2365
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002366 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002368 fsf_req->data = (unsigned long) erp_action->port;
2369 fsf_req->erp_action = erp_action;
2370 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002372 zfcp_erp_start_timer(fsf_req);
2373 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 if (retval) {
2375 ZFCP_LOG_INFO("error: Could not send open port request for "
2376 "port 0x%016Lx on adapter %s.\n",
2377 erp_action->port->wwpn,
2378 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002379 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 erp_action->fsf_req = NULL;
2381 goto out;
2382 }
2383
2384 ZFCP_LOG_DEBUG("open port request initiated "
2385 "(adapter %s, port 0x%016Lx)\n",
2386 zfcp_get_busid_by_adapter(erp_action->adapter),
2387 erp_action->port->wwpn);
2388 out:
2389 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2390 lock_flags);
2391 return retval;
2392}
2393
2394/*
2395 * function: zfcp_fsf_open_port_handler
2396 *
2397 * purpose: is called for finished Open Port command
2398 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002399 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 */
2401static int
2402zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2403{
2404 int retval = -EINVAL;
2405 struct zfcp_port *port;
2406 struct fsf_plogi *plogi;
2407 struct fsf_qtcb_header *header;
2408 u16 subtable, rule, counter;
2409
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002410 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 header = &fsf_req->qtcb->header;
2412
2413 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2414 /* don't change port status in our bookkeeping */
2415 goto skip_fsfstatus;
2416 }
2417
2418 /* evaluate FSF status in QTCB */
2419 switch (header->fsf_status) {
2420
2421 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2423 "is already open.\n",
2424 port->wwpn, zfcp_get_busid_by_port(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 /*
2426 * This is a bug, however operation should continue normally
2427 * if it is simply ignored
2428 */
2429 break;
2430
2431 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2433 "on adapter %s\n",
2434 port->wwpn, zfcp_get_busid_by_port(port));
2435 for (counter = 0; counter < 2; counter++) {
2436 subtable = header->fsf_status_qual.halfword[counter * 2];
2437 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2438 switch (subtable) {
2439 case FSF_SQ_CFDC_SUBTABLE_OS:
2440 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2441 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2442 case FSF_SQ_CFDC_SUBTABLE_LUN:
2443 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2444 zfcp_act_subtable_type[subtable], rule);
2445 break;
2446 }
2447 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02002448 zfcp_erp_port_access_denied(port, 57, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2450 break;
2451
2452 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2454 "The remote port 0x%016Lx on adapter %s "
2455 "could not be opened. Disabling it.\n",
2456 port->wwpn, zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002457 zfcp_erp_port_failed(port, 31, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2459 break;
2460
2461 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 switch (header->fsf_status_qual.word[0]) {
2463 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 /* ERP strategy will escalate */
2465 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2466 break;
2467 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2468 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2470 break;
2471 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2473 "adapter %s could not be opened. "
2474 "Disabling it.\n",
2475 port->wwpn,
2476 zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002477 zfcp_erp_port_failed(port, 32, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2479 break;
2480 default:
2481 ZFCP_LOG_NORMAL
2482 ("bug: Wrong status qualifier 0x%x arrived.\n",
2483 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 break;
2485 }
2486 break;
2487
2488 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 /* save port handle assigned by FSF */
2490 port->handle = header->port_handle;
2491 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2492 "was opened, it's port handle is 0x%x\n",
2493 port->wwpn, zfcp_get_busid_by_port(port),
2494 port->handle);
2495 /* mark port as open */
2496 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2497 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002498 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2499 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2500 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 retval = 0;
2502 /* check whether D_ID has changed during open */
2503 /*
2504 * FIXME: This check is not airtight, as the FCP channel does
2505 * not monitor closures of target port connections caused on
2506 * the remote side. Thus, they might miss out on invalidating
2507 * locally cached WWPNs (and other N_Port parameters) of gone
2508 * target ports. So, our heroic attempt to make things safe
2509 * could be undermined by 'open port' response data tagged with
2510 * obsolete WWPNs. Another reason to monitor potential
2511 * connection closures ourself at least (by interpreting
2512 * incoming ELS' and unsolicited status). It just crosses my
2513 * mind that one should be able to cross-check by means of
2514 * another GID_PN straight after a port has been opened.
2515 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2516 */
2517 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2518 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2519 {
2520 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002521 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 ZFCP_LOG_INFO(
2523 "warning: insufficient length of "
2524 "PLOGI payload (%i)\n",
2525 fsf_req->qtcb->bottom.support.els1_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 /* skip sanity check and assume wwpn is ok */
2527 } else {
2528 if (plogi->serv_param.wwpn != port->wwpn) {
2529 ZFCP_LOG_INFO("warning: d_id of port "
2530 "0x%016Lx changed during "
2531 "open\n", port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 atomic_clear_mask(
2533 ZFCP_STATUS_PORT_DID_DID,
2534 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002535 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002537 zfcp_plogi_evaluate(port, plogi);
2538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 }
2540 }
2541 break;
2542
2543 case FSF_UNKNOWN_OP_SUBTYPE:
2544 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2546 "op_subtype=0x%x)\n",
2547 zfcp_get_busid_by_port(port),
2548 fsf_req->qtcb->bottom.support.operation_subtype);
2549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2550 break;
2551
2552 default:
2553 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2554 "(debug info 0x%x)\n",
2555 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 break;
2557 }
2558
2559 skip_fsfstatus:
2560 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2561 return retval;
2562}
2563
2564/*
2565 * function: zfcp_fsf_close_port
2566 *
2567 * purpose: submit FSF command "close port"
2568 *
2569 * returns: address of initiated FSF request
2570 * NULL - request could not be initiated
2571 */
2572int
2573zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2574{
2575 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002576 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 unsigned long lock_flags;
2578 int retval = 0;
2579
2580 /* setup new FSF request */
2581 retval = zfcp_fsf_req_create(erp_action->adapter,
2582 FSF_QTCB_CLOSE_PORT,
2583 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2584 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002585 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 if (retval < 0) {
2587 ZFCP_LOG_INFO("error: Could not create a close port request "
2588 "for port 0x%016Lx on adapter %s.\n",
2589 erp_action->port->wwpn,
2590 zfcp_get_busid_by_adapter(erp_action->adapter));
2591 goto out;
2592 }
2593
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002594 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2596 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2597
2598 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002599 fsf_req->data = (unsigned long) erp_action->port;
2600 fsf_req->erp_action = erp_action;
2601 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2602 fsf_req->erp_action = erp_action;
2603 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002605 zfcp_erp_start_timer(fsf_req);
2606 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 if (retval) {
2608 ZFCP_LOG_INFO("error: Could not send a close port request for "
2609 "port 0x%016Lx on adapter %s.\n",
2610 erp_action->port->wwpn,
2611 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002612 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 erp_action->fsf_req = NULL;
2614 goto out;
2615 }
2616
2617 ZFCP_LOG_TRACE("close port request initiated "
2618 "(adapter %s, port 0x%016Lx)\n",
2619 zfcp_get_busid_by_adapter(erp_action->adapter),
2620 erp_action->port->wwpn);
2621 out:
2622 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2623 lock_flags);
2624 return retval;
2625}
2626
2627/*
2628 * function: zfcp_fsf_close_port_handler
2629 *
2630 * purpose: is called for finished Close Port FSF command
2631 *
2632 * returns:
2633 */
2634static int
2635zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2636{
2637 int retval = -EINVAL;
2638 struct zfcp_port *port;
2639
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002640 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
2642 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2643 /* don't change port status in our bookkeeping */
2644 goto skip_fsfstatus;
2645 }
2646
2647 /* evaluate FSF status in QTCB */
2648 switch (fsf_req->qtcb->header.fsf_status) {
2649
2650 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2652 "0x%016Lx on adapter %s invalid. This may happen "
2653 "occasionally.\n", port->handle,
2654 port->wwpn, zfcp_get_busid_by_port(port));
2655 ZFCP_LOG_DEBUG("status qualifier:\n");
2656 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2657 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2658 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002659 zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2661 break;
2662
2663 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 /* Note: FSF has actually closed the port in this case.
2665 * The status code is just daft. Fingers crossed for a change
2666 */
2667 retval = 0;
2668 break;
2669
2670 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2672 "port handle 0x%x\n", port->wwpn,
2673 zfcp_get_busid_by_port(port), port->handle);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002674 zfcp_erp_modify_port_status(port, 33, fsf_req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 ZFCP_STATUS_COMMON_OPEN,
2676 ZFCP_CLEAR);
2677 retval = 0;
2678 break;
2679
2680 default:
2681 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2682 "(debug info 0x%x)\n",
2683 fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 break;
2685 }
2686
2687 skip_fsfstatus:
2688 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2689 return retval;
2690}
2691
2692/*
2693 * function: zfcp_fsf_close_physical_port
2694 *
2695 * purpose: submit FSF command "close physical port"
2696 *
2697 * returns: address of initiated FSF request
2698 * NULL - request could not be initiated
2699 */
2700int
2701zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2702{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002704 struct zfcp_fsf_req *fsf_req;
2705 unsigned long lock_flags;
2706 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
2708 /* setup new FSF request */
2709 retval = zfcp_fsf_req_create(erp_action->adapter,
2710 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2711 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2712 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002713 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 if (retval < 0) {
2715 ZFCP_LOG_INFO("error: Could not create close physical port "
2716 "request (adapter %s, port 0x%016Lx)\n",
2717 zfcp_get_busid_by_adapter(erp_action->adapter),
2718 erp_action->port->wwpn);
2719
2720 goto out;
2721 }
2722
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002723 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2725 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2726
2727 /* mark port as being closed */
2728 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2729 &erp_action->port->status);
2730 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002731 fsf_req->data = (unsigned long) erp_action->port;
2732 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2733 fsf_req->erp_action = erp_action;
2734 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002736 zfcp_erp_start_timer(fsf_req);
2737 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 if (retval) {
2739 ZFCP_LOG_INFO("error: Could not send close physical port "
2740 "request (adapter %s, port 0x%016Lx)\n",
2741 zfcp_get_busid_by_adapter(erp_action->adapter),
2742 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002743 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 erp_action->fsf_req = NULL;
2745 goto out;
2746 }
2747
2748 ZFCP_LOG_TRACE("close physical port request initiated "
2749 "(adapter %s, port 0x%016Lx)\n",
2750 zfcp_get_busid_by_adapter(erp_action->adapter),
2751 erp_action->port->wwpn);
2752 out:
2753 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2754 lock_flags);
2755 return retval;
2756}
2757
2758/*
2759 * function: zfcp_fsf_close_physical_port_handler
2760 *
2761 * purpose: is called for finished Close Physical Port FSF command
2762 *
2763 * returns:
2764 */
2765static int
2766zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2767{
2768 int retval = -EINVAL;
2769 struct zfcp_port *port;
2770 struct zfcp_unit *unit;
2771 struct fsf_qtcb_header *header;
2772 u16 subtable, rule, counter;
2773
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002774 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 header = &fsf_req->qtcb->header;
2776
2777 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2778 /* don't change port status in our bookkeeping */
2779 goto skip_fsfstatus;
2780 }
2781
2782 /* evaluate FSF status in QTCB */
2783 switch (header->fsf_status) {
2784
2785 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2787 "(adapter %s, port 0x%016Lx). "
2788 "This may happen occasionally.\n",
2789 port->handle,
2790 zfcp_get_busid_by_port(port),
2791 port->wwpn);
2792 ZFCP_LOG_DEBUG("status qualifier:\n");
2793 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2794 (char *) &header->fsf_status_qual,
2795 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002796 zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2798 break;
2799
2800 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 ZFCP_LOG_NORMAL("Access denied, cannot close "
2802 "physical port 0x%016Lx on adapter %s\n",
2803 port->wwpn, zfcp_get_busid_by_port(port));
2804 for (counter = 0; counter < 2; counter++) {
2805 subtable = header->fsf_status_qual.halfword[counter * 2];
2806 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2807 switch (subtable) {
2808 case FSF_SQ_CFDC_SUBTABLE_OS:
2809 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2810 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2811 case FSF_SQ_CFDC_SUBTABLE_LUN:
2812 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2813 zfcp_act_subtable_type[subtable], rule);
2814 break;
2815 }
2816 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02002817 zfcp_erp_port_access_denied(port, 58, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2819 break;
2820
2821 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2823 "%s needs to be reopened but it was attempted "
2824 "to close it physically.\n",
2825 port->wwpn,
2826 zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002827 zfcp_erp_port_boxed(port, 50, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2829 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01002830
2831 /* can't use generic zfcp_erp_modify_port_status because
2832 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2833 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2834 list_for_each_entry(unit, &port->unit_list_head, list)
2835 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2836 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 break;
2838
2839 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 switch (header->fsf_status_qual.word[0]) {
2841 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 /* This will now be escalated by ERP */
2843 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2844 break;
2845 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2848 break;
2849 default:
2850 ZFCP_LOG_NORMAL
2851 ("bug: Wrong status qualifier 0x%x arrived.\n",
2852 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 break;
2854 }
2855 break;
2856
2857 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2859 "physically closed, port handle 0x%x\n",
2860 port->wwpn,
2861 zfcp_get_busid_by_port(port), port->handle);
2862 /* can't use generic zfcp_erp_modify_port_status because
2863 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2864 */
2865 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2866 list_for_each_entry(unit, &port->unit_list_head, list)
2867 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2868 retval = 0;
2869 break;
2870
2871 default:
2872 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2873 "(debug info 0x%x)\n",
2874 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 break;
2876 }
2877
2878 skip_fsfstatus:
2879 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2880 return retval;
2881}
2882
2883/*
2884 * function: zfcp_fsf_open_unit
2885 *
2886 * purpose:
2887 *
2888 * returns:
2889 *
2890 * assumptions: This routine does not check whether the associated
2891 * remote port has already been opened. This should be
2892 * done by calling routines. Otherwise some status
2893 * may be presented by FSF
2894 */
2895int
2896zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2897{
2898 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002899 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 unsigned long lock_flags;
2901 int retval = 0;
2902
2903 /* setup new FSF request */
2904 retval = zfcp_fsf_req_create(erp_action->adapter,
2905 FSF_QTCB_OPEN_LUN,
2906 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2907 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002908 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 if (retval < 0) {
2910 ZFCP_LOG_INFO("error: Could not create open unit request for "
2911 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2912 erp_action->unit->fcp_lun,
2913 erp_action->unit->port->wwpn,
2914 zfcp_get_busid_by_adapter(erp_action->adapter));
2915 goto out;
2916 }
2917
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002918 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2920 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2921
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002922 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2923 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002924 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002925 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02002926 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002928 fsf_req->data = (unsigned long) erp_action->unit;
2929 fsf_req->erp_action = erp_action;
2930 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002932 zfcp_erp_start_timer(fsf_req);
2933 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 if (retval) {
2935 ZFCP_LOG_INFO("error: Could not send an open unit request "
2936 "on the adapter %s, port 0x%016Lx for "
2937 "unit 0x%016Lx\n",
2938 zfcp_get_busid_by_adapter(erp_action->adapter),
2939 erp_action->port->wwpn,
2940 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002941 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 erp_action->fsf_req = NULL;
2943 goto out;
2944 }
2945
2946 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2947 "port 0x%016Lx, unit 0x%016Lx)\n",
2948 zfcp_get_busid_by_adapter(erp_action->adapter),
2949 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2950 out:
2951 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2952 lock_flags);
2953 return retval;
2954}
2955
2956/*
2957 * function: zfcp_fsf_open_unit_handler
2958 *
2959 * purpose: is called for finished Open LUN command
2960 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002961 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 */
2963static int
2964zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2965{
2966 int retval = -EINVAL;
2967 struct zfcp_adapter *adapter;
2968 struct zfcp_unit *unit;
2969 struct fsf_qtcb_header *header;
2970 struct fsf_qtcb_bottom_support *bottom;
2971 struct fsf_queue_designator *queue_designator;
2972 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002973 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002975 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
2977 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2978 /* don't change unit status in our bookkeeping */
2979 goto skip_fsfstatus;
2980 }
2981
2982 adapter = fsf_req->adapter;
2983 header = &fsf_req->qtcb->header;
2984 bottom = &fsf_req->qtcb->bottom.support;
2985 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2986
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02002988 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 ZFCP_STATUS_UNIT_SHARED |
2990 ZFCP_STATUS_UNIT_READONLY,
2991 &unit->status);
2992
2993 /* evaluate FSF status in QTCB */
2994 switch (header->fsf_status) {
2995
2996 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
2998 "for port 0x%016Lx on adapter %s invalid "
2999 "This may happen occasionally\n",
3000 unit->port->handle,
3001 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3002 ZFCP_LOG_DEBUG("status qualifier:\n");
3003 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3004 (char *) &header->fsf_status_qual,
3005 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003006 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3008 break;
3009
3010 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3012 "remote port 0x%016Lx on adapter %s twice.\n",
3013 unit->fcp_lun,
3014 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3016 break;
3017
3018 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3020 "remote port 0x%016Lx on adapter %s\n",
3021 unit->fcp_lun, unit->port->wwpn,
3022 zfcp_get_busid_by_unit(unit));
3023 for (counter = 0; counter < 2; counter++) {
3024 subtable = header->fsf_status_qual.halfword[counter * 2];
3025 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3026 switch (subtable) {
3027 case FSF_SQ_CFDC_SUBTABLE_OS:
3028 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3029 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3030 case FSF_SQ_CFDC_SUBTABLE_LUN:
3031 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3032 zfcp_act_subtable_type[subtable], rule);
3033 break;
3034 }
3035 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02003036 zfcp_erp_unit_access_denied(unit, 59, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3038 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3039 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3040 break;
3041
3042 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3044 "needs to be reopened\n",
3045 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003046 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3048 ZFCP_STATUS_FSFREQ_RETRY;
3049 break;
3050
3051 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 if (header->fsf_status_qual.word[0] != 0) {
3053 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3054 "with WWPN 0x%Lx "
3055 "connected to the adapter %s "
3056 "is already in use in LPAR%d, CSS%d\n",
3057 unit->fcp_lun,
3058 unit->port->wwpn,
3059 zfcp_get_busid_by_unit(unit),
3060 queue_designator->hla,
3061 queue_designator->cssid);
3062 } else {
3063 subtable = header->fsf_status_qual.halfword[4];
3064 rule = header->fsf_status_qual.halfword[5];
3065 switch (subtable) {
3066 case FSF_SQ_CFDC_SUBTABLE_OS:
3067 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3068 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3069 case FSF_SQ_CFDC_SUBTABLE_LUN:
3070 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3071 "remote port with WWPN 0x%Lx "
3072 "connected to the adapter %s "
3073 "is denied (%s rule %d)\n",
3074 unit->fcp_lun,
3075 unit->port->wwpn,
3076 zfcp_get_busid_by_unit(unit),
3077 zfcp_act_subtable_type[subtable],
3078 rule);
3079 break;
3080 }
3081 }
3082 ZFCP_LOG_DEBUG("status qualifier:\n");
3083 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3084 (char *) &header->fsf_status_qual,
3085 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003086 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3088 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3089 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3090 break;
3091
3092 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3094 "There is no handle (temporary port identifier) "
3095 "available for unit 0x%016Lx on port 0x%016Lx "
3096 "on adapter %s\n",
3097 unit->fcp_lun,
3098 unit->port->wwpn,
3099 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003100 zfcp_erp_unit_failed(unit, 34, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3102 break;
3103
3104 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 switch (header->fsf_status_qual.word[0]) {
3106 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 /* Re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003108 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3110 break;
3111 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3114 break;
3115 default:
3116 ZFCP_LOG_NORMAL
3117 ("bug: Wrong status qualifier 0x%x arrived.\n",
3118 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 }
3120 break;
3121
3122 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 ZFCP_LOG_NORMAL(
3124 "Invalid option 0x%x has been specified "
3125 "in QTCB bottom sent to the adapter %s\n",
3126 bottom->option,
3127 zfcp_get_busid_by_adapter(adapter));
3128 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3129 retval = -EINVAL;
3130 break;
3131
3132 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 /* save LUN handle assigned by FSF */
3134 unit->handle = header->lun_handle;
3135 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3136 "adapter %s opened, port handle 0x%x\n",
3137 unit->fcp_lun,
3138 unit->port->wwpn,
3139 zfcp_get_busid_by_unit(unit),
3140 unit->handle);
3141 /* mark unit as open */
3142 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003143
3144 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3145 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3146 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3147 exclusive = (bottom->lun_access_info &
3148 FSF_UNIT_ACCESS_EXCLUSIVE);
3149 readwrite = (bottom->lun_access_info &
3150 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3151
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 if (!exclusive)
3153 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3154 &unit->status);
3155
3156 if (!readwrite) {
3157 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3158 &unit->status);
3159 ZFCP_LOG_NORMAL("read-only access for unit "
3160 "(adapter %s, wwpn=0x%016Lx, "
3161 "fcp_lun=0x%016Lx)\n",
3162 zfcp_get_busid_by_unit(unit),
3163 unit->port->wwpn,
3164 unit->fcp_lun);
3165 }
3166
3167 if (exclusive && !readwrite) {
3168 ZFCP_LOG_NORMAL("exclusive access of read-only "
3169 "unit not supported\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02003170 zfcp_erp_unit_failed(unit, 35, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003172 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 } else if (!exclusive && readwrite) {
3174 ZFCP_LOG_NORMAL("shared access of read-write "
3175 "unit not supported\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02003176 zfcp_erp_unit_failed(unit, 36, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003178 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 }
3180 }
3181
3182 retval = 0;
3183 break;
3184
3185 default:
3186 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3187 "(debug info 0x%x)\n",
3188 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 break;
3190 }
3191
3192 skip_fsfstatus:
3193 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3194 return retval;
3195}
3196
3197/*
3198 * function: zfcp_fsf_close_unit
3199 *
3200 * purpose:
3201 *
3202 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003203 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 *
3205 * assumptions: This routine does not check whether the associated
3206 * remote port/lun has already been opened. This should be
3207 * done by calling routines. Otherwise some status
3208 * may be presented by FSF
3209 */
3210int
3211zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3212{
3213 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003214 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 unsigned long lock_flags;
3216 int retval = 0;
3217
3218 /* setup new FSF request */
3219 retval = zfcp_fsf_req_create(erp_action->adapter,
3220 FSF_QTCB_CLOSE_LUN,
3221 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3222 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003223 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 if (retval < 0) {
3225 ZFCP_LOG_INFO("error: Could not create close unit request for "
3226 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3227 erp_action->unit->fcp_lun,
3228 erp_action->port->wwpn,
3229 zfcp_get_busid_by_adapter(erp_action->adapter));
3230 goto out;
3231 }
3232
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003233 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3235 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3236
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003237 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3238 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003240 fsf_req->data = (unsigned long) erp_action->unit;
3241 fsf_req->erp_action = erp_action;
3242 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003244 zfcp_erp_start_timer(fsf_req);
3245 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 if (retval) {
3247 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3248 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3249 erp_action->unit->fcp_lun,
3250 erp_action->port->wwpn,
3251 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003252 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 erp_action->fsf_req = NULL;
3254 goto out;
3255 }
3256
3257 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3258 "port 0x%016Lx, unit 0x%016Lx)\n",
3259 zfcp_get_busid_by_adapter(erp_action->adapter),
3260 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3261 out:
3262 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3263 lock_flags);
3264 return retval;
3265}
3266
3267/*
3268 * function: zfcp_fsf_close_unit_handler
3269 *
3270 * purpose: is called for finished Close LUN FSF command
3271 *
3272 * returns:
3273 */
3274static int
3275zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3276{
3277 int retval = -EINVAL;
3278 struct zfcp_unit *unit;
3279
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003280 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
3282 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3283 /* don't change unit status in our bookkeeping */
3284 goto skip_fsfstatus;
3285 }
3286
3287 /* evaluate FSF status in QTCB */
3288 switch (fsf_req->qtcb->header.fsf_status) {
3289
3290 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3292 "0x%016Lx on adapter %s invalid. This may "
3293 "happen in rare circumstances\n",
3294 unit->port->handle,
3295 unit->port->wwpn,
3296 zfcp_get_busid_by_unit(unit));
3297 ZFCP_LOG_DEBUG("status qualifier:\n");
3298 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3299 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3300 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003301 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3303 break;
3304
3305 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3307 "0x%016Lx on port 0x%016Lx on adapter %s is "
3308 "invalid. This may happen occasionally.\n",
3309 unit->handle,
3310 unit->fcp_lun,
3311 unit->port->wwpn,
3312 zfcp_get_busid_by_unit(unit));
3313 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3314 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3315 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3316 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003317 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3319 break;
3320
3321 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3323 "needs to be reopened\n",
3324 unit->port->wwpn,
3325 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003326 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3328 ZFCP_STATUS_FSFREQ_RETRY;
3329 break;
3330
3331 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3333 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003335 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3337 break;
3338 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3341 break;
3342 default:
3343 ZFCP_LOG_NORMAL
3344 ("bug: Wrong status qualifier 0x%x arrived.\n",
3345 fsf_req->qtcb->header.fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 break;
3347 }
3348 break;
3349
3350 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3352 "closed, port handle 0x%x\n",
3353 unit->fcp_lun,
3354 unit->port->wwpn,
3355 zfcp_get_busid_by_unit(unit),
3356 unit->handle);
3357 /* mark unit as closed */
3358 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3359 retval = 0;
3360 break;
3361
3362 default:
3363 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3364 "(debug info 0x%x)\n",
3365 fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 break;
3367 }
3368
3369 skip_fsfstatus:
3370 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3371 return retval;
3372}
3373
3374/**
3375 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3376 * @adapter: adapter where scsi command is issued
3377 * @unit: unit where command is sent to
3378 * @scsi_cmnd: scsi command to be sent
3379 * @timer: timer to be started when request is initiated
3380 * @req_flags: flags for fsf_request
3381 */
3382int
3383zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3384 struct zfcp_unit *unit,
3385 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003386 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387{
3388 struct zfcp_fsf_req *fsf_req = NULL;
3389 struct fcp_cmnd_iu *fcp_cmnd_iu;
3390 unsigned int sbtype;
3391 unsigned long lock_flags;
3392 int real_bytes = 0;
3393 int retval = 0;
3394 int mask;
3395
3396 /* setup new FSF request */
3397 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3398 adapter->pool.fsf_req_scsi,
3399 &lock_flags, &fsf_req);
3400 if (unlikely(retval < 0)) {
3401 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3402 "for unit 0x%016Lx on port 0x%016Lx on "
3403 "adapter %s\n",
3404 unit->fcp_lun,
3405 unit->port->wwpn,
3406 zfcp_get_busid_by_adapter(adapter));
3407 goto failed_req_create;
3408 }
3409
Christof Schmittba172422007-12-20 12:30:26 +01003410 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3411 &unit->status))) {
3412 retval = -EBUSY;
3413 goto unit_blocked;
3414 }
3415
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003416 zfcp_unit_get(unit);
3417 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003419 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003420 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003421
3422 /* associate SCSI command with FSF request */
3423 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
3425 /* set handles of unit and its parent port in QTCB */
3426 fsf_req->qtcb->header.lun_handle = unit->handle;
3427 fsf_req->qtcb->header.port_handle = unit->port->handle;
3428
3429 /* FSF does not define the structure of the FCP_CMND IU */
3430 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3431 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3432
3433 /*
3434 * set depending on data direction:
3435 * data direction bits in SBALE (SB Type)
3436 * data direction bits in QTCB
3437 * data direction bits in FCP_CMND IU
3438 */
3439 switch (scsi_cmnd->sc_data_direction) {
3440 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3442 /*
3443 * FIXME(qdio):
3444 * what is the correct type for commands
3445 * without 'real' data buffers?
3446 */
3447 sbtype = SBAL_FLAGS0_TYPE_READ;
3448 break;
3449 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3451 sbtype = SBAL_FLAGS0_TYPE_READ;
3452 fcp_cmnd_iu->rddata = 1;
3453 break;
3454 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3456 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3457 fcp_cmnd_iu->wddata = 1;
3458 break;
3459 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 default:
3461 /*
3462 * dummy, catch this condition earlier
3463 * in zfcp_scsi_queuecommand
3464 */
3465 goto failed_scsi_cmnd;
3466 }
3467
3468 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003469 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
3471 /* set FCP_LUN in FCP_CMND IU in QTCB */
3472 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3473
3474 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3475
3476 /* set task attributes in FCP_CMND IU in QTCB */
3477 if (likely((scsi_cmnd->device->simple_tags) ||
3478 (atomic_test_mask(mask, &unit->status))))
3479 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3480 else
3481 fcp_cmnd_iu->task_attribute = UNTAGGED;
3482
3483 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3484 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3485 fcp_cmnd_iu->add_fcp_cdb_length
3486 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3487 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3488 "additional FCP_CDB length is 0x%x "
3489 "(shifted right 2 bits)\n",
3490 scsi_cmnd->cmd_len,
3491 fcp_cmnd_iu->add_fcp_cdb_length);
3492 }
3493 /*
3494 * copy SCSI CDB (including additional length, if any) to
3495 * FCP_CDB in FCP_CMND IU in QTCB
3496 */
3497 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3498
3499 /* FCP CMND IU length in QTCB */
3500 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3501 sizeof (struct fcp_cmnd_iu) +
3502 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3503
3504 /* generate SBALEs from data buffer */
3505 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3506 if (unlikely(real_bytes < 0)) {
3507 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3508 ZFCP_LOG_DEBUG(
3509 "Data did not fit into available buffer(s), "
3510 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003511 retval = -EIO;
3512 } else {
3513 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3514 "required. Shutting down unit "
3515 "(adapter %s, port 0x%016Lx, "
3516 "unit 0x%016Lx)\n",
3517 zfcp_get_busid_by_unit(unit),
3518 unit->port->wwpn,
3519 unit->fcp_lun);
Martin Peschke1f6f7122008-04-18 12:51:55 +02003520 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
Christof Schmitt2282f652007-08-28 09:30:22 +02003521 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 }
3523 goto no_fit;
3524 }
3525
3526 /* set length of FCP data length in FCP_CMND IU in QTCB */
3527 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3528
3529 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3530 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3531 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3532
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003533 if (use_timer)
3534 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3535
3536 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 if (unlikely(retval < 0)) {
3538 ZFCP_LOG_INFO("error: Could not send FCP command request "
3539 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3540 zfcp_get_busid_by_adapter(adapter),
3541 unit->port->wwpn,
3542 unit->fcp_lun);
3543 goto send_failed;
3544 }
3545
3546 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3547 "port 0x%016Lx, unit 0x%016Lx)\n",
3548 zfcp_get_busid_by_adapter(adapter),
3549 unit->port->wwpn,
3550 unit->fcp_lun);
3551 goto success;
3552
3553 send_failed:
3554 no_fit:
3555 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003556 zfcp_unit_put(unit);
Christof Schmitt57b76582008-04-18 12:51:57 +02003557 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 zfcp_fsf_req_free(fsf_req);
3559 fsf_req = NULL;
3560 scsi_cmnd->host_scribble = NULL;
3561 success:
3562 failed_req_create:
3563 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3564 return retval;
3565}
3566
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567struct zfcp_fsf_req *
3568zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3569 struct zfcp_unit *unit,
3570 u8 tm_flags, int req_flags)
3571{
3572 struct zfcp_fsf_req *fsf_req = NULL;
3573 int retval = 0;
3574 struct fcp_cmnd_iu *fcp_cmnd_iu;
3575 unsigned long lock_flags;
3576 volatile struct qdio_buffer_element *sbale;
3577
3578 /* setup new FSF request */
3579 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3580 adapter->pool.fsf_req_scsi,
3581 &lock_flags, &fsf_req);
3582 if (retval < 0) {
3583 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3584 "management) request for adapter %s, port "
3585 " 0x%016Lx, unit 0x%016Lx.\n",
3586 zfcp_get_busid_by_adapter(adapter),
3587 unit->port->wwpn, unit->fcp_lun);
3588 goto out;
3589 }
3590
Christof Schmittfdf23452007-12-20 12:30:27 +01003591 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3592 &unit->status)))
3593 goto unit_blocked;
3594
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 /*
3596 * Used to decide on proper handler in the return path,
3597 * could be either zfcp_fsf_send_fcp_command_task_handler or
3598 * zfcp_fsf_send_fcp_command_task_management_handler */
3599
3600 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3601
3602 /*
3603 * hold a pointer to the unit being target of this
3604 * task management request
3605 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003606 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607
3608 /* set FSF related fields in QTCB */
3609 fsf_req->qtcb->header.lun_handle = unit->handle;
3610 fsf_req->qtcb->header.port_handle = unit->port->handle;
3611 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003612 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3614 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3615
3616 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3617 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3618 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3619
3620 /* set FCP related fields in FCP_CMND IU in QTCB */
3621 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3622 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3623 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3624 fcp_cmnd_iu->task_management_flags = tm_flags;
3625
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003626 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3627 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmittfdf23452007-12-20 12:30:27 +01003628 if (!retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
Christof Schmittfdf23452007-12-20 12:30:27 +01003631 unit_blocked:
3632 zfcp_fsf_req_free(fsf_req);
3633 fsf_req = NULL;
3634
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 out:
3636 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3637 return fsf_req;
3638}
3639
Christof Schmittc9615852008-05-06 11:00:05 +02003640static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
3641{
3642 lat_rec->sum += lat;
3643 if (lat_rec->min > lat)
3644 lat_rec->min = lat;
3645 if (lat_rec->max < lat)
3646 lat_rec->max = lat;
3647}
3648
3649static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
3650{
3651 struct fsf_qual_latency_info *lat_inf;
3652 struct latency_cont *lat;
3653 struct zfcp_unit *unit;
3654 unsigned long flags;
3655
3656 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
3657 unit = fsf_req->unit;
3658
3659 switch (fsf_req->qtcb->bottom.io.data_direction) {
3660 case FSF_DATADIR_READ:
3661 lat = &unit->latencies.read;
3662 break;
3663 case FSF_DATADIR_WRITE:
3664 lat = &unit->latencies.write;
3665 break;
3666 case FSF_DATADIR_CMND:
3667 lat = &unit->latencies.cmd;
3668 break;
3669 default:
3670 return;
3671 }
3672
3673 spin_lock_irqsave(&unit->latencies.lock, flags);
3674 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
3675 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
3676 lat->counter++;
3677 spin_unlock_irqrestore(&unit->latencies.lock, flags);
3678}
3679
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680/*
3681 * function: zfcp_fsf_send_fcp_command_handler
3682 *
3683 * purpose: is called for finished Send FCP Command
3684 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003685 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 */
3687static int
3688zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3689{
3690 int retval = -EINVAL;
3691 struct zfcp_unit *unit;
3692 struct fsf_qtcb_header *header;
3693 u16 subtable, rule, counter;
3694
3695 header = &fsf_req->qtcb->header;
3696
3697 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003698 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003700 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
3702 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3703 /* go directly to calls of special handlers */
3704 goto skip_fsfstatus;
3705 }
3706
3707 /* evaluate FSF status in QTCB */
3708 switch (header->fsf_status) {
3709
3710 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3712 "0x%016Lx on adapter %s invalid\n",
3713 unit->port->handle,
3714 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3715 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3716 (char *) &header->fsf_status_qual,
3717 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003718 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3720 break;
3721
3722 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3724 "0x%016Lx on port 0x%016Lx on adapter %s is "
3725 "invalid. This may happen occasionally.\n",
3726 unit->handle,
3727 unit->fcp_lun,
3728 unit->port->wwpn,
3729 zfcp_get_busid_by_unit(unit));
3730 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3731 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3732 (char *) &header->fsf_status_qual,
3733 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003734 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3736 break;
3737
3738 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3740 "unexpectedly. (adapter %s, port 0x%016Lx, "
3741 "unit 0x%016Lx)\n",
3742 unit->port->handle,
3743 zfcp_get_busid_by_unit(unit),
3744 unit->port->wwpn,
3745 unit->fcp_lun);
3746 ZFCP_LOG_NORMAL("status qualifier:\n");
3747 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3748 (char *) &header->fsf_status_qual,
3749 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003750 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3752 break;
3753
3754 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003755 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3756 "class %d.\n",
3757 zfcp_get_busid_by_unit(unit),
3758 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003760 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3762 break;
3763
3764 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3766 "adapter %s does not have correct unit "
3767 "handle 0x%x\n",
3768 unit->fcp_lun,
3769 unit->port->wwpn,
3770 zfcp_get_busid_by_unit(unit),
3771 unit->handle);
3772 ZFCP_LOG_DEBUG("status qualifier:\n");
3773 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3774 (char *) &header->fsf_status_qual,
3775 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003776 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3778 break;
3779
3780 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3782 "unit 0x%016Lx on port 0x%016Lx on "
3783 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3784 zfcp_get_busid_by_unit(unit));
3785 for (counter = 0; counter < 2; counter++) {
3786 subtable = header->fsf_status_qual.halfword[counter * 2];
3787 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3788 switch (subtable) {
3789 case FSF_SQ_CFDC_SUBTABLE_OS:
3790 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3791 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3792 case FSF_SQ_CFDC_SUBTABLE_LUN:
3793 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3794 zfcp_act_subtable_type[subtable], rule);
3795 break;
3796 }
3797 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02003798 zfcp_erp_unit_access_denied(unit, 61, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3800 break;
3801
3802 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3804 "0x%016Lx on port 0x%016Lx on adapter %s "
3805 "(debug info %d)\n",
3806 unit->fcp_lun,
3807 unit->port->wwpn,
3808 zfcp_get_busid_by_unit(unit),
3809 fsf_req->qtcb->bottom.io.data_direction);
3810 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003811 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3813 break;
3814
3815 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 ZFCP_LOG_NORMAL
3817 ("bug: An invalid control-data-block length field "
3818 "was found in a command for unit 0x%016Lx on port "
3819 "0x%016Lx on adapter %s " "(debug info %d)\n",
3820 unit->fcp_lun, unit->port->wwpn,
3821 zfcp_get_busid_by_unit(unit),
3822 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3823 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003824 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3826 break;
3827
3828 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3830 "needs to be reopened\n",
3831 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003832 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3834 ZFCP_STATUS_FSFREQ_RETRY;
3835 break;
3836
3837 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3839 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3840 zfcp_get_busid_by_unit(unit),
3841 unit->port->wwpn, unit->fcp_lun);
Martin Peschke1f6f7122008-04-18 12:51:55 +02003842 zfcp_erp_unit_boxed(unit, 54, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3844 | ZFCP_STATUS_FSFREQ_RETRY;
3845 break;
3846
3847 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 switch (header->fsf_status_qual.word[0]) {
3849 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003851 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 break;
3853 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 /* FIXME(hw) need proper specs for proper action */
3855 /* let scsi stack deal with retries and escalation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 break;
3857 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003859 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 break;
3862 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003863 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 break;
3865
3866 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 break;
3868
3869 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 }
3872
3873 skip_fsfstatus:
3874 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3875 retval =
3876 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3877 } else {
3878 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003879 fsf_req->unit = NULL;
3880 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 }
3882 return retval;
3883}
3884
3885/*
3886 * function: zfcp_fsf_send_fcp_command_task_handler
3887 *
3888 * purpose: evaluates FCP_RSP IU
3889 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003890 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 */
3892static int
3893zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3894{
3895 int retval = 0;
3896 struct scsi_cmnd *scpnt;
3897 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3898 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3899 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3900 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3901 u32 sns_len;
3902 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3903 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003904 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905
3906 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003907 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 if (unlikely(!scpnt)) {
3909 ZFCP_LOG_DEBUG
3910 ("Command with fsf_req %p is not associated to "
3911 "a scsi command anymore. Aborted?\n", fsf_req);
3912 goto out;
3913 }
3914 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3915 /* FIXME: (design) mid-layer should handle DID_ABORT like
3916 * DID_SOFT_ERROR by retrying the request for devices
3917 * that allow retries.
3918 */
3919 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3920 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3921 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3922 goto skip_fsfstatus;
3923 }
3924
3925 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3926 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3927 set_host_byte(&scpnt->result, DID_ERROR);
3928 goto skip_fsfstatus;
3929 }
3930
3931 /* set message byte of result in SCSI command */
3932 scpnt->result |= COMMAND_COMPLETE << 8;
3933
3934 /*
3935 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3936 * of result in SCSI command
3937 */
3938 scpnt->result |= fcp_rsp_iu->scsi_status;
3939 if (unlikely(fcp_rsp_iu->scsi_status)) {
3940 /* DEBUG */
3941 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
3942 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3943 scpnt->cmnd, scpnt->cmd_len);
3944 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
3945 fcp_rsp_iu->scsi_status);
3946 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3947 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
3948 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3949 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
3950 fcp_rsp_iu->fcp_sns_len);
3951 }
3952
Christof Schmittc9615852008-05-06 11:00:05 +02003953 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
3954 zfcp_fsf_req_latency(fsf_req);
3955
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 /* check FCP_RSP_INFO */
3957 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
3958 ZFCP_LOG_DEBUG("rsp_len is valid\n");
3959 switch (fcp_rsp_info[3]) {
3960 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 /* ok, continue */
3962 ZFCP_LOG_TRACE("no failure or Task Management "
3963 "Function complete\n");
3964 set_host_byte(&scpnt->result, DID_OK);
3965 break;
3966 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 /* hardware bug */
3968 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3969 "that the fibrechannel protocol data "
3970 "length differs from the burst length. "
3971 "The problem occured on unit 0x%016Lx "
3972 "on port 0x%016Lx on adapter %s",
3973 unit->fcp_lun,
3974 unit->port->wwpn,
3975 zfcp_get_busid_by_unit(unit));
3976 /* dump SCSI CDB as prepared by zfcp */
3977 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3978 (char *) &fsf_req->qtcb->
3979 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 set_host_byte(&scpnt->result, DID_ERROR);
3981 goto skip_fsfstatus;
3982 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 /* driver or hardware bug */
3984 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3985 "that the fibrechannel protocol data "
3986 "fields were incorrectly set up. "
3987 "The problem occured on the unit "
3988 "0x%016Lx on port 0x%016Lx on "
3989 "adapter %s",
3990 unit->fcp_lun,
3991 unit->port->wwpn,
3992 zfcp_get_busid_by_unit(unit));
3993 /* dump SCSI CDB as prepared by zfcp */
3994 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3995 (char *) &fsf_req->qtcb->
3996 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3997 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 goto skip_fsfstatus;
3999 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 /* hardware bug */
4001 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4002 "that conflicting values for the "
4003 "fibrechannel payload offset from the "
4004 "header were found. "
4005 "The problem occured on unit 0x%016Lx "
4006 "on port 0x%016Lx on adapter %s.\n",
4007 unit->fcp_lun,
4008 unit->port->wwpn,
4009 zfcp_get_busid_by_unit(unit));
4010 /* dump SCSI CDB as prepared by zfcp */
4011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4012 (char *) &fsf_req->qtcb->
4013 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 set_host_byte(&scpnt->result, DID_ERROR);
4015 goto skip_fsfstatus;
4016 default:
4017 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4018 "code was detected for a command. "
4019 "The problem occured on the unit "
4020 "0x%016Lx on port 0x%016Lx on "
4021 "adapter %s (debug info 0x%x)\n",
4022 unit->fcp_lun,
4023 unit->port->wwpn,
4024 zfcp_get_busid_by_unit(unit),
4025 fcp_rsp_info[3]);
4026 /* dump SCSI CDB as prepared by zfcp */
4027 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4028 (char *) &fsf_req->qtcb->
4029 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004031 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 }
4033 }
4034
4035 /* check for sense data */
4036 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4037 sns_len = FSF_FCP_RSP_SIZE -
4038 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4039 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4040 sns_len);
4041 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4042 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4043 SCSI_SENSE_BUFFERSIZE);
4044 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4045 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4046 scpnt->result);
4047 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
Boaz Harrosh64a87b22008-04-30 11:19:47 +03004048 scpnt->cmnd, scpnt->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049
4050 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4051 fcp_rsp_iu->fcp_sns_len);
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004052 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4054 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004055 (void *)scpnt->sense_buffer, sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 }
4057
4058 /* check for overrun */
4059 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4060 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4061 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4062 "The response data length is "
4063 "%d, the original length was %d.\n",
4064 unit->fcp_lun,
4065 unit->port->wwpn,
4066 zfcp_get_busid_by_unit(unit),
4067 fcp_rsp_iu->fcp_resid,
4068 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4069 }
4070
4071 /* check for underrun */
4072 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4073 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4074 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4075 "The response data length is "
4076 "%d, the original length was %d.\n",
4077 unit->fcp_lun,
4078 unit->port->wwpn,
4079 zfcp_get_busid_by_unit(unit),
4080 fcp_rsp_iu->fcp_resid,
4081 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4082
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004083 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4084 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4085 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004086 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 }
4088
4089 skip_fsfstatus:
4090 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4091
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004092 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004093 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004094 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004095 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004096 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004097 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098
4099 /* cleanup pointer (need this especially for abort) */
4100 scpnt->host_scribble = NULL;
4101
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 (scpnt->scsi_done) (scpnt);
4104
4105 /*
4106 * We must hold this lock until scsi_done has been called.
4107 * Otherwise we may call scsi_done after abort regarding this
4108 * command has completed.
4109 * Note: scsi_done must not block!
4110 */
4111 out:
4112 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4113 return retval;
4114}
4115
4116/*
4117 * function: zfcp_fsf_send_fcp_command_task_management_handler
4118 *
4119 * purpose: evaluates FCP_RSP IU
4120 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004121 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 */
4123static int
4124zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4125{
4126 int retval = 0;
4127 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4128 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4129 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004130 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4133 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4134 goto skip_fsfstatus;
4135 }
4136
4137 /* check FCP_RSP_INFO */
4138 switch (fcp_rsp_info[3]) {
4139 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 /* ok, continue */
4141 ZFCP_LOG_DEBUG("no failure or Task Management "
4142 "Function complete\n");
4143 break;
4144 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4146 "is not supported on the target device "
4147 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4148 unit->fcp_lun,
4149 unit->port->wwpn,
4150 zfcp_get_busid_by_unit(unit));
4151 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4152 break;
4153 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4155 "failed to complete successfully. "
4156 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4157 unit->fcp_lun,
4158 unit->port->wwpn,
4159 zfcp_get_busid_by_unit(unit));
4160 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4161 break;
4162 default:
4163 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4164 "code was detected for a command. "
4165 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4166 "(debug info 0x%x)\n",
4167 unit->fcp_lun,
4168 unit->port->wwpn,
4169 zfcp_get_busid_by_unit(unit),
4170 fcp_rsp_info[3]);
4171 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4172 }
4173
4174 skip_fsfstatus:
4175 return retval;
4176}
4177
4178
4179/*
4180 * function: zfcp_fsf_control_file
4181 *
4182 * purpose: Initiator of the control file upload/download FSF requests
4183 *
4184 * returns: 0 - FSF request is successfuly created and queued
4185 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4186 * -EINVAL - Invalid direction specified
4187 * -ENOMEM - Insufficient memory
4188 * -EPERM - Cannot create FSF request or place it in QDIO queue
4189 */
4190int
4191zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4192 struct zfcp_fsf_req **fsf_req_ptr,
4193 u32 fsf_command,
4194 u32 option,
4195 struct zfcp_sg_list *sg_list)
4196{
4197 struct zfcp_fsf_req *fsf_req;
4198 struct fsf_qtcb_bottom_support *bottom;
4199 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 unsigned long lock_flags;
4201 int req_flags = 0;
4202 int direction;
4203 int retval = 0;
4204
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004205 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4207 zfcp_get_busid_by_adapter(adapter));
4208 retval = -EOPNOTSUPP;
4209 goto out;
4210 }
4211
4212 switch (fsf_command) {
4213
4214 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4215 direction = SBAL_FLAGS0_TYPE_WRITE;
4216 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4217 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4218 req_flags = ZFCP_WAIT_FOR_SBAL;
4219 break;
4220
4221 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4222 direction = SBAL_FLAGS0_TYPE_READ;
4223 break;
4224
4225 default:
4226 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4227 retval = -EINVAL;
4228 goto out;
4229 }
4230
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4232 NULL, &lock_flags, &fsf_req);
4233 if (retval < 0) {
4234 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4235 "adapter %s\n",
4236 zfcp_get_busid_by_adapter(adapter));
4237 retval = -EPERM;
4238 goto unlock_queue_lock;
4239 }
4240
4241 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4242 sbale[0].flags |= direction;
4243
4244 bottom = &fsf_req->qtcb->bottom.support;
4245 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4246 bottom->option = option;
4247
4248 if (sg_list->count > 0) {
4249 int bytes;
4250
4251 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4252 sg_list->sg, sg_list->count,
4253 ZFCP_MAX_SBALS_PER_REQ);
4254 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4255 ZFCP_LOG_INFO(
4256 "error: Could not create sufficient number of "
4257 "SBALS for an FSF request to the adapter %s\n",
4258 zfcp_get_busid_by_adapter(adapter));
4259 retval = -ENOMEM;
4260 goto free_fsf_req;
4261 }
4262 } else
4263 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4264
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004265 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4266 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 if (retval < 0) {
4268 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4269 "(adapter %s)\n",
4270 zfcp_get_busid_by_adapter(adapter));
4271 retval = -EPERM;
4272 goto free_fsf_req;
4273 }
4274 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4275
4276 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4277 "adapter %s\n",
4278 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4279 "download" : "upload",
4280 zfcp_get_busid_by_adapter(adapter));
4281
4282 wait_event(fsf_req->completion_wq,
4283 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4284
4285 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004286 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287
4288 free_fsf_req:
4289 zfcp_fsf_req_free(fsf_req);
4290 unlock_queue_lock:
4291 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 out:
4293 return retval;
4294}
4295
4296
4297/*
4298 * function: zfcp_fsf_control_file_handler
4299 *
4300 * purpose: Handler of the control file upload/download FSF requests
4301 *
4302 * returns: 0 - FSF request successfuly processed
4303 * -EAGAIN - Operation has to be repeated because of a temporary problem
4304 * -EACCES - There is no permission to execute an operation
4305 * -EPERM - The control file is not in a right format
4306 * -EIO - There is a problem with the FCP adapter
4307 * -EINVAL - Invalid operation
4308 * -EFAULT - User space memory I/O operation fault
4309 */
4310static int
4311zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4312{
4313 struct zfcp_adapter *adapter = fsf_req->adapter;
4314 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4315 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4316 int retval = 0;
4317
4318 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4319 retval = -EINVAL;
4320 goto skip_fsfstatus;
4321 }
4322
4323 switch (header->fsf_status) {
4324
4325 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 ZFCP_LOG_NORMAL(
4327 "The FSF request has been successfully completed "
4328 "on the adapter %s\n",
4329 zfcp_get_busid_by_adapter(adapter));
4330 break;
4331
4332 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4334 switch (header->fsf_status_qual.word[0]) {
4335
6f71d9b2005-04-10 23:04:28 -05004336 case FSF_SQ_CFDC_HARDENED_ON_SE:
4337 ZFCP_LOG_NORMAL(
4338 "CFDC on the adapter %s has being "
4339 "hardened on primary and secondary SE\n",
4340 zfcp_get_busid_by_adapter(adapter));
4341 break;
4342
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4344 ZFCP_LOG_NORMAL(
4345 "CFDC of the adapter %s could not "
4346 "be saved on the SE\n",
4347 zfcp_get_busid_by_adapter(adapter));
4348 break;
4349
4350 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4351 ZFCP_LOG_NORMAL(
4352 "CFDC of the adapter %s could not "
4353 "be copied to the secondary SE\n",
4354 zfcp_get_busid_by_adapter(adapter));
4355 break;
4356
4357 default:
4358 ZFCP_LOG_NORMAL(
4359 "CFDC could not be hardened "
4360 "on the adapter %s\n",
4361 zfcp_get_busid_by_adapter(adapter));
4362 }
4363 }
4364 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4365 retval = -EAGAIN;
4366 break;
4367
4368 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 ZFCP_LOG_NORMAL(
4370 "Adapter %s does not accept privileged commands\n",
4371 zfcp_get_busid_by_adapter(adapter));
4372 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4373 retval = -EACCES;
4374 break;
4375
4376 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 ZFCP_LOG_NORMAL(
4378 "Error at position %d in the CFDC, "
4379 "CFDC is discarded by the adapter %s\n",
4380 header->fsf_status_qual.word[0],
4381 zfcp_get_busid_by_adapter(adapter));
4382 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4383 retval = -EPERM;
4384 break;
4385
4386 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 ZFCP_LOG_NORMAL(
4388 "Adapter %s cannot harden the control file, "
4389 "file is discarded\n",
4390 zfcp_get_busid_by_adapter(adapter));
4391 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4392 retval = -EIO;
4393 break;
4394
4395 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 ZFCP_LOG_NORMAL(
4397 "Control file is too large, file is discarded "
4398 "by the adapter %s\n",
4399 zfcp_get_busid_by_adapter(adapter));
4400 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4401 retval = -EIO;
4402 break;
4403
4404 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4406 ZFCP_LOG_NORMAL(
4407 "CFDC has been discarded by the adapter %s, "
4408 "because activation would impact "
4409 "%d active connection(s)\n",
4410 zfcp_get_busid_by_adapter(adapter),
4411 header->fsf_status_qual.word[0]);
4412 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4413 retval = -EIO;
4414 break;
4415
4416 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4418 ZFCP_LOG_NORMAL(
4419 "CFDC has been activated on the adapter %s, "
4420 "but activation has impacted "
4421 "%d active connection(s)\n",
4422 zfcp_get_busid_by_adapter(adapter),
4423 header->fsf_status_qual.word[0]);
4424 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4425 retval = -EIO;
4426 break;
4427
4428 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4430 "op_subtype=0x%x)\n",
4431 zfcp_get_busid_by_adapter(adapter),
4432 bottom->operation_subtype);
4433 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4434 retval = -EINVAL;
4435 break;
4436
4437 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 ZFCP_LOG_NORMAL(
4439 "Invalid option 0x%x has been specified "
4440 "in QTCB bottom sent to the adapter %s\n",
4441 bottom->option,
4442 zfcp_get_busid_by_adapter(adapter));
4443 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4444 retval = -EINVAL;
4445 break;
4446
4447 default:
4448 ZFCP_LOG_NORMAL(
4449 "bug: An unknown/unexpected FSF status 0x%08x "
4450 "was presented on the adapter %s\n",
4451 header->fsf_status,
4452 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4454 retval = -EINVAL;
4455 break;
4456 }
4457
4458skip_fsfstatus:
4459 return retval;
4460}
4461
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462static inline int
4463zfcp_fsf_req_sbal_check(unsigned long *flags,
4464 struct zfcp_qdio_queue *queue, int needed)
4465{
4466 write_lock_irqsave(&queue->queue_lock, *flags);
4467 if (likely(atomic_read(&queue->free_count) >= needed))
4468 return 1;
4469 write_unlock_irqrestore(&queue->queue_lock, *flags);
4470 return 0;
4471}
4472
4473/*
4474 * set qtcb pointer in fsf_req and initialize QTCB
4475 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004476static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004477zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478{
4479 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004480 fsf_req->qtcb->prefix.req_seq_no =
4481 fsf_req->adapter->fsf_req_seq_no;
4482 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004484 fsf_req->qtcb->prefix.qtcb_type =
4485 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004487 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004488 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 }
4490}
4491
4492/**
4493 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4494 * @adapter: adapter for which request queue is examined
4495 * @req_flags: flags indicating whether to wait for needed SBAL or not
4496 * @lock_flags: lock_flags if queue_lock is taken
4497 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4498 * Locks: lock adapter->request_queue->queue_lock on success
4499 */
4500static int
4501zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4502 unsigned long *lock_flags)
4503{
4504 long ret;
4505 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4506
4507 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4508 ret = wait_event_interruptible_timeout(adapter->request_wq,
4509 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4510 ZFCP_SBAL_TIMEOUT);
4511 if (ret < 0)
4512 return ret;
4513 if (!ret)
4514 return -EIO;
4515 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4516 return -EIO;
4517
4518 return 0;
4519}
4520
4521/*
4522 * function: zfcp_fsf_req_create
4523 *
4524 * purpose: create an FSF request at the specified adapter and
4525 * setup common fields
4526 *
4527 * returns: -ENOMEM if there was insufficient memory for a request
4528 * -EIO if no qdio buffers could be allocate to the request
4529 * -EINVAL/-EPERM on bug conditions in req_dequeue
4530 * 0 in success
4531 *
4532 * note: The created request is returned by reference.
4533 *
4534 * locks: lock of concerned request queue must not be held,
4535 * but is held on completion (write, irqsave)
4536 */
4537int
4538zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4539 mempool_t *pool, unsigned long *lock_flags,
4540 struct zfcp_fsf_req **fsf_req_p)
4541{
4542 volatile struct qdio_buffer_element *sbale;
4543 struct zfcp_fsf_req *fsf_req = NULL;
4544 int ret = 0;
4545 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4546
4547 /* allocate new FSF request */
4548 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4549 if (unlikely(NULL == fsf_req)) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +01004550 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 "the outbound (send) queue.\n");
4552 ret = -ENOMEM;
4553 goto failed_fsf_req;
4554 }
4555
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004556 fsf_req->adapter = adapter;
4557 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004558 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004559 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004561 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 this request completion */
4563 init_waitqueue_head(&fsf_req->completion_wq);
4564
4565 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004566 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004568
4569 /* this is serialized (we are holding req_queue-lock of adapter) */
4570 if (adapter->req_no == 0)
4571 adapter->req_no++;
4572 fsf_req->req_id = adapter->req_no++;
4573
4574 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575
4576 /*
4577 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4578 * if it is not set (see also *_open_qdio and *_close_qdio).
4579 */
4580
4581 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4582 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4583 ret = -EIO;
4584 goto failed_sbals;
4585 }
4586
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004587 if (fsf_req->qtcb) {
4588 fsf_req->seq_no = adapter->fsf_req_seq_no;
4589 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 fsf_req->sbal_number = 1;
4592 fsf_req->sbal_first = req_queue->free_index;
4593 fsf_req->sbal_curr = req_queue->free_index;
4594 fsf_req->sbale_curr = 1;
4595
4596 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4597 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4598 }
4599
4600 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4601
4602 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004603 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4605 if (likely(fsf_req->qtcb != NULL)) {
4606 sbale[1].addr = (void *) fsf_req->qtcb;
4607 sbale[1].length = sizeof(struct fsf_qtcb);
4608 }
4609
4610 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4611 fsf_req->sbal_number, fsf_req->sbal_first);
4612
4613 goto success;
4614
4615 failed_sbals:
4616/* dequeue new FSF request previously enqueued */
4617 zfcp_fsf_req_free(fsf_req);
4618 fsf_req = NULL;
4619
4620 failed_fsf_req:
4621 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4622 success:
4623 *fsf_req_p = fsf_req;
4624 return ret;
4625}
4626
4627/*
4628 * function: zfcp_fsf_req_send
4629 *
4630 * purpose: start transfer of FSF request via QDIO
4631 *
4632 * returns: 0 - request transfer succesfully started
4633 * !0 - start of request transfer failed
4634 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004635static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636{
4637 struct zfcp_adapter *adapter;
4638 struct zfcp_qdio_queue *req_queue;
4639 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004640 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 int new_distance_from_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 int retval = 0;
4643
4644 adapter = fsf_req->adapter;
4645 req_queue = &adapter->request_queue,
4646
4647
4648 /* FIXME(debug): remove it later */
4649 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4650 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4651 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4652 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4653 sbale[1].length);
4654
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004655 /* put allocated FSF request into hash table */
4656 spin_lock(&adapter->req_list_lock);
4657 zfcp_reqlist_add(adapter, fsf_req);
4658 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004660 inc_seq_no = (fsf_req->qtcb != NULL);
4661
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 ZFCP_LOG_TRACE("request queue of adapter %s: "
4663 "next free SBAL is %i, %i free SBALs\n",
4664 zfcp_get_busid_by_adapter(adapter),
4665 req_queue->free_index,
4666 atomic_read(&req_queue->free_count));
4667
4668 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4669 "index_in_queue=%i, count=%i, buffers=%p\n",
4670 zfcp_get_busid_by_adapter(adapter),
4671 QDIO_FLAG_SYNC_OUTPUT,
4672 0, fsf_req->sbal_first, fsf_req->sbal_number,
4673 &req_queue->buffer[fsf_req->sbal_first]);
4674
4675 /*
4676 * adjust the number of free SBALs in request queue as well as
4677 * position of first one
4678 */
4679 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4680 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4681 req_queue->free_index += fsf_req->sbal_number; /* increase */
4682 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4683 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4684
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004685 fsf_req->issued = get_clock();
4686
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 retval = do_QDIO(adapter->ccw_device,
4688 QDIO_FLAG_SYNC_OUTPUT,
4689 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4690
4691 if (unlikely(retval)) {
4692 /* Queues are down..... */
4693 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004694 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004695 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004696 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004697 spin_unlock(&adapter->req_list_lock);
4698 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 zfcp_qdio_zero_sbals(req_queue->buffer,
4700 fsf_req->sbal_first, fsf_req->sbal_number);
4701 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004702 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4704 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Martin Peschke1f6f7122008-04-18 12:51:55 +02004705 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 } else {
4707 req_queue->distance_from_int = new_distance_from_int;
4708 /*
4709 * increase FSF sequence counter -
4710 * this must only be done for request successfully enqueued to
4711 * QDIO this rejected requests may be cleaned up by calling
4712 * routines resulting in missing sequence counter values
4713 * otherwise,
4714 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004715
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004717 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004719
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004721 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 }
4723 return retval;
4724}
4725
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726#undef ZFCP_LOG_AREA