blob: a8b02542ac2da30aaaf9a953153d41e419c18da0 [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 *
83 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
84 * unsolicited requests) via helper functions
85 * Does some initial fsf request set-up.
86 *
87 * 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
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200159/**
160 * zfcp_fsf_req_dismiss - dismiss a single fsf request
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200162static void zfcp_fsf_req_dismiss(struct zfcp_adapter *adapter,
163 struct zfcp_fsf_req *fsf_req,
164 unsigned int counter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200166 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200168 dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
169 dbg_tmp[1] = (u64) counter;
170 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
171 list_del(&fsf_req->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
173 zfcp_fsf_req_complete(fsf_req);
174}
175
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200176/**
177 * zfcp_fsf_req_dismiss_all - dismiss all remaining fsf requests
178 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100179void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200180{
181 struct zfcp_fsf_req *request, *tmp;
182 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100183 LIST_HEAD(remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200184 unsigned int i, counter;
185
186 spin_lock_irqsave(&adapter->req_list_lock, flags);
187 atomic_set(&adapter->reqs_active, 0);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100188 for (i=0; i<REQUEST_LIST_SIZE; i++)
189 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200190
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200191 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
192
Swen Schillig6fcc4712007-02-07 13:17:57 +0100193 counter = 0;
194 list_for_each_entry_safe(request, tmp, &remove_queue, list) {
195 zfcp_fsf_req_dismiss(adapter, request, counter);
196 counter++;
197 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200198}
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200/*
201 * function: zfcp_fsf_req_complete
202 *
203 * purpose: Updates active counts and timers for openfcp-reqs
204 * May cleanup request after req_eval returns
205 *
206 * returns: 0 - success
207 * !0 - failure
208 *
209 * context:
210 */
211int
212zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
213{
214 int retval = 0;
215 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
218 ZFCP_LOG_DEBUG("Status read response received\n");
219 /*
220 * Note: all cleanup handling is done in the callchain of
221 * the function call-chain below.
222 */
223 zfcp_fsf_status_read_handler(fsf_req);
224 goto out;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200225 } else {
226 del_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 zfcp_fsf_protstatus_eval(fsf_req);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /*
231 * fsf_req may be deleted due to waking up functions, so
232 * cleanup is saved here and used later
233 */
234 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
235 cleanup = 1;
236 else
237 cleanup = 0;
238
239 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
240
241 /* cleanup request if requested by initiator */
242 if (likely(cleanup)) {
243 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
244 /*
245 * lock must not be held here since it will be
246 * grabed by the called routine, too
247 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200248 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 } else {
250 /* notify initiator waiting for the requests completion */
251 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
252 /*
253 * FIXME: Race! We must not access fsf_req here as it might have been
254 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
255 * flag. It's an improbable case. But, we have the same paranoia for
256 * the cleanup flag already.
257 * Might better be handled using complete()?
258 * (setting the flag and doing wakeup ought to be atomic
259 * with regard to checking the flag as long as waitqueue is
260 * part of the to be released structure)
261 */
262 wake_up(&fsf_req->completion_wq);
263 }
264
265 out:
266 return retval;
267}
268
269/*
270 * function: zfcp_fsf_protstatus_eval
271 *
272 * purpose: evaluates the QTCB of the finished FSF request
273 * and initiates appropriate actions
274 * (usually calling FSF command specific handlers)
275 *
276 * returns:
277 *
278 * context:
279 *
280 * locks:
281 */
282static int
283zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
284{
285 int retval = 0;
286 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200287 struct fsf_qtcb *qtcb = fsf_req->qtcb;
288 union fsf_prot_status_qual *prot_status_qual =
289 &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200291 zfcp_hba_dbf_event_fsf_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
294 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
295 (unsigned long) fsf_req);
296 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
297 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 goto skip_protstatus;
299 }
300
301 /* log additional information provided by FSF (if any) */
Heiko Carstens862794f2007-02-21 09:28:00 +0100302 if (likely(qtcb->header.log_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 /* do not trust them ;-) */
Heiko Carstens862794f2007-02-21 09:28:00 +0100304 if (unlikely(qtcb->header.log_start >
305 sizeof(struct fsf_qtcb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 ZFCP_LOG_NORMAL
307 ("bug: ULP (FSF logging) log data starts "
308 "beyond end of packet header. Ignored. "
309 "(start=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200310 qtcb->header.log_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 sizeof(struct fsf_qtcb));
312 goto forget_log;
313 }
Heiko Carstens862794f2007-02-21 09:28:00 +0100314 if (unlikely((size_t) (qtcb->header.log_start +
315 qtcb->header.log_length) >
316 sizeof(struct fsf_qtcb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
318 "beyond end of packet header. Ignored. "
319 "(start=%i, length=%i, size=%li)\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200320 qtcb->header.log_start,
321 qtcb->header.log_length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 sizeof(struct fsf_qtcb));
323 goto forget_log;
324 }
325 ZFCP_LOG_TRACE("ULP log data: \n");
326 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200327 (char *) qtcb + qtcb->header.log_start,
328 qtcb->header.log_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330 forget_log:
331
332 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200333 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 break;
338
339 case FSF_PROT_QTCB_VERSION_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 ZFCP_LOG_NORMAL("error: The adapter %s contains "
341 "microcode of version 0x%x, the device driver "
342 "only supports 0x%x. Aborting.\n",
343 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200344 prot_status_qual->version_error.fsf_version,
345 ZFCP_QTCB_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
348 break;
349
350 case FSF_PROT_SEQ_NUMB_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
352 "driver (0x%x) and adapter %s (0x%x). "
353 "Restarting all operations on this adapter.\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200354 qtcb->prefix.req_seq_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200356 prot_status_qual->sequence_error.exp_req_seq_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
359 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
360 break;
361
362 case FSF_PROT_UNSUPP_QTCB_TYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 ZFCP_LOG_NORMAL("error: Packet header type used by the "
364 "device driver is incompatible with "
365 "that used on adapter %s. "
366 "Stopping all operations on this adapter.\n",
367 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
370 break;
371
372 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
374 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
375 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 break;
377
378 case FSF_PROT_DUPLICATE_REQUEST_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
380 "to the adapter %s is ambiguous. "
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200381 "Stopping all operations on this adapter.\n",
382 *(unsigned long long*)
383 (&qtcb->bottom.support.req_handle),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 zfcp_erp_adapter_shutdown(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
387 break;
388
389 case FSF_PROT_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200390 zfcp_fsf_link_down_info_eval(adapter,
391 &prot_status_qual->link_down_info);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100392 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
394 break;
395
396 case FSF_PROT_REEST_QUEUE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397 ZFCP_LOG_NORMAL("The local link to adapter with "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 "%s was re-plugged. "
399 "Re-starting operations on this adapter.\n",
400 zfcp_get_busid_by_adapter(adapter));
401 /* All ports should be marked as ready to run again */
402 zfcp_erp_modify_adapter_status(adapter,
403 ZFCP_STATUS_COMMON_RUNNING,
404 ZFCP_SET);
405 zfcp_erp_adapter_reopen(adapter,
406 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
407 | ZFCP_STATUS_COMMON_ERP_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
409 break;
410
411 case FSF_PROT_ERROR_STATE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 ZFCP_LOG_NORMAL("error: The adapter %s "
413 "has entered the error state. "
414 "Restarting all operations on this "
415 "adapter.\n",
416 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
420 break;
421
422 default:
423 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
424 "provided by the adapter %s "
425 "is not compatible with the device driver. "
426 "Stopping all operations on this adapter. "
427 "(debug info 0x%x).\n",
428 zfcp_get_busid_by_adapter(adapter),
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200429 qtcb->prefix.prot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 zfcp_erp_adapter_shutdown(adapter, 0);
431 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
432 }
433
434 skip_protstatus:
435 /*
436 * always call specific handlers to give them a chance to do
437 * something meaningful even in error cases
438 */
439 zfcp_fsf_fsfstatus_eval(fsf_req);
440 return retval;
441}
442
443/*
444 * function: zfcp_fsf_fsfstatus_eval
445 *
446 * purpose: evaluates FSF status of completed FSF request
447 * and acts accordingly
448 *
449 * returns:
450 */
451static int
452zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
453{
454 int retval = 0;
455
456 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
457 goto skip_fsfstatus;
458 }
459
460 /* evaluate FSF Status */
461 switch (fsf_req->qtcb->header.fsf_status) {
462 case FSF_UNKNOWN_COMMAND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
464 "not known by the adapter %s "
465 "Stopping all operations on this adapter. "
466 "(debug info 0x%x).\n",
467 zfcp_get_busid_by_adapter(fsf_req->adapter),
468 fsf_req->qtcb->header.fsf_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
471 break;
472
473 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
475 "SCSI stack.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 break;
477
478 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
480 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482
483 skip_fsfstatus:
484 /*
485 * always call specific handlers to give them a chance to do
486 * something meaningful even in error cases
487 */
488 zfcp_fsf_req_dispatch(fsf_req);
489
490 return retval;
491}
492
493/*
494 * function: zfcp_fsf_fsfstatus_qual_eval
495 *
496 * purpose: evaluates FSF status-qualifier of completed FSF request
497 * and acts accordingly
498 *
499 * returns:
500 */
501static int
502zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
503{
504 int retval = 0;
505
506 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
507 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
509 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
512 break;
513 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
517 break;
518 case FSF_SQ_NO_RECOM:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
520 "problem on the adapter %s "
521 "Stopping all operations on this adapter. ",
522 zfcp_get_busid_by_adapter(fsf_req->adapter));
523 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
525 break;
526 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
528 "(adapter %s)\n",
529 zfcp_get_busid_by_adapter(fsf_req->adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
531 break;
532 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
533 case FSF_SQ_NO_RETRY_POSSIBLE:
534 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
535 /* dealt with in the respective functions */
536 break;
537 default:
538 ZFCP_LOG_NORMAL("bug: Additional status info could "
539 "not be interpreted properly.\n");
540 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
541 (char *) &fsf_req->qtcb->header.fsf_status_qual,
542 sizeof (union fsf_status_qual));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
544 break;
545 }
546
547 return retval;
548}
549
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200550/**
551 * zfcp_fsf_link_down_info_eval - evaluate link down information block
552 */
553static void
554zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
555 struct fsf_link_down_info *link_down)
556{
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100557 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
558 &adapter->status))
559 return;
560
561 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
562
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100563 if (link_down == NULL)
564 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100565
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200566 switch (link_down->error_code) {
567 case FSF_PSQ_LINK_NO_LIGHT:
568 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
569 "(no light detected)\n",
570 zfcp_get_busid_by_adapter(adapter));
571 break;
572 case FSF_PSQ_LINK_WRAP_PLUG:
573 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
574 "(wrap plug detected)\n",
575 zfcp_get_busid_by_adapter(adapter));
576 break;
577 case FSF_PSQ_LINK_NO_FCP:
578 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
579 "(adjacent node on link does not support FCP)\n",
580 zfcp_get_busid_by_adapter(adapter));
581 break;
582 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
583 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
584 "(firmware update in progress)\n",
585 zfcp_get_busid_by_adapter(adapter));
586 break;
587 case FSF_PSQ_LINK_INVALID_WWPN:
588 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
589 "(duplicate or invalid WWPN detected)\n",
590 zfcp_get_busid_by_adapter(adapter));
591 break;
592 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
593 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
594 "(no support for NPIV by Fabric)\n",
595 zfcp_get_busid_by_adapter(adapter));
596 break;
597 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
598 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
599 "(out of resource in FCP daughtercard)\n",
600 zfcp_get_busid_by_adapter(adapter));
601 break;
602 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
603 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
604 "(out of resource in Fabric)\n",
605 zfcp_get_busid_by_adapter(adapter));
606 break;
607 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
608 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
609 "(unable to Fabric login)\n",
610 zfcp_get_busid_by_adapter(adapter));
611 break;
612 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
613 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
614 zfcp_get_busid_by_adapter(adapter));
615 break;
616 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
617 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
618 zfcp_get_busid_by_adapter(adapter));
619 break;
620 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
621 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
622 zfcp_get_busid_by_adapter(adapter));
623 break;
624 default:
625 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
626 "(warning: unknown reason code %d)\n",
627 zfcp_get_busid_by_adapter(adapter),
628 link_down->error_code);
629 }
630
631 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
632 ZFCP_LOG_DEBUG("Debug information to link down: "
633 "primary_status=0x%02x "
634 "ioerr_code=0x%02x "
635 "action_code=0x%02x "
636 "reason_code=0x%02x "
637 "explanation_code=0x%02x "
638 "vendor_specific_code=0x%02x\n",
639 link_down->primary_status,
640 link_down->ioerr_code,
641 link_down->action_code,
642 link_down->reason_code,
643 link_down->explanation_code,
644 link_down->vendor_specific_code);
645
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100646 out:
647 zfcp_erp_adapter_failed(adapter);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200648}
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650/*
651 * function: zfcp_fsf_req_dispatch
652 *
653 * purpose: calls the appropriate command specific handler
654 *
655 * returns:
656 */
657static int
658zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
659{
660 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
661 struct zfcp_adapter *adapter = fsf_req->adapter;
662 int retval = 0;
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 switch (fsf_req->fsf_command) {
666
667 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 zfcp_fsf_send_fcp_command_handler(fsf_req);
669 break;
670
671 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 zfcp_fsf_abort_fcp_command_handler(fsf_req);
673 break;
674
675 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 zfcp_fsf_send_ct_handler(fsf_req);
677 break;
678
679 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 zfcp_fsf_open_port_handler(fsf_req);
681 break;
682
683 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 zfcp_fsf_open_unit_handler(fsf_req);
685 break;
686
687 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 zfcp_fsf_close_unit_handler(fsf_req);
689 break;
690
691 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 zfcp_fsf_close_port_handler(fsf_req);
693 break;
694
695 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 zfcp_fsf_close_physical_port_handler(fsf_req);
697 break;
698
699 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 zfcp_fsf_exchange_config_data_handler(fsf_req);
701 break;
702
703 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 zfcp_fsf_exchange_port_data_handler(fsf_req);
705 break;
706
707 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 zfcp_fsf_send_els_handler(fsf_req);
709 break;
710
711 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 zfcp_fsf_control_file_handler(fsf_req);
713 break;
714
715 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 zfcp_fsf_control_file_handler(fsf_req);
717 break;
718
719 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
721 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
722 "not supported by the adapter %s\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200723 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
725 ZFCP_LOG_NORMAL
726 ("bug: Command issued by the device driver differs "
727 "from the command returned by the adapter %s "
728 "(debug info 0x%x, 0x%x).\n",
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200729 zfcp_get_busid_by_adapter(adapter),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 fsf_req->fsf_command,
731 fsf_req->qtcb->header.fsf_command);
732 }
733
734 if (!erp_action)
735 return retval;
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 zfcp_erp_async_handler(erp_action, 0);
738
739 return retval;
740}
741
742/*
743 * function: zfcp_fsf_status_read
744 *
745 * purpose: initiates a Status Read command at the specified adapter
746 *
747 * returns:
748 */
749int
750zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
751{
752 struct zfcp_fsf_req *fsf_req;
753 struct fsf_status_read_buffer *status_buffer;
754 unsigned long lock_flags;
755 volatile struct qdio_buffer_element *sbale;
756 int retval = 0;
757
758 /* setup new FSF request */
759 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
760 req_flags | ZFCP_REQ_NO_QTCB,
761 adapter->pool.fsf_req_status_read,
762 &lock_flags, &fsf_req);
763 if (retval < 0) {
764 ZFCP_LOG_INFO("error: Could not create unsolicited status "
765 "buffer for adapter %s.\n",
766 zfcp_get_busid_by_adapter(adapter));
767 goto failed_req_create;
768 }
769
770 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
771 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
772 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
773 fsf_req->sbale_curr = 2;
774
775 status_buffer =
776 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
777 if (!status_buffer) {
778 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
779 goto failed_buf;
780 }
781 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200782 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 /* insert pointer to respective buffer */
785 sbale = zfcp_qdio_sbale_curr(fsf_req);
786 sbale->addr = (void *) status_buffer;
787 sbale->length = sizeof(struct fsf_status_read_buffer);
788
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200789 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if (retval) {
791 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
792 "environment.\n");
793 goto failed_req_send;
794 }
795
796 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
797 zfcp_get_busid_by_adapter(adapter));
798 goto out;
799
800 failed_req_send:
801 mempool_free(status_buffer, adapter->pool.data_status_read);
802
803 failed_buf:
804 zfcp_fsf_req_free(fsf_req);
805 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200806 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 out:
808 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
809 return retval;
810}
811
812static int
813zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
814{
815 struct fsf_status_read_buffer *status_buffer;
816 struct zfcp_adapter *adapter;
817 struct zfcp_port *port;
818 unsigned long flags;
819
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200820 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 adapter = fsf_req->adapter;
822
823 read_lock_irqsave(&zfcp_data.config_lock, flags);
824 list_for_each_entry(port, &adapter->port_list_head, list)
825 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
826 break;
827 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
828
829 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
830 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200831 "nonexisting port with d_id 0x%06x on "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 "adapter %s. Ignored.\n",
833 status_buffer->d_id & ZFCP_DID_MASK,
834 zfcp_get_busid_by_adapter(adapter));
835 goto out;
836 }
837
838 switch (status_buffer->status_subtype) {
839
840 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
842 zfcp_erp_port_reopen(port, 0);
843 break;
844
845 case FSF_STATUS_READ_SUB_ERROR_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
847 zfcp_erp_port_shutdown(port, 0);
848 break;
849
850 default:
851 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
852 debug_exception(adapter->erp_dbf, 0,
853 &status_buffer->status_subtype, sizeof (u32));
854 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
855 "for a reopen indication on port with "
Christof Schmitt1d589ed2007-05-08 11:14:41 +0200856 "d_id 0x%06x on the adapter %s. "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 "Ignored. (debug info 0x%x)\n",
858 status_buffer->d_id,
859 zfcp_get_busid_by_adapter(adapter),
860 status_buffer->status_subtype);
861 }
862 out:
863 return 0;
864}
865
866/*
867 * function: zfcp_fsf_status_read_handler
868 *
869 * purpose: is called for finished Open Port command
870 *
871 * returns:
872 */
873static int
874zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
875{
876 int retval = 0;
877 struct zfcp_adapter *adapter = fsf_req->adapter;
878 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200879 (struct fsf_status_read_buffer *) fsf_req->data;
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200880 struct fsf_bit_error_payload *fsf_bit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200883 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200885 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 goto out;
887 }
888
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200889 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 switch (status_buffer->status_type) {
892
893 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 zfcp_fsf_status_read_port_closed(fsf_req);
895 break;
896
897 case FSF_STATUS_READ_INCOMING_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 zfcp_fsf_incoming_els(fsf_req);
899 break;
900
901 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
903 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 break;
905
906 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Ralph Wuerthnerb7a52fa2006-05-22 18:21:28 +0200907 fsf_bit_error = (struct fsf_bit_error_payload *)
908 status_buffer->payload;
909 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
910 "received (adapter %s, "
911 "link failures = %i, loss of sync errors = %i, "
912 "loss of signal errors = %i, "
913 "primitive sequence errors = %i, "
914 "invalid transmission word errors = %i, "
915 "CRC errors = %i)\n",
916 zfcp_get_busid_by_adapter(adapter),
917 fsf_bit_error->link_failure_error_count,
918 fsf_bit_error->loss_of_sync_error_count,
919 fsf_bit_error->loss_of_signal_error_count,
920 fsf_bit_error->primitive_sequence_error_count,
921 fsf_bit_error->invalid_transmission_word_error_count,
922 fsf_bit_error->crc_error_count);
923 ZFCP_LOG_INFO("Additional bit error threshold data "
924 "(adapter %s, "
925 "primitive sequence event time-outs = %i, "
926 "elastic buffer overrun errors = %i, "
927 "advertised receive buffer-to-buffer credit = %i, "
928 "current receice buffer-to-buffer credit = %i, "
929 "advertised transmit buffer-to-buffer credit = %i, "
930 "current transmit buffer-to-buffer credit = %i)\n",
931 zfcp_get_busid_by_adapter(adapter),
932 fsf_bit_error->primitive_sequence_event_timeout_count,
933 fsf_bit_error->elastic_buffer_overrun_error_count,
934 fsf_bit_error->advertised_receive_b2b_credit,
935 fsf_bit_error->current_receive_b2b_credit,
936 fsf_bit_error->advertised_transmit_b2b_credit,
937 fsf_bit_error->current_transmit_b2b_credit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 break;
939
940 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200941 switch (status_buffer->status_subtype) {
942 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
943 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
944 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100945 zfcp_fsf_link_down_info_eval(adapter,
946 (struct fsf_link_down_info *)
947 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200948 break;
949 case FSF_STATUS_READ_SUB_FDISC_FAILED:
950 ZFCP_LOG_INFO("Local link to adapter %s is down "
951 "due to failed FDISC login\n",
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100952 zfcp_get_busid_by_adapter(adapter));
953 zfcp_fsf_link_down_info_eval(adapter,
954 (struct fsf_link_down_info *)
955 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200956 break;
957 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
958 ZFCP_LOG_INFO("Local link to adapter %s is down "
959 "due to firmware update on adapter\n",
960 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100961 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200962 break;
963 default:
964 ZFCP_LOG_INFO("Local link to adapter %s is down "
965 "due to unknown reason\n",
966 zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100967 zfcp_fsf_link_down_info_eval(adapter, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200968 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 break;
970
971 case FSF_STATUS_READ_LINK_UP:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200972 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100973 "Restarting operations on this adapter\n",
974 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 /* All ports should be marked as ready to run again */
976 zfcp_erp_modify_adapter_status(adapter,
977 ZFCP_STATUS_COMMON_RUNNING,
978 ZFCP_SET);
979 zfcp_erp_adapter_reopen(adapter,
980 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
981 | ZFCP_STATUS_COMMON_ERP_FAILED);
982 break;
983
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100984 case FSF_STATUS_READ_NOTIFICATION_LOST:
985 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
986 "adapter %s%s%s%s%s%s%s%s%s\n",
987 zfcp_get_busid_by_adapter(adapter),
988 (status_buffer->status_subtype &
989 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
990 ", incoming ELS" : "",
991 (status_buffer->status_subtype &
992 FSF_STATUS_READ_SUB_SENSE_DATA) ?
993 ", sense data" : "",
994 (status_buffer->status_subtype &
995 FSF_STATUS_READ_SUB_LINK_STATUS) ?
996 ", link status change" : "",
997 (status_buffer->status_subtype &
998 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
999 ", port close" : "",
1000 (status_buffer->status_subtype &
1001 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
1002 ", bit error exception" : "",
1003 (status_buffer->status_subtype &
1004 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
1005 ", ACT update" : "",
1006 (status_buffer->status_subtype &
1007 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
1008 ", ACT hardening" : "",
1009 (status_buffer->status_subtype &
1010 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
1011 ", adapter feature change" : "");
1012
1013 if (status_buffer->status_subtype &
1014 FSF_STATUS_READ_SUB_ACT_UPDATED)
1015 zfcp_erp_adapter_access_changed(adapter);
1016 break;
1017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 case FSF_STATUS_READ_CFDC_UPDATED:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001019 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 zfcp_get_busid_by_adapter(adapter));
1021 zfcp_erp_adapter_access_changed(adapter);
1022 break;
1023
1024 case FSF_STATUS_READ_CFDC_HARDENED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 switch (status_buffer->status_subtype) {
1026 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001027 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 zfcp_get_busid_by_adapter(adapter));
1029 break;
1030 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001031 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 "to the secondary SE\n",
1033 zfcp_get_busid_by_adapter(adapter));
1034 break;
1035 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001036 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 zfcp_get_busid_by_adapter(adapter));
1038 }
1039 break;
1040
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001041 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1042 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1043 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1044 "been changed from 0x%08X to 0x%08X\n",
1045 zfcp_get_busid_by_adapter(adapter),
1046 *(u32*) (status_buffer->payload + 4),
1047 *(u32*) (status_buffer->payload));
1048 adapter->adapter_features = *(u32*) status_buffer->payload;
1049 break;
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 default:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001052 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 "type was received (debug info 0x%x)\n",
1054 status_buffer->status_type);
1055 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1056 status_buffer);
1057 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1058 (char *) status_buffer,
1059 sizeof (struct fsf_status_read_buffer));
1060 break;
1061 }
1062 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +02001063 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 /*
1065 * recycle buffer and start new request repeat until outbound
1066 * queue is empty or adapter shutdown is requested
1067 */
1068 /*
1069 * FIXME(qdio):
1070 * we may wait in the req_create for 5s during shutdown, so
1071 * qdio_cleanup will have to wait at least that long before returning
1072 * with failure to allow us a proper cleanup under all circumstances
1073 */
1074 /*
1075 * FIXME:
1076 * allocation failure possible? (Is this code needed?)
1077 */
1078 retval = zfcp_fsf_status_read(adapter, 0);
1079 if (retval < 0) {
1080 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1081 "request for the adapter %s.\n",
1082 zfcp_get_busid_by_adapter(adapter));
1083 /* temporary fix to avoid status read buffer shortage */
1084 adapter->status_read_failed++;
1085 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1086 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1087 ZFCP_LOG_INFO("restart adapter %s due to status read "
1088 "buffer shortage\n",
1089 zfcp_get_busid_by_adapter(adapter));
1090 zfcp_erp_adapter_reopen(adapter, 0);
1091 }
1092 }
1093 out:
1094 return retval;
1095}
1096
1097/*
1098 * function: zfcp_fsf_abort_fcp_command
1099 *
1100 * purpose: tells FSF to abort a running SCSI command
1101 *
1102 * returns: address of initiated FSF request
1103 * NULL - request could not be initiated
1104 *
1105 * FIXME(design): should be watched by a timeout !!!
1106 * FIXME(design) shouldn't this be modified to return an int
1107 * also...don't know how though
1108 */
1109struct zfcp_fsf_req *
1110zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1111 struct zfcp_adapter *adapter,
1112 struct zfcp_unit *unit, int req_flags)
1113{
1114 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001116 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 int retval = 0;
1118
1119 /* setup new FSF request */
1120 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1121 req_flags, adapter->pool.fsf_req_abort,
1122 &lock_flags, &fsf_req);
1123 if (retval < 0) {
1124 ZFCP_LOG_INFO("error: Failed to create an abort command "
1125 "request for lun 0x%016Lx on port 0x%016Lx "
1126 "on adapter %s.\n",
1127 unit->fcp_lun,
1128 unit->port->wwpn,
1129 zfcp_get_busid_by_adapter(adapter));
1130 goto out;
1131 }
1132
1133 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1134 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1135 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1136
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001137 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
1139 /* set handles of unit and its parent port in QTCB */
1140 fsf_req->qtcb->header.lun_handle = unit->handle;
1141 fsf_req->qtcb->header.port_handle = unit->port->handle;
1142
1143 /* set handle of request which should be aborted */
1144 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1145
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001146 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1147 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 ZFCP_LOG_INFO("error: Failed to send abort command request "
1150 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1151 zfcp_get_busid_by_adapter(adapter),
1152 unit->port->wwpn, unit->fcp_lun);
1153 zfcp_fsf_req_free(fsf_req);
1154 fsf_req = NULL;
1155 goto out;
1156 }
1157
1158 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001159 "(adapter%s, port d_id=0x%06x, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 "unit x%016Lx, old_req_id=0x%lx)\n",
1161 zfcp_get_busid_by_adapter(adapter),
1162 unit->port->d_id,
1163 unit->fcp_lun, old_req_id);
1164 out:
1165 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1166 return fsf_req;
1167}
1168
1169/*
1170 * function: zfcp_fsf_abort_fcp_command_handler
1171 *
1172 * purpose: is called for finished Abort FCP Command request
1173 *
1174 * returns:
1175 */
1176static int
1177zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1178{
1179 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001180 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 unsigned char status_qual =
1182 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1185 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1186 goto skip_fsfstatus;
1187 }
1188
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001189 unit = (struct zfcp_unit *) new_fsf_req->data;
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 /* evaluate FSF status in QTCB */
1192 switch (new_fsf_req->qtcb->header.fsf_status) {
1193
1194 case FSF_PORT_HANDLE_NOT_VALID:
1195 if (status_qual >> 4 != status_qual % 0xf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1197 "fsf_s_phand_nv0");
1198 /*
1199 * In this case a command that was sent prior to a port
1200 * reopen was aborted (handles are different). This is
1201 * fine.
1202 */
1203 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1205 "port 0x%016Lx on adapter %s invalid. "
1206 "This may happen occasionally.\n",
1207 unit->port->handle,
1208 unit->port->wwpn,
1209 zfcp_get_busid_by_unit(unit));
1210 ZFCP_LOG_INFO("status qualifier:\n");
1211 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1212 (char *) &new_fsf_req->qtcb->header.
1213 fsf_status_qual,
1214 sizeof (union fsf_status_qual));
1215 /* Let's hope this sorts out the mess */
1216 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1217 "fsf_s_phand_nv1");
1218 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1219 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1220 }
1221 break;
1222
1223 case FSF_LUN_HANDLE_NOT_VALID:
1224 if (status_qual >> 4 != status_qual % 0xf) {
1225 /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1227 "fsf_s_lhand_nv0");
1228 /*
1229 * In this case a command that was sent prior to a unit
1230 * reopen was aborted (handles are different).
1231 * This is fine.
1232 */
1233 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 ZFCP_LOG_INFO
1235 ("Warning: Temporary LUN identifier 0x%x of LUN "
1236 "0x%016Lx on port 0x%016Lx on adapter %s is "
1237 "invalid. This may happen in rare cases. "
1238 "Trying to re-establish link.\n",
1239 unit->handle,
1240 unit->fcp_lun,
1241 unit->port->wwpn,
1242 zfcp_get_busid_by_unit(unit));
1243 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1244 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1245 (char *) &new_fsf_req->qtcb->header.
1246 fsf_status_qual,
1247 sizeof (union fsf_status_qual));
1248 /* Let's hope this sorts out the mess */
1249 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1250 "fsf_s_lhand_nv1");
1251 zfcp_erp_port_reopen(unit->port, 0);
1252 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1253 }
1254 break;
1255
1256 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 retval = 0;
1258 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1259 "fsf_s_no_exist");
1260 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1261 break;
1262
1263 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1265 "be reopened\n", unit->port->wwpn,
1266 zfcp_get_busid_by_unit(unit));
1267 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1268 "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001269 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1271 | ZFCP_STATUS_FSFREQ_RETRY;
1272 break;
1273
1274 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 ZFCP_LOG_INFO(
1276 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1277 "to be reopened\n",
1278 unit->fcp_lun, unit->port->wwpn,
1279 zfcp_get_busid_by_unit(unit));
1280 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001281 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1283 | ZFCP_STATUS_FSFREQ_RETRY;
1284 break;
1285
1286 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1288 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1290 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001291 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1293 break;
1294 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 /* SCSI stack will escalate */
1296 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1297 "fsf_sq_ulp");
1298 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1299 break;
1300 default:
1301 ZFCP_LOG_NORMAL
1302 ("bug: Wrong status qualifier 0x%x arrived.\n",
1303 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1304 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1305 "fsf_sq_inval:");
1306 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1307 &new_fsf_req->qtcb->header.
1308 fsf_status_qual.word[0], sizeof (u32));
1309 break;
1310 }
1311 break;
1312
1313 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 retval = 0;
1315 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1316 break;
1317
1318 default:
1319 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1320 "(debug info 0x%x)\n",
1321 new_fsf_req->qtcb->header.fsf_status);
1322 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1323 "fsf_s_inval:");
1324 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1325 &new_fsf_req->qtcb->header.fsf_status,
1326 sizeof (u32));
1327 break;
1328 }
1329 skip_fsfstatus:
1330 return retval;
1331}
1332
1333/**
1334 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1335 * one SBALE
1336 * Two scatter-gather lists are passed, one for the reqeust and one for the
1337 * response.
1338 */
1339static inline int
1340zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1341 struct scatterlist *resp, int resp_count)
1342{
1343 return ((req_count == 1) &&
1344 (resp_count == 1) &&
1345 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1346 PAGE_MASK) ==
1347 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1348 req[0].length - 1) & PAGE_MASK)) &&
1349 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1350 PAGE_MASK) ==
1351 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1352 resp[0].length - 1) & PAGE_MASK)));
1353}
1354
1355/**
1356 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1357 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1358 * the request
1359 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1360 * a struct zfcp_fsf_req
1361 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1362 * is sent within error recovery
1363 */
1364int
1365zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1366 struct zfcp_erp_action *erp_action)
1367{
1368 volatile struct qdio_buffer_element *sbale;
1369 struct zfcp_port *port;
1370 struct zfcp_adapter *adapter;
1371 struct zfcp_fsf_req *fsf_req;
1372 unsigned long lock_flags;
1373 int bytes;
1374 int ret = 0;
1375
1376 port = ct->port;
1377 adapter = port->adapter;
1378
1379 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1380 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1381 pool, &lock_flags, &fsf_req);
1382 if (ret < 0) {
1383 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1384 "adapter: %s\n",
1385 zfcp_get_busid_by_adapter(adapter));
1386 goto failed_req;
1387 }
1388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1390 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1391 ct->resp, ct->resp_count)){
1392 /* both request buffer and response buffer
1393 fit into one sbale each */
1394 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1395 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1396 sbale[2].length = ct->req[0].length;
1397 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1398 sbale[3].length = ct->resp[0].length;
1399 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001400 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1402 /* try to use chained SBALs */
1403 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1404 SBAL_FLAGS0_TYPE_WRITE_READ,
1405 ct->req, ct->req_count,
1406 ZFCP_MAX_SBALS_PER_CT_REQ);
1407 if (bytes <= 0) {
1408 ZFCP_LOG_INFO("error: creation of CT request failed "
1409 "on adapter %s\n",
1410 zfcp_get_busid_by_adapter(adapter));
1411 if (bytes == 0)
1412 ret = -ENOMEM;
1413 else
1414 ret = bytes;
1415
1416 goto failed_send;
1417 }
1418 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1419 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1420 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1421 SBAL_FLAGS0_TYPE_WRITE_READ,
1422 ct->resp, ct->resp_count,
1423 ZFCP_MAX_SBALS_PER_CT_REQ);
1424 if (bytes <= 0) {
1425 ZFCP_LOG_INFO("error: creation of CT request failed "
1426 "on adapter %s\n",
1427 zfcp_get_busid_by_adapter(adapter));
1428 if (bytes == 0)
1429 ret = -ENOMEM;
1430 else
1431 ret = bytes;
1432
1433 goto failed_send;
1434 }
1435 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1436 } else {
1437 /* reject send generic request */
1438 ZFCP_LOG_INFO(
1439 "error: microcode does not support chained SBALs,"
1440 "CT request too big (adapter %s)\n",
1441 zfcp_get_busid_by_adapter(adapter));
1442 ret = -EOPNOTSUPP;
1443 goto failed_send;
1444 }
1445
1446 /* settings in QTCB */
1447 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001448 fsf_req->qtcb->bottom.support.service_class =
1449 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001451 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001453 zfcp_san_dbf_event_ct_request(fsf_req);
1454
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001455 if (erp_action) {
1456 erp_action->fsf_req = fsf_req;
1457 fsf_req->erp_action = erp_action;
1458 zfcp_erp_start_timer(fsf_req);
1459 } else
1460 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1461
1462 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 if (ret) {
1464 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1465 "(adapter %s, port 0x%016Lx)\n",
1466 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1467 goto failed_send;
1468 }
1469
1470 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1471 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1472 goto out;
1473
1474 failed_send:
1475 zfcp_fsf_req_free(fsf_req);
1476 if (erp_action != NULL) {
1477 erp_action->fsf_req = NULL;
1478 }
1479 failed_req:
1480 out:
1481 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1482 lock_flags);
1483 return ret;
1484}
1485
1486/**
1487 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1488 * @fsf_req: pointer to struct zfcp_fsf_req
1489 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001490 * Data specific for the Generic Service request is passed using
1491 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1492 * Usually a specific handler for the CT request is called which is
1493 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 */
1495static int
1496zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1497{
1498 struct zfcp_port *port;
1499 struct zfcp_adapter *adapter;
1500 struct zfcp_send_ct *send_ct;
1501 struct fsf_qtcb_header *header;
1502 struct fsf_qtcb_bottom_support *bottom;
1503 int retval = -EINVAL;
1504 u16 subtable, rule, counter;
1505
1506 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001507 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 port = send_ct->port;
1509 header = &fsf_req->qtcb->header;
1510 bottom = &fsf_req->qtcb->bottom.support;
1511
1512 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1513 goto skip_fsfstatus;
1514
1515 /* evaluate FSF status in QTCB */
1516 switch (header->fsf_status) {
1517
1518 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001519 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 retval = 0;
1521 break;
1522
1523 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001524 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1525 "class %d.\n",
1526 zfcp_get_busid_by_port(port),
1527 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 /* stop operation for this adapter */
1529 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1530 zfcp_erp_adapter_shutdown(adapter, 0);
1531 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1532 break;
1533
1534 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 switch (header->fsf_status_qual.word[0]){
1536 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 /* reopening link to port */
1538 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1539 zfcp_test_link(port);
1540 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1541 break;
1542 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 /* ERP strategy will escalate */
1544 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1545 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1546 break;
1547 default:
1548 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1549 "arrived.\n",
1550 header->fsf_status_qual.word[0]);
1551 break;
1552 }
1553 break;
1554
1555 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001557 "command (adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 zfcp_get_busid_by_port(port), port->d_id);
1559 for (counter = 0; counter < 2; counter++) {
1560 subtable = header->fsf_status_qual.halfword[counter * 2];
1561 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1562 switch (subtable) {
1563 case FSF_SQ_CFDC_SUBTABLE_OS:
1564 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1565 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1566 case FSF_SQ_CFDC_SUBTABLE_LUN:
1567 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1568 zfcp_act_subtable_type[subtable], rule);
1569 break;
1570 }
1571 }
1572 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1573 zfcp_erp_port_access_denied(port);
1574 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1575 break;
1576
1577 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 ZFCP_LOG_INFO("generic service command rejected "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001579 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 zfcp_get_busid_by_port(port), port->d_id);
1581 ZFCP_LOG_INFO("status qualifier:\n");
1582 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1583 (char *) &header->fsf_status_qual,
1584 sizeof (union fsf_status_qual));
1585 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1587 break;
1588
1589 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1591 "0x%016Lx on adapter %s invalid. This may "
1592 "happen occasionally.\n", port->handle,
1593 port->wwpn, zfcp_get_busid_by_port(port));
1594 ZFCP_LOG_INFO("status qualifier:\n");
1595 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1596 (char *) &header->fsf_status_qual,
1597 sizeof (union fsf_status_qual));
1598 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1599 zfcp_erp_adapter_reopen(adapter, 0);
1600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1601 break;
1602
1603 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 ZFCP_LOG_INFO("port needs to be reopened "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001605 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 zfcp_get_busid_by_port(port), port->d_id);
1607 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001608 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1610 | ZFCP_STATUS_FSFREQ_RETRY;
1611 break;
1612
1613 /* following states should never occure, all cases avoided
1614 in zfcp_fsf_send_ct - but who knows ... */
1615 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1617 "req_buf_length=%d, resp_buf_length=%d)\n",
1618 zfcp_get_busid_by_adapter(adapter),
1619 bottom->req_buf_length, bottom->resp_buf_length);
1620 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1621 break;
1622 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1624 "req_buf_length=%d)\n",
1625 zfcp_get_busid_by_adapter(adapter),
1626 bottom->req_buf_length);
1627 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1628 break;
1629 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1631 "resp_buf_length=%d)\n",
1632 zfcp_get_busid_by_adapter(adapter),
1633 bottom->resp_buf_length);
1634 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1635 break;
1636 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1638 "resp_buf_length=%d)\n",
1639 zfcp_get_busid_by_adapter(adapter),
1640 bottom->req_buf_length, bottom->resp_buf_length);
1641 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1642 break;
1643
1644 default:
1645 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1646 "(debug info 0x%x)\n", header->fsf_status);
1647 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1648 debug_exception(adapter->erp_dbf, 0,
1649 &header->fsf_status_qual.word[0], sizeof (u32));
1650 break;
1651 }
1652
1653skip_fsfstatus:
1654 send_ct->status = retval;
1655
1656 if (send_ct->handler != NULL)
1657 send_ct->handler(send_ct->handler_data);
1658
1659 return retval;
1660}
1661
1662/**
1663 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1664 * @els: pointer to struct zfcp_send_els which contains all needed data for
1665 * the command.
1666 */
1667int
1668zfcp_fsf_send_els(struct zfcp_send_els *els)
1669{
1670 volatile struct qdio_buffer_element *sbale;
1671 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001672 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 struct zfcp_adapter *adapter;
1674 unsigned long lock_flags;
1675 int bytes;
1676 int ret = 0;
1677
1678 d_id = els->d_id;
1679 adapter = els->adapter;
1680
1681 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1682 ZFCP_REQ_AUTO_CLEANUP,
1683 NULL, &lock_flags, &fsf_req);
1684 if (ret < 0) {
1685 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001686 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 zfcp_get_busid_by_adapter(adapter), d_id);
1688 goto failed_req;
1689 }
1690
1691 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1692 if (zfcp_use_one_sbal(els->req, els->req_count,
1693 els->resp, els->resp_count)){
1694 /* both request buffer and response buffer
1695 fit into one sbale each */
1696 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1697 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1698 sbale[2].length = els->req[0].length;
1699 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1700 sbale[3].length = els->resp[0].length;
1701 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001702 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1704 /* try to use chained SBALs */
1705 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1706 SBAL_FLAGS0_TYPE_WRITE_READ,
1707 els->req, els->req_count,
1708 ZFCP_MAX_SBALS_PER_ELS_REQ);
1709 if (bytes <= 0) {
1710 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001711 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 zfcp_get_busid_by_adapter(adapter), d_id);
1713 if (bytes == 0) {
1714 ret = -ENOMEM;
1715 } else {
1716 ret = bytes;
1717 }
1718 goto failed_send;
1719 }
1720 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1721 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1722 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1723 SBAL_FLAGS0_TYPE_WRITE_READ,
1724 els->resp, els->resp_count,
1725 ZFCP_MAX_SBALS_PER_ELS_REQ);
1726 if (bytes <= 0) {
1727 ZFCP_LOG_INFO("error: creation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001728 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 zfcp_get_busid_by_adapter(adapter), d_id);
1730 if (bytes == 0) {
1731 ret = -ENOMEM;
1732 } else {
1733 ret = bytes;
1734 }
1735 goto failed_send;
1736 }
1737 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1738 } else {
1739 /* reject request */
1740 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1741 ", ELS request too big (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001742 "port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 zfcp_get_busid_by_adapter(adapter), d_id);
1744 ret = -EOPNOTSUPP;
1745 goto failed_send;
1746 }
1747
1748 /* settings in QTCB */
1749 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001750 fsf_req->qtcb->bottom.support.service_class =
1751 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001753 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1756
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001757 zfcp_san_dbf_event_els_request(fsf_req);
1758
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001759 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1760 ret = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 if (ret) {
1762 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001763 "(adapter %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 zfcp_get_busid_by_adapter(adapter), d_id);
1765 goto failed_send;
1766 }
1767
1768 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001769 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 goto out;
1771
1772 failed_send:
1773 zfcp_fsf_req_free(fsf_req);
1774
1775 failed_req:
1776 out:
1777 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1778 lock_flags);
1779
1780 return ret;
1781}
1782
1783/**
1784 * zfcp_fsf_send_els_handler - handler for ELS commands
1785 * @fsf_req: pointer to struct zfcp_fsf_req
1786 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001787 * Data specific for the ELS command is passed using
1788 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1789 * Usually a specific handler for the ELS command is called which is
1790 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 */
1792static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1793{
1794 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001796 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 struct fsf_qtcb_header *header;
1798 struct fsf_qtcb_bottom_support *bottom;
1799 struct zfcp_send_els *send_els;
1800 int retval = -EINVAL;
1801 u16 subtable, rule, counter;
1802
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001803 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001805 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 d_id = send_els->d_id;
1807 header = &fsf_req->qtcb->header;
1808 bottom = &fsf_req->qtcb->bottom.support;
1809
1810 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1811 goto skip_fsfstatus;
1812
1813 switch (header->fsf_status) {
1814
1815 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001816 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 retval = 0;
1818 break;
1819
1820 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02001821 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1822 "class %d.\n",
1823 zfcp_get_busid_by_adapter(adapter),
1824 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 /* stop operation for this adapter */
1826 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1827 zfcp_erp_adapter_shutdown(adapter, 0);
1828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 break;
1830
1831 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 switch (header->fsf_status_qual.word[0]){
1833 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001835 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1836 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1838 break;
1839 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1841 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1842 retval =
1843 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1844 (struct zfcp_ls_rjt_par *)
1845 &header->fsf_status_qual.word[2]);
1846 break;
1847 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1849 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1850 break;
1851 default:
1852 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1853 header->fsf_status_qual.word[0]);
1854 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1855 (char*)header->fsf_status_qual.word, 16);
1856 }
1857 break;
1858
1859 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1861 "prohibited sending "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001862 "(adapter: %s, port d_id: 0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 zfcp_get_busid_by_adapter(adapter), d_id);
1864
1865 break;
1866
1867 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 ZFCP_LOG_INFO(
1869 "ELS request size and ELS response size must be either "
1870 "both 0, or both greater than 0 "
1871 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1872 zfcp_get_busid_by_adapter(adapter),
1873 bottom->req_buf_length,
1874 bottom->resp_buf_length);
1875 break;
1876
1877 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 ZFCP_LOG_INFO(
1879 "Length of the ELS request buffer, "
1880 "specified in QTCB bottom, "
1881 "exceeds the size of the buffers "
1882 "that have been allocated for ELS request data "
1883 "(adapter: %s, req_buf_length=%d)\n",
1884 zfcp_get_busid_by_adapter(adapter),
1885 bottom->req_buf_length);
1886 break;
1887
1888 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 ZFCP_LOG_INFO(
1890 "Length of the ELS response buffer, "
1891 "specified in QTCB bottom, "
1892 "exceeds the size of the buffers "
1893 "that have been allocated for ELS response data "
1894 "(adapter: %s, resp_buf_length=%d)\n",
1895 zfcp_get_busid_by_adapter(adapter),
1896 bottom->resp_buf_length);
1897 break;
1898
1899 case FSF_SBAL_MISMATCH:
1900 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1902 "resp_buf_length=%d)\n",
1903 zfcp_get_busid_by_adapter(adapter),
1904 bottom->req_buf_length, bottom->resp_buf_length);
1905 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1906 break;
1907
1908 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001910 "(adapter %s, port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 zfcp_get_busid_by_adapter(adapter), d_id);
1912 for (counter = 0; counter < 2; counter++) {
1913 subtable = header->fsf_status_qual.halfword[counter * 2];
1914 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1915 switch (subtable) {
1916 case FSF_SQ_CFDC_SUBTABLE_OS:
1917 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1918 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1919 case FSF_SQ_CFDC_SUBTABLE_LUN:
1920 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1921 zfcp_act_subtable_type[subtable], rule);
1922 break;
1923 }
1924 }
1925 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 if (port != NULL)
1927 zfcp_erp_port_access_denied(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1929 break;
1930
1931 default:
1932 ZFCP_LOG_NORMAL(
1933 "bug: An unknown FSF Status was presented "
1934 "(adapter: %s, fsf_status=0x%08x)\n",
1935 zfcp_get_busid_by_adapter(adapter),
1936 header->fsf_status);
1937 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1938 debug_exception(adapter->erp_dbf, 0,
1939 &header->fsf_status_qual.word[0], sizeof(u32));
1940 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1941 break;
1942 }
1943
1944skip_fsfstatus:
1945 send_els->status = retval;
1946
1947 if (send_els->handler != 0)
1948 send_els->handler(send_els->handler_data);
1949
1950 return retval;
1951}
1952
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953int
1954zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1955{
1956 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001957 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 unsigned long lock_flags;
1959 int retval = 0;
1960
1961 /* setup new FSF request */
1962 retval = zfcp_fsf_req_create(erp_action->adapter,
1963 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1964 ZFCP_REQ_AUTO_CLEANUP,
1965 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001966 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 if (retval < 0) {
1968 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1969 "data request for adapter %s.\n",
1970 zfcp_get_busid_by_adapter(erp_action->adapter));
1971 goto out;
1972 }
1973
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001974 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1976 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1977
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001978 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001979 FSF_FEATURE_CFDC |
1980 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001981 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001982 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001983 fsf_req->erp_action = erp_action;
1984 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001986 zfcp_erp_start_timer(fsf_req);
1987 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 if (retval) {
1989 ZFCP_LOG_INFO
1990 ("error: Could not send exchange configuration data "
1991 "command on the adapter %s\n",
1992 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001993 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 erp_action->fsf_req = NULL;
1995 goto out;
1996 }
1997
1998 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1999 "(adapter %s)\n",
2000 zfcp_get_busid_by_adapter(erp_action->adapter));
2001
2002 out:
2003 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2004 lock_flags);
2005 return retval;
2006}
2007
2008/**
2009 * zfcp_fsf_exchange_config_evaluate
2010 * @fsf_req: fsf_req which belongs to xchg config data request
2011 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2012 *
2013 * returns: -EIO on error, 0 otherwise
2014 */
2015static int
2016zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2017{
2018 struct fsf_qtcb_bottom_config *bottom;
2019 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002020 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
2022 bottom = &fsf_req->qtcb->bottom.config;
2023 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2024 bottom->low_qtcb_version, bottom->high_qtcb_version);
2025 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002026 adapter->adapter_features = bottom->adapter_features;
2027 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05002028 adapter->peer_wwpn = 0;
2029 adapter->peer_wwnn = 0;
2030 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 if (xchg_ok) {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002033 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2034 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2035 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2036 fc_host_speed(shost) = bottom->fc_link_speed;
2037 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 adapter->hydra_version = bottom->adapter_type;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002039 if (fc_host_permanent_port_name(shost) == -1)
2040 fc_host_permanent_port_name(shost) =
2041 fc_host_port_name(shost);
2042 if (bottom->fc_topology == FSF_TOPO_P2P) {
2043 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2044 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2045 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2046 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2047 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2048 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2049 else if (bottom->fc_topology == FSF_TOPO_AL)
2050 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2051 else
2052 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002054 fc_host_node_name(shost) = 0;
2055 fc_host_port_name(shost) = 0;
2056 fc_host_port_id(shost) = 0;
2057 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002058 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 adapter->hydra_version = 0;
2060 }
2061
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002062 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002064 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2065 min(FC_SERIAL_NUMBER_SIZE, 17));
2066 EBCASC(fc_host_serial_number(shost),
2067 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 }
2069
6f71d9b2005-04-10 23:04:28 -05002070 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002071 "WWNN 0x%016Lx, "
2072 "WWPN 0x%016Lx, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002073 "S_ID 0x%06x,\n"
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02002074 "adapter version 0x%x, "
2075 "LIC version 0x%x, "
2076 "FC link speed %d Gb/s\n",
2077 zfcp_get_busid_by_adapter(adapter),
2078 (wwn_t) fc_host_node_name(shost),
2079 (wwn_t) fc_host_port_name(shost),
2080 fc_host_port_id(shost),
2081 adapter->hydra_version,
2082 adapter->fsf_lic_version,
2083 fc_host_speed(shost));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2085 ZFCP_LOG_NORMAL("error: the adapter %s "
2086 "only supports newer control block "
2087 "versions in comparison to this device "
2088 "driver (try updated device driver)\n",
2089 zfcp_get_busid_by_adapter(adapter));
2090 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2091 zfcp_erp_adapter_shutdown(adapter, 0);
2092 return -EIO;
2093 }
2094 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2095 ZFCP_LOG_NORMAL("error: the adapter %s "
2096 "only supports older control block "
2097 "versions than this device driver uses"
2098 "(consider a microcode upgrade)\n",
2099 zfcp_get_busid_by_adapter(adapter));
2100 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2101 zfcp_erp_adapter_shutdown(adapter, 0);
2102 return -EIO;
2103 }
2104 return 0;
2105}
2106
2107/*
2108 * function: zfcp_fsf_exchange_config_data_handler
2109 *
2110 * purpose: is called for finished Exchange Configuration Data command
2111 *
2112 * returns:
2113 */
2114static int
2115zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2116{
2117 struct fsf_qtcb_bottom_config *bottom;
2118 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002119 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2122 return -EIO;
2123
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002124 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
2126 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2128 return -EIO;
2129
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002130 switch (fc_host_port_type(adapter->scsi_host)) {
2131 case FC_PORTTYPE_PTP:
6f71d9b2005-04-10 23:04:28 -05002132 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2133 "configuration detected at adapter %s\n"
2134 "Peer WWNN 0x%016llx, "
2135 "peer WWPN 0x%016llx, "
2136 "peer d_id 0x%06x\n",
2137 zfcp_get_busid_by_adapter(adapter),
2138 adapter->peer_wwnn,
2139 adapter->peer_wwpn,
2140 adapter->peer_d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2142 "top-p-to-p");
6f71d9b2005-04-10 23:04:28 -05002143 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002144 case FC_PORTTYPE_NLPORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2146 "topology detected at adapter %s "
2147 "unsupported, shutting down adapter\n",
2148 zfcp_get_busid_by_adapter(adapter));
2149 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2150 "top-al");
2151 zfcp_erp_adapter_shutdown(adapter, 0);
2152 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002153 case FC_PORTTYPE_NPORT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002154 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 "network detected at adapter %s.\n",
2156 zfcp_get_busid_by_adapter(adapter));
2157 break;
2158 default:
2159 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2160 "reported by the exchange "
2161 "configuration command for "
2162 "the adapter %s is not "
2163 "of a type known to the zfcp "
2164 "driver, shutting down adapter\n",
2165 zfcp_get_busid_by_adapter(adapter));
2166 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2167 "unknown-topo");
2168 zfcp_erp_adapter_shutdown(adapter, 0);
2169 return -EIO;
2170 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002171 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2173 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2174 "allowed by the adapter %s "
2175 "is lower than the minimum "
2176 "required by the driver (%ld bytes).\n",
2177 bottom->max_qtcb_size,
2178 zfcp_get_busid_by_adapter(adapter),
2179 sizeof(struct fsf_qtcb));
2180 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2181 "qtcb-size");
2182 debug_event(fsf_req->adapter->erp_dbf, 0,
2183 &bottom->max_qtcb_size, sizeof (u32));
2184 zfcp_erp_adapter_shutdown(adapter, 0);
2185 return -EIO;
2186 }
2187 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2188 &adapter->status);
2189 break;
2190 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2191 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2192
2193 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2194 return -EIO;
2195
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002196 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2197
2198 zfcp_fsf_link_down_info_eval(adapter,
2199 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 break;
2201 default:
2202 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2203 debug_event(fsf_req->adapter->erp_dbf, 0,
2204 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2205 zfcp_erp_adapter_shutdown(adapter, 0);
2206 return -EIO;
2207 }
2208 return 0;
2209}
2210
2211/**
2212 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002213 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 * @adapter: for which port data is requested
2215 * @data: response to exchange port data request
2216 */
2217int
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002218zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2219 struct zfcp_adapter *adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 struct fsf_qtcb_bottom_port *data)
2221{
2222 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002224 unsigned long lock_flags;
2225 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002227 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 ZFCP_LOG_INFO("error: exchange port data "
2229 "command not supported by adapter %s\n",
2230 zfcp_get_busid_by_adapter(adapter));
2231 return -EOPNOTSUPP;
2232 }
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 /* setup new FSF request */
2235 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Andreas Herrmann2448c452005-12-01 02:50:36 +01002236 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
Heiko Carstensd2c993d2006-07-12 16:41:55 +02002237 NULL, &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 if (retval < 0) {
2239 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2240 "exchange port data request for"
2241 "the adapter %s.\n",
2242 zfcp_get_busid_by_adapter(adapter));
2243 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2244 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002245 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002246 }
2247
2248 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01002249 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002250
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2252 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2253 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2254
Andreas Herrmann2448c452005-12-01 02:50:36 +01002255 if (erp_action) {
2256 erp_action->fsf_req = fsf_req;
2257 fsf_req->erp_action = erp_action;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002258 zfcp_erp_start_timer(fsf_req);
2259 } else
2260 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002262 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 if (retval) {
2264 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2265 "command on the adapter %s\n",
2266 zfcp_get_busid_by_adapter(adapter));
2267 zfcp_fsf_req_free(fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002268 if (erp_action)
2269 erp_action->fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2271 lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002272 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 }
2274
Andreas Herrmann2448c452005-12-01 02:50:36 +01002275 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Andreas Herrmann2448c452005-12-01 02:50:36 +01002277 if (!erp_action) {
2278 wait_event(fsf_req->completion_wq,
2279 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002280 zfcp_fsf_req_free(fsf_req);
Andreas Herrmann2448c452005-12-01 02:50:36 +01002281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 return retval;
2283}
2284
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002285/**
2286 * zfcp_fsf_exchange_port_evaluate
2287 * @fsf_req: fsf_req which belongs to xchg port data request
2288 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2289 */
2290static void
2291zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2292{
2293 struct zfcp_adapter *adapter;
2294 struct fsf_qtcb *qtcb;
2295 struct fsf_qtcb_bottom_port *bottom, *data;
2296 struct Scsi_Host *shost;
2297
2298 adapter = fsf_req->adapter;
2299 qtcb = fsf_req->qtcb;
2300 bottom = &qtcb->bottom.port;
2301 shost = adapter->scsi_host;
2302
2303 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2304 if (data)
2305 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2306
2307 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2308 fc_host_permanent_port_name(shost) = bottom->wwpn;
2309 else
2310 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2311 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2312 fc_host_supported_speeds(shost) = bottom->supported_speed;
2313}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
2315/**
2316 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2317 * @fsf_req: pointer to struct zfcp_fsf_req
2318 */
2319static void
2320zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2321{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002322 struct zfcp_adapter *adapter;
2323 struct fsf_qtcb *qtcb;
2324
2325 adapter = fsf_req->adapter;
2326 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
2328 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2329 return;
2330
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002331 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002333 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002334 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002335 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002336 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002337 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002338 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002339 zfcp_fsf_link_down_info_eval(adapter,
2340 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 default:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002343 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2344 debug_event(adapter->erp_dbf, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2346 }
2347}
2348
2349
2350/*
2351 * function: zfcp_fsf_open_port
2352 *
2353 * purpose:
2354 *
2355 * returns: address of initiated FSF request
2356 * NULL - request could not be initiated
2357 */
2358int
2359zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2360{
2361 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002362 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 unsigned long lock_flags;
2364 int retval = 0;
2365
2366 /* setup new FSF request */
2367 retval = zfcp_fsf_req_create(erp_action->adapter,
2368 FSF_QTCB_OPEN_PORT_WITH_DID,
2369 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2370 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002371 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 if (retval < 0) {
2373 ZFCP_LOG_INFO("error: Could not create open port request "
2374 "for port 0x%016Lx on adapter %s.\n",
2375 erp_action->port->wwpn,
2376 zfcp_get_busid_by_adapter(erp_action->adapter));
2377 goto out;
2378 }
2379
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002380 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2382 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2383
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002384 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002386 fsf_req->data = (unsigned long) erp_action->port;
2387 fsf_req->erp_action = erp_action;
2388 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002390 zfcp_erp_start_timer(fsf_req);
2391 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 if (retval) {
2393 ZFCP_LOG_INFO("error: Could not send open port request for "
2394 "port 0x%016Lx on adapter %s.\n",
2395 erp_action->port->wwpn,
2396 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002397 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 erp_action->fsf_req = NULL;
2399 goto out;
2400 }
2401
2402 ZFCP_LOG_DEBUG("open port request initiated "
2403 "(adapter %s, port 0x%016Lx)\n",
2404 zfcp_get_busid_by_adapter(erp_action->adapter),
2405 erp_action->port->wwpn);
2406 out:
2407 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2408 lock_flags);
2409 return retval;
2410}
2411
2412/*
2413 * function: zfcp_fsf_open_port_handler
2414 *
2415 * purpose: is called for finished Open Port command
2416 *
2417 * returns:
2418 */
2419static int
2420zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2421{
2422 int retval = -EINVAL;
2423 struct zfcp_port *port;
2424 struct fsf_plogi *plogi;
2425 struct fsf_qtcb_header *header;
2426 u16 subtable, rule, counter;
2427
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002428 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 header = &fsf_req->qtcb->header;
2430
2431 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2432 /* don't change port status in our bookkeeping */
2433 goto skip_fsfstatus;
2434 }
2435
2436 /* evaluate FSF status in QTCB */
2437 switch (header->fsf_status) {
2438
2439 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2441 "is already open.\n",
2442 port->wwpn, zfcp_get_busid_by_port(port));
2443 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2444 "fsf_s_popen");
2445 /*
2446 * This is a bug, however operation should continue normally
2447 * if it is simply ignored
2448 */
2449 break;
2450
2451 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2453 "on adapter %s\n",
2454 port->wwpn, zfcp_get_busid_by_port(port));
2455 for (counter = 0; counter < 2; counter++) {
2456 subtable = header->fsf_status_qual.halfword[counter * 2];
2457 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2458 switch (subtable) {
2459 case FSF_SQ_CFDC_SUBTABLE_OS:
2460 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2461 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2462 case FSF_SQ_CFDC_SUBTABLE_LUN:
2463 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2464 zfcp_act_subtable_type[subtable], rule);
2465 break;
2466 }
2467 }
2468 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2469 zfcp_erp_port_access_denied(port);
2470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2471 break;
2472
2473 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2475 "The remote port 0x%016Lx on adapter %s "
2476 "could not be opened. Disabling it.\n",
2477 port->wwpn, zfcp_get_busid_by_port(port));
2478 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2479 "fsf_s_max_ports");
2480 zfcp_erp_port_failed(port);
2481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2482 break;
2483
2484 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 switch (header->fsf_status_qual.word[0]) {
2486 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2488 "fsf_sq_ltest");
2489 /* ERP strategy will escalate */
2490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2491 break;
2492 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2493 /* ERP strategy will escalate */
2494 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2495 "fsf_sq_ulp");
2496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2497 break;
2498 case FSF_SQ_NO_RETRY_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2500 "adapter %s could not be opened. "
2501 "Disabling it.\n",
2502 port->wwpn,
2503 zfcp_get_busid_by_port(port));
2504 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2505 "fsf_sq_no_retry");
2506 zfcp_erp_port_failed(port);
2507 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2508 break;
2509 default:
2510 ZFCP_LOG_NORMAL
2511 ("bug: Wrong status qualifier 0x%x arrived.\n",
2512 header->fsf_status_qual.word[0]);
2513 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2514 "fsf_sq_inval:");
2515 debug_exception(
2516 fsf_req->adapter->erp_dbf, 0,
2517 &header->fsf_status_qual.word[0],
2518 sizeof (u32));
2519 break;
2520 }
2521 break;
2522
2523 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 /* save port handle assigned by FSF */
2525 port->handle = header->port_handle;
2526 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2527 "was opened, it's port handle is 0x%x\n",
2528 port->wwpn, zfcp_get_busid_by_port(port),
2529 port->handle);
2530 /* mark port as open */
2531 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2532 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002533 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2534 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2535 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 retval = 0;
2537 /* check whether D_ID has changed during open */
2538 /*
2539 * FIXME: This check is not airtight, as the FCP channel does
2540 * not monitor closures of target port connections caused on
2541 * the remote side. Thus, they might miss out on invalidating
2542 * locally cached WWPNs (and other N_Port parameters) of gone
2543 * target ports. So, our heroic attempt to make things safe
2544 * could be undermined by 'open port' response data tagged with
2545 * obsolete WWPNs. Another reason to monitor potential
2546 * connection closures ourself at least (by interpreting
2547 * incoming ELS' and unsolicited status). It just crosses my
2548 * mind that one should be able to cross-check by means of
2549 * another GID_PN straight after a port has been opened.
2550 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2551 */
2552 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2553 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2554 {
2555 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002556 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 ZFCP_LOG_INFO(
2558 "warning: insufficient length of "
2559 "PLOGI payload (%i)\n",
2560 fsf_req->qtcb->bottom.support.els1_length);
2561 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2562 "fsf_s_short_plogi:");
2563 /* skip sanity check and assume wwpn is ok */
2564 } else {
2565 if (plogi->serv_param.wwpn != port->wwpn) {
2566 ZFCP_LOG_INFO("warning: d_id of port "
2567 "0x%016Lx changed during "
2568 "open\n", port->wwpn);
2569 debug_text_event(
2570 fsf_req->adapter->erp_dbf, 0,
2571 "fsf_s_did_change:");
2572 atomic_clear_mask(
2573 ZFCP_STATUS_PORT_DID_DID,
2574 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002575 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 port->wwnn = plogi->serv_param.wwnn;
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002577 zfcp_plogi_evaluate(port, plogi);
2578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 }
2580 }
2581 break;
2582
2583 case FSF_UNKNOWN_OP_SUBTYPE:
2584 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2586 "op_subtype=0x%x)\n",
2587 zfcp_get_busid_by_port(port),
2588 fsf_req->qtcb->bottom.support.operation_subtype);
2589 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2590 break;
2591
2592 default:
2593 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2594 "(debug info 0x%x)\n",
2595 header->fsf_status);
2596 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2597 debug_exception(fsf_req->adapter->erp_dbf, 0,
2598 &header->fsf_status, sizeof (u32));
2599 break;
2600 }
2601
2602 skip_fsfstatus:
2603 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2604 return retval;
2605}
2606
2607/*
2608 * function: zfcp_fsf_close_port
2609 *
2610 * purpose: submit FSF command "close port"
2611 *
2612 * returns: address of initiated FSF request
2613 * NULL - request could not be initiated
2614 */
2615int
2616zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2617{
2618 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002619 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 unsigned long lock_flags;
2621 int retval = 0;
2622
2623 /* setup new FSF request */
2624 retval = zfcp_fsf_req_create(erp_action->adapter,
2625 FSF_QTCB_CLOSE_PORT,
2626 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2627 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002628 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 if (retval < 0) {
2630 ZFCP_LOG_INFO("error: Could not create a close port request "
2631 "for port 0x%016Lx on adapter %s.\n",
2632 erp_action->port->wwpn,
2633 zfcp_get_busid_by_adapter(erp_action->adapter));
2634 goto out;
2635 }
2636
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002637 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2639 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2640
2641 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002642 fsf_req->data = (unsigned long) erp_action->port;
2643 fsf_req->erp_action = erp_action;
2644 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2645 fsf_req->erp_action = erp_action;
2646 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002648 zfcp_erp_start_timer(fsf_req);
2649 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if (retval) {
2651 ZFCP_LOG_INFO("error: Could not send a close port request for "
2652 "port 0x%016Lx on adapter %s.\n",
2653 erp_action->port->wwpn,
2654 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002655 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 erp_action->fsf_req = NULL;
2657 goto out;
2658 }
2659
2660 ZFCP_LOG_TRACE("close port request initiated "
2661 "(adapter %s, port 0x%016Lx)\n",
2662 zfcp_get_busid_by_adapter(erp_action->adapter),
2663 erp_action->port->wwpn);
2664 out:
2665 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2666 lock_flags);
2667 return retval;
2668}
2669
2670/*
2671 * function: zfcp_fsf_close_port_handler
2672 *
2673 * purpose: is called for finished Close Port FSF command
2674 *
2675 * returns:
2676 */
2677static int
2678zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2679{
2680 int retval = -EINVAL;
2681 struct zfcp_port *port;
2682
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002683 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
2685 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2686 /* don't change port status in our bookkeeping */
2687 goto skip_fsfstatus;
2688 }
2689
2690 /* evaluate FSF status in QTCB */
2691 switch (fsf_req->qtcb->header.fsf_status) {
2692
2693 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2695 "0x%016Lx on adapter %s invalid. This may happen "
2696 "occasionally.\n", port->handle,
2697 port->wwpn, zfcp_get_busid_by_port(port));
2698 ZFCP_LOG_DEBUG("status qualifier:\n");
2699 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2700 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2701 sizeof (union fsf_status_qual));
2702 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2703 "fsf_s_phand_nv");
2704 zfcp_erp_adapter_reopen(port->adapter, 0);
2705 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2706 break;
2707
2708 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 /* Note: FSF has actually closed the port in this case.
2710 * The status code is just daft. Fingers crossed for a change
2711 */
2712 retval = 0;
2713 break;
2714
2715 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2717 "port handle 0x%x\n", port->wwpn,
2718 zfcp_get_busid_by_port(port), port->handle);
2719 zfcp_erp_modify_port_status(port,
2720 ZFCP_STATUS_COMMON_OPEN,
2721 ZFCP_CLEAR);
2722 retval = 0;
2723 break;
2724
2725 default:
2726 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2727 "(debug info 0x%x)\n",
2728 fsf_req->qtcb->header.fsf_status);
2729 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2730 debug_exception(fsf_req->adapter->erp_dbf, 0,
2731 &fsf_req->qtcb->header.fsf_status,
2732 sizeof (u32));
2733 break;
2734 }
2735
2736 skip_fsfstatus:
2737 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2738 return retval;
2739}
2740
2741/*
2742 * function: zfcp_fsf_close_physical_port
2743 *
2744 * purpose: submit FSF command "close physical port"
2745 *
2746 * returns: address of initiated FSF request
2747 * NULL - request could not be initiated
2748 */
2749int
2750zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2751{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002753 struct zfcp_fsf_req *fsf_req;
2754 unsigned long lock_flags;
2755 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
2757 /* setup new FSF request */
2758 retval = zfcp_fsf_req_create(erp_action->adapter,
2759 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2760 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2761 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002762 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 if (retval < 0) {
2764 ZFCP_LOG_INFO("error: Could not create close physical port "
2765 "request (adapter %s, port 0x%016Lx)\n",
2766 zfcp_get_busid_by_adapter(erp_action->adapter),
2767 erp_action->port->wwpn);
2768
2769 goto out;
2770 }
2771
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002772 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2774 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2775
2776 /* mark port as being closed */
2777 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2778 &erp_action->port->status);
2779 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002780 fsf_req->data = (unsigned long) erp_action->port;
2781 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2782 fsf_req->erp_action = erp_action;
2783 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002785 zfcp_erp_start_timer(fsf_req);
2786 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 if (retval) {
2788 ZFCP_LOG_INFO("error: Could not send close physical port "
2789 "request (adapter %s, port 0x%016Lx)\n",
2790 zfcp_get_busid_by_adapter(erp_action->adapter),
2791 erp_action->port->wwpn);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002792 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 erp_action->fsf_req = NULL;
2794 goto out;
2795 }
2796
2797 ZFCP_LOG_TRACE("close physical port request initiated "
2798 "(adapter %s, port 0x%016Lx)\n",
2799 zfcp_get_busid_by_adapter(erp_action->adapter),
2800 erp_action->port->wwpn);
2801 out:
2802 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2803 lock_flags);
2804 return retval;
2805}
2806
2807/*
2808 * function: zfcp_fsf_close_physical_port_handler
2809 *
2810 * purpose: is called for finished Close Physical Port FSF command
2811 *
2812 * returns:
2813 */
2814static int
2815zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2816{
2817 int retval = -EINVAL;
2818 struct zfcp_port *port;
2819 struct zfcp_unit *unit;
2820 struct fsf_qtcb_header *header;
2821 u16 subtable, rule, counter;
2822
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002823 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 header = &fsf_req->qtcb->header;
2825
2826 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2827 /* don't change port status in our bookkeeping */
2828 goto skip_fsfstatus;
2829 }
2830
2831 /* evaluate FSF status in QTCB */
2832 switch (header->fsf_status) {
2833
2834 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2836 "(adapter %s, port 0x%016Lx). "
2837 "This may happen occasionally.\n",
2838 port->handle,
2839 zfcp_get_busid_by_port(port),
2840 port->wwpn);
2841 ZFCP_LOG_DEBUG("status qualifier:\n");
2842 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2843 (char *) &header->fsf_status_qual,
2844 sizeof (union fsf_status_qual));
2845 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2846 "fsf_s_phand_nv");
2847 zfcp_erp_adapter_reopen(port->adapter, 0);
2848 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2849 break;
2850
2851 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 ZFCP_LOG_NORMAL("Access denied, cannot close "
2853 "physical port 0x%016Lx on adapter %s\n",
2854 port->wwpn, zfcp_get_busid_by_port(port));
2855 for (counter = 0; counter < 2; counter++) {
2856 subtable = header->fsf_status_qual.halfword[counter * 2];
2857 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2858 switch (subtable) {
2859 case FSF_SQ_CFDC_SUBTABLE_OS:
2860 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2861 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2862 case FSF_SQ_CFDC_SUBTABLE_LUN:
2863 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2864 zfcp_act_subtable_type[subtable], rule);
2865 break;
2866 }
2867 }
2868 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2869 zfcp_erp_port_access_denied(port);
2870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2871 break;
2872
2873 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2875 "%s needs to be reopened but it was attempted "
2876 "to close it physically.\n",
2877 port->wwpn,
2878 zfcp_get_busid_by_port(port));
2879 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002880 zfcp_erp_port_boxed(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2882 ZFCP_STATUS_FSFREQ_RETRY;
2883 break;
2884
2885 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 switch (header->fsf_status_qual.word[0]) {
2887 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2889 "fsf_sq_ltest");
2890 /* This will now be escalated by ERP */
2891 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2892 break;
2893 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 /* ERP strategy will escalate */
2895 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2896 "fsf_sq_ulp");
2897 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2898 break;
2899 default:
2900 ZFCP_LOG_NORMAL
2901 ("bug: Wrong status qualifier 0x%x arrived.\n",
2902 header->fsf_status_qual.word[0]);
2903 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2904 "fsf_sq_inval:");
2905 debug_exception(
2906 fsf_req->adapter->erp_dbf, 0,
2907 &header->fsf_status_qual.word[0], sizeof (u32));
2908 break;
2909 }
2910 break;
2911
2912 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2914 "physically closed, port handle 0x%x\n",
2915 port->wwpn,
2916 zfcp_get_busid_by_port(port), port->handle);
2917 /* can't use generic zfcp_erp_modify_port_status because
2918 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2919 */
2920 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2921 list_for_each_entry(unit, &port->unit_list_head, list)
2922 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2923 retval = 0;
2924 break;
2925
2926 default:
2927 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2928 "(debug info 0x%x)\n",
2929 header->fsf_status);
2930 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2931 debug_exception(fsf_req->adapter->erp_dbf, 0,
2932 &header->fsf_status, sizeof (u32));
2933 break;
2934 }
2935
2936 skip_fsfstatus:
2937 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2938 return retval;
2939}
2940
2941/*
2942 * function: zfcp_fsf_open_unit
2943 *
2944 * purpose:
2945 *
2946 * returns:
2947 *
2948 * assumptions: This routine does not check whether the associated
2949 * remote port has already been opened. This should be
2950 * done by calling routines. Otherwise some status
2951 * may be presented by FSF
2952 */
2953int
2954zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2955{
2956 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002957 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 unsigned long lock_flags;
2959 int retval = 0;
2960
2961 /* setup new FSF request */
2962 retval = zfcp_fsf_req_create(erp_action->adapter,
2963 FSF_QTCB_OPEN_LUN,
2964 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2965 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002966 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 if (retval < 0) {
2968 ZFCP_LOG_INFO("error: Could not create open unit request for "
2969 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2970 erp_action->unit->fcp_lun,
2971 erp_action->unit->port->wwpn,
2972 zfcp_get_busid_by_adapter(erp_action->adapter));
2973 goto out;
2974 }
2975
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002976 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2978 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2979
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002980 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2981 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002982 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002983 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02002984 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002986 fsf_req->data = (unsigned long) erp_action->unit;
2987 fsf_req->erp_action = erp_action;
2988 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002990 zfcp_erp_start_timer(fsf_req);
2991 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 if (retval) {
2993 ZFCP_LOG_INFO("error: Could not send an open unit request "
2994 "on the adapter %s, port 0x%016Lx for "
2995 "unit 0x%016Lx\n",
2996 zfcp_get_busid_by_adapter(erp_action->adapter),
2997 erp_action->port->wwpn,
2998 erp_action->unit->fcp_lun);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002999 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 erp_action->fsf_req = NULL;
3001 goto out;
3002 }
3003
3004 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3005 "port 0x%016Lx, unit 0x%016Lx)\n",
3006 zfcp_get_busid_by_adapter(erp_action->adapter),
3007 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3008 out:
3009 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3010 lock_flags);
3011 return retval;
3012}
3013
3014/*
3015 * function: zfcp_fsf_open_unit_handler
3016 *
3017 * purpose: is called for finished Open LUN command
3018 *
3019 * returns:
3020 */
3021static int
3022zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3023{
3024 int retval = -EINVAL;
3025 struct zfcp_adapter *adapter;
3026 struct zfcp_unit *unit;
3027 struct fsf_qtcb_header *header;
3028 struct fsf_qtcb_bottom_support *bottom;
3029 struct fsf_queue_designator *queue_designator;
3030 u16 subtable, rule, counter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003031 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003033 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034
3035 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3036 /* don't change unit status in our bookkeeping */
3037 goto skip_fsfstatus;
3038 }
3039
3040 adapter = fsf_req->adapter;
3041 header = &fsf_req->qtcb->header;
3042 bottom = &fsf_req->qtcb->bottom.support;
3043 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3044
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02003046 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 ZFCP_STATUS_UNIT_SHARED |
3048 ZFCP_STATUS_UNIT_READONLY,
3049 &unit->status);
3050
3051 /* evaluate FSF status in QTCB */
3052 switch (header->fsf_status) {
3053
3054 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3056 "for port 0x%016Lx on adapter %s invalid "
3057 "This may happen occasionally\n",
3058 unit->port->handle,
3059 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3060 ZFCP_LOG_DEBUG("status qualifier:\n");
3061 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3062 (char *) &header->fsf_status_qual,
3063 sizeof (union fsf_status_qual));
3064 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3065 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3066 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3067 break;
3068
3069 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3071 "remote port 0x%016Lx on adapter %s twice.\n",
3072 unit->fcp_lun,
3073 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3074 debug_text_exception(adapter->erp_dbf, 0,
3075 "fsf_s_uopen");
3076 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3077 break;
3078
3079 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3081 "remote port 0x%016Lx on adapter %s\n",
3082 unit->fcp_lun, unit->port->wwpn,
3083 zfcp_get_busid_by_unit(unit));
3084 for (counter = 0; counter < 2; counter++) {
3085 subtable = header->fsf_status_qual.halfword[counter * 2];
3086 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3087 switch (subtable) {
3088 case FSF_SQ_CFDC_SUBTABLE_OS:
3089 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3090 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3091 case FSF_SQ_CFDC_SUBTABLE_LUN:
3092 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3093 zfcp_act_subtable_type[subtable], rule);
3094 break;
3095 }
3096 }
3097 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3098 zfcp_erp_unit_access_denied(unit);
3099 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3100 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3101 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3102 break;
3103
3104 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3106 "needs to be reopened\n",
3107 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3108 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003109 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3111 ZFCP_STATUS_FSFREQ_RETRY;
3112 break;
3113
3114 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 if (header->fsf_status_qual.word[0] != 0) {
3116 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3117 "with WWPN 0x%Lx "
3118 "connected to the adapter %s "
3119 "is already in use in LPAR%d, CSS%d\n",
3120 unit->fcp_lun,
3121 unit->port->wwpn,
3122 zfcp_get_busid_by_unit(unit),
3123 queue_designator->hla,
3124 queue_designator->cssid);
3125 } else {
3126 subtable = header->fsf_status_qual.halfword[4];
3127 rule = header->fsf_status_qual.halfword[5];
3128 switch (subtable) {
3129 case FSF_SQ_CFDC_SUBTABLE_OS:
3130 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3131 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3132 case FSF_SQ_CFDC_SUBTABLE_LUN:
3133 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3134 "remote port with WWPN 0x%Lx "
3135 "connected to the adapter %s "
3136 "is denied (%s rule %d)\n",
3137 unit->fcp_lun,
3138 unit->port->wwpn,
3139 zfcp_get_busid_by_unit(unit),
3140 zfcp_act_subtable_type[subtable],
3141 rule);
3142 break;
3143 }
3144 }
3145 ZFCP_LOG_DEBUG("status qualifier:\n");
3146 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3147 (char *) &header->fsf_status_qual,
3148 sizeof (union fsf_status_qual));
3149 debug_text_event(adapter->erp_dbf, 2,
3150 "fsf_s_l_sh_vio");
3151 zfcp_erp_unit_access_denied(unit);
3152 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3153 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3155 break;
3156
3157 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3159 "There is no handle (temporary port identifier) "
3160 "available for unit 0x%016Lx on port 0x%016Lx "
3161 "on adapter %s\n",
3162 unit->fcp_lun,
3163 unit->port->wwpn,
3164 zfcp_get_busid_by_unit(unit));
3165 debug_text_event(adapter->erp_dbf, 1,
3166 "fsf_s_max_units");
3167 zfcp_erp_unit_failed(unit);
3168 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3169 break;
3170
3171 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 switch (header->fsf_status_qual.word[0]) {
3173 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 /* Re-establish link to port */
3175 debug_text_event(adapter->erp_dbf, 1,
3176 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003177 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3179 break;
3180 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 /* ERP strategy will escalate */
3182 debug_text_event(adapter->erp_dbf, 1,
3183 "fsf_sq_ulp");
3184 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3185 break;
3186 default:
3187 ZFCP_LOG_NORMAL
3188 ("bug: Wrong status qualifier 0x%x arrived.\n",
3189 header->fsf_status_qual.word[0]);
3190 debug_text_event(adapter->erp_dbf, 0,
3191 "fsf_sq_inval:");
3192 debug_exception(adapter->erp_dbf, 0,
3193 &header->fsf_status_qual.word[0],
3194 sizeof (u32));
3195 }
3196 break;
3197
3198 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 ZFCP_LOG_NORMAL(
3200 "Invalid option 0x%x has been specified "
3201 "in QTCB bottom sent to the adapter %s\n",
3202 bottom->option,
3203 zfcp_get_busid_by_adapter(adapter));
3204 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3205 retval = -EINVAL;
3206 break;
3207
3208 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 /* save LUN handle assigned by FSF */
3210 unit->handle = header->lun_handle;
3211 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3212 "adapter %s opened, port handle 0x%x\n",
3213 unit->fcp_lun,
3214 unit->port->wwpn,
3215 zfcp_get_busid_by_unit(unit),
3216 unit->handle);
3217 /* mark unit as open */
3218 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003219
3220 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3221 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3222 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3223 exclusive = (bottom->lun_access_info &
3224 FSF_UNIT_ACCESS_EXCLUSIVE);
3225 readwrite = (bottom->lun_access_info &
3226 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3227
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 if (!exclusive)
3229 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3230 &unit->status);
3231
3232 if (!readwrite) {
3233 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3234 &unit->status);
3235 ZFCP_LOG_NORMAL("read-only access for unit "
3236 "(adapter %s, wwpn=0x%016Lx, "
3237 "fcp_lun=0x%016Lx)\n",
3238 zfcp_get_busid_by_unit(unit),
3239 unit->port->wwpn,
3240 unit->fcp_lun);
3241 }
3242
3243 if (exclusive && !readwrite) {
3244 ZFCP_LOG_NORMAL("exclusive access of read-only "
3245 "unit not supported\n");
3246 zfcp_erp_unit_failed(unit);
3247 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3248 zfcp_erp_unit_shutdown(unit, 0);
3249 } else if (!exclusive && readwrite) {
3250 ZFCP_LOG_NORMAL("shared access of read-write "
3251 "unit not supported\n");
3252 zfcp_erp_unit_failed(unit);
3253 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3254 zfcp_erp_unit_shutdown(unit, 0);
3255 }
3256 }
3257
3258 retval = 0;
3259 break;
3260
3261 default:
3262 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3263 "(debug info 0x%x)\n",
3264 header->fsf_status);
3265 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3266 debug_exception(adapter->erp_dbf, 0,
3267 &header->fsf_status, sizeof (u32));
3268 break;
3269 }
3270
3271 skip_fsfstatus:
3272 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3273 return retval;
3274}
3275
3276/*
3277 * function: zfcp_fsf_close_unit
3278 *
3279 * purpose:
3280 *
3281 * returns: address of fsf_req - request successfully initiated
3282 * NULL -
3283 *
3284 * assumptions: This routine does not check whether the associated
3285 * remote port/lun has already been opened. This should be
3286 * done by calling routines. Otherwise some status
3287 * may be presented by FSF
3288 */
3289int
3290zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3291{
3292 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003293 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 unsigned long lock_flags;
3295 int retval = 0;
3296
3297 /* setup new FSF request */
3298 retval = zfcp_fsf_req_create(erp_action->adapter,
3299 FSF_QTCB_CLOSE_LUN,
3300 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3301 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003302 &lock_flags, &fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 if (retval < 0) {
3304 ZFCP_LOG_INFO("error: Could not create close unit request for "
3305 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3306 erp_action->unit->fcp_lun,
3307 erp_action->port->wwpn,
3308 zfcp_get_busid_by_adapter(erp_action->adapter));
3309 goto out;
3310 }
3311
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003312 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3314 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3315
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003316 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3317 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003319 fsf_req->data = (unsigned long) erp_action->unit;
3320 fsf_req->erp_action = erp_action;
3321 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003323 zfcp_erp_start_timer(fsf_req);
3324 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 if (retval) {
3326 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3327 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3328 erp_action->unit->fcp_lun,
3329 erp_action->port->wwpn,
3330 zfcp_get_busid_by_adapter(erp_action->adapter));
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003331 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 erp_action->fsf_req = NULL;
3333 goto out;
3334 }
3335
3336 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3337 "port 0x%016Lx, unit 0x%016Lx)\n",
3338 zfcp_get_busid_by_adapter(erp_action->adapter),
3339 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3340 out:
3341 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3342 lock_flags);
3343 return retval;
3344}
3345
3346/*
3347 * function: zfcp_fsf_close_unit_handler
3348 *
3349 * purpose: is called for finished Close LUN FSF command
3350 *
3351 * returns:
3352 */
3353static int
3354zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3355{
3356 int retval = -EINVAL;
3357 struct zfcp_unit *unit;
3358
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003359 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
3361 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3362 /* don't change unit status in our bookkeeping */
3363 goto skip_fsfstatus;
3364 }
3365
3366 /* evaluate FSF status in QTCB */
3367 switch (fsf_req->qtcb->header.fsf_status) {
3368
3369 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3371 "0x%016Lx on adapter %s invalid. This may "
3372 "happen in rare circumstances\n",
3373 unit->port->handle,
3374 unit->port->wwpn,
3375 zfcp_get_busid_by_unit(unit));
3376 ZFCP_LOG_DEBUG("status qualifier:\n");
3377 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3378 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3379 sizeof (union fsf_status_qual));
3380 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3381 "fsf_s_phand_nv");
3382 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3384 break;
3385
3386 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3388 "0x%016Lx on port 0x%016Lx on adapter %s is "
3389 "invalid. This may happen occasionally.\n",
3390 unit->handle,
3391 unit->fcp_lun,
3392 unit->port->wwpn,
3393 zfcp_get_busid_by_unit(unit));
3394 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3395 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3396 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3397 sizeof (union fsf_status_qual));
3398 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3399 "fsf_s_lhand_nv");
3400 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3402 break;
3403
3404 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3406 "needs to be reopened\n",
3407 unit->port->wwpn,
3408 zfcp_get_busid_by_unit(unit));
3409 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003410 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3412 ZFCP_STATUS_FSFREQ_RETRY;
3413 break;
3414
3415 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3417 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 /* re-establish link to port */
3419 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3420 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003421 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3423 break;
3424 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 /* ERP strategy will escalate */
3426 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3427 "fsf_sq_ulp");
3428 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3429 break;
3430 default:
3431 ZFCP_LOG_NORMAL
3432 ("bug: Wrong status qualifier 0x%x arrived.\n",
3433 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3434 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3435 "fsf_sq_inval:");
3436 debug_exception(
3437 fsf_req->adapter->erp_dbf, 0,
3438 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3439 sizeof (u32));
3440 break;
3441 }
3442 break;
3443
3444 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3446 "closed, port handle 0x%x\n",
3447 unit->fcp_lun,
3448 unit->port->wwpn,
3449 zfcp_get_busid_by_unit(unit),
3450 unit->handle);
3451 /* mark unit as closed */
3452 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3453 retval = 0;
3454 break;
3455
3456 default:
3457 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3458 "(debug info 0x%x)\n",
3459 fsf_req->qtcb->header.fsf_status);
3460 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3461 debug_exception(fsf_req->adapter->erp_dbf, 0,
3462 &fsf_req->qtcb->header.fsf_status,
3463 sizeof (u32));
3464 break;
3465 }
3466
3467 skip_fsfstatus:
3468 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3469 return retval;
3470}
3471
3472/**
3473 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3474 * @adapter: adapter where scsi command is issued
3475 * @unit: unit where command is sent to
3476 * @scsi_cmnd: scsi command to be sent
3477 * @timer: timer to be started when request is initiated
3478 * @req_flags: flags for fsf_request
3479 */
3480int
3481zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3482 struct zfcp_unit *unit,
3483 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003484 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485{
3486 struct zfcp_fsf_req *fsf_req = NULL;
3487 struct fcp_cmnd_iu *fcp_cmnd_iu;
3488 unsigned int sbtype;
3489 unsigned long lock_flags;
3490 int real_bytes = 0;
3491 int retval = 0;
3492 int mask;
3493
3494 /* setup new FSF request */
3495 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3496 adapter->pool.fsf_req_scsi,
3497 &lock_flags, &fsf_req);
3498 if (unlikely(retval < 0)) {
3499 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3500 "for unit 0x%016Lx on port 0x%016Lx on "
3501 "adapter %s\n",
3502 unit->fcp_lun,
3503 unit->port->wwpn,
3504 zfcp_get_busid_by_adapter(adapter));
3505 goto failed_req_create;
3506 }
3507
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003508 zfcp_unit_get(unit);
3509 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003511 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02003512 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003513
3514 /* associate SCSI command with FSF request */
3515 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516
3517 /* set handles of unit and its parent port in QTCB */
3518 fsf_req->qtcb->header.lun_handle = unit->handle;
3519 fsf_req->qtcb->header.port_handle = unit->port->handle;
3520
3521 /* FSF does not define the structure of the FCP_CMND IU */
3522 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3523 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3524
3525 /*
3526 * set depending on data direction:
3527 * data direction bits in SBALE (SB Type)
3528 * data direction bits in QTCB
3529 * data direction bits in FCP_CMND IU
3530 */
3531 switch (scsi_cmnd->sc_data_direction) {
3532 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3534 /*
3535 * FIXME(qdio):
3536 * what is the correct type for commands
3537 * without 'real' data buffers?
3538 */
3539 sbtype = SBAL_FLAGS0_TYPE_READ;
3540 break;
3541 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3543 sbtype = SBAL_FLAGS0_TYPE_READ;
3544 fcp_cmnd_iu->rddata = 1;
3545 break;
3546 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3548 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3549 fcp_cmnd_iu->wddata = 1;
3550 break;
3551 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 default:
3553 /*
3554 * dummy, catch this condition earlier
3555 * in zfcp_scsi_queuecommand
3556 */
3557 goto failed_scsi_cmnd;
3558 }
3559
3560 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02003561 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562
3563 /* set FCP_LUN in FCP_CMND IU in QTCB */
3564 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3565
3566 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3567
3568 /* set task attributes in FCP_CMND IU in QTCB */
3569 if (likely((scsi_cmnd->device->simple_tags) ||
3570 (atomic_test_mask(mask, &unit->status))))
3571 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3572 else
3573 fcp_cmnd_iu->task_attribute = UNTAGGED;
3574
3575 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3576 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3577 fcp_cmnd_iu->add_fcp_cdb_length
3578 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3579 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3580 "additional FCP_CDB length is 0x%x "
3581 "(shifted right 2 bits)\n",
3582 scsi_cmnd->cmd_len,
3583 fcp_cmnd_iu->add_fcp_cdb_length);
3584 }
3585 /*
3586 * copy SCSI CDB (including additional length, if any) to
3587 * FCP_CDB in FCP_CMND IU in QTCB
3588 */
3589 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3590
3591 /* FCP CMND IU length in QTCB */
3592 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3593 sizeof (struct fcp_cmnd_iu) +
3594 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3595
3596 /* generate SBALEs from data buffer */
3597 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3598 if (unlikely(real_bytes < 0)) {
3599 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3600 ZFCP_LOG_DEBUG(
3601 "Data did not fit into available buffer(s), "
3602 "waiting for more...\n");
3603 retval = -EIO;
3604 } else {
3605 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3606 "required. Shutting down unit "
3607 "(adapter %s, port 0x%016Lx, "
3608 "unit 0x%016Lx)\n",
3609 zfcp_get_busid_by_unit(unit),
3610 unit->port->wwpn,
3611 unit->fcp_lun);
3612 zfcp_erp_unit_shutdown(unit, 0);
3613 retval = -EINVAL;
3614 }
3615 goto no_fit;
3616 }
3617
3618 /* set length of FCP data length in FCP_CMND IU in QTCB */
3619 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3620
3621 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3622 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3623 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3624
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003625 if (use_timer)
3626 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3627
3628 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 if (unlikely(retval < 0)) {
3630 ZFCP_LOG_INFO("error: Could not send FCP command request "
3631 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3632 zfcp_get_busid_by_adapter(adapter),
3633 unit->port->wwpn,
3634 unit->fcp_lun);
3635 goto send_failed;
3636 }
3637
3638 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3639 "port 0x%016Lx, unit 0x%016Lx)\n",
3640 zfcp_get_busid_by_adapter(adapter),
3641 unit->port->wwpn,
3642 unit->fcp_lun);
3643 goto success;
3644
3645 send_failed:
3646 no_fit:
3647 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003648 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 zfcp_fsf_req_free(fsf_req);
3650 fsf_req = NULL;
3651 scsi_cmnd->host_scribble = NULL;
3652 success:
3653 failed_req_create:
3654 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3655 return retval;
3656}
3657
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658struct zfcp_fsf_req *
3659zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3660 struct zfcp_unit *unit,
3661 u8 tm_flags, int req_flags)
3662{
3663 struct zfcp_fsf_req *fsf_req = NULL;
3664 int retval = 0;
3665 struct fcp_cmnd_iu *fcp_cmnd_iu;
3666 unsigned long lock_flags;
3667 volatile struct qdio_buffer_element *sbale;
3668
3669 /* setup new FSF request */
3670 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3671 adapter->pool.fsf_req_scsi,
3672 &lock_flags, &fsf_req);
3673 if (retval < 0) {
3674 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3675 "management) request for adapter %s, port "
3676 " 0x%016Lx, unit 0x%016Lx.\n",
3677 zfcp_get_busid_by_adapter(adapter),
3678 unit->port->wwpn, unit->fcp_lun);
3679 goto out;
3680 }
3681
3682 /*
3683 * Used to decide on proper handler in the return path,
3684 * could be either zfcp_fsf_send_fcp_command_task_handler or
3685 * zfcp_fsf_send_fcp_command_task_management_handler */
3686
3687 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3688
3689 /*
3690 * hold a pointer to the unit being target of this
3691 * task management request
3692 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003693 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694
3695 /* set FSF related fields in QTCB */
3696 fsf_req->qtcb->header.lun_handle = unit->handle;
3697 fsf_req->qtcb->header.port_handle = unit->port->handle;
3698 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02003699 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3701 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3702
3703 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3704 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3705 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3706
3707 /* set FCP related fields in FCP_CMND IU in QTCB */
3708 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3709 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3710 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3711 fcp_cmnd_iu->task_management_flags = tm_flags;
3712
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003713 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3714 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 if (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3717 "management) on adapter %s, port 0x%016Lx for "
3718 "unit LUN 0x%016Lx\n",
3719 zfcp_get_busid_by_adapter(adapter),
3720 unit->port->wwpn,
3721 unit->fcp_lun);
3722 zfcp_fsf_req_free(fsf_req);
3723 fsf_req = NULL;
3724 goto out;
3725 }
3726
3727 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3728 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3729 "tm_flags=0x%x)\n",
3730 zfcp_get_busid_by_adapter(adapter),
3731 unit->port->wwpn,
3732 unit->fcp_lun,
3733 tm_flags);
3734 out:
3735 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3736 return fsf_req;
3737}
3738
3739/*
3740 * function: zfcp_fsf_send_fcp_command_handler
3741 *
3742 * purpose: is called for finished Send FCP Command
3743 *
3744 * returns:
3745 */
3746static int
3747zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3748{
3749 int retval = -EINVAL;
3750 struct zfcp_unit *unit;
3751 struct fsf_qtcb_header *header;
3752 u16 subtable, rule, counter;
3753
3754 header = &fsf_req->qtcb->header;
3755
3756 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003757 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003759 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760
3761 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3762 /* go directly to calls of special handlers */
3763 goto skip_fsfstatus;
3764 }
3765
3766 /* evaluate FSF status in QTCB */
3767 switch (header->fsf_status) {
3768
3769 case FSF_PORT_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3771 "0x%016Lx on adapter %s invalid\n",
3772 unit->port->handle,
3773 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3774 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3775 (char *) &header->fsf_status_qual,
3776 sizeof (union fsf_status_qual));
3777 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3778 "fsf_s_phand_nv");
3779 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3780 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3781 break;
3782
3783 case FSF_LUN_HANDLE_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3785 "0x%016Lx on port 0x%016Lx on adapter %s is "
3786 "invalid. This may happen occasionally.\n",
3787 unit->handle,
3788 unit->fcp_lun,
3789 unit->port->wwpn,
3790 zfcp_get_busid_by_unit(unit));
3791 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3792 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3793 (char *) &header->fsf_status_qual,
3794 sizeof (union fsf_status_qual));
3795 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3796 "fsf_s_uhand_nv");
3797 zfcp_erp_port_reopen(unit->port, 0);
3798 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3799 break;
3800
3801 case FSF_HANDLE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3803 "unexpectedly. (adapter %s, port 0x%016Lx, "
3804 "unit 0x%016Lx)\n",
3805 unit->port->handle,
3806 zfcp_get_busid_by_unit(unit),
3807 unit->port->wwpn,
3808 unit->fcp_lun);
3809 ZFCP_LOG_NORMAL("status qualifier:\n");
3810 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3811 (char *) &header->fsf_status_qual,
3812 sizeof (union fsf_status_qual));
3813 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3814 "fsf_s_hand_mis");
3815 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3817 break;
3818
3819 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Andreas Herrmann06506d02006-05-22 18:18:19 +02003820 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3821 "class %d.\n",
3822 zfcp_get_busid_by_unit(unit),
3823 ZFCP_FC_SERVICE_CLASS_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 /* stop operation for this adapter */
3825 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3826 "fsf_s_class_nsup");
3827 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3829 break;
3830
3831 case FSF_FCPLUN_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3833 "adapter %s does not have correct unit "
3834 "handle 0x%x\n",
3835 unit->fcp_lun,
3836 unit->port->wwpn,
3837 zfcp_get_busid_by_unit(unit),
3838 unit->handle);
3839 ZFCP_LOG_DEBUG("status qualifier:\n");
3840 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3841 (char *) &header->fsf_status_qual,
3842 sizeof (union fsf_status_qual));
3843 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3844 "fsf_s_fcp_lun_nv");
3845 zfcp_erp_port_reopen(unit->port, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3847 break;
3848
3849 case FSF_ACCESS_DENIED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3851 "unit 0x%016Lx on port 0x%016Lx on "
3852 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3853 zfcp_get_busid_by_unit(unit));
3854 for (counter = 0; counter < 2; counter++) {
3855 subtable = header->fsf_status_qual.halfword[counter * 2];
3856 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3857 switch (subtable) {
3858 case FSF_SQ_CFDC_SUBTABLE_OS:
3859 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3860 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3861 case FSF_SQ_CFDC_SUBTABLE_LUN:
3862 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3863 zfcp_act_subtable_type[subtable], rule);
3864 break;
3865 }
3866 }
3867 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3868 zfcp_erp_unit_access_denied(unit);
3869 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3870 break;
3871
3872 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3874 "0x%016Lx on port 0x%016Lx on adapter %s "
3875 "(debug info %d)\n",
3876 unit->fcp_lun,
3877 unit->port->wwpn,
3878 zfcp_get_busid_by_unit(unit),
3879 fsf_req->qtcb->bottom.io.data_direction);
3880 /* stop operation for this adapter */
3881 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3882 "fsf_s_dir_ind_nv");
3883 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3885 break;
3886
3887 case FSF_CMND_LENGTH_NOT_VALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 ZFCP_LOG_NORMAL
3889 ("bug: An invalid control-data-block length field "
3890 "was found in a command for unit 0x%016Lx on port "
3891 "0x%016Lx on adapter %s " "(debug info %d)\n",
3892 unit->fcp_lun, unit->port->wwpn,
3893 zfcp_get_busid_by_unit(unit),
3894 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3895 /* stop operation for this adapter */
3896 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3897 "fsf_s_cmd_len_nv");
3898 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3900 break;
3901
3902 case FSF_PORT_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3904 "needs to be reopened\n",
3905 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3906 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003907 zfcp_erp_port_boxed(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3909 ZFCP_STATUS_FSFREQ_RETRY;
3910 break;
3911
3912 case FSF_LUN_BOXED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3914 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3915 zfcp_get_busid_by_unit(unit),
3916 unit->port->wwpn, unit->fcp_lun);
3917 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003918 zfcp_erp_unit_boxed(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3920 | ZFCP_STATUS_FSFREQ_RETRY;
3921 break;
3922
3923 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 switch (header->fsf_status_qual.word[0]) {
3925 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 /* re-establish link to port */
3927 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3928 "fsf_sq_ltest");
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02003929 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 break;
3931 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 /* FIXME(hw) need proper specs for proper action */
3933 /* let scsi stack deal with retries and escalation */
3934 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3935 "fsf_sq_ulp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 break;
3937 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 ZFCP_LOG_NORMAL
Andreas Herrmann516a4202005-06-13 13:17:44 +02003939 ("Unknown status qualifier 0x%x arrived.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 header->fsf_status_qual.word[0]);
3941 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3942 "fsf_sq_inval:");
3943 debug_exception(fsf_req->adapter->erp_dbf, 0,
3944 &header->fsf_status_qual.word[0],
3945 sizeof(u32));
3946 break;
3947 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02003948 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 break;
3950
3951 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 break;
3953
3954 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 break;
3956
3957 default:
3958 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3959 debug_exception(fsf_req->adapter->erp_dbf, 0,
3960 &header->fsf_status, sizeof(u32));
3961 break;
3962 }
3963
3964 skip_fsfstatus:
3965 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3966 retval =
3967 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3968 } else {
3969 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003970 fsf_req->unit = NULL;
3971 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
3973 return retval;
3974}
3975
3976/*
3977 * function: zfcp_fsf_send_fcp_command_task_handler
3978 *
3979 * purpose: evaluates FCP_RSP IU
3980 *
3981 * returns:
3982 */
3983static int
3984zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3985{
3986 int retval = 0;
3987 struct scsi_cmnd *scpnt;
3988 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3989 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3990 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3991 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3992 u32 sns_len;
3993 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3994 unsigned long flags;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003995 struct zfcp_unit *unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
3997 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003998 scpnt = (struct scsi_cmnd *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 if (unlikely(!scpnt)) {
4000 ZFCP_LOG_DEBUG
4001 ("Command with fsf_req %p is not associated to "
4002 "a scsi command anymore. Aborted?\n", fsf_req);
4003 goto out;
4004 }
4005 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4006 /* FIXME: (design) mid-layer should handle DID_ABORT like
4007 * DID_SOFT_ERROR by retrying the request for devices
4008 * that allow retries.
4009 */
4010 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4011 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4012 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4013 goto skip_fsfstatus;
4014 }
4015
4016 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4017 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4018 set_host_byte(&scpnt->result, DID_ERROR);
4019 goto skip_fsfstatus;
4020 }
4021
4022 /* set message byte of result in SCSI command */
4023 scpnt->result |= COMMAND_COMPLETE << 8;
4024
4025 /*
4026 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4027 * of result in SCSI command
4028 */
4029 scpnt->result |= fcp_rsp_iu->scsi_status;
4030 if (unlikely(fcp_rsp_iu->scsi_status)) {
4031 /* DEBUG */
4032 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4033 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4034 scpnt->cmnd, scpnt->cmd_len);
4035 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4036 fcp_rsp_iu->scsi_status);
4037 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4038 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4039 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4040 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4041 fcp_rsp_iu->fcp_sns_len);
4042 }
4043
4044 /* check FCP_RSP_INFO */
4045 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4046 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4047 switch (fcp_rsp_info[3]) {
4048 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 /* ok, continue */
4050 ZFCP_LOG_TRACE("no failure or Task Management "
4051 "Function complete\n");
4052 set_host_byte(&scpnt->result, DID_OK);
4053 break;
4054 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 /* hardware bug */
4056 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4057 "that the fibrechannel protocol data "
4058 "length differs from the burst length. "
4059 "The problem occured on unit 0x%016Lx "
4060 "on port 0x%016Lx on adapter %s",
4061 unit->fcp_lun,
4062 unit->port->wwpn,
4063 zfcp_get_busid_by_unit(unit));
4064 /* dump SCSI CDB as prepared by zfcp */
4065 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4066 (char *) &fsf_req->qtcb->
4067 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 set_host_byte(&scpnt->result, DID_ERROR);
4069 goto skip_fsfstatus;
4070 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 /* driver or hardware bug */
4072 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4073 "that the fibrechannel protocol data "
4074 "fields were incorrectly set up. "
4075 "The problem occured on the unit "
4076 "0x%016Lx on port 0x%016Lx on "
4077 "adapter %s",
4078 unit->fcp_lun,
4079 unit->port->wwpn,
4080 zfcp_get_busid_by_unit(unit));
4081 /* dump SCSI CDB as prepared by zfcp */
4082 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4083 (char *) &fsf_req->qtcb->
4084 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4085 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 goto skip_fsfstatus;
4087 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 /* hardware bug */
4089 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4090 "that conflicting values for the "
4091 "fibrechannel payload offset from the "
4092 "header were found. "
4093 "The problem occured on unit 0x%016Lx "
4094 "on port 0x%016Lx on adapter %s.\n",
4095 unit->fcp_lun,
4096 unit->port->wwpn,
4097 zfcp_get_busid_by_unit(unit));
4098 /* dump SCSI CDB as prepared by zfcp */
4099 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4100 (char *) &fsf_req->qtcb->
4101 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 set_host_byte(&scpnt->result, DID_ERROR);
4103 goto skip_fsfstatus;
4104 default:
4105 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4106 "code was detected for a command. "
4107 "The problem occured on the unit "
4108 "0x%016Lx on port 0x%016Lx on "
4109 "adapter %s (debug info 0x%x)\n",
4110 unit->fcp_lun,
4111 unit->port->wwpn,
4112 zfcp_get_busid_by_unit(unit),
4113 fcp_rsp_info[3]);
4114 /* dump SCSI CDB as prepared by zfcp */
4115 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4116 (char *) &fsf_req->qtcb->
4117 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 set_host_byte(&scpnt->result, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05004119 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 }
4121 }
4122
4123 /* check for sense data */
4124 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4125 sns_len = FSF_FCP_RSP_SIZE -
4126 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4127 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4128 sns_len);
4129 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4130 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4131 SCSI_SENSE_BUFFERSIZE);
4132 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4133 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4134 scpnt->result);
4135 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4136 (void *) &scpnt->cmnd, scpnt->cmd_len);
4137
4138 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4139 fcp_rsp_iu->fcp_sns_len);
4140 memcpy(&scpnt->sense_buffer,
4141 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4142 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4143 (void *) &scpnt->sense_buffer, sns_len);
4144 }
4145
4146 /* check for overrun */
4147 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4148 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4149 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4150 "The response data length is "
4151 "%d, the original length was %d.\n",
4152 unit->fcp_lun,
4153 unit->port->wwpn,
4154 zfcp_get_busid_by_unit(unit),
4155 fcp_rsp_iu->fcp_resid,
4156 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4157 }
4158
4159 /* check for underrun */
4160 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4161 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4162 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4163 "The response data length is "
4164 "%d, the original length was %d.\n",
4165 unit->fcp_lun,
4166 unit->port->wwpn,
4167 zfcp_get_busid_by_unit(unit),
4168 fcp_rsp_iu->fcp_resid,
4169 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4170
4171 scpnt->resid = fcp_rsp_iu->fcp_resid;
4172 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
6f71d9b2005-04-10 23:04:28 -05004173 set_host_byte(&scpnt->result, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 }
4175
4176 skip_fsfstatus:
4177 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4178
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004179 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004180 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004181 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004182 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004183 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01004184 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185
4186 /* cleanup pointer (need this especially for abort) */
4187 scpnt->host_scribble = NULL;
4188
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 (scpnt->scsi_done) (scpnt);
4191
4192 /*
4193 * We must hold this lock until scsi_done has been called.
4194 * Otherwise we may call scsi_done after abort regarding this
4195 * command has completed.
4196 * Note: scsi_done must not block!
4197 */
4198 out:
4199 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4200 return retval;
4201}
4202
4203/*
4204 * function: zfcp_fsf_send_fcp_command_task_management_handler
4205 *
4206 * purpose: evaluates FCP_RSP IU
4207 *
4208 * returns:
4209 */
4210static int
4211zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4212{
4213 int retval = 0;
4214 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4215 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4216 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02004217 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4220 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4221 goto skip_fsfstatus;
4222 }
4223
4224 /* check FCP_RSP_INFO */
4225 switch (fcp_rsp_info[3]) {
4226 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 /* ok, continue */
4228 ZFCP_LOG_DEBUG("no failure or Task Management "
4229 "Function complete\n");
4230 break;
4231 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4233 "is not supported on the target device "
4234 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4235 unit->fcp_lun,
4236 unit->port->wwpn,
4237 zfcp_get_busid_by_unit(unit));
4238 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4239 break;
4240 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4242 "failed to complete successfully. "
4243 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4244 unit->fcp_lun,
4245 unit->port->wwpn,
4246 zfcp_get_busid_by_unit(unit));
4247 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4248 break;
4249 default:
4250 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4251 "code was detected for a command. "
4252 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4253 "(debug info 0x%x)\n",
4254 unit->fcp_lun,
4255 unit->port->wwpn,
4256 zfcp_get_busid_by_unit(unit),
4257 fcp_rsp_info[3]);
4258 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4259 }
4260
4261 skip_fsfstatus:
4262 return retval;
4263}
4264
4265
4266/*
4267 * function: zfcp_fsf_control_file
4268 *
4269 * purpose: Initiator of the control file upload/download FSF requests
4270 *
4271 * returns: 0 - FSF request is successfuly created and queued
4272 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4273 * -EINVAL - Invalid direction specified
4274 * -ENOMEM - Insufficient memory
4275 * -EPERM - Cannot create FSF request or place it in QDIO queue
4276 */
4277int
4278zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4279 struct zfcp_fsf_req **fsf_req_ptr,
4280 u32 fsf_command,
4281 u32 option,
4282 struct zfcp_sg_list *sg_list)
4283{
4284 struct zfcp_fsf_req *fsf_req;
4285 struct fsf_qtcb_bottom_support *bottom;
4286 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 unsigned long lock_flags;
4288 int req_flags = 0;
4289 int direction;
4290 int retval = 0;
4291
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02004292 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4294 zfcp_get_busid_by_adapter(adapter));
4295 retval = -EOPNOTSUPP;
4296 goto out;
4297 }
4298
4299 switch (fsf_command) {
4300
4301 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4302 direction = SBAL_FLAGS0_TYPE_WRITE;
4303 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4304 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4305 req_flags = ZFCP_WAIT_FOR_SBAL;
4306 break;
4307
4308 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4309 direction = SBAL_FLAGS0_TYPE_READ;
4310 break;
4311
4312 default:
4313 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4314 retval = -EINVAL;
4315 goto out;
4316 }
4317
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4319 NULL, &lock_flags, &fsf_req);
4320 if (retval < 0) {
4321 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4322 "adapter %s\n",
4323 zfcp_get_busid_by_adapter(adapter));
4324 retval = -EPERM;
4325 goto unlock_queue_lock;
4326 }
4327
4328 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4329 sbale[0].flags |= direction;
4330
4331 bottom = &fsf_req->qtcb->bottom.support;
4332 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4333 bottom->option = option;
4334
4335 if (sg_list->count > 0) {
4336 int bytes;
4337
4338 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4339 sg_list->sg, sg_list->count,
4340 ZFCP_MAX_SBALS_PER_REQ);
4341 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4342 ZFCP_LOG_INFO(
4343 "error: Could not create sufficient number of "
4344 "SBALS for an FSF request to the adapter %s\n",
4345 zfcp_get_busid_by_adapter(adapter));
4346 retval = -ENOMEM;
4347 goto free_fsf_req;
4348 }
4349 } else
4350 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4351
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004352 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4353 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 if (retval < 0) {
4355 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4356 "(adapter %s)\n",
4357 zfcp_get_busid_by_adapter(adapter));
4358 retval = -EPERM;
4359 goto free_fsf_req;
4360 }
4361 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4362
4363 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4364 "adapter %s\n",
4365 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4366 "download" : "upload",
4367 zfcp_get_busid_by_adapter(adapter));
4368
4369 wait_event(fsf_req->completion_wq,
4370 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4371
4372 *fsf_req_ptr = fsf_req;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004373 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374
4375 free_fsf_req:
4376 zfcp_fsf_req_free(fsf_req);
4377 unlock_queue_lock:
4378 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 out:
4380 return retval;
4381}
4382
4383
4384/*
4385 * function: zfcp_fsf_control_file_handler
4386 *
4387 * purpose: Handler of the control file upload/download FSF requests
4388 *
4389 * returns: 0 - FSF request successfuly processed
4390 * -EAGAIN - Operation has to be repeated because of a temporary problem
4391 * -EACCES - There is no permission to execute an operation
4392 * -EPERM - The control file is not in a right format
4393 * -EIO - There is a problem with the FCP adapter
4394 * -EINVAL - Invalid operation
4395 * -EFAULT - User space memory I/O operation fault
4396 */
4397static int
4398zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4399{
4400 struct zfcp_adapter *adapter = fsf_req->adapter;
4401 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4402 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4403 int retval = 0;
4404
4405 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4406 retval = -EINVAL;
4407 goto skip_fsfstatus;
4408 }
4409
4410 switch (header->fsf_status) {
4411
4412 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 ZFCP_LOG_NORMAL(
4414 "The FSF request has been successfully completed "
4415 "on the adapter %s\n",
4416 zfcp_get_busid_by_adapter(adapter));
4417 break;
4418
4419 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4421 switch (header->fsf_status_qual.word[0]) {
4422
6f71d9b2005-04-10 23:04:28 -05004423 case FSF_SQ_CFDC_HARDENED_ON_SE:
4424 ZFCP_LOG_NORMAL(
4425 "CFDC on the adapter %s has being "
4426 "hardened on primary and secondary SE\n",
4427 zfcp_get_busid_by_adapter(adapter));
4428 break;
4429
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4431 ZFCP_LOG_NORMAL(
4432 "CFDC of the adapter %s could not "
4433 "be saved on the SE\n",
4434 zfcp_get_busid_by_adapter(adapter));
4435 break;
4436
4437 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4438 ZFCP_LOG_NORMAL(
4439 "CFDC of the adapter %s could not "
4440 "be copied to the secondary SE\n",
4441 zfcp_get_busid_by_adapter(adapter));
4442 break;
4443
4444 default:
4445 ZFCP_LOG_NORMAL(
4446 "CFDC could not be hardened "
4447 "on the adapter %s\n",
4448 zfcp_get_busid_by_adapter(adapter));
4449 }
4450 }
4451 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4452 retval = -EAGAIN;
4453 break;
4454
4455 case FSF_AUTHORIZATION_FAILURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456 ZFCP_LOG_NORMAL(
4457 "Adapter %s does not accept privileged commands\n",
4458 zfcp_get_busid_by_adapter(adapter));
4459 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4460 retval = -EACCES;
4461 break;
4462
4463 case FSF_CFDC_ERROR_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 ZFCP_LOG_NORMAL(
4465 "Error at position %d in the CFDC, "
4466 "CFDC is discarded by the adapter %s\n",
4467 header->fsf_status_qual.word[0],
4468 zfcp_get_busid_by_adapter(adapter));
4469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4470 retval = -EPERM;
4471 break;
4472
4473 case FSF_CONTROL_FILE_UPDATE_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 ZFCP_LOG_NORMAL(
4475 "Adapter %s cannot harden the control file, "
4476 "file is discarded\n",
4477 zfcp_get_busid_by_adapter(adapter));
4478 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4479 retval = -EIO;
4480 break;
4481
4482 case FSF_CONTROL_FILE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 ZFCP_LOG_NORMAL(
4484 "Control file is too large, file is discarded "
4485 "by the adapter %s\n",
4486 zfcp_get_busid_by_adapter(adapter));
4487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4488 retval = -EIO;
4489 break;
4490
4491 case FSF_ACCESS_CONFLICT_DETECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4493 ZFCP_LOG_NORMAL(
4494 "CFDC has been discarded by the adapter %s, "
4495 "because activation would impact "
4496 "%d active connection(s)\n",
4497 zfcp_get_busid_by_adapter(adapter),
4498 header->fsf_status_qual.word[0]);
4499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4500 retval = -EIO;
4501 break;
4502
4503 case FSF_CONFLICTS_OVERRULED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4505 ZFCP_LOG_NORMAL(
4506 "CFDC has been activated on the adapter %s, "
4507 "but activation has impacted "
4508 "%d active connection(s)\n",
4509 zfcp_get_busid_by_adapter(adapter),
4510 header->fsf_status_qual.word[0]);
4511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4512 retval = -EIO;
4513 break;
4514
4515 case FSF_UNKNOWN_OP_SUBTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4517 "op_subtype=0x%x)\n",
4518 zfcp_get_busid_by_adapter(adapter),
4519 bottom->operation_subtype);
4520 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4521 retval = -EINVAL;
4522 break;
4523
4524 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 ZFCP_LOG_NORMAL(
4526 "Invalid option 0x%x has been specified "
4527 "in QTCB bottom sent to the adapter %s\n",
4528 bottom->option,
4529 zfcp_get_busid_by_adapter(adapter));
4530 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4531 retval = -EINVAL;
4532 break;
4533
4534 default:
4535 ZFCP_LOG_NORMAL(
4536 "bug: An unknown/unexpected FSF status 0x%08x "
4537 "was presented on the adapter %s\n",
4538 header->fsf_status,
4539 zfcp_get_busid_by_adapter(adapter));
4540 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4541 debug_exception(fsf_req->adapter->erp_dbf, 0,
4542 &header->fsf_status_qual.word[0], sizeof(u32));
4543 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4544 retval = -EINVAL;
4545 break;
4546 }
4547
4548skip_fsfstatus:
4549 return retval;
4550}
4551
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552static inline int
4553zfcp_fsf_req_sbal_check(unsigned long *flags,
4554 struct zfcp_qdio_queue *queue, int needed)
4555{
4556 write_lock_irqsave(&queue->queue_lock, *flags);
4557 if (likely(atomic_read(&queue->free_count) >= needed))
4558 return 1;
4559 write_unlock_irqrestore(&queue->queue_lock, *flags);
4560 return 0;
4561}
4562
4563/*
4564 * set qtcb pointer in fsf_req and initialize QTCB
4565 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01004566static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004567zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568{
4569 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004570 fsf_req->qtcb->prefix.req_seq_no =
4571 fsf_req->adapter->fsf_req_seq_no;
4572 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004574 fsf_req->qtcb->prefix.qtcb_type =
4575 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004577 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004578 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 }
4580}
4581
4582/**
4583 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4584 * @adapter: adapter for which request queue is examined
4585 * @req_flags: flags indicating whether to wait for needed SBAL or not
4586 * @lock_flags: lock_flags if queue_lock is taken
4587 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4588 * Locks: lock adapter->request_queue->queue_lock on success
4589 */
4590static int
4591zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4592 unsigned long *lock_flags)
4593{
4594 long ret;
4595 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4596
4597 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4598 ret = wait_event_interruptible_timeout(adapter->request_wq,
4599 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4600 ZFCP_SBAL_TIMEOUT);
4601 if (ret < 0)
4602 return ret;
4603 if (!ret)
4604 return -EIO;
4605 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4606 return -EIO;
4607
4608 return 0;
4609}
4610
4611/*
4612 * function: zfcp_fsf_req_create
4613 *
4614 * purpose: create an FSF request at the specified adapter and
4615 * setup common fields
4616 *
4617 * returns: -ENOMEM if there was insufficient memory for a request
4618 * -EIO if no qdio buffers could be allocate to the request
4619 * -EINVAL/-EPERM on bug conditions in req_dequeue
4620 * 0 in success
4621 *
4622 * note: The created request is returned by reference.
4623 *
4624 * locks: lock of concerned request queue must not be held,
4625 * but is held on completion (write, irqsave)
4626 */
4627int
4628zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4629 mempool_t *pool, unsigned long *lock_flags,
4630 struct zfcp_fsf_req **fsf_req_p)
4631{
4632 volatile struct qdio_buffer_element *sbale;
4633 struct zfcp_fsf_req *fsf_req = NULL;
4634 int ret = 0;
4635 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4636
4637 /* allocate new FSF request */
4638 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4639 if (unlikely(NULL == fsf_req)) {
4640 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4641 "the outbound (send) queue.\n");
4642 ret = -ENOMEM;
4643 goto failed_fsf_req;
4644 }
4645
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004646 fsf_req->adapter = adapter;
4647 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004648 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004649 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650
4651 /* initialize waitqueue which may be used to wait on
4652 this request completion */
4653 init_waitqueue_head(&fsf_req->completion_wq);
4654
4655 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004656 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02004658
4659 /* this is serialized (we are holding req_queue-lock of adapter) */
4660 if (adapter->req_no == 0)
4661 adapter->req_no++;
4662 fsf_req->req_id = adapter->req_no++;
4663
4664 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665
4666 /*
4667 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4668 * if it is not set (see also *_open_qdio and *_close_qdio).
4669 */
4670
4671 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4672 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4673 ret = -EIO;
4674 goto failed_sbals;
4675 }
4676
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004677 if (fsf_req->qtcb) {
4678 fsf_req->seq_no = adapter->fsf_req_seq_no;
4679 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681 fsf_req->sbal_number = 1;
4682 fsf_req->sbal_first = req_queue->free_index;
4683 fsf_req->sbal_curr = req_queue->free_index;
4684 fsf_req->sbale_curr = 1;
4685
4686 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4687 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4688 }
4689
4690 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4691
4692 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004693 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4695 if (likely(fsf_req->qtcb != NULL)) {
4696 sbale[1].addr = (void *) fsf_req->qtcb;
4697 sbale[1].length = sizeof(struct fsf_qtcb);
4698 }
4699
4700 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4701 fsf_req->sbal_number, fsf_req->sbal_first);
4702
4703 goto success;
4704
4705 failed_sbals:
4706/* dequeue new FSF request previously enqueued */
4707 zfcp_fsf_req_free(fsf_req);
4708 fsf_req = NULL;
4709
4710 failed_fsf_req:
4711 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4712 success:
4713 *fsf_req_p = fsf_req;
4714 return ret;
4715}
4716
4717/*
4718 * function: zfcp_fsf_req_send
4719 *
4720 * purpose: start transfer of FSF request via QDIO
4721 *
4722 * returns: 0 - request transfer succesfully started
4723 * !0 - start of request transfer failed
4724 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004725static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726{
4727 struct zfcp_adapter *adapter;
4728 struct zfcp_qdio_queue *req_queue;
4729 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004730 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 int new_distance_from_int;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004732 u64 dbg_tmp[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 int retval = 0;
4734
4735 adapter = fsf_req->adapter;
4736 req_queue = &adapter->request_queue,
4737
4738
4739 /* FIXME(debug): remove it later */
4740 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4741 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4742 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4743 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4744 sbale[1].length);
4745
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004746 /* put allocated FSF request into hash table */
4747 spin_lock(&adapter->req_list_lock);
4748 zfcp_reqlist_add(adapter, fsf_req);
4749 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004751 inc_seq_no = (fsf_req->qtcb != NULL);
4752
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 ZFCP_LOG_TRACE("request queue of adapter %s: "
4754 "next free SBAL is %i, %i free SBALs\n",
4755 zfcp_get_busid_by_adapter(adapter),
4756 req_queue->free_index,
4757 atomic_read(&req_queue->free_count));
4758
4759 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4760 "index_in_queue=%i, count=%i, buffers=%p\n",
4761 zfcp_get_busid_by_adapter(adapter),
4762 QDIO_FLAG_SYNC_OUTPUT,
4763 0, fsf_req->sbal_first, fsf_req->sbal_number,
4764 &req_queue->buffer[fsf_req->sbal_first]);
4765
4766 /*
4767 * adjust the number of free SBALs in request queue as well as
4768 * position of first one
4769 */
4770 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4771 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4772 req_queue->free_index += fsf_req->sbal_number; /* increase */
4773 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4774 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4775
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004776 fsf_req->issued = get_clock();
4777
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 retval = do_QDIO(adapter->ccw_device,
4779 QDIO_FLAG_SYNC_OUTPUT,
4780 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4781
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004782 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4783 dbg_tmp[1] = (u64) retval;
4784 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4785
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 if (unlikely(retval)) {
4787 /* Queues are down..... */
4788 retval = -EIO;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02004789 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004790 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02004791 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004792 spin_unlock(&adapter->req_list_lock);
4793 /* undo changes in request queue made for this request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 zfcp_qdio_zero_sbals(req_queue->buffer,
4795 fsf_req->sbal_first, fsf_req->sbal_number);
4796 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004797 req_queue->free_index -= fsf_req->sbal_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4799 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004800 zfcp_erp_adapter_reopen(adapter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 } else {
4802 req_queue->distance_from_int = new_distance_from_int;
4803 /*
4804 * increase FSF sequence counter -
4805 * this must only be done for request successfully enqueued to
4806 * QDIO this rejected requests may be cleaned up by calling
4807 * routines resulting in missing sequence counter values
4808 * otherwise,
4809 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004810
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004812 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 adapter->fsf_req_seq_no++;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02004814
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 /* count FSF requests pending */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02004816 atomic_inc(&adapter->reqs_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 }
4818 return retval;
4819}
4820
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821#undef ZFCP_LOG_AREA