blob: cc48a6462e6cf33816e7181e8ec11e194bd58b2c [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 *);
Christof Schmitt45633fd2008-06-10 18:20:55 +020039static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static 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);
Martin Peschke869b2b42007-05-09 11:01:20 +0200174 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100175 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200176 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
177
Martin Peschke869b2b42007-05-09 11:01:20 +0200178 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
179 list_del(&fsf_req->list);
180 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
181 zfcp_fsf_req_complete(fsf_req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100182 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200183}
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/*
186 * function: zfcp_fsf_req_complete
187 *
188 * purpose: Updates active counts and timers for openfcp-reqs
189 * May cleanup request after req_eval returns
190 *
191 * returns: 0 - success
192 * !0 - failure
193 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200194 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 */
196int
197zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
198{
199 int retval = 0;
200 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
203 ZFCP_LOG_DEBUG("Status read response received\n");
204 /*
205 * Note: all cleanup handling is done in the callchain of
206 * the function call-chain below.
207 */
208 zfcp_fsf_status_read_handler(fsf_req);
209 goto out;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200210 } else {
211 del_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 zfcp_fsf_protstatus_eval(fsf_req);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 /*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200216 * fsf_req may be deleted due to waking up functions, so
217 * cleanup is saved here and used later
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 */
219 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
220 cleanup = 1;
221 else
222 cleanup = 0;
223
224 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
225
226 /* cleanup request if requested by initiator */
227 if (likely(cleanup)) {
228 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
229 /*
230 * lock must not be held here since it will be
231 * grabed by the called routine, too
232 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200233 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 } else {
235 /* notify initiator waiting for the requests completion */
236 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
237 /*
238 * FIXME: Race! We must not access fsf_req here as it might have been
239 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
240 * flag. It's an improbable case. But, we have the same paranoia for
241 * the cleanup flag already.
242 * Might better be handled using complete()?
243 * (setting the flag and doing wakeup ought to be atomic
244 * with regard to checking the flag as long as waitqueue is
245 * part of the to be released structure)
246 */
247 wake_up(&fsf_req->completion_wq);
248 }
249
250 out:
251 return retval;
252}
253
254/*
255 * function: zfcp_fsf_protstatus_eval
256 *
257 * purpose: evaluates the QTCB of the finished FSF request
258 * and initiates appropriate actions
259 * (usually calling FSF command specific handlers)
260 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200261 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200263 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 *
265 * locks:
266 */
267static int
268zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
269{
270 int retval = 0;
271 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200272 struct fsf_qtcb *qtcb = fsf_req->qtcb;
273 union fsf_prot_status_qual *prot_status_qual =
274 &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200276 zfcp_hba_dbf_event_fsf_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
279 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
280 (unsigned long) fsf_req);
281 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
282 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 goto skip_protstatus;
284 }
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200287 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 break;
292
293 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 ZFCP_LOG_NORMAL("error: The adapter %s contains "
295 "microcode of version 0x%x, the device driver "
296 "only supports 0x%x. Aborting.\n",
297 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200298 prot_status_qual->version_error.fsf_version,
299 ZFCP_QTCB_VERSION);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200300 zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
302 break;
303
304 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
306 "driver (0x%x) and adapter %s (0x%x). "
307 "Restarting all operations on this adapter.\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200308 qtcb->prefix.req_seq_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200310 prot_status_qual->sequence_error.exp_req_seq_no);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200311 zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
313 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
314 break;
315
316 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 ZFCP_LOG_NORMAL("error: Packet header type used by the "
318 "device driver is incompatible with "
319 "that used on adapter %s. "
320 "Stopping all operations on this adapter.\n",
321 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200322 zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
324 break;
325
326 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
328 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
329 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 break;
331
332 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
334 "to the adapter %s is ambiguous. "
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200335 "Stopping all operations on this adapter.\n",
336 *(unsigned long long*)
337 (&qtcb->bottom.support.req_handle),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200339 zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
341 break;
342
343 case FSF_PROT_LINK_DOWN:
Martin Peschke698ec0162008-03-27 14:22:02 +0100344 zfcp_fsf_link_down_info_eval(fsf_req, 37,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200345 &prot_status_qual->link_down_info);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100346 /* FIXME: reopening adapter now? better wait for link up */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200347 zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
349 break;
350
351 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 "%s was re-plugged. "
354 "Re-starting operations on this adapter.\n",
355 zfcp_get_busid_by_adapter(adapter));
356 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200357 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
358 ZFCP_STATUS_COMMON_RUNNING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 ZFCP_SET);
360 zfcp_erp_adapter_reopen(adapter,
361 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100362 | ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200363 99, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
365 break;
366
367 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 ZFCP_LOG_NORMAL("error: The adapter %s "
369 "has entered the error state. "
370 "Restarting all operations on this "
371 "adapter.\n",
372 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200373 zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
375 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
376 break;
377
378 default:
379 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
380 "provided by the adapter %s "
381 "is not compatible with the device driver. "
382 "Stopping all operations on this adapter. "
383 "(debug info 0x%x).\n",
384 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200385 qtcb->prefix.prot_status);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200386 zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
388 }
389
390 skip_protstatus:
391 /*
392 * always call specific handlers to give them a chance to do
393 * something meaningful even in error cases
394 */
395 zfcp_fsf_fsfstatus_eval(fsf_req);
396 return retval;
397}
398
399/*
400 * function: zfcp_fsf_fsfstatus_eval
401 *
402 * purpose: evaluates FSF status of completed FSF request
403 * and acts accordingly
404 *
405 * returns:
406 */
407static int
408zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
409{
410 int retval = 0;
411
412 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
413 goto skip_fsfstatus;
414 }
415
416 /* evaluate FSF Status */
417 switch (fsf_req->qtcb->header.fsf_status) {
418 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
420 "not known by the adapter %s "
421 "Stopping all operations on this adapter. "
422 "(debug info 0x%x).\n",
423 zfcp_get_busid_by_adapter(fsf_req->adapter),
424 fsf_req->qtcb->header.fsf_command);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200425 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
427 break;
428
429 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
431 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 break;
433
434 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
436 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
439 skip_fsfstatus:
440 /*
441 * always call specific handlers to give them a chance to do
442 * something meaningful even in error cases
443 */
444 zfcp_fsf_req_dispatch(fsf_req);
445
446 return retval;
447}
448
449/*
450 * function: zfcp_fsf_fsfstatus_qual_eval
451 *
452 * purpose: evaluates FSF status-qualifier of completed FSF request
453 * and acts accordingly
454 *
455 * returns:
456 */
457static int
458zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
459{
460 int retval = 0;
461
462 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
463 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 break;
465 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
468 break;
469 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
473 break;
474 case FSF_SQ_NO_RECOM:
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100475 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 "problem on the adapter %s "
477 "Stopping all operations on this adapter. ",
478 zfcp_get_busid_by_adapter(fsf_req->adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200479 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
481 break;
482 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
484 "(adapter %s)\n",
485 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
487 break;
488 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
489 case FSF_SQ_NO_RETRY_POSSIBLE:
490 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
491 /* dealt with in the respective functions */
492 break;
493 default:
494 ZFCP_LOG_NORMAL("bug: Additional status info could "
495 "not be interpreted properly.\n");
496 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
497 (char *) &fsf_req->qtcb->header.fsf_status_qual,
498 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
500 break;
501 }
502
503 return retval;
504}
505
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200506/**
507 * zfcp_fsf_link_down_info_eval - evaluate link down information block
508 */
509static void
Martin Peschke698ec0162008-03-27 14:22:02 +0100510zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200511 struct fsf_link_down_info *link_down)
512{
Martin Peschke698ec0162008-03-27 14:22:02 +0100513 struct zfcp_adapter *adapter = fsf_req->adapter;
514
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100515 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
516 &adapter->status))
517 return;
518
519 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
520
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100521 if (link_down == NULL)
522 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100523
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200524 switch (link_down->error_code) {
525 case FSF_PSQ_LINK_NO_LIGHT:
526 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
527 "(no light detected)\n",
528 zfcp_get_busid_by_adapter(adapter));
529 break;
530 case FSF_PSQ_LINK_WRAP_PLUG:
531 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
532 "(wrap plug detected)\n",
533 zfcp_get_busid_by_adapter(adapter));
534 break;
535 case FSF_PSQ_LINK_NO_FCP:
536 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
537 "(adjacent node on link does not support FCP)\n",
538 zfcp_get_busid_by_adapter(adapter));
539 break;
540 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
541 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
542 "(firmware update in progress)\n",
543 zfcp_get_busid_by_adapter(adapter));
544 break;
545 case FSF_PSQ_LINK_INVALID_WWPN:
546 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
547 "(duplicate or invalid WWPN detected)\n",
548 zfcp_get_busid_by_adapter(adapter));
549 break;
550 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
551 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
552 "(no support for NPIV by Fabric)\n",
553 zfcp_get_busid_by_adapter(adapter));
554 break;
555 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
556 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
557 "(out of resource in FCP daughtercard)\n",
558 zfcp_get_busid_by_adapter(adapter));
559 break;
560 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
561 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
562 "(out of resource in Fabric)\n",
563 zfcp_get_busid_by_adapter(adapter));
564 break;
565 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
566 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
567 "(unable to Fabric login)\n",
568 zfcp_get_busid_by_adapter(adapter));
569 break;
570 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
571 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
572 zfcp_get_busid_by_adapter(adapter));
573 break;
574 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
575 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
576 zfcp_get_busid_by_adapter(adapter));
577 break;
578 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
579 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
580 zfcp_get_busid_by_adapter(adapter));
581 break;
582 default:
583 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
584 "(warning: unknown reason code %d)\n",
585 zfcp_get_busid_by_adapter(adapter),
586 link_down->error_code);
587 }
588
589 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
590 ZFCP_LOG_DEBUG("Debug information to link down: "
591 "primary_status=0x%02x "
592 "ioerr_code=0x%02x "
593 "action_code=0x%02x "
594 "reason_code=0x%02x "
595 "explanation_code=0x%02x "
596 "vendor_specific_code=0x%02x\n",
597 link_down->primary_status,
598 link_down->ioerr_code,
599 link_down->action_code,
600 link_down->reason_code,
601 link_down->explanation_code,
602 link_down->vendor_specific_code);
603
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100604 out:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200605 zfcp_erp_adapter_failed(adapter, id, fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200606}
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608/*
609 * function: zfcp_fsf_req_dispatch
610 *
611 * purpose: calls the appropriate command specific handler
612 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200613 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 */
615static int
616zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
617{
618 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
619 struct zfcp_adapter *adapter = fsf_req->adapter;
620 int retval = 0;
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 switch (fsf_req->fsf_command) {
624
625 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 zfcp_fsf_send_fcp_command_handler(fsf_req);
627 break;
628
629 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 zfcp_fsf_abort_fcp_command_handler(fsf_req);
631 break;
632
633 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 zfcp_fsf_send_ct_handler(fsf_req);
635 break;
636
637 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 zfcp_fsf_open_port_handler(fsf_req);
639 break;
640
641 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 zfcp_fsf_open_unit_handler(fsf_req);
643 break;
644
645 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 zfcp_fsf_close_unit_handler(fsf_req);
647 break;
648
649 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 zfcp_fsf_close_port_handler(fsf_req);
651 break;
652
653 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 zfcp_fsf_close_physical_port_handler(fsf_req);
655 break;
656
657 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 zfcp_fsf_exchange_config_data_handler(fsf_req);
659 break;
660
661 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 zfcp_fsf_exchange_port_data_handler(fsf_req);
663 break;
664
665 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 zfcp_fsf_send_els_handler(fsf_req);
667 break;
668
669 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 zfcp_fsf_control_file_handler(fsf_req);
671 break;
672
673 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 zfcp_fsf_control_file_handler(fsf_req);
675 break;
676
677 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
679 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
680 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200681 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
683 ZFCP_LOG_NORMAL
684 ("bug: Command issued by the device driver differs "
685 "from the command returned by the adapter %s "
686 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200687 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 fsf_req->fsf_command,
689 fsf_req->qtcb->header.fsf_command);
690 }
691
692 if (!erp_action)
693 return retval;
694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 zfcp_erp_async_handler(erp_action, 0);
696
697 return retval;
698}
699
700/*
701 * function: zfcp_fsf_status_read
702 *
703 * purpose: initiates a Status Read command at the specified adapter
704 *
705 * returns:
706 */
707int
708zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
709{
710 struct zfcp_fsf_req *fsf_req;
711 struct fsf_status_read_buffer *status_buffer;
712 unsigned long lock_flags;
713 volatile struct qdio_buffer_element *sbale;
Heiko Carstensb2141782008-05-19 12:17:39 +0200714 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 /* setup new FSF request */
717 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
718 req_flags | ZFCP_REQ_NO_QTCB,
719 adapter->pool.fsf_req_status_read,
720 &lock_flags, &fsf_req);
721 if (retval < 0) {
722 ZFCP_LOG_INFO("error: Could not create unsolicited status "
723 "buffer for adapter %s.\n",
724 zfcp_get_busid_by_adapter(adapter));
725 goto failed_req_create;
726 }
727
Swen Schillig00bab912008-06-10 18:20:57 +0200728 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
730 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
731 fsf_req->sbale_curr = 2;
732
Heiko Carstensb2141782008-05-19 12:17:39 +0200733 retval = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 status_buffer =
735 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
Heiko Carstensb2141782008-05-19 12:17:39 +0200736 if (!status_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 goto failed_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200739 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 /* insert pointer to respective buffer */
742 sbale = zfcp_qdio_sbale_curr(fsf_req);
743 sbale->addr = (void *) status_buffer;
744 sbale->length = sizeof(struct fsf_status_read_buffer);
745
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200746 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 if (retval) {
748 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
749 "environment.\n");
750 goto failed_req_send;
751 }
752
753 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
754 zfcp_get_busid_by_adapter(adapter));
755 goto out;
756
757 failed_req_send:
758 mempool_free(status_buffer, adapter->pool.data_status_read);
759
760 failed_buf:
761 zfcp_fsf_req_free(fsf_req);
762 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200763 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 out:
Swen Schillig00bab912008-06-10 18:20:57 +0200765 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 return retval;
767}
768
769static int
770zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
771{
772 struct fsf_status_read_buffer *status_buffer;
773 struct zfcp_adapter *adapter;
774 struct zfcp_port *port;
775 unsigned long flags;
776
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200777 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 adapter = fsf_req->adapter;
779
780 read_lock_irqsave(&zfcp_data.config_lock, flags);
781 list_for_each_entry(port, &adapter->port_list_head, list)
782 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
783 break;
784 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
785
786 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +0100787 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200788 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 "adapter %s. Ignored.\n",
790 status_buffer->d_id & ZFCP_DID_MASK,
791 zfcp_get_busid_by_adapter(adapter));
792 goto out;
793 }
794
795 switch (status_buffer->status_subtype) {
796
797 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200798 zfcp_erp_port_reopen(port, 0, 101, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 break;
800
801 case FSF_STATUS_READ_SUB_ERROR_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200802 zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 break;
804
805 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
807 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200808 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 "Ignored. (debug info 0x%x)\n",
810 status_buffer->d_id,
811 zfcp_get_busid_by_adapter(adapter),
812 status_buffer->status_subtype);
813 }
814 out:
815 return 0;
816}
817
818/*
819 * function: zfcp_fsf_status_read_handler
820 *
821 * purpose: is called for finished Open Port command
822 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200823 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 */
825static int
826zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
827{
828 int retval = 0;
829 struct zfcp_adapter *adapter = fsf_req->adapter;
830 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200831 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200832 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200835 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200837 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 goto out;
839 }
840
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200841 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 switch (status_buffer->status_type) {
844
845 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 zfcp_fsf_status_read_port_closed(fsf_req);
847 break;
848
849 case FSF_STATUS_READ_INCOMING_ELS:
Christof Schmitt24073b42008-06-10 18:20:54 +0200850 zfcp_fc_incoming_els(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 break;
852
853 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
855 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 break;
857
858 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200859 fsf_bit_error = (struct fsf_bit_error_payload *)
860 status_buffer->payload;
861 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
862 "received (adapter %s, "
863 "link failures = %i, loss of sync errors = %i, "
864 "loss of signal errors = %i, "
865 "primitive sequence errors = %i, "
866 "invalid transmission word errors = %i, "
867 "CRC errors = %i)\n",
868 zfcp_get_busid_by_adapter(adapter),
869 fsf_bit_error->link_failure_error_count,
870 fsf_bit_error->loss_of_sync_error_count,
871 fsf_bit_error->loss_of_signal_error_count,
872 fsf_bit_error->primitive_sequence_error_count,
873 fsf_bit_error->invalid_transmission_word_error_count,
874 fsf_bit_error->crc_error_count);
875 ZFCP_LOG_INFO("Additional bit error threshold data "
876 "(adapter %s, "
877 "primitive sequence event time-outs = %i, "
878 "elastic buffer overrun errors = %i, "
879 "advertised receive buffer-to-buffer credit = %i, "
880 "current receice buffer-to-buffer credit = %i, "
881 "advertised transmit buffer-to-buffer credit = %i, "
882 "current transmit buffer-to-buffer credit = %i)\n",
883 zfcp_get_busid_by_adapter(adapter),
884 fsf_bit_error->primitive_sequence_event_timeout_count,
885 fsf_bit_error->elastic_buffer_overrun_error_count,
886 fsf_bit_error->advertised_receive_b2b_credit,
887 fsf_bit_error->current_receive_b2b_credit,
888 fsf_bit_error->advertised_transmit_b2b_credit,
889 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 break;
891
892 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200893 switch (status_buffer->status_subtype) {
894 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
895 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
896 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100897 zfcp_fsf_link_down_info_eval(fsf_req, 38,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100898 (struct fsf_link_down_info *)
899 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200900 break;
901 case FSF_STATUS_READ_SUB_FDISC_FAILED:
902 ZFCP_LOG_INFO("Local link to adapter %s is down "
903 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100904 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100905 zfcp_fsf_link_down_info_eval(fsf_req, 39,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100906 (struct fsf_link_down_info *)
907 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200908 break;
909 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
910 ZFCP_LOG_INFO("Local link to adapter %s is down "
911 "due to firmware update on adapter\n",
912 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100913 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200914 break;
915 default:
916 ZFCP_LOG_INFO("Local link to adapter %s is down "
917 "due to unknown reason\n",
918 zfcp_get_busid_by_adapter(adapter));
Martin Peschke698ec0162008-03-27 14:22:02 +0100919 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200920 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 break;
922
923 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200924 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100925 "Restarting operations on this adapter\n",
926 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200928 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 ZFCP_STATUS_COMMON_RUNNING,
930 ZFCP_SET);
931 zfcp_erp_adapter_reopen(adapter,
932 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100933 | ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200934 102, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 break;
936
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100937 case FSF_STATUS_READ_NOTIFICATION_LOST:
938 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
939 "adapter %s%s%s%s%s%s%s%s%s\n",
940 zfcp_get_busid_by_adapter(adapter),
941 (status_buffer->status_subtype &
942 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
943 ", incoming ELS" : "",
944 (status_buffer->status_subtype &
945 FSF_STATUS_READ_SUB_SENSE_DATA) ?
946 ", sense data" : "",
947 (status_buffer->status_subtype &
948 FSF_STATUS_READ_SUB_LINK_STATUS) ?
949 ", link status change" : "",
950 (status_buffer->status_subtype &
951 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
952 ", port close" : "",
953 (status_buffer->status_subtype &
954 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
955 ", bit error exception" : "",
956 (status_buffer->status_subtype &
957 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
958 ", ACT update" : "",
959 (status_buffer->status_subtype &
960 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
961 ", ACT hardening" : "",
962 (status_buffer->status_subtype &
963 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
964 ", adapter feature change" : "");
965
966 if (status_buffer->status_subtype &
967 FSF_STATUS_READ_SUB_ACT_UPDATED)
Martin Peschke1f6f7122008-04-18 12:51:55 +0200968 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100969 break;
970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200972 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200974 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 break;
976
977 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 switch (status_buffer->status_subtype) {
979 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200980 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 zfcp_get_busid_by_adapter(adapter));
982 break;
983 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200984 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 "to the secondary SE\n",
986 zfcp_get_busid_by_adapter(adapter));
987 break;
988 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200989 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 zfcp_get_busid_by_adapter(adapter));
991 }
992 break;
993
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200994 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200995 ZFCP_LOG_INFO("List of supported features on adapter %s has "
996 "been changed from 0x%08X to 0x%08X\n",
997 zfcp_get_busid_by_adapter(adapter),
998 *(u32*) (status_buffer->payload + 4),
999 *(u32*) (status_buffer->payload));
1000 adapter->adapter_features = *(u32*) status_buffer->payload;
1001 break;
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001004 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 "type was received (debug info 0x%x)\n",
1006 status_buffer->status_type);
1007 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1008 status_buffer);
1009 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1010 (char *) status_buffer,
1011 sizeof (struct fsf_status_read_buffer));
1012 break;
1013 }
1014 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001015 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 /*
1017 * recycle buffer and start new request repeat until outbound
1018 * queue is empty or adapter shutdown is requested
1019 */
1020 /*
1021 * FIXME(qdio):
1022 * we may wait in the req_create for 5s during shutdown, so
1023 * qdio_cleanup will have to wait at least that long before returning
1024 * with failure to allow us a proper cleanup under all circumstances
1025 */
1026 /*
1027 * FIXME:
1028 * allocation failure possible? (Is this code needed?)
1029 */
Swen Schilligd26ab062008-05-19 12:17:37 +02001030
1031 atomic_inc(&adapter->stat_miss);
1032 schedule_work(&adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 out:
1034 return retval;
1035}
1036
1037/*
1038 * function: zfcp_fsf_abort_fcp_command
1039 *
1040 * purpose: tells FSF to abort a running SCSI command
1041 *
1042 * returns: address of initiated FSF request
1043 * NULL - request could not be initiated
1044 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001045 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 * FIXME(design) shouldn't this be modified to return an int
1047 * also...don't know how though
1048 */
1049struct zfcp_fsf_req *
1050zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1051 struct zfcp_adapter *adapter,
1052 struct zfcp_unit *unit, int req_flags)
1053{
1054 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001056 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 int retval = 0;
1058
1059 /* setup new FSF request */
1060 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1061 req_flags, adapter->pool.fsf_req_abort,
1062 &lock_flags, &fsf_req);
1063 if (retval < 0) {
1064 ZFCP_LOG_INFO("error: Failed to create an abort command "
1065 "request for lun 0x%016Lx on port 0x%016Lx "
1066 "on adapter %s.\n",
1067 unit->fcp_lun,
1068 unit->port->wwpn,
1069 zfcp_get_busid_by_adapter(adapter));
1070 goto out;
1071 }
1072
Christof Schmitt951f7462007-12-20 12:30:24 +01001073 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1074 &unit->status)))
1075 goto unit_blocked;
1076
Swen Schillig00bab912008-06-10 18:20:57 +02001077 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1079 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1080
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001081 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
1083 /* set handles of unit and its parent port in QTCB */
1084 fsf_req->qtcb->header.lun_handle = unit->handle;
1085 fsf_req->qtcb->header.port_handle = unit->port->handle;
1086
1087 /* set handle of request which should be aborted */
1088 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1089
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001090 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1091 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001092 if (!retval)
1093 goto out;
1094
1095 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 zfcp_fsf_req_free(fsf_req);
1097 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 out:
Swen Schillig00bab912008-06-10 18:20:57 +02001100 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 return fsf_req;
1102}
1103
1104/*
1105 * function: zfcp_fsf_abort_fcp_command_handler
1106 *
1107 * purpose: is called for finished Abort FCP Command request
1108 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001109 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 */
1111static int
1112zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1113{
1114 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001115 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001116 union fsf_status_qual *fsf_stat_qual =
1117 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1120 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1121 goto skip_fsfstatus;
1122 }
1123
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001124 unit = (struct zfcp_unit *) new_fsf_req->data;
1125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 /* evaluate FSF status in QTCB */
1127 switch (new_fsf_req->qtcb->header.fsf_status) {
1128
1129 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001130 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 /*
1132 * In this case a command that was sent prior to a port
1133 * reopen was aborted (handles are different). This is
1134 * fine.
1135 */
1136 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1138 "port 0x%016Lx on adapter %s invalid. "
1139 "This may happen occasionally.\n",
1140 unit->port->handle,
1141 unit->port->wwpn,
1142 zfcp_get_busid_by_unit(unit));
1143 ZFCP_LOG_INFO("status qualifier:\n");
1144 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1145 (char *) &new_fsf_req->qtcb->header.
1146 fsf_status_qual,
1147 sizeof (union fsf_status_qual));
1148 /* Let's hope this sorts out the mess */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001149 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001150 new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1152 }
1153 break;
1154
1155 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001156 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 /*
1158 * In this case a command that was sent prior to a unit
1159 * reopen was aborted (handles are different).
1160 * This is fine.
1161 */
1162 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 ZFCP_LOG_INFO
1164 ("Warning: Temporary LUN identifier 0x%x of LUN "
1165 "0x%016Lx on port 0x%016Lx on adapter %s is "
1166 "invalid. This may happen in rare cases. "
1167 "Trying to re-establish link.\n",
1168 unit->handle,
1169 unit->fcp_lun,
1170 unit->port->wwpn,
1171 zfcp_get_busid_by_unit(unit));
1172 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1173 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1174 (char *) &new_fsf_req->qtcb->header.
1175 fsf_status_qual,
1176 sizeof (union fsf_status_qual));
1177 /* Let's hope this sorts out the mess */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001178 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1180 }
1181 break;
1182
1183 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1186 break;
1187
1188 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1190 "be reopened\n", unit->port->wwpn,
1191 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001192 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1194 | ZFCP_STATUS_FSFREQ_RETRY;
1195 break;
1196
1197 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 ZFCP_LOG_INFO(
1199 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1200 "to be reopened\n",
1201 unit->fcp_lun, unit->port->wwpn,
1202 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001203 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1205 | ZFCP_STATUS_FSFREQ_RETRY;
1206 break;
1207
1208 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1210 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001211 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1213 break;
1214 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 /* SCSI stack will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1217 break;
1218 default:
1219 ZFCP_LOG_NORMAL
1220 ("bug: Wrong status qualifier 0x%x arrived.\n",
1221 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 break;
1223 }
1224 break;
1225
1226 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 retval = 0;
1228 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1229 break;
1230
1231 default:
1232 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1233 "(debug info 0x%x)\n",
1234 new_fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 break;
1236 }
1237 skip_fsfstatus:
1238 return retval;
1239}
1240
1241/**
1242 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1243 * one SBALE
1244 * Two scatter-gather lists are passed, one for the reqeust and one for the
1245 * response.
1246 */
1247static inline int
1248zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1249 struct scatterlist *resp, int resp_count)
1250{
1251 return ((req_count == 1) &&
1252 (resp_count == 1) &&
1253 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1254 PAGE_MASK) ==
1255 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1256 req[0].length - 1) & PAGE_MASK)) &&
1257 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1258 PAGE_MASK) ==
1259 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1260 resp[0].length - 1) & PAGE_MASK)));
1261}
1262
1263/**
1264 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1265 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1266 * the request
1267 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1268 * a struct zfcp_fsf_req
1269 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1270 * is sent within error recovery
1271 */
1272int
1273zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1274 struct zfcp_erp_action *erp_action)
1275{
1276 volatile struct qdio_buffer_element *sbale;
1277 struct zfcp_port *port;
1278 struct zfcp_adapter *adapter;
1279 struct zfcp_fsf_req *fsf_req;
1280 unsigned long lock_flags;
1281 int bytes;
1282 int ret = 0;
1283
1284 port = ct->port;
1285 adapter = port->adapter;
1286
1287 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1288 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1289 pool, &lock_flags, &fsf_req);
1290 if (ret < 0) {
1291 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1292 "adapter: %s\n",
1293 zfcp_get_busid_by_adapter(adapter));
1294 goto failed_req;
1295 }
1296
Swen Schillig00bab912008-06-10 18:20:57 +02001297 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1299 ct->resp, ct->resp_count)){
1300 /* both request buffer and response buffer
1301 fit into one sbale each */
1302 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1303 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1304 sbale[2].length = ct->req[0].length;
1305 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1306 sbale[3].length = ct->resp[0].length;
1307 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001308 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1310 /* try to use chained SBALs */
1311 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1312 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001313 ct->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 ZFCP_MAX_SBALS_PER_CT_REQ);
1315 if (bytes <= 0) {
1316 ZFCP_LOG_INFO("error: creation of CT request failed "
1317 "on adapter %s\n",
1318 zfcp_get_busid_by_adapter(adapter));
1319 if (bytes == 0)
1320 ret = -ENOMEM;
1321 else
1322 ret = bytes;
1323
1324 goto failed_send;
1325 }
1326 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1327 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1328 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1329 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001330 ct->resp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 ZFCP_MAX_SBALS_PER_CT_REQ);
1332 if (bytes <= 0) {
1333 ZFCP_LOG_INFO("error: creation of CT request failed "
1334 "on adapter %s\n",
1335 zfcp_get_busid_by_adapter(adapter));
1336 if (bytes == 0)
1337 ret = -ENOMEM;
1338 else
1339 ret = bytes;
1340
1341 goto failed_send;
1342 }
1343 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1344 } else {
1345 /* reject send generic request */
1346 ZFCP_LOG_INFO(
1347 "error: microcode does not support chained SBALs,"
1348 "CT request too big (adapter %s)\n",
1349 zfcp_get_busid_by_adapter(adapter));
1350 ret = -EOPNOTSUPP;
1351 goto failed_send;
1352 }
1353
1354 /* settings in QTCB */
1355 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001356 fsf_req->qtcb->bottom.support.service_class =
1357 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001359 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001361 zfcp_san_dbf_event_ct_request(fsf_req);
1362
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001363 if (erp_action) {
1364 erp_action->fsf_req = fsf_req;
1365 fsf_req->erp_action = erp_action;
1366 zfcp_erp_start_timer(fsf_req);
1367 } else
1368 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1369
1370 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 if (ret) {
1372 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1373 "(adapter %s, port 0x%016Lx)\n",
1374 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1375 goto failed_send;
1376 }
1377
1378 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1379 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1380 goto out;
1381
1382 failed_send:
1383 zfcp_fsf_req_free(fsf_req);
1384 if (erp_action != NULL) {
1385 erp_action->fsf_req = NULL;
1386 }
1387 failed_req:
1388 out:
Swen Schillig00bab912008-06-10 18:20:57 +02001389 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 return ret;
1391}
1392
1393/**
1394 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1395 * @fsf_req: pointer to struct zfcp_fsf_req
1396 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001397 * Data specific for the Generic Service request is passed using
1398 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1399 * Usually a specific handler for the CT request is called which is
1400 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 */
1402static int
1403zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1404{
1405 struct zfcp_port *port;
1406 struct zfcp_adapter *adapter;
1407 struct zfcp_send_ct *send_ct;
1408 struct fsf_qtcb_header *header;
1409 struct fsf_qtcb_bottom_support *bottom;
1410 int retval = -EINVAL;
1411 u16 subtable, rule, counter;
1412
1413 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001414 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 port = send_ct->port;
1416 header = &fsf_req->qtcb->header;
1417 bottom = &fsf_req->qtcb->bottom.support;
1418
1419 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1420 goto skip_fsfstatus;
1421
1422 /* evaluate FSF status in QTCB */
1423 switch (header->fsf_status) {
1424
1425 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001426 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 retval = 0;
1428 break;
1429
1430 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001431 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1432 "class %d.\n",
1433 zfcp_get_busid_by_port(port),
1434 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001436 zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1438 break;
1439
1440 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 switch (header->fsf_status_qual.word[0]){
1442 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 /* reopening link to port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 zfcp_test_link(port);
1445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1446 break;
1447 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1450 break;
1451 default:
1452 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1453 "arrived.\n",
1454 header->fsf_status_qual.word[0]);
1455 break;
1456 }
1457 break;
1458
1459 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001461 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 zfcp_get_busid_by_port(port), port->d_id);
1463 for (counter = 0; counter < 2; counter++) {
1464 subtable = header->fsf_status_qual.halfword[counter * 2];
1465 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1466 switch (subtable) {
1467 case FSF_SQ_CFDC_SUBTABLE_OS:
1468 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1469 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1470 case FSF_SQ_CFDC_SUBTABLE_LUN:
1471 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1472 zfcp_act_subtable_type[subtable], rule);
1473 break;
1474 }
1475 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02001476 zfcp_erp_port_access_denied(port, 55, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1478 break;
1479
1480 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001482 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 zfcp_get_busid_by_port(port), port->d_id);
1484 ZFCP_LOG_INFO("status qualifier:\n");
1485 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1486 (char *) &header->fsf_status_qual,
1487 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1489 break;
1490
1491 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1493 "0x%016Lx on adapter %s invalid. This may "
1494 "happen occasionally.\n", port->handle,
1495 port->wwpn, zfcp_get_busid_by_port(port));
1496 ZFCP_LOG_INFO("status qualifier:\n");
1497 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1498 (char *) &header->fsf_status_qual,
1499 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001500 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1502 break;
1503
1504 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001506 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 zfcp_get_busid_by_port(port), port->d_id);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001508 zfcp_erp_port_boxed(port, 49, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1510 | ZFCP_STATUS_FSFREQ_RETRY;
1511 break;
1512
1513 /* following states should never occure, all cases avoided
1514 in zfcp_fsf_send_ct - but who knows ... */
1515 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1517 "req_buf_length=%d, resp_buf_length=%d)\n",
1518 zfcp_get_busid_by_adapter(adapter),
1519 bottom->req_buf_length, bottom->resp_buf_length);
1520 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1521 break;
1522 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1524 "req_buf_length=%d)\n",
1525 zfcp_get_busid_by_adapter(adapter),
1526 bottom->req_buf_length);
1527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1528 break;
1529 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1531 "resp_buf_length=%d)\n",
1532 zfcp_get_busid_by_adapter(adapter),
1533 bottom->resp_buf_length);
1534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1535 break;
1536 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1538 "resp_buf_length=%d)\n",
1539 zfcp_get_busid_by_adapter(adapter),
1540 bottom->req_buf_length, bottom->resp_buf_length);
1541 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1542 break;
1543
1544 default:
1545 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1546 "(debug info 0x%x)\n", header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 break;
1548 }
1549
1550skip_fsfstatus:
1551 send_ct->status = retval;
1552
1553 if (send_ct->handler != NULL)
1554 send_ct->handler(send_ct->handler_data);
1555
1556 return retval;
1557}
1558
1559/**
1560 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1561 * @els: pointer to struct zfcp_send_els which contains all needed data for
1562 * the command.
1563 */
1564int
1565zfcp_fsf_send_els(struct zfcp_send_els *els)
1566{
1567 volatile struct qdio_buffer_element *sbale;
1568 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001569 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 struct zfcp_adapter *adapter;
1571 unsigned long lock_flags;
1572 int bytes;
1573 int ret = 0;
1574
1575 d_id = els->d_id;
1576 adapter = els->adapter;
1577
1578 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1579 ZFCP_REQ_AUTO_CLEANUP,
1580 NULL, &lock_flags, &fsf_req);
1581 if (ret < 0) {
1582 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001583 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 zfcp_get_busid_by_adapter(adapter), d_id);
1585 goto failed_req;
1586 }
1587
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001588 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1589 &els->port->status))) {
1590 ret = -EBUSY;
1591 goto port_blocked;
1592 }
1593
Swen Schillig00bab912008-06-10 18:20:57 +02001594 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 if (zfcp_use_one_sbal(els->req, els->req_count,
1596 els->resp, els->resp_count)){
1597 /* both request buffer and response buffer
1598 fit into one sbale each */
1599 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1600 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1601 sbale[2].length = els->req[0].length;
1602 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1603 sbale[3].length = els->resp[0].length;
1604 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001605 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1607 /* try to use chained SBALs */
1608 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1609 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001610 els->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 ZFCP_MAX_SBALS_PER_ELS_REQ);
1612 if (bytes <= 0) {
1613 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001614 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 zfcp_get_busid_by_adapter(adapter), d_id);
1616 if (bytes == 0) {
1617 ret = -ENOMEM;
1618 } else {
1619 ret = bytes;
1620 }
1621 goto failed_send;
1622 }
1623 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1624 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1625 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1626 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001627 els->resp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 ZFCP_MAX_SBALS_PER_ELS_REQ);
1629 if (bytes <= 0) {
1630 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001631 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 zfcp_get_busid_by_adapter(adapter), d_id);
1633 if (bytes == 0) {
1634 ret = -ENOMEM;
1635 } else {
1636 ret = bytes;
1637 }
1638 goto failed_send;
1639 }
1640 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1641 } else {
1642 /* reject request */
1643 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1644 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001645 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 zfcp_get_busid_by_adapter(adapter), d_id);
1647 ret = -EOPNOTSUPP;
1648 goto failed_send;
1649 }
1650
1651 /* settings in QTCB */
1652 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001653 fsf_req->qtcb->bottom.support.service_class =
1654 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001656 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
Swen Schillig00bab912008-06-10 18:20:57 +02001658 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001660 zfcp_san_dbf_event_els_request(fsf_req);
1661
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001662 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1663 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 if (ret) {
1665 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001666 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 zfcp_get_busid_by_adapter(adapter), d_id);
1668 goto failed_send;
1669 }
1670
1671 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001672 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 goto out;
1674
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001675 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 failed_send:
1677 zfcp_fsf_req_free(fsf_req);
1678
1679 failed_req:
1680 out:
Swen Schillig00bab912008-06-10 18:20:57 +02001681 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
1683 return ret;
1684}
1685
1686/**
1687 * zfcp_fsf_send_els_handler - handler for ELS commands
1688 * @fsf_req: pointer to struct zfcp_fsf_req
1689 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001690 * Data specific for the ELS command is passed using
1691 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1692 * Usually a specific handler for the ELS command is called which is
1693 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 */
1695static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1696{
1697 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001699 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 struct fsf_qtcb_header *header;
1701 struct fsf_qtcb_bottom_support *bottom;
1702 struct zfcp_send_els *send_els;
1703 int retval = -EINVAL;
1704 u16 subtable, rule, counter;
1705
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001706 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001708 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 d_id = send_els->d_id;
1710 header = &fsf_req->qtcb->header;
1711 bottom = &fsf_req->qtcb->bottom.support;
1712
1713 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1714 goto skip_fsfstatus;
1715
1716 switch (header->fsf_status) {
1717
1718 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001719 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 retval = 0;
1721 break;
1722
1723 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001724 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1725 "class %d.\n",
1726 zfcp_get_busid_by_adapter(adapter),
1727 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001729 zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1731 break;
1732
1733 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 switch (header->fsf_status_qual.word[0]){
1735 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001736 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1737 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1739 break;
1740 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 break;
1743 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1745 break;
1746 default:
1747 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1748 header->fsf_status_qual.word[0]);
1749 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1750 (char*)header->fsf_status_qual.word, 16);
1751 }
1752 break;
1753
1754 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1756 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001757 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 zfcp_get_busid_by_adapter(adapter), d_id);
1759
1760 break;
1761
1762 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 ZFCP_LOG_INFO(
1764 "ELS request size and ELS response size must be either "
1765 "both 0, or both greater than 0 "
1766 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1767 zfcp_get_busid_by_adapter(adapter),
1768 bottom->req_buf_length,
1769 bottom->resp_buf_length);
1770 break;
1771
1772 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 ZFCP_LOG_INFO(
1774 "Length of the ELS request buffer, "
1775 "specified in QTCB bottom, "
1776 "exceeds the size of the buffers "
1777 "that have been allocated for ELS request data "
1778 "(adapter: %s, req_buf_length=%d)\n",
1779 zfcp_get_busid_by_adapter(adapter),
1780 bottom->req_buf_length);
1781 break;
1782
1783 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 ZFCP_LOG_INFO(
1785 "Length of the ELS response buffer, "
1786 "specified in QTCB bottom, "
1787 "exceeds the size of the buffers "
1788 "that have been allocated for ELS response data "
1789 "(adapter: %s, resp_buf_length=%d)\n",
1790 zfcp_get_busid_by_adapter(adapter),
1791 bottom->resp_buf_length);
1792 break;
1793
1794 case FSF_SBAL_MISMATCH:
1795 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1797 "resp_buf_length=%d)\n",
1798 zfcp_get_busid_by_adapter(adapter),
1799 bottom->req_buf_length, bottom->resp_buf_length);
1800 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1801 break;
1802
1803 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001805 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 zfcp_get_busid_by_adapter(adapter), d_id);
1807 for (counter = 0; counter < 2; counter++) {
1808 subtable = header->fsf_status_qual.halfword[counter * 2];
1809 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1810 switch (subtable) {
1811 case FSF_SQ_CFDC_SUBTABLE_OS:
1812 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1813 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1814 case FSF_SQ_CFDC_SUBTABLE_LUN:
1815 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1816 zfcp_act_subtable_type[subtable], rule);
1817 break;
1818 }
1819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 if (port != NULL)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001821 zfcp_erp_port_access_denied(port, 56, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1823 break;
1824
1825 default:
1826 ZFCP_LOG_NORMAL(
1827 "bug: An unknown FSF Status was presented "
1828 "(adapter: %s, fsf_status=0x%08x)\n",
1829 zfcp_get_busid_by_adapter(adapter),
1830 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1832 break;
1833 }
1834
1835skip_fsfstatus:
1836 send_els->status = retval;
1837
Heiko Carstensaa551da2007-07-18 10:55:10 +02001838 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 send_els->handler(send_els->handler_data);
1840
1841 return retval;
1842}
1843
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844int
1845zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1846{
1847 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001848 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001849 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001851 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001854 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1856 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001857 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001858 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001859 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1861 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001862 zfcp_get_busid_by_adapter(adapter));
Swen Schillig00bab912008-06-10 18:20:57 +02001863 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001864 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
1866
Swen Schillig00bab912008-06-10 18:20:57 +02001867 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001868 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1869 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001871 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001872 FSF_FEATURE_CFDC |
1873 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001874 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001875 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001876 fsf_req->erp_action = erp_action;
1877 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001879 zfcp_erp_start_timer(fsf_req);
1880 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02001881 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001883 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1884 "data command on the adapter %s\n",
1885 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001886 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001888 }
1889 else
1890 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1891 "(adapter %s)\n",
1892 zfcp_get_busid_by_adapter(adapter));
1893
1894 return retval;
1895}
1896
1897int
1898zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1899 struct fsf_qtcb_bottom_config *data)
1900{
1901 volatile struct qdio_buffer_element *sbale;
1902 struct zfcp_fsf_req *fsf_req;
1903 unsigned long lock_flags;
1904 int retval;
1905
1906 /* setup new FSF request */
1907 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Swen Schilligaee6ef12008-04-24 19:35:52 +02001908 ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
1909 &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001910 if (retval) {
1911 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1912 "data request for adapter %s.\n",
1913 zfcp_get_busid_by_adapter(adapter));
Swen Schillig00bab912008-06-10 18:20:57 +02001914 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001915 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 }
1917
Swen Schillig00bab912008-06-10 18:20:57 +02001918 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001919 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1920 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Swen Schillig52ef11a2007-08-28 09:31:09 +02001922 fsf_req->qtcb->bottom.config.feature_selection =
1923 FSF_FEATURE_CFDC |
1924 FSF_FEATURE_LUN_SHARING |
1925 FSF_FEATURE_NOTIFICATION_LOST |
1926 FSF_FEATURE_UPDATE_ALERT;
1927
1928 if (data)
1929 fsf_req->data = (unsigned long) data;
1930
1931 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1932 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02001933 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001934 if (retval)
1935 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1936 "data command on the adapter %s\n",
1937 zfcp_get_busid_by_adapter(adapter));
1938 else
1939 wait_event(fsf_req->completion_wq,
1940 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1941
1942 zfcp_fsf_req_free(fsf_req);
1943
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 return retval;
1945}
1946
1947/**
1948 * zfcp_fsf_exchange_config_evaluate
1949 * @fsf_req: fsf_req which belongs to xchg config data request
1950 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1951 *
1952 * returns: -EIO on error, 0 otherwise
1953 */
1954static int
1955zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1956{
1957 struct fsf_qtcb_bottom_config *bottom;
1958 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001959 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 bottom = &fsf_req->qtcb->bottom.config;
1962 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1963 bottom->low_qtcb_version, bottom->high_qtcb_version);
1964 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001965 adapter->adapter_features = bottom->adapter_features;
1966 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05001967 adapter->peer_wwpn = 0;
1968 adapter->peer_wwnn = 0;
1969 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
1971 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001972
1973 if (fsf_req->data)
1974 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1975 bottom, sizeof (struct fsf_qtcb_bottom_config));
1976
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001977 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
1978 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
1979 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
1980 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001981 fc_host_supported_classes(shost) =
1982 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 adapter->hydra_version = bottom->adapter_type;
Christof Schmittc9615852008-05-06 11:00:05 +02001984 adapter->timer_ticks = bottom->timer_interval;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001985 if (fc_host_permanent_port_name(shost) == -1)
1986 fc_host_permanent_port_name(shost) =
1987 fc_host_port_name(shost);
1988 if (bottom->fc_topology == FSF_TOPO_P2P) {
1989 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
1990 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
1991 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
1992 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1993 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
1994 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1995 else if (bottom->fc_topology == FSF_TOPO_AL)
1996 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1997 else
1998 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002000 fc_host_node_name(shost) = 0;
2001 fc_host_port_name(shost) = 0;
2002 fc_host_port_id(shost) = 0;
2003 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002004 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 adapter->hydra_version = 0;
2006 }
2007
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002008 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002010 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2011 min(FC_SERIAL_NUMBER_SIZE, 17));
2012 EBCASC(fc_host_serial_number(shost),
2013 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 }
2015
Swen Schilligec258fe2008-04-24 19:35:53 +02002016 if (fsf_req->erp_action)
2017 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2018 "characteristics:\n"
2019 "WWNN 0x%016Lx, WWPN 0x%016Lx, "
2020 "S_ID 0x%06x,\n"
2021 "adapter version 0x%x, "
2022 "LIC version 0x%x, "
2023 "FC link speed %d Gb/s\n",
2024 zfcp_get_busid_by_adapter(adapter),
2025 (wwn_t) fc_host_node_name(shost),
2026 (wwn_t) fc_host_port_name(shost),
2027 fc_host_port_id(shost),
2028 adapter->hydra_version,
2029 adapter->fsf_lic_version,
2030 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2032 ZFCP_LOG_NORMAL("error: the adapter %s "
2033 "only supports newer control block "
2034 "versions in comparison to this device "
2035 "driver (try updated device driver)\n",
2036 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002037 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 return -EIO;
2039 }
2040 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2041 ZFCP_LOG_NORMAL("error: the adapter %s "
2042 "only supports older control block "
2043 "versions than this device driver uses"
2044 "(consider a microcode upgrade)\n",
2045 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002046 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 return -EIO;
2048 }
2049 return 0;
2050}
2051
Swen Schillig52ef11a2007-08-28 09:31:09 +02002052/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 * function: zfcp_fsf_exchange_config_data_handler
2054 *
2055 * purpose: is called for finished Exchange Configuration Data command
2056 *
2057 * returns:
2058 */
2059static int
2060zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2061{
2062 struct fsf_qtcb_bottom_config *bottom;
2063 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002064 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2067 return -EIO;
2068
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002069 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
2071 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2073 return -EIO;
2074
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002075 switch (fc_host_port_type(adapter->scsi_host)) {
2076 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002077 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2078 "configuration detected at adapter %s\n"
2079 "Peer WWNN 0x%016llx, "
2080 "peer WWPN 0x%016llx, "
2081 "peer d_id 0x%06x\n",
2082 zfcp_get_busid_by_adapter(adapter),
2083 adapter->peer_wwnn,
2084 adapter->peer_wwpn,
2085 adapter->peer_d_id);
6f71d9b2005-04-10 23:04:28 -05002086 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002087 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2089 "topology detected at adapter %s "
2090 "unsupported, shutting down adapter\n",
2091 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002092 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002094 case FC_PORTTYPE_NPORT:
Swen Schilligec258fe2008-04-24 19:35:53 +02002095 if (fsf_req->erp_action)
2096 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2097 "network detected at adapter "
2098 "%s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02002099 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 break;
2101 default:
2102 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2103 "reported by the exchange "
2104 "configuration command for "
2105 "the adapter %s is not "
2106 "of a type known to the zfcp "
2107 "driver, shutting down adapter\n",
2108 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002109 zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 return -EIO;
2111 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002112 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2114 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2115 "allowed by the adapter %s "
2116 "is lower than the minimum "
2117 "required by the driver (%ld bytes).\n",
2118 bottom->max_qtcb_size,
2119 zfcp_get_busid_by_adapter(adapter),
2120 sizeof(struct fsf_qtcb));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002121 zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 return -EIO;
2123 }
2124 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2125 &adapter->status);
2126 break;
2127 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2129 return -EIO;
2130
Swen Schillig52ef11a2007-08-28 09:31:09 +02002131 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2132 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002133
Martin Peschke698ec0162008-03-27 14:22:02 +01002134 zfcp_fsf_link_down_info_eval(fsf_req, 42,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002135 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 break;
2137 default:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002138 zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 return -EIO;
2140 }
2141 return 0;
2142}
2143
2144/**
2145 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002146 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 */
2148int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002149zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
2151 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002152 struct zfcp_fsf_req *fsf_req;
2153 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002154 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002155 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002157 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002159 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002161 return -EOPNOTSUPP;
2162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 /* setup new FSF request */
2165 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002166 ZFCP_REQ_AUTO_CLEANUP,
2167 adapter->pool.fsf_req_erp,
2168 &lock_flags, &fsf_req);
2169 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002171 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002172 "the adapter %s.\n",
2173 zfcp_get_busid_by_adapter(adapter));
Swen Schillig00bab912008-06-10 18:20:57 +02002174 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002175 return retval;
2176 }
2177
Swen Schillig00bab912008-06-10 18:20:57 +02002178 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002179 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2180 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2181
2182 erp_action->fsf_req = fsf_req;
2183 fsf_req->erp_action = erp_action;
2184 zfcp_erp_start_timer(fsf_req);
2185
2186 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02002187 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002188
2189 if (retval) {
2190 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2191 "command on the adapter %s\n",
2192 zfcp_get_busid_by_adapter(adapter));
2193 zfcp_fsf_req_free(fsf_req);
2194 erp_action->fsf_req = NULL;
2195 }
2196 else
2197 ZFCP_LOG_DEBUG("exchange port data request initiated "
2198 "(adapter %s)\n",
2199 zfcp_get_busid_by_adapter(adapter));
2200 return retval;
2201}
2202
2203
2204/**
2205 * zfcp_fsf_exchange_port_data_sync - request information about local port
2206 * and wait until information is ready
2207 */
2208int
2209zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2210 struct fsf_qtcb_bottom_port *data)
2211{
2212 volatile struct qdio_buffer_element *sbale;
2213 struct zfcp_fsf_req *fsf_req;
2214 unsigned long lock_flags;
2215 int retval;
2216
2217 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2218 ZFCP_LOG_INFO("error: exchange port data "
2219 "command not supported by adapter %s\n",
2220 zfcp_get_busid_by_adapter(adapter));
2221 return -EOPNOTSUPP;
2222 }
2223
2224 /* setup new FSF request */
2225 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2226 0, NULL, &lock_flags, &fsf_req);
2227 if (retval) {
2228 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Joe Perchesceb3dfb2008-01-26 14:11:10 +01002229 "exchange port data request for "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002230 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 zfcp_get_busid_by_adapter(adapter));
Swen Schillig00bab912008-06-10 18:20:57 +02002232 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002233 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002234 }
2235
2236 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002237 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002238
Swen Schillig00bab912008-06-10 18:20:57 +02002239 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002240 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2241 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Swen Schillig52ef11a2007-08-28 09:31:09 +02002243 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002244 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02002245 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Swen Schillig52ef11a2007-08-28 09:31:09 +02002247 if (retval)
2248 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2249 "command on the adapter %s\n",
2250 zfcp_get_busid_by_adapter(adapter));
2251 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002252 wait_event(fsf_req->completion_wq,
2253 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002254
2255 zfcp_fsf_req_free(fsf_req);
2256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 return retval;
2258}
2259
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002260/**
2261 * zfcp_fsf_exchange_port_evaluate
2262 * @fsf_req: fsf_req which belongs to xchg port data request
2263 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2264 */
2265static void
2266zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2267{
2268 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002269 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002270 struct Scsi_Host *shost;
2271
2272 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002273 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002274 shost = adapter->scsi_host;
2275
Swen Schillig52ef11a2007-08-28 09:31:09 +02002276 if (fsf_req->data)
2277 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2278 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002279
2280 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2281 fc_host_permanent_port_name(shost) = bottom->wwpn;
2282 else
2283 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2284 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2285 fc_host_supported_speeds(shost) = bottom->supported_speed;
2286}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
2288/**
2289 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2290 * @fsf_req: pointer to struct zfcp_fsf_req
2291 */
2292static void
2293zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2294{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002295 struct zfcp_adapter *adapter;
2296 struct fsf_qtcb *qtcb;
2297
2298 adapter = fsf_req->adapter;
2299 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2302 return;
2303
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002304 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002306 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002307 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002308 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002309 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002310 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002311 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Martin Peschke698ec0162008-03-27 14:22:02 +01002312 zfcp_fsf_link_down_info_eval(fsf_req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002313 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 }
2316}
2317
2318
2319/*
2320 * function: zfcp_fsf_open_port
2321 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002322 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 *
2324 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002325 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 */
2327int
2328zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2329{
2330 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002331 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 unsigned long lock_flags;
2333 int retval = 0;
2334
2335 /* setup new FSF request */
2336 retval = zfcp_fsf_req_create(erp_action->adapter,
2337 FSF_QTCB_OPEN_PORT_WITH_DID,
2338 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2339 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002340 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 if (retval < 0) {
2342 ZFCP_LOG_INFO("error: Could not create open port request "
2343 "for port 0x%016Lx on adapter %s.\n",
2344 erp_action->port->wwpn,
2345 zfcp_get_busid_by_adapter(erp_action->adapter));
2346 goto out;
2347 }
2348
Swen Schillig00bab912008-06-10 18:20:57 +02002349 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2351 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2352
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002353 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002355 fsf_req->data = (unsigned long) erp_action->port;
2356 fsf_req->erp_action = erp_action;
2357 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002359 zfcp_erp_start_timer(fsf_req);
2360 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 if (retval) {
2362 ZFCP_LOG_INFO("error: Could not send open port request for "
2363 "port 0x%016Lx on adapter %s.\n",
2364 erp_action->port->wwpn,
2365 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002366 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 erp_action->fsf_req = NULL;
2368 goto out;
2369 }
2370
2371 ZFCP_LOG_DEBUG("open port request initiated "
2372 "(adapter %s, port 0x%016Lx)\n",
2373 zfcp_get_busid_by_adapter(erp_action->adapter),
2374 erp_action->port->wwpn);
2375 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002376 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 return retval;
2378}
2379
2380/*
2381 * function: zfcp_fsf_open_port_handler
2382 *
2383 * purpose: is called for finished Open Port command
2384 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002385 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 */
2387static int
2388zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2389{
2390 int retval = -EINVAL;
2391 struct zfcp_port *port;
2392 struct fsf_plogi *plogi;
2393 struct fsf_qtcb_header *header;
2394 u16 subtable, rule, counter;
2395
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002396 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 header = &fsf_req->qtcb->header;
2398
2399 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2400 /* don't change port status in our bookkeeping */
2401 goto skip_fsfstatus;
2402 }
2403
2404 /* evaluate FSF status in QTCB */
2405 switch (header->fsf_status) {
2406
2407 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2409 "is already open.\n",
2410 port->wwpn, zfcp_get_busid_by_port(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 /*
2412 * This is a bug, however operation should continue normally
2413 * if it is simply ignored
2414 */
2415 break;
2416
2417 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2419 "on adapter %s\n",
2420 port->wwpn, zfcp_get_busid_by_port(port));
2421 for (counter = 0; counter < 2; counter++) {
2422 subtable = header->fsf_status_qual.halfword[counter * 2];
2423 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2424 switch (subtable) {
2425 case FSF_SQ_CFDC_SUBTABLE_OS:
2426 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2427 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2428 case FSF_SQ_CFDC_SUBTABLE_LUN:
2429 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2430 zfcp_act_subtable_type[subtable], rule);
2431 break;
2432 }
2433 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02002434 zfcp_erp_port_access_denied(port, 57, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2436 break;
2437
2438 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2440 "The remote port 0x%016Lx on adapter %s "
2441 "could not be opened. Disabling it.\n",
2442 port->wwpn, zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002443 zfcp_erp_port_failed(port, 31, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2445 break;
2446
2447 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 switch (header->fsf_status_qual.word[0]) {
2449 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 /* ERP strategy will escalate */
2451 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2452 break;
2453 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2454 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2456 break;
2457 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2459 "adapter %s could not be opened. "
2460 "Disabling it.\n",
2461 port->wwpn,
2462 zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002463 zfcp_erp_port_failed(port, 32, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2465 break;
2466 default:
2467 ZFCP_LOG_NORMAL
2468 ("bug: Wrong status qualifier 0x%x arrived.\n",
2469 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 break;
2471 }
2472 break;
2473
2474 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 /* save port handle assigned by FSF */
2476 port->handle = header->port_handle;
2477 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2478 "was opened, it's port handle is 0x%x\n",
2479 port->wwpn, zfcp_get_busid_by_port(port),
2480 port->handle);
2481 /* mark port as open */
2482 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2483 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002484 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2485 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2486 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 retval = 0;
2488 /* check whether D_ID has changed during open */
2489 /*
2490 * FIXME: This check is not airtight, as the FCP channel does
2491 * not monitor closures of target port connections caused on
2492 * the remote side. Thus, they might miss out on invalidating
2493 * locally cached WWPNs (and other N_Port parameters) of gone
2494 * target ports. So, our heroic attempt to make things safe
2495 * could be undermined by 'open port' response data tagged with
2496 * obsolete WWPNs. Another reason to monitor potential
2497 * connection closures ourself at least (by interpreting
2498 * incoming ELS' and unsolicited status). It just crosses my
2499 * mind that one should be able to cross-check by means of
2500 * another GID_PN straight after a port has been opened.
2501 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2502 */
2503 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2504 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2505 {
2506 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002507 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 ZFCP_LOG_INFO(
2509 "warning: insufficient length of "
2510 "PLOGI payload (%i)\n",
2511 fsf_req->qtcb->bottom.support.els1_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 /* skip sanity check and assume wwpn is ok */
2513 } else {
2514 if (plogi->serv_param.wwpn != port->wwpn) {
2515 ZFCP_LOG_INFO("warning: d_id of port "
2516 "0x%016Lx changed during "
2517 "open\n", port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 atomic_clear_mask(
2519 ZFCP_STATUS_PORT_DID_DID,
2520 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002521 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 port->wwnn = plogi->serv_param.wwnn;
Christof Schmitt24073b42008-06-10 18:20:54 +02002523 zfcp_fc_plogi_evaluate(port, plogi);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 }
2526 }
2527 break;
2528
2529 case FSF_UNKNOWN_OP_SUBTYPE:
2530 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2532 "op_subtype=0x%x)\n",
2533 zfcp_get_busid_by_port(port),
2534 fsf_req->qtcb->bottom.support.operation_subtype);
2535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2536 break;
2537
2538 default:
2539 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2540 "(debug info 0x%x)\n",
2541 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 break;
2543 }
2544
2545 skip_fsfstatus:
2546 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2547 return retval;
2548}
2549
2550/*
2551 * function: zfcp_fsf_close_port
2552 *
2553 * purpose: submit FSF command "close port"
2554 *
2555 * returns: address of initiated FSF request
2556 * NULL - request could not be initiated
2557 */
2558int
2559zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2560{
2561 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002562 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 unsigned long lock_flags;
2564 int retval = 0;
2565
2566 /* setup new FSF request */
2567 retval = zfcp_fsf_req_create(erp_action->adapter,
2568 FSF_QTCB_CLOSE_PORT,
2569 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2570 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002571 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 if (retval < 0) {
2573 ZFCP_LOG_INFO("error: Could not create a close port request "
2574 "for port 0x%016Lx on adapter %s.\n",
2575 erp_action->port->wwpn,
2576 zfcp_get_busid_by_adapter(erp_action->adapter));
2577 goto out;
2578 }
2579
Swen Schillig00bab912008-06-10 18:20:57 +02002580 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2582 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2583
2584 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002585 fsf_req->data = (unsigned long) erp_action->port;
2586 fsf_req->erp_action = erp_action;
2587 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2588 fsf_req->erp_action = erp_action;
2589 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002591 zfcp_erp_start_timer(fsf_req);
2592 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 if (retval) {
2594 ZFCP_LOG_INFO("error: Could not send a close port request for "
2595 "port 0x%016Lx on adapter %s.\n",
2596 erp_action->port->wwpn,
2597 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002598 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 erp_action->fsf_req = NULL;
2600 goto out;
2601 }
2602
2603 ZFCP_LOG_TRACE("close port request initiated "
2604 "(adapter %s, port 0x%016Lx)\n",
2605 zfcp_get_busid_by_adapter(erp_action->adapter),
2606 erp_action->port->wwpn);
2607 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002608 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 return retval;
2610}
2611
2612/*
2613 * function: zfcp_fsf_close_port_handler
2614 *
2615 * purpose: is called for finished Close Port FSF command
2616 *
2617 * returns:
2618 */
2619static int
2620zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2621{
2622 int retval = -EINVAL;
2623 struct zfcp_port *port;
2624
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002625 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
2627 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2628 /* don't change port status in our bookkeeping */
2629 goto skip_fsfstatus;
2630 }
2631
2632 /* evaluate FSF status in QTCB */
2633 switch (fsf_req->qtcb->header.fsf_status) {
2634
2635 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2637 "0x%016Lx on adapter %s invalid. This may happen "
2638 "occasionally.\n", port->handle,
2639 port->wwpn, zfcp_get_busid_by_port(port));
2640 ZFCP_LOG_DEBUG("status qualifier:\n");
2641 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2642 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2643 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002644 zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2646 break;
2647
2648 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 /* Note: FSF has actually closed the port in this case.
2650 * The status code is just daft. Fingers crossed for a change
2651 */
2652 retval = 0;
2653 break;
2654
2655 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2657 "port handle 0x%x\n", port->wwpn,
2658 zfcp_get_busid_by_port(port), port->handle);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002659 zfcp_erp_modify_port_status(port, 33, fsf_req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 ZFCP_STATUS_COMMON_OPEN,
2661 ZFCP_CLEAR);
2662 retval = 0;
2663 break;
2664
2665 default:
2666 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2667 "(debug info 0x%x)\n",
2668 fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 break;
2670 }
2671
2672 skip_fsfstatus:
2673 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2674 return retval;
2675}
2676
2677/*
2678 * function: zfcp_fsf_close_physical_port
2679 *
2680 * purpose: submit FSF command "close physical port"
2681 *
2682 * returns: address of initiated FSF request
2683 * NULL - request could not be initiated
2684 */
2685int
2686zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2687{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002689 struct zfcp_fsf_req *fsf_req;
2690 unsigned long lock_flags;
2691 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 /* setup new FSF request */
2694 retval = zfcp_fsf_req_create(erp_action->adapter,
2695 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2696 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2697 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002698 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 if (retval < 0) {
2700 ZFCP_LOG_INFO("error: Could not create close physical port "
2701 "request (adapter %s, port 0x%016Lx)\n",
2702 zfcp_get_busid_by_adapter(erp_action->adapter),
2703 erp_action->port->wwpn);
2704
2705 goto out;
2706 }
2707
Swen Schillig00bab912008-06-10 18:20:57 +02002708 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2710 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2711
2712 /* mark port as being closed */
2713 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2714 &erp_action->port->status);
2715 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002716 fsf_req->data = (unsigned long) erp_action->port;
2717 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2718 fsf_req->erp_action = erp_action;
2719 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002721 zfcp_erp_start_timer(fsf_req);
2722 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 if (retval) {
2724 ZFCP_LOG_INFO("error: Could not send 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);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002728 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 erp_action->fsf_req = NULL;
2730 goto out;
2731 }
2732
2733 ZFCP_LOG_TRACE("close physical port request initiated "
2734 "(adapter %s, port 0x%016Lx)\n",
2735 zfcp_get_busid_by_adapter(erp_action->adapter),
2736 erp_action->port->wwpn);
2737 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002738 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 return retval;
2740}
2741
2742/*
2743 * function: zfcp_fsf_close_physical_port_handler
2744 *
2745 * purpose: is called for finished Close Physical Port FSF command
2746 *
2747 * returns:
2748 */
2749static int
2750zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2751{
2752 int retval = -EINVAL;
2753 struct zfcp_port *port;
2754 struct zfcp_unit *unit;
2755 struct fsf_qtcb_header *header;
2756 u16 subtable, rule, counter;
2757
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002758 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 header = &fsf_req->qtcb->header;
2760
2761 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2762 /* don't change port status in our bookkeeping */
2763 goto skip_fsfstatus;
2764 }
2765
2766 /* evaluate FSF status in QTCB */
2767 switch (header->fsf_status) {
2768
2769 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2771 "(adapter %s, port 0x%016Lx). "
2772 "This may happen occasionally.\n",
2773 port->handle,
2774 zfcp_get_busid_by_port(port),
2775 port->wwpn);
2776 ZFCP_LOG_DEBUG("status qualifier:\n");
2777 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2778 (char *) &header->fsf_status_qual,
2779 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002780 zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2782 break;
2783
2784 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 ZFCP_LOG_NORMAL("Access denied, cannot close "
2786 "physical port 0x%016Lx on adapter %s\n",
2787 port->wwpn, zfcp_get_busid_by_port(port));
2788 for (counter = 0; counter < 2; counter++) {
2789 subtable = header->fsf_status_qual.halfword[counter * 2];
2790 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2791 switch (subtable) {
2792 case FSF_SQ_CFDC_SUBTABLE_OS:
2793 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2794 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2795 case FSF_SQ_CFDC_SUBTABLE_LUN:
2796 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2797 zfcp_act_subtable_type[subtable], rule);
2798 break;
2799 }
2800 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02002801 zfcp_erp_port_access_denied(port, 58, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2803 break;
2804
2805 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2807 "%s needs to be reopened but it was attempted "
2808 "to close it physically.\n",
2809 port->wwpn,
2810 zfcp_get_busid_by_port(port));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002811 zfcp_erp_port_boxed(port, 50, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2813 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01002814
2815 /* can't use generic zfcp_erp_modify_port_status because
2816 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2817 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2818 list_for_each_entry(unit, &port->unit_list_head, list)
2819 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2820 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 break;
2822
2823 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 switch (header->fsf_status_qual.word[0]) {
2825 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 /* This will now be escalated by ERP */
2827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2828 break;
2829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2832 break;
2833 default:
2834 ZFCP_LOG_NORMAL
2835 ("bug: Wrong status qualifier 0x%x arrived.\n",
2836 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 break;
2838 }
2839 break;
2840
2841 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2843 "physically closed, port handle 0x%x\n",
2844 port->wwpn,
2845 zfcp_get_busid_by_port(port), port->handle);
2846 /* can't use generic zfcp_erp_modify_port_status because
2847 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2848 */
2849 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2850 list_for_each_entry(unit, &port->unit_list_head, list)
2851 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2852 retval = 0;
2853 break;
2854
2855 default:
2856 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2857 "(debug info 0x%x)\n",
2858 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 break;
2860 }
2861
2862 skip_fsfstatus:
2863 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2864 return retval;
2865}
2866
2867/*
2868 * function: zfcp_fsf_open_unit
2869 *
2870 * purpose:
2871 *
2872 * returns:
2873 *
2874 * assumptions: This routine does not check whether the associated
2875 * remote port has already been opened. This should be
2876 * done by calling routines. Otherwise some status
2877 * may be presented by FSF
2878 */
2879int
2880zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2881{
2882 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002883 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 unsigned long lock_flags;
2885 int retval = 0;
2886
2887 /* setup new FSF request */
2888 retval = zfcp_fsf_req_create(erp_action->adapter,
2889 FSF_QTCB_OPEN_LUN,
2890 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2891 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002892 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 if (retval < 0) {
2894 ZFCP_LOG_INFO("error: Could not create open unit request for "
2895 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2896 erp_action->unit->fcp_lun,
2897 erp_action->unit->port->wwpn,
2898 zfcp_get_busid_by_adapter(erp_action->adapter));
2899 goto out;
2900 }
2901
Swen Schillig00bab912008-06-10 18:20:57 +02002902 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2904 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2905
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002906 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2907 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002908 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002909 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02002910 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002912 fsf_req->data = (unsigned long) erp_action->unit;
2913 fsf_req->erp_action = erp_action;
2914 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002916 zfcp_erp_start_timer(fsf_req);
2917 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 if (retval) {
2919 ZFCP_LOG_INFO("error: Could not send an open unit request "
2920 "on the adapter %s, port 0x%016Lx for "
2921 "unit 0x%016Lx\n",
2922 zfcp_get_busid_by_adapter(erp_action->adapter),
2923 erp_action->port->wwpn,
2924 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002925 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 erp_action->fsf_req = NULL;
2927 goto out;
2928 }
2929
2930 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2931 "port 0x%016Lx, unit 0x%016Lx)\n",
2932 zfcp_get_busid_by_adapter(erp_action->adapter),
2933 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2934 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002935 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 return retval;
2937}
2938
2939/*
2940 * function: zfcp_fsf_open_unit_handler
2941 *
2942 * purpose: is called for finished Open LUN command
2943 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002944 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 */
2946static int
2947zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2948{
2949 int retval = -EINVAL;
2950 struct zfcp_adapter *adapter;
2951 struct zfcp_unit *unit;
2952 struct fsf_qtcb_header *header;
2953 struct fsf_qtcb_bottom_support *bottom;
2954 struct fsf_queue_designator *queue_designator;
2955 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002956 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002958 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
2960 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2961 /* don't change unit status in our bookkeeping */
2962 goto skip_fsfstatus;
2963 }
2964
2965 adapter = fsf_req->adapter;
2966 header = &fsf_req->qtcb->header;
2967 bottom = &fsf_req->qtcb->bottom.support;
2968 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2969
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02002971 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 ZFCP_STATUS_UNIT_SHARED |
2973 ZFCP_STATUS_UNIT_READONLY,
2974 &unit->status);
2975
2976 /* evaluate FSF status in QTCB */
2977 switch (header->fsf_status) {
2978
2979 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
2981 "for port 0x%016Lx on adapter %s invalid "
2982 "This may happen occasionally\n",
2983 unit->port->handle,
2984 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2985 ZFCP_LOG_DEBUG("status qualifier:\n");
2986 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2987 (char *) &header->fsf_status_qual,
2988 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02002989 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2991 break;
2992
2993 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
2995 "remote port 0x%016Lx on adapter %s twice.\n",
2996 unit->fcp_lun,
2997 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2999 break;
3000
3001 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3003 "remote port 0x%016Lx on adapter %s\n",
3004 unit->fcp_lun, unit->port->wwpn,
3005 zfcp_get_busid_by_unit(unit));
3006 for (counter = 0; counter < 2; counter++) {
3007 subtable = header->fsf_status_qual.halfword[counter * 2];
3008 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3009 switch (subtable) {
3010 case FSF_SQ_CFDC_SUBTABLE_OS:
3011 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3012 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3013 case FSF_SQ_CFDC_SUBTABLE_LUN:
3014 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3015 zfcp_act_subtable_type[subtable], rule);
3016 break;
3017 }
3018 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02003019 zfcp_erp_unit_access_denied(unit, 59, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3021 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3022 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3023 break;
3024
3025 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3027 "needs to be reopened\n",
3028 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003029 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3031 ZFCP_STATUS_FSFREQ_RETRY;
3032 break;
3033
3034 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 if (header->fsf_status_qual.word[0] != 0) {
3036 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3037 "with WWPN 0x%Lx "
3038 "connected to the adapter %s "
3039 "is already in use in LPAR%d, CSS%d\n",
3040 unit->fcp_lun,
3041 unit->port->wwpn,
3042 zfcp_get_busid_by_unit(unit),
3043 queue_designator->hla,
3044 queue_designator->cssid);
3045 } else {
3046 subtable = header->fsf_status_qual.halfword[4];
3047 rule = header->fsf_status_qual.halfword[5];
3048 switch (subtable) {
3049 case FSF_SQ_CFDC_SUBTABLE_OS:
3050 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3051 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3052 case FSF_SQ_CFDC_SUBTABLE_LUN:
3053 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3054 "remote port with WWPN 0x%Lx "
3055 "connected to the adapter %s "
3056 "is denied (%s rule %d)\n",
3057 unit->fcp_lun,
3058 unit->port->wwpn,
3059 zfcp_get_busid_by_unit(unit),
3060 zfcp_act_subtable_type[subtable],
3061 rule);
3062 break;
3063 }
3064 }
3065 ZFCP_LOG_DEBUG("status qualifier:\n");
3066 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3067 (char *) &header->fsf_status_qual,
3068 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003069 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3071 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3072 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3073 break;
3074
3075 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3077 "There is no handle (temporary port identifier) "
3078 "available for unit 0x%016Lx on port 0x%016Lx "
3079 "on adapter %s\n",
3080 unit->fcp_lun,
3081 unit->port->wwpn,
3082 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003083 zfcp_erp_unit_failed(unit, 34, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3085 break;
3086
3087 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 switch (header->fsf_status_qual.word[0]) {
3089 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 /* Re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003091 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3093 break;
3094 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3097 break;
3098 default:
3099 ZFCP_LOG_NORMAL
3100 ("bug: Wrong status qualifier 0x%x arrived.\n",
3101 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 }
3103 break;
3104
3105 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 ZFCP_LOG_NORMAL(
3107 "Invalid option 0x%x has been specified "
3108 "in QTCB bottom sent to the adapter %s\n",
3109 bottom->option,
3110 zfcp_get_busid_by_adapter(adapter));
3111 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3112 retval = -EINVAL;
3113 break;
3114
3115 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 /* save LUN handle assigned by FSF */
3117 unit->handle = header->lun_handle;
3118 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3119 "adapter %s opened, port handle 0x%x\n",
3120 unit->fcp_lun,
3121 unit->port->wwpn,
3122 zfcp_get_busid_by_unit(unit),
3123 unit->handle);
3124 /* mark unit as open */
3125 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003126
3127 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3128 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3129 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3130 exclusive = (bottom->lun_access_info &
3131 FSF_UNIT_ACCESS_EXCLUSIVE);
3132 readwrite = (bottom->lun_access_info &
3133 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3134
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 if (!exclusive)
3136 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3137 &unit->status);
3138
3139 if (!readwrite) {
3140 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3141 &unit->status);
3142 ZFCP_LOG_NORMAL("read-only access for unit "
3143 "(adapter %s, wwpn=0x%016Lx, "
3144 "fcp_lun=0x%016Lx)\n",
3145 zfcp_get_busid_by_unit(unit),
3146 unit->port->wwpn,
3147 unit->fcp_lun);
3148 }
3149
3150 if (exclusive && !readwrite) {
3151 ZFCP_LOG_NORMAL("exclusive access of read-only "
3152 "unit not supported\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02003153 zfcp_erp_unit_failed(unit, 35, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003155 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 } else if (!exclusive && readwrite) {
3157 ZFCP_LOG_NORMAL("shared access of read-write "
3158 "unit not supported\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02003159 zfcp_erp_unit_failed(unit, 36, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003161 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
3163 }
3164
3165 retval = 0;
3166 break;
3167
3168 default:
3169 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3170 "(debug info 0x%x)\n",
3171 header->fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 break;
3173 }
3174
3175 skip_fsfstatus:
3176 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3177 return retval;
3178}
3179
3180/*
3181 * function: zfcp_fsf_close_unit
3182 *
3183 * purpose:
3184 *
3185 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003186 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 *
3188 * assumptions: This routine does not check whether the associated
3189 * remote port/lun has already been opened. This should be
3190 * done by calling routines. Otherwise some status
3191 * may be presented by FSF
3192 */
3193int
3194zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3195{
3196 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003197 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 unsigned long lock_flags;
3199 int retval = 0;
3200
3201 /* setup new FSF request */
3202 retval = zfcp_fsf_req_create(erp_action->adapter,
3203 FSF_QTCB_CLOSE_LUN,
3204 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3205 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003206 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 if (retval < 0) {
3208 ZFCP_LOG_INFO("error: Could not create close unit request for "
3209 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3210 erp_action->unit->fcp_lun,
3211 erp_action->port->wwpn,
3212 zfcp_get_busid_by_adapter(erp_action->adapter));
3213 goto out;
3214 }
3215
Swen Schillig00bab912008-06-10 18:20:57 +02003216 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3218 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3219
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003220 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3221 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003223 fsf_req->data = (unsigned long) erp_action->unit;
3224 fsf_req->erp_action = erp_action;
3225 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003227 zfcp_erp_start_timer(fsf_req);
3228 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 if (retval) {
3230 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3231 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3232 erp_action->unit->fcp_lun,
3233 erp_action->port->wwpn,
3234 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003235 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 erp_action->fsf_req = NULL;
3237 goto out;
3238 }
3239
3240 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3241 "port 0x%016Lx, unit 0x%016Lx)\n",
3242 zfcp_get_busid_by_adapter(erp_action->adapter),
3243 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3244 out:
Swen Schillig00bab912008-06-10 18:20:57 +02003245 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 return retval;
3247}
3248
3249/*
3250 * function: zfcp_fsf_close_unit_handler
3251 *
3252 * purpose: is called for finished Close LUN FSF command
3253 *
3254 * returns:
3255 */
3256static int
3257zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3258{
3259 int retval = -EINVAL;
3260 struct zfcp_unit *unit;
3261
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003262 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3265 /* don't change unit status in our bookkeeping */
3266 goto skip_fsfstatus;
3267 }
3268
3269 /* evaluate FSF status in QTCB */
3270 switch (fsf_req->qtcb->header.fsf_status) {
3271
3272 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3274 "0x%016Lx on adapter %s invalid. This may "
3275 "happen in rare circumstances\n",
3276 unit->port->handle,
3277 unit->port->wwpn,
3278 zfcp_get_busid_by_unit(unit));
3279 ZFCP_LOG_DEBUG("status qualifier:\n");
3280 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3281 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3282 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003283 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3285 break;
3286
3287 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3289 "0x%016Lx on port 0x%016Lx on adapter %s is "
3290 "invalid. This may happen occasionally.\n",
3291 unit->handle,
3292 unit->fcp_lun,
3293 unit->port->wwpn,
3294 zfcp_get_busid_by_unit(unit));
3295 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3296 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3297 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3298 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003299 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3301 break;
3302
3303 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3305 "needs to be reopened\n",
3306 unit->port->wwpn,
3307 zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003308 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3310 ZFCP_STATUS_FSFREQ_RETRY;
3311 break;
3312
3313 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3315 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003317 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3319 break;
3320 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3323 break;
3324 default:
3325 ZFCP_LOG_NORMAL
3326 ("bug: Wrong status qualifier 0x%x arrived.\n",
3327 fsf_req->qtcb->header.fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 break;
3329 }
3330 break;
3331
3332 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3334 "closed, port handle 0x%x\n",
3335 unit->fcp_lun,
3336 unit->port->wwpn,
3337 zfcp_get_busid_by_unit(unit),
3338 unit->handle);
3339 /* mark unit as closed */
3340 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3341 retval = 0;
3342 break;
3343
3344 default:
3345 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3346 "(debug info 0x%x)\n",
3347 fsf_req->qtcb->header.fsf_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 break;
3349 }
3350
3351 skip_fsfstatus:
3352 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3353 return retval;
3354}
3355
3356/**
3357 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3358 * @adapter: adapter where scsi command is issued
3359 * @unit: unit where command is sent to
3360 * @scsi_cmnd: scsi command to be sent
3361 * @timer: timer to be started when request is initiated
3362 * @req_flags: flags for fsf_request
3363 */
3364int
3365zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3366 struct zfcp_unit *unit,
3367 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003368 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369{
3370 struct zfcp_fsf_req *fsf_req = NULL;
3371 struct fcp_cmnd_iu *fcp_cmnd_iu;
3372 unsigned int sbtype;
3373 unsigned long lock_flags;
3374 int real_bytes = 0;
3375 int retval = 0;
3376 int mask;
3377
3378 /* setup new FSF request */
3379 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3380 adapter->pool.fsf_req_scsi,
3381 &lock_flags, &fsf_req);
3382 if (unlikely(retval < 0)) {
3383 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3384 "for unit 0x%016Lx on port 0x%016Lx on "
3385 "adapter %s\n",
3386 unit->fcp_lun,
3387 unit->port->wwpn,
3388 zfcp_get_busid_by_adapter(adapter));
3389 goto failed_req_create;
3390 }
3391
Christof Schmittba172422007-12-20 12:30:26 +01003392 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3393 &unit->status))) {
3394 retval = -EBUSY;
3395 goto unit_blocked;
3396 }
3397
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003398 zfcp_unit_get(unit);
3399 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003401 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003402 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003403
3404 /* associate SCSI command with FSF request */
3405 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406
3407 /* set handles of unit and its parent port in QTCB */
3408 fsf_req->qtcb->header.lun_handle = unit->handle;
3409 fsf_req->qtcb->header.port_handle = unit->port->handle;
3410
3411 /* FSF does not define the structure of the FCP_CMND IU */
3412 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3413 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3414
3415 /*
3416 * set depending on data direction:
3417 * data direction bits in SBALE (SB Type)
3418 * data direction bits in QTCB
3419 * data direction bits in FCP_CMND IU
3420 */
3421 switch (scsi_cmnd->sc_data_direction) {
3422 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3424 /*
3425 * FIXME(qdio):
3426 * what is the correct type for commands
3427 * without 'real' data buffers?
3428 */
3429 sbtype = SBAL_FLAGS0_TYPE_READ;
3430 break;
3431 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3433 sbtype = SBAL_FLAGS0_TYPE_READ;
3434 fcp_cmnd_iu->rddata = 1;
3435 break;
3436 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3438 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3439 fcp_cmnd_iu->wddata = 1;
3440 break;
3441 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 default:
3443 /*
3444 * dummy, catch this condition earlier
3445 * in zfcp_scsi_queuecommand
3446 */
3447 goto failed_scsi_cmnd;
3448 }
3449
3450 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003451 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
3453 /* set FCP_LUN in FCP_CMND IU in QTCB */
3454 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3455
3456 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3457
3458 /* set task attributes in FCP_CMND IU in QTCB */
3459 if (likely((scsi_cmnd->device->simple_tags) ||
3460 (atomic_test_mask(mask, &unit->status))))
3461 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3462 else
3463 fcp_cmnd_iu->task_attribute = UNTAGGED;
3464
3465 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3466 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3467 fcp_cmnd_iu->add_fcp_cdb_length
3468 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3469 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3470 "additional FCP_CDB length is 0x%x "
3471 "(shifted right 2 bits)\n",
3472 scsi_cmnd->cmd_len,
3473 fcp_cmnd_iu->add_fcp_cdb_length);
3474 }
3475 /*
3476 * copy SCSI CDB (including additional length, if any) to
3477 * FCP_CDB in FCP_CMND IU in QTCB
3478 */
3479 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3480
3481 /* FCP CMND IU length in QTCB */
3482 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3483 sizeof (struct fcp_cmnd_iu) +
3484 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3485
3486 /* generate SBALEs from data buffer */
Swen Schillig00bab912008-06-10 18:20:57 +02003487 real_bytes = zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
3488 scsi_sglist(scsi_cmnd),
3489 ZFCP_MAX_SBALS_PER_REQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 if (unlikely(real_bytes < 0)) {
3491 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3492 ZFCP_LOG_DEBUG(
3493 "Data did not fit into available buffer(s), "
3494 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003495 retval = -EIO;
3496 } else {
3497 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3498 "required. Shutting down unit "
3499 "(adapter %s, port 0x%016Lx, "
3500 "unit 0x%016Lx)\n",
3501 zfcp_get_busid_by_unit(unit),
3502 unit->port->wwpn,
3503 unit->fcp_lun);
Martin Peschke1f6f7122008-04-18 12:51:55 +02003504 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
Christof Schmitt2282f652007-08-28 09:30:22 +02003505 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 }
3507 goto no_fit;
3508 }
3509
3510 /* set length of FCP data length in FCP_CMND IU in QTCB */
3511 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3512
3513 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3514 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3515 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3516
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003517 if (use_timer)
3518 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3519
3520 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 if (unlikely(retval < 0)) {
3522 ZFCP_LOG_INFO("error: Could not send FCP command request "
3523 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3524 zfcp_get_busid_by_adapter(adapter),
3525 unit->port->wwpn,
3526 unit->fcp_lun);
3527 goto send_failed;
3528 }
3529
3530 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3531 "port 0x%016Lx, unit 0x%016Lx)\n",
3532 zfcp_get_busid_by_adapter(adapter),
3533 unit->port->wwpn,
3534 unit->fcp_lun);
3535 goto success;
3536
3537 send_failed:
3538 no_fit:
3539 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003540 zfcp_unit_put(unit);
Christof Schmitt57b76582008-04-18 12:51:57 +02003541 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 zfcp_fsf_req_free(fsf_req);
3543 fsf_req = NULL;
3544 scsi_cmnd->host_scribble = NULL;
3545 success:
3546 failed_req_create:
Swen Schillig00bab912008-06-10 18:20:57 +02003547 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 return retval;
3549}
3550
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551struct zfcp_fsf_req *
3552zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3553 struct zfcp_unit *unit,
3554 u8 tm_flags, int req_flags)
3555{
3556 struct zfcp_fsf_req *fsf_req = NULL;
3557 int retval = 0;
3558 struct fcp_cmnd_iu *fcp_cmnd_iu;
3559 unsigned long lock_flags;
3560 volatile struct qdio_buffer_element *sbale;
3561
3562 /* setup new FSF request */
3563 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3564 adapter->pool.fsf_req_scsi,
3565 &lock_flags, &fsf_req);
3566 if (retval < 0) {
3567 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3568 "management) request for adapter %s, port "
3569 " 0x%016Lx, unit 0x%016Lx.\n",
3570 zfcp_get_busid_by_adapter(adapter),
3571 unit->port->wwpn, unit->fcp_lun);
3572 goto out;
3573 }
3574
Christof Schmittfdf23452007-12-20 12:30:27 +01003575 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3576 &unit->status)))
3577 goto unit_blocked;
3578
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 /*
3580 * Used to decide on proper handler in the return path,
3581 * could be either zfcp_fsf_send_fcp_command_task_handler or
3582 * zfcp_fsf_send_fcp_command_task_management_handler */
3583
3584 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3585
3586 /*
3587 * hold a pointer to the unit being target of this
3588 * task management request
3589 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003590 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
3592 /* set FSF related fields in QTCB */
3593 fsf_req->qtcb->header.lun_handle = unit->handle;
3594 fsf_req->qtcb->header.port_handle = unit->port->handle;
3595 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003596 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3598 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3599
Swen Schillig00bab912008-06-10 18:20:57 +02003600 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3602 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3603
3604 /* set FCP related fields in FCP_CMND IU in QTCB */
3605 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3606 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3607 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3608 fcp_cmnd_iu->task_management_flags = tm_flags;
3609
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003610 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3611 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmittfdf23452007-12-20 12:30:27 +01003612 if (!retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Christof Schmittfdf23452007-12-20 12:30:27 +01003615 unit_blocked:
3616 zfcp_fsf_req_free(fsf_req);
3617 fsf_req = NULL;
3618
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 out:
Swen Schillig00bab912008-06-10 18:20:57 +02003620 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 return fsf_req;
3622}
3623
Christof Schmittc9615852008-05-06 11:00:05 +02003624static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
3625{
3626 lat_rec->sum += lat;
3627 if (lat_rec->min > lat)
3628 lat_rec->min = lat;
3629 if (lat_rec->max < lat)
3630 lat_rec->max = lat;
3631}
3632
3633static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
3634{
3635 struct fsf_qual_latency_info *lat_inf;
3636 struct latency_cont *lat;
3637 struct zfcp_unit *unit;
3638 unsigned long flags;
3639
3640 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
3641 unit = fsf_req->unit;
3642
3643 switch (fsf_req->qtcb->bottom.io.data_direction) {
3644 case FSF_DATADIR_READ:
3645 lat = &unit->latencies.read;
3646 break;
3647 case FSF_DATADIR_WRITE:
3648 lat = &unit->latencies.write;
3649 break;
3650 case FSF_DATADIR_CMND:
3651 lat = &unit->latencies.cmd;
3652 break;
3653 default:
3654 return;
3655 }
3656
3657 spin_lock_irqsave(&unit->latencies.lock, flags);
3658 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
3659 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
3660 lat->counter++;
3661 spin_unlock_irqrestore(&unit->latencies.lock, flags);
3662}
3663
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664/*
3665 * function: zfcp_fsf_send_fcp_command_handler
3666 *
3667 * purpose: is called for finished Send FCP Command
3668 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003669 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 */
3671static int
3672zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3673{
3674 int retval = -EINVAL;
3675 struct zfcp_unit *unit;
3676 struct fsf_qtcb_header *header;
3677 u16 subtable, rule, counter;
3678
3679 header = &fsf_req->qtcb->header;
3680
3681 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003682 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003684 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685
3686 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3687 /* go directly to calls of special handlers */
3688 goto skip_fsfstatus;
3689 }
3690
3691 /* evaluate FSF status in QTCB */
3692 switch (header->fsf_status) {
3693
3694 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3696 "0x%016Lx on adapter %s invalid\n",
3697 unit->port->handle,
3698 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3699 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3700 (char *) &header->fsf_status_qual,
3701 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003702 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3704 break;
3705
3706 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3708 "0x%016Lx on port 0x%016Lx on adapter %s is "
3709 "invalid. This may happen occasionally.\n",
3710 unit->handle,
3711 unit->fcp_lun,
3712 unit->port->wwpn,
3713 zfcp_get_busid_by_unit(unit));
3714 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3715 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3716 (char *) &header->fsf_status_qual,
3717 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003718 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3720 break;
3721
3722 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3724 "unexpectedly. (adapter %s, port 0x%016Lx, "
3725 "unit 0x%016Lx)\n",
3726 unit->port->handle,
3727 zfcp_get_busid_by_unit(unit),
3728 unit->port->wwpn,
3729 unit->fcp_lun);
3730 ZFCP_LOG_NORMAL("status qualifier:\n");
3731 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3732 (char *) &header->fsf_status_qual,
3733 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003734 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3736 break;
3737
3738 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003739 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3740 "class %d.\n",
3741 zfcp_get_busid_by_unit(unit),
3742 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003744 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3746 break;
3747
3748 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3750 "adapter %s does not have correct unit "
3751 "handle 0x%x\n",
3752 unit->fcp_lun,
3753 unit->port->wwpn,
3754 zfcp_get_busid_by_unit(unit),
3755 unit->handle);
3756 ZFCP_LOG_DEBUG("status qualifier:\n");
3757 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3758 (char *) &header->fsf_status_qual,
3759 sizeof (union fsf_status_qual));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003760 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3762 break;
3763
3764 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3766 "unit 0x%016Lx on port 0x%016Lx on "
3767 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3768 zfcp_get_busid_by_unit(unit));
3769 for (counter = 0; counter < 2; counter++) {
3770 subtable = header->fsf_status_qual.halfword[counter * 2];
3771 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3772 switch (subtable) {
3773 case FSF_SQ_CFDC_SUBTABLE_OS:
3774 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3775 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3776 case FSF_SQ_CFDC_SUBTABLE_LUN:
3777 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3778 zfcp_act_subtable_type[subtable], rule);
3779 break;
3780 }
3781 }
Martin Peschke1f6f7122008-04-18 12:51:55 +02003782 zfcp_erp_unit_access_denied(unit, 61, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3784 break;
3785
3786 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3788 "0x%016Lx on port 0x%016Lx on adapter %s "
3789 "(debug info %d)\n",
3790 unit->fcp_lun,
3791 unit->port->wwpn,
3792 zfcp_get_busid_by_unit(unit),
3793 fsf_req->qtcb->bottom.io.data_direction);
3794 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003795 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3797 break;
3798
3799 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 ZFCP_LOG_NORMAL
3801 ("bug: An invalid control-data-block length field "
3802 "was found in a command for unit 0x%016Lx on port "
3803 "0x%016Lx on adapter %s " "(debug info %d)\n",
3804 unit->fcp_lun, unit->port->wwpn,
3805 zfcp_get_busid_by_unit(unit),
3806 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3807 /* stop operation for this adapter */
Martin Peschke1f6f7122008-04-18 12:51:55 +02003808 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3810 break;
3811
3812 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3814 "needs to be reopened\n",
3815 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Martin Peschke1f6f7122008-04-18 12:51:55 +02003816 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3818 ZFCP_STATUS_FSFREQ_RETRY;
3819 break;
3820
3821 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3823 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3824 zfcp_get_busid_by_unit(unit),
3825 unit->port->wwpn, unit->fcp_lun);
Martin Peschke1f6f7122008-04-18 12:51:55 +02003826 zfcp_erp_unit_boxed(unit, 54, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3828 | ZFCP_STATUS_FSFREQ_RETRY;
3829 break;
3830
3831 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 switch (header->fsf_status_qual.word[0]) {
3833 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003835 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 break;
3837 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 /* FIXME(hw) need proper specs for proper action */
3839 /* let scsi stack deal with retries and escalation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 break;
3841 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003843 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 header->fsf_status_qual.word[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 break;
3846 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003847 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 break;
3849
3850 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 break;
3852
3853 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 }
3856
3857 skip_fsfstatus:
3858 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3859 retval =
3860 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3861 } else {
3862 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003863 fsf_req->unit = NULL;
3864 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 }
3866 return retval;
3867}
3868
3869/*
3870 * function: zfcp_fsf_send_fcp_command_task_handler
3871 *
3872 * purpose: evaluates FCP_RSP IU
3873 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003874 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 */
3876static int
3877zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3878{
3879 int retval = 0;
3880 struct scsi_cmnd *scpnt;
3881 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3882 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3883 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3884 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3885 u32 sns_len;
3886 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3887 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003888 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889
3890 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003891 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 if (unlikely(!scpnt)) {
3893 ZFCP_LOG_DEBUG
3894 ("Command with fsf_req %p is not associated to "
3895 "a scsi command anymore. Aborted?\n", fsf_req);
3896 goto out;
3897 }
3898 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3899 /* FIXME: (design) mid-layer should handle DID_ABORT like
3900 * DID_SOFT_ERROR by retrying the request for devices
3901 * that allow retries.
3902 */
3903 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3904 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3905 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3906 goto skip_fsfstatus;
3907 }
3908
3909 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3910 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3911 set_host_byte(&scpnt->result, DID_ERROR);
3912 goto skip_fsfstatus;
3913 }
3914
3915 /* set message byte of result in SCSI command */
3916 scpnt->result |= COMMAND_COMPLETE << 8;
3917
3918 /*
3919 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3920 * of result in SCSI command
3921 */
3922 scpnt->result |= fcp_rsp_iu->scsi_status;
3923 if (unlikely(fcp_rsp_iu->scsi_status)) {
3924 /* DEBUG */
3925 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
3926 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3927 scpnt->cmnd, scpnt->cmd_len);
3928 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
3929 fcp_rsp_iu->scsi_status);
3930 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3931 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
3932 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3933 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
3934 fcp_rsp_iu->fcp_sns_len);
3935 }
3936
Christof Schmittc9615852008-05-06 11:00:05 +02003937 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
3938 zfcp_fsf_req_latency(fsf_req);
3939
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 /* check FCP_RSP_INFO */
3941 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
3942 ZFCP_LOG_DEBUG("rsp_len is valid\n");
3943 switch (fcp_rsp_info[3]) {
3944 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 /* ok, continue */
3946 ZFCP_LOG_TRACE("no failure or Task Management "
3947 "Function complete\n");
3948 set_host_byte(&scpnt->result, DID_OK);
3949 break;
3950 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 /* hardware bug */
3952 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3953 "that the fibrechannel protocol data "
3954 "length differs from the burst length. "
3955 "The problem occured on unit 0x%016Lx "
3956 "on port 0x%016Lx on adapter %s",
3957 unit->fcp_lun,
3958 unit->port->wwpn,
3959 zfcp_get_busid_by_unit(unit));
3960 /* dump SCSI CDB as prepared by zfcp */
3961 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3962 (char *) &fsf_req->qtcb->
3963 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 set_host_byte(&scpnt->result, DID_ERROR);
3965 goto skip_fsfstatus;
3966 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 /* driver or hardware bug */
3968 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3969 "that the fibrechannel protocol data "
3970 "fields were incorrectly set up. "
3971 "The problem occured on the unit "
3972 "0x%016Lx on port 0x%016Lx on "
3973 "adapter %s",
3974 unit->fcp_lun,
3975 unit->port->wwpn,
3976 zfcp_get_busid_by_unit(unit));
3977 /* dump SCSI CDB as prepared by zfcp */
3978 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3979 (char *) &fsf_req->qtcb->
3980 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3981 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 goto skip_fsfstatus;
3983 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 /* hardware bug */
3985 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
3986 "that conflicting values for the "
3987 "fibrechannel payload offset from the "
3988 "header were found. "
3989 "The problem occured on unit 0x%016Lx "
3990 "on port 0x%016Lx on adapter %s.\n",
3991 unit->fcp_lun,
3992 unit->port->wwpn,
3993 zfcp_get_busid_by_unit(unit));
3994 /* dump SCSI CDB as prepared by zfcp */
3995 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3996 (char *) &fsf_req->qtcb->
3997 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 set_host_byte(&scpnt->result, DID_ERROR);
3999 goto skip_fsfstatus;
4000 default:
4001 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4002 "code was detected for a command. "
4003 "The problem occured on the unit "
4004 "0x%016Lx on port 0x%016Lx on "
4005 "adapter %s (debug info 0x%x)\n",
4006 unit->fcp_lun,
4007 unit->port->wwpn,
4008 zfcp_get_busid_by_unit(unit),
4009 fcp_rsp_info[3]);
4010 /* dump SCSI CDB as prepared by zfcp */
4011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4012 (char *) &fsf_req->qtcb->
4013 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004015 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 }
4017 }
4018
4019 /* check for sense data */
4020 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4021 sns_len = FSF_FCP_RSP_SIZE -
4022 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4023 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4024 sns_len);
4025 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4026 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4027 SCSI_SENSE_BUFFERSIZE);
4028 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4029 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4030 scpnt->result);
4031 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
Boaz Harrosh64a87b22008-04-30 11:19:47 +03004032 scpnt->cmnd, scpnt->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033
4034 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4035 fcp_rsp_iu->fcp_sns_len);
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004036 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4038 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09004039 (void *)scpnt->sense_buffer, sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 }
4041
4042 /* check for overrun */
4043 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4044 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4045 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4046 "The response data length is "
4047 "%d, the original length was %d.\n",
4048 unit->fcp_lun,
4049 unit->port->wwpn,
4050 zfcp_get_busid_by_unit(unit),
4051 fcp_rsp_iu->fcp_resid,
4052 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4053 }
4054
4055 /* check for underrun */
4056 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4057 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4058 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4059 "The response data length is "
4060 "%d, the original length was %d.\n",
4061 unit->fcp_lun,
4062 unit->port->wwpn,
4063 zfcp_get_busid_by_unit(unit),
4064 fcp_rsp_iu->fcp_resid,
4065 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4066
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004067 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4068 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4069 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004070 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 }
4072
4073 skip_fsfstatus:
4074 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4075
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004076 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004077 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004078 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004079 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004080 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004081 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082
4083 /* cleanup pointer (need this especially for abort) */
4084 scpnt->host_scribble = NULL;
4085
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 (scpnt->scsi_done) (scpnt);
4088
4089 /*
4090 * We must hold this lock until scsi_done has been called.
4091 * Otherwise we may call scsi_done after abort regarding this
4092 * command has completed.
4093 * Note: scsi_done must not block!
4094 */
4095 out:
4096 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4097 return retval;
4098}
4099
4100/*
4101 * function: zfcp_fsf_send_fcp_command_task_management_handler
4102 *
4103 * purpose: evaluates FCP_RSP IU
4104 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004105 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 */
4107static int
4108zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4109{
4110 int retval = 0;
4111 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4112 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4113 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004114 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4117 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4118 goto skip_fsfstatus;
4119 }
4120
4121 /* check FCP_RSP_INFO */
4122 switch (fcp_rsp_info[3]) {
4123 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 /* ok, continue */
4125 ZFCP_LOG_DEBUG("no failure or Task Management "
4126 "Function complete\n");
4127 break;
4128 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4130 "is not supported on the target device "
4131 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4132 unit->fcp_lun,
4133 unit->port->wwpn,
4134 zfcp_get_busid_by_unit(unit));
4135 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4136 break;
4137 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4139 "failed to complete successfully. "
4140 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4141 unit->fcp_lun,
4142 unit->port->wwpn,
4143 zfcp_get_busid_by_unit(unit));
4144 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4145 break;
4146 default:
4147 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4148 "code was detected for a command. "
4149 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4150 "(debug info 0x%x)\n",
4151 unit->fcp_lun,
4152 unit->port->wwpn,
4153 zfcp_get_busid_by_unit(unit),
4154 fcp_rsp_info[3]);
4155 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4156 }
4157
4158 skip_fsfstatus:
4159 return retval;
4160}
4161
4162
4163/*
4164 * function: zfcp_fsf_control_file
4165 *
4166 * purpose: Initiator of the control file upload/download FSF requests
4167 *
4168 * returns: 0 - FSF request is successfuly created and queued
4169 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4170 * -EINVAL - Invalid direction specified
4171 * -ENOMEM - Insufficient memory
4172 * -EPERM - Cannot create FSF request or place it in QDIO queue
4173 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02004174struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4175 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176{
4177 struct zfcp_fsf_req *fsf_req;
4178 struct fsf_qtcb_bottom_support *bottom;
4179 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 int direction;
Christof Schmitt45633fd2008-06-10 18:20:55 +02004182 int retval;
4183 int bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184
Christof Schmitt45633fd2008-06-10 18:20:55 +02004185 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
4186 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187
Christof Schmitt45633fd2008-06-10 18:20:55 +02004188 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4190 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4193 direction = SBAL_FLAGS0_TYPE_READ;
4194 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02004196 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 }
4198
Christof Schmitt45633fd2008-06-10 18:20:55 +02004199 retval = zfcp_fsf_req_create(adapter, fsf_cfdc->command,
4200 ZFCP_WAIT_FOR_SBAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 NULL, &lock_flags, &fsf_req);
4202 if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 retval = -EPERM;
4204 goto unlock_queue_lock;
4205 }
4206
Swen Schillig00bab912008-06-10 18:20:57 +02004207 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 sbale[0].flags |= direction;
4209
4210 bottom = &fsf_req->qtcb->bottom.support;
4211 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02004212 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213
Christof Schmitt45633fd2008-06-10 18:20:55 +02004214 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
Swen Schillig00bab912008-06-10 18:20:57 +02004215 fsf_cfdc->sg,
Christof Schmitt45633fd2008-06-10 18:20:55 +02004216 ZFCP_MAX_SBALS_PER_REQ);
4217 if (bytes != ZFCP_CFDC_MAX_SIZE) {
4218 retval = -ENOMEM;
4219 goto free_fsf_req;
4220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004222 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4223 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 retval = -EPERM;
4226 goto free_fsf_req;
4227 }
Swen Schillig00bab912008-06-10 18:20:57 +02004228 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 wait_event(fsf_req->completion_wq,
4231 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4232
Christof Schmitt45633fd2008-06-10 18:20:55 +02004233 return fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234
4235 free_fsf_req:
4236 zfcp_fsf_req_free(fsf_req);
4237 unlock_queue_lock:
Swen Schillig00bab912008-06-10 18:20:57 +02004238 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Christof Schmitt45633fd2008-06-10 18:20:55 +02004239 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240}
4241
Christof Schmitt45633fd2008-06-10 18:20:55 +02004242static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243{
Christof Schmitt45633fd2008-06-10 18:20:55 +02004244 if (fsf_req->qtcb->header.fsf_status != FSF_GOOD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246}
4247
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248static inline int
4249zfcp_fsf_req_sbal_check(unsigned long *flags,
4250 struct zfcp_qdio_queue *queue, int needed)
4251{
Swen Schillig00bab912008-06-10 18:20:57 +02004252 write_lock_irqsave(&queue->lock, *flags);
4253 if (likely(atomic_read(&queue->count) >= needed))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 return 1;
Swen Schillig00bab912008-06-10 18:20:57 +02004255 write_unlock_irqrestore(&queue->lock, *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 return 0;
4257}
4258
4259/*
4260 * set qtcb pointer in fsf_req and initialize QTCB
4261 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004262static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004263zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264{
4265 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004266 fsf_req->qtcb->prefix.req_seq_no =
4267 fsf_req->adapter->fsf_req_seq_no;
4268 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004270 fsf_req->qtcb->prefix.qtcb_type =
4271 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004273 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004274 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 }
4276}
4277
4278/**
4279 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4280 * @adapter: adapter for which request queue is examined
4281 * @req_flags: flags indicating whether to wait for needed SBAL or not
4282 * @lock_flags: lock_flags if queue_lock is taken
4283 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
Swen Schillig00bab912008-06-10 18:20:57 +02004284 * Locks: lock adapter->req_q->lock on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 */
4286static int
4287zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4288 unsigned long *lock_flags)
4289{
4290 long ret;
Swen Schillig00bab912008-06-10 18:20:57 +02004291 struct zfcp_qdio_queue *req_q = &adapter->req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292
4293 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4294 ret = wait_event_interruptible_timeout(adapter->request_wq,
Swen Schillig00bab912008-06-10 18:20:57 +02004295 zfcp_fsf_req_sbal_check(lock_flags, req_q, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 ZFCP_SBAL_TIMEOUT);
4297 if (ret < 0)
4298 return ret;
4299 if (!ret)
4300 return -EIO;
Swen Schillig00bab912008-06-10 18:20:57 +02004301 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_q, 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 return -EIO;
4303
4304 return 0;
4305}
4306
4307/*
4308 * function: zfcp_fsf_req_create
4309 *
4310 * purpose: create an FSF request at the specified adapter and
4311 * setup common fields
4312 *
4313 * returns: -ENOMEM if there was insufficient memory for a request
4314 * -EIO if no qdio buffers could be allocate to the request
4315 * -EINVAL/-EPERM on bug conditions in req_dequeue
4316 * 0 in success
4317 *
4318 * note: The created request is returned by reference.
4319 *
4320 * locks: lock of concerned request queue must not be held,
4321 * but is held on completion (write, irqsave)
4322 */
4323int
4324zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4325 mempool_t *pool, unsigned long *lock_flags,
4326 struct zfcp_fsf_req **fsf_req_p)
4327{
4328 volatile struct qdio_buffer_element *sbale;
4329 struct zfcp_fsf_req *fsf_req = NULL;
4330 int ret = 0;
Swen Schillig00bab912008-06-10 18:20:57 +02004331 struct zfcp_qdio_queue *req_q = &adapter->req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332
4333 /* allocate new FSF request */
4334 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4335 if (unlikely(NULL == fsf_req)) {
Joe Perchesceb3dfb2008-01-26 14:11:10 +01004336 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 "the outbound (send) queue.\n");
4338 ret = -ENOMEM;
4339 goto failed_fsf_req;
4340 }
4341
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004342 fsf_req->adapter = adapter;
4343 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004344 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004345 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004347 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 this request completion */
4349 init_waitqueue_head(&fsf_req->completion_wq);
4350
4351 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004352 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004354
4355 /* this is serialized (we are holding req_queue-lock of adapter) */
4356 if (adapter->req_no == 0)
4357 adapter->req_no++;
4358 fsf_req->req_id = adapter->req_no++;
4359
4360 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
4362 /*
4363 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4364 * if it is not set (see also *_open_qdio and *_close_qdio).
4365 */
4366
4367 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
Swen Schillig00bab912008-06-10 18:20:57 +02004368 write_unlock_irqrestore(&req_q->lock, *lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 ret = -EIO;
4370 goto failed_sbals;
4371 }
4372
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004373 if (fsf_req->qtcb) {
4374 fsf_req->seq_no = adapter->fsf_req_seq_no;
4375 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 fsf_req->sbal_number = 1;
Swen Schillig00bab912008-06-10 18:20:57 +02004378 fsf_req->sbal_first = req_q->first;
4379 fsf_req->sbal_last = req_q->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 fsf_req->sbale_curr = 1;
4381
4382 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4383 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4384 }
4385
Swen Schillig00bab912008-06-10 18:20:57 +02004386 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387
4388 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004389 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4391 if (likely(fsf_req->qtcb != NULL)) {
4392 sbale[1].addr = (void *) fsf_req->qtcb;
4393 sbale[1].length = sizeof(struct fsf_qtcb);
4394 }
4395
4396 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4397 fsf_req->sbal_number, fsf_req->sbal_first);
4398
4399 goto success;
4400
4401 failed_sbals:
4402/* dequeue new FSF request previously enqueued */
4403 zfcp_fsf_req_free(fsf_req);
4404 fsf_req = NULL;
4405
4406 failed_fsf_req:
Swen Schillig00bab912008-06-10 18:20:57 +02004407 write_lock_irqsave(&req_q->lock, *lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 success:
4409 *fsf_req_p = fsf_req;
4410 return ret;
4411}
4412
4413/*
4414 * function: zfcp_fsf_req_send
4415 *
4416 * purpose: start transfer of FSF request via QDIO
4417 *
4418 * returns: 0 - request transfer succesfully started
4419 * !0 - start of request transfer failed
4420 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004421static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422{
4423 struct zfcp_adapter *adapter;
Swen Schillig00bab912008-06-10 18:20:57 +02004424 struct zfcp_qdio_queue *req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004426 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 int retval = 0;
4428
4429 adapter = fsf_req->adapter;
Swen Schillig00bab912008-06-10 18:20:57 +02004430 req_q = &adapter->req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431
4432
4433 /* FIXME(debug): remove it later */
Swen Schillig00bab912008-06-10 18:20:57 +02004434 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4436 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4437 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4438 sbale[1].length);
4439
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004440 /* put allocated FSF request into hash table */
4441 spin_lock(&adapter->req_list_lock);
4442 zfcp_reqlist_add(adapter, fsf_req);
4443 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004445 inc_seq_no = (fsf_req->qtcb != NULL);
4446
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004447 fsf_req->issued = get_clock();
4448
Swen Schillig00bab912008-06-10 18:20:57 +02004449 retval = zfcp_qdio_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450
4451 if (unlikely(retval)) {
4452 /* Queues are down..... */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004453 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004454 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004455 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004456 spin_unlock(&adapter->req_list_lock);
4457 /* undo changes in request queue made for this request */
Swen Schillig00bab912008-06-10 18:20:57 +02004458 atomic_add(fsf_req->sbal_number, &req_q->count);
4459 req_q->first -= fsf_req->sbal_number;
4460 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
4461 req_q->first %= QDIO_MAX_BUFFERS_PER_Q;
Martin Peschke1f6f7122008-04-18 12:51:55 +02004462 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02004463 retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 /*
4466 * increase FSF sequence counter -
4467 * this must only be done for request successfully enqueued to
4468 * QDIO this rejected requests may be cleaned up by calling
4469 * routines resulting in missing sequence counter values
4470 * otherwise,
4471 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004472
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004474 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 adapter->fsf_req_seq_no++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 }
4477 return retval;
4478}
4479
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480#undef ZFCP_LOG_AREA