blob: 665fcb6ec5d5f667e11272a3810f00bf3a9fddb9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02002 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02005 * (C) Copyright IBM Corp. 2002, 2006
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "zfcp_ext.h"
23
24static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
25static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
26static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
27static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
28static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
29static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
30static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
31static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
32static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
33static int zfcp_fsf_send_fcp_command_task_management_handler(
34 struct zfcp_fsf_req *);
35static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
36static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
37static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
38static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
39static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
40static inline int zfcp_fsf_req_sbal_check(
41 unsigned long *, struct zfcp_qdio_queue *, int);
42static inline int zfcp_use_one_sbal(
43 struct scatterlist *, int, struct scatterlist *, int);
44static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
Andreas Herrmann2abbe862006-09-18 22:29:56 +020045static int zfcp_fsf_req_send(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
47static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
48static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020049static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
50 struct fsf_link_down_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/* association between FSF command and FSF QTCB type */
54static u32 fsf_qtcb_type[] = {
55 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
56 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
62 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
65 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
66 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
67 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
68};
69
70static const char zfcp_act_subtable_type[5][8] = {
71 "unknown", "OS", "WWPN", "DID", "LUN"
72};
73
74/****************************************************************/
75/*************** FSF related Functions *************************/
76/****************************************************************/
77
78#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
79
80/*
81 * function: zfcp_fsf_req_alloc
82 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +020083 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 * unsolicited requests) via helper functions
85 * Does some initial fsf request set-up.
Swen Schillig41fa2ad2007-09-07 09:15:31 +020086 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 * returns: pointer to allocated fsf_req if successfull
88 * NULL otherwise
89 *
90 * locks: none
91 *
92 */
93static struct zfcp_fsf_req *
94zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
95{
96 size_t size;
97 void *ptr;
98 struct zfcp_fsf_req *fsf_req = NULL;
99
100 if (req_flags & ZFCP_REQ_NO_QTCB)
101 size = sizeof(struct zfcp_fsf_req);
102 else
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200103 size = sizeof(struct zfcp_fsf_req_qtcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200105 if (likely(pool))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 ptr = mempool_alloc(pool, GFP_ATOMIC);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200107 else {
108 if (req_flags & ZFCP_REQ_NO_QTCB)
109 ptr = kmalloc(size, GFP_ATOMIC);
110 else
111 ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
Christoph Lameter54e6ecb2006-12-06 20:33:16 -0800112 GFP_ATOMIC);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200115 if (unlikely(!ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 goto out;
117
118 memset(ptr, 0, size);
119
120 if (req_flags & ZFCP_REQ_NO_QTCB) {
121 fsf_req = (struct zfcp_fsf_req *) ptr;
122 } else {
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200123 fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
124 fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126
127 fsf_req->pool = pool;
128
129 out:
130 return fsf_req;
131}
132
133/*
134 * function: zfcp_fsf_req_free
135 *
136 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
137 * returns it into the pool via helper functions.
138 *
139 * returns: sod all
140 *
141 * locks: none
142 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200143void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
145{
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200146 if (likely(fsf_req->pool)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 mempool_free(fsf_req, fsf_req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200148 return;
149 }
150
151 if (fsf_req->qtcb) {
152 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
153 return;
154 }
155
156 kfree(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
Martin Peschke869b2b42007-05-09 11:01:20 +0200159/*
160 * Never ever call this without shutting down the adapter first.
161 * Otherwise the adapter would continue using and corrupting s390 storage.
162 * Included BUG_ON() call to ensure this is done.
163 * ERP is supposed to be the only user of this function.
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200164 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100165void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200166{
Martin Peschke869b2b42007-05-09 11:01:20 +0200167 struct zfcp_fsf_req *fsf_req, *tmp;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200168 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100169 LIST_HEAD(remove_queue);
Martin Peschke869b2b42007-05-09 11:01:20 +0200170 unsigned int i;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200171
Martin Peschke869b2b42007-05-09 11:01:20 +0200172 BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status));
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200173 spin_lock_irqsave(&adapter->req_list_lock, flags);
174 atomic_set(&adapter->reqs_active, 0);
Martin Peschke869b2b42007-05-09 11:01:20 +0200175 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100176 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200177 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
178
Martin Peschke869b2b42007-05-09 11:01:20 +0200179 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
180 list_del(&fsf_req->list);
181 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
182 zfcp_fsf_req_complete(fsf_req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100183 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200184}
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/*
187 * function: zfcp_fsf_req_complete
188 *
189 * purpose: Updates active counts and timers for openfcp-reqs
190 * May cleanup request after req_eval returns
191 *
192 * returns: 0 - success
193 * !0 - failure
194 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200195 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 */
197int
198zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
199{
200 int retval = 0;
201 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
204 ZFCP_LOG_DEBUG("Status read response received\n");
205 /*
206 * Note: all cleanup handling is done in the callchain of
207 * the function call-chain below.
208 */
209 zfcp_fsf_status_read_handler(fsf_req);
210 goto out;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200211 } else {
212 del_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 zfcp_fsf_protstatus_eval(fsf_req);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 /*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200217 * fsf_req may be deleted due to waking up functions, so
218 * cleanup is saved here and used later
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 */
220 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
221 cleanup = 1;
222 else
223 cleanup = 0;
224
225 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
226
227 /* cleanup request if requested by initiator */
228 if (likely(cleanup)) {
229 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
230 /*
231 * lock must not be held here since it will be
232 * grabed by the called routine, too
233 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200234 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 } else {
236 /* notify initiator waiting for the requests completion */
237 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
238 /*
239 * FIXME: Race! We must not access fsf_req here as it might have been
240 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
241 * flag. It's an improbable case. But, we have the same paranoia for
242 * the cleanup flag already.
243 * Might better be handled using complete()?
244 * (setting the flag and doing wakeup ought to be atomic
245 * with regard to checking the flag as long as waitqueue is
246 * part of the to be released structure)
247 */
248 wake_up(&fsf_req->completion_wq);
249 }
250
251 out:
252 return retval;
253}
254
255/*
256 * function: zfcp_fsf_protstatus_eval
257 *
258 * purpose: evaluates the QTCB of the finished FSF request
259 * and initiates appropriate actions
260 * (usually calling FSF command specific handlers)
261 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200262 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200264 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 *
266 * locks:
267 */
268static int
269zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
270{
271 int retval = 0;
272 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200273 struct fsf_qtcb *qtcb = fsf_req->qtcb;
274 union fsf_prot_status_qual *prot_status_qual =
275 &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200277 zfcp_hba_dbf_event_fsf_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
280 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
281 (unsigned long) fsf_req);
282 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
283 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 goto skip_protstatus;
285 }
286
287 /* log additional information provided by FSF (if any) */
Heiko Carstens862794f2007-02-21 09:28:00 +0100288 if (likely(qtcb->header.log_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* do not trust them ;-) */
Heiko Carstens862794f2007-02-21 09:28:00 +0100290 if (unlikely(qtcb->header.log_start >
291 sizeof(struct fsf_qtcb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 ZFCP_LOG_NORMAL
293 ("bug: ULP (FSF logging) log data starts "
294 "beyond end of packet header. Ignored. "
295 "(start=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200296 qtcb->header.log_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 sizeof(struct fsf_qtcb));
298 goto forget_log;
299 }
Heiko Carstens862794f2007-02-21 09:28:00 +0100300 if (unlikely((size_t) (qtcb->header.log_start +
301 qtcb->header.log_length) >
302 sizeof(struct fsf_qtcb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
304 "beyond end of packet header. Ignored. "
305 "(start=%i, length=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200306 qtcb->header.log_start,
307 qtcb->header.log_length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 sizeof(struct fsf_qtcb));
309 goto forget_log;
310 }
311 ZFCP_LOG_TRACE("ULP log data: \n");
312 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200313 (char *) qtcb + qtcb->header.log_start,
314 qtcb->header.log_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316 forget_log:
317
318 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200319 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 break;
324
325 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 ZFCP_LOG_NORMAL("error: The adapter %s contains "
327 "microcode of version 0x%x, the device driver "
328 "only supports 0x%x. Aborting.\n",
329 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200330 prot_status_qual->version_error.fsf_version,
331 ZFCP_QTCB_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
334 break;
335
336 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
338 "driver (0x%x) and adapter %s (0x%x). "
339 "Restarting all operations on this adapter.\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200340 qtcb->prefix.req_seq_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200342 prot_status_qual->sequence_error.exp_req_seq_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
345 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
346 break;
347
348 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 ZFCP_LOG_NORMAL("error: Packet header type used by the "
350 "device driver is incompatible with "
351 "that used on adapter %s. "
352 "Stopping all operations on this adapter.\n",
353 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
356 break;
357
358 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
360 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
361 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 break;
363
364 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
366 "to the adapter %s is ambiguous. "
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200367 "Stopping all operations on this adapter.\n",
368 *(unsigned long long*)
369 (&qtcb->bottom.support.req_handle),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
373 break;
374
375 case FSF_PROT_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200376 zfcp_fsf_link_down_info_eval(adapter,
377 &prot_status_qual->link_down_info);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100378 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
380 break;
381
382 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200383 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 "%s was re-plugged. "
385 "Re-starting operations on this adapter.\n",
386 zfcp_get_busid_by_adapter(adapter));
387 /* All ports should be marked as ready to run again */
388 zfcp_erp_modify_adapter_status(adapter,
389 ZFCP_STATUS_COMMON_RUNNING,
390 ZFCP_SET);
391 zfcp_erp_adapter_reopen(adapter,
392 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
393 | ZFCP_STATUS_COMMON_ERP_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
395 break;
396
397 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 ZFCP_LOG_NORMAL("error: The adapter %s "
399 "has entered the error state. "
400 "Restarting all operations on this "
401 "adapter.\n",
402 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
405 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
406 break;
407
408 default:
409 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
410 "provided by the adapter %s "
411 "is not compatible with the device driver. "
412 "Stopping all operations on this adapter. "
413 "(debug info 0x%x).\n",
414 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200415 qtcb->prefix.prot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 zfcp_erp_adapter_shutdown(adapter, 0);
417 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
418 }
419
420 skip_protstatus:
421 /*
422 * always call specific handlers to give them a chance to do
423 * something meaningful even in error cases
424 */
425 zfcp_fsf_fsfstatus_eval(fsf_req);
426 return retval;
427}
428
429/*
430 * function: zfcp_fsf_fsfstatus_eval
431 *
432 * purpose: evaluates FSF status of completed FSF request
433 * and acts accordingly
434 *
435 * returns:
436 */
437static int
438zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
439{
440 int retval = 0;
441
442 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
443 goto skip_fsfstatus;
444 }
445
446 /* evaluate FSF Status */
447 switch (fsf_req->qtcb->header.fsf_status) {
448 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
450 "not known by the adapter %s "
451 "Stopping all operations on this adapter. "
452 "(debug info 0x%x).\n",
453 zfcp_get_busid_by_adapter(fsf_req->adapter),
454 fsf_req->qtcb->header.fsf_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
457 break;
458
459 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
461 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 break;
463
464 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
466 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
469 skip_fsfstatus:
470 /*
471 * always call specific handlers to give them a chance to do
472 * something meaningful even in error cases
473 */
474 zfcp_fsf_req_dispatch(fsf_req);
475
476 return retval;
477}
478
479/*
480 * function: zfcp_fsf_fsfstatus_qual_eval
481 *
482 * purpose: evaluates FSF status-qualifier of completed FSF request
483 * and acts accordingly
484 *
485 * returns:
486 */
487static int
488zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
489{
490 int retval = 0;
491
492 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
493 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 break;
495 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
498 break;
499 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
503 break;
504 case FSF_SQ_NO_RECOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
506 "problem on the adapter %s "
507 "Stopping all operations on this adapter. ",
508 zfcp_get_busid_by_adapter(fsf_req->adapter));
509 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
511 break;
512 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
514 "(adapter %s)\n",
515 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
517 break;
518 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
519 case FSF_SQ_NO_RETRY_POSSIBLE:
520 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
521 /* dealt with in the respective functions */
522 break;
523 default:
524 ZFCP_LOG_NORMAL("bug: Additional status info could "
525 "not be interpreted properly.\n");
526 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
527 (char *) &fsf_req->qtcb->header.fsf_status_qual,
528 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
530 break;
531 }
532
533 return retval;
534}
535
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200536/**
537 * zfcp_fsf_link_down_info_eval - evaluate link down information block
538 */
539static void
540zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
541 struct fsf_link_down_info *link_down)
542{
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100543 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
544 &adapter->status))
545 return;
546
547 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
548
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100549 if (link_down == NULL)
550 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100551
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200552 switch (link_down->error_code) {
553 case FSF_PSQ_LINK_NO_LIGHT:
554 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
555 "(no light detected)\n",
556 zfcp_get_busid_by_adapter(adapter));
557 break;
558 case FSF_PSQ_LINK_WRAP_PLUG:
559 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
560 "(wrap plug detected)\n",
561 zfcp_get_busid_by_adapter(adapter));
562 break;
563 case FSF_PSQ_LINK_NO_FCP:
564 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
565 "(adjacent node on link does not support FCP)\n",
566 zfcp_get_busid_by_adapter(adapter));
567 break;
568 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
569 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
570 "(firmware update in progress)\n",
571 zfcp_get_busid_by_adapter(adapter));
572 break;
573 case FSF_PSQ_LINK_INVALID_WWPN:
574 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
575 "(duplicate or invalid WWPN detected)\n",
576 zfcp_get_busid_by_adapter(adapter));
577 break;
578 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
579 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
580 "(no support for NPIV by Fabric)\n",
581 zfcp_get_busid_by_adapter(adapter));
582 break;
583 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(out of resource in FCP daughtercard)\n",
586 zfcp_get_busid_by_adapter(adapter));
587 break;
588 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
589 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
590 "(out of resource in Fabric)\n",
591 zfcp_get_busid_by_adapter(adapter));
592 break;
593 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
594 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
595 "(unable to Fabric login)\n",
596 zfcp_get_busid_by_adapter(adapter));
597 break;
598 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
599 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
600 zfcp_get_busid_by_adapter(adapter));
601 break;
602 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
603 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
604 zfcp_get_busid_by_adapter(adapter));
605 break;
606 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
607 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
608 zfcp_get_busid_by_adapter(adapter));
609 break;
610 default:
611 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
612 "(warning: unknown reason code %d)\n",
613 zfcp_get_busid_by_adapter(adapter),
614 link_down->error_code);
615 }
616
617 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
618 ZFCP_LOG_DEBUG("Debug information to link down: "
619 "primary_status=0x%02x "
620 "ioerr_code=0x%02x "
621 "action_code=0x%02x "
622 "reason_code=0x%02x "
623 "explanation_code=0x%02x "
624 "vendor_specific_code=0x%02x\n",
625 link_down->primary_status,
626 link_down->ioerr_code,
627 link_down->action_code,
628 link_down->reason_code,
629 link_down->explanation_code,
630 link_down->vendor_specific_code);
631
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100632 out:
633 zfcp_erp_adapter_failed(adapter);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200634}
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636/*
637 * function: zfcp_fsf_req_dispatch
638 *
639 * purpose: calls the appropriate command specific handler
640 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200641 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 */
643static int
644zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
645{
646 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
647 struct zfcp_adapter *adapter = fsf_req->adapter;
648 int retval = 0;
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 switch (fsf_req->fsf_command) {
652
653 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 zfcp_fsf_send_fcp_command_handler(fsf_req);
655 break;
656
657 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 zfcp_fsf_abort_fcp_command_handler(fsf_req);
659 break;
660
661 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 zfcp_fsf_send_ct_handler(fsf_req);
663 break;
664
665 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 zfcp_fsf_open_port_handler(fsf_req);
667 break;
668
669 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 zfcp_fsf_open_unit_handler(fsf_req);
671 break;
672
673 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 zfcp_fsf_close_unit_handler(fsf_req);
675 break;
676
677 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 zfcp_fsf_close_port_handler(fsf_req);
679 break;
680
681 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 zfcp_fsf_close_physical_port_handler(fsf_req);
683 break;
684
685 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 zfcp_fsf_exchange_config_data_handler(fsf_req);
687 break;
688
689 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 zfcp_fsf_exchange_port_data_handler(fsf_req);
691 break;
692
693 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 zfcp_fsf_send_els_handler(fsf_req);
695 break;
696
697 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 zfcp_fsf_control_file_handler(fsf_req);
699 break;
700
701 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 zfcp_fsf_control_file_handler(fsf_req);
703 break;
704
705 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
707 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
708 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200709 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
711 ZFCP_LOG_NORMAL
712 ("bug: Command issued by the device driver differs "
713 "from the command returned by the adapter %s "
714 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200715 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 fsf_req->fsf_command,
717 fsf_req->qtcb->header.fsf_command);
718 }
719
720 if (!erp_action)
721 return retval;
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 zfcp_erp_async_handler(erp_action, 0);
724
725 return retval;
726}
727
728/*
729 * function: zfcp_fsf_status_read
730 *
731 * purpose: initiates a Status Read command at the specified adapter
732 *
733 * returns:
734 */
735int
736zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
737{
738 struct zfcp_fsf_req *fsf_req;
739 struct fsf_status_read_buffer *status_buffer;
740 unsigned long lock_flags;
741 volatile struct qdio_buffer_element *sbale;
742 int retval = 0;
743
744 /* setup new FSF request */
745 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
746 req_flags | ZFCP_REQ_NO_QTCB,
747 adapter->pool.fsf_req_status_read,
748 &lock_flags, &fsf_req);
749 if (retval < 0) {
750 ZFCP_LOG_INFO("error: Could not create unsolicited status "
751 "buffer for adapter %s.\n",
752 zfcp_get_busid_by_adapter(adapter));
753 goto failed_req_create;
754 }
755
756 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
757 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
758 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
759 fsf_req->sbale_curr = 2;
760
761 status_buffer =
762 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
763 if (!status_buffer) {
764 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
765 goto failed_buf;
766 }
767 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200768 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 /* insert pointer to respective buffer */
771 sbale = zfcp_qdio_sbale_curr(fsf_req);
772 sbale->addr = (void *) status_buffer;
773 sbale->length = sizeof(struct fsf_status_read_buffer);
774
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200775 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (retval) {
777 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
778 "environment.\n");
779 goto failed_req_send;
780 }
781
782 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
783 zfcp_get_busid_by_adapter(adapter));
784 goto out;
785
786 failed_req_send:
787 mempool_free(status_buffer, adapter->pool.data_status_read);
788
789 failed_buf:
790 zfcp_fsf_req_free(fsf_req);
791 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200792 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 out:
794 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
795 return retval;
796}
797
798static int
799zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
800{
801 struct fsf_status_read_buffer *status_buffer;
802 struct zfcp_adapter *adapter;
803 struct zfcp_port *port;
804 unsigned long flags;
805
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200806 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 adapter = fsf_req->adapter;
808
809 read_lock_irqsave(&zfcp_data.config_lock, flags);
810 list_for_each_entry(port, &adapter->port_list_head, list)
811 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
812 break;
813 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
814
815 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
816 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200817 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 "adapter %s. Ignored.\n",
819 status_buffer->d_id & ZFCP_DID_MASK,
820 zfcp_get_busid_by_adapter(adapter));
821 goto out;
822 }
823
824 switch (status_buffer->status_subtype) {
825
826 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
828 zfcp_erp_port_reopen(port, 0);
829 break;
830
831 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
833 zfcp_erp_port_shutdown(port, 0);
834 break;
835
836 default:
837 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
838 debug_exception(adapter->erp_dbf, 0,
839 &status_buffer->status_subtype, sizeof (u32));
840 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
841 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200842 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 "Ignored. (debug info 0x%x)\n",
844 status_buffer->d_id,
845 zfcp_get_busid_by_adapter(adapter),
846 status_buffer->status_subtype);
847 }
848 out:
849 return 0;
850}
851
852/*
853 * function: zfcp_fsf_status_read_handler
854 *
855 * purpose: is called for finished Open Port command
856 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200857 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 */
859static int
860zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
861{
862 int retval = 0;
863 struct zfcp_adapter *adapter = fsf_req->adapter;
864 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200865 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200866 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200869 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200871 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 goto out;
873 }
874
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200875 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 switch (status_buffer->status_type) {
878
879 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 zfcp_fsf_status_read_port_closed(fsf_req);
881 break;
882
883 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 zfcp_fsf_incoming_els(fsf_req);
885 break;
886
887 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
889 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 break;
891
892 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200893 fsf_bit_error = (struct fsf_bit_error_payload *)
894 status_buffer->payload;
895 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
896 "received (adapter %s, "
897 "link failures = %i, loss of sync errors = %i, "
898 "loss of signal errors = %i, "
899 "primitive sequence errors = %i, "
900 "invalid transmission word errors = %i, "
901 "CRC errors = %i)\n",
902 zfcp_get_busid_by_adapter(adapter),
903 fsf_bit_error->link_failure_error_count,
904 fsf_bit_error->loss_of_sync_error_count,
905 fsf_bit_error->loss_of_signal_error_count,
906 fsf_bit_error->primitive_sequence_error_count,
907 fsf_bit_error->invalid_transmission_word_error_count,
908 fsf_bit_error->crc_error_count);
909 ZFCP_LOG_INFO("Additional bit error threshold data "
910 "(adapter %s, "
911 "primitive sequence event time-outs = %i, "
912 "elastic buffer overrun errors = %i, "
913 "advertised receive buffer-to-buffer credit = %i, "
914 "current receice buffer-to-buffer credit = %i, "
915 "advertised transmit buffer-to-buffer credit = %i, "
916 "current transmit buffer-to-buffer credit = %i)\n",
917 zfcp_get_busid_by_adapter(adapter),
918 fsf_bit_error->primitive_sequence_event_timeout_count,
919 fsf_bit_error->elastic_buffer_overrun_error_count,
920 fsf_bit_error->advertised_receive_b2b_credit,
921 fsf_bit_error->current_receive_b2b_credit,
922 fsf_bit_error->advertised_transmit_b2b_credit,
923 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 break;
925
926 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200927 switch (status_buffer->status_subtype) {
928 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
929 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
930 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100931 zfcp_fsf_link_down_info_eval(adapter,
932 (struct fsf_link_down_info *)
933 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200934 break;
935 case FSF_STATUS_READ_SUB_FDISC_FAILED:
936 ZFCP_LOG_INFO("Local link to adapter %s is down "
937 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100938 zfcp_get_busid_by_adapter(adapter));
939 zfcp_fsf_link_down_info_eval(adapter,
940 (struct fsf_link_down_info *)
941 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200942 break;
943 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
944 ZFCP_LOG_INFO("Local link to adapter %s is down "
945 "due to firmware update on adapter\n",
946 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100947 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200948 break;
949 default:
950 ZFCP_LOG_INFO("Local link to adapter %s is down "
951 "due to unknown reason\n",
952 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100953 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200954 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 break;
956
957 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200958 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100959 "Restarting operations on this adapter\n",
960 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 /* All ports should be marked as ready to run again */
962 zfcp_erp_modify_adapter_status(adapter,
963 ZFCP_STATUS_COMMON_RUNNING,
964 ZFCP_SET);
965 zfcp_erp_adapter_reopen(adapter,
966 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
967 | ZFCP_STATUS_COMMON_ERP_FAILED);
968 break;
969
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100970 case FSF_STATUS_READ_NOTIFICATION_LOST:
971 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
972 "adapter %s%s%s%s%s%s%s%s%s\n",
973 zfcp_get_busid_by_adapter(adapter),
974 (status_buffer->status_subtype &
975 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
976 ", incoming ELS" : "",
977 (status_buffer->status_subtype &
978 FSF_STATUS_READ_SUB_SENSE_DATA) ?
979 ", sense data" : "",
980 (status_buffer->status_subtype &
981 FSF_STATUS_READ_SUB_LINK_STATUS) ?
982 ", link status change" : "",
983 (status_buffer->status_subtype &
984 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
985 ", port close" : "",
986 (status_buffer->status_subtype &
987 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
988 ", bit error exception" : "",
989 (status_buffer->status_subtype &
990 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
991 ", ACT update" : "",
992 (status_buffer->status_subtype &
993 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
994 ", ACT hardening" : "",
995 (status_buffer->status_subtype &
996 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
997 ", adapter feature change" : "");
998
999 if (status_buffer->status_subtype &
1000 FSF_STATUS_READ_SUB_ACT_UPDATED)
1001 zfcp_erp_adapter_access_changed(adapter);
1002 break;
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001005 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 zfcp_get_busid_by_adapter(adapter));
1007 zfcp_erp_adapter_access_changed(adapter);
1008 break;
1009
1010 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 switch (status_buffer->status_subtype) {
1012 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001013 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 zfcp_get_busid_by_adapter(adapter));
1015 break;
1016 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001017 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 "to the secondary SE\n",
1019 zfcp_get_busid_by_adapter(adapter));
1020 break;
1021 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001022 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 zfcp_get_busid_by_adapter(adapter));
1024 }
1025 break;
1026
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001027 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1028 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1029 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1030 "been changed from 0x%08X to 0x%08X\n",
1031 zfcp_get_busid_by_adapter(adapter),
1032 *(u32*) (status_buffer->payload + 4),
1033 *(u32*) (status_buffer->payload));
1034 adapter->adapter_features = *(u32*) status_buffer->payload;
1035 break;
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001038 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 "type was received (debug info 0x%x)\n",
1040 status_buffer->status_type);
1041 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1042 status_buffer);
1043 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1044 (char *) status_buffer,
1045 sizeof (struct fsf_status_read_buffer));
1046 break;
1047 }
1048 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001049 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 /*
1051 * recycle buffer and start new request repeat until outbound
1052 * queue is empty or adapter shutdown is requested
1053 */
1054 /*
1055 * FIXME(qdio):
1056 * we may wait in the req_create for 5s during shutdown, so
1057 * qdio_cleanup will have to wait at least that long before returning
1058 * with failure to allow us a proper cleanup under all circumstances
1059 */
1060 /*
1061 * FIXME:
1062 * allocation failure possible? (Is this code needed?)
1063 */
1064 retval = zfcp_fsf_status_read(adapter, 0);
1065 if (retval < 0) {
1066 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1067 "request for the adapter %s.\n",
1068 zfcp_get_busid_by_adapter(adapter));
1069 /* temporary fix to avoid status read buffer shortage */
1070 adapter->status_read_failed++;
1071 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1072 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1073 ZFCP_LOG_INFO("restart adapter %s due to status read "
1074 "buffer shortage\n",
1075 zfcp_get_busid_by_adapter(adapter));
1076 zfcp_erp_adapter_reopen(adapter, 0);
1077 }
1078 }
1079 out:
1080 return retval;
1081}
1082
1083/*
1084 * function: zfcp_fsf_abort_fcp_command
1085 *
1086 * purpose: tells FSF to abort a running SCSI command
1087 *
1088 * returns: address of initiated FSF request
1089 * NULL - request could not be initiated
1090 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001091 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 * FIXME(design) shouldn't this be modified to return an int
1093 * also...don't know how though
1094 */
1095struct zfcp_fsf_req *
1096zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1097 struct zfcp_adapter *adapter,
1098 struct zfcp_unit *unit, int req_flags)
1099{
1100 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001102 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 int retval = 0;
1104
1105 /* setup new FSF request */
1106 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1107 req_flags, adapter->pool.fsf_req_abort,
1108 &lock_flags, &fsf_req);
1109 if (retval < 0) {
1110 ZFCP_LOG_INFO("error: Failed to create an abort command "
1111 "request for lun 0x%016Lx on port 0x%016Lx "
1112 "on adapter %s.\n",
1113 unit->fcp_lun,
1114 unit->port->wwpn,
1115 zfcp_get_busid_by_adapter(adapter));
1116 goto out;
1117 }
1118
Christof Schmitt951f7462007-12-20 12:30:24 +01001119 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1120 &unit->status)))
1121 goto unit_blocked;
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1124 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1125 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1126
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001127 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 /* set handles of unit and its parent port in QTCB */
1130 fsf_req->qtcb->header.lun_handle = unit->handle;
1131 fsf_req->qtcb->header.port_handle = unit->port->handle;
1132
1133 /* set handle of request which should be aborted */
1134 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1135
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001136 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1137 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +01001138 if (!retval)
1139 goto out;
1140
1141 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 zfcp_fsf_req_free(fsf_req);
1143 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 out:
1146 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1147 return fsf_req;
1148}
1149
1150/*
1151 * function: zfcp_fsf_abort_fcp_command_handler
1152 *
1153 * purpose: is called for finished Abort FCP Command request
1154 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001155 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 */
1157static int
1158zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1159{
1160 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001161 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +01001162 union fsf_status_qual *fsf_stat_qual =
1163 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1166 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1167 goto skip_fsfstatus;
1168 }
1169
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001170 unit = (struct zfcp_unit *) new_fsf_req->data;
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* evaluate FSF status in QTCB */
1173 switch (new_fsf_req->qtcb->header.fsf_status) {
1174
1175 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001176 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1178 "fsf_s_phand_nv0");
1179 /*
1180 * In this case a command that was sent prior to a port
1181 * reopen was aborted (handles are different). This is
1182 * fine.
1183 */
1184 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1186 "port 0x%016Lx on adapter %s invalid. "
1187 "This may happen occasionally.\n",
1188 unit->port->handle,
1189 unit->port->wwpn,
1190 zfcp_get_busid_by_unit(unit));
1191 ZFCP_LOG_INFO("status qualifier:\n");
1192 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1193 (char *) &new_fsf_req->qtcb->header.
1194 fsf_status_qual,
1195 sizeof (union fsf_status_qual));
1196 /* Let's hope this sorts out the mess */
1197 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1198 "fsf_s_phand_nv1");
1199 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1200 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1201 }
1202 break;
1203
1204 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001205 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1207 "fsf_s_lhand_nv0");
1208 /*
1209 * In this case a command that was sent prior to a unit
1210 * reopen was aborted (handles are different).
1211 * This is fine.
1212 */
1213 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 ZFCP_LOG_INFO
1215 ("Warning: Temporary LUN identifier 0x%x of LUN "
1216 "0x%016Lx on port 0x%016Lx on adapter %s is "
1217 "invalid. This may happen in rare cases. "
1218 "Trying to re-establish link.\n",
1219 unit->handle,
1220 unit->fcp_lun,
1221 unit->port->wwpn,
1222 zfcp_get_busid_by_unit(unit));
1223 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1224 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1225 (char *) &new_fsf_req->qtcb->header.
1226 fsf_status_qual,
1227 sizeof (union fsf_status_qual));
1228 /* Let's hope this sorts out the mess */
1229 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1230 "fsf_s_lhand_nv1");
1231 zfcp_erp_port_reopen(unit->port, 0);
1232 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1233 }
1234 break;
1235
1236 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 retval = 0;
1238 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1239 "fsf_s_no_exist");
1240 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1241 break;
1242
1243 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1245 "be reopened\n", unit->port->wwpn,
1246 zfcp_get_busid_by_unit(unit));
1247 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1248 "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001249 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1251 | ZFCP_STATUS_FSFREQ_RETRY;
1252 break;
1253
1254 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 ZFCP_LOG_INFO(
1256 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1257 "to be reopened\n",
1258 unit->fcp_lun, unit->port->wwpn,
1259 zfcp_get_busid_by_unit(unit));
1260 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001261 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1263 | ZFCP_STATUS_FSFREQ_RETRY;
1264 break;
1265
1266 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1268 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1270 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001271 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1273 break;
1274 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 /* SCSI stack will escalate */
1276 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1277 "fsf_sq_ulp");
1278 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1279 break;
1280 default:
1281 ZFCP_LOG_NORMAL
1282 ("bug: Wrong status qualifier 0x%x arrived.\n",
1283 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1284 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1285 "fsf_sq_inval:");
1286 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1287 &new_fsf_req->qtcb->header.
1288 fsf_status_qual.word[0], sizeof (u32));
1289 break;
1290 }
1291 break;
1292
1293 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 retval = 0;
1295 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1296 break;
1297
1298 default:
1299 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1300 "(debug info 0x%x)\n",
1301 new_fsf_req->qtcb->header.fsf_status);
1302 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1303 "fsf_s_inval:");
1304 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1305 &new_fsf_req->qtcb->header.fsf_status,
1306 sizeof (u32));
1307 break;
1308 }
1309 skip_fsfstatus:
1310 return retval;
1311}
1312
1313/**
1314 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1315 * one SBALE
1316 * Two scatter-gather lists are passed, one for the reqeust and one for the
1317 * response.
1318 */
1319static inline int
1320zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1321 struct scatterlist *resp, int resp_count)
1322{
1323 return ((req_count == 1) &&
1324 (resp_count == 1) &&
1325 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1326 PAGE_MASK) ==
1327 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1328 req[0].length - 1) & PAGE_MASK)) &&
1329 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1330 PAGE_MASK) ==
1331 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1332 resp[0].length - 1) & PAGE_MASK)));
1333}
1334
1335/**
1336 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1337 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1338 * the request
1339 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1340 * a struct zfcp_fsf_req
1341 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1342 * is sent within error recovery
1343 */
1344int
1345zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1346 struct zfcp_erp_action *erp_action)
1347{
1348 volatile struct qdio_buffer_element *sbale;
1349 struct zfcp_port *port;
1350 struct zfcp_adapter *adapter;
1351 struct zfcp_fsf_req *fsf_req;
1352 unsigned long lock_flags;
1353 int bytes;
1354 int ret = 0;
1355
1356 port = ct->port;
1357 adapter = port->adapter;
1358
1359 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1360 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1361 pool, &lock_flags, &fsf_req);
1362 if (ret < 0) {
1363 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1364 "adapter: %s\n",
1365 zfcp_get_busid_by_adapter(adapter));
1366 goto failed_req;
1367 }
1368
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1370 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1371 ct->resp, ct->resp_count)){
1372 /* both request buffer and response buffer
1373 fit into one sbale each */
1374 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1375 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1376 sbale[2].length = ct->req[0].length;
1377 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1378 sbale[3].length = ct->resp[0].length;
1379 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001380 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1382 /* try to use chained SBALs */
1383 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1384 SBAL_FLAGS0_TYPE_WRITE_READ,
1385 ct->req, ct->req_count,
1386 ZFCP_MAX_SBALS_PER_CT_REQ);
1387 if (bytes <= 0) {
1388 ZFCP_LOG_INFO("error: creation of CT request failed "
1389 "on adapter %s\n",
1390 zfcp_get_busid_by_adapter(adapter));
1391 if (bytes == 0)
1392 ret = -ENOMEM;
1393 else
1394 ret = bytes;
1395
1396 goto failed_send;
1397 }
1398 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1399 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1400 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1401 SBAL_FLAGS0_TYPE_WRITE_READ,
1402 ct->resp, ct->resp_count,
1403 ZFCP_MAX_SBALS_PER_CT_REQ);
1404 if (bytes <= 0) {
1405 ZFCP_LOG_INFO("error: creation of CT request failed "
1406 "on adapter %s\n",
1407 zfcp_get_busid_by_adapter(adapter));
1408 if (bytes == 0)
1409 ret = -ENOMEM;
1410 else
1411 ret = bytes;
1412
1413 goto failed_send;
1414 }
1415 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1416 } else {
1417 /* reject send generic request */
1418 ZFCP_LOG_INFO(
1419 "error: microcode does not support chained SBALs,"
1420 "CT request too big (adapter %s)\n",
1421 zfcp_get_busid_by_adapter(adapter));
1422 ret = -EOPNOTSUPP;
1423 goto failed_send;
1424 }
1425
1426 /* settings in QTCB */
1427 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001428 fsf_req->qtcb->bottom.support.service_class =
1429 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001431 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001433 zfcp_san_dbf_event_ct_request(fsf_req);
1434
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001435 if (erp_action) {
1436 erp_action->fsf_req = fsf_req;
1437 fsf_req->erp_action = erp_action;
1438 zfcp_erp_start_timer(fsf_req);
1439 } else
1440 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1441
1442 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 if (ret) {
1444 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1445 "(adapter %s, port 0x%016Lx)\n",
1446 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1447 goto failed_send;
1448 }
1449
1450 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1451 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1452 goto out;
1453
1454 failed_send:
1455 zfcp_fsf_req_free(fsf_req);
1456 if (erp_action != NULL) {
1457 erp_action->fsf_req = NULL;
1458 }
1459 failed_req:
1460 out:
1461 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1462 lock_flags);
1463 return ret;
1464}
1465
1466/**
1467 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1468 * @fsf_req: pointer to struct zfcp_fsf_req
1469 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001470 * Data specific for the Generic Service request is passed using
1471 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1472 * Usually a specific handler for the CT request is called which is
1473 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 */
1475static int
1476zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1477{
1478 struct zfcp_port *port;
1479 struct zfcp_adapter *adapter;
1480 struct zfcp_send_ct *send_ct;
1481 struct fsf_qtcb_header *header;
1482 struct fsf_qtcb_bottom_support *bottom;
1483 int retval = -EINVAL;
1484 u16 subtable, rule, counter;
1485
1486 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001487 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 port = send_ct->port;
1489 header = &fsf_req->qtcb->header;
1490 bottom = &fsf_req->qtcb->bottom.support;
1491
1492 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1493 goto skip_fsfstatus;
1494
1495 /* evaluate FSF status in QTCB */
1496 switch (header->fsf_status) {
1497
1498 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001499 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 retval = 0;
1501 break;
1502
1503 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001504 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1505 "class %d.\n",
1506 zfcp_get_busid_by_port(port),
1507 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 /* stop operation for this adapter */
1509 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1510 zfcp_erp_adapter_shutdown(adapter, 0);
1511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1512 break;
1513
1514 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 switch (header->fsf_status_qual.word[0]){
1516 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 /* reopening link to port */
1518 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1519 zfcp_test_link(port);
1520 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1521 break;
1522 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 /* ERP strategy will escalate */
1524 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1526 break;
1527 default:
1528 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1529 "arrived.\n",
1530 header->fsf_status_qual.word[0]);
1531 break;
1532 }
1533 break;
1534
1535 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001537 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 zfcp_get_busid_by_port(port), port->d_id);
1539 for (counter = 0; counter < 2; counter++) {
1540 subtable = header->fsf_status_qual.halfword[counter * 2];
1541 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1542 switch (subtable) {
1543 case FSF_SQ_CFDC_SUBTABLE_OS:
1544 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1545 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1546 case FSF_SQ_CFDC_SUBTABLE_LUN:
1547 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1548 zfcp_act_subtable_type[subtable], rule);
1549 break;
1550 }
1551 }
1552 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1553 zfcp_erp_port_access_denied(port);
1554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1555 break;
1556
1557 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001559 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 zfcp_get_busid_by_port(port), port->d_id);
1561 ZFCP_LOG_INFO("status qualifier:\n");
1562 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1563 (char *) &header->fsf_status_qual,
1564 sizeof (union fsf_status_qual));
1565 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1566 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1567 break;
1568
1569 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1571 "0x%016Lx on adapter %s invalid. This may "
1572 "happen occasionally.\n", port->handle,
1573 port->wwpn, zfcp_get_busid_by_port(port));
1574 ZFCP_LOG_INFO("status qualifier:\n");
1575 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1576 (char *) &header->fsf_status_qual,
1577 sizeof (union fsf_status_qual));
1578 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1579 zfcp_erp_adapter_reopen(adapter, 0);
1580 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1581 break;
1582
1583 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001585 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 zfcp_get_busid_by_port(port), port->d_id);
1587 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02001588 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1590 | ZFCP_STATUS_FSFREQ_RETRY;
1591 break;
1592
1593 /* following states should never occure, all cases avoided
1594 in zfcp_fsf_send_ct - but who knows ... */
1595 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1597 "req_buf_length=%d, resp_buf_length=%d)\n",
1598 zfcp_get_busid_by_adapter(adapter),
1599 bottom->req_buf_length, bottom->resp_buf_length);
1600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1601 break;
1602 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1604 "req_buf_length=%d)\n",
1605 zfcp_get_busid_by_adapter(adapter),
1606 bottom->req_buf_length);
1607 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1608 break;
1609 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1611 "resp_buf_length=%d)\n",
1612 zfcp_get_busid_by_adapter(adapter),
1613 bottom->resp_buf_length);
1614 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1615 break;
1616 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1618 "resp_buf_length=%d)\n",
1619 zfcp_get_busid_by_adapter(adapter),
1620 bottom->req_buf_length, bottom->resp_buf_length);
1621 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1622 break;
1623
1624 default:
1625 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1626 "(debug info 0x%x)\n", header->fsf_status);
1627 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1628 debug_exception(adapter->erp_dbf, 0,
1629 &header->fsf_status_qual.word[0], sizeof (u32));
1630 break;
1631 }
1632
1633skip_fsfstatus:
1634 send_ct->status = retval;
1635
1636 if (send_ct->handler != NULL)
1637 send_ct->handler(send_ct->handler_data);
1638
1639 return retval;
1640}
1641
1642/**
1643 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1644 * @els: pointer to struct zfcp_send_els which contains all needed data for
1645 * the command.
1646 */
1647int
1648zfcp_fsf_send_els(struct zfcp_send_els *els)
1649{
1650 volatile struct qdio_buffer_element *sbale;
1651 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001652 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 struct zfcp_adapter *adapter;
1654 unsigned long lock_flags;
1655 int bytes;
1656 int ret = 0;
1657
1658 d_id = els->d_id;
1659 adapter = els->adapter;
1660
1661 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1662 ZFCP_REQ_AUTO_CLEANUP,
1663 NULL, &lock_flags, &fsf_req);
1664 if (ret < 0) {
1665 ZFCP_LOG_INFO("error: creation 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_req;
1669 }
1670
1671 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1672 if (zfcp_use_one_sbal(els->req, els->req_count,
1673 els->resp, els->resp_count)){
1674 /* both request buffer and response buffer
1675 fit into one sbale each */
1676 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1677 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1678 sbale[2].length = els->req[0].length;
1679 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1680 sbale[3].length = els->resp[0].length;
1681 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001682 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1684 /* try to use chained SBALs */
1685 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1686 SBAL_FLAGS0_TYPE_WRITE_READ,
1687 els->req, els->req_count,
1688 ZFCP_MAX_SBALS_PER_ELS_REQ);
1689 if (bytes <= 0) {
1690 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001691 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 zfcp_get_busid_by_adapter(adapter), d_id);
1693 if (bytes == 0) {
1694 ret = -ENOMEM;
1695 } else {
1696 ret = bytes;
1697 }
1698 goto failed_send;
1699 }
1700 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1701 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1702 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1703 SBAL_FLAGS0_TYPE_WRITE_READ,
1704 els->resp, els->resp_count,
1705 ZFCP_MAX_SBALS_PER_ELS_REQ);
1706 if (bytes <= 0) {
1707 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001708 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 zfcp_get_busid_by_adapter(adapter), d_id);
1710 if (bytes == 0) {
1711 ret = -ENOMEM;
1712 } else {
1713 ret = bytes;
1714 }
1715 goto failed_send;
1716 }
1717 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1718 } else {
1719 /* reject request */
1720 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1721 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001722 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 zfcp_get_busid_by_adapter(adapter), d_id);
1724 ret = -EOPNOTSUPP;
1725 goto failed_send;
1726 }
1727
1728 /* settings in QTCB */
1729 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001730 fsf_req->qtcb->bottom.support.service_class =
1731 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001733 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1736
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001737 zfcp_san_dbf_event_els_request(fsf_req);
1738
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001739 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1740 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 if (ret) {
1742 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001743 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 zfcp_get_busid_by_adapter(adapter), d_id);
1745 goto failed_send;
1746 }
1747
1748 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001749 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 goto out;
1751
1752 failed_send:
1753 zfcp_fsf_req_free(fsf_req);
1754
1755 failed_req:
1756 out:
1757 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1758 lock_flags);
1759
1760 return ret;
1761}
1762
1763/**
1764 * zfcp_fsf_send_els_handler - handler for ELS commands
1765 * @fsf_req: pointer to struct zfcp_fsf_req
1766 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001767 * Data specific for the ELS command is passed using
1768 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1769 * Usually a specific handler for the ELS command is called which is
1770 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 */
1772static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1773{
1774 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001776 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 struct fsf_qtcb_header *header;
1778 struct fsf_qtcb_bottom_support *bottom;
1779 struct zfcp_send_els *send_els;
1780 int retval = -EINVAL;
1781 u16 subtable, rule, counter;
1782
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001783 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001785 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 d_id = send_els->d_id;
1787 header = &fsf_req->qtcb->header;
1788 bottom = &fsf_req->qtcb->bottom.support;
1789
1790 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1791 goto skip_fsfstatus;
1792
1793 switch (header->fsf_status) {
1794
1795 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001796 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 retval = 0;
1798 break;
1799
1800 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001801 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1802 "class %d.\n",
1803 zfcp_get_busid_by_adapter(adapter),
1804 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 /* stop operation for this adapter */
1806 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1807 zfcp_erp_adapter_shutdown(adapter, 0);
1808 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1809 break;
1810
1811 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 switch (header->fsf_status_qual.word[0]){
1813 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001815 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1816 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1818 break;
1819 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1821 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1822 retval =
1823 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1824 (struct zfcp_ls_rjt_par *)
1825 &header->fsf_status_qual.word[2]);
1826 break;
1827 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1830 break;
1831 default:
1832 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1833 header->fsf_status_qual.word[0]);
1834 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1835 (char*)header->fsf_status_qual.word, 16);
1836 }
1837 break;
1838
1839 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1841 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001842 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 zfcp_get_busid_by_adapter(adapter), d_id);
1844
1845 break;
1846
1847 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 ZFCP_LOG_INFO(
1849 "ELS request size and ELS response size must be either "
1850 "both 0, or both greater than 0 "
1851 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1852 zfcp_get_busid_by_adapter(adapter),
1853 bottom->req_buf_length,
1854 bottom->resp_buf_length);
1855 break;
1856
1857 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 ZFCP_LOG_INFO(
1859 "Length of the ELS request buffer, "
1860 "specified in QTCB bottom, "
1861 "exceeds the size of the buffers "
1862 "that have been allocated for ELS request data "
1863 "(adapter: %s, req_buf_length=%d)\n",
1864 zfcp_get_busid_by_adapter(adapter),
1865 bottom->req_buf_length);
1866 break;
1867
1868 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 ZFCP_LOG_INFO(
1870 "Length of the ELS response buffer, "
1871 "specified in QTCB bottom, "
1872 "exceeds the size of the buffers "
1873 "that have been allocated for ELS response data "
1874 "(adapter: %s, resp_buf_length=%d)\n",
1875 zfcp_get_busid_by_adapter(adapter),
1876 bottom->resp_buf_length);
1877 break;
1878
1879 case FSF_SBAL_MISMATCH:
1880 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1882 "resp_buf_length=%d)\n",
1883 zfcp_get_busid_by_adapter(adapter),
1884 bottom->req_buf_length, bottom->resp_buf_length);
1885 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1886 break;
1887
1888 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001890 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 zfcp_get_busid_by_adapter(adapter), d_id);
1892 for (counter = 0; counter < 2; counter++) {
1893 subtable = header->fsf_status_qual.halfword[counter * 2];
1894 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1895 switch (subtable) {
1896 case FSF_SQ_CFDC_SUBTABLE_OS:
1897 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1898 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1899 case FSF_SQ_CFDC_SUBTABLE_LUN:
1900 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1901 zfcp_act_subtable_type[subtable], rule);
1902 break;
1903 }
1904 }
1905 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 if (port != NULL)
1907 zfcp_erp_port_access_denied(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1909 break;
1910
1911 default:
1912 ZFCP_LOG_NORMAL(
1913 "bug: An unknown FSF Status was presented "
1914 "(adapter: %s, fsf_status=0x%08x)\n",
1915 zfcp_get_busid_by_adapter(adapter),
1916 header->fsf_status);
1917 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1918 debug_exception(adapter->erp_dbf, 0,
1919 &header->fsf_status_qual.word[0], sizeof(u32));
1920 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1921 break;
1922 }
1923
1924skip_fsfstatus:
1925 send_els->status = retval;
1926
Heiko Carstensaa551da2007-07-18 10:55:10 +02001927 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 send_els->handler(send_els->handler_data);
1929
1930 return retval;
1931}
1932
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933int
1934zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1935{
1936 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001937 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001938 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001940 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
1942 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001943 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1945 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001946 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001947 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001948 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1950 "data request for adapter %s.\n",
Swen Schillig52ef11a2007-08-28 09:31:09 +02001951 zfcp_get_busid_by_adapter(adapter));
1952 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1953 lock_flags);
1954 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 }
1956
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001957 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001958 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1959 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001961 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001962 FSF_FEATURE_CFDC |
1963 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001964 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001965 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001966 fsf_req->erp_action = erp_action;
1967 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001969 zfcp_erp_start_timer(fsf_req);
1970 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001971 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1972 lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001974 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1975 "data command on the adapter %s\n",
1976 zfcp_get_busid_by_adapter(adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001977 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001979 }
1980 else
1981 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1982 "(adapter %s)\n",
1983 zfcp_get_busid_by_adapter(adapter));
1984
1985 return retval;
1986}
1987
1988int
1989zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1990 struct fsf_qtcb_bottom_config *data)
1991{
1992 volatile struct qdio_buffer_element *sbale;
1993 struct zfcp_fsf_req *fsf_req;
1994 unsigned long lock_flags;
1995 int retval;
1996
1997 /* setup new FSF request */
1998 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1999 0, NULL, &lock_flags, &fsf_req);
2000 if (retval) {
2001 ZFCP_LOG_INFO("error: Could not create exchange configuration "
2002 "data request for adapter %s.\n",
2003 zfcp_get_busid_by_adapter(adapter));
2004 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2005 lock_flags);
2006 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 }
2008
Swen Schillig52ef11a2007-08-28 09:31:09 +02002009 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2010 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2011 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Swen Schillig52ef11a2007-08-28 09:31:09 +02002013 fsf_req->qtcb->bottom.config.feature_selection =
2014 FSF_FEATURE_CFDC |
2015 FSF_FEATURE_LUN_SHARING |
2016 FSF_FEATURE_NOTIFICATION_LOST |
2017 FSF_FEATURE_UPDATE_ALERT;
2018
2019 if (data)
2020 fsf_req->data = (unsigned long) data;
2021
2022 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2023 retval = zfcp_fsf_req_send(fsf_req);
2024 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002026 if (retval)
2027 ZFCP_LOG_INFO("error: Could not send exchange configuration "
2028 "data command on the adapter %s\n",
2029 zfcp_get_busid_by_adapter(adapter));
2030 else
2031 wait_event(fsf_req->completion_wq,
2032 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2033
2034 zfcp_fsf_req_free(fsf_req);
2035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 return retval;
2037}
2038
2039/**
2040 * zfcp_fsf_exchange_config_evaluate
2041 * @fsf_req: fsf_req which belongs to xchg config data request
2042 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2043 *
2044 * returns: -EIO on error, 0 otherwise
2045 */
2046static int
2047zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2048{
2049 struct fsf_qtcb_bottom_config *bottom;
2050 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002051 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
2053 bottom = &fsf_req->qtcb->bottom.config;
2054 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2055 bottom->low_qtcb_version, bottom->high_qtcb_version);
2056 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002057 adapter->adapter_features = bottom->adapter_features;
2058 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05002059 adapter->peer_wwpn = 0;
2060 adapter->peer_wwnn = 0;
2061 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02002064
2065 if (fsf_req->data)
2066 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
2067 bottom, sizeof (struct fsf_qtcb_bottom_config));
2068
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002069 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2070 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2071 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2072 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002073 fc_host_supported_classes(shost) =
2074 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002076 if (fc_host_permanent_port_name(shost) == -1)
2077 fc_host_permanent_port_name(shost) =
2078 fc_host_port_name(shost);
2079 if (bottom->fc_topology == FSF_TOPO_P2P) {
2080 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2081 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2082 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2083 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2084 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2085 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2086 else if (bottom->fc_topology == FSF_TOPO_AL)
2087 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2088 else
2089 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002091 fc_host_node_name(shost) = 0;
2092 fc_host_port_name(shost) = 0;
2093 fc_host_port_id(shost) = 0;
2094 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002095 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 adapter->hydra_version = 0;
2097 }
2098
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002099 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002101 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2102 min(FC_SERIAL_NUMBER_SIZE, 17));
2103 EBCASC(fc_host_serial_number(shost),
2104 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 }
2106
Swen Schillig52ef11a2007-08-28 09:31:09 +02002107 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2108 "characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002109 "WWNN 0x%016Lx, "
2110 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002111 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002112 "adapter version 0x%x, "
2113 "LIC version 0x%x, "
2114 "FC link speed %d Gb/s\n",
2115 zfcp_get_busid_by_adapter(adapter),
2116 (wwn_t) fc_host_node_name(shost),
2117 (wwn_t) fc_host_port_name(shost),
2118 fc_host_port_id(shost),
2119 adapter->hydra_version,
2120 adapter->fsf_lic_version,
2121 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2123 ZFCP_LOG_NORMAL("error: the adapter %s "
2124 "only supports newer control block "
2125 "versions in comparison to this device "
2126 "driver (try updated device driver)\n",
2127 zfcp_get_busid_by_adapter(adapter));
2128 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2129 zfcp_erp_adapter_shutdown(adapter, 0);
2130 return -EIO;
2131 }
2132 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2133 ZFCP_LOG_NORMAL("error: the adapter %s "
2134 "only supports older control block "
2135 "versions than this device driver uses"
2136 "(consider a microcode upgrade)\n",
2137 zfcp_get_busid_by_adapter(adapter));
2138 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2139 zfcp_erp_adapter_shutdown(adapter, 0);
2140 return -EIO;
2141 }
2142 return 0;
2143}
2144
Swen Schillig52ef11a2007-08-28 09:31:09 +02002145/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 * function: zfcp_fsf_exchange_config_data_handler
2147 *
2148 * purpose: is called for finished Exchange Configuration Data command
2149 *
2150 * returns:
2151 */
2152static int
2153zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2154{
2155 struct fsf_qtcb_bottom_config *bottom;
2156 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002157 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2160 return -EIO;
2161
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002162 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2166 return -EIO;
2167
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002168 switch (fc_host_port_type(adapter->scsi_host)) {
2169 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002170 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2171 "configuration detected at adapter %s\n"
2172 "Peer WWNN 0x%016llx, "
2173 "peer WWPN 0x%016llx, "
2174 "peer d_id 0x%06x\n",
2175 zfcp_get_busid_by_adapter(adapter),
2176 adapter->peer_wwnn,
2177 adapter->peer_wwpn,
2178 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 debug_text_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002180 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002181 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002182 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2184 "topology detected at adapter %s "
2185 "unsupported, shutting down adapter\n",
2186 zfcp_get_busid_by_adapter(adapter));
2187 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2188 "top-al");
2189 zfcp_erp_adapter_shutdown(adapter, 0);
2190 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002191 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002192 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002193 "network detected at adapter %s.\n",
2194 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 break;
2196 default:
2197 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2198 "reported by the exchange "
2199 "configuration command for "
2200 "the adapter %s is not "
2201 "of a type known to the zfcp "
2202 "driver, shutting down adapter\n",
2203 zfcp_get_busid_by_adapter(adapter));
2204 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2205 "unknown-topo");
2206 zfcp_erp_adapter_shutdown(adapter, 0);
2207 return -EIO;
2208 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002209 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2211 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2212 "allowed by the adapter %s "
2213 "is lower than the minimum "
2214 "required by the driver (%ld bytes).\n",
2215 bottom->max_qtcb_size,
2216 zfcp_get_busid_by_adapter(adapter),
2217 sizeof(struct fsf_qtcb));
2218 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2219 "qtcb-size");
2220 debug_event(fsf_req->adapter->erp_dbf, 0,
2221 &bottom->max_qtcb_size, sizeof (u32));
2222 zfcp_erp_adapter_shutdown(adapter, 0);
2223 return -EIO;
2224 }
2225 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2226 &adapter->status);
2227 break;
2228 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2229 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2230
2231 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2232 return -EIO;
2233
Swen Schillig52ef11a2007-08-28 09:31:09 +02002234 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2235 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002236
2237 zfcp_fsf_link_down_info_eval(adapter,
2238 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 break;
2240 default:
2241 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2242 debug_event(fsf_req->adapter->erp_dbf, 0,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002243 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 zfcp_erp_adapter_shutdown(adapter, 0);
2245 return -EIO;
2246 }
2247 return 0;
2248}
2249
2250/**
2251 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002252 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 */
2254int
Swen Schillig52ef11a2007-08-28 09:31:09 +02002255zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
2257 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002258 struct zfcp_fsf_req *fsf_req;
2259 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002260 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002261 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002263 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 ZFCP_LOG_INFO("error: exchange port data "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002265 "command not supported by adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 zfcp_get_busid_by_adapter(adapter));
Swen Schillig52ef11a2007-08-28 09:31:09 +02002267 return -EOPNOTSUPP;
2268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 /* setup new FSF request */
2271 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02002272 ZFCP_REQ_AUTO_CLEANUP,
2273 adapter->pool.fsf_req_erp,
2274 &lock_flags, &fsf_req);
2275 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
Swen Schillig52ef11a2007-08-28 09:31:09 +02002277 "exchange port data request for"
2278 "the adapter %s.\n",
2279 zfcp_get_busid_by_adapter(adapter));
2280 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2281 lock_flags);
2282 return retval;
2283 }
2284
2285 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2286 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2287 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2288
2289 erp_action->fsf_req = fsf_req;
2290 fsf_req->erp_action = erp_action;
2291 zfcp_erp_start_timer(fsf_req);
2292
2293 retval = zfcp_fsf_req_send(fsf_req);
2294 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2295
2296 if (retval) {
2297 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2298 "command on the adapter %s\n",
2299 zfcp_get_busid_by_adapter(adapter));
2300 zfcp_fsf_req_free(fsf_req);
2301 erp_action->fsf_req = NULL;
2302 }
2303 else
2304 ZFCP_LOG_DEBUG("exchange port data request initiated "
2305 "(adapter %s)\n",
2306 zfcp_get_busid_by_adapter(adapter));
2307 return retval;
2308}
2309
2310
2311/**
2312 * zfcp_fsf_exchange_port_data_sync - request information about local port
2313 * and wait until information is ready
2314 */
2315int
2316zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2317 struct fsf_qtcb_bottom_port *data)
2318{
2319 volatile struct qdio_buffer_element *sbale;
2320 struct zfcp_fsf_req *fsf_req;
2321 unsigned long lock_flags;
2322 int retval;
2323
2324 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2325 ZFCP_LOG_INFO("error: exchange port data "
2326 "command not supported by adapter %s\n",
2327 zfcp_get_busid_by_adapter(adapter));
2328 return -EOPNOTSUPP;
2329 }
2330
2331 /* setup new FSF request */
2332 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2333 0, NULL, &lock_flags, &fsf_req);
2334 if (retval) {
2335 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2336 "exchange port data request for"
2337 "the adapter %s.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 zfcp_get_busid_by_adapter(adapter));
2339 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2340 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002341 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002342 }
2343
2344 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002345 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002348 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2349 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Swen Schillig52ef11a2007-08-28 09:31:09 +02002351 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002352 retval = zfcp_fsf_req_send(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002353 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Swen Schillig52ef11a2007-08-28 09:31:09 +02002355 if (retval)
2356 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2357 "command on the adapter %s\n",
2358 zfcp_get_busid_by_adapter(adapter));
2359 else
Andreas Herrmann2448c452005-12-01 02:50:36 +01002360 wait_event(fsf_req->completion_wq,
2361 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02002362
2363 zfcp_fsf_req_free(fsf_req);
2364
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 return retval;
2366}
2367
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002368/**
2369 * zfcp_fsf_exchange_port_evaluate
2370 * @fsf_req: fsf_req which belongs to xchg port data request
2371 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2372 */
2373static void
2374zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2375{
2376 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002377 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002378 struct Scsi_Host *shost;
2379
2380 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02002381 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002382 shost = adapter->scsi_host;
2383
Swen Schillig52ef11a2007-08-28 09:31:09 +02002384 if (fsf_req->data)
2385 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2386 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002387
2388 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2389 fc_host_permanent_port_name(shost) = bottom->wwpn;
2390 else
2391 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2392 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2393 fc_host_supported_speeds(shost) = bottom->supported_speed;
2394}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
2396/**
2397 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2398 * @fsf_req: pointer to struct zfcp_fsf_req
2399 */
2400static void
2401zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2402{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002403 struct zfcp_adapter *adapter;
2404 struct fsf_qtcb *qtcb;
2405
2406 adapter = fsf_req->adapter;
2407 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
2409 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2410 return;
2411
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002412 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002414 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002415 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002416 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002417 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002418 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002419 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002420 zfcp_fsf_link_down_info_eval(adapter,
2421 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002424 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2425 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2427 }
2428}
2429
2430
2431/*
2432 * function: zfcp_fsf_open_port
2433 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002434 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 *
2436 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002437 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 */
2439int
2440zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2441{
2442 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002443 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 unsigned long lock_flags;
2445 int retval = 0;
2446
2447 /* setup new FSF request */
2448 retval = zfcp_fsf_req_create(erp_action->adapter,
2449 FSF_QTCB_OPEN_PORT_WITH_DID,
2450 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2451 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002452 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 if (retval < 0) {
2454 ZFCP_LOG_INFO("error: Could not create open port request "
2455 "for port 0x%016Lx on adapter %s.\n",
2456 erp_action->port->wwpn,
2457 zfcp_get_busid_by_adapter(erp_action->adapter));
2458 goto out;
2459 }
2460
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002461 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2463 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2464
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002465 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002467 fsf_req->data = (unsigned long) erp_action->port;
2468 fsf_req->erp_action = erp_action;
2469 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002471 zfcp_erp_start_timer(fsf_req);
2472 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 if (retval) {
2474 ZFCP_LOG_INFO("error: Could not send open port request for "
2475 "port 0x%016Lx on adapter %s.\n",
2476 erp_action->port->wwpn,
2477 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002478 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 erp_action->fsf_req = NULL;
2480 goto out;
2481 }
2482
2483 ZFCP_LOG_DEBUG("open port request initiated "
2484 "(adapter %s, port 0x%016Lx)\n",
2485 zfcp_get_busid_by_adapter(erp_action->adapter),
2486 erp_action->port->wwpn);
2487 out:
2488 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2489 lock_flags);
2490 return retval;
2491}
2492
2493/*
2494 * function: zfcp_fsf_open_port_handler
2495 *
2496 * purpose: is called for finished Open Port command
2497 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002498 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 */
2500static int
2501zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2502{
2503 int retval = -EINVAL;
2504 struct zfcp_port *port;
2505 struct fsf_plogi *plogi;
2506 struct fsf_qtcb_header *header;
2507 u16 subtable, rule, counter;
2508
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002509 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 header = &fsf_req->qtcb->header;
2511
2512 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2513 /* don't change port status in our bookkeeping */
2514 goto skip_fsfstatus;
2515 }
2516
2517 /* evaluate FSF status in QTCB */
2518 switch (header->fsf_status) {
2519
2520 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2522 "is already open.\n",
2523 port->wwpn, zfcp_get_busid_by_port(port));
2524 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2525 "fsf_s_popen");
2526 /*
2527 * This is a bug, however operation should continue normally
2528 * if it is simply ignored
2529 */
2530 break;
2531
2532 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2534 "on adapter %s\n",
2535 port->wwpn, zfcp_get_busid_by_port(port));
2536 for (counter = 0; counter < 2; counter++) {
2537 subtable = header->fsf_status_qual.halfword[counter * 2];
2538 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2539 switch (subtable) {
2540 case FSF_SQ_CFDC_SUBTABLE_OS:
2541 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2542 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2543 case FSF_SQ_CFDC_SUBTABLE_LUN:
2544 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2545 zfcp_act_subtable_type[subtable], rule);
2546 break;
2547 }
2548 }
2549 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2550 zfcp_erp_port_access_denied(port);
2551 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2552 break;
2553
2554 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2556 "The remote port 0x%016Lx on adapter %s "
2557 "could not be opened. Disabling it.\n",
2558 port->wwpn, zfcp_get_busid_by_port(port));
2559 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2560 "fsf_s_max_ports");
2561 zfcp_erp_port_failed(port);
2562 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2563 break;
2564
2565 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 switch (header->fsf_status_qual.word[0]) {
2567 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2569 "fsf_sq_ltest");
2570 /* ERP strategy will escalate */
2571 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2572 break;
2573 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2574 /* ERP strategy will escalate */
2575 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2576 "fsf_sq_ulp");
2577 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2578 break;
2579 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2581 "adapter %s could not be opened. "
2582 "Disabling it.\n",
2583 port->wwpn,
2584 zfcp_get_busid_by_port(port));
2585 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2586 "fsf_sq_no_retry");
2587 zfcp_erp_port_failed(port);
2588 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2589 break;
2590 default:
2591 ZFCP_LOG_NORMAL
2592 ("bug: Wrong status qualifier 0x%x arrived.\n",
2593 header->fsf_status_qual.word[0]);
2594 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2595 "fsf_sq_inval:");
2596 debug_exception(
2597 fsf_req->adapter->erp_dbf, 0,
2598 &header->fsf_status_qual.word[0],
2599 sizeof (u32));
2600 break;
2601 }
2602 break;
2603
2604 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 /* save port handle assigned by FSF */
2606 port->handle = header->port_handle;
2607 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2608 "was opened, it's port handle is 0x%x\n",
2609 port->wwpn, zfcp_get_busid_by_port(port),
2610 port->handle);
2611 /* mark port as open */
2612 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2613 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002614 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2615 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2616 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 retval = 0;
2618 /* check whether D_ID has changed during open */
2619 /*
2620 * FIXME: This check is not airtight, as the FCP channel does
2621 * not monitor closures of target port connections caused on
2622 * the remote side. Thus, they might miss out on invalidating
2623 * locally cached WWPNs (and other N_Port parameters) of gone
2624 * target ports. So, our heroic attempt to make things safe
2625 * could be undermined by 'open port' response data tagged with
2626 * obsolete WWPNs. Another reason to monitor potential
2627 * connection closures ourself at least (by interpreting
2628 * incoming ELS' and unsolicited status). It just crosses my
2629 * mind that one should be able to cross-check by means of
2630 * another GID_PN straight after a port has been opened.
2631 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2632 */
2633 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2634 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2635 {
2636 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002637 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 ZFCP_LOG_INFO(
2639 "warning: insufficient length of "
2640 "PLOGI payload (%i)\n",
2641 fsf_req->qtcb->bottom.support.els1_length);
2642 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2643 "fsf_s_short_plogi:");
2644 /* skip sanity check and assume wwpn is ok */
2645 } else {
2646 if (plogi->serv_param.wwpn != port->wwpn) {
2647 ZFCP_LOG_INFO("warning: d_id of port "
2648 "0x%016Lx changed during "
2649 "open\n", port->wwpn);
2650 debug_text_event(
2651 fsf_req->adapter->erp_dbf, 0,
2652 "fsf_s_did_change:");
2653 atomic_clear_mask(
2654 ZFCP_STATUS_PORT_DID_DID,
2655 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002656 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002658 zfcp_plogi_evaluate(port, plogi);
2659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
2661 }
2662 break;
2663
2664 case FSF_UNKNOWN_OP_SUBTYPE:
2665 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2667 "op_subtype=0x%x)\n",
2668 zfcp_get_busid_by_port(port),
2669 fsf_req->qtcb->bottom.support.operation_subtype);
2670 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2671 break;
2672
2673 default:
2674 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2675 "(debug info 0x%x)\n",
2676 header->fsf_status);
2677 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2678 debug_exception(fsf_req->adapter->erp_dbf, 0,
2679 &header->fsf_status, sizeof (u32));
2680 break;
2681 }
2682
2683 skip_fsfstatus:
2684 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2685 return retval;
2686}
2687
2688/*
2689 * function: zfcp_fsf_close_port
2690 *
2691 * purpose: submit FSF command "close port"
2692 *
2693 * returns: address of initiated FSF request
2694 * NULL - request could not be initiated
2695 */
2696int
2697zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2698{
2699 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002700 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 unsigned long lock_flags;
2702 int retval = 0;
2703
2704 /* setup new FSF request */
2705 retval = zfcp_fsf_req_create(erp_action->adapter,
2706 FSF_QTCB_CLOSE_PORT,
2707 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2708 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002709 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 if (retval < 0) {
2711 ZFCP_LOG_INFO("error: Could not create a close port request "
2712 "for port 0x%016Lx on adapter %s.\n",
2713 erp_action->port->wwpn,
2714 zfcp_get_busid_by_adapter(erp_action->adapter));
2715 goto out;
2716 }
2717
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002718 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2720 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2721
2722 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002723 fsf_req->data = (unsigned long) erp_action->port;
2724 fsf_req->erp_action = erp_action;
2725 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2726 fsf_req->erp_action = erp_action;
2727 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002729 zfcp_erp_start_timer(fsf_req);
2730 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 if (retval) {
2732 ZFCP_LOG_INFO("error: Could not send a close port request for "
2733 "port 0x%016Lx on adapter %s.\n",
2734 erp_action->port->wwpn,
2735 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002736 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 erp_action->fsf_req = NULL;
2738 goto out;
2739 }
2740
2741 ZFCP_LOG_TRACE("close port request initiated "
2742 "(adapter %s, port 0x%016Lx)\n",
2743 zfcp_get_busid_by_adapter(erp_action->adapter),
2744 erp_action->port->wwpn);
2745 out:
2746 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2747 lock_flags);
2748 return retval;
2749}
2750
2751/*
2752 * function: zfcp_fsf_close_port_handler
2753 *
2754 * purpose: is called for finished Close Port FSF command
2755 *
2756 * returns:
2757 */
2758static int
2759zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2760{
2761 int retval = -EINVAL;
2762 struct zfcp_port *port;
2763
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002764 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765
2766 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2767 /* don't change port status in our bookkeeping */
2768 goto skip_fsfstatus;
2769 }
2770
2771 /* evaluate FSF status in QTCB */
2772 switch (fsf_req->qtcb->header.fsf_status) {
2773
2774 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2776 "0x%016Lx on adapter %s invalid. This may happen "
2777 "occasionally.\n", port->handle,
2778 port->wwpn, zfcp_get_busid_by_port(port));
2779 ZFCP_LOG_DEBUG("status qualifier:\n");
2780 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2781 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2782 sizeof (union fsf_status_qual));
2783 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2784 "fsf_s_phand_nv");
2785 zfcp_erp_adapter_reopen(port->adapter, 0);
2786 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2787 break;
2788
2789 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 /* Note: FSF has actually closed the port in this case.
2791 * The status code is just daft. Fingers crossed for a change
2792 */
2793 retval = 0;
2794 break;
2795
2796 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2798 "port handle 0x%x\n", port->wwpn,
2799 zfcp_get_busid_by_port(port), port->handle);
2800 zfcp_erp_modify_port_status(port,
2801 ZFCP_STATUS_COMMON_OPEN,
2802 ZFCP_CLEAR);
2803 retval = 0;
2804 break;
2805
2806 default:
2807 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2808 "(debug info 0x%x)\n",
2809 fsf_req->qtcb->header.fsf_status);
2810 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2811 debug_exception(fsf_req->adapter->erp_dbf, 0,
2812 &fsf_req->qtcb->header.fsf_status,
2813 sizeof (u32));
2814 break;
2815 }
2816
2817 skip_fsfstatus:
2818 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2819 return retval;
2820}
2821
2822/*
2823 * function: zfcp_fsf_close_physical_port
2824 *
2825 * purpose: submit FSF command "close physical port"
2826 *
2827 * returns: address of initiated FSF request
2828 * NULL - request could not be initiated
2829 */
2830int
2831zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2832{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002834 struct zfcp_fsf_req *fsf_req;
2835 unsigned long lock_flags;
2836 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
2838 /* setup new FSF request */
2839 retval = zfcp_fsf_req_create(erp_action->adapter,
2840 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2841 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2842 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002843 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 if (retval < 0) {
2845 ZFCP_LOG_INFO("error: Could not create close physical port "
2846 "request (adapter %s, port 0x%016Lx)\n",
2847 zfcp_get_busid_by_adapter(erp_action->adapter),
2848 erp_action->port->wwpn);
2849
2850 goto out;
2851 }
2852
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002853 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2855 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2856
2857 /* mark port as being closed */
2858 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2859 &erp_action->port->status);
2860 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002861 fsf_req->data = (unsigned long) erp_action->port;
2862 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2863 fsf_req->erp_action = erp_action;
2864 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002866 zfcp_erp_start_timer(fsf_req);
2867 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 if (retval) {
2869 ZFCP_LOG_INFO("error: Could not send close physical port "
2870 "request (adapter %s, port 0x%016Lx)\n",
2871 zfcp_get_busid_by_adapter(erp_action->adapter),
2872 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002873 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 erp_action->fsf_req = NULL;
2875 goto out;
2876 }
2877
2878 ZFCP_LOG_TRACE("close physical port request initiated "
2879 "(adapter %s, port 0x%016Lx)\n",
2880 zfcp_get_busid_by_adapter(erp_action->adapter),
2881 erp_action->port->wwpn);
2882 out:
2883 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2884 lock_flags);
2885 return retval;
2886}
2887
2888/*
2889 * function: zfcp_fsf_close_physical_port_handler
2890 *
2891 * purpose: is called for finished Close Physical Port FSF command
2892 *
2893 * returns:
2894 */
2895static int
2896zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2897{
2898 int retval = -EINVAL;
2899 struct zfcp_port *port;
2900 struct zfcp_unit *unit;
2901 struct fsf_qtcb_header *header;
2902 u16 subtable, rule, counter;
2903
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002904 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 header = &fsf_req->qtcb->header;
2906
2907 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2908 /* don't change port status in our bookkeeping */
2909 goto skip_fsfstatus;
2910 }
2911
2912 /* evaluate FSF status in QTCB */
2913 switch (header->fsf_status) {
2914
2915 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2917 "(adapter %s, port 0x%016Lx). "
2918 "This may happen occasionally.\n",
2919 port->handle,
2920 zfcp_get_busid_by_port(port),
2921 port->wwpn);
2922 ZFCP_LOG_DEBUG("status qualifier:\n");
2923 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2924 (char *) &header->fsf_status_qual,
2925 sizeof (union fsf_status_qual));
2926 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2927 "fsf_s_phand_nv");
2928 zfcp_erp_adapter_reopen(port->adapter, 0);
2929 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2930 break;
2931
2932 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 ZFCP_LOG_NORMAL("Access denied, cannot close "
2934 "physical port 0x%016Lx on adapter %s\n",
2935 port->wwpn, zfcp_get_busid_by_port(port));
2936 for (counter = 0; counter < 2; counter++) {
2937 subtable = header->fsf_status_qual.halfword[counter * 2];
2938 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2939 switch (subtable) {
2940 case FSF_SQ_CFDC_SUBTABLE_OS:
2941 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2942 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2943 case FSF_SQ_CFDC_SUBTABLE_LUN:
2944 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2945 zfcp_act_subtable_type[subtable], rule);
2946 break;
2947 }
2948 }
2949 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2950 zfcp_erp_port_access_denied(port);
2951 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2952 break;
2953
2954 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2956 "%s needs to be reopened but it was attempted "
2957 "to close it physically.\n",
2958 port->wwpn,
2959 zfcp_get_busid_by_port(port));
2960 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02002961 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2963 ZFCP_STATUS_FSFREQ_RETRY;
2964 break;
2965
2966 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 switch (header->fsf_status_qual.word[0]) {
2968 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2970 "fsf_sq_ltest");
2971 /* This will now be escalated by ERP */
2972 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2973 break;
2974 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 /* ERP strategy will escalate */
2976 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2977 "fsf_sq_ulp");
2978 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2979 break;
2980 default:
2981 ZFCP_LOG_NORMAL
2982 ("bug: Wrong status qualifier 0x%x arrived.\n",
2983 header->fsf_status_qual.word[0]);
2984 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2985 "fsf_sq_inval:");
2986 debug_exception(
2987 fsf_req->adapter->erp_dbf, 0,
2988 &header->fsf_status_qual.word[0], sizeof (u32));
2989 break;
2990 }
2991 break;
2992
2993 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2995 "physically closed, port handle 0x%x\n",
2996 port->wwpn,
2997 zfcp_get_busid_by_port(port), port->handle);
2998 /* can't use generic zfcp_erp_modify_port_status because
2999 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
3000 */
3001 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
3002 list_for_each_entry(unit, &port->unit_list_head, list)
3003 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3004 retval = 0;
3005 break;
3006
3007 default:
3008 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3009 "(debug info 0x%x)\n",
3010 header->fsf_status);
3011 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3012 debug_exception(fsf_req->adapter->erp_dbf, 0,
3013 &header->fsf_status, sizeof (u32));
3014 break;
3015 }
3016
3017 skip_fsfstatus:
3018 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
3019 return retval;
3020}
3021
3022/*
3023 * function: zfcp_fsf_open_unit
3024 *
3025 * purpose:
3026 *
3027 * returns:
3028 *
3029 * assumptions: This routine does not check whether the associated
3030 * remote port has already been opened. This should be
3031 * done by calling routines. Otherwise some status
3032 * may be presented by FSF
3033 */
3034int
3035zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3036{
3037 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003038 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 unsigned long lock_flags;
3040 int retval = 0;
3041
3042 /* setup new FSF request */
3043 retval = zfcp_fsf_req_create(erp_action->adapter,
3044 FSF_QTCB_OPEN_LUN,
3045 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3046 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003047 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 if (retval < 0) {
3049 ZFCP_LOG_INFO("error: Could not create open unit request for "
3050 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3051 erp_action->unit->fcp_lun,
3052 erp_action->unit->port->wwpn,
3053 zfcp_get_busid_by_adapter(erp_action->adapter));
3054 goto out;
3055 }
3056
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003057 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3059 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3060
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003061 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3062 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003063 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003064 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02003065 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003067 fsf_req->data = (unsigned long) erp_action->unit;
3068 fsf_req->erp_action = erp_action;
3069 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003071 zfcp_erp_start_timer(fsf_req);
3072 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 if (retval) {
3074 ZFCP_LOG_INFO("error: Could not send an open unit request "
3075 "on the adapter %s, port 0x%016Lx for "
3076 "unit 0x%016Lx\n",
3077 zfcp_get_busid_by_adapter(erp_action->adapter),
3078 erp_action->port->wwpn,
3079 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003080 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 erp_action->fsf_req = NULL;
3082 goto out;
3083 }
3084
3085 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3086 "port 0x%016Lx, unit 0x%016Lx)\n",
3087 zfcp_get_busid_by_adapter(erp_action->adapter),
3088 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3089 out:
3090 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3091 lock_flags);
3092 return retval;
3093}
3094
3095/*
3096 * function: zfcp_fsf_open_unit_handler
3097 *
3098 * purpose: is called for finished Open LUN command
3099 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003100 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 */
3102static int
3103zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3104{
3105 int retval = -EINVAL;
3106 struct zfcp_adapter *adapter;
3107 struct zfcp_unit *unit;
3108 struct fsf_qtcb_header *header;
3109 struct fsf_qtcb_bottom_support *bottom;
3110 struct fsf_queue_designator *queue_designator;
3111 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003112 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003114 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
3116 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3117 /* don't change unit status in our bookkeeping */
3118 goto skip_fsfstatus;
3119 }
3120
3121 adapter = fsf_req->adapter;
3122 header = &fsf_req->qtcb->header;
3123 bottom = &fsf_req->qtcb->bottom.support;
3124 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3125
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02003127 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 ZFCP_STATUS_UNIT_SHARED |
3129 ZFCP_STATUS_UNIT_READONLY,
3130 &unit->status);
3131
3132 /* evaluate FSF status in QTCB */
3133 switch (header->fsf_status) {
3134
3135 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3137 "for port 0x%016Lx on adapter %s invalid "
3138 "This may happen occasionally\n",
3139 unit->port->handle,
3140 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3141 ZFCP_LOG_DEBUG("status qualifier:\n");
3142 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3143 (char *) &header->fsf_status_qual,
3144 sizeof (union fsf_status_qual));
3145 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3146 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3147 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3148 break;
3149
3150 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3152 "remote port 0x%016Lx on adapter %s twice.\n",
3153 unit->fcp_lun,
3154 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3155 debug_text_exception(adapter->erp_dbf, 0,
3156 "fsf_s_uopen");
3157 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3158 break;
3159
3160 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3162 "remote port 0x%016Lx on adapter %s\n",
3163 unit->fcp_lun, unit->port->wwpn,
3164 zfcp_get_busid_by_unit(unit));
3165 for (counter = 0; counter < 2; counter++) {
3166 subtable = header->fsf_status_qual.halfword[counter * 2];
3167 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3168 switch (subtable) {
3169 case FSF_SQ_CFDC_SUBTABLE_OS:
3170 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3171 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3172 case FSF_SQ_CFDC_SUBTABLE_LUN:
3173 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3174 zfcp_act_subtable_type[subtable], rule);
3175 break;
3176 }
3177 }
3178 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3179 zfcp_erp_unit_access_denied(unit);
3180 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3181 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3182 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3183 break;
3184
3185 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3187 "needs to be reopened\n",
3188 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3189 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003190 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3192 ZFCP_STATUS_FSFREQ_RETRY;
3193 break;
3194
3195 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 if (header->fsf_status_qual.word[0] != 0) {
3197 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3198 "with WWPN 0x%Lx "
3199 "connected to the adapter %s "
3200 "is already in use in LPAR%d, CSS%d\n",
3201 unit->fcp_lun,
3202 unit->port->wwpn,
3203 zfcp_get_busid_by_unit(unit),
3204 queue_designator->hla,
3205 queue_designator->cssid);
3206 } else {
3207 subtable = header->fsf_status_qual.halfword[4];
3208 rule = header->fsf_status_qual.halfword[5];
3209 switch (subtable) {
3210 case FSF_SQ_CFDC_SUBTABLE_OS:
3211 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3212 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3213 case FSF_SQ_CFDC_SUBTABLE_LUN:
3214 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3215 "remote port with WWPN 0x%Lx "
3216 "connected to the adapter %s "
3217 "is denied (%s rule %d)\n",
3218 unit->fcp_lun,
3219 unit->port->wwpn,
3220 zfcp_get_busid_by_unit(unit),
3221 zfcp_act_subtable_type[subtable],
3222 rule);
3223 break;
3224 }
3225 }
3226 ZFCP_LOG_DEBUG("status qualifier:\n");
3227 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3228 (char *) &header->fsf_status_qual,
3229 sizeof (union fsf_status_qual));
3230 debug_text_event(adapter->erp_dbf, 2,
3231 "fsf_s_l_sh_vio");
3232 zfcp_erp_unit_access_denied(unit);
3233 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3234 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3235 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3236 break;
3237
3238 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3240 "There is no handle (temporary port identifier) "
3241 "available for unit 0x%016Lx on port 0x%016Lx "
3242 "on adapter %s\n",
3243 unit->fcp_lun,
3244 unit->port->wwpn,
3245 zfcp_get_busid_by_unit(unit));
3246 debug_text_event(adapter->erp_dbf, 1,
3247 "fsf_s_max_units");
3248 zfcp_erp_unit_failed(unit);
3249 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3250 break;
3251
3252 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 switch (header->fsf_status_qual.word[0]) {
3254 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 /* Re-establish link to port */
3256 debug_text_event(adapter->erp_dbf, 1,
3257 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003258 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3260 break;
3261 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 /* ERP strategy will escalate */
3263 debug_text_event(adapter->erp_dbf, 1,
3264 "fsf_sq_ulp");
3265 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3266 break;
3267 default:
3268 ZFCP_LOG_NORMAL
3269 ("bug: Wrong status qualifier 0x%x arrived.\n",
3270 header->fsf_status_qual.word[0]);
3271 debug_text_event(adapter->erp_dbf, 0,
3272 "fsf_sq_inval:");
3273 debug_exception(adapter->erp_dbf, 0,
3274 &header->fsf_status_qual.word[0],
3275 sizeof (u32));
3276 }
3277 break;
3278
3279 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 ZFCP_LOG_NORMAL(
3281 "Invalid option 0x%x has been specified "
3282 "in QTCB bottom sent to the adapter %s\n",
3283 bottom->option,
3284 zfcp_get_busid_by_adapter(adapter));
3285 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3286 retval = -EINVAL;
3287 break;
3288
3289 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 /* save LUN handle assigned by FSF */
3291 unit->handle = header->lun_handle;
3292 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3293 "adapter %s opened, port handle 0x%x\n",
3294 unit->fcp_lun,
3295 unit->port->wwpn,
3296 zfcp_get_busid_by_unit(unit),
3297 unit->handle);
3298 /* mark unit as open */
3299 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003300
3301 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3302 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3303 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3304 exclusive = (bottom->lun_access_info &
3305 FSF_UNIT_ACCESS_EXCLUSIVE);
3306 readwrite = (bottom->lun_access_info &
3307 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3308
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 if (!exclusive)
3310 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3311 &unit->status);
3312
3313 if (!readwrite) {
3314 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3315 &unit->status);
3316 ZFCP_LOG_NORMAL("read-only access for unit "
3317 "(adapter %s, wwpn=0x%016Lx, "
3318 "fcp_lun=0x%016Lx)\n",
3319 zfcp_get_busid_by_unit(unit),
3320 unit->port->wwpn,
3321 unit->fcp_lun);
3322 }
3323
3324 if (exclusive && !readwrite) {
3325 ZFCP_LOG_NORMAL("exclusive access of read-only "
3326 "unit not supported\n");
3327 zfcp_erp_unit_failed(unit);
3328 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3329 zfcp_erp_unit_shutdown(unit, 0);
3330 } else if (!exclusive && readwrite) {
3331 ZFCP_LOG_NORMAL("shared access of read-write "
3332 "unit not supported\n");
3333 zfcp_erp_unit_failed(unit);
3334 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3335 zfcp_erp_unit_shutdown(unit, 0);
3336 }
3337 }
3338
3339 retval = 0;
3340 break;
3341
3342 default:
3343 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3344 "(debug info 0x%x)\n",
3345 header->fsf_status);
3346 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3347 debug_exception(adapter->erp_dbf, 0,
3348 &header->fsf_status, sizeof (u32));
3349 break;
3350 }
3351
3352 skip_fsfstatus:
3353 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3354 return retval;
3355}
3356
3357/*
3358 * function: zfcp_fsf_close_unit
3359 *
3360 * purpose:
3361 *
3362 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003363 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 *
3365 * assumptions: This routine does not check whether the associated
3366 * remote port/lun has already been opened. This should be
3367 * done by calling routines. Otherwise some status
3368 * may be presented by FSF
3369 */
3370int
3371zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3372{
3373 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003374 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 unsigned long lock_flags;
3376 int retval = 0;
3377
3378 /* setup new FSF request */
3379 retval = zfcp_fsf_req_create(erp_action->adapter,
3380 FSF_QTCB_CLOSE_LUN,
3381 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3382 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003383 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 if (retval < 0) {
3385 ZFCP_LOG_INFO("error: Could not create close unit request for "
3386 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3387 erp_action->unit->fcp_lun,
3388 erp_action->port->wwpn,
3389 zfcp_get_busid_by_adapter(erp_action->adapter));
3390 goto out;
3391 }
3392
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003393 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3395 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3396
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003397 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3398 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003400 fsf_req->data = (unsigned long) erp_action->unit;
3401 fsf_req->erp_action = erp_action;
3402 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003404 zfcp_erp_start_timer(fsf_req);
3405 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 if (retval) {
3407 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3408 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3409 erp_action->unit->fcp_lun,
3410 erp_action->port->wwpn,
3411 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003412 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 erp_action->fsf_req = NULL;
3414 goto out;
3415 }
3416
3417 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3418 "port 0x%016Lx, unit 0x%016Lx)\n",
3419 zfcp_get_busid_by_adapter(erp_action->adapter),
3420 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3421 out:
3422 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3423 lock_flags);
3424 return retval;
3425}
3426
3427/*
3428 * function: zfcp_fsf_close_unit_handler
3429 *
3430 * purpose: is called for finished Close LUN FSF command
3431 *
3432 * returns:
3433 */
3434static int
3435zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3436{
3437 int retval = -EINVAL;
3438 struct zfcp_unit *unit;
3439
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003440 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
3442 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3443 /* don't change unit status in our bookkeeping */
3444 goto skip_fsfstatus;
3445 }
3446
3447 /* evaluate FSF status in QTCB */
3448 switch (fsf_req->qtcb->header.fsf_status) {
3449
3450 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3452 "0x%016Lx on adapter %s invalid. This may "
3453 "happen in rare circumstances\n",
3454 unit->port->handle,
3455 unit->port->wwpn,
3456 zfcp_get_busid_by_unit(unit));
3457 ZFCP_LOG_DEBUG("status qualifier:\n");
3458 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3459 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3460 sizeof (union fsf_status_qual));
3461 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3462 "fsf_s_phand_nv");
3463 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3465 break;
3466
3467 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3469 "0x%016Lx on port 0x%016Lx on adapter %s is "
3470 "invalid. This may happen occasionally.\n",
3471 unit->handle,
3472 unit->fcp_lun,
3473 unit->port->wwpn,
3474 zfcp_get_busid_by_unit(unit));
3475 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3476 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3477 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3478 sizeof (union fsf_status_qual));
3479 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3480 "fsf_s_lhand_nv");
3481 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3483 break;
3484
3485 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3487 "needs to be reopened\n",
3488 unit->port->wwpn,
3489 zfcp_get_busid_by_unit(unit));
3490 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003491 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3493 ZFCP_STATUS_FSFREQ_RETRY;
3494 break;
3495
3496 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3498 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 /* re-establish link to port */
3500 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3501 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003502 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3504 break;
3505 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 /* ERP strategy will escalate */
3507 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3508 "fsf_sq_ulp");
3509 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3510 break;
3511 default:
3512 ZFCP_LOG_NORMAL
3513 ("bug: Wrong status qualifier 0x%x arrived.\n",
3514 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3515 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3516 "fsf_sq_inval:");
3517 debug_exception(
3518 fsf_req->adapter->erp_dbf, 0,
3519 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3520 sizeof (u32));
3521 break;
3522 }
3523 break;
3524
3525 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3527 "closed, port handle 0x%x\n",
3528 unit->fcp_lun,
3529 unit->port->wwpn,
3530 zfcp_get_busid_by_unit(unit),
3531 unit->handle);
3532 /* mark unit as closed */
3533 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3534 retval = 0;
3535 break;
3536
3537 default:
3538 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3539 "(debug info 0x%x)\n",
3540 fsf_req->qtcb->header.fsf_status);
3541 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3542 debug_exception(fsf_req->adapter->erp_dbf, 0,
3543 &fsf_req->qtcb->header.fsf_status,
3544 sizeof (u32));
3545 break;
3546 }
3547
3548 skip_fsfstatus:
3549 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3550 return retval;
3551}
3552
3553/**
3554 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3555 * @adapter: adapter where scsi command is issued
3556 * @unit: unit where command is sent to
3557 * @scsi_cmnd: scsi command to be sent
3558 * @timer: timer to be started when request is initiated
3559 * @req_flags: flags for fsf_request
3560 */
3561int
3562zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3563 struct zfcp_unit *unit,
3564 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003565 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566{
3567 struct zfcp_fsf_req *fsf_req = NULL;
3568 struct fcp_cmnd_iu *fcp_cmnd_iu;
3569 unsigned int sbtype;
3570 unsigned long lock_flags;
3571 int real_bytes = 0;
3572 int retval = 0;
3573 int mask;
3574
3575 /* setup new FSF request */
3576 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3577 adapter->pool.fsf_req_scsi,
3578 &lock_flags, &fsf_req);
3579 if (unlikely(retval < 0)) {
3580 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3581 "for unit 0x%016Lx on port 0x%016Lx on "
3582 "adapter %s\n",
3583 unit->fcp_lun,
3584 unit->port->wwpn,
3585 zfcp_get_busid_by_adapter(adapter));
3586 goto failed_req_create;
3587 }
3588
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003589 zfcp_unit_get(unit);
3590 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003592 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003593 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003594
3595 /* associate SCSI command with FSF request */
3596 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597
3598 /* set handles of unit and its parent port in QTCB */
3599 fsf_req->qtcb->header.lun_handle = unit->handle;
3600 fsf_req->qtcb->header.port_handle = unit->port->handle;
3601
3602 /* FSF does not define the structure of the FCP_CMND IU */
3603 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3604 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3605
3606 /*
3607 * set depending on data direction:
3608 * data direction bits in SBALE (SB Type)
3609 * data direction bits in QTCB
3610 * data direction bits in FCP_CMND IU
3611 */
3612 switch (scsi_cmnd->sc_data_direction) {
3613 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3615 /*
3616 * FIXME(qdio):
3617 * what is the correct type for commands
3618 * without 'real' data buffers?
3619 */
3620 sbtype = SBAL_FLAGS0_TYPE_READ;
3621 break;
3622 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3624 sbtype = SBAL_FLAGS0_TYPE_READ;
3625 fcp_cmnd_iu->rddata = 1;
3626 break;
3627 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3629 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3630 fcp_cmnd_iu->wddata = 1;
3631 break;
3632 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 default:
3634 /*
3635 * dummy, catch this condition earlier
3636 * in zfcp_scsi_queuecommand
3637 */
3638 goto failed_scsi_cmnd;
3639 }
3640
3641 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003642 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643
3644 /* set FCP_LUN in FCP_CMND IU in QTCB */
3645 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3646
3647 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3648
3649 /* set task attributes in FCP_CMND IU in QTCB */
3650 if (likely((scsi_cmnd->device->simple_tags) ||
3651 (atomic_test_mask(mask, &unit->status))))
3652 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3653 else
3654 fcp_cmnd_iu->task_attribute = UNTAGGED;
3655
3656 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3657 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3658 fcp_cmnd_iu->add_fcp_cdb_length
3659 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3660 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3661 "additional FCP_CDB length is 0x%x "
3662 "(shifted right 2 bits)\n",
3663 scsi_cmnd->cmd_len,
3664 fcp_cmnd_iu->add_fcp_cdb_length);
3665 }
3666 /*
3667 * copy SCSI CDB (including additional length, if any) to
3668 * FCP_CDB in FCP_CMND IU in QTCB
3669 */
3670 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3671
3672 /* FCP CMND IU length in QTCB */
3673 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3674 sizeof (struct fcp_cmnd_iu) +
3675 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3676
3677 /* generate SBALEs from data buffer */
3678 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3679 if (unlikely(real_bytes < 0)) {
3680 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3681 ZFCP_LOG_DEBUG(
3682 "Data did not fit into available buffer(s), "
3683 "waiting for more...\n");
Christof Schmitt2282f652007-08-28 09:30:22 +02003684 retval = -EIO;
3685 } else {
3686 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3687 "required. Shutting down unit "
3688 "(adapter %s, port 0x%016Lx, "
3689 "unit 0x%016Lx)\n",
3690 zfcp_get_busid_by_unit(unit),
3691 unit->port->wwpn,
3692 unit->fcp_lun);
3693 zfcp_erp_unit_shutdown(unit, 0);
3694 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 }
3696 goto no_fit;
3697 }
3698
3699 /* set length of FCP data length in FCP_CMND IU in QTCB */
3700 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3701
3702 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3703 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3704 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3705
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003706 if (use_timer)
3707 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3708
3709 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 if (unlikely(retval < 0)) {
3711 ZFCP_LOG_INFO("error: Could not send FCP command request "
3712 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3713 zfcp_get_busid_by_adapter(adapter),
3714 unit->port->wwpn,
3715 unit->fcp_lun);
3716 goto send_failed;
3717 }
3718
3719 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3720 "port 0x%016Lx, unit 0x%016Lx)\n",
3721 zfcp_get_busid_by_adapter(adapter),
3722 unit->port->wwpn,
3723 unit->fcp_lun);
3724 goto success;
3725
3726 send_failed:
3727 no_fit:
3728 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003729 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 zfcp_fsf_req_free(fsf_req);
3731 fsf_req = NULL;
3732 scsi_cmnd->host_scribble = NULL;
3733 success:
3734 failed_req_create:
3735 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3736 return retval;
3737}
3738
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739struct zfcp_fsf_req *
3740zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3741 struct zfcp_unit *unit,
3742 u8 tm_flags, int req_flags)
3743{
3744 struct zfcp_fsf_req *fsf_req = NULL;
3745 int retval = 0;
3746 struct fcp_cmnd_iu *fcp_cmnd_iu;
3747 unsigned long lock_flags;
3748 volatile struct qdio_buffer_element *sbale;
3749
3750 /* setup new FSF request */
3751 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3752 adapter->pool.fsf_req_scsi,
3753 &lock_flags, &fsf_req);
3754 if (retval < 0) {
3755 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3756 "management) request for adapter %s, port "
3757 " 0x%016Lx, unit 0x%016Lx.\n",
3758 zfcp_get_busid_by_adapter(adapter),
3759 unit->port->wwpn, unit->fcp_lun);
3760 goto out;
3761 }
3762
3763 /*
3764 * Used to decide on proper handler in the return path,
3765 * could be either zfcp_fsf_send_fcp_command_task_handler or
3766 * zfcp_fsf_send_fcp_command_task_management_handler */
3767
3768 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3769
3770 /*
3771 * hold a pointer to the unit being target of this
3772 * task management request
3773 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003774 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
3776 /* set FSF related fields in QTCB */
3777 fsf_req->qtcb->header.lun_handle = unit->handle;
3778 fsf_req->qtcb->header.port_handle = unit->port->handle;
3779 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003780 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3782 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3783
3784 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3785 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3786 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3787
3788 /* set FCP related fields in FCP_CMND IU in QTCB */
3789 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3790 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3791 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3792 fcp_cmnd_iu->task_management_flags = tm_flags;
3793
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003794 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3795 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3798 "management) on adapter %s, port 0x%016Lx for "
3799 "unit LUN 0x%016Lx\n",
3800 zfcp_get_busid_by_adapter(adapter),
3801 unit->port->wwpn,
3802 unit->fcp_lun);
3803 zfcp_fsf_req_free(fsf_req);
3804 fsf_req = NULL;
3805 goto out;
3806 }
3807
3808 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3809 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3810 "tm_flags=0x%x)\n",
3811 zfcp_get_busid_by_adapter(adapter),
3812 unit->port->wwpn,
3813 unit->fcp_lun,
3814 tm_flags);
3815 out:
3816 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3817 return fsf_req;
3818}
3819
3820/*
3821 * function: zfcp_fsf_send_fcp_command_handler
3822 *
3823 * purpose: is called for finished Send FCP Command
3824 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003825 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 */
3827static int
3828zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3829{
3830 int retval = -EINVAL;
3831 struct zfcp_unit *unit;
3832 struct fsf_qtcb_header *header;
3833 u16 subtable, rule, counter;
3834
3835 header = &fsf_req->qtcb->header;
3836
3837 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003838 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003840 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841
3842 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3843 /* go directly to calls of special handlers */
3844 goto skip_fsfstatus;
3845 }
3846
3847 /* evaluate FSF status in QTCB */
3848 switch (header->fsf_status) {
3849
3850 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3852 "0x%016Lx on adapter %s invalid\n",
3853 unit->port->handle,
3854 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3855 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3856 (char *) &header->fsf_status_qual,
3857 sizeof (union fsf_status_qual));
3858 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3859 "fsf_s_phand_nv");
3860 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3861 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3862 break;
3863
3864 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3866 "0x%016Lx on port 0x%016Lx on adapter %s is "
3867 "invalid. This may happen occasionally.\n",
3868 unit->handle,
3869 unit->fcp_lun,
3870 unit->port->wwpn,
3871 zfcp_get_busid_by_unit(unit));
3872 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3873 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3874 (char *) &header->fsf_status_qual,
3875 sizeof (union fsf_status_qual));
3876 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3877 "fsf_s_uhand_nv");
3878 zfcp_erp_port_reopen(unit->port, 0);
3879 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3880 break;
3881
3882 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3884 "unexpectedly. (adapter %s, port 0x%016Lx, "
3885 "unit 0x%016Lx)\n",
3886 unit->port->handle,
3887 zfcp_get_busid_by_unit(unit),
3888 unit->port->wwpn,
3889 unit->fcp_lun);
3890 ZFCP_LOG_NORMAL("status qualifier:\n");
3891 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3892 (char *) &header->fsf_status_qual,
3893 sizeof (union fsf_status_qual));
3894 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3895 "fsf_s_hand_mis");
3896 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3898 break;
3899
3900 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003901 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3902 "class %d.\n",
3903 zfcp_get_busid_by_unit(unit),
3904 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 /* stop operation for this adapter */
3906 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3907 "fsf_s_class_nsup");
3908 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3910 break;
3911
3912 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3914 "adapter %s does not have correct unit "
3915 "handle 0x%x\n",
3916 unit->fcp_lun,
3917 unit->port->wwpn,
3918 zfcp_get_busid_by_unit(unit),
3919 unit->handle);
3920 ZFCP_LOG_DEBUG("status qualifier:\n");
3921 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3922 (char *) &header->fsf_status_qual,
3923 sizeof (union fsf_status_qual));
3924 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3925 "fsf_s_fcp_lun_nv");
3926 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3928 break;
3929
3930 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3932 "unit 0x%016Lx on port 0x%016Lx on "
3933 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3934 zfcp_get_busid_by_unit(unit));
3935 for (counter = 0; counter < 2; counter++) {
3936 subtable = header->fsf_status_qual.halfword[counter * 2];
3937 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3938 switch (subtable) {
3939 case FSF_SQ_CFDC_SUBTABLE_OS:
3940 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3941 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3942 case FSF_SQ_CFDC_SUBTABLE_LUN:
3943 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3944 zfcp_act_subtable_type[subtable], rule);
3945 break;
3946 }
3947 }
3948 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3949 zfcp_erp_unit_access_denied(unit);
3950 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3951 break;
3952
3953 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3955 "0x%016Lx on port 0x%016Lx on adapter %s "
3956 "(debug info %d)\n",
3957 unit->fcp_lun,
3958 unit->port->wwpn,
3959 zfcp_get_busid_by_unit(unit),
3960 fsf_req->qtcb->bottom.io.data_direction);
3961 /* stop operation for this adapter */
3962 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3963 "fsf_s_dir_ind_nv");
3964 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3966 break;
3967
3968 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 ZFCP_LOG_NORMAL
3970 ("bug: An invalid control-data-block length field "
3971 "was found in a command for unit 0x%016Lx on port "
3972 "0x%016Lx on adapter %s " "(debug info %d)\n",
3973 unit->fcp_lun, unit->port->wwpn,
3974 zfcp_get_busid_by_unit(unit),
3975 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3976 /* stop operation for this adapter */
3977 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3978 "fsf_s_cmd_len_nv");
3979 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3981 break;
3982
3983 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3985 "needs to be reopened\n",
3986 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3987 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003988 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3990 ZFCP_STATUS_FSFREQ_RETRY;
3991 break;
3992
3993 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3995 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3996 zfcp_get_busid_by_unit(unit),
3997 unit->port->wwpn, unit->fcp_lun);
3998 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a272005-06-13 13:23:57 +02003999 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
4001 | ZFCP_STATUS_FSFREQ_RETRY;
4002 break;
4003
4004 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 switch (header->fsf_status_qual.word[0]) {
4006 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 /* re-establish link to port */
4008 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4009 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02004010 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 break;
4012 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013 /* FIXME(hw) need proper specs for proper action */
4014 /* let scsi stack deal with retries and escalation */
4015 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4016 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 break;
4018 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02004020 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 header->fsf_status_qual.word[0]);
4022 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4023 "fsf_sq_inval:");
4024 debug_exception(fsf_req->adapter->erp_dbf, 0,
4025 &header->fsf_status_qual.word[0],
4026 sizeof(u32));
4027 break;
4028 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02004029 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 break;
4031
4032 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 break;
4034
4035 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 break;
4037
4038 default:
4039 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4040 debug_exception(fsf_req->adapter->erp_dbf, 0,
4041 &header->fsf_status, sizeof(u32));
4042 break;
4043 }
4044
4045 skip_fsfstatus:
4046 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4047 retval =
4048 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4049 } else {
4050 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004051 fsf_req->unit = NULL;
4052 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 }
4054 return retval;
4055}
4056
4057/*
4058 * function: zfcp_fsf_send_fcp_command_task_handler
4059 *
4060 * purpose: evaluates FCP_RSP IU
4061 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004062 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 */
4064static int
4065zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4066{
4067 int retval = 0;
4068 struct scsi_cmnd *scpnt;
4069 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4070 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4071 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4072 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4073 u32 sns_len;
4074 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4075 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004076 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077
4078 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004079 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 if (unlikely(!scpnt)) {
4081 ZFCP_LOG_DEBUG
4082 ("Command with fsf_req %p is not associated to "
4083 "a scsi command anymore. Aborted?\n", fsf_req);
4084 goto out;
4085 }
4086 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4087 /* FIXME: (design) mid-layer should handle DID_ABORT like
4088 * DID_SOFT_ERROR by retrying the request for devices
4089 * that allow retries.
4090 */
4091 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4092 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4093 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4094 goto skip_fsfstatus;
4095 }
4096
4097 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4098 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4099 set_host_byte(&scpnt->result, DID_ERROR);
4100 goto skip_fsfstatus;
4101 }
4102
4103 /* set message byte of result in SCSI command */
4104 scpnt->result |= COMMAND_COMPLETE << 8;
4105
4106 /*
4107 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4108 * of result in SCSI command
4109 */
4110 scpnt->result |= fcp_rsp_iu->scsi_status;
4111 if (unlikely(fcp_rsp_iu->scsi_status)) {
4112 /* DEBUG */
4113 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4114 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4115 scpnt->cmnd, scpnt->cmd_len);
4116 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4117 fcp_rsp_iu->scsi_status);
4118 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4119 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4120 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4121 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4122 fcp_rsp_iu->fcp_sns_len);
4123 }
4124
4125 /* check FCP_RSP_INFO */
4126 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4127 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4128 switch (fcp_rsp_info[3]) {
4129 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 /* ok, continue */
4131 ZFCP_LOG_TRACE("no failure or Task Management "
4132 "Function complete\n");
4133 set_host_byte(&scpnt->result, DID_OK);
4134 break;
4135 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 /* hardware bug */
4137 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4138 "that the fibrechannel protocol data "
4139 "length differs from the burst length. "
4140 "The problem occured on unit 0x%016Lx "
4141 "on port 0x%016Lx on adapter %s",
4142 unit->fcp_lun,
4143 unit->port->wwpn,
4144 zfcp_get_busid_by_unit(unit));
4145 /* dump SCSI CDB as prepared by zfcp */
4146 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4147 (char *) &fsf_req->qtcb->
4148 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 set_host_byte(&scpnt->result, DID_ERROR);
4150 goto skip_fsfstatus;
4151 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 /* driver or hardware bug */
4153 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4154 "that the fibrechannel protocol data "
4155 "fields were incorrectly set up. "
4156 "The problem occured on the unit "
4157 "0x%016Lx on port 0x%016Lx on "
4158 "adapter %s",
4159 unit->fcp_lun,
4160 unit->port->wwpn,
4161 zfcp_get_busid_by_unit(unit));
4162 /* dump SCSI CDB as prepared by zfcp */
4163 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4164 (char *) &fsf_req->qtcb->
4165 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4166 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 goto skip_fsfstatus;
4168 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 /* hardware bug */
4170 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4171 "that conflicting values for the "
4172 "fibrechannel payload offset from the "
4173 "header were found. "
4174 "The problem occured on unit 0x%016Lx "
4175 "on port 0x%016Lx on adapter %s.\n",
4176 unit->fcp_lun,
4177 unit->port->wwpn,
4178 zfcp_get_busid_by_unit(unit));
4179 /* dump SCSI CDB as prepared by zfcp */
4180 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4181 (char *) &fsf_req->qtcb->
4182 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 set_host_byte(&scpnt->result, DID_ERROR);
4184 goto skip_fsfstatus;
4185 default:
4186 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4187 "code was detected for a command. "
4188 "The problem occured on the unit "
4189 "0x%016Lx on port 0x%016Lx on "
4190 "adapter %s (debug info 0x%x)\n",
4191 unit->fcp_lun,
4192 unit->port->wwpn,
4193 zfcp_get_busid_by_unit(unit),
4194 fcp_rsp_info[3]);
4195 /* dump SCSI CDB as prepared by zfcp */
4196 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4197 (char *) &fsf_req->qtcb->
4198 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004200 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 }
4202 }
4203
4204 /* check for sense data */
4205 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4206 sns_len = FSF_FCP_RSP_SIZE -
4207 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4208 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4209 sns_len);
4210 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4211 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4212 SCSI_SENSE_BUFFERSIZE);
4213 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4214 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4215 scpnt->result);
4216 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4217 (void *) &scpnt->cmnd, scpnt->cmd_len);
4218
4219 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4220 fcp_rsp_iu->fcp_sns_len);
4221 memcpy(&scpnt->sense_buffer,
4222 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4223 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4224 (void *) &scpnt->sense_buffer, sns_len);
4225 }
4226
4227 /* check for overrun */
4228 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4229 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4230 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4231 "The response data length is "
4232 "%d, the original length was %d.\n",
4233 unit->fcp_lun,
4234 unit->port->wwpn,
4235 zfcp_get_busid_by_unit(unit),
4236 fcp_rsp_iu->fcp_resid,
4237 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4238 }
4239
4240 /* check for underrun */
4241 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4242 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4243 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4244 "The response data length is "
4245 "%d, the original length was %d.\n",
4246 unit->fcp_lun,
4247 unit->port->wwpn,
4248 zfcp_get_busid_by_unit(unit),
4249 fcp_rsp_iu->fcp_resid,
4250 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4251
FUJITA Tomonori7936a892007-07-29 16:46:28 +09004252 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4253 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4254 scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004255 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 }
4257
4258 skip_fsfstatus:
4259 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4260
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004261 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004262 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004263 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004264 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004265 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004266 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267
4268 /* cleanup pointer (need this especially for abort) */
4269 scpnt->host_scribble = NULL;
4270
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 (scpnt->scsi_done) (scpnt);
4273
4274 /*
4275 * We must hold this lock until scsi_done has been called.
4276 * Otherwise we may call scsi_done after abort regarding this
4277 * command has completed.
4278 * Note: scsi_done must not block!
4279 */
4280 out:
4281 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4282 return retval;
4283}
4284
4285/*
4286 * function: zfcp_fsf_send_fcp_command_task_management_handler
4287 *
4288 * purpose: evaluates FCP_RSP IU
4289 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004290 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 */
4292static int
4293zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4294{
4295 int retval = 0;
4296 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4297 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4298 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004299 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4302 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4303 goto skip_fsfstatus;
4304 }
4305
4306 /* check FCP_RSP_INFO */
4307 switch (fcp_rsp_info[3]) {
4308 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 /* ok, continue */
4310 ZFCP_LOG_DEBUG("no failure or Task Management "
4311 "Function complete\n");
4312 break;
4313 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4315 "is not supported on the target device "
4316 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4317 unit->fcp_lun,
4318 unit->port->wwpn,
4319 zfcp_get_busid_by_unit(unit));
4320 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4321 break;
4322 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4324 "failed to complete successfully. "
4325 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4326 unit->fcp_lun,
4327 unit->port->wwpn,
4328 zfcp_get_busid_by_unit(unit));
4329 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4330 break;
4331 default:
4332 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4333 "code was detected for a command. "
4334 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4335 "(debug info 0x%x)\n",
4336 unit->fcp_lun,
4337 unit->port->wwpn,
4338 zfcp_get_busid_by_unit(unit),
4339 fcp_rsp_info[3]);
4340 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4341 }
4342
4343 skip_fsfstatus:
4344 return retval;
4345}
4346
4347
4348/*
4349 * function: zfcp_fsf_control_file
4350 *
4351 * purpose: Initiator of the control file upload/download FSF requests
4352 *
4353 * returns: 0 - FSF request is successfuly created and queued
4354 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4355 * -EINVAL - Invalid direction specified
4356 * -ENOMEM - Insufficient memory
4357 * -EPERM - Cannot create FSF request or place it in QDIO queue
4358 */
4359int
4360zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4361 struct zfcp_fsf_req **fsf_req_ptr,
4362 u32 fsf_command,
4363 u32 option,
4364 struct zfcp_sg_list *sg_list)
4365{
4366 struct zfcp_fsf_req *fsf_req;
4367 struct fsf_qtcb_bottom_support *bottom;
4368 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 unsigned long lock_flags;
4370 int req_flags = 0;
4371 int direction;
4372 int retval = 0;
4373
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004374 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4376 zfcp_get_busid_by_adapter(adapter));
4377 retval = -EOPNOTSUPP;
4378 goto out;
4379 }
4380
4381 switch (fsf_command) {
4382
4383 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4384 direction = SBAL_FLAGS0_TYPE_WRITE;
4385 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4386 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4387 req_flags = ZFCP_WAIT_FOR_SBAL;
4388 break;
4389
4390 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4391 direction = SBAL_FLAGS0_TYPE_READ;
4392 break;
4393
4394 default:
4395 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4396 retval = -EINVAL;
4397 goto out;
4398 }
4399
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4401 NULL, &lock_flags, &fsf_req);
4402 if (retval < 0) {
4403 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4404 "adapter %s\n",
4405 zfcp_get_busid_by_adapter(adapter));
4406 retval = -EPERM;
4407 goto unlock_queue_lock;
4408 }
4409
4410 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4411 sbale[0].flags |= direction;
4412
4413 bottom = &fsf_req->qtcb->bottom.support;
4414 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4415 bottom->option = option;
4416
4417 if (sg_list->count > 0) {
4418 int bytes;
4419
4420 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4421 sg_list->sg, sg_list->count,
4422 ZFCP_MAX_SBALS_PER_REQ);
4423 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4424 ZFCP_LOG_INFO(
4425 "error: Could not create sufficient number of "
4426 "SBALS for an FSF request to the adapter %s\n",
4427 zfcp_get_busid_by_adapter(adapter));
4428 retval = -ENOMEM;
4429 goto free_fsf_req;
4430 }
4431 } else
4432 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4433
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004434 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4435 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 if (retval < 0) {
4437 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4438 "(adapter %s)\n",
4439 zfcp_get_busid_by_adapter(adapter));
4440 retval = -EPERM;
4441 goto free_fsf_req;
4442 }
4443 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4444
4445 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4446 "adapter %s\n",
4447 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4448 "download" : "upload",
4449 zfcp_get_busid_by_adapter(adapter));
4450
4451 wait_event(fsf_req->completion_wq,
4452 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4453
4454 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004455 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456
4457 free_fsf_req:
4458 zfcp_fsf_req_free(fsf_req);
4459 unlock_queue_lock:
4460 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 out:
4462 return retval;
4463}
4464
4465
4466/*
4467 * function: zfcp_fsf_control_file_handler
4468 *
4469 * purpose: Handler of the control file upload/download FSF requests
4470 *
4471 * returns: 0 - FSF request successfuly processed
4472 * -EAGAIN - Operation has to be repeated because of a temporary problem
4473 * -EACCES - There is no permission to execute an operation
4474 * -EPERM - The control file is not in a right format
4475 * -EIO - There is a problem with the FCP adapter
4476 * -EINVAL - Invalid operation
4477 * -EFAULT - User space memory I/O operation fault
4478 */
4479static int
4480zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4481{
4482 struct zfcp_adapter *adapter = fsf_req->adapter;
4483 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4484 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4485 int retval = 0;
4486
4487 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4488 retval = -EINVAL;
4489 goto skip_fsfstatus;
4490 }
4491
4492 switch (header->fsf_status) {
4493
4494 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 ZFCP_LOG_NORMAL(
4496 "The FSF request has been successfully completed "
4497 "on the adapter %s\n",
4498 zfcp_get_busid_by_adapter(adapter));
4499 break;
4500
4501 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4503 switch (header->fsf_status_qual.word[0]) {
4504
6f71d9b2005-04-10 23:04:28 -05004505 case FSF_SQ_CFDC_HARDENED_ON_SE:
4506 ZFCP_LOG_NORMAL(
4507 "CFDC on the adapter %s has being "
4508 "hardened on primary and secondary SE\n",
4509 zfcp_get_busid_by_adapter(adapter));
4510 break;
4511
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4513 ZFCP_LOG_NORMAL(
4514 "CFDC of the adapter %s could not "
4515 "be saved on the SE\n",
4516 zfcp_get_busid_by_adapter(adapter));
4517 break;
4518
4519 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4520 ZFCP_LOG_NORMAL(
4521 "CFDC of the adapter %s could not "
4522 "be copied to the secondary SE\n",
4523 zfcp_get_busid_by_adapter(adapter));
4524 break;
4525
4526 default:
4527 ZFCP_LOG_NORMAL(
4528 "CFDC could not be hardened "
4529 "on the adapter %s\n",
4530 zfcp_get_busid_by_adapter(adapter));
4531 }
4532 }
4533 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4534 retval = -EAGAIN;
4535 break;
4536
4537 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 ZFCP_LOG_NORMAL(
4539 "Adapter %s does not accept privileged commands\n",
4540 zfcp_get_busid_by_adapter(adapter));
4541 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4542 retval = -EACCES;
4543 break;
4544
4545 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 ZFCP_LOG_NORMAL(
4547 "Error at position %d in the CFDC, "
4548 "CFDC is discarded by the adapter %s\n",
4549 header->fsf_status_qual.word[0],
4550 zfcp_get_busid_by_adapter(adapter));
4551 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4552 retval = -EPERM;
4553 break;
4554
4555 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 ZFCP_LOG_NORMAL(
4557 "Adapter %s cannot harden the control file, "
4558 "file is discarded\n",
4559 zfcp_get_busid_by_adapter(adapter));
4560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4561 retval = -EIO;
4562 break;
4563
4564 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 ZFCP_LOG_NORMAL(
4566 "Control file is too large, file is discarded "
4567 "by the adapter %s\n",
4568 zfcp_get_busid_by_adapter(adapter));
4569 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4570 retval = -EIO;
4571 break;
4572
4573 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4575 ZFCP_LOG_NORMAL(
4576 "CFDC has been discarded by the adapter %s, "
4577 "because activation would impact "
4578 "%d active connection(s)\n",
4579 zfcp_get_busid_by_adapter(adapter),
4580 header->fsf_status_qual.word[0]);
4581 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4582 retval = -EIO;
4583 break;
4584
4585 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4587 ZFCP_LOG_NORMAL(
4588 "CFDC has been activated on the adapter %s, "
4589 "but activation has impacted "
4590 "%d active connection(s)\n",
4591 zfcp_get_busid_by_adapter(adapter),
4592 header->fsf_status_qual.word[0]);
4593 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4594 retval = -EIO;
4595 break;
4596
4597 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4599 "op_subtype=0x%x)\n",
4600 zfcp_get_busid_by_adapter(adapter),
4601 bottom->operation_subtype);
4602 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4603 retval = -EINVAL;
4604 break;
4605
4606 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 ZFCP_LOG_NORMAL(
4608 "Invalid option 0x%x has been specified "
4609 "in QTCB bottom sent to the adapter %s\n",
4610 bottom->option,
4611 zfcp_get_busid_by_adapter(adapter));
4612 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4613 retval = -EINVAL;
4614 break;
4615
4616 default:
4617 ZFCP_LOG_NORMAL(
4618 "bug: An unknown/unexpected FSF status 0x%08x "
4619 "was presented on the adapter %s\n",
4620 header->fsf_status,
4621 zfcp_get_busid_by_adapter(adapter));
4622 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4623 debug_exception(fsf_req->adapter->erp_dbf, 0,
4624 &header->fsf_status_qual.word[0], sizeof(u32));
4625 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4626 retval = -EINVAL;
4627 break;
4628 }
4629
4630skip_fsfstatus:
4631 return retval;
4632}
4633
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634static inline int
4635zfcp_fsf_req_sbal_check(unsigned long *flags,
4636 struct zfcp_qdio_queue *queue, int needed)
4637{
4638 write_lock_irqsave(&queue->queue_lock, *flags);
4639 if (likely(atomic_read(&queue->free_count) >= needed))
4640 return 1;
4641 write_unlock_irqrestore(&queue->queue_lock, *flags);
4642 return 0;
4643}
4644
4645/*
4646 * set qtcb pointer in fsf_req and initialize QTCB
4647 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004648static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004649zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650{
4651 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004652 fsf_req->qtcb->prefix.req_seq_no =
4653 fsf_req->adapter->fsf_req_seq_no;
4654 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004656 fsf_req->qtcb->prefix.qtcb_type =
4657 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004659 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004660 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 }
4662}
4663
4664/**
4665 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4666 * @adapter: adapter for which request queue is examined
4667 * @req_flags: flags indicating whether to wait for needed SBAL or not
4668 * @lock_flags: lock_flags if queue_lock is taken
4669 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4670 * Locks: lock adapter->request_queue->queue_lock on success
4671 */
4672static int
4673zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4674 unsigned long *lock_flags)
4675{
4676 long ret;
4677 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4678
4679 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4680 ret = wait_event_interruptible_timeout(adapter->request_wq,
4681 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4682 ZFCP_SBAL_TIMEOUT);
4683 if (ret < 0)
4684 return ret;
4685 if (!ret)
4686 return -EIO;
4687 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4688 return -EIO;
4689
4690 return 0;
4691}
4692
4693/*
4694 * function: zfcp_fsf_req_create
4695 *
4696 * purpose: create an FSF request at the specified adapter and
4697 * setup common fields
4698 *
4699 * returns: -ENOMEM if there was insufficient memory for a request
4700 * -EIO if no qdio buffers could be allocate to the request
4701 * -EINVAL/-EPERM on bug conditions in req_dequeue
4702 * 0 in success
4703 *
4704 * note: The created request is returned by reference.
4705 *
4706 * locks: lock of concerned request queue must not be held,
4707 * but is held on completion (write, irqsave)
4708 */
4709int
4710zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4711 mempool_t *pool, unsigned long *lock_flags,
4712 struct zfcp_fsf_req **fsf_req_p)
4713{
4714 volatile struct qdio_buffer_element *sbale;
4715 struct zfcp_fsf_req *fsf_req = NULL;
4716 int ret = 0;
4717 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4718
4719 /* allocate new FSF request */
4720 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4721 if (unlikely(NULL == fsf_req)) {
4722 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4723 "the outbound (send) queue.\n");
4724 ret = -ENOMEM;
4725 goto failed_fsf_req;
4726 }
4727
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004728 fsf_req->adapter = adapter;
4729 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004730 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004731 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732
Swen Schillig41fa2ad2007-09-07 09:15:31 +02004733 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 this request completion */
4735 init_waitqueue_head(&fsf_req->completion_wq);
4736
4737 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004738 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004740
4741 /* this is serialized (we are holding req_queue-lock of adapter) */
4742 if (adapter->req_no == 0)
4743 adapter->req_no++;
4744 fsf_req->req_id = adapter->req_no++;
4745
4746 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747
4748 /*
4749 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4750 * if it is not set (see also *_open_qdio and *_close_qdio).
4751 */
4752
4753 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4754 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4755 ret = -EIO;
4756 goto failed_sbals;
4757 }
4758
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004759 if (fsf_req->qtcb) {
4760 fsf_req->seq_no = adapter->fsf_req_seq_no;
4761 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 fsf_req->sbal_number = 1;
4764 fsf_req->sbal_first = req_queue->free_index;
4765 fsf_req->sbal_curr = req_queue->free_index;
4766 fsf_req->sbale_curr = 1;
4767
4768 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4769 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4770 }
4771
4772 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4773
4774 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004775 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4777 if (likely(fsf_req->qtcb != NULL)) {
4778 sbale[1].addr = (void *) fsf_req->qtcb;
4779 sbale[1].length = sizeof(struct fsf_qtcb);
4780 }
4781
4782 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4783 fsf_req->sbal_number, fsf_req->sbal_first);
4784
4785 goto success;
4786
4787 failed_sbals:
4788/* dequeue new FSF request previously enqueued */
4789 zfcp_fsf_req_free(fsf_req);
4790 fsf_req = NULL;
4791
4792 failed_fsf_req:
4793 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4794 success:
4795 *fsf_req_p = fsf_req;
4796 return ret;
4797}
4798
4799/*
4800 * function: zfcp_fsf_req_send
4801 *
4802 * purpose: start transfer of FSF request via QDIO
4803 *
4804 * returns: 0 - request transfer succesfully started
4805 * !0 - start of request transfer failed
4806 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004807static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808{
4809 struct zfcp_adapter *adapter;
4810 struct zfcp_qdio_queue *req_queue;
4811 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004812 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 int new_distance_from_int;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004814 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 int retval = 0;
4816
4817 adapter = fsf_req->adapter;
4818 req_queue = &adapter->request_queue,
4819
4820
4821 /* FIXME(debug): remove it later */
4822 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4823 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4824 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4825 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4826 sbale[1].length);
4827
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004828 /* put allocated FSF request into hash table */
4829 spin_lock(&adapter->req_list_lock);
4830 zfcp_reqlist_add(adapter, fsf_req);
4831 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004833 inc_seq_no = (fsf_req->qtcb != NULL);
4834
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 ZFCP_LOG_TRACE("request queue of adapter %s: "
4836 "next free SBAL is %i, %i free SBALs\n",
4837 zfcp_get_busid_by_adapter(adapter),
4838 req_queue->free_index,
4839 atomic_read(&req_queue->free_count));
4840
4841 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4842 "index_in_queue=%i, count=%i, buffers=%p\n",
4843 zfcp_get_busid_by_adapter(adapter),
4844 QDIO_FLAG_SYNC_OUTPUT,
4845 0, fsf_req->sbal_first, fsf_req->sbal_number,
4846 &req_queue->buffer[fsf_req->sbal_first]);
4847
4848 /*
4849 * adjust the number of free SBALs in request queue as well as
4850 * position of first one
4851 */
4852 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4853 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4854 req_queue->free_index += fsf_req->sbal_number; /* increase */
4855 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4856 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4857
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004858 fsf_req->issued = get_clock();
4859
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 retval = do_QDIO(adapter->ccw_device,
4861 QDIO_FLAG_SYNC_OUTPUT,
4862 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4863
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004864 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4865 dbg_tmp[1] = (u64) retval;
4866 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4867
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 if (unlikely(retval)) {
4869 /* Queues are down..... */
4870 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004871 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004872 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004873 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004874 spin_unlock(&adapter->req_list_lock);
4875 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 zfcp_qdio_zero_sbals(req_queue->buffer,
4877 fsf_req->sbal_first, fsf_req->sbal_number);
4878 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004879 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4881 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004882 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 } else {
4884 req_queue->distance_from_int = new_distance_from_int;
4885 /*
4886 * increase FSF sequence counter -
4887 * this must only be done for request successfully enqueued to
4888 * QDIO this rejected requests may be cleaned up by calling
4889 * routines resulting in missing sequence counter values
4890 * otherwise,
4891 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004892
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004894 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004896
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004898 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 }
4900 return retval;
4901}
4902
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903#undef ZFCP_LOG_AREA