blob: 150e78dd00b286296cfc7456a6eff8bffdbae0a8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Implementation of FSF commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Christof Schmitt553448f2008-06-10 18:20:58 +02006 * Copyright IBM Corporation 2002, 2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "zfcp_ext.h"
10
11static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
12static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
13static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
14static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
15static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
16static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
17static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
18static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
19static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
20static int zfcp_fsf_send_fcp_command_task_management_handler(
21 struct zfcp_fsf_req *);
22static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
23static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
24static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
25static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
Christof Schmitt45633fd2008-06-10 18:20:55 +020026static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static inline int zfcp_fsf_req_sbal_check(
28 unsigned long *, struct zfcp_qdio_queue *, int);
29static inline int zfcp_use_one_sbal(
30 struct scatterlist *, int, struct scatterlist *, int);
31static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
Andreas Herrmann2abbe862006-09-18 22:29:56 +020032static int zfcp_fsf_req_send(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
34static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
35static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
Martin Peschke698ec0162008-03-27 14:22:02 +010036static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020037 struct fsf_link_down_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/* association between FSF command and FSF QTCB type */
41static u32 fsf_qtcb_type[] = {
42 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
43 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
44 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
45 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
46 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
47 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
52 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
53 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
55};
56
57static const char zfcp_act_subtable_type[5][8] = {
58 "unknown", "OS", "WWPN", "DID", "LUN"
59};
60
Christof Schmitt553448f2008-06-10 18:20:58 +020061static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
62{
63 u16 subtable = (table & 0xffff0000) >> 16;
64 u16 rule = table & 0xffff;
65
66 if (subtable > 0 &&
67 subtable < ARRAY_SIZE(zfcp_act_subtable_type)) {
68 dev_warn(&adapter->ccw_device->dev,
69 "Access denied in subtable %s, rule %d.\n",
70 zfcp_act_subtable_type[subtable], rule);
71 }
72}
73
74static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
75 struct zfcp_port *port)
76{
77 struct fsf_qtcb_header *header = &req->qtcb->header;
78 dev_warn(&req->adapter->ccw_device->dev,
79 "Access denied, cannot send command to port 0x%016Lx.\n",
80 port->wwpn);
81 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
82 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
83 zfcp_erp_port_access_denied(port, 55, req);
84 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
85}
86
87static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
88 struct zfcp_unit *unit)
89{
90 struct fsf_qtcb_header *header = &req->qtcb->header;
91 dev_warn(&req->adapter->ccw_device->dev,
92 "Access denied for unit 0x%016Lx on port 0x%016Lx.\n",
93 unit->fcp_lun, unit->port->wwpn);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
95 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
96 zfcp_erp_unit_access_denied(unit, 59, req);
97 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
98}
99
100static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
101{
102 dev_err(&req->adapter->ccw_device->dev,
103 "Required FC class not supported by adapter, "
104 "shutting down adapter.\n");
105 zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
106 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
107}
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/****************************************************************/
110/*************** FSF related Functions *************************/
111/****************************************************************/
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*
114 * function: zfcp_fsf_req_alloc
115 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200116 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 * unsolicited requests) via helper functions
118 * Does some initial fsf request set-up.
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200119 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * returns: pointer to allocated fsf_req if successfull
121 * NULL otherwise
122 *
123 * locks: none
124 *
125 */
126static struct zfcp_fsf_req *
127zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
128{
129 size_t size;
130 void *ptr;
131 struct zfcp_fsf_req *fsf_req = NULL;
132
133 if (req_flags & ZFCP_REQ_NO_QTCB)
134 size = sizeof(struct zfcp_fsf_req);
135 else
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200136 size = sizeof(struct zfcp_fsf_req_qtcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200138 if (likely(pool))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 ptr = mempool_alloc(pool, GFP_ATOMIC);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200140 else {
141 if (req_flags & ZFCP_REQ_NO_QTCB)
142 ptr = kmalloc(size, GFP_ATOMIC);
143 else
144 ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
Christoph Lameter54e6ecb2006-12-06 20:33:16 -0800145 GFP_ATOMIC);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200148 if (unlikely(!ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 goto out;
150
151 memset(ptr, 0, size);
152
153 if (req_flags & ZFCP_REQ_NO_QTCB) {
154 fsf_req = (struct zfcp_fsf_req *) ptr;
155 } else {
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200156 fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
157 fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
160 fsf_req->pool = pool;
161
162 out:
163 return fsf_req;
164}
165
166/*
167 * function: zfcp_fsf_req_free
168 *
169 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
170 * returns it into the pool via helper functions.
171 *
172 * returns: sod all
173 *
174 * locks: none
175 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200176void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
178{
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200179 if (likely(fsf_req->pool)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 mempool_free(fsf_req, fsf_req->pool);
Heiko Carstensdd52e0e2006-09-18 22:28:49 +0200181 return;
182 }
183
184 if (fsf_req->qtcb) {
185 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
186 return;
187 }
188
189 kfree(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
Martin Peschke869b2b42007-05-09 11:01:20 +0200192/*
193 * Never ever call this without shutting down the adapter first.
194 * Otherwise the adapter would continue using and corrupting s390 storage.
195 * Included BUG_ON() call to ensure this is done.
196 * ERP is supposed to be the only user of this function.
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200197 */
Swen Schillig6fcc4712007-02-07 13:17:57 +0100198void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200199{
Martin Peschke869b2b42007-05-09 11:01:20 +0200200 struct zfcp_fsf_req *fsf_req, *tmp;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200201 unsigned long flags;
Swen Schillig6fcc4712007-02-07 13:17:57 +0100202 LIST_HEAD(remove_queue);
Martin Peschke869b2b42007-05-09 11:01:20 +0200203 unsigned int i;
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200204
Martin Peschke869b2b42007-05-09 11:01:20 +0200205 BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status));
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200206 spin_lock_irqsave(&adapter->req_list_lock, flags);
Martin Peschke869b2b42007-05-09 11:01:20 +0200207 for (i = 0; i < REQUEST_LIST_SIZE; i++)
Swen Schillig6fcc4712007-02-07 13:17:57 +0100208 list_splice_init(&adapter->req_list[i], &remove_queue);
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200209 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
210
Martin Peschke869b2b42007-05-09 11:01:20 +0200211 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
212 list_del(&fsf_req->list);
213 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
214 zfcp_fsf_req_complete(fsf_req);
Swen Schillig6fcc4712007-02-07 13:17:57 +0100215 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200216}
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218/*
219 * function: zfcp_fsf_req_complete
220 *
221 * purpose: Updates active counts and timers for openfcp-reqs
222 * May cleanup request after req_eval returns
223 *
224 * returns: 0 - success
225 * !0 - failure
226 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200227 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 */
229int
230zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
231{
232 int retval = 0;
233 int cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 /*
237 * Note: all cleanup handling is done in the callchain of
238 * the function call-chain below.
239 */
240 zfcp_fsf_status_read_handler(fsf_req);
241 goto out;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200242 } else {
243 del_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 zfcp_fsf_protstatus_eval(fsf_req);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 /*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200248 * fsf_req may be deleted due to waking up functions, so
249 * cleanup is saved here and used later
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 */
251 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
252 cleanup = 1;
253 else
254 cleanup = 0;
255
256 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
257
258 /* cleanup request if requested by initiator */
259 if (likely(cleanup)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 /*
261 * lock must not be held here since it will be
262 * grabed by the called routine, too
263 */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200264 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 } else {
266 /* notify initiator waiting for the requests completion */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /*
268 * FIXME: Race! We must not access fsf_req here as it might have been
269 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
270 * flag. It's an improbable case. But, we have the same paranoia for
271 * the cleanup flag already.
272 * Might better be handled using complete()?
273 * (setting the flag and doing wakeup ought to be atomic
274 * with regard to checking the flag as long as waitqueue is
275 * part of the to be released structure)
276 */
277 wake_up(&fsf_req->completion_wq);
278 }
279
280 out:
281 return retval;
282}
283
284/*
285 * function: zfcp_fsf_protstatus_eval
286 *
287 * purpose: evaluates the QTCB of the finished FSF request
288 * and initiates appropriate actions
289 * (usually calling FSF command specific handlers)
290 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200291 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200293 * context:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 *
295 * locks:
296 */
297static int
298zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
299{
300 int retval = 0;
301 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200302 struct fsf_qtcb *qtcb = fsf_req->qtcb;
303 union fsf_prot_status_qual *prot_status_qual =
304 &qtcb->prefix.prot_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200306 zfcp_hba_dbf_event_fsf_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
310 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 goto skip_protstatus;
312 }
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 /* evaluate FSF Protocol Status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200315 switch (qtcb->prefix.prot_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 case FSF_PROT_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 case FSF_PROT_FSF_STATUS_PRESENTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 break;
320
321 case FSF_PROT_QTCB_VERSION_ERROR:
Christof Schmitt553448f2008-06-10 18:20:58 +0200322 dev_err(&adapter->ccw_device->dev,
323 "The QTCB version requested by zfcp (0x%x) is not "
324 "supported by the FCP adapter (lowest supported 0x%x, "
325 "highest supported 0x%x).\n",
326 ZFCP_QTCB_VERSION, prot_status_qual->word[0],
327 prot_status_qual->word[1]);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200328 zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
330 break;
331
332 case FSF_PROT_SEQ_NUMB_ERROR:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200333 zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
335 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
336 break;
337
338 case FSF_PROT_UNSUPP_QTCB_TYPE:
Christof Schmitt553448f2008-06-10 18:20:58 +0200339 dev_err(&adapter->ccw_device->dev,
340 "Packet header type used by the device driver is "
341 "incompatible with that used on the adapter.\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +0200342 zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
344 break;
345
346 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
348 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
349 &(adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
351
352 case FSF_PROT_DUPLICATE_REQUEST_ID:
Christof Schmitt553448f2008-06-10 18:20:58 +0200353 dev_err(&adapter->ccw_device->dev,
354 "The request identifier 0x%Lx is ambiguous.\n",
355 (unsigned long long)qtcb->bottom.support.req_handle);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200356 zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
358 break;
359
360 case FSF_PROT_LINK_DOWN:
Martin Peschke698ec0162008-03-27 14:22:02 +0100361 zfcp_fsf_link_down_info_eval(fsf_req, 37,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200362 &prot_status_qual->link_down_info);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100363 /* FIXME: reopening adapter now? better wait for link up */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200364 zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
366 break;
367
368 case FSF_PROT_REEST_QUEUE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200370 zfcp_erp_modify_adapter_status(adapter, 28, NULL,
371 ZFCP_STATUS_COMMON_RUNNING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 ZFCP_SET);
373 zfcp_erp_adapter_reopen(adapter,
374 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100375 | ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200376 99, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
378 break;
379
380 case FSF_PROT_ERROR_STATE:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200381 zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
383 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
384 break;
385
386 default:
Christof Schmitt553448f2008-06-10 18:20:58 +0200387 dev_err(&adapter->ccw_device->dev,
388 "Transfer protocol status information"
389 "provided by the adapter (0x%x) "
390 "is not compatible with the device driver.\n",
391 qtcb->prefix.prot_status);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200392 zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
394 }
395
396 skip_protstatus:
397 /*
398 * always call specific handlers to give them a chance to do
399 * something meaningful even in error cases
400 */
401 zfcp_fsf_fsfstatus_eval(fsf_req);
402 return retval;
403}
404
405/*
406 * function: zfcp_fsf_fsfstatus_eval
407 *
408 * purpose: evaluates FSF status of completed FSF request
409 * and acts accordingly
410 *
411 * returns:
412 */
413static int
414zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
415{
416 int retval = 0;
417
418 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
419 goto skip_fsfstatus;
420 }
421
422 /* evaluate FSF Status */
423 switch (fsf_req->qtcb->header.fsf_status) {
424 case FSF_UNKNOWN_COMMAND:
Christof Schmitt553448f2008-06-10 18:20:58 +0200425 dev_err(&fsf_req->adapter->ccw_device->dev,
426 "Command issued by the device driver (0x%x) is "
427 "not known by the adapter.\n",
428 fsf_req->qtcb->header.fsf_command);
Martin Peschke1f6f7122008-04-18 12:51:55 +0200429 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
431 break;
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
435 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
438 skip_fsfstatus:
439 /*
440 * always call specific handlers to give them a chance to do
441 * something meaningful even in error cases
442 */
443 zfcp_fsf_req_dispatch(fsf_req);
444
445 return retval;
446}
447
448/*
449 * function: zfcp_fsf_fsfstatus_qual_eval
450 *
451 * purpose: evaluates FSF status-qualifier of completed FSF request
452 * and acts accordingly
453 *
454 * returns:
455 */
456static int
457zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
458{
459 int retval = 0;
460
461 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
462 case FSF_SQ_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 break;
464 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /* The SCSI-stack may now issue retries or escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
467 break;
468 case FSF_SQ_COMMAND_ABORTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /* Carry the aborted state on to upper layer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
471 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
472 break;
473 case FSF_SQ_NO_RECOM:
Christof Schmitt553448f2008-06-10 18:20:58 +0200474 dev_err(&fsf_req->adapter->ccw_device->dev,
475 "No recommendation could be given for a "
476 "problem on the adapter.\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +0200477 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
479 break;
480 case FSF_SQ_ULP_PROGRAMMING_ERROR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
482 break;
483 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
484 case FSF_SQ_NO_RETRY_POSSIBLE:
485 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
486 /* dealt with in the respective functions */
487 break;
488 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
490 break;
491 }
492
493 return retval;
494}
495
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200496/**
497 * zfcp_fsf_link_down_info_eval - evaluate link down information block
498 */
499static void
Martin Peschke698ec0162008-03-27 14:22:02 +0100500zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200501 struct fsf_link_down_info *link_down)
502{
Martin Peschke698ec0162008-03-27 14:22:02 +0100503 struct zfcp_adapter *adapter = fsf_req->adapter;
504
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100505 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
506 &adapter->status))
507 return;
508
509 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
510
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100511 if (link_down == NULL)
512 goto out;
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100513
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200514 switch (link_down->error_code) {
515 case FSF_PSQ_LINK_NO_LIGHT:
Christof Schmitt553448f2008-06-10 18:20:58 +0200516 dev_warn(&fsf_req->adapter->ccw_device->dev,
517 "The local link is down: "
518 "no light detected.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200519 break;
520 case FSF_PSQ_LINK_WRAP_PLUG:
Christof Schmitt553448f2008-06-10 18:20:58 +0200521 dev_warn(&fsf_req->adapter->ccw_device->dev,
522 "The local link is down: "
523 "wrap plug detected.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200524 break;
525 case FSF_PSQ_LINK_NO_FCP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200526 dev_warn(&fsf_req->adapter->ccw_device->dev,
527 "The local link is down: "
528 "adjacent node on link does not support FCP.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200529 break;
530 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
Christof Schmitt553448f2008-06-10 18:20:58 +0200531 dev_warn(&fsf_req->adapter->ccw_device->dev,
532 "The local link is down: "
533 "firmware update in progress.\n");
534 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200535 case FSF_PSQ_LINK_INVALID_WWPN:
Christof Schmitt553448f2008-06-10 18:20:58 +0200536 dev_warn(&fsf_req->adapter->ccw_device->dev,
537 "The local link is down: "
538 "duplicate or invalid WWPN detected.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200539 break;
540 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
Christof Schmitt553448f2008-06-10 18:20:58 +0200541 dev_warn(&fsf_req->adapter->ccw_device->dev,
542 "The local link is down: "
543 "no support for NPIV by Fabric.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200544 break;
545 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
Christof Schmitt553448f2008-06-10 18:20:58 +0200546 dev_warn(&fsf_req->adapter->ccw_device->dev,
547 "The local link is down: "
548 "out of resource in FCP daughtercard.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200549 break;
550 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
Christof Schmitt553448f2008-06-10 18:20:58 +0200551 dev_warn(&fsf_req->adapter->ccw_device->dev,
552 "The local link is down: "
553 "out of resource in Fabric.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200554 break;
555 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
Christof Schmitt553448f2008-06-10 18:20:58 +0200556 dev_warn(&fsf_req->adapter->ccw_device->dev,
557 "The local link is down: "
558 "unable to login to Fabric.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200559 break;
560 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
Christof Schmitt553448f2008-06-10 18:20:58 +0200561 dev_warn(&fsf_req->adapter->ccw_device->dev,
562 "WWPN assignment file corrupted on adapter.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200563 break;
564 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
Christof Schmitt553448f2008-06-10 18:20:58 +0200565 dev_warn(&fsf_req->adapter->ccw_device->dev,
566 "Mode table corrupted on adapter.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200567 break;
568 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
Christof Schmitt553448f2008-06-10 18:20:58 +0200569 dev_warn(&fsf_req->adapter->ccw_device->dev,
570 "No WWPN for assignment table on adapter.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200571 break;
572 default:
Christof Schmitt553448f2008-06-10 18:20:58 +0200573 dev_warn(&fsf_req->adapter->ccw_device->dev,
574 "The local link to adapter is down.\n");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200575 }
576
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +0100577 out:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200578 zfcp_erp_adapter_failed(adapter, id, fsf_req);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200579}
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581/*
582 * function: zfcp_fsf_req_dispatch
583 *
584 * purpose: calls the appropriate command specific handler
585 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200586 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 */
588static int
589zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
590{
591 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 int retval = 0;
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 switch (fsf_req->fsf_command) {
596
597 case FSF_QTCB_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 zfcp_fsf_send_fcp_command_handler(fsf_req);
599 break;
600
601 case FSF_QTCB_ABORT_FCP_CMND:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 zfcp_fsf_abort_fcp_command_handler(fsf_req);
603 break;
604
605 case FSF_QTCB_SEND_GENERIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 zfcp_fsf_send_ct_handler(fsf_req);
607 break;
608
609 case FSF_QTCB_OPEN_PORT_WITH_DID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 zfcp_fsf_open_port_handler(fsf_req);
611 break;
612
613 case FSF_QTCB_OPEN_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 zfcp_fsf_open_unit_handler(fsf_req);
615 break;
616
617 case FSF_QTCB_CLOSE_LUN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 zfcp_fsf_close_unit_handler(fsf_req);
619 break;
620
621 case FSF_QTCB_CLOSE_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 zfcp_fsf_close_port_handler(fsf_req);
623 break;
624
625 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 zfcp_fsf_close_physical_port_handler(fsf_req);
627 break;
628
629 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 zfcp_fsf_exchange_config_data_handler(fsf_req);
631 break;
632
633 case FSF_QTCB_EXCHANGE_PORT_DATA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 zfcp_fsf_exchange_port_data_handler(fsf_req);
635 break;
636
637 case FSF_QTCB_SEND_ELS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 zfcp_fsf_send_els_handler(fsf_req);
639 break;
640
641 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 zfcp_fsf_control_file_handler(fsf_req);
643 break;
644
645 case FSF_QTCB_UPLOAD_CONTROL_FILE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 zfcp_fsf_control_file_handler(fsf_req);
647 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649
650 if (!erp_action)
651 return retval;
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 zfcp_erp_async_handler(erp_action, 0);
654
655 return retval;
656}
657
658/*
659 * function: zfcp_fsf_status_read
660 *
661 * purpose: initiates a Status Read command at the specified adapter
662 *
663 * returns:
664 */
665int
666zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
667{
668 struct zfcp_fsf_req *fsf_req;
669 struct fsf_status_read_buffer *status_buffer;
670 unsigned long lock_flags;
671 volatile struct qdio_buffer_element *sbale;
Heiko Carstensb2141782008-05-19 12:17:39 +0200672 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 /* setup new FSF request */
675 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
676 req_flags | ZFCP_REQ_NO_QTCB,
677 adapter->pool.fsf_req_status_read,
678 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200679 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 goto failed_req_create;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Swen Schillig00bab912008-06-10 18:20:57 +0200682 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
684 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
685 fsf_req->sbale_curr = 2;
686
Heiko Carstensb2141782008-05-19 12:17:39 +0200687 retval = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 status_buffer =
689 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
Heiko Carstensb2141782008-05-19 12:17:39 +0200690 if (!status_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 goto failed_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200693 fsf_req->data = (unsigned long) status_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 /* insert pointer to respective buffer */
696 sbale = zfcp_qdio_sbale_curr(fsf_req);
697 sbale->addr = (void *) status_buffer;
698 sbale->length = sizeof(struct fsf_status_read_buffer);
699
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200700 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200701 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 goto failed_req_send;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 goto out;
705
706 failed_req_send:
707 mempool_free(status_buffer, adapter->pool.data_status_read);
708
709 failed_buf:
710 zfcp_fsf_req_free(fsf_req);
711 failed_req_create:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200712 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 out:
Swen Schillig00bab912008-06-10 18:20:57 +0200714 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return retval;
716}
717
718static int
719zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
720{
721 struct fsf_status_read_buffer *status_buffer;
722 struct zfcp_adapter *adapter;
723 struct zfcp_port *port;
724 unsigned long flags;
725
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200726 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 adapter = fsf_req->adapter;
728
729 read_lock_irqsave(&zfcp_data.config_lock, flags);
730 list_for_each_entry(port, &adapter->port_list_head, list)
731 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
732 break;
733 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
734
Christof Schmitt553448f2008-06-10 18:20:58 +0200735 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 switch (status_buffer->status_subtype) {
739
740 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200741 zfcp_erp_port_reopen(port, 0, 101, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 break;
743
744 case FSF_STATUS_READ_SUB_ERROR_PORT:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200745 zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748 out:
749 return 0;
750}
751
Christof Schmitt553448f2008-06-10 18:20:58 +0200752static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req)
753{
754 struct zfcp_adapter *adapter = req->adapter;
755 struct fsf_status_read_buffer *buf =
756 (struct fsf_status_read_buffer *) req->data;
757 struct fsf_bit_error_payload *err =
758 (struct fsf_bit_error_payload *) buf->payload;
759 dev_warn(&adapter->ccw_device->dev,
760 "Warning: bit error threshold data "
761 "received for the adapter: "
762 "link failures = %i, loss of sync errors = %i, "
763 "loss of signal errors = %i, "
764 "primitive sequence errors = %i, "
765 "invalid transmission word errors = %i, "
766 "CRC errors = %i).\n",
767 err->link_failure_error_count,
768 err->loss_of_sync_error_count,
769 err->loss_of_signal_error_count,
770 err->primitive_sequence_error_count,
771 err->invalid_transmission_word_error_count,
772 err->crc_error_count);
773 dev_warn(&adapter->ccw_device->dev,
774 "Additional bit error threshold data of the adapter: "
775 "primitive sequence event time-outs = %i, "
776 "elastic buffer overrun errors = %i, "
777 "advertised receive buffer-to-buffer credit = %i, "
778 "current receice buffer-to-buffer credit = %i, "
779 "advertised transmit buffer-to-buffer credit = %i, "
780 "current transmit buffer-to-buffer credit = %i).\n",
781 err->primitive_sequence_event_timeout_count,
782 err->elastic_buffer_overrun_error_count,
783 err->advertised_receive_b2b_credit,
784 err->current_receive_b2b_credit,
785 err->advertised_transmit_b2b_credit,
786 err->current_transmit_b2b_credit);
787}
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789/*
790 * function: zfcp_fsf_status_read_handler
791 *
792 * purpose: is called for finished Open Port command
793 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200794 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 */
796static int
797zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
798{
799 int retval = 0;
800 struct zfcp_adapter *adapter = fsf_req->adapter;
801 struct fsf_status_read_buffer *status_buffer =
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200802 (struct fsf_status_read_buffer *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200805 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200807 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 goto out;
809 }
810
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200811 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 switch (status_buffer->status_type) {
814
815 case FSF_STATUS_READ_PORT_CLOSED:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 zfcp_fsf_status_read_port_closed(fsf_req);
817 break;
818
819 case FSF_STATUS_READ_INCOMING_ELS:
Christof Schmitt24073b42008-06-10 18:20:54 +0200820 zfcp_fc_incoming_els(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 break;
822
823 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 break;
825
826 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
Christof Schmitt553448f2008-06-10 18:20:58 +0200827 zfcp_fsf_bit_error_threshold(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 break;
829
830 case FSF_STATUS_READ_LINK_DOWN:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200831 switch (status_buffer->status_subtype) {
832 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
Christof Schmitt553448f2008-06-10 18:20:58 +0200833 dev_warn(&adapter->ccw_device->dev,
834 "Physical link is down.\n");
Martin Peschke698ec0162008-03-27 14:22:02 +0100835 zfcp_fsf_link_down_info_eval(fsf_req, 38,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100836 (struct fsf_link_down_info *)
837 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200838 break;
839 case FSF_STATUS_READ_SUB_FDISC_FAILED:
Christof Schmitt553448f2008-06-10 18:20:58 +0200840 dev_warn(&adapter->ccw_device->dev,
841 "Local link is down "
842 "due to failed FDISC login.\n");
Martin Peschke698ec0162008-03-27 14:22:02 +0100843 zfcp_fsf_link_down_info_eval(fsf_req, 39,
Maxim Shchetyninee69ab72005-12-01 02:48:41 +0100844 (struct fsf_link_down_info *)
845 &status_buffer->payload);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200846 break;
847 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
Christof Schmitt553448f2008-06-10 18:20:58 +0200848 dev_warn(&adapter->ccw_device->dev,
849 "Local link is down "
850 "due to firmware update on adapter.\n");
Martin Peschke698ec0162008-03-27 14:22:02 +0100851 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200852 break;
853 default:
Christof Schmitt553448f2008-06-10 18:20:58 +0200854 dev_warn(&adapter->ccw_device->dev,
855 "Local link is down.\n");
Martin Peschke698ec0162008-03-27 14:22:02 +0100856 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200857 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 break;
859
860 case FSF_STATUS_READ_LINK_UP:
Christof Schmitt553448f2008-06-10 18:20:58 +0200861 dev_info(&adapter->ccw_device->dev,
862 "Local link was replugged.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 /* All ports should be marked as ready to run again */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200864 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 ZFCP_STATUS_COMMON_RUNNING,
866 ZFCP_SET);
867 zfcp_erp_adapter_reopen(adapter,
868 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
Martin Peschke9467a9b2008-03-27 14:22:03 +0100869 | ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200870 102, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 break;
872
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100873 case FSF_STATUS_READ_NOTIFICATION_LOST:
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100874 if (status_buffer->status_subtype &
875 FSF_STATUS_READ_SUB_ACT_UPDATED)
Martin Peschke1f6f7122008-04-18 12:51:55 +0200876 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
Swen Schilligcc8c2822008-06-10 18:21:00 +0200877 if (status_buffer->status_subtype &
878 FSF_STATUS_READ_SUB_INCOMING_ELS)
879 schedule_work(&adapter->scan_work);
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +0100880 break;
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 case FSF_STATUS_READ_CFDC_UPDATED:
Martin Peschke1f6f7122008-04-18 12:51:55 +0200883 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 break;
885
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200886 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
Maxim Shchetyninaef4a982005-09-13 21:51:16 +0200887 adapter->adapter_features = *(u32*) status_buffer->payload;
888 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890 mempool_free(status_buffer, adapter->pool.data_status_read);
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200891 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 /*
893 * recycle buffer and start new request repeat until outbound
894 * queue is empty or adapter shutdown is requested
895 */
896 /*
897 * FIXME(qdio):
898 * we may wait in the req_create for 5s during shutdown, so
899 * qdio_cleanup will have to wait at least that long before returning
900 * with failure to allow us a proper cleanup under all circumstances
901 */
902 /*
903 * FIXME:
904 * allocation failure possible? (Is this code needed?)
905 */
Swen Schilligd26ab062008-05-19 12:17:37 +0200906
907 atomic_inc(&adapter->stat_miss);
908 schedule_work(&adapter->stat_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 out:
910 return retval;
911}
912
913/*
914 * function: zfcp_fsf_abort_fcp_command
915 *
916 * purpose: tells FSF to abort a running SCSI command
917 *
918 * returns: address of initiated FSF request
919 * NULL - request could not be initiated
920 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200921 * FIXME(design): should be watched by a timeout !!!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 * FIXME(design) shouldn't this be modified to return an int
923 * also...don't know how though
924 */
925struct zfcp_fsf_req *
926zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
927 struct zfcp_adapter *adapter,
928 struct zfcp_unit *unit, int req_flags)
929{
930 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 struct zfcp_fsf_req *fsf_req = NULL;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200932 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 int retval = 0;
934
935 /* setup new FSF request */
936 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
937 req_flags, adapter->pool.fsf_req_abort,
938 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +0200939 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Christof Schmitt951f7462007-12-20 12:30:24 +0100942 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
943 &unit->status)))
944 goto unit_blocked;
945
Swen Schillig00bab912008-06-10 18:20:57 +0200946 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
948 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
949
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200950 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /* set handles of unit and its parent port in QTCB */
953 fsf_req->qtcb->header.lun_handle = unit->handle;
954 fsf_req->qtcb->header.port_handle = unit->port->handle;
955
956 /* set handle of request which should be aborted */
957 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
958
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200959 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
960 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt951f7462007-12-20 12:30:24 +0100961 if (!retval)
962 goto out;
963
964 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 zfcp_fsf_req_free(fsf_req);
966 fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 out:
Swen Schillig00bab912008-06-10 18:20:57 +0200969 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 return fsf_req;
971}
972
973/*
974 * function: zfcp_fsf_abort_fcp_command_handler
975 *
976 * purpose: is called for finished Abort FCP Command request
977 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200978 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 */
980static int
981zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
982{
983 int retval = -EINVAL;
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200984 struct zfcp_unit *unit;
Christof Schmitt86275332007-12-20 12:30:23 +0100985 union fsf_status_qual *fsf_stat_qual =
986 &new_fsf_req->qtcb->header.fsf_status_qual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
989 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
990 goto skip_fsfstatus;
991 }
992
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200993 unit = (struct zfcp_unit *) new_fsf_req->data;
994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 /* evaluate FSF status in QTCB */
996 switch (new_fsf_req->qtcb->header.fsf_status) {
997
998 case FSF_PORT_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +0100999 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 /*
1001 * In this case a command that was sent prior to a port
1002 * reopen was aborted (handles are different). This is
1003 * fine.
1004 */
1005 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 /* Let's hope this sorts out the mess */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001007 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001008 new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1010 }
1011 break;
1012
1013 case FSF_LUN_HANDLE_NOT_VALID:
Christof Schmitt86275332007-12-20 12:30:23 +01001014 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 /*
1016 * In this case a command that was sent prior to a unit
1017 * reopen was aborted (handles are different).
1018 * This is fine.
1019 */
1020 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 /* Let's hope this sorts out the mess */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001022 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1024 }
1025 break;
1026
1027 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1030 break;
1031
1032 case FSF_PORT_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02001033 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1035 | ZFCP_STATUS_FSFREQ_RETRY;
1036 break;
1037
1038 case FSF_LUN_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02001039 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1041 | ZFCP_STATUS_FSFREQ_RETRY;
1042 break;
1043
1044 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1046 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02001047 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1049 break;
1050 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 /* SCSI stack will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1053 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 break;
1056
1057 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 retval = 0;
1059 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1060 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062 skip_fsfstatus:
1063 return retval;
1064}
1065
1066/**
1067 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1068 * one SBALE
1069 * Two scatter-gather lists are passed, one for the reqeust and one for the
1070 * response.
1071 */
1072static inline int
1073zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1074 struct scatterlist *resp, int resp_count)
1075{
1076 return ((req_count == 1) &&
1077 (resp_count == 1) &&
1078 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1079 PAGE_MASK) ==
1080 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1081 req[0].length - 1) & PAGE_MASK)) &&
1082 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1083 PAGE_MASK) ==
1084 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1085 resp[0].length - 1) & PAGE_MASK)));
1086}
1087
1088/**
1089 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1090 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1091 * the request
1092 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1093 * a struct zfcp_fsf_req
1094 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1095 * is sent within error recovery
1096 */
1097int
1098zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1099 struct zfcp_erp_action *erp_action)
1100{
1101 volatile struct qdio_buffer_element *sbale;
1102 struct zfcp_port *port;
1103 struct zfcp_adapter *adapter;
1104 struct zfcp_fsf_req *fsf_req;
1105 unsigned long lock_flags;
1106 int bytes;
1107 int ret = 0;
1108
1109 port = ct->port;
1110 adapter = port->adapter;
1111
1112 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1113 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1114 pool, &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02001115 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 goto failed_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Swen Schillig00bab912008-06-10 18:20:57 +02001118 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1120 ct->resp, ct->resp_count)){
1121 /* both request buffer and response buffer
1122 fit into one sbale each */
1123 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1124 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1125 sbale[2].length = ct->req[0].length;
1126 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1127 sbale[3].length = ct->resp[0].length;
1128 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001129 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1131 /* try to use chained SBALs */
1132 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1133 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001134 ct->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 ZFCP_MAX_SBALS_PER_CT_REQ);
1136 if (bytes <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 if (bytes == 0)
1138 ret = -ENOMEM;
1139 else
1140 ret = bytes;
1141
1142 goto failed_send;
1143 }
1144 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1145 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1146 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1147 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001148 ct->resp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 ZFCP_MAX_SBALS_PER_CT_REQ);
1150 if (bytes <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 if (bytes == 0)
1152 ret = -ENOMEM;
1153 else
1154 ret = bytes;
1155
1156 goto failed_send;
1157 }
1158 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1159 } else {
1160 /* reject send generic request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 ret = -EOPNOTSUPP;
1162 goto failed_send;
1163 }
1164
1165 /* settings in QTCB */
1166 fsf_req->qtcb->header.port_handle = port->handle;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001167 fsf_req->qtcb->bottom.support.service_class =
1168 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001170 fsf_req->data = (unsigned long) ct;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001172 zfcp_san_dbf_event_ct_request(fsf_req);
1173
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001174 if (erp_action) {
1175 erp_action->fsf_req = fsf_req;
1176 fsf_req->erp_action = erp_action;
1177 zfcp_erp_start_timer(fsf_req);
1178 } else
1179 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1180
1181 ret = zfcp_fsf_req_send(fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02001182 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 goto failed_send;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 goto out;
1186
1187 failed_send:
1188 zfcp_fsf_req_free(fsf_req);
1189 if (erp_action != NULL) {
1190 erp_action->fsf_req = NULL;
1191 }
1192 failed_req:
1193 out:
Swen Schillig00bab912008-06-10 18:20:57 +02001194 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 return ret;
1196}
1197
1198/**
1199 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1200 * @fsf_req: pointer to struct zfcp_fsf_req
1201 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001202 * Data specific for the Generic Service request is passed using
1203 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1204 * Usually a specific handler for the CT request is called which is
1205 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 */
1207static int
1208zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1209{
1210 struct zfcp_port *port;
1211 struct zfcp_adapter *adapter;
1212 struct zfcp_send_ct *send_ct;
1213 struct fsf_qtcb_header *header;
1214 struct fsf_qtcb_bottom_support *bottom;
1215 int retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 adapter = fsf_req->adapter;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001218 send_ct = (struct zfcp_send_ct *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 port = send_ct->port;
1220 header = &fsf_req->qtcb->header;
1221 bottom = &fsf_req->qtcb->bottom.support;
1222
1223 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1224 goto skip_fsfstatus;
1225
1226 /* evaluate FSF status in QTCB */
1227 switch (header->fsf_status) {
1228
1229 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001230 zfcp_san_dbf_event_ct_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 retval = 0;
1232 break;
1233
1234 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Christof Schmitt553448f2008-06-10 18:20:58 +02001235 zfcp_fsf_class_not_supp(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 break;
1237
1238 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 switch (header->fsf_status_qual.word[0]){
1240 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 /* reopening link to port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 zfcp_test_link(port);
1243 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1244 break;
1245 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1248 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
1250 break;
1251
1252 case FSF_ACCESS_DENIED:
Christof Schmitt553448f2008-06-10 18:20:58 +02001253 zfcp_fsf_access_denied_port(fsf_req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 break;
1255
1256 case FSF_GENERIC_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1258 break;
1259
1260 case FSF_PORT_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02001261 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1263 break;
1264
1265 case FSF_PORT_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02001266 zfcp_erp_port_boxed(port, 49, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1268 | ZFCP_STATUS_FSFREQ_RETRY;
1269 break;
1270
1271 /* following states should never occure, all cases avoided
1272 in zfcp_fsf_send_ct - but who knows ... */
1273 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 case FSF_SBAL_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1278 break;
1279
1280 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 break;
1282 }
1283
1284skip_fsfstatus:
1285 send_ct->status = retval;
1286
1287 if (send_ct->handler != NULL)
1288 send_ct->handler(send_ct->handler_data);
1289
1290 return retval;
1291}
1292
1293/**
1294 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1295 * @els: pointer to struct zfcp_send_els which contains all needed data for
1296 * the command.
1297 */
1298int
1299zfcp_fsf_send_els(struct zfcp_send_els *els)
1300{
1301 volatile struct qdio_buffer_element *sbale;
1302 struct zfcp_fsf_req *fsf_req;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001303 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 struct zfcp_adapter *adapter;
1305 unsigned long lock_flags;
1306 int bytes;
1307 int ret = 0;
1308
1309 d_id = els->d_id;
1310 adapter = els->adapter;
1311
1312 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1313 ZFCP_REQ_AUTO_CLEANUP,
1314 NULL, &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02001315 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 goto failed_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001318 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1319 &els->port->status))) {
1320 ret = -EBUSY;
1321 goto port_blocked;
1322 }
1323
Swen Schillig00bab912008-06-10 18:20:57 +02001324 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 if (zfcp_use_one_sbal(els->req, els->req_count,
1326 els->resp, els->resp_count)){
1327 /* both request buffer and response buffer
1328 fit into one sbale each */
1329 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1330 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1331 sbale[2].length = els->req[0].length;
1332 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1333 sbale[3].length = els->resp[0].length;
1334 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001335 } else if (adapter->adapter_features &
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1337 /* try to use chained SBALs */
1338 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1339 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001340 els->req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 ZFCP_MAX_SBALS_PER_ELS_REQ);
1342 if (bytes <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 if (bytes == 0) {
1344 ret = -ENOMEM;
1345 } else {
1346 ret = bytes;
1347 }
1348 goto failed_send;
1349 }
1350 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1351 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1352 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1353 SBAL_FLAGS0_TYPE_WRITE_READ,
Swen Schillig00bab912008-06-10 18:20:57 +02001354 els->resp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 ZFCP_MAX_SBALS_PER_ELS_REQ);
1356 if (bytes <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if (bytes == 0) {
1358 ret = -ENOMEM;
1359 } else {
1360 ret = bytes;
1361 }
1362 goto failed_send;
1363 }
1364 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1365 } else {
1366 /* reject request */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 ret = -EOPNOTSUPP;
1368 goto failed_send;
1369 }
1370
1371 /* settings in QTCB */
1372 fsf_req->qtcb->bottom.support.d_id = d_id;
Andreas Herrmann06506d02006-05-22 18:18:19 +02001373 fsf_req->qtcb->bottom.support.service_class =
1374 ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001376 fsf_req->data = (unsigned long) els;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Swen Schillig00bab912008-06-10 18:20:57 +02001378 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001380 zfcp_san_dbf_event_els_request(fsf_req);
1381
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001382 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1383 ret = zfcp_fsf_req_send(fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02001384 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 goto failed_send;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 goto out;
1388
Christof Schmitt3f0ca622007-12-20 12:30:25 +01001389 port_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 failed_send:
1391 zfcp_fsf_req_free(fsf_req);
1392
1393 failed_req:
1394 out:
Swen Schillig00bab912008-06-10 18:20:57 +02001395 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 return ret;
1398}
1399
1400/**
1401 * zfcp_fsf_send_els_handler - handler for ELS commands
1402 * @fsf_req: pointer to struct zfcp_fsf_req
1403 *
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001404 * Data specific for the ELS command is passed using
1405 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1406 * Usually a specific handler for the ELS command is called which is
1407 * found in this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 */
1409static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1410{
1411 struct zfcp_adapter *adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 struct zfcp_port *port;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001413 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 struct fsf_qtcb_header *header;
1415 struct fsf_qtcb_bottom_support *bottom;
1416 struct zfcp_send_els *send_els;
1417 int retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001419 send_els = (struct zfcp_send_els *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001421 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 d_id = send_els->d_id;
1423 header = &fsf_req->qtcb->header;
1424 bottom = &fsf_req->qtcb->bottom.support;
1425
1426 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1427 goto skip_fsfstatus;
1428
1429 switch (header->fsf_status) {
1430
1431 case FSF_GOOD:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001432 zfcp_san_dbf_event_els_response(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 retval = 0;
1434 break;
1435
1436 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Christof Schmitt553448f2008-06-10 18:20:58 +02001437 zfcp_fsf_class_not_supp(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 break;
1439
1440 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 switch (header->fsf_status_qual.word[0]){
1442 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Andreas Herrmann64b29a132005-06-13 13:18:56 +02001443 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1444 zfcp_test_link(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1446 break;
1447 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 break;
1450 case FSF_SQ_RETRY_IF_POSSIBLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1452 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454 break;
1455
1456 case FSF_ELS_COMMAND_REJECTED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 case FSF_PAYLOAD_SIZE_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 case FSF_REQUEST_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 case FSF_RESPONSE_SIZE_TOO_LARGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 break;
1461
1462 case FSF_SBAL_MISMATCH:
1463 /* should never occure, avoided in zfcp_fsf_send_els */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1465 break;
1466
1467 case FSF_ACCESS_DENIED:
Christof Schmitt553448f2008-06-10 18:20:58 +02001468 zfcp_fsf_access_denied_port(fsf_req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 break;
1470
1471 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1473 break;
1474 }
1475
1476skip_fsfstatus:
1477 send_els->status = retval;
1478
Heiko Carstensaa551da2007-07-18 10:55:10 +02001479 if (send_els->handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 send_els->handler(send_els->handler_data);
1481
1482 return retval;
1483}
1484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485int
1486zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1487{
1488 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001489 struct zfcp_fsf_req *fsf_req;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001490 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001492 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 /* setup new FSF request */
Swen Schillig52ef11a2007-08-28 09:31:09 +02001495 retval = zfcp_fsf_req_create(adapter,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1497 ZFCP_REQ_AUTO_CLEANUP,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001498 adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001499 &lock_flags, &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001500 if (retval) {
Swen Schillig00bab912008-06-10 18:20:57 +02001501 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001502 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 }
1504
Swen Schillig00bab912008-06-10 18:20:57 +02001505 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001506 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1507 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001509 fsf_req->qtcb->bottom.config.feature_selection =
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001510 FSF_FEATURE_CFDC |
1511 FSF_FEATURE_LUN_SHARING |
Maxim Shchetynin9eb69af2006-01-05 09:56:47 +01001512 FSF_FEATURE_NOTIFICATION_LOST |
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001513 FSF_FEATURE_UPDATE_ALERT;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001514 fsf_req->erp_action = erp_action;
1515 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001517 zfcp_erp_start_timer(fsf_req);
1518 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02001519 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 if (retval) {
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001521 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 erp_action->fsf_req = NULL;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001523 }
Swen Schillig52ef11a2007-08-28 09:31:09 +02001524
1525 return retval;
1526}
1527
1528int
1529zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1530 struct fsf_qtcb_bottom_config *data)
1531{
1532 volatile struct qdio_buffer_element *sbale;
1533 struct zfcp_fsf_req *fsf_req;
1534 unsigned long lock_flags;
1535 int retval;
1536
1537 /* setup new FSF request */
1538 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
Swen Schilligaee6ef12008-04-24 19:35:52 +02001539 ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
1540 &fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001541 if (retval) {
Swen Schillig00bab912008-06-10 18:20:57 +02001542 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001543 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 }
1545
Swen Schillig00bab912008-06-10 18:20:57 +02001546 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001547 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1548 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Swen Schillig52ef11a2007-08-28 09:31:09 +02001550 fsf_req->qtcb->bottom.config.feature_selection =
1551 FSF_FEATURE_CFDC |
1552 FSF_FEATURE_LUN_SHARING |
1553 FSF_FEATURE_NOTIFICATION_LOST |
1554 FSF_FEATURE_UPDATE_ALERT;
1555
1556 if (data)
1557 fsf_req->data = (unsigned long) data;
1558
1559 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1560 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02001561 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Christof Schmitt553448f2008-06-10 18:20:58 +02001562 if (!retval)
Swen Schillig52ef11a2007-08-28 09:31:09 +02001563 wait_event(fsf_req->completion_wq,
1564 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1565
1566 zfcp_fsf_req_free(fsf_req);
1567
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 return retval;
1569}
1570
1571/**
1572 * zfcp_fsf_exchange_config_evaluate
1573 * @fsf_req: fsf_req which belongs to xchg config data request
1574 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1575 *
1576 * returns: -EIO on error, 0 otherwise
1577 */
1578static int
1579zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1580{
1581 struct fsf_qtcb_bottom_config *bottom;
1582 struct zfcp_adapter *adapter = fsf_req->adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001583 struct Scsi_Host *shost = adapter->scsi_host;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 bottom = &fsf_req->qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 adapter->fsf_lic_version = bottom->lic_version;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001587 adapter->adapter_features = bottom->adapter_features;
1588 adapter->connection_features = bottom->connection_features;
6f71d9b2005-04-10 23:04:28 -05001589 adapter->peer_wwpn = 0;
1590 adapter->peer_wwnn = 0;
1591 adapter->peer_d_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
1593 if (xchg_ok) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001594
1595 if (fsf_req->data)
1596 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1597 bottom, sizeof (struct fsf_qtcb_bottom_config));
1598
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001599 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
1600 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
1601 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
1602 fc_host_speed(shost) = bottom->fc_link_speed;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001603 fc_host_supported_classes(shost) =
1604 FC_COS_CLASS2 | FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 adapter->hydra_version = bottom->adapter_type;
Christof Schmittc9615852008-05-06 11:00:05 +02001606 adapter->timer_ticks = bottom->timer_interval;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001607 if (fc_host_permanent_port_name(shost) == -1)
1608 fc_host_permanent_port_name(shost) =
1609 fc_host_port_name(shost);
1610 if (bottom->fc_topology == FSF_TOPO_P2P) {
1611 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
1612 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
1613 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
1614 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1615 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
1616 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1617 else if (bottom->fc_topology == FSF_TOPO_AL)
1618 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1619 else
1620 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 } else {
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001622 fc_host_node_name(shost) = 0;
1623 fc_host_port_name(shost) = 0;
1624 fc_host_port_id(shost) = 0;
1625 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001626 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 adapter->hydra_version = 0;
1628 }
1629
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001630 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 adapter->hardware_version = bottom->hardware_version;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +02001632 memcpy(fc_host_serial_number(shost), bottom->serial_number,
1633 min(FC_SERIAL_NUMBER_SIZE, 17));
1634 EBCASC(fc_host_serial_number(shost),
1635 min(FC_SERIAL_NUMBER_SIZE, 17));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 }
1637
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001639 dev_err(&adapter->ccw_device->dev,
1640 "The adapter only supports newer control block "
1641 "versions, try updated device driver.\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02001642 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 return -EIO;
1644 }
1645 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001646 dev_err(&adapter->ccw_device->dev,
1647 "The adapter only supports older control block "
1648 "versions, consider a microcode upgrade.\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02001649 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 return -EIO;
1651 }
1652 return 0;
1653}
1654
Swen Schillig52ef11a2007-08-28 09:31:09 +02001655/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 * function: zfcp_fsf_exchange_config_data_handler
1657 *
1658 * purpose: is called for finished Exchange Configuration Data command
1659 *
1660 * returns:
1661 */
1662static int
1663zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
1664{
1665 struct fsf_qtcb_bottom_config *bottom;
1666 struct zfcp_adapter *adapter = fsf_req->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001667 struct fsf_qtcb *qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1670 return -EIO;
1671
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001672 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
1676 return -EIO;
1677
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001678 switch (fc_host_port_type(adapter->scsi_host)) {
1679 case FC_PORTTYPE_PTP:
Christof Schmitt553448f2008-06-10 18:20:58 +02001680 if (fsf_req->erp_action)
1681 dev_info(&adapter->ccw_device->dev,
1682 "Point-to-Point fibrechannel "
1683 "configuration detected.\n");
6f71d9b2005-04-10 23:04:28 -05001684 break;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001685 case FC_PORTTYPE_NLPORT:
Christof Schmitt553448f2008-06-10 18:20:58 +02001686 dev_err(&adapter->ccw_device->dev,
1687 "Unsupported arbitrated loop fibrechannel "
1688 "topology detected, shutting down adapter\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02001689 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 return -EIO;
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001691 case FC_PORTTYPE_NPORT:
Swen Schilligec258fe2008-04-24 19:35:53 +02001692 if (fsf_req->erp_action)
Christof Schmitt553448f2008-06-10 18:20:58 +02001693 dev_info(&adapter->ccw_device->dev,
1694 "Switched fabric fibrechannel "
1695 "network detected.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 break;
1697 default:
Christof Schmitt553448f2008-06-10 18:20:58 +02001698 dev_err(&adapter->ccw_device->dev,
1699 "The fibrechannel topology reported by the "
1700 "adapter is not known by the zfcp driver, "
1701 "shutting down adapter.\n");
Martin Peschke1f6f7122008-04-18 12:51:55 +02001702 zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return -EIO;
1704 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001705 bottom = &qtcb->bottom.config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001707 dev_err(&adapter->ccw_device->dev,
1708 "Maximum QTCB size (%d bytes) allowed by "
1709 "the adapter is lower than the minimum "
1710 "required by the driver (%ld bytes).\n",
1711 bottom->max_qtcb_size, sizeof(struct fsf_qtcb));
Martin Peschke1f6f7122008-04-18 12:51:55 +02001712 zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 return -EIO;
1714 }
1715 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
1716 &adapter->status);
1717 break;
1718 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
1720 return -EIO;
1721
Swen Schillig52ef11a2007-08-28 09:31:09 +02001722 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
1723 &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001724
Martin Peschke698ec0162008-03-27 14:22:02 +01001725 zfcp_fsf_link_down_info_eval(fsf_req, 42,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001726 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 break;
1728 default:
Martin Peschke1f6f7122008-04-18 12:51:55 +02001729 zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 return -EIO;
1731 }
1732 return 0;
1733}
1734
1735/**
1736 * zfcp_fsf_exchange_port_data - request information about local port
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001737 * @erp_action: ERP action for the adapter for which port data is requested
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 */
1739int
Swen Schillig52ef11a2007-08-28 09:31:09 +02001740zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
1742 volatile struct qdio_buffer_element *sbale;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001743 struct zfcp_fsf_req *fsf_req;
1744 struct zfcp_adapter *adapter = erp_action->adapter;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001745 unsigned long lock_flags;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001746 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Christof Schmitt553448f2008-06-10 18:20:58 +02001748 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schillig52ef11a2007-08-28 09:31:09 +02001749 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 /* setup new FSF request */
1752 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
Swen Schillig52ef11a2007-08-28 09:31:09 +02001753 ZFCP_REQ_AUTO_CLEANUP,
1754 adapter->pool.fsf_req_erp,
1755 &lock_flags, &fsf_req);
1756 if (retval) {
Swen Schillig00bab912008-06-10 18:20:57 +02001757 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001758 return retval;
1759 }
1760
Swen Schillig00bab912008-06-10 18:20:57 +02001761 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001762 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1763 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1764
1765 erp_action->fsf_req = fsf_req;
1766 fsf_req->erp_action = erp_action;
1767 zfcp_erp_start_timer(fsf_req);
1768
1769 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02001770 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001771
1772 if (retval) {
Swen Schillig52ef11a2007-08-28 09:31:09 +02001773 zfcp_fsf_req_free(fsf_req);
1774 erp_action->fsf_req = NULL;
1775 }
Swen Schillig52ef11a2007-08-28 09:31:09 +02001776 return retval;
1777}
1778
1779
1780/**
1781 * zfcp_fsf_exchange_port_data_sync - request information about local port
1782 * and wait until information is ready
1783 */
1784int
1785zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
1786 struct fsf_qtcb_bottom_port *data)
1787{
1788 volatile struct qdio_buffer_element *sbale;
1789 struct zfcp_fsf_req *fsf_req;
1790 unsigned long lock_flags;
1791 int retval;
1792
Christof Schmitt553448f2008-06-10 18:20:58 +02001793 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
Swen Schillig52ef11a2007-08-28 09:31:09 +02001794 return -EOPNOTSUPP;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001795
1796 /* setup new FSF request */
1797 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
1798 0, NULL, &lock_flags, &fsf_req);
1799 if (retval) {
Swen Schillig00bab912008-06-10 18:20:57 +02001800 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Andreas Herrmann2448c452005-12-01 02:50:36 +01001801 return retval;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001802 }
1803
1804 if (data)
Andreas Herrmann2448c452005-12-01 02:50:36 +01001805 fsf_req->data = (unsigned long) data;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001806
Swen Schillig00bab912008-06-10 18:20:57 +02001807 sbale = zfcp_qdio_sbale_req(fsf_req);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001808 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1809 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Swen Schillig52ef11a2007-08-28 09:31:09 +02001811 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001812 retval = zfcp_fsf_req_send(fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02001813 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Christof Schmitt553448f2008-06-10 18:20:58 +02001815 if (!retval)
Andreas Herrmann2448c452005-12-01 02:50:36 +01001816 wait_event(fsf_req->completion_wq,
1817 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
Swen Schillig52ef11a2007-08-28 09:31:09 +02001818
1819 zfcp_fsf_req_free(fsf_req);
1820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 return retval;
1822}
1823
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001824/**
1825 * zfcp_fsf_exchange_port_evaluate
1826 * @fsf_req: fsf_req which belongs to xchg port data request
1827 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
1828 */
1829static void
1830zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1831{
1832 struct zfcp_adapter *adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001833 struct fsf_qtcb_bottom_port *bottom;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001834 struct Scsi_Host *shost;
1835
1836 adapter = fsf_req->adapter;
Swen Schillig52ef11a2007-08-28 09:31:09 +02001837 bottom = &fsf_req->qtcb->bottom.port;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001838 shost = adapter->scsi_host;
1839
Swen Schillig52ef11a2007-08-28 09:31:09 +02001840 if (fsf_req->data)
1841 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
1842 sizeof(struct fsf_qtcb_bottom_port));
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001843
1844 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1845 fc_host_permanent_port_name(shost) = bottom->wwpn;
1846 else
1847 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
1848 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
1849 fc_host_supported_speeds(shost) = bottom->supported_speed;
1850}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852/**
1853 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
1854 * @fsf_req: pointer to struct zfcp_fsf_req
1855 */
1856static void
1857zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
1858{
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001859 struct zfcp_adapter *adapter;
1860 struct fsf_qtcb *qtcb;
1861
1862 adapter = fsf_req->adapter;
1863 qtcb = fsf_req->qtcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1866 return;
1867
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001868 switch (qtcb->header.fsf_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 case FSF_GOOD:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001870 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001871 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001872 break;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001873 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001874 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001875 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
Martin Peschke698ec0162008-03-27 14:22:02 +01001876 zfcp_fsf_link_down_info_eval(fsf_req, 43,
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001877 &qtcb->header.fsf_status_qual.link_down_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 }
1880}
1881
1882
1883/*
1884 * function: zfcp_fsf_open_port
1885 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001886 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 *
1888 * returns: address of initiated FSF request
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001889 * NULL - request could not be initiated
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 */
1891int
1892zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1893{
1894 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001895 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 unsigned long lock_flags;
1897 int retval = 0;
1898
1899 /* setup new FSF request */
1900 retval = zfcp_fsf_req_create(erp_action->adapter,
1901 FSF_QTCB_OPEN_PORT_WITH_DID,
1902 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1903 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001904 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02001905 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Swen Schillig00bab912008-06-10 18:20:57 +02001908 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1910 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1911
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001912 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001914 fsf_req->data = (unsigned long) erp_action->port;
1915 fsf_req->erp_action = erp_action;
1916 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001918 zfcp_erp_start_timer(fsf_req);
1919 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 if (retval) {
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001921 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 erp_action->fsf_req = NULL;
1923 goto out;
1924 }
1925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 out:
Swen Schillig00bab912008-06-10 18:20:57 +02001927 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 return retval;
1929}
1930
1931/*
1932 * function: zfcp_fsf_open_port_handler
1933 *
1934 * purpose: is called for finished Open Port command
1935 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001936 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 */
1938static int
1939zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
1940{
1941 int retval = -EINVAL;
1942 struct zfcp_port *port;
1943 struct fsf_plogi *plogi;
1944 struct fsf_qtcb_header *header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Andreas Herrmann059c97d2005-09-13 21:47:52 +02001946 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 header = &fsf_req->qtcb->header;
1948
1949 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1950 /* don't change port status in our bookkeeping */
1951 goto skip_fsfstatus;
1952 }
1953
1954 /* evaluate FSF status in QTCB */
1955 switch (header->fsf_status) {
1956
1957 case FSF_PORT_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 /*
1959 * This is a bug, however operation should continue normally
1960 * if it is simply ignored
1961 */
1962 break;
1963
1964 case FSF_ACCESS_DENIED:
Christof Schmitt553448f2008-06-10 18:20:58 +02001965 zfcp_fsf_access_denied_port(fsf_req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 break;
1967
1968 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
Christof Schmitt553448f2008-06-10 18:20:58 +02001969 dev_warn(&fsf_req->adapter->ccw_device->dev,
1970 "The adapter is out of resources. The remote port "
1971 "0x%016Lx could not be opened, disabling it.\n",
1972 port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001973 zfcp_erp_port_failed(port, 31, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1975 break;
1976
1977 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 switch (header->fsf_status_qual.word[0]) {
1979 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 /* ERP strategy will escalate */
1981 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1982 break;
1983 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1984 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1986 break;
1987 case FSF_SQ_NO_RETRY_POSSIBLE:
Christof Schmitt553448f2008-06-10 18:20:58 +02001988 dev_warn(&fsf_req->adapter->ccw_device->dev,
1989 "The remote port 0x%016Lx could not be "
1990 "opened. Disabling it.\n", port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001991 zfcp_erp_port_failed(port, 32, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1993 break;
1994 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 break;
1996 }
1997 break;
1998
1999 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 /* save port handle assigned by FSF */
2001 port->handle = header->port_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 /* mark port as open */
2003 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2004 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
Andreas Herrmannd736a272005-06-13 13:23:57 +02002005 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2006 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2007 &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 retval = 0;
2009 /* check whether D_ID has changed during open */
2010 /*
2011 * FIXME: This check is not airtight, as the FCP channel does
2012 * not monitor closures of target port connections caused on
2013 * the remote side. Thus, they might miss out on invalidating
2014 * locally cached WWPNs (and other N_Port parameters) of gone
2015 * target ports. So, our heroic attempt to make things safe
2016 * could be undermined by 'open port' response data tagged with
2017 * obsolete WWPNs. Another reason to monitor potential
2018 * connection closures ourself at least (by interpreting
2019 * incoming ELS' and unsolicited status). It just crosses my
2020 * mind that one should be able to cross-check by means of
2021 * another GID_PN straight after a port has been opened.
2022 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2023 */
2024 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2025 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2026 {
2027 if (fsf_req->qtcb->bottom.support.els1_length <
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002028 sizeof (struct fsf_plogi)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 /* skip sanity check and assume wwpn is ok */
2030 } else {
2031 if (plogi->serv_param.wwpn != port->wwpn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 atomic_clear_mask(
2033 ZFCP_STATUS_PORT_DID_DID,
2034 &port->status);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002035 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 port->wwnn = plogi->serv_param.wwnn;
Christof Schmitt24073b42008-06-10 18:20:54 +02002037 zfcp_fc_plogi_evaluate(port, plogi);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002038 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 }
2040 }
2041 break;
2042
2043 case FSF_UNKNOWN_OP_SUBTYPE:
2044 /* should never occure, subtype not set in zfcp_fsf_open_port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2046 break;
2047
2048 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 break;
2050 }
2051
2052 skip_fsfstatus:
2053 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2054 return retval;
2055}
2056
2057/*
2058 * function: zfcp_fsf_close_port
2059 *
2060 * purpose: submit FSF command "close port"
2061 *
2062 * returns: address of initiated FSF request
2063 * NULL - request could not be initiated
2064 */
2065int
2066zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2067{
2068 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002069 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 unsigned long lock_flags;
2071 int retval = 0;
2072
2073 /* setup new FSF request */
2074 retval = zfcp_fsf_req_create(erp_action->adapter,
2075 FSF_QTCB_CLOSE_PORT,
2076 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2077 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002078 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002079 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Swen Schillig00bab912008-06-10 18:20:57 +02002082 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2084 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2085
2086 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002087 fsf_req->data = (unsigned long) erp_action->port;
2088 fsf_req->erp_action = erp_action;
2089 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2090 fsf_req->erp_action = erp_action;
2091 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002093 zfcp_erp_start_timer(fsf_req);
2094 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 if (retval) {
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002096 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 erp_action->fsf_req = NULL;
2098 goto out;
2099 }
2100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002102 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 return retval;
2104}
2105
2106/*
2107 * function: zfcp_fsf_close_port_handler
2108 *
2109 * purpose: is called for finished Close Port FSF command
2110 *
2111 * returns:
2112 */
2113static int
2114zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2115{
2116 int retval = -EINVAL;
2117 struct zfcp_port *port;
2118
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002119 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2122 /* don't change port status in our bookkeeping */
2123 goto skip_fsfstatus;
2124 }
2125
2126 /* evaluate FSF status in QTCB */
2127 switch (fsf_req->qtcb->header.fsf_status) {
2128
2129 case FSF_PORT_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002130 zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2132 break;
2133
2134 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 /* Note: FSF has actually closed the port in this case.
2136 * The status code is just daft. Fingers crossed for a change
2137 */
2138 retval = 0;
2139 break;
2140
2141 case FSF_GOOD:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002142 zfcp_erp_modify_port_status(port, 33, fsf_req,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 ZFCP_STATUS_COMMON_OPEN,
2144 ZFCP_CLEAR);
2145 retval = 0;
2146 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 }
2148
2149 skip_fsfstatus:
2150 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2151 return retval;
2152}
2153
2154/*
2155 * function: zfcp_fsf_close_physical_port
2156 *
2157 * purpose: submit FSF command "close physical port"
2158 *
2159 * returns: address of initiated FSF request
2160 * NULL - request could not be initiated
2161 */
2162int
2163zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002166 struct zfcp_fsf_req *fsf_req;
2167 unsigned long lock_flags;
2168 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 /* setup new FSF request */
2171 retval = zfcp_fsf_req_create(erp_action->adapter,
2172 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2173 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2174 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002175 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002176 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Swen Schillig00bab912008-06-10 18:20:57 +02002179 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2181 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2182
2183 /* mark port as being closed */
2184 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2185 &erp_action->port->status);
2186 /* save a pointer to this port */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002187 fsf_req->data = (unsigned long) erp_action->port;
2188 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2189 fsf_req->erp_action = erp_action;
2190 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002192 zfcp_erp_start_timer(fsf_req);
2193 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 if (retval) {
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002195 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 erp_action->fsf_req = NULL;
2197 goto out;
2198 }
2199
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002201 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 return retval;
2203}
2204
2205/*
2206 * function: zfcp_fsf_close_physical_port_handler
2207 *
2208 * purpose: is called for finished Close Physical Port FSF command
2209 *
2210 * returns:
2211 */
2212static int
2213zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2214{
2215 int retval = -EINVAL;
2216 struct zfcp_port *port;
2217 struct zfcp_unit *unit;
2218 struct fsf_qtcb_header *header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002220 port = (struct zfcp_port *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 header = &fsf_req->qtcb->header;
2222
2223 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2224 /* don't change port status in our bookkeeping */
2225 goto skip_fsfstatus;
2226 }
2227
2228 /* evaluate FSF status in QTCB */
2229 switch (header->fsf_status) {
2230
2231 case FSF_PORT_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002232 zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2234 break;
2235
2236 case FSF_ACCESS_DENIED:
Christof Schmitt553448f2008-06-10 18:20:58 +02002237 zfcp_fsf_access_denied_port(fsf_req, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 break;
2239
2240 case FSF_PORT_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002241 zfcp_erp_port_boxed(port, 50, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2243 ZFCP_STATUS_FSFREQ_RETRY;
Christof Schmitt5c815d12008-03-10 16:18:54 +01002244
2245 /* can't use generic zfcp_erp_modify_port_status because
2246 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2247 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2248 list_for_each_entry(unit, &port->unit_list_head, list)
2249 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2250 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 break;
2252
2253 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 switch (header->fsf_status_qual.word[0]) {
2255 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 /* This will now be escalated by ERP */
2257 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2258 break;
2259 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2262 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 }
2264 break;
2265
2266 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 /* can't use generic zfcp_erp_modify_port_status because
2268 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2269 */
2270 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2271 list_for_each_entry(unit, &port->unit_list_head, list)
2272 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2273 retval = 0;
2274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 }
2276
2277 skip_fsfstatus:
2278 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2279 return retval;
2280}
2281
2282/*
2283 * function: zfcp_fsf_open_unit
2284 *
2285 * purpose:
2286 *
2287 * returns:
2288 *
2289 * assumptions: This routine does not check whether the associated
2290 * remote port has already been opened. This should be
2291 * done by calling routines. Otherwise some status
2292 * may be presented by FSF
2293 */
2294int
2295zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2296{
2297 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002298 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 unsigned long lock_flags;
2300 int retval = 0;
2301
2302 /* setup new FSF request */
2303 retval = zfcp_fsf_req_create(erp_action->adapter,
2304 FSF_QTCB_OPEN_LUN,
2305 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2306 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002307 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002308 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Swen Schillig00bab912008-06-10 18:20:57 +02002311 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2313 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2314
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002315 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2316 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002317 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002318 fsf_req->qtcb->bottom.support.option =
Andreas Herrmann06506d02006-05-22 18:18:19 +02002319 FSF_OPEN_LUN_SUPPRESS_BOXING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002321 fsf_req->data = (unsigned long) erp_action->unit;
2322 fsf_req->erp_action = erp_action;
2323 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002325 zfcp_erp_start_timer(fsf_req);
2326 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 if (retval) {
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002328 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 erp_action->fsf_req = NULL;
2330 goto out;
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002333 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 return retval;
2335}
2336
2337/*
2338 * function: zfcp_fsf_open_unit_handler
2339 *
2340 * purpose: is called for finished Open LUN command
2341 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002342 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 */
2344static int
2345zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2346{
2347 int retval = -EINVAL;
2348 struct zfcp_adapter *adapter;
2349 struct zfcp_unit *unit;
2350 struct fsf_qtcb_header *header;
2351 struct fsf_qtcb_bottom_support *bottom;
2352 struct fsf_queue_designator *queue_designator;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002353 int exclusive, readwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002355 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
2357 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2358 /* don't change unit status in our bookkeeping */
2359 goto skip_fsfstatus;
2360 }
2361
2362 adapter = fsf_req->adapter;
2363 header = &fsf_req->qtcb->header;
2364 bottom = &fsf_req->qtcb->bottom.support;
2365 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Heiko Carstensb64ddf92007-05-08 11:19:57 +02002368 ZFCP_STATUS_COMMON_ACCESS_BOXED |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 ZFCP_STATUS_UNIT_SHARED |
2370 ZFCP_STATUS_UNIT_READONLY,
2371 &unit->status);
2372
2373 /* evaluate FSF status in QTCB */
2374 switch (header->fsf_status) {
2375
2376 case FSF_PORT_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002377 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2379 break;
2380
2381 case FSF_LUN_ALREADY_OPEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2383 break;
2384
2385 case FSF_ACCESS_DENIED:
Christof Schmitt553448f2008-06-10 18:20:58 +02002386 zfcp_fsf_access_denied_unit(fsf_req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02002388 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 break;
2390
2391 case FSF_PORT_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002392 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2394 ZFCP_STATUS_FSFREQ_RETRY;
2395 break;
2396
2397 case FSF_LUN_SHARING_VIOLATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 if (header->fsf_status_qual.word[0] != 0) {
Christof Schmitt553448f2008-06-10 18:20:58 +02002399 dev_warn(&adapter->ccw_device->dev,
2400 "FCP-LUN 0x%Lx at the remote port "
2401 "with WWPN 0x%Lx "
2402 "connected to the adapter "
2403 "is already in use in LPAR%d, CSS%d.\n",
2404 unit->fcp_lun,
2405 unit->port->wwpn,
2406 queue_designator->hla,
2407 queue_designator->cssid);
2408 } else
2409 zfcp_act_eval_err(adapter,
2410 header->fsf_status_qual.word[2]);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002411 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
2413 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
2414 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2415 break;
2416
2417 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
Christof Schmitt553448f2008-06-10 18:20:58 +02002418 dev_warn(&fsf_req->adapter->ccw_device->dev,
2419 "The adapter ran out of resources. There is no "
2420 "handle available for unit 0x%016Lx on port 0x%016Lx.",
2421 unit->fcp_lun, unit->port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002422 zfcp_erp_unit_failed(unit, 34, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2424 break;
2425
2426 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 switch (header->fsf_status_qual.word[0]) {
2428 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 /* Re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02002430 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2432 break;
2433 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2436 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
2438 break;
2439
2440 case FSF_INVALID_COMMAND_OPTION:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2442 retval = -EINVAL;
2443 break;
2444
2445 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 /* save LUN handle assigned by FSF */
2447 unit->handle = header->lun_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 /* mark unit as open */
2449 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002450
2451 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
2452 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
2453 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
2454 exclusive = (bottom->lun_access_info &
2455 FSF_UNIT_ACCESS_EXCLUSIVE);
2456 readwrite = (bottom->lun_access_info &
2457 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 if (!exclusive)
2460 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
2461 &unit->status);
2462
2463 if (!readwrite) {
2464 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
2465 &unit->status);
Christof Schmitt553448f2008-06-10 18:20:58 +02002466 dev_info(&fsf_req->adapter->ccw_device->dev,
2467 "Read-only access for unit 0x%016Lx "
2468 "on port 0x%016Lx.\n",
2469 unit->fcp_lun, unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 }
2471
2472 if (exclusive && !readwrite) {
Christof Schmitt553448f2008-06-10 18:20:58 +02002473 dev_err(&fsf_req->adapter->ccw_device->dev,
2474 "Exclusive access of read-only unit "
2475 "0x%016Lx on port 0x%016Lx not "
2476 "supported, disabling unit.\n",
2477 unit->fcp_lun, unit->port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002478 zfcp_erp_unit_failed(unit, 35, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02002480 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 } else if (!exclusive && readwrite) {
Christof Schmitt553448f2008-06-10 18:20:58 +02002482 dev_err(&fsf_req->adapter->ccw_device->dev,
2483 "Shared access of read-write unit "
2484 "0x%016Lx on port 0x%016Lx not "
2485 "supported, disabling unit.\n",
2486 unit->fcp_lun, unit->port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002487 zfcp_erp_unit_failed(unit, 36, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Martin Peschke1f6f7122008-04-18 12:51:55 +02002489 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 }
2491 }
2492
2493 retval = 0;
2494 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 }
2496
2497 skip_fsfstatus:
2498 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
2499 return retval;
2500}
2501
2502/*
2503 * function: zfcp_fsf_close_unit
2504 *
2505 * purpose:
2506 *
2507 * returns: address of fsf_req - request successfully initiated
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002508 * NULL -
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 *
2510 * assumptions: This routine does not check whether the associated
2511 * remote port/lun has already been opened. This should be
2512 * done by calling routines. Otherwise some status
2513 * may be presented by FSF
2514 */
2515int
2516zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2517{
2518 volatile struct qdio_buffer_element *sbale;
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002519 struct zfcp_fsf_req *fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 unsigned long lock_flags;
2521 int retval = 0;
2522
2523 /* setup new FSF request */
2524 retval = zfcp_fsf_req_create(erp_action->adapter,
2525 FSF_QTCB_CLOSE_LUN,
2526 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2527 erp_action->adapter->pool.fsf_req_erp,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002528 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002529 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Swen Schillig00bab912008-06-10 18:20:57 +02002532 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2534 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2535
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002536 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2537 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002539 fsf_req->data = (unsigned long) erp_action->unit;
2540 fsf_req->erp_action = erp_action;
2541 erp_action->fsf_req = fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002543 zfcp_erp_start_timer(fsf_req);
2544 retval = zfcp_fsf_req_send(erp_action->fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 if (retval) {
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002546 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 erp_action->fsf_req = NULL;
2548 goto out;
2549 }
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002552 write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 return retval;
2554}
2555
2556/*
2557 * function: zfcp_fsf_close_unit_handler
2558 *
2559 * purpose: is called for finished Close LUN FSF command
2560 *
2561 * returns:
2562 */
2563static int
2564zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
2565{
2566 int retval = -EINVAL;
2567 struct zfcp_unit *unit;
2568
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002569 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
2571 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2572 /* don't change unit status in our bookkeeping */
2573 goto skip_fsfstatus;
2574 }
2575
2576 /* evaluate FSF status in QTCB */
2577 switch (fsf_req->qtcb->header.fsf_status) {
2578
2579 case FSF_PORT_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002580 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2582 break;
2583
2584 case FSF_LUN_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002585 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2587 break;
2588
2589 case FSF_PORT_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002590 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2592 ZFCP_STATUS_FSFREQ_RETRY;
2593 break;
2594
2595 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
2597 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02002599 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2601 break;
2602 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 /* ERP strategy will escalate */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2605 break;
2606 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 break;
2608 }
2609 break;
2610
2611 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 /* mark unit as closed */
2613 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2614 retval = 0;
2615 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 }
2617
2618 skip_fsfstatus:
2619 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
2620 return retval;
2621}
2622
2623/**
2624 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2625 * @adapter: adapter where scsi command is issued
2626 * @unit: unit where command is sent to
2627 * @scsi_cmnd: scsi command to be sent
2628 * @timer: timer to be started when request is initiated
2629 * @req_flags: flags for fsf_request
2630 */
2631int
2632zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
2633 struct zfcp_unit *unit,
2634 struct scsi_cmnd * scsi_cmnd,
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002635 int use_timer, int req_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636{
2637 struct zfcp_fsf_req *fsf_req = NULL;
2638 struct fcp_cmnd_iu *fcp_cmnd_iu;
2639 unsigned int sbtype;
2640 unsigned long lock_flags;
2641 int real_bytes = 0;
2642 int retval = 0;
2643 int mask;
2644
2645 /* setup new FSF request */
2646 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2647 adapter->pool.fsf_req_scsi,
2648 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002649 if (unlikely(retval < 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 goto failed_req_create;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Christof Schmittba172422007-12-20 12:30:26 +01002652 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2653 &unit->status))) {
2654 retval = -EBUSY;
2655 goto unit_blocked;
2656 }
2657
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002658 zfcp_unit_get(unit);
2659 fsf_req->unit = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002661 /* associate FSF request with SCSI request (for look up on abort) */
Andreas Herrmann4eff4a32006-09-18 22:29:20 +02002662 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002663
2664 /* associate SCSI command with FSF request */
2665 fsf_req->data = (unsigned long) scsi_cmnd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
2667 /* set handles of unit and its parent port in QTCB */
2668 fsf_req->qtcb->header.lun_handle = unit->handle;
2669 fsf_req->qtcb->header.port_handle = unit->port->handle;
2670
2671 /* FSF does not define the structure of the FCP_CMND IU */
2672 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
2673 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
2674
2675 /*
2676 * set depending on data direction:
2677 * data direction bits in SBALE (SB Type)
2678 * data direction bits in QTCB
2679 * data direction bits in FCP_CMND IU
2680 */
2681 switch (scsi_cmnd->sc_data_direction) {
2682 case DMA_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2684 /*
2685 * FIXME(qdio):
2686 * what is the correct type for commands
2687 * without 'real' data buffers?
2688 */
2689 sbtype = SBAL_FLAGS0_TYPE_READ;
2690 break;
2691 case DMA_FROM_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2693 sbtype = SBAL_FLAGS0_TYPE_READ;
2694 fcp_cmnd_iu->rddata = 1;
2695 break;
2696 case DMA_TO_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2698 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2699 fcp_cmnd_iu->wddata = 1;
2700 break;
2701 case DMA_BIDIRECTIONAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 default:
2703 /*
2704 * dummy, catch this condition earlier
2705 * in zfcp_scsi_queuecommand
2706 */
2707 goto failed_scsi_cmnd;
2708 }
2709
2710 /* set FC service class in QTCB (3 per default) */
Andreas Herrmann06506d02006-05-22 18:18:19 +02002711 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712
2713 /* set FCP_LUN in FCP_CMND IU in QTCB */
2714 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2715
2716 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
2717
2718 /* set task attributes in FCP_CMND IU in QTCB */
2719 if (likely((scsi_cmnd->device->simple_tags) ||
2720 (atomic_test_mask(mask, &unit->status))))
2721 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
2722 else
2723 fcp_cmnd_iu->task_attribute = UNTAGGED;
2724
2725 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
Christof Schmitt553448f2008-06-10 18:20:58 +02002726 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 fcp_cmnd_iu->add_fcp_cdb_length
2728 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /*
2730 * copy SCSI CDB (including additional length, if any) to
2731 * FCP_CDB in FCP_CMND IU in QTCB
2732 */
2733 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
2734
2735 /* FCP CMND IU length in QTCB */
2736 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
2737 sizeof (struct fcp_cmnd_iu) +
2738 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
2739
2740 /* generate SBALEs from data buffer */
Swen Schillig00bab912008-06-10 18:20:57 +02002741 real_bytes = zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
2742 scsi_sglist(scsi_cmnd),
2743 ZFCP_MAX_SBALS_PER_REQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 if (unlikely(real_bytes < 0)) {
Christof Schmitt553448f2008-06-10 18:20:58 +02002745 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ)
Christof Schmitt2282f652007-08-28 09:30:22 +02002746 retval = -EIO;
Christof Schmitt553448f2008-06-10 18:20:58 +02002747 else {
2748 dev_err(&adapter->ccw_device->dev,
2749 "SCSI request too large. "
2750 "Shutting down unit 0x%016Lx on port "
2751 "0x%016Lx.\n", unit->fcp_lun,
2752 unit->port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002753 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
Christof Schmitt2282f652007-08-28 09:30:22 +02002754 retval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 }
2756 goto no_fit;
2757 }
2758
2759 /* set length of FCP data length in FCP_CMND IU in QTCB */
2760 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
2761
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002762 if (use_timer)
2763 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2764
2765 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002766 if (unlikely(retval < 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 goto send_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 goto success;
2770
2771 send_failed:
2772 no_fit:
2773 failed_scsi_cmnd:
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002774 zfcp_unit_put(unit);
Christof Schmitt57b76582008-04-18 12:51:57 +02002775 unit_blocked:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 zfcp_fsf_req_free(fsf_req);
2777 fsf_req = NULL;
2778 scsi_cmnd->host_scribble = NULL;
2779 success:
2780 failed_req_create:
Swen Schillig00bab912008-06-10 18:20:57 +02002781 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 return retval;
2783}
2784
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785struct zfcp_fsf_req *
2786zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
2787 struct zfcp_unit *unit,
2788 u8 tm_flags, int req_flags)
2789{
2790 struct zfcp_fsf_req *fsf_req = NULL;
2791 int retval = 0;
2792 struct fcp_cmnd_iu *fcp_cmnd_iu;
2793 unsigned long lock_flags;
2794 volatile struct qdio_buffer_element *sbale;
2795
2796 /* setup new FSF request */
2797 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
2798 adapter->pool.fsf_req_scsi,
2799 &lock_flags, &fsf_req);
Christof Schmitt553448f2008-06-10 18:20:58 +02002800 if (retval < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Christof Schmittfdf23452007-12-20 12:30:27 +01002803 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2804 &unit->status)))
2805 goto unit_blocked;
2806
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 /*
2808 * Used to decide on proper handler in the return path,
2809 * could be either zfcp_fsf_send_fcp_command_task_handler or
2810 * zfcp_fsf_send_fcp_command_task_management_handler */
2811
2812 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2813
2814 /*
2815 * hold a pointer to the unit being target of this
2816 * task management request
2817 */
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002818 fsf_req->data = (unsigned long) unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 /* set FSF related fields in QTCB */
2821 fsf_req->qtcb->header.lun_handle = unit->handle;
2822 fsf_req->qtcb->header.port_handle = unit->port->handle;
2823 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
Andreas Herrmann06506d02006-05-22 18:18:19 +02002824 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
2826 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
2827
Swen Schillig00bab912008-06-10 18:20:57 +02002828 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2830 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2831
2832 /* set FCP related fields in FCP_CMND IU in QTCB */
2833 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
2834 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
2835 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
2836 fcp_cmnd_iu->task_management_flags = tm_flags;
2837
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002838 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
2839 retval = zfcp_fsf_req_send(fsf_req);
Christof Schmittfdf23452007-12-20 12:30:27 +01002840 if (!retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842
Christof Schmittfdf23452007-12-20 12:30:27 +01002843 unit_blocked:
2844 zfcp_fsf_req_free(fsf_req);
2845 fsf_req = NULL;
2846
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 out:
Swen Schillig00bab912008-06-10 18:20:57 +02002848 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 return fsf_req;
2850}
2851
Christof Schmittc9615852008-05-06 11:00:05 +02002852static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2853{
2854 lat_rec->sum += lat;
2855 if (lat_rec->min > lat)
2856 lat_rec->min = lat;
2857 if (lat_rec->max < lat)
2858 lat_rec->max = lat;
2859}
2860
2861static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
2862{
2863 struct fsf_qual_latency_info *lat_inf;
2864 struct latency_cont *lat;
2865 struct zfcp_unit *unit;
2866 unsigned long flags;
2867
2868 lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
2869 unit = fsf_req->unit;
2870
2871 switch (fsf_req->qtcb->bottom.io.data_direction) {
2872 case FSF_DATADIR_READ:
2873 lat = &unit->latencies.read;
2874 break;
2875 case FSF_DATADIR_WRITE:
2876 lat = &unit->latencies.write;
2877 break;
2878 case FSF_DATADIR_CMND:
2879 lat = &unit->latencies.cmd;
2880 break;
2881 default:
2882 return;
2883 }
2884
2885 spin_lock_irqsave(&unit->latencies.lock, flags);
2886 zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
2887 zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
2888 lat->counter++;
2889 spin_unlock_irqrestore(&unit->latencies.lock, flags);
2890}
2891
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892/*
2893 * function: zfcp_fsf_send_fcp_command_handler
2894 *
2895 * purpose: is called for finished Send FCP Command
2896 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002897 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 */
2899static int
2900zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
2901{
2902 int retval = -EINVAL;
2903 struct zfcp_unit *unit;
2904 struct fsf_qtcb_header *header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905
2906 header = &fsf_req->qtcb->header;
2907
2908 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002909 unit = (struct zfcp_unit *) fsf_req->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 else
Andreas Herrmann059c97d2005-09-13 21:47:52 +02002911 unit = fsf_req->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
2913 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2914 /* go directly to calls of special handlers */
2915 goto skip_fsfstatus;
2916 }
2917
2918 /* evaluate FSF status in QTCB */
2919 switch (header->fsf_status) {
2920
2921 case FSF_PORT_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002922 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2924 break;
2925
2926 case FSF_LUN_HANDLE_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002927 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2929 break;
2930
2931 case FSF_HANDLE_MISMATCH:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002932 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2934 break;
2935
2936 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
Christof Schmitt553448f2008-06-10 18:20:58 +02002937 zfcp_fsf_class_not_supp(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 break;
2939
2940 case FSF_FCPLUN_NOT_VALID:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002941 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2943 break;
2944
2945 case FSF_ACCESS_DENIED:
Christof Schmitt553448f2008-06-10 18:20:58 +02002946 zfcp_fsf_access_denied_unit(fsf_req, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 break;
2948
2949 case FSF_DIRECTION_INDICATOR_NOT_VALID:
Christof Schmitt553448f2008-06-10 18:20:58 +02002950 dev_err(&fsf_req->adapter->ccw_device->dev,
2951 "Invalid data direction (%d) given for unit 0x%016Lx "
2952 "on port 0x%016Lx, shutting down adapter.\n",
2953 fsf_req->qtcb->bottom.io.data_direction,
2954 unit->fcp_lun, unit->port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002955 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2957 break;
2958
2959 case FSF_CMND_LENGTH_NOT_VALID:
Christof Schmitt553448f2008-06-10 18:20:58 +02002960 dev_err(&fsf_req->adapter->ccw_device->dev,
2961 "An invalid control-data-block length field (%d) "
2962 "was found in a command for unit 0x%016Lx on port "
2963 "0x%016Lx. Shutting down adapter.\n",
2964 fsf_req->qtcb->bottom.io.fcp_cmnd_length,
2965 unit->fcp_lun, unit->port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002966 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2968 break;
2969
2970 case FSF_PORT_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002971 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2973 ZFCP_STATUS_FSFREQ_RETRY;
2974 break;
2975
2976 case FSF_LUN_BOXED:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002977 zfcp_erp_unit_boxed(unit, 54, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
2979 | ZFCP_STATUS_FSFREQ_RETRY;
2980 break;
2981
2982 case FSF_ADAPTER_STATUS_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 switch (header->fsf_status_qual.word[0]) {
2984 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 /* re-establish link to port */
Andreas Herrmann65a8d4e2005-06-13 13:16:27 +02002986 zfcp_test_link(unit->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 break;
2988 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 /* FIXME(hw) need proper specs for proper action */
2990 /* let scsi stack deal with retries and escalation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 }
Andreas Herrmann516a4202005-06-13 13:17:44 +02002993 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 break;
2995
2996 case FSF_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 break;
2998
2999 case FSF_FCP_RSP_AVAILABLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 }
3002
3003 skip_fsfstatus:
3004 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3005 retval =
3006 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3007 } else {
3008 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003009 fsf_req->unit = NULL;
3010 zfcp_unit_put(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 }
3012 return retval;
3013}
3014
3015/*
3016 * function: zfcp_fsf_send_fcp_command_task_handler
3017 *
3018 * purpose: evaluates FCP_RSP IU
3019 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003020 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 */
3022static int
3023zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3024{
3025 int retval = 0;
3026 struct scsi_cmnd *scpnt;
3027 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3028 &(fsf_req->qtcb->bottom.io.fcp_rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 u32 sns_len;
3030 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3031 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
3033 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
Andreas Herrmann059c97d2005-09-13 21:47:52 +02003034 scpnt = (struct scsi_cmnd *) fsf_req->data;
Christof Schmitt553448f2008-06-10 18:20:58 +02003035 if (unlikely(!scpnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 goto out;
Christof Schmitt553448f2008-06-10 18:20:58 +02003037
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3039 /* FIXME: (design) mid-layer should handle DID_ABORT like
3040 * DID_SOFT_ERROR by retrying the request for devices
3041 * that allow retries.
3042 */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003043 set_host_byte(scpnt, DID_SOFT_ERROR);
3044 set_driver_byte(scpnt, SUGGEST_RETRY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 goto skip_fsfstatus;
3046 }
3047
3048 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
Martin Petermannfeac6a02008-07-02 10:56:35 +02003049 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 goto skip_fsfstatus;
3051 }
3052
3053 /* set message byte of result in SCSI command */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003054 set_msg_byte(scpnt, COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
3056 /*
3057 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3058 * of result in SCSI command
3059 */
3060 scpnt->result |= fcp_rsp_iu->scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061
Christof Schmittc9615852008-05-06 11:00:05 +02003062 if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
3063 zfcp_fsf_req_latency(fsf_req);
3064
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 /* check FCP_RSP_INFO */
3066 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 switch (fcp_rsp_info[3]) {
3068 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 /* ok, continue */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003070 set_host_byte(scpnt, DID_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 break;
3072 case RSP_CODE_LENGTH_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 /* hardware bug */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003074 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 goto skip_fsfstatus;
3076 case RSP_CODE_FIELD_INVALID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 /* driver or hardware bug */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003078 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 goto skip_fsfstatus;
3080 case RSP_CODE_RO_MISMATCH:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 /* hardware bug */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003082 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 goto skip_fsfstatus;
3084 default:
Christof Schmitt553448f2008-06-10 18:20:58 +02003085 /* invalid FCP response code */
Martin Petermannfeac6a02008-07-02 10:56:35 +02003086 set_host_byte(scpnt, DID_ERROR);
6f71d9b2005-04-10 23:04:28 -05003087 goto skip_fsfstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 }
3089 }
3090
3091 /* check for sense data */
3092 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
3093 sns_len = FSF_FCP_RSP_SIZE -
3094 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
FUJITA Tomonori9d058ec2008-01-27 12:41:50 +09003098 memcpy(scpnt->sense_buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
3101
3102 /* check for underrun */
3103 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
FUJITA Tomonori7936a892007-07-29 16:46:28 +09003104 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
3105 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
3106 scpnt->underflow)
Martin Petermannfeac6a02008-07-02 10:56:35 +02003107 set_host_byte(scpnt, DID_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 }
3109
3110 skip_fsfstatus:
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003111 if (scpnt->result != 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01003112 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003113 else if (scpnt->retries > 0)
Maxim Shchetynined829ad2006-02-11 01:42:58 +01003114 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003115 else
Maxim Shchetynined829ad2006-02-11 01:42:58 +01003116 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
3118 /* cleanup pointer (need this especially for abort) */
3119 scpnt->host_scribble = NULL;
3120
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 /* always call back */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 (scpnt->scsi_done) (scpnt);
3123
3124 /*
3125 * We must hold this lock until scsi_done has been called.
3126 * Otherwise we may call scsi_done after abort regarding this
3127 * command has completed.
3128 * Note: scsi_done must not block!
3129 */
3130 out:
3131 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
3132 return retval;
3133}
3134
3135/*
3136 * function: zfcp_fsf_send_fcp_command_task_management_handler
3137 *
3138 * purpose: evaluates FCP_RSP IU
3139 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003140 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 */
3142static int
3143zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
3144{
3145 int retval = 0;
3146 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3147 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3148 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3151 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
3152 goto skip_fsfstatus;
3153 }
3154
3155 /* check FCP_RSP_INFO */
3156 switch (fcp_rsp_info[3]) {
3157 case RSP_CODE_GOOD:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 /* ok, continue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 break;
3160 case RSP_CODE_TASKMAN_UNSUPP:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
3162 break;
3163 case RSP_CODE_TASKMAN_FAILED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
3165 break;
3166 default:
Christof Schmitt553448f2008-06-10 18:20:58 +02003167 /* invalid FCP response code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
3169 }
3170
3171 skip_fsfstatus:
3172 return retval;
3173}
3174
3175
3176/*
3177 * function: zfcp_fsf_control_file
3178 *
3179 * purpose: Initiator of the control file upload/download FSF requests
3180 *
3181 * returns: 0 - FSF request is successfuly created and queued
3182 * -EOPNOTSUPP - The FCP adapter does not have Control File support
3183 * -EINVAL - Invalid direction specified
3184 * -ENOMEM - Insufficient memory
3185 * -EPERM - Cannot create FSF request or place it in QDIO queue
3186 */
Christof Schmitt45633fd2008-06-10 18:20:55 +02003187struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
3188 struct zfcp_fsf_cfdc *fsf_cfdc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189{
3190 struct zfcp_fsf_req *fsf_req;
3191 struct fsf_qtcb_bottom_support *bottom;
3192 volatile struct qdio_buffer_element *sbale;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 int direction;
Christof Schmitt45633fd2008-06-10 18:20:55 +02003195 int retval;
3196 int bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197
Christof Schmitt45633fd2008-06-10 18:20:55 +02003198 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
3199 return ERR_PTR(-EOPNOTSUPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
Christof Schmitt45633fd2008-06-10 18:20:55 +02003201 switch (fsf_cfdc->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
3203 direction = SBAL_FLAGS0_TYPE_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 case FSF_QTCB_UPLOAD_CONTROL_FILE:
3206 direction = SBAL_FLAGS0_TYPE_READ;
3207 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 default:
Christof Schmitt45633fd2008-06-10 18:20:55 +02003209 return ERR_PTR(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 }
3211
Christof Schmitt45633fd2008-06-10 18:20:55 +02003212 retval = zfcp_fsf_req_create(adapter, fsf_cfdc->command,
3213 ZFCP_WAIT_FOR_SBAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 NULL, &lock_flags, &fsf_req);
3215 if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 retval = -EPERM;
3217 goto unlock_queue_lock;
3218 }
3219
Swen Schillig00bab912008-06-10 18:20:57 +02003220 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 sbale[0].flags |= direction;
3222
3223 bottom = &fsf_req->qtcb->bottom.support;
3224 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
Christof Schmitt45633fd2008-06-10 18:20:55 +02003225 bottom->option = fsf_cfdc->option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
Christof Schmitt45633fd2008-06-10 18:20:55 +02003227 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
Swen Schillig00bab912008-06-10 18:20:57 +02003228 fsf_cfdc->sg,
Christof Schmitt45633fd2008-06-10 18:20:55 +02003229 ZFCP_MAX_SBALS_PER_REQ);
3230 if (bytes != ZFCP_CFDC_MAX_SIZE) {
3231 retval = -ENOMEM;
3232 goto free_fsf_req;
3233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003235 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3236 retval = zfcp_fsf_req_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 retval = -EPERM;
3239 goto free_fsf_req;
3240 }
Swen Schillig00bab912008-06-10 18:20:57 +02003241 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 wait_event(fsf_req->completion_wq,
3244 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
3245
Christof Schmitt45633fd2008-06-10 18:20:55 +02003246 return fsf_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
3248 free_fsf_req:
3249 zfcp_fsf_req_free(fsf_req);
3250 unlock_queue_lock:
Swen Schillig00bab912008-06-10 18:20:57 +02003251 write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
Christof Schmitt45633fd2008-06-10 18:20:55 +02003252 return ERR_PTR(retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253}
3254
Christof Schmitt45633fd2008-06-10 18:20:55 +02003255static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256{
Christof Schmitt45633fd2008-06-10 18:20:55 +02003257 if (fsf_req->qtcb->header.fsf_status != FSF_GOOD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259}
3260
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261static inline int
3262zfcp_fsf_req_sbal_check(unsigned long *flags,
3263 struct zfcp_qdio_queue *queue, int needed)
3264{
Swen Schillig00bab912008-06-10 18:20:57 +02003265 write_lock_irqsave(&queue->lock, *flags);
3266 if (likely(atomic_read(&queue->count) >= needed))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 return 1;
Swen Schillig00bab912008-06-10 18:20:57 +02003268 write_unlock_irqrestore(&queue->lock, *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 return 0;
3270}
3271
3272/*
3273 * set qtcb pointer in fsf_req and initialize QTCB
3274 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01003275static void
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003276zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277{
3278 if (likely(fsf_req->qtcb != NULL)) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003279 fsf_req->qtcb->prefix.req_seq_no =
3280 fsf_req->adapter->fsf_req_seq_no;
3281 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003283 fsf_req->qtcb->prefix.qtcb_type =
3284 fsf_qtcb_type[fsf_req->fsf_command];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003286 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003287 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 }
3289}
3290
3291/**
3292 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
3293 * @adapter: adapter for which request queue is examined
3294 * @req_flags: flags indicating whether to wait for needed SBAL or not
3295 * @lock_flags: lock_flags if queue_lock is taken
3296 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
Swen Schillig00bab912008-06-10 18:20:57 +02003297 * Locks: lock adapter->req_q->lock on success
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 */
3299static int
3300zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
3301 unsigned long *lock_flags)
3302{
3303 long ret;
Swen Schillig00bab912008-06-10 18:20:57 +02003304 struct zfcp_qdio_queue *req_q = &adapter->req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
3306 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
3307 ret = wait_event_interruptible_timeout(adapter->request_wq,
Swen Schillig00bab912008-06-10 18:20:57 +02003308 zfcp_fsf_req_sbal_check(lock_flags, req_q, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 ZFCP_SBAL_TIMEOUT);
3310 if (ret < 0)
3311 return ret;
3312 if (!ret)
3313 return -EIO;
Swen Schillig00bab912008-06-10 18:20:57 +02003314 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_q, 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 return -EIO;
3316
3317 return 0;
3318}
3319
3320/*
3321 * function: zfcp_fsf_req_create
3322 *
3323 * purpose: create an FSF request at the specified adapter and
3324 * setup common fields
3325 *
3326 * returns: -ENOMEM if there was insufficient memory for a request
3327 * -EIO if no qdio buffers could be allocate to the request
3328 * -EINVAL/-EPERM on bug conditions in req_dequeue
3329 * 0 in success
3330 *
3331 * note: The created request is returned by reference.
3332 *
3333 * locks: lock of concerned request queue must not be held,
3334 * but is held on completion (write, irqsave)
3335 */
3336int
3337zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
3338 mempool_t *pool, unsigned long *lock_flags,
3339 struct zfcp_fsf_req **fsf_req_p)
3340{
3341 volatile struct qdio_buffer_element *sbale;
3342 struct zfcp_fsf_req *fsf_req = NULL;
3343 int ret = 0;
Swen Schillig00bab912008-06-10 18:20:57 +02003344 struct zfcp_qdio_queue *req_q = &adapter->req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
3346 /* allocate new FSF request */
3347 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
Christof Schmitt553448f2008-06-10 18:20:58 +02003348 if (unlikely(!fsf_req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 ret = -ENOMEM;
3350 goto failed_fsf_req;
3351 }
3352
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003353 fsf_req->adapter = adapter;
3354 fsf_req->fsf_command = fsf_cmd;
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003355 INIT_LIST_HEAD(&fsf_req->list);
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003356 init_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Swen Schillig41fa2ad2007-09-07 09:15:31 +02003358 /* initialize waitqueue which may be used to wait on
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 this request completion */
3360 init_waitqueue_head(&fsf_req->completion_wq);
3361
3362 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
Christof Schmitt801e0ce2007-05-08 11:15:48 +02003363 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 goto failed_sbals;
Christof Schmitt801e0ce2007-05-08 11:15:48 +02003365
3366 /* this is serialized (we are holding req_queue-lock of adapter) */
3367 if (adapter->req_no == 0)
3368 adapter->req_no++;
3369 fsf_req->req_id = adapter->req_no++;
3370
3371 zfcp_fsf_req_qtcb_init(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
3373 /*
3374 * We hold queue_lock here. Check if QDIOUP is set and let request fail
3375 * if it is not set (see also *_open_qdio and *_close_qdio).
3376 */
3377
3378 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
Swen Schillig00bab912008-06-10 18:20:57 +02003379 write_unlock_irqrestore(&req_q->lock, *lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 ret = -EIO;
3381 goto failed_sbals;
3382 }
3383
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003384 if (fsf_req->qtcb) {
3385 fsf_req->seq_no = adapter->fsf_req_seq_no;
3386 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
3387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 fsf_req->sbal_number = 1;
Swen Schillig00bab912008-06-10 18:20:57 +02003389 fsf_req->sbal_first = req_q->first;
3390 fsf_req->sbal_last = req_q->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 fsf_req->sbale_curr = 1;
3392
3393 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
3394 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
3395 }
3396
Swen Schillig00bab912008-06-10 18:20:57 +02003397 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398
3399 /* setup common SBALE fields */
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003400 sbale[0].addr = (void *) fsf_req->req_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
3402 if (likely(fsf_req->qtcb != NULL)) {
3403 sbale[1].addr = (void *) fsf_req->qtcb;
3404 sbale[1].length = sizeof(struct fsf_qtcb);
3405 }
3406
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 goto success;
3408
3409 failed_sbals:
3410/* dequeue new FSF request previously enqueued */
3411 zfcp_fsf_req_free(fsf_req);
3412 fsf_req = NULL;
3413
3414 failed_fsf_req:
Swen Schillig00bab912008-06-10 18:20:57 +02003415 write_lock_irqsave(&req_q->lock, *lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 success:
3417 *fsf_req_p = fsf_req;
3418 return ret;
3419}
3420
3421/*
3422 * function: zfcp_fsf_req_send
3423 *
3424 * purpose: start transfer of FSF request via QDIO
3425 *
3426 * returns: 0 - request transfer succesfully started
3427 * !0 - start of request transfer failed
3428 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003429static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430{
3431 struct zfcp_adapter *adapter;
Swen Schillig00bab912008-06-10 18:20:57 +02003432 struct zfcp_qdio_queue *req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 volatile struct qdio_buffer_element *sbale;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003434 int inc_seq_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 int retval = 0;
3436
3437 adapter = fsf_req->adapter;
Swen Schillig00bab912008-06-10 18:20:57 +02003438 req_q = &adapter->req_q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
Swen Schillig00bab912008-06-10 18:20:57 +02003440 sbale = zfcp_qdio_sbale_req(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003442 /* put allocated FSF request into hash table */
3443 spin_lock(&adapter->req_list_lock);
3444 zfcp_reqlist_add(adapter, fsf_req);
3445 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003447 inc_seq_no = (fsf_req->qtcb != NULL);
3448
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003449 fsf_req->issued = get_clock();
3450
Swen Schillig00bab912008-06-10 18:20:57 +02003451 retval = zfcp_qdio_send(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
3453 if (unlikely(retval)) {
3454 /* Queues are down..... */
Andreas Herrmann2abbe862006-09-18 22:29:56 +02003455 del_timer(&fsf_req->timer);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003456 spin_lock(&adapter->req_list_lock);
Heiko Carstensca2d02c2007-05-08 11:17:54 +02003457 zfcp_reqlist_remove(adapter, fsf_req);
Volker Sameskefea9d6c2006-08-02 11:05:16 +02003458 spin_unlock(&adapter->req_list_lock);
3459 /* undo changes in request queue made for this request */
Swen Schillig00bab912008-06-10 18:20:57 +02003460 atomic_add(fsf_req->sbal_number, &req_q->count);
3461 req_q->first -= fsf_req->sbal_number;
3462 req_q->first += QDIO_MAX_BUFFERS_PER_Q;
3463 req_q->first %= QDIO_MAX_BUFFERS_PER_Q;
Martin Peschke1f6f7122008-04-18 12:51:55 +02003464 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
Swen Schillig00bab912008-06-10 18:20:57 +02003465 retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 /*
3468 * increase FSF sequence counter -
3469 * this must only be done for request successfully enqueued to
3470 * QDIO this rejected requests may be cleaned up by calling
3471 * routines resulting in missing sequence counter values
3472 * otherwise,
3473 */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003474
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 /* Don't increase for unsolicited status */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003476 if (inc_seq_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 adapter->fsf_req_seq_no++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 }
3479 return retval;
3480}