blob: 7c3f02816e95c35b8ed6005c9f0c7d7fa2f9fa21 [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;
715 int retval = 0;
716
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
734 status_buffer =
735 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
736 if (!status_buffer) {
737 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
738 goto failed_buf;
739 }
740 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200741 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 /* insert pointer to respective buffer */
744 sbale = zfcp_qdio_sbale_curr(fsf_req);
745 sbale->addr = (void *) status_buffer;
746 sbale->length = sizeof(struct fsf_status_read_buffer);
747
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200748 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 if (retval) {
750 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
751 "environment.\n");
752 goto failed_req_send;
753 }
754
755 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
756 zfcp_get_busid_by_adapter(adapter));
757 goto out;
758
759 failed_req_send:
760 mempool_free(status_buffer, adapter->pool.data_status_read);
761
762 failed_buf:
763 zfcp_fsf_req_free(fsf_req);
764 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200765 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 out:
767 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
768 return retval;
769}
770
771static int
772zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
773{
774 struct fsf_status_read_buffer *status_buffer;
775 struct zfcp_adapter *adapter;
776 struct zfcp_port *port;
777 unsigned long flags;
778
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200779 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 adapter = fsf_req->adapter;
781
782 read_lock_irqsave(&zfcp_data.config_lock, flags);
783 list_for_each_entry(port, &adapter->port_list_head, list)
784 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
785 break;
786 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
787
788 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100789 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200790 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 "adapter %s. Ignored.\n",
792 status_buffer->d_id & ZFCP_DID_MASK,
793 zfcp_get_busid_by_adapter(adapter));
794 goto out;
795 }
796
797 switch (status_buffer->status_subtype) {
798
799 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200800 zfcp_erp_port_reopen(port, 0, 101, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 break;
802
803 case FSF_STATUS_READ_SUB_ERROR_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200804 zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 break;
806
807 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
809 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200810 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 "Ignored. (debug info 0x%x)\n",
812 status_buffer->d_id,
813 zfcp_get_busid_by_adapter(adapter),
814 status_buffer->status_subtype);
815 }
816 out:
817 return 0;
818}
819
820/*
821 * function: zfcp_fsf_status_read_handler
822 *
823 * purpose: is called for finished Open Port command
824 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200825 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 */
827static int
828zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
829{
830 int retval = 0;
831 struct zfcp_adapter *adapter = fsf_req->adapter;
832 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200833 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200834 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200837 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200839 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 goto out;
841 }
842
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200843 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 switch (status_buffer->status_type) {
846
847 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 zfcp_fsf_status_read_port_closed(fsf_req);
849 break;
850
851 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 zfcp_fsf_incoming_els(fsf_req);
853 break;
854
855 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
857 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 break;
859
860 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200861 fsf_bit_error = (struct fsf_bit_error_payload *)
862 status_buffer->payload;
863 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
864 "received (adapter %s, "
865 "link failures = %i, loss of sync errors = %i, "
866 "loss of signal errors = %i, "
867 "primitive sequence errors = %i, "
868 "invalid transmission word errors = %i, "
869 "CRC errors = %i)\n",
870 zfcp_get_busid_by_adapter(adapter),
871 fsf_bit_error->link_failure_error_count,
872 fsf_bit_error->loss_of_sync_error_count,
873 fsf_bit_error->loss_of_signal_error_count,
874 fsf_bit_error->primitive_sequence_error_count,
875 fsf_bit_error->invalid_transmission_word_error_count,
876 fsf_bit_error->crc_error_count);
877 ZFCP_LOG_INFO("Additional bit error threshold data "
878 "(adapter %s, "
879 "primitive sequence event time-outs = %i, "
880 "elastic buffer overrun errors = %i, "
881 "advertised receive buffer-to-buffer credit = %i, "
882 "current receice buffer-to-buffer credit = %i, "
883 "advertised transmit buffer-to-buffer credit = %i, "
884 "current transmit buffer-to-buffer credit = %i)\n",
885 zfcp_get_busid_by_adapter(adapter),
886 fsf_bit_error->primitive_sequence_event_timeout_count,
887 fsf_bit_error->elastic_buffer_overrun_error_count,
888 fsf_bit_error->advertised_receive_b2b_credit,
889 fsf_bit_error->current_receive_b2b_credit,
890 fsf_bit_error->advertised_transmit_b2b_credit,
891 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 break;
893
894 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200895 switch (status_buffer->status_subtype) {
896 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
897 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
898 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100899 zfcp_fsf_link_down_info_eval(fsf_req, 38,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100900 (struct fsf_link_down_info *)
901 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200902 break;
903 case FSF_STATUS_READ_SUB_FDISC_FAILED:
904 ZFCP_LOG_INFO("Local link to adapter %s is down "
905 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100906 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100907 zfcp_fsf_link_down_info_eval(fsf_req, 39,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100908 (struct fsf_link_down_info *)
909 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200910 break;
911 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
912 ZFCP_LOG_INFO("Local link to adapter %s is down "
913 "due to firmware update on adapter\n",
914 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100915 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200916 break;
917 default:
918 ZFCP_LOG_INFO("Local link to adapter %s is down "
919 "due to unknown reason\n",
920 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100921 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200922 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 break;
924
925 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200926 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100927 "Restarting operations on this adapter\n",
928 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200930 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 ZFCP_STATUS_COMMON_RUNNING,
932 ZFCP_SET);
933 zfcp_erp_adapter_reopen(adapter,
934 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100935 | ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200936 102, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 break;
938
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100939 case FSF_STATUS_READ_NOTIFICATION_LOST:
940 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
941 "adapter %s%s%s%s%s%s%s%s%s\n",
942 zfcp_get_busid_by_adapter(adapter),
943 (status_buffer->status_subtype &
944 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
945 ", incoming ELS" : "",
946 (status_buffer->status_subtype &
947 FSF_STATUS_READ_SUB_SENSE_DATA) ?
948 ", sense data" : "",
949 (status_buffer->status_subtype &
950 FSF_STATUS_READ_SUB_LINK_STATUS) ?
951 ", link status change" : "",
952 (status_buffer->status_subtype &
953 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
954 ", port close" : "",
955 (status_buffer->status_subtype &
956 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
957 ", bit error exception" : "",
958 (status_buffer->status_subtype &
959 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
960 ", ACT update" : "",
961 (status_buffer->status_subtype &
962 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
963 ", ACT hardening" : "",
964 (status_buffer->status_subtype &
965 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
966 ", adapter feature change" : "");
967
968 if (status_buffer->status_subtype &
969 FSF_STATUS_READ_SUB_ACT_UPDATED)
Martin Peschke1f6f7122008-04-18 12:51:55 +0200970 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100971 break;
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200974 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200976 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 break;
978
979 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 switch (status_buffer->status_subtype) {
981 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200982 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 zfcp_get_busid_by_adapter(adapter));
984 break;
985 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200986 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 "to the secondary SE\n",
988 zfcp_get_busid_by_adapter(adapter));
989 break;
990 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200991 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 zfcp_get_busid_by_adapter(adapter));
993 }
994 break;
995
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200996 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200997 ZFCP_LOG_INFO("List of supported features on adapter %s has "
998 "been changed from 0x%08X to 0x%08X\n",
999 zfcp_get_busid_by_adapter(adapter),
1000 *(u32*) (status_buffer->payload + 4),
1001 *(u32*) (status_buffer->payload));
1002 adapter->adapter_features = *(u32*) status_buffer->payload;
1003 break;
1004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001006 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 "type was received (debug info 0x%x)\n",
1008 status_buffer->status_type);
1009 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1010 status_buffer);
1011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1012 (char *) status_buffer,
1013 sizeof (struct fsf_status_read_buffer));
1014 break;
1015 }
1016 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001017 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 /*
1019 * recycle buffer and start new request repeat until outbound
1020 * queue is empty or adapter shutdown is requested
1021 */
1022 /*
1023 * FIXME(qdio):
1024 * we may wait in the req_create for 5s during shutdown, so
1025 * qdio_cleanup will have to wait at least that long before returning
1026 * with failure to allow us a proper cleanup under all circumstances
1027 */
1028 /*
1029 * FIXME:
1030 * allocation failure possible? (Is this code needed?)
1031 */
1032 retval = zfcp_fsf_status_read(adapter, 0);
1033 if (retval < 0) {
1034 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1035 "request for the adapter %s.\n",
1036 zfcp_get_busid_by_adapter(adapter));
1037 /* temporary fix to avoid status read buffer shortage */
1038 adapter->status_read_failed++;
1039 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1040 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1041 ZFCP_LOG_INFO("restart adapter %s due to status read "
1042 "buffer shortage\n",
1043 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001044 zfcp_erp_adapter_reopen(adapter, 0, 103, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 }
1047 out:
1048 return retval;
1049}
1050
1051/*
1052 * function: zfcp_fsf_abort_fcp_command
1053 *
1054 * purpose: tells FSF to abort a running SCSI command
1055 *
1056 * returns: address of initiated FSF request
1057 * NULL - request could not be initiated
1058 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001059 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 * FIXME(design) shouldn't this be modified to return an int
1061 * also...don't know how though
1062 */
1063struct zfcp_fsf_req *
1064zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1065 struct zfcp_adapter *adapter,
1066 struct zfcp_unit *unit, int req_flags)
1067{
1068 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001070 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 int retval = 0;
1072
1073 /* setup new FSF request */
1074 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1075 req_flags, adapter->pool.fsf_req_abort,
1076 &lock_flags, &fsf_req);
1077 if (retval < 0) {
1078 ZFCP_LOG_INFO("error: Failed to create an abort command "
1079 "request for lun 0x%016Lx on port 0x%016Lx "
1080 "on adapter %s.\n",
1081 unit->fcp_lun,
1082 unit->port->wwpn,
1083 zfcp_get_busid_by_adapter(adapter));
1084 goto out;
1085 }
1086
Christof Schmitt951f7462007-12-20 12:30:24 +01001087 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1088 &unit->status)))
1089 goto unit_blocked;
1090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1092 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1093 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1094
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001095 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /* set handles of unit and its parent port in QTCB */
1098 fsf_req->qtcb->header.lun_handle = unit->handle;
1099 fsf_req->qtcb->header.port_handle = unit->port->handle;
1100
1101 /* set handle of request which should be aborted */
1102 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1103
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001104 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1105 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001106 if (!retval)
1107 goto out;
1108
1109 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 zfcp_fsf_req_free(fsf_req);
1111 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 out:
1114 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1115 return fsf_req;
1116}
1117
1118/*
1119 * function: zfcp_fsf_abort_fcp_command_handler
1120 *
1121 * purpose: is called for finished Abort FCP Command request
1122 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001123 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 */
1125static int
1126zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1127{
1128 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001129 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001130 union fsf_status_qual *fsf_stat_qual =
1131 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1134 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1135 goto skip_fsfstatus;
1136 }
1137
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001138 unit = (struct zfcp_unit *) new_fsf_req->data;
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 /* evaluate FSF status in QTCB */
1141 switch (new_fsf_req->qtcb->header.fsf_status) {
1142
1143 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001144 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 /*
1146 * In this case a command that was sent prior to a port
1147 * reopen was aborted (handles are different). This is
1148 * fine.
1149 */
1150 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1152 "port 0x%016Lx on adapter %s invalid. "
1153 "This may happen occasionally.\n",
1154 unit->port->handle,
1155 unit->port->wwpn,
1156 zfcp_get_busid_by_unit(unit));
1157 ZFCP_LOG_INFO("status qualifier:\n");
1158 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1159 (char *) &new_fsf_req->qtcb->header.
1160 fsf_status_qual,
1161 sizeof (union fsf_status_qual));
1162 /* Let's hope this sorts out the mess */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001163 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001164 new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1166 }
1167 break;
1168
1169 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001170 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /*
1172 * In this case a command that was sent prior to a unit
1173 * reopen was aborted (handles are different).
1174 * This is fine.
1175 */
1176 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 ZFCP_LOG_INFO
1178 ("Warning: Temporary LUN identifier 0x%x of LUN "
1179 "0x%016Lx on port 0x%016Lx on adapter %s is "
1180 "invalid. This may happen in rare cases. "
1181 "Trying to re-establish link.\n",
1182 unit->handle,
1183 unit->fcp_lun,
1184 unit->port->wwpn,
1185 zfcp_get_busid_by_unit(unit));
1186 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1188 (char *) &new_fsf_req->qtcb->header.
1189 fsf_status_qual,
1190 sizeof (union fsf_status_qual));
1191 /* Let's hope this sorts out the mess */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001192 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1194 }
1195 break;
1196
1197 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1200 break;
1201
1202 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1204 "be reopened\n", unit->port->wwpn,
1205 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001206 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1208 | ZFCP_STATUS_FSFREQ_RETRY;
1209 break;
1210
1211 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 ZFCP_LOG_INFO(
1213 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1214 "to be reopened\n",
1215 unit->fcp_lun, unit->port->wwpn,
1216 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001217 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1219 | ZFCP_STATUS_FSFREQ_RETRY;
1220 break;
1221
1222 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1224 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001225 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1227 break;
1228 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 /* SCSI stack will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1231 break;
1232 default:
1233 ZFCP_LOG_NORMAL
1234 ("bug: Wrong status qualifier 0x%x arrived.\n",
1235 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 break;
1237 }
1238 break;
1239
1240 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 retval = 0;
1242 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1243 break;
1244
1245 default:
1246 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1247 "(debug info 0x%x)\n",
1248 new_fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 break;
1250 }
1251 skip_fsfstatus:
1252 return retval;
1253}
1254
1255/**
1256 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1257 * one SBALE
1258 * Two scatter-gather lists are passed, one for the reqeust and one for the
1259 * response.
1260 */
1261static inline int
1262zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1263 struct scatterlist *resp, int resp_count)
1264{
1265 return ((req_count == 1) &&
1266 (resp_count == 1) &&
1267 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1268 PAGE_MASK) ==
1269 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1270 req[0].length - 1) & PAGE_MASK)) &&
1271 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1272 PAGE_MASK) ==
1273 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1274 resp[0].length - 1) & PAGE_MASK)));
1275}
1276
1277/**
1278 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1279 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1280 * the request
1281 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1282 * a struct zfcp_fsf_req
1283 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1284 * is sent within error recovery
1285 */
1286int
1287zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1288 struct zfcp_erp_action *erp_action)
1289{
1290 volatile struct qdio_buffer_element *sbale;
1291 struct zfcp_port *port;
1292 struct zfcp_adapter *adapter;
1293 struct zfcp_fsf_req *fsf_req;
1294 unsigned long lock_flags;
1295 int bytes;
1296 int ret = 0;
1297
1298 port = ct->port;
1299 adapter = port->adapter;
1300
1301 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1302 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1303 pool, &lock_flags, &fsf_req);
1304 if (ret < 0) {
1305 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1306 "adapter: %s\n",
1307 zfcp_get_busid_by_adapter(adapter));
1308 goto failed_req;
1309 }
1310
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1312 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1313 ct->resp, ct->resp_count)){
1314 /* both request buffer and response buffer
1315 fit into one sbale each */
1316 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1317 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1318 sbale[2].length = ct->req[0].length;
1319 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1320 sbale[3].length = ct->resp[0].length;
1321 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001322 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1324 /* try to use chained SBALs */
1325 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1326 SBAL_FLAGS0_TYPE_WRITE_READ,
1327 ct->req, ct->req_count,
1328 ZFCP_MAX_SBALS_PER_CT_REQ);
1329 if (bytes <= 0) {
1330 ZFCP_LOG_INFO("error: creation of CT request failed "
1331 "on adapter %s\n",
1332 zfcp_get_busid_by_adapter(adapter));
1333 if (bytes == 0)
1334 ret = -ENOMEM;
1335 else
1336 ret = bytes;
1337
1338 goto failed_send;
1339 }
1340 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1341 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1342 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1343 SBAL_FLAGS0_TYPE_WRITE_READ,
1344 ct->resp, ct->resp_count,
1345 ZFCP_MAX_SBALS_PER_CT_REQ);
1346 if (bytes <= 0) {
1347 ZFCP_LOG_INFO("error: creation of CT request failed "
1348 "on adapter %s\n",
1349 zfcp_get_busid_by_adapter(adapter));
1350 if (bytes == 0)
1351 ret = -ENOMEM;
1352 else
1353 ret = bytes;
1354
1355 goto failed_send;
1356 }
1357 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1358 } else {
1359 /* reject send generic request */
1360 ZFCP_LOG_INFO(
1361 "error: microcode does not support chained SBALs,"
1362 "CT request too big (adapter %s)\n",
1363 zfcp_get_busid_by_adapter(adapter));
1364 ret = -EOPNOTSUPP;
1365 goto failed_send;
1366 }
1367
1368 /* settings in QTCB */
1369 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001370 fsf_req->qtcb->bottom.support.service_class =
1371 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001373 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001375 zfcp_san_dbf_event_ct_request(fsf_req);
1376
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001377 if (erp_action) {
1378 erp_action->fsf_req = fsf_req;
1379 fsf_req->erp_action = erp_action;
1380 zfcp_erp_start_timer(fsf_req);
1381 } else
1382 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1383
1384 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 if (ret) {
1386 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1387 "(adapter %s, port 0x%016Lx)\n",
1388 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1389 goto failed_send;
1390 }
1391
1392 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1393 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1394 goto out;
1395
1396 failed_send:
1397 zfcp_fsf_req_free(fsf_req);
1398 if (erp_action != NULL) {
1399 erp_action->fsf_req = NULL;
1400 }
1401 failed_req:
1402 out:
1403 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1404 lock_flags);
1405 return ret;
1406}
1407
1408/**
1409 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1410 * @fsf_req: pointer to struct zfcp_fsf_req
1411 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001412 * Data specific for the Generic Service request is passed using
1413 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1414 * Usually a specific handler for the CT request is called which is
1415 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 */
1417static int
1418zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1419{
1420 struct zfcp_port *port;
1421 struct zfcp_adapter *adapter;
1422 struct zfcp_send_ct *send_ct;
1423 struct fsf_qtcb_header *header;
1424 struct fsf_qtcb_bottom_support *bottom;
1425 int retval = -EINVAL;
1426 u16 subtable, rule, counter;
1427
1428 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001429 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 port = send_ct->port;
1431 header = &fsf_req->qtcb->header;
1432 bottom = &fsf_req->qtcb->bottom.support;
1433
1434 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1435 goto skip_fsfstatus;
1436
1437 /* evaluate FSF status in QTCB */
1438 switch (header->fsf_status) {
1439
1440 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001441 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 retval = 0;
1443 break;
1444
1445 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001446 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1447 "class %d.\n",
1448 zfcp_get_busid_by_port(port),
1449 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001451 zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1453 break;
1454
1455 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 switch (header->fsf_status_qual.word[0]){
1457 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 /* reopening link to port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 zfcp_test_link(port);
1460 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1461 break;
1462 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1465 break;
1466 default:
1467 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1468 "arrived.\n",
1469 header->fsf_status_qual.word[0]);
1470 break;
1471 }
1472 break;
1473
1474 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001476 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 zfcp_get_busid_by_port(port), port->d_id);
1478 for (counter = 0; counter < 2; counter++) {
1479 subtable = header->fsf_status_qual.halfword[counter * 2];
1480 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1481 switch (subtable) {
1482 case FSF_SQ_CFDC_SUBTABLE_OS:
1483 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1484 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1485 case FSF_SQ_CFDC_SUBTABLE_LUN:
1486 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1487 zfcp_act_subtable_type[subtable], rule);
1488 break;
1489 }
1490 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02001491 zfcp_erp_port_access_denied(port, 55, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1493 break;
1494
1495 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001497 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 zfcp_get_busid_by_port(port), port->d_id);
1499 ZFCP_LOG_INFO("status qualifier:\n");
1500 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1501 (char *) &header->fsf_status_qual,
1502 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1504 break;
1505
1506 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1508 "0x%016Lx on adapter %s invalid. This may "
1509 "happen occasionally.\n", port->handle,
1510 port->wwpn, zfcp_get_busid_by_port(port));
1511 ZFCP_LOG_INFO("status qualifier:\n");
1512 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1513 (char *) &header->fsf_status_qual,
1514 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001515 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1517 break;
1518
1519 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001521 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 zfcp_get_busid_by_port(port), port->d_id);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001523 zfcp_erp_port_boxed(port, 49, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1525 | ZFCP_STATUS_FSFREQ_RETRY;
1526 break;
1527
1528 /* following states should never occure, all cases avoided
1529 in zfcp_fsf_send_ct - but who knows ... */
1530 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1532 "req_buf_length=%d, resp_buf_length=%d)\n",
1533 zfcp_get_busid_by_adapter(adapter),
1534 bottom->req_buf_length, bottom->resp_buf_length);
1535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1536 break;
1537 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1539 "req_buf_length=%d)\n",
1540 zfcp_get_busid_by_adapter(adapter),
1541 bottom->req_buf_length);
1542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1543 break;
1544 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1546 "resp_buf_length=%d)\n",
1547 zfcp_get_busid_by_adapter(adapter),
1548 bottom->resp_buf_length);
1549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1550 break;
1551 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1553 "resp_buf_length=%d)\n",
1554 zfcp_get_busid_by_adapter(adapter),
1555 bottom->req_buf_length, bottom->resp_buf_length);
1556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1557 break;
1558
1559 default:
1560 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1561 "(debug info 0x%x)\n", header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 break;
1563 }
1564
1565skip_fsfstatus:
1566 send_ct->status = retval;
1567
1568 if (send_ct->handler != NULL)
1569 send_ct->handler(send_ct->handler_data);
1570
1571 return retval;
1572}
1573
1574/**
1575 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1576 * @els: pointer to struct zfcp_send_els which contains all needed data for
1577 * the command.
1578 */
1579int
1580zfcp_fsf_send_els(struct zfcp_send_els *els)
1581{
1582 volatile struct qdio_buffer_element *sbale;
1583 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001584 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 struct zfcp_adapter *adapter;
1586 unsigned long lock_flags;
1587 int bytes;
1588 int ret = 0;
1589
1590 d_id = els->d_id;
1591 adapter = els->adapter;
1592
1593 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1594 ZFCP_REQ_AUTO_CLEANUP,
1595 NULL, &lock_flags, &fsf_req);
1596 if (ret < 0) {
1597 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001598 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 zfcp_get_busid_by_adapter(adapter), d_id);
1600 goto failed_req;
1601 }
1602
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001603 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1604 &els->port->status))) {
1605 ret = -EBUSY;
1606 goto port_blocked;
1607 }
1608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1610 if (zfcp_use_one_sbal(els->req, els->req_count,
1611 els->resp, els->resp_count)){
1612 /* both request buffer and response buffer
1613 fit into one sbale each */
1614 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1615 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1616 sbale[2].length = els->req[0].length;
1617 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1618 sbale[3].length = els->resp[0].length;
1619 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001620 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1622 /* try to use chained SBALs */
1623 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1624 SBAL_FLAGS0_TYPE_WRITE_READ,
1625 els->req, els->req_count,
1626 ZFCP_MAX_SBALS_PER_ELS_REQ);
1627 if (bytes <= 0) {
1628 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001629 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 zfcp_get_busid_by_adapter(adapter), d_id);
1631 if (bytes == 0) {
1632 ret = -ENOMEM;
1633 } else {
1634 ret = bytes;
1635 }
1636 goto failed_send;
1637 }
1638 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1639 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1640 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1641 SBAL_FLAGS0_TYPE_WRITE_READ,
1642 els->resp, els->resp_count,
1643 ZFCP_MAX_SBALS_PER_ELS_REQ);
1644 if (bytes <= 0) {
1645 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001646 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 zfcp_get_busid_by_adapter(adapter), d_id);
1648 if (bytes == 0) {
1649 ret = -ENOMEM;
1650 } else {
1651 ret = bytes;
1652 }
1653 goto failed_send;
1654 }
1655 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1656 } else {
1657 /* reject request */
1658 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1659 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001660 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 zfcp_get_busid_by_adapter(adapter), d_id);
1662 ret = -EOPNOTSUPP;
1663 goto failed_send;
1664 }
1665
1666 /* settings in QTCB */
1667 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001668 fsf_req->qtcb->bottom.support.service_class =
1669 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001671 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1674
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001675 zfcp_san_dbf_event_els_request(fsf_req);
1676
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001677 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1678 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 if (ret) {
1680 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001681 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 zfcp_get_busid_by_adapter(adapter), d_id);
1683 goto failed_send;
1684 }
1685
1686 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001687 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 goto out;
1689
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001690 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 failed_send:
1692 zfcp_fsf_req_free(fsf_req);
1693
1694 failed_req:
1695 out:
1696 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1697 lock_flags);
1698
1699 return ret;
1700}
1701
1702/**
1703 * zfcp_fsf_send_els_handler - handler for ELS commands
1704 * @fsf_req: pointer to struct zfcp_fsf_req
1705 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001706 * Data specific for the ELS command is passed using
1707 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1708 * Usually a specific handler for the ELS command is called which is
1709 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 */
1711static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1712{
1713 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001715 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 struct fsf_qtcb_header *header;
1717 struct fsf_qtcb_bottom_support *bottom;
1718 struct zfcp_send_els *send_els;
1719 int retval = -EINVAL;
1720 u16 subtable, rule, counter;
1721
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001722 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001724 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 d_id = send_els->d_id;
1726 header = &fsf_req->qtcb->header;
1727 bottom = &fsf_req->qtcb->bottom.support;
1728
1729 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1730 goto skip_fsfstatus;
1731
1732 switch (header->fsf_status) {
1733
1734 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001735 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 retval = 0;
1737 break;
1738
1739 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001740 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1741 "class %d.\n",
1742 zfcp_get_busid_by_adapter(adapter),
1743 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001745 zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1747 break;
1748
1749 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 switch (header->fsf_status_qual.word[0]){
1751 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001752 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1753 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1755 break;
1756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1758 retval =
1759 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1760 (struct zfcp_ls_rjt_par *)
1761 &header->fsf_status_qual.word[2]);
1762 break;
1763 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1765 break;
1766 default:
1767 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1768 header->fsf_status_qual.word[0]);
1769 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1770 (char*)header->fsf_status_qual.word, 16);
1771 }
1772 break;
1773
1774 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1776 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001777 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 zfcp_get_busid_by_adapter(adapter), d_id);
1779
1780 break;
1781
1782 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 ZFCP_LOG_INFO(
1784 "ELS request size and ELS response size must be either "
1785 "both 0, or both greater than 0 "
1786 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1787 zfcp_get_busid_by_adapter(adapter),
1788 bottom->req_buf_length,
1789 bottom->resp_buf_length);
1790 break;
1791
1792 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 ZFCP_LOG_INFO(
1794 "Length of the ELS request buffer, "
1795 "specified in QTCB bottom, "
1796 "exceeds the size of the buffers "
1797 "that have been allocated for ELS request data "
1798 "(adapter: %s, req_buf_length=%d)\n",
1799 zfcp_get_busid_by_adapter(adapter),
1800 bottom->req_buf_length);
1801 break;
1802
1803 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 ZFCP_LOG_INFO(
1805 "Length of the ELS response buffer, "
1806 "specified in QTCB bottom, "
1807 "exceeds the size of the buffers "
1808 "that have been allocated for ELS response data "
1809 "(adapter: %s, resp_buf_length=%d)\n",
1810 zfcp_get_busid_by_adapter(adapter),
1811 bottom->resp_buf_length);
1812 break;
1813
1814 case FSF_SBAL_MISMATCH:
1815 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1817 "resp_buf_length=%d)\n",
1818 zfcp_get_busid_by_adapter(adapter),
1819 bottom->req_buf_length, bottom->resp_buf_length);
1820 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1821 break;
1822
1823 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001825 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 zfcp_get_busid_by_adapter(adapter), d_id);
1827 for (counter = 0; counter < 2; counter++) {
1828 subtable = header->fsf_status_qual.halfword[counter * 2];
1829 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1830 switch (subtable) {
1831 case FSF_SQ_CFDC_SUBTABLE_OS:
1832 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1833 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1834 case FSF_SQ_CFDC_SUBTABLE_LUN:
1835 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1836 zfcp_act_subtable_type[subtable], rule);
1837 break;
1838 }
1839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (port != NULL)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001841 zfcp_erp_port_access_denied(port, 56, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1843 break;
1844
1845 default:
1846 ZFCP_LOG_NORMAL(
1847 "bug: An unknown FSF Status was presented "
1848 "(adapter: %s, fsf_status=0x%08x)\n",
1849 zfcp_get_busid_by_adapter(adapter),
1850 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1852 break;
1853 }
1854
1855skip_fsfstatus:
1856 send_els->status = retval;
1857
Heiko Carstensaa551da2007-07-18 10:55:10 +02001858 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 send_els->handler(send_els->handler_data);
1860
1861 return retval;
1862}
1863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864int
1865zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1866{
1867 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001868 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001869 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001871 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
1873 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001874 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1876 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001877 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001878 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001879 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1881 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001882 zfcp_get_busid_by_adapter(adapter));
1883 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1884 lock_flags);
1885 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
1887
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001888 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001889 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1890 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001892 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001893 FSF_FEATURE_CFDC |
1894 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001895 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001896 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001897 fsf_req->erp_action = erp_action;
1898 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001900 zfcp_erp_start_timer(fsf_req);
1901 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001902 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1903 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001905 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1906 "data command on the adapter %s\n",
1907 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001908 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001910 }
1911 else
1912 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1913 "(adapter %s)\n",
1914 zfcp_get_busid_by_adapter(adapter));
1915
1916 return retval;
1917}
1918
1919int
1920zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1921 struct fsf_qtcb_bottom_config *data)
1922{
1923 volatile struct qdio_buffer_element *sbale;
1924 struct zfcp_fsf_req *fsf_req;
1925 unsigned long lock_flags;
1926 int retval;
1927
1928 /* setup new FSF request */
1929 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1930 0, NULL, &lock_flags, &fsf_req);
1931 if (retval) {
1932 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1933 "data request for adapter %s.\n",
1934 zfcp_get_busid_by_adapter(adapter));
1935 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1936 lock_flags);
1937 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 }
1939
Swen Schillig52ef11a2007-08-28 09:31:09 +02001940 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1941 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1942 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Swen Schillig52ef11a2007-08-28 09:31:09 +02001944 fsf_req->qtcb->bottom.config.feature_selection =
1945 FSF_FEATURE_CFDC |
1946 FSF_FEATURE_LUN_SHARING |
1947 FSF_FEATURE_NOTIFICATION_LOST |
1948 FSF_FEATURE_UPDATE_ALERT;
1949
1950 if (data)
1951 fsf_req->data = (unsigned long) data;
1952
1953 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1954 retval = zfcp_fsf_req_send(fsf_req);
1955 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001957 if (retval)
1958 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1959 "data command on the adapter %s\n",
1960 zfcp_get_busid_by_adapter(adapter));
1961 else
1962 wait_event(fsf_req->completion_wq,
1963 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1964
1965 zfcp_fsf_req_free(fsf_req);
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return retval;
1968}
1969
1970/**
1971 * zfcp_fsf_exchange_config_evaluate
1972 * @fsf_req: fsf_req which belongs to xchg config data request
1973 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1974 *
1975 * returns: -EIO on error, 0 otherwise
1976 */
1977static int
1978zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1979{
1980 struct fsf_qtcb_bottom_config *bottom;
1981 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001982 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984 bottom = &fsf_req->qtcb->bottom.config;
1985 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1986 bottom->low_qtcb_version, bottom->high_qtcb_version);
1987 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001988 adapter->adapter_features = bottom->adapter_features;
1989 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05001990 adapter->peer_wwpn = 0;
1991 adapter->peer_wwnn = 0;
1992 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001995
1996 if (fsf_req->data)
1997 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1998 bottom, sizeof (struct fsf_qtcb_bottom_config));
1999
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002000 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2001 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2002 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2003 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002004 fc_host_supported_classes(shost) =
2005 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002007 if (fc_host_permanent_port_name(shost) == -1)
2008 fc_host_permanent_port_name(shost) =
2009 fc_host_port_name(shost);
2010 if (bottom->fc_topology == FSF_TOPO_P2P) {
2011 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2012 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2013 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2014 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2015 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2016 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2017 else if (bottom->fc_topology == FSF_TOPO_AL)
2018 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2019 else
2020 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002022 fc_host_node_name(shost) = 0;
2023 fc_host_port_name(shost) = 0;
2024 fc_host_port_id(shost) = 0;
2025 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002026 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 adapter->hydra_version = 0;
2028 }
2029
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002030 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002032 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2033 min(FC_SERIAL_NUMBER_SIZE, 17));
2034 EBCASC(fc_host_serial_number(shost),
2035 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 }
2037
Swen Schillig52ef11a2007-08-28 09:31:09 +02002038 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2039 "characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002040 "WWNN 0x%016Lx, "
2041 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002042 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002043 "adapter version 0x%x, "
2044 "LIC version 0x%x, "
2045 "FC link speed %d Gb/s\n",
2046 zfcp_get_busid_by_adapter(adapter),
2047 (wwn_t) fc_host_node_name(shost),
2048 (wwn_t) fc_host_port_name(shost),
2049 fc_host_port_id(shost),
2050 adapter->hydra_version,
2051 adapter->fsf_lic_version,
2052 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2054 ZFCP_LOG_NORMAL("error: the adapter %s "
2055 "only supports newer control block "
2056 "versions in comparison to this device "
2057 "driver (try updated device driver)\n",
2058 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002059 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 return -EIO;
2061 }
2062 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2063 ZFCP_LOG_NORMAL("error: the adapter %s "
2064 "only supports older control block "
2065 "versions than this device driver uses"
2066 "(consider a microcode upgrade)\n",
2067 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002068 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 return -EIO;
2070 }
2071 return 0;
2072}
2073
Swen Schillig52ef11a2007-08-28 09:31:09 +02002074/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 * function: zfcp_fsf_exchange_config_data_handler
2076 *
2077 * purpose: is called for finished Exchange Configuration Data command
2078 *
2079 * returns:
2080 */
2081static int
2082zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2083{
2084 struct fsf_qtcb_bottom_config *bottom;
2085 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002086 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
2088 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2089 return -EIO;
2090
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002091 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2095 return -EIO;
2096
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002097 switch (fc_host_port_type(adapter->scsi_host)) {
2098 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002099 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2100 "configuration detected at adapter %s\n"
2101 "Peer WWNN 0x%016llx, "
2102 "peer WWPN 0x%016llx, "
2103 "peer d_id 0x%06x\n",
2104 zfcp_get_busid_by_adapter(adapter),
2105 adapter->peer_wwnn,
2106 adapter->peer_wwpn,
2107 adapter->peer_d_id);
6f71d9b2005-04-10 23:04:28 -05002108 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002109 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2111 "topology detected at adapter %s "
2112 "unsupported, shutting down adapter\n",
2113 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002114 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002116 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002117 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002118 "network detected at adapter %s.\n",
2119 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 break;
2121 default:
2122 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2123 "reported by the exchange "
2124 "configuration command for "
2125 "the adapter %s is not "
2126 "of a type known to the zfcp "
2127 "driver, shutting down adapter\n",
2128 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002129 zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 return -EIO;
2131 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002132 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2134 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2135 "allowed by the adapter %s "
2136 "is lower than the minimum "
2137 "required by the driver (%ld bytes).\n",
2138 bottom->max_qtcb_size,
2139 zfcp_get_busid_by_adapter(adapter),
2140 sizeof(struct fsf_qtcb));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002141 zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 return -EIO;
2143 }
2144 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2145 &adapter->status);
2146 break;
2147 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2149 return -EIO;
2150
Swen Schillig52ef11a2007-08-28 09:31:09 +02002151 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2152 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002153
Martin Peschke698ec0162008-03-27 14:22:02 +01002154 zfcp_fsf_link_down_info_eval(fsf_req, 42,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002155 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 break;
2157 default:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002158 zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 return -EIO;
2160 }
2161 return 0;
2162}
2163
2164/**
2165 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002166 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 */
2168int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002169zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
2171 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002172 struct zfcp_fsf_req *fsf_req;
2173 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002174 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002175 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002177 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002179 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002181 return -EOPNOTSUPP;
2182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 /* setup new FSF request */
2185 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002186 ZFCP_REQ_AUTO_CLEANUP,
2187 adapter->pool.fsf_req_erp,
2188 &lock_flags, &fsf_req);
2189 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002191 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002192 "the adapter %s.\n",
2193 zfcp_get_busid_by_adapter(adapter));
2194 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2195 lock_flags);
2196 return retval;
2197 }
2198
2199 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2200 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2201 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2202
2203 erp_action->fsf_req = fsf_req;
2204 fsf_req->erp_action = erp_action;
2205 zfcp_erp_start_timer(fsf_req);
2206
2207 retval = zfcp_fsf_req_send(fsf_req);
2208 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2209
2210 if (retval) {
2211 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2212 "command on the adapter %s\n",
2213 zfcp_get_busid_by_adapter(adapter));
2214 zfcp_fsf_req_free(fsf_req);
2215 erp_action->fsf_req = NULL;
2216 }
2217 else
2218 ZFCP_LOG_DEBUG("exchange port data request initiated "
2219 "(adapter %s)\n",
2220 zfcp_get_busid_by_adapter(adapter));
2221 return retval;
2222}
2223
2224
2225/**
2226 * zfcp_fsf_exchange_port_data_sync - request information about local port
2227 * and wait until information is ready
2228 */
2229int
2230zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2231 struct fsf_qtcb_bottom_port *data)
2232{
2233 volatile struct qdio_buffer_element *sbale;
2234 struct zfcp_fsf_req *fsf_req;
2235 unsigned long lock_flags;
2236 int retval;
2237
2238 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2239 ZFCP_LOG_INFO("error: exchange port data "
2240 "command not supported by adapter %s\n",
2241 zfcp_get_busid_by_adapter(adapter));
2242 return -EOPNOTSUPP;
2243 }
2244
2245 /* setup new FSF request */
2246 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2247 0, NULL, &lock_flags, &fsf_req);
2248 if (retval) {
2249 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002250 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002251 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 zfcp_get_busid_by_adapter(adapter));
2253 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2254 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002255 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002256 }
2257
2258 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002259 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002262 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2263 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Swen Schillig52ef11a2007-08-28 09:31:09 +02002265 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002266 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002267 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Swen Schillig52ef11a2007-08-28 09:31:09 +02002269 if (retval)
2270 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2271 "command on the adapter %s\n",
2272 zfcp_get_busid_by_adapter(adapter));
2273 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002274 wait_event(fsf_req->completion_wq,
2275 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002276
2277 zfcp_fsf_req_free(fsf_req);
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 return retval;
2280}
2281
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002282/**
2283 * zfcp_fsf_exchange_port_evaluate
2284 * @fsf_req: fsf_req which belongs to xchg port data request
2285 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2286 */
2287static void
2288zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2289{
2290 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002291 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002292 struct Scsi_Host *shost;
2293
2294 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002295 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002296 shost = adapter->scsi_host;
2297
Swen Schillig52ef11a2007-08-28 09:31:09 +02002298 if (fsf_req->data)
2299 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2300 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002301
2302 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2303 fc_host_permanent_port_name(shost) = bottom->wwpn;
2304 else
2305 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2306 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2307 fc_host_supported_speeds(shost) = bottom->supported_speed;
2308}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
2310/**
2311 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2312 * @fsf_req: pointer to struct zfcp_fsf_req
2313 */
2314static void
2315zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2316{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002317 struct zfcp_adapter *adapter;
2318 struct fsf_qtcb *qtcb;
2319
2320 adapter = fsf_req->adapter;
2321 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
2323 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2324 return;
2325
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002326 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002328 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002329 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002330 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002331 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002332 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002333 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Martin Peschke698ec0162008-03-27 14:22:02 +01002334 zfcp_fsf_link_down_info_eval(fsf_req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002335 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
2338}
2339
2340
2341/*
2342 * function: zfcp_fsf_open_port
2343 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002344 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 *
2346 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002347 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 */
2349int
2350zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2351{
2352 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002353 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 unsigned long lock_flags;
2355 int retval = 0;
2356
2357 /* setup new FSF request */
2358 retval = zfcp_fsf_req_create(erp_action->adapter,
2359 FSF_QTCB_OPEN_PORT_WITH_DID,
2360 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2361 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002362 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 if (retval < 0) {
2364 ZFCP_LOG_INFO("error: Could not create open port request "
2365 "for port 0x%016Lx on adapter %s.\n",
2366 erp_action->port->wwpn,
2367 zfcp_get_busid_by_adapter(erp_action->adapter));
2368 goto out;
2369 }
2370
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002371 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2373 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2374
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002375 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002377 fsf_req->data = (unsigned long) erp_action->port;
2378 fsf_req->erp_action = erp_action;
2379 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002381 zfcp_erp_start_timer(fsf_req);
2382 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 if (retval) {
2384 ZFCP_LOG_INFO("error: Could not send open port request for "
2385 "port 0x%016Lx on adapter %s.\n",
2386 erp_action->port->wwpn,
2387 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002388 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 erp_action->fsf_req = NULL;
2390 goto out;
2391 }
2392
2393 ZFCP_LOG_DEBUG("open port request initiated "
2394 "(adapter %s, port 0x%016Lx)\n",
2395 zfcp_get_busid_by_adapter(erp_action->adapter),
2396 erp_action->port->wwpn);
2397 out:
2398 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2399 lock_flags);
2400 return retval;
2401}
2402
2403/*
2404 * function: zfcp_fsf_open_port_handler
2405 *
2406 * purpose: is called for finished Open Port command
2407 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002408 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 */
2410static int
2411zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2412{
2413 int retval = -EINVAL;
2414 struct zfcp_port *port;
2415 struct fsf_plogi *plogi;
2416 struct fsf_qtcb_header *header;
2417 u16 subtable, rule, counter;
2418
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002419 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 header = &fsf_req->qtcb->header;
2421
2422 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2423 /* don't change port status in our bookkeeping */
2424 goto skip_fsfstatus;
2425 }
2426
2427 /* evaluate FSF status in QTCB */
2428 switch (header->fsf_status) {
2429
2430 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2432 "is already open.\n",
2433 port->wwpn, zfcp_get_busid_by_port(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 /*
2435 * This is a bug, however operation should continue normally
2436 * if it is simply ignored
2437 */
2438 break;
2439
2440 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2442 "on adapter %s\n",
2443 port->wwpn, zfcp_get_busid_by_port(port));
2444 for (counter = 0; counter < 2; counter++) {
2445 subtable = header->fsf_status_qual.halfword[counter * 2];
2446 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2447 switch (subtable) {
2448 case FSF_SQ_CFDC_SUBTABLE_OS:
2449 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2450 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2451 case FSF_SQ_CFDC_SUBTABLE_LUN:
2452 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2453 zfcp_act_subtable_type[subtable], rule);
2454 break;
2455 }
2456 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02002457 zfcp_erp_port_access_denied(port, 57, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2459 break;
2460
2461 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2463 "The remote port 0x%016Lx on adapter %s "
2464 "could not be opened. Disabling it.\n",
2465 port->wwpn, zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002466 zfcp_erp_port_failed(port, 31, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2468 break;
2469
2470 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 switch (header->fsf_status_qual.word[0]) {
2472 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 /* ERP strategy will escalate */
2474 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2475 break;
2476 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2477 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2479 break;
2480 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2482 "adapter %s could not be opened. "
2483 "Disabling it.\n",
2484 port->wwpn,
2485 zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002486 zfcp_erp_port_failed(port, 32, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2488 break;
2489 default:
2490 ZFCP_LOG_NORMAL
2491 ("bug: Wrong status qualifier 0x%x arrived.\n",
2492 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 break;
2494 }
2495 break;
2496
2497 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 /* save port handle assigned by FSF */
2499 port->handle = header->port_handle;
2500 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2501 "was opened, it's port handle is 0x%x\n",
2502 port->wwpn, zfcp_get_busid_by_port(port),
2503 port->handle);
2504 /* mark port as open */
2505 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2506 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002507 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2508 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2509 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 retval = 0;
2511 /* check whether D_ID has changed during open */
2512 /*
2513 * FIXME: This check is not airtight, as the FCP channel does
2514 * not monitor closures of target port connections caused on
2515 * the remote side. Thus, they might miss out on invalidating
2516 * locally cached WWPNs (and other N_Port parameters) of gone
2517 * target ports. So, our heroic attempt to make things safe
2518 * could be undermined by 'open port' response data tagged with
2519 * obsolete WWPNs. Another reason to monitor potential
2520 * connection closures ourself at least (by interpreting
2521 * incoming ELS' and unsolicited status). It just crosses my
2522 * mind that one should be able to cross-check by means of
2523 * another GID_PN straight after a port has been opened.
2524 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2525 */
2526 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2527 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2528 {
2529 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002530 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 ZFCP_LOG_INFO(
2532 "warning: insufficient length of "
2533 "PLOGI payload (%i)\n",
2534 fsf_req->qtcb->bottom.support.els1_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 /* skip sanity check and assume wwpn is ok */
2536 } else {
2537 if (plogi->serv_param.wwpn != port->wwpn) {
2538 ZFCP_LOG_INFO("warning: d_id of port "
2539 "0x%016Lx changed during "
2540 "open\n", port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 atomic_clear_mask(
2542 ZFCP_STATUS_PORT_DID_DID,
2543 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002544 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002546 zfcp_plogi_evaluate(port, plogi);
2547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 }
2549 }
2550 break;
2551
2552 case FSF_UNKNOWN_OP_SUBTYPE:
2553 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2555 "op_subtype=0x%x)\n",
2556 zfcp_get_busid_by_port(port),
2557 fsf_req->qtcb->bottom.support.operation_subtype);
2558 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2559 break;
2560
2561 default:
2562 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2563 "(debug info 0x%x)\n",
2564 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 break;
2566 }
2567
2568 skip_fsfstatus:
2569 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2570 return retval;
2571}
2572
2573/*
2574 * function: zfcp_fsf_close_port
2575 *
2576 * purpose: submit FSF command "close port"
2577 *
2578 * returns: address of initiated FSF request
2579 * NULL - request could not be initiated
2580 */
2581int
2582zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2583{
2584 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002585 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 unsigned long lock_flags;
2587 int retval = 0;
2588
2589 /* setup new FSF request */
2590 retval = zfcp_fsf_req_create(erp_action->adapter,
2591 FSF_QTCB_CLOSE_PORT,
2592 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2593 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002594 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 if (retval < 0) {
2596 ZFCP_LOG_INFO("error: Could not create a close port request "
2597 "for port 0x%016Lx on adapter %s.\n",
2598 erp_action->port->wwpn,
2599 zfcp_get_busid_by_adapter(erp_action->adapter));
2600 goto out;
2601 }
2602
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002603 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2605 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2606
2607 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002608 fsf_req->data = (unsigned long) erp_action->port;
2609 fsf_req->erp_action = erp_action;
2610 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2611 fsf_req->erp_action = erp_action;
2612 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002614 zfcp_erp_start_timer(fsf_req);
2615 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 if (retval) {
2617 ZFCP_LOG_INFO("error: Could not send a close port request for "
2618 "port 0x%016Lx on adapter %s.\n",
2619 erp_action->port->wwpn,
2620 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002621 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 erp_action->fsf_req = NULL;
2623 goto out;
2624 }
2625
2626 ZFCP_LOG_TRACE("close port request initiated "
2627 "(adapter %s, port 0x%016Lx)\n",
2628 zfcp_get_busid_by_adapter(erp_action->adapter),
2629 erp_action->port->wwpn);
2630 out:
2631 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2632 lock_flags);
2633 return retval;
2634}
2635
2636/*
2637 * function: zfcp_fsf_close_port_handler
2638 *
2639 * purpose: is called for finished Close Port FSF command
2640 *
2641 * returns:
2642 */
2643static int
2644zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2645{
2646 int retval = -EINVAL;
2647 struct zfcp_port *port;
2648
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002649 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2652 /* don't change port status in our bookkeeping */
2653 goto skip_fsfstatus;
2654 }
2655
2656 /* evaluate FSF status in QTCB */
2657 switch (fsf_req->qtcb->header.fsf_status) {
2658
2659 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2661 "0x%016Lx on adapter %s invalid. This may happen "
2662 "occasionally.\n", port->handle,
2663 port->wwpn, zfcp_get_busid_by_port(port));
2664 ZFCP_LOG_DEBUG("status qualifier:\n");
2665 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2666 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2667 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002668 zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2670 break;
2671
2672 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 /* Note: FSF has actually closed the port in this case.
2674 * The status code is just daft. Fingers crossed for a change
2675 */
2676 retval = 0;
2677 break;
2678
2679 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2681 "port handle 0x%x\n", port->wwpn,
2682 zfcp_get_busid_by_port(port), port->handle);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002683 zfcp_erp_modify_port_status(port, 33, fsf_req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 ZFCP_STATUS_COMMON_OPEN,
2685 ZFCP_CLEAR);
2686 retval = 0;
2687 break;
2688
2689 default:
2690 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2691 "(debug info 0x%x)\n",
2692 fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 break;
2694 }
2695
2696 skip_fsfstatus:
2697 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2698 return retval;
2699}
2700
2701/*
2702 * function: zfcp_fsf_close_physical_port
2703 *
2704 * purpose: submit FSF command "close physical port"
2705 *
2706 * returns: address of initiated FSF request
2707 * NULL - request could not be initiated
2708 */
2709int
2710zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2711{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002713 struct zfcp_fsf_req *fsf_req;
2714 unsigned long lock_flags;
2715 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716
2717 /* setup new FSF request */
2718 retval = zfcp_fsf_req_create(erp_action->adapter,
2719 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2720 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2721 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002722 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 if (retval < 0) {
2724 ZFCP_LOG_INFO("error: Could not create close physical port "
2725 "request (adapter %s, port 0x%016Lx)\n",
2726 zfcp_get_busid_by_adapter(erp_action->adapter),
2727 erp_action->port->wwpn);
2728
2729 goto out;
2730 }
2731
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002732 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2734 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2735
2736 /* mark port as being closed */
2737 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2738 &erp_action->port->status);
2739 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002740 fsf_req->data = (unsigned long) erp_action->port;
2741 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2742 fsf_req->erp_action = erp_action;
2743 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002745 zfcp_erp_start_timer(fsf_req);
2746 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 if (retval) {
2748 ZFCP_LOG_INFO("error: Could not send close physical port "
2749 "request (adapter %s, port 0x%016Lx)\n",
2750 zfcp_get_busid_by_adapter(erp_action->adapter),
2751 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002752 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 erp_action->fsf_req = NULL;
2754 goto out;
2755 }
2756
2757 ZFCP_LOG_TRACE("close physical port request initiated "
2758 "(adapter %s, port 0x%016Lx)\n",
2759 zfcp_get_busid_by_adapter(erp_action->adapter),
2760 erp_action->port->wwpn);
2761 out:
2762 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2763 lock_flags);
2764 return retval;
2765}
2766
2767/*
2768 * function: zfcp_fsf_close_physical_port_handler
2769 *
2770 * purpose: is called for finished Close Physical Port FSF command
2771 *
2772 * returns:
2773 */
2774static int
2775zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2776{
2777 int retval = -EINVAL;
2778 struct zfcp_port *port;
2779 struct zfcp_unit *unit;
2780 struct fsf_qtcb_header *header;
2781 u16 subtable, rule, counter;
2782
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002783 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 header = &fsf_req->qtcb->header;
2785
2786 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2787 /* don't change port status in our bookkeeping */
2788 goto skip_fsfstatus;
2789 }
2790
2791 /* evaluate FSF status in QTCB */
2792 switch (header->fsf_status) {
2793
2794 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2796 "(adapter %s, port 0x%016Lx). "
2797 "This may happen occasionally.\n",
2798 port->handle,
2799 zfcp_get_busid_by_port(port),
2800 port->wwpn);
2801 ZFCP_LOG_DEBUG("status qualifier:\n");
2802 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2803 (char *) &header->fsf_status_qual,
2804 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002805 zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2807 break;
2808
2809 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 ZFCP_LOG_NORMAL("Access denied, cannot close "
2811 "physical port 0x%016Lx on adapter %s\n",
2812 port->wwpn, zfcp_get_busid_by_port(port));
2813 for (counter = 0; counter < 2; counter++) {
2814 subtable = header->fsf_status_qual.halfword[counter * 2];
2815 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2816 switch (subtable) {
2817 case FSF_SQ_CFDC_SUBTABLE_OS:
2818 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2819 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2820 case FSF_SQ_CFDC_SUBTABLE_LUN:
2821 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2822 zfcp_act_subtable_type[subtable], rule);
2823 break;
2824 }
2825 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02002826 zfcp_erp_port_access_denied(port, 58, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2828 break;
2829
2830 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2832 "%s needs to be reopened but it was attempted "
2833 "to close it physically.\n",
2834 port->wwpn,
2835 zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002836 zfcp_erp_port_boxed(port, 50, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2838 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01002839
2840 /* can't use generic zfcp_erp_modify_port_status because
2841 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2842 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2843 list_for_each_entry(unit, &port->unit_list_head, list)
2844 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2845 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 break;
2847
2848 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 switch (header->fsf_status_qual.word[0]) {
2850 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 /* This will now be escalated by ERP */
2852 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2853 break;
2854 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2857 break;
2858 default:
2859 ZFCP_LOG_NORMAL
2860 ("bug: Wrong status qualifier 0x%x arrived.\n",
2861 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 break;
2863 }
2864 break;
2865
2866 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2868 "physically closed, port handle 0x%x\n",
2869 port->wwpn,
2870 zfcp_get_busid_by_port(port), port->handle);
2871 /* can't use generic zfcp_erp_modify_port_status because
2872 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2873 */
2874 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2875 list_for_each_entry(unit, &port->unit_list_head, list)
2876 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2877 retval = 0;
2878 break;
2879
2880 default:
2881 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2882 "(debug info 0x%x)\n",
2883 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 break;
2885 }
2886
2887 skip_fsfstatus:
2888 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2889 return retval;
2890}
2891
2892/*
2893 * function: zfcp_fsf_open_unit
2894 *
2895 * purpose:
2896 *
2897 * returns:
2898 *
2899 * assumptions: This routine does not check whether the associated
2900 * remote port has already been opened. This should be
2901 * done by calling routines. Otherwise some status
2902 * may be presented by FSF
2903 */
2904int
2905zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2906{
2907 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002908 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 unsigned long lock_flags;
2910 int retval = 0;
2911
2912 /* setup new FSF request */
2913 retval = zfcp_fsf_req_create(erp_action->adapter,
2914 FSF_QTCB_OPEN_LUN,
2915 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2916 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002917 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 if (retval < 0) {
2919 ZFCP_LOG_INFO("error: Could not create open unit request for "
2920 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2921 erp_action->unit->fcp_lun,
2922 erp_action->unit->port->wwpn,
2923 zfcp_get_busid_by_adapter(erp_action->adapter));
2924 goto out;
2925 }
2926
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002927 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2929 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2930
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002931 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2932 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002933 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002934 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02002935 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002937 fsf_req->data = (unsigned long) erp_action->unit;
2938 fsf_req->erp_action = erp_action;
2939 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002941 zfcp_erp_start_timer(fsf_req);
2942 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 if (retval) {
2944 ZFCP_LOG_INFO("error: Could not send an open unit request "
2945 "on the adapter %s, port 0x%016Lx for "
2946 "unit 0x%016Lx\n",
2947 zfcp_get_busid_by_adapter(erp_action->adapter),
2948 erp_action->port->wwpn,
2949 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002950 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 erp_action->fsf_req = NULL;
2952 goto out;
2953 }
2954
2955 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2956 "port 0x%016Lx, unit 0x%016Lx)\n",
2957 zfcp_get_busid_by_adapter(erp_action->adapter),
2958 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2959 out:
2960 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2961 lock_flags);
2962 return retval;
2963}
2964
2965/*
2966 * function: zfcp_fsf_open_unit_handler
2967 *
2968 * purpose: is called for finished Open LUN command
2969 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002970 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 */
2972static int
2973zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2974{
2975 int retval = -EINVAL;
2976 struct zfcp_adapter *adapter;
2977 struct zfcp_unit *unit;
2978 struct fsf_qtcb_header *header;
2979 struct fsf_qtcb_bottom_support *bottom;
2980 struct fsf_queue_designator *queue_designator;
2981 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002982 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002984 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
2986 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2987 /* don't change unit status in our bookkeeping */
2988 goto skip_fsfstatus;
2989 }
2990
2991 adapter = fsf_req->adapter;
2992 header = &fsf_req->qtcb->header;
2993 bottom = &fsf_req->qtcb->bottom.support;
2994 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2995
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02002997 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 ZFCP_STATUS_UNIT_SHARED |
2999 ZFCP_STATUS_UNIT_READONLY,
3000 &unit->status);
3001
3002 /* evaluate FSF status in QTCB */
3003 switch (header->fsf_status) {
3004
3005 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3007 "for port 0x%016Lx on adapter %s invalid "
3008 "This may happen occasionally\n",
3009 unit->port->handle,
3010 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3011 ZFCP_LOG_DEBUG("status qualifier:\n");
3012 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3013 (char *) &header->fsf_status_qual,
3014 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003015 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3017 break;
3018
3019 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3021 "remote port 0x%016Lx on adapter %s twice.\n",
3022 unit->fcp_lun,
3023 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3025 break;
3026
3027 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3029 "remote port 0x%016Lx on adapter %s\n",
3030 unit->fcp_lun, unit->port->wwpn,
3031 zfcp_get_busid_by_unit(unit));
3032 for (counter = 0; counter < 2; counter++) {
3033 subtable = header->fsf_status_qual.halfword[counter * 2];
3034 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3035 switch (subtable) {
3036 case FSF_SQ_CFDC_SUBTABLE_OS:
3037 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3038 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3039 case FSF_SQ_CFDC_SUBTABLE_LUN:
3040 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3041 zfcp_act_subtable_type[subtable], rule);
3042 break;
3043 }
3044 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02003045 zfcp_erp_unit_access_denied(unit, 59, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3047 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3048 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3049 break;
3050
3051 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3053 "needs to be reopened\n",
3054 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003055 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3057 ZFCP_STATUS_FSFREQ_RETRY;
3058 break;
3059
3060 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 if (header->fsf_status_qual.word[0] != 0) {
3062 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3063 "with WWPN 0x%Lx "
3064 "connected to the adapter %s "
3065 "is already in use in LPAR%d, CSS%d\n",
3066 unit->fcp_lun,
3067 unit->port->wwpn,
3068 zfcp_get_busid_by_unit(unit),
3069 queue_designator->hla,
3070 queue_designator->cssid);
3071 } else {
3072 subtable = header->fsf_status_qual.halfword[4];
3073 rule = header->fsf_status_qual.halfword[5];
3074 switch (subtable) {
3075 case FSF_SQ_CFDC_SUBTABLE_OS:
3076 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3077 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3078 case FSF_SQ_CFDC_SUBTABLE_LUN:
3079 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3080 "remote port with WWPN 0x%Lx "
3081 "connected to the adapter %s "
3082 "is denied (%s rule %d)\n",
3083 unit->fcp_lun,
3084 unit->port->wwpn,
3085 zfcp_get_busid_by_unit(unit),
3086 zfcp_act_subtable_type[subtable],
3087 rule);
3088 break;
3089 }
3090 }
3091 ZFCP_LOG_DEBUG("status qualifier:\n");
3092 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3093 (char *) &header->fsf_status_qual,
3094 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003095 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3097 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3098 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3099 break;
3100
3101 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3103 "There is no handle (temporary port identifier) "
3104 "available for unit 0x%016Lx on port 0x%016Lx "
3105 "on adapter %s\n",
3106 unit->fcp_lun,
3107 unit->port->wwpn,
3108 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003109 zfcp_erp_unit_failed(unit, 34, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3111 break;
3112
3113 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 switch (header->fsf_status_qual.word[0]) {
3115 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 /* Re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003117 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3119 break;
3120 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3123 break;
3124 default:
3125 ZFCP_LOG_NORMAL
3126 ("bug: Wrong status qualifier 0x%x arrived.\n",
3127 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 }
3129 break;
3130
3131 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 ZFCP_LOG_NORMAL(
3133 "Invalid option 0x%x has been specified "
3134 "in QTCB bottom sent to the adapter %s\n",
3135 bottom->option,
3136 zfcp_get_busid_by_adapter(adapter));
3137 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3138 retval = -EINVAL;
3139 break;
3140
3141 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 /* save LUN handle assigned by FSF */
3143 unit->handle = header->lun_handle;
3144 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3145 "adapter %s opened, port handle 0x%x\n",
3146 unit->fcp_lun,
3147 unit->port->wwpn,
3148 zfcp_get_busid_by_unit(unit),
3149 unit->handle);
3150 /* mark unit as open */
3151 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003152
3153 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3154 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3155 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3156 exclusive = (bottom->lun_access_info &
3157 FSF_UNIT_ACCESS_EXCLUSIVE);
3158 readwrite = (bottom->lun_access_info &
3159 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3160
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 if (!exclusive)
3162 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3163 &unit->status);
3164
3165 if (!readwrite) {
3166 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3167 &unit->status);
3168 ZFCP_LOG_NORMAL("read-only access for unit "
3169 "(adapter %s, wwpn=0x%016Lx, "
3170 "fcp_lun=0x%016Lx)\n",
3171 zfcp_get_busid_by_unit(unit),
3172 unit->port->wwpn,
3173 unit->fcp_lun);
3174 }
3175
3176 if (exclusive && !readwrite) {
3177 ZFCP_LOG_NORMAL("exclusive access of read-only "
3178 "unit not supported\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02003179 zfcp_erp_unit_failed(unit, 35, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003181 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 } else if (!exclusive && readwrite) {
3183 ZFCP_LOG_NORMAL("shared access of read-write "
3184 "unit not supported\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02003185 zfcp_erp_unit_failed(unit, 36, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003187 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 }
3189 }
3190
3191 retval = 0;
3192 break;
3193
3194 default:
3195 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3196 "(debug info 0x%x)\n",
3197 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 break;
3199 }
3200
3201 skip_fsfstatus:
3202 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3203 return retval;
3204}
3205
3206/*
3207 * function: zfcp_fsf_close_unit
3208 *
3209 * purpose:
3210 *
3211 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003212 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 *
3214 * assumptions: This routine does not check whether the associated
3215 * remote port/lun has already been opened. This should be
3216 * done by calling routines. Otherwise some status
3217 * may be presented by FSF
3218 */
3219int
3220zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3221{
3222 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003223 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 unsigned long lock_flags;
3225 int retval = 0;
3226
3227 /* setup new FSF request */
3228 retval = zfcp_fsf_req_create(erp_action->adapter,
3229 FSF_QTCB_CLOSE_LUN,
3230 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3231 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003232 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 if (retval < 0) {
3234 ZFCP_LOG_INFO("error: Could not create close unit request for "
3235 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3236 erp_action->unit->fcp_lun,
3237 erp_action->port->wwpn,
3238 zfcp_get_busid_by_adapter(erp_action->adapter));
3239 goto out;
3240 }
3241
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003242 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3244 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3245
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003246 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3247 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003249 fsf_req->data = (unsigned long) erp_action->unit;
3250 fsf_req->erp_action = erp_action;
3251 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003253 zfcp_erp_start_timer(fsf_req);
3254 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 if (retval) {
3256 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3257 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3258 erp_action->unit->fcp_lun,
3259 erp_action->port->wwpn,
3260 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003261 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 erp_action->fsf_req = NULL;
3263 goto out;
3264 }
3265
3266 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3267 "port 0x%016Lx, unit 0x%016Lx)\n",
3268 zfcp_get_busid_by_adapter(erp_action->adapter),
3269 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3270 out:
3271 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3272 lock_flags);
3273 return retval;
3274}
3275
3276/*
3277 * function: zfcp_fsf_close_unit_handler
3278 *
3279 * purpose: is called for finished Close LUN FSF command
3280 *
3281 * returns:
3282 */
3283static int
3284zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3285{
3286 int retval = -EINVAL;
3287 struct zfcp_unit *unit;
3288
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003289 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
3291 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3292 /* don't change unit status in our bookkeeping */
3293 goto skip_fsfstatus;
3294 }
3295
3296 /* evaluate FSF status in QTCB */
3297 switch (fsf_req->qtcb->header.fsf_status) {
3298
3299 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3301 "0x%016Lx on adapter %s invalid. This may "
3302 "happen in rare circumstances\n",
3303 unit->port->handle,
3304 unit->port->wwpn,
3305 zfcp_get_busid_by_unit(unit));
3306 ZFCP_LOG_DEBUG("status qualifier:\n");
3307 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3308 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3309 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003310 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3312 break;
3313
3314 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3316 "0x%016Lx on port 0x%016Lx on adapter %s is "
3317 "invalid. This may happen occasionally.\n",
3318 unit->handle,
3319 unit->fcp_lun,
3320 unit->port->wwpn,
3321 zfcp_get_busid_by_unit(unit));
3322 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3323 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3324 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3325 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003326 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3328 break;
3329
3330 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3332 "needs to be reopened\n",
3333 unit->port->wwpn,
3334 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003335 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3337 ZFCP_STATUS_FSFREQ_RETRY;
3338 break;
3339
3340 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3342 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003344 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3346 break;
3347 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3350 break;
3351 default:
3352 ZFCP_LOG_NORMAL
3353 ("bug: Wrong status qualifier 0x%x arrived.\n",
3354 fsf_req->qtcb->header.fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 break;
3356 }
3357 break;
3358
3359 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3361 "closed, port handle 0x%x\n",
3362 unit->fcp_lun,
3363 unit->port->wwpn,
3364 zfcp_get_busid_by_unit(unit),
3365 unit->handle);
3366 /* mark unit as closed */
3367 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3368 retval = 0;
3369 break;
3370
3371 default:
3372 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3373 "(debug info 0x%x)\n",
3374 fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 break;
3376 }
3377
3378 skip_fsfstatus:
3379 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3380 return retval;
3381}
3382
3383/**
3384 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3385 * @adapter: adapter where scsi command is issued
3386 * @unit: unit where command is sent to
3387 * @scsi_cmnd: scsi command to be sent
3388 * @timer: timer to be started when request is initiated
3389 * @req_flags: flags for fsf_request
3390 */
3391int
3392zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3393 struct zfcp_unit *unit,
3394 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003395 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396{
3397 struct zfcp_fsf_req *fsf_req = NULL;
3398 struct fcp_cmnd_iu *fcp_cmnd_iu;
3399 unsigned int sbtype;
3400 unsigned long lock_flags;
3401 int real_bytes = 0;
3402 int retval = 0;
3403 int mask;
3404
3405 /* setup new FSF request */
3406 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3407 adapter->pool.fsf_req_scsi,
3408 &lock_flags, &fsf_req);
3409 if (unlikely(retval < 0)) {
3410 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3411 "for unit 0x%016Lx on port 0x%016Lx on "
3412 "adapter %s\n",
3413 unit->fcp_lun,
3414 unit->port->wwpn,
3415 zfcp_get_busid_by_adapter(adapter));
3416 goto failed_req_create;
3417 }
3418
Christof Schmittba172422007-12-20 12:30:26 +01003419 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3420 &unit->status))) {
3421 retval = -EBUSY;
3422 goto unit_blocked;
3423 }
3424
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003425 zfcp_unit_get(unit);
3426 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003428 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003429 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003430
3431 /* associate SCSI command with FSF request */
3432 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433
3434 /* set handles of unit and its parent port in QTCB */
3435 fsf_req->qtcb->header.lun_handle = unit->handle;
3436 fsf_req->qtcb->header.port_handle = unit->port->handle;
3437
3438 /* FSF does not define the structure of the FCP_CMND IU */
3439 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3440 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3441
3442 /*
3443 * set depending on data direction:
3444 * data direction bits in SBALE (SB Type)
3445 * data direction bits in QTCB
3446 * data direction bits in FCP_CMND IU
3447 */
3448 switch (scsi_cmnd->sc_data_direction) {
3449 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3451 /*
3452 * FIXME(qdio):
3453 * what is the correct type for commands
3454 * without 'real' data buffers?
3455 */
3456 sbtype = SBAL_FLAGS0_TYPE_READ;
3457 break;
3458 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3460 sbtype = SBAL_FLAGS0_TYPE_READ;
3461 fcp_cmnd_iu->rddata = 1;
3462 break;
3463 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3465 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3466 fcp_cmnd_iu->wddata = 1;
3467 break;
3468 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 default:
3470 /*
3471 * dummy, catch this condition earlier
3472 * in zfcp_scsi_queuecommand
3473 */
3474 goto failed_scsi_cmnd;
3475 }
3476
3477 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003478 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 /* set FCP_LUN in FCP_CMND IU in QTCB */
3481 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3482
3483 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3484
3485 /* set task attributes in FCP_CMND IU in QTCB */
3486 if (likely((scsi_cmnd->device->simple_tags) ||
3487 (atomic_test_mask(mask, &unit->status))))
3488 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3489 else
3490 fcp_cmnd_iu->task_attribute = UNTAGGED;
3491
3492 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3493 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3494 fcp_cmnd_iu->add_fcp_cdb_length
3495 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3496 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3497 "additional FCP_CDB length is 0x%x "
3498 "(shifted right 2 bits)\n",
3499 scsi_cmnd->cmd_len,
3500 fcp_cmnd_iu->add_fcp_cdb_length);
3501 }
3502 /*
3503 * copy SCSI CDB (including additional length, if any) to
3504 * FCP_CDB in FCP_CMND IU in QTCB
3505 */
3506 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3507
3508 /* FCP CMND IU length in QTCB */
3509 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3510 sizeof (struct fcp_cmnd_iu) +
3511 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3512
3513 /* generate SBALEs from data buffer */
3514 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3515 if (unlikely(real_bytes < 0)) {
3516 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3517 ZFCP_LOG_DEBUG(
3518 "Data did not fit into available buffer(s), "
3519 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003520 retval = -EIO;
3521 } else {
3522 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3523 "required. Shutting down unit "
3524 "(adapter %s, port 0x%016Lx, "
3525 "unit 0x%016Lx)\n",
3526 zfcp_get_busid_by_unit(unit),
3527 unit->port->wwpn,
3528 unit->fcp_lun);
Martin Peschke1f6f7122008-04-18 12:51:55 +02003529 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
Christof Schmitt2282f652007-08-28 09:30:22 +02003530 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 }
3532 goto no_fit;
3533 }
3534
3535 /* set length of FCP data length in FCP_CMND IU in QTCB */
3536 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3537
3538 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3539 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3540 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3541
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003542 if (use_timer)
3543 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3544
3545 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 if (unlikely(retval < 0)) {
3547 ZFCP_LOG_INFO("error: Could not send FCP command request "
3548 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3549 zfcp_get_busid_by_adapter(adapter),
3550 unit->port->wwpn,
3551 unit->fcp_lun);
3552 goto send_failed;
3553 }
3554
3555 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3556 "port 0x%016Lx, unit 0x%016Lx)\n",
3557 zfcp_get_busid_by_adapter(adapter),
3558 unit->port->wwpn,
3559 unit->fcp_lun);
3560 goto success;
3561
3562 send_failed:
3563 no_fit:
3564 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003565 zfcp_unit_put(unit);
Christof Schmitt57b76582008-04-18 12:51:57 +02003566 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 zfcp_fsf_req_free(fsf_req);
3568 fsf_req = NULL;
3569 scsi_cmnd->host_scribble = NULL;
3570 success:
3571 failed_req_create:
3572 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3573 return retval;
3574}
3575
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576struct zfcp_fsf_req *
3577zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3578 struct zfcp_unit *unit,
3579 u8 tm_flags, int req_flags)
3580{
3581 struct zfcp_fsf_req *fsf_req = NULL;
3582 int retval = 0;
3583 struct fcp_cmnd_iu *fcp_cmnd_iu;
3584 unsigned long lock_flags;
3585 volatile struct qdio_buffer_element *sbale;
3586
3587 /* setup new FSF request */
3588 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3589 adapter->pool.fsf_req_scsi,
3590 &lock_flags, &fsf_req);
3591 if (retval < 0) {
3592 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3593 "management) request for adapter %s, port "
3594 " 0x%016Lx, unit 0x%016Lx.\n",
3595 zfcp_get_busid_by_adapter(adapter),
3596 unit->port->wwpn, unit->fcp_lun);
3597 goto out;
3598 }
3599
Christof Schmittfdf23452007-12-20 12:30:27 +01003600 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3601 &unit->status)))
3602 goto unit_blocked;
3603
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 /*
3605 * Used to decide on proper handler in the return path,
3606 * could be either zfcp_fsf_send_fcp_command_task_handler or
3607 * zfcp_fsf_send_fcp_command_task_management_handler */
3608
3609 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3610
3611 /*
3612 * hold a pointer to the unit being target of this
3613 * task management request
3614 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003615 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616
3617 /* set FSF related fields in QTCB */
3618 fsf_req->qtcb->header.lun_handle = unit->handle;
3619 fsf_req->qtcb->header.port_handle = unit->port->handle;
3620 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003621 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3623 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3624
3625 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3626 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3627 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3628
3629 /* set FCP related fields in FCP_CMND IU in QTCB */
3630 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3631 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3632 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3633 fcp_cmnd_iu->task_management_flags = tm_flags;
3634
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003635 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3636 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmittfdf23452007-12-20 12:30:27 +01003637 if (!retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639
Christof Schmittfdf23452007-12-20 12:30:27 +01003640 unit_blocked:
3641 zfcp_fsf_req_free(fsf_req);
3642 fsf_req = NULL;
3643
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 out:
3645 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3646 return fsf_req;
3647}
3648
3649/*
3650 * function: zfcp_fsf_send_fcp_command_handler
3651 *
3652 * purpose: is called for finished Send FCP Command
3653 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003654 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 */
3656static int
3657zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3658{
3659 int retval = -EINVAL;
3660 struct zfcp_unit *unit;
3661 struct fsf_qtcb_header *header;
3662 u16 subtable, rule, counter;
3663
3664 header = &fsf_req->qtcb->header;
3665
3666 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003667 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003669 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670
3671 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3672 /* go directly to calls of special handlers */
3673 goto skip_fsfstatus;
3674 }
3675
3676 /* evaluate FSF status in QTCB */
3677 switch (header->fsf_status) {
3678
3679 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3681 "0x%016Lx on adapter %s invalid\n",
3682 unit->port->handle,
3683 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3684 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3685 (char *) &header->fsf_status_qual,
3686 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003687 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3689 break;
3690
3691 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3693 "0x%016Lx on port 0x%016Lx on adapter %s is "
3694 "invalid. This may happen occasionally.\n",
3695 unit->handle,
3696 unit->fcp_lun,
3697 unit->port->wwpn,
3698 zfcp_get_busid_by_unit(unit));
3699 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3700 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3701 (char *) &header->fsf_status_qual,
3702 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003703 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3705 break;
3706
3707 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3709 "unexpectedly. (adapter %s, port 0x%016Lx, "
3710 "unit 0x%016Lx)\n",
3711 unit->port->handle,
3712 zfcp_get_busid_by_unit(unit),
3713 unit->port->wwpn,
3714 unit->fcp_lun);
3715 ZFCP_LOG_NORMAL("status qualifier:\n");
3716 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3717 (char *) &header->fsf_status_qual,
3718 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003719 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3721 break;
3722
3723 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003724 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3725 "class %d.\n",
3726 zfcp_get_busid_by_unit(unit),
3727 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003729 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3731 break;
3732
3733 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3735 "adapter %s does not have correct unit "
3736 "handle 0x%x\n",
3737 unit->fcp_lun,
3738 unit->port->wwpn,
3739 zfcp_get_busid_by_unit(unit),
3740 unit->handle);
3741 ZFCP_LOG_DEBUG("status qualifier:\n");
3742 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3743 (char *) &header->fsf_status_qual,
3744 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003745 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3747 break;
3748
3749 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3751 "unit 0x%016Lx on port 0x%016Lx on "
3752 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3753 zfcp_get_busid_by_unit(unit));
3754 for (counter = 0; counter < 2; counter++) {
3755 subtable = header->fsf_status_qual.halfword[counter * 2];
3756 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3757 switch (subtable) {
3758 case FSF_SQ_CFDC_SUBTABLE_OS:
3759 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3760 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3761 case FSF_SQ_CFDC_SUBTABLE_LUN:
3762 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3763 zfcp_act_subtable_type[subtable], rule);
3764 break;
3765 }
3766 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02003767 zfcp_erp_unit_access_denied(unit, 61, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3769 break;
3770
3771 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3773 "0x%016Lx on port 0x%016Lx on adapter %s "
3774 "(debug info %d)\n",
3775 unit->fcp_lun,
3776 unit->port->wwpn,
3777 zfcp_get_busid_by_unit(unit),
3778 fsf_req->qtcb->bottom.io.data_direction);
3779 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003780 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3782 break;
3783
3784 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 ZFCP_LOG_NORMAL
3786 ("bug: An invalid control-data-block length field "
3787 "was found in a command for unit 0x%016Lx on port "
3788 "0x%016Lx on adapter %s " "(debug info %d)\n",
3789 unit->fcp_lun, unit->port->wwpn,
3790 zfcp_get_busid_by_unit(unit),
3791 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3792 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003793 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3795 break;
3796
3797 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3799 "needs to be reopened\n",
3800 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003801 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3803 ZFCP_STATUS_FSFREQ_RETRY;
3804 break;
3805
3806 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3808 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3809 zfcp_get_busid_by_unit(unit),
3810 unit->port->wwpn, unit->fcp_lun);
Martin Peschke1f6f7122008-04-18 12:51:55 +02003811 zfcp_erp_unit_boxed(unit, 54, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3813 | ZFCP_STATUS_FSFREQ_RETRY;
3814 break;
3815
3816 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 switch (header->fsf_status_qual.word[0]) {
3818 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003820 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 break;
3822 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 /* FIXME(hw) need proper specs for proper action */
3824 /* let scsi stack deal with retries and escalation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 break;
3826 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003828 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 break;
3831 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003832 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 break;
3834
3835 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 break;
3837
3838 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 }
3841
3842 skip_fsfstatus:
3843 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3844 retval =
3845 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3846 } else {
3847 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003848 fsf_req->unit = NULL;
3849 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 }
3851 return retval;
3852}
3853
3854/*
3855 * function: zfcp_fsf_send_fcp_command_task_handler
3856 *
3857 * purpose: evaluates FCP_RSP IU
3858 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003859 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 */
3861static int
3862zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3863{
3864 int retval = 0;
3865 struct scsi_cmnd *scpnt;
3866 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3867 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3868 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3869 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3870 u32 sns_len;
3871 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3872 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003873 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874
3875 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003876 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 if (unlikely(!scpnt)) {
3878 ZFCP_LOG_DEBUG
3879 ("Command with fsf_req %p is not associated to "
3880 "a scsi command anymore. Aborted?\n", fsf_req);
3881 goto out;
3882 }
3883 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3884 /* FIXME: (design) mid-layer should handle DID_ABORT like
3885 * DID_SOFT_ERROR by retrying the request for devices
3886 * that allow retries.
3887 */
3888 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3889 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3890 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3891 goto skip_fsfstatus;
3892 }
3893
3894 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3895 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3896 set_host_byte(&scpnt->result, DID_ERROR);
3897 goto skip_fsfstatus;
3898 }
3899
3900 /* set message byte of result in SCSI command */
3901 scpnt->result |= COMMAND_COMPLETE << 8;
3902
3903 /*
3904 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3905 * of result in SCSI command
3906 */
3907 scpnt->result |= fcp_rsp_iu->scsi_status;
3908 if (unlikely(fcp_rsp_iu->scsi_status)) {
3909 /* DEBUG */
3910 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
3911 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3912 scpnt->cmnd, scpnt->cmd_len);
3913 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
3914 fcp_rsp_iu->scsi_status);
3915 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3916 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
3917 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3918 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
3919 fcp_rsp_iu->fcp_sns_len);
3920 }
3921
3922 /* check FCP_RSP_INFO */
3923 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
3924 ZFCP_LOG_DEBUG("rsp_len is valid\n");
3925 switch (fcp_rsp_info[3]) {
3926 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 /* ok, continue */
3928 ZFCP_LOG_TRACE("no failure or Task Management "
3929 "Function complete\n");
3930 set_host_byte(&scpnt->result, DID_OK);
3931 break;
3932 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 /* hardware bug */
3934 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3935 "that the fibrechannel protocol data "
3936 "length differs from the burst length. "
3937 "The problem occured on unit 0x%016Lx "
3938 "on port 0x%016Lx on adapter %s",
3939 unit->fcp_lun,
3940 unit->port->wwpn,
3941 zfcp_get_busid_by_unit(unit));
3942 /* dump SCSI CDB as prepared by zfcp */
3943 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3944 (char *) &fsf_req->qtcb->
3945 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 set_host_byte(&scpnt->result, DID_ERROR);
3947 goto skip_fsfstatus;
3948 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 /* driver or hardware bug */
3950 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3951 "that the fibrechannel protocol data "
3952 "fields were incorrectly set up. "
3953 "The problem occured on the unit "
3954 "0x%016Lx on port 0x%016Lx on "
3955 "adapter %s",
3956 unit->fcp_lun,
3957 unit->port->wwpn,
3958 zfcp_get_busid_by_unit(unit));
3959 /* dump SCSI CDB as prepared by zfcp */
3960 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3961 (char *) &fsf_req->qtcb->
3962 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3963 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 goto skip_fsfstatus;
3965 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 /* hardware bug */
3967 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
3968 "that conflicting values for the "
3969 "fibrechannel payload offset from the "
3970 "header were found. "
3971 "The problem occured on unit 0x%016Lx "
3972 "on port 0x%016Lx on adapter %s.\n",
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 default:
3983 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
3984 "code was detected for a command. "
3985 "The problem occured on the unit "
3986 "0x%016Lx on port 0x%016Lx on "
3987 "adapter %s (debug info 0x%x)\n",
3988 unit->fcp_lun,
3989 unit->port->wwpn,
3990 zfcp_get_busid_by_unit(unit),
3991 fcp_rsp_info[3]);
3992 /* dump SCSI CDB as prepared by zfcp */
3993 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3994 (char *) &fsf_req->qtcb->
3995 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05003997 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 }
3999 }
4000
4001 /* check for sense data */
4002 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4003 sns_len = FSF_FCP_RSP_SIZE -
4004 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4005 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4006 sns_len);
4007 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4008 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4009 SCSI_SENSE_BUFFERSIZE);
4010 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4011 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4012 scpnt->result);
4013 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4014 (void *) &scpnt->cmnd, scpnt->cmd_len);
4015
4016 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4017 fcp_rsp_iu->fcp_sns_len);
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004018 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4020 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004021 (void *)scpnt->sense_buffer, sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 }
4023
4024 /* check for overrun */
4025 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4026 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4027 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4028 "The response data length is "
4029 "%d, the original length was %d.\n",
4030 unit->fcp_lun,
4031 unit->port->wwpn,
4032 zfcp_get_busid_by_unit(unit),
4033 fcp_rsp_iu->fcp_resid,
4034 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4035 }
4036
4037 /* check for underrun */
4038 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4039 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4040 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4041 "The response data length is "
4042 "%d, the original length was %d.\n",
4043 unit->fcp_lun,
4044 unit->port->wwpn,
4045 zfcp_get_busid_by_unit(unit),
4046 fcp_rsp_iu->fcp_resid,
4047 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4048
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004049 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4050 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4051 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004052 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 }
4054
4055 skip_fsfstatus:
4056 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4057
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004058 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004059 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004060 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004061 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004062 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004063 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064
4065 /* cleanup pointer (need this especially for abort) */
4066 scpnt->host_scribble = NULL;
4067
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 (scpnt->scsi_done) (scpnt);
4070
4071 /*
4072 * We must hold this lock until scsi_done has been called.
4073 * Otherwise we may call scsi_done after abort regarding this
4074 * command has completed.
4075 * Note: scsi_done must not block!
4076 */
4077 out:
4078 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4079 return retval;
4080}
4081
4082/*
4083 * function: zfcp_fsf_send_fcp_command_task_management_handler
4084 *
4085 * purpose: evaluates FCP_RSP IU
4086 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004087 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 */
4089static int
4090zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4091{
4092 int retval = 0;
4093 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4094 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4095 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004096 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4099 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4100 goto skip_fsfstatus;
4101 }
4102
4103 /* check FCP_RSP_INFO */
4104 switch (fcp_rsp_info[3]) {
4105 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 /* ok, continue */
4107 ZFCP_LOG_DEBUG("no failure or Task Management "
4108 "Function complete\n");
4109 break;
4110 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4112 "is not supported on the target device "
4113 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4114 unit->fcp_lun,
4115 unit->port->wwpn,
4116 zfcp_get_busid_by_unit(unit));
4117 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4118 break;
4119 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4121 "failed to complete successfully. "
4122 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4123 unit->fcp_lun,
4124 unit->port->wwpn,
4125 zfcp_get_busid_by_unit(unit));
4126 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4127 break;
4128 default:
4129 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4130 "code was detected for a command. "
4131 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4132 "(debug info 0x%x)\n",
4133 unit->fcp_lun,
4134 unit->port->wwpn,
4135 zfcp_get_busid_by_unit(unit),
4136 fcp_rsp_info[3]);
4137 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4138 }
4139
4140 skip_fsfstatus:
4141 return retval;
4142}
4143
4144
4145/*
4146 * function: zfcp_fsf_control_file
4147 *
4148 * purpose: Initiator of the control file upload/download FSF requests
4149 *
4150 * returns: 0 - FSF request is successfuly created and queued
4151 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4152 * -EINVAL - Invalid direction specified
4153 * -ENOMEM - Insufficient memory
4154 * -EPERM - Cannot create FSF request or place it in QDIO queue
4155 */
4156int
4157zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4158 struct zfcp_fsf_req **fsf_req_ptr,
4159 u32 fsf_command,
4160 u32 option,
4161 struct zfcp_sg_list *sg_list)
4162{
4163 struct zfcp_fsf_req *fsf_req;
4164 struct fsf_qtcb_bottom_support *bottom;
4165 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 unsigned long lock_flags;
4167 int req_flags = 0;
4168 int direction;
4169 int retval = 0;
4170
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004171 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4173 zfcp_get_busid_by_adapter(adapter));
4174 retval = -EOPNOTSUPP;
4175 goto out;
4176 }
4177
4178 switch (fsf_command) {
4179
4180 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4181 direction = SBAL_FLAGS0_TYPE_WRITE;
4182 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4183 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4184 req_flags = ZFCP_WAIT_FOR_SBAL;
4185 break;
4186
4187 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4188 direction = SBAL_FLAGS0_TYPE_READ;
4189 break;
4190
4191 default:
4192 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4193 retval = -EINVAL;
4194 goto out;
4195 }
4196
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4198 NULL, &lock_flags, &fsf_req);
4199 if (retval < 0) {
4200 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4201 "adapter %s\n",
4202 zfcp_get_busid_by_adapter(adapter));
4203 retval = -EPERM;
4204 goto unlock_queue_lock;
4205 }
4206
4207 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4208 sbale[0].flags |= direction;
4209
4210 bottom = &fsf_req->qtcb->bottom.support;
4211 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4212 bottom->option = option;
4213
4214 if (sg_list->count > 0) {
4215 int bytes;
4216
4217 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4218 sg_list->sg, sg_list->count,
4219 ZFCP_MAX_SBALS_PER_REQ);
4220 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4221 ZFCP_LOG_INFO(
4222 "error: Could not create sufficient number of "
4223 "SBALS for an FSF request to the adapter %s\n",
4224 zfcp_get_busid_by_adapter(adapter));
4225 retval = -ENOMEM;
4226 goto free_fsf_req;
4227 }
4228 } else
4229 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4230
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004231 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4232 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 if (retval < 0) {
4234 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4235 "(adapter %s)\n",
4236 zfcp_get_busid_by_adapter(adapter));
4237 retval = -EPERM;
4238 goto free_fsf_req;
4239 }
4240 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4241
4242 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4243 "adapter %s\n",
4244 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4245 "download" : "upload",
4246 zfcp_get_busid_by_adapter(adapter));
4247
4248 wait_event(fsf_req->completion_wq,
4249 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4250
4251 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004252 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253
4254 free_fsf_req:
4255 zfcp_fsf_req_free(fsf_req);
4256 unlock_queue_lock:
4257 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 out:
4259 return retval;
4260}
4261
4262
4263/*
4264 * function: zfcp_fsf_control_file_handler
4265 *
4266 * purpose: Handler of the control file upload/download FSF requests
4267 *
4268 * returns: 0 - FSF request successfuly processed
4269 * -EAGAIN - Operation has to be repeated because of a temporary problem
4270 * -EACCES - There is no permission to execute an operation
4271 * -EPERM - The control file is not in a right format
4272 * -EIO - There is a problem with the FCP adapter
4273 * -EINVAL - Invalid operation
4274 * -EFAULT - User space memory I/O operation fault
4275 */
4276static int
4277zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4278{
4279 struct zfcp_adapter *adapter = fsf_req->adapter;
4280 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4281 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4282 int retval = 0;
4283
4284 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4285 retval = -EINVAL;
4286 goto skip_fsfstatus;
4287 }
4288
4289 switch (header->fsf_status) {
4290
4291 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 ZFCP_LOG_NORMAL(
4293 "The FSF request has been successfully completed "
4294 "on the adapter %s\n",
4295 zfcp_get_busid_by_adapter(adapter));
4296 break;
4297
4298 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4300 switch (header->fsf_status_qual.word[0]) {
4301
6f71d9b2005-04-10 23:04:28 -05004302 case FSF_SQ_CFDC_HARDENED_ON_SE:
4303 ZFCP_LOG_NORMAL(
4304 "CFDC on the adapter %s has being "
4305 "hardened on primary and secondary SE\n",
4306 zfcp_get_busid_by_adapter(adapter));
4307 break;
4308
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4310 ZFCP_LOG_NORMAL(
4311 "CFDC of the adapter %s could not "
4312 "be saved on the SE\n",
4313 zfcp_get_busid_by_adapter(adapter));
4314 break;
4315
4316 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4317 ZFCP_LOG_NORMAL(
4318 "CFDC of the adapter %s could not "
4319 "be copied to the secondary SE\n",
4320 zfcp_get_busid_by_adapter(adapter));
4321 break;
4322
4323 default:
4324 ZFCP_LOG_NORMAL(
4325 "CFDC could not be hardened "
4326 "on the adapter %s\n",
4327 zfcp_get_busid_by_adapter(adapter));
4328 }
4329 }
4330 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4331 retval = -EAGAIN;
4332 break;
4333
4334 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 ZFCP_LOG_NORMAL(
4336 "Adapter %s does not accept privileged commands\n",
4337 zfcp_get_busid_by_adapter(adapter));
4338 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4339 retval = -EACCES;
4340 break;
4341
4342 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 ZFCP_LOG_NORMAL(
4344 "Error at position %d in the CFDC, "
4345 "CFDC is discarded by the adapter %s\n",
4346 header->fsf_status_qual.word[0],
4347 zfcp_get_busid_by_adapter(adapter));
4348 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4349 retval = -EPERM;
4350 break;
4351
4352 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 ZFCP_LOG_NORMAL(
4354 "Adapter %s cannot harden the control file, "
4355 "file is discarded\n",
4356 zfcp_get_busid_by_adapter(adapter));
4357 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4358 retval = -EIO;
4359 break;
4360
4361 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362 ZFCP_LOG_NORMAL(
4363 "Control file is too large, file is discarded "
4364 "by the adapter %s\n",
4365 zfcp_get_busid_by_adapter(adapter));
4366 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4367 retval = -EIO;
4368 break;
4369
4370 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4372 ZFCP_LOG_NORMAL(
4373 "CFDC has been discarded by the adapter %s, "
4374 "because activation would impact "
4375 "%d active connection(s)\n",
4376 zfcp_get_busid_by_adapter(adapter),
4377 header->fsf_status_qual.word[0]);
4378 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4379 retval = -EIO;
4380 break;
4381
4382 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4384 ZFCP_LOG_NORMAL(
4385 "CFDC has been activated on the adapter %s, "
4386 "but activation has impacted "
4387 "%d active connection(s)\n",
4388 zfcp_get_busid_by_adapter(adapter),
4389 header->fsf_status_qual.word[0]);
4390 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4391 retval = -EIO;
4392 break;
4393
4394 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4396 "op_subtype=0x%x)\n",
4397 zfcp_get_busid_by_adapter(adapter),
4398 bottom->operation_subtype);
4399 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4400 retval = -EINVAL;
4401 break;
4402
4403 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 ZFCP_LOG_NORMAL(
4405 "Invalid option 0x%x has been specified "
4406 "in QTCB bottom sent to the adapter %s\n",
4407 bottom->option,
4408 zfcp_get_busid_by_adapter(adapter));
4409 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4410 retval = -EINVAL;
4411 break;
4412
4413 default:
4414 ZFCP_LOG_NORMAL(
4415 "bug: An unknown/unexpected FSF status 0x%08x "
4416 "was presented on the adapter %s\n",
4417 header->fsf_status,
4418 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4420 retval = -EINVAL;
4421 break;
4422 }
4423
4424skip_fsfstatus:
4425 return retval;
4426}
4427
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428static inline int
4429zfcp_fsf_req_sbal_check(unsigned long *flags,
4430 struct zfcp_qdio_queue *queue, int needed)
4431{
4432 write_lock_irqsave(&queue->queue_lock, *flags);
4433 if (likely(atomic_read(&queue->free_count) >= needed))
4434 return 1;
4435 write_unlock_irqrestore(&queue->queue_lock, *flags);
4436 return 0;
4437}
4438
4439/*
4440 * set qtcb pointer in fsf_req and initialize QTCB
4441 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004442static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004443zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444{
4445 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004446 fsf_req->qtcb->prefix.req_seq_no =
4447 fsf_req->adapter->fsf_req_seq_no;
4448 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004450 fsf_req->qtcb->prefix.qtcb_type =
4451 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004453 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004454 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 }
4456}
4457
4458/**
4459 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4460 * @adapter: adapter for which request queue is examined
4461 * @req_flags: flags indicating whether to wait for needed SBAL or not
4462 * @lock_flags: lock_flags if queue_lock is taken
4463 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4464 * Locks: lock adapter->request_queue->queue_lock on success
4465 */
4466static int
4467zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4468 unsigned long *lock_flags)
4469{
4470 long ret;
4471 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4472
4473 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4474 ret = wait_event_interruptible_timeout(adapter->request_wq,
4475 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4476 ZFCP_SBAL_TIMEOUT);
4477 if (ret < 0)
4478 return ret;
4479 if (!ret)
4480 return -EIO;
4481 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4482 return -EIO;
4483
4484 return 0;
4485}
4486
4487/*
4488 * function: zfcp_fsf_req_create
4489 *
4490 * purpose: create an FSF request at the specified adapter and
4491 * setup common fields
4492 *
4493 * returns: -ENOMEM if there was insufficient memory for a request
4494 * -EIO if no qdio buffers could be allocate to the request
4495 * -EINVAL/-EPERM on bug conditions in req_dequeue
4496 * 0 in success
4497 *
4498 * note: The created request is returned by reference.
4499 *
4500 * locks: lock of concerned request queue must not be held,
4501 * but is held on completion (write, irqsave)
4502 */
4503int
4504zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4505 mempool_t *pool, unsigned long *lock_flags,
4506 struct zfcp_fsf_req **fsf_req_p)
4507{
4508 volatile struct qdio_buffer_element *sbale;
4509 struct zfcp_fsf_req *fsf_req = NULL;
4510 int ret = 0;
4511 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4512
4513 /* allocate new FSF request */
4514 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4515 if (unlikely(NULL == fsf_req)) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +01004516 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 "the outbound (send) queue.\n");
4518 ret = -ENOMEM;
4519 goto failed_fsf_req;
4520 }
4521
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004522 fsf_req->adapter = adapter;
4523 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004524 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004525 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004527 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 this request completion */
4529 init_waitqueue_head(&fsf_req->completion_wq);
4530
4531 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004532 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004534
4535 /* this is serialized (we are holding req_queue-lock of adapter) */
4536 if (adapter->req_no == 0)
4537 adapter->req_no++;
4538 fsf_req->req_id = adapter->req_no++;
4539
4540 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541
4542 /*
4543 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4544 * if it is not set (see also *_open_qdio and *_close_qdio).
4545 */
4546
4547 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4548 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4549 ret = -EIO;
4550 goto failed_sbals;
4551 }
4552
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004553 if (fsf_req->qtcb) {
4554 fsf_req->seq_no = adapter->fsf_req_seq_no;
4555 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 fsf_req->sbal_number = 1;
4558 fsf_req->sbal_first = req_queue->free_index;
4559 fsf_req->sbal_curr = req_queue->free_index;
4560 fsf_req->sbale_curr = 1;
4561
4562 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4563 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4564 }
4565
4566 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4567
4568 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004569 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4571 if (likely(fsf_req->qtcb != NULL)) {
4572 sbale[1].addr = (void *) fsf_req->qtcb;
4573 sbale[1].length = sizeof(struct fsf_qtcb);
4574 }
4575
4576 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4577 fsf_req->sbal_number, fsf_req->sbal_first);
4578
4579 goto success;
4580
4581 failed_sbals:
4582/* dequeue new FSF request previously enqueued */
4583 zfcp_fsf_req_free(fsf_req);
4584 fsf_req = NULL;
4585
4586 failed_fsf_req:
4587 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4588 success:
4589 *fsf_req_p = fsf_req;
4590 return ret;
4591}
4592
4593/*
4594 * function: zfcp_fsf_req_send
4595 *
4596 * purpose: start transfer of FSF request via QDIO
4597 *
4598 * returns: 0 - request transfer succesfully started
4599 * !0 - start of request transfer failed
4600 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004601static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602{
4603 struct zfcp_adapter *adapter;
4604 struct zfcp_qdio_queue *req_queue;
4605 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004606 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 int new_distance_from_int;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 int retval = 0;
4609
4610 adapter = fsf_req->adapter;
4611 req_queue = &adapter->request_queue,
4612
4613
4614 /* FIXME(debug): remove it later */
4615 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4616 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4617 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4618 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4619 sbale[1].length);
4620
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004621 /* put allocated FSF request into hash table */
4622 spin_lock(&adapter->req_list_lock);
4623 zfcp_reqlist_add(adapter, fsf_req);
4624 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004626 inc_seq_no = (fsf_req->qtcb != NULL);
4627
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 ZFCP_LOG_TRACE("request queue of adapter %s: "
4629 "next free SBAL is %i, %i free SBALs\n",
4630 zfcp_get_busid_by_adapter(adapter),
4631 req_queue->free_index,
4632 atomic_read(&req_queue->free_count));
4633
4634 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4635 "index_in_queue=%i, count=%i, buffers=%p\n",
4636 zfcp_get_busid_by_adapter(adapter),
4637 QDIO_FLAG_SYNC_OUTPUT,
4638 0, fsf_req->sbal_first, fsf_req->sbal_number,
4639 &req_queue->buffer[fsf_req->sbal_first]);
4640
4641 /*
4642 * adjust the number of free SBALs in request queue as well as
4643 * position of first one
4644 */
4645 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4646 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4647 req_queue->free_index += fsf_req->sbal_number; /* increase */
4648 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4649 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4650
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004651 fsf_req->issued = get_clock();
4652
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653 retval = do_QDIO(adapter->ccw_device,
4654 QDIO_FLAG_SYNC_OUTPUT,
4655 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4656
4657 if (unlikely(retval)) {
4658 /* Queues are down..... */
4659 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004660 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004661 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004662 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004663 spin_unlock(&adapter->req_list_lock);
4664 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 zfcp_qdio_zero_sbals(req_queue->buffer,
4666 fsf_req->sbal_first, fsf_req->sbal_number);
4667 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004668 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4670 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Martin Peschke1f6f7122008-04-18 12:51:55 +02004671 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 } else {
4673 req_queue->distance_from_int = new_distance_from_int;
4674 /*
4675 * increase FSF sequence counter -
4676 * this must only be done for request successfully enqueued to
4677 * QDIO this rejected requests may be cleaned up by calling
4678 * routines resulting in missing sequence counter values
4679 * otherwise,
4680 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004681
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004683 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004685
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004687 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688 }
4689 return retval;
4690}
4691
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692#undef ZFCP_LOG_AREA