diff options
author | Swen Schillig <swen@vnet.ibm.com> | 2008-07-02 04:56:39 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-07-12 09:22:35 -0400 |
commit | c41f8cbddd4e0e72951e0575165dea8ea26f1c4b (patch) | |
tree | 67eaa89161e594ff2b45dbc9c1bdaee7176b2a32 /drivers/s390/scsi/zfcp_fsf.c | |
parent | 60221920706a01bef89af2577f9a90a8eeb4e662 (diff) |
[SCSI] zfcp: zfcp_fsf cleanup.
Code cleanup for the zfcp_fsf.c file.
Signed-off-by: Swen Schillig <swen@vnet.ibm.com>
Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/s390/scsi/zfcp_fsf.c')
-rw-r--r-- | drivers/s390/scsi/zfcp_fsf.c | 4119 |
1 files changed, 1536 insertions, 2583 deletions
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c index 22e3aa612786..e6d815593b49 100644 --- a/drivers/s390/scsi/zfcp_fsf.c +++ b/drivers/s390/scsi/zfcp_fsf.c | |||
@@ -8,35 +8,6 @@ | |||
8 | 8 | ||
9 | #include "zfcp_ext.h" | 9 | #include "zfcp_ext.h" |
10 | 10 | ||
11 | static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *); | ||
12 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *); | ||
13 | static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *); | ||
14 | static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *); | ||
15 | static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *); | ||
16 | static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *); | ||
17 | static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *); | ||
18 | static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *); | ||
19 | static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *); | ||
20 | static int zfcp_fsf_send_fcp_command_task_management_handler( | ||
21 | struct zfcp_fsf_req *); | ||
22 | static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *); | ||
23 | static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *); | ||
24 | static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *); | ||
25 | static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *); | ||
26 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *); | ||
27 | static inline int zfcp_fsf_req_sbal_check( | ||
28 | unsigned long *, struct zfcp_qdio_queue *, int); | ||
29 | static inline int zfcp_use_one_sbal( | ||
30 | struct scatterlist *, int, struct scatterlist *, int); | ||
31 | static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int); | ||
32 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *); | ||
33 | static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *); | ||
34 | static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *); | ||
35 | static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *); | ||
36 | static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8, | ||
37 | struct fsf_link_down_info *); | ||
38 | static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *); | ||
39 | |||
40 | /* association between FSF command and FSF QTCB type */ | 11 | /* association between FSF command and FSF QTCB type */ |
41 | static u32 fsf_qtcb_type[] = { | 12 | static u32 fsf_qtcb_type[] = { |
42 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, | 13 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, |
@@ -54,21 +25,19 @@ static u32 fsf_qtcb_type[] = { | |||
54 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND | 25 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND |
55 | }; | 26 | }; |
56 | 27 | ||
57 | static const char zfcp_act_subtable_type[5][8] = { | 28 | static const char *zfcp_act_subtable_type[] = { |
58 | "unknown", "OS", "WWPN", "DID", "LUN" | 29 | "unknown", "OS", "WWPN", "DID", "LUN" |
59 | }; | 30 | }; |
60 | 31 | ||
61 | static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table) | 32 | static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table) |
62 | { | 33 | { |
63 | u16 subtable = (table & 0xffff0000) >> 16; | 34 | u16 subtable = table >> 16; |
64 | u16 rule = table & 0xffff; | 35 | u16 rule = table & 0xffff; |
65 | 36 | ||
66 | if (subtable > 0 && | 37 | if (subtable && subtable < ARRAY_SIZE(zfcp_act_subtable_type)) |
67 | subtable < ARRAY_SIZE(zfcp_act_subtable_type)) { | ||
68 | dev_warn(&adapter->ccw_device->dev, | 38 | dev_warn(&adapter->ccw_device->dev, |
69 | "Access denied in subtable %s, rule %d.\n", | 39 | "Access denied in subtable %s, rule %d.\n", |
70 | zfcp_act_subtable_type[subtable], rule); | 40 | zfcp_act_subtable_type[subtable], rule); |
71 | } | ||
72 | } | 41 | } |
73 | 42 | ||
74 | static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req, | 43 | static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req, |
@@ -106,90 +75,27 @@ static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req) | |||
106 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 75 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
107 | } | 76 | } |
108 | 77 | ||
109 | /****************************************************************/ | 78 | /** |
110 | /*************** FSF related Functions *************************/ | 79 | * zfcp_fsf_req_free - free memory used by fsf request |
111 | /****************************************************************/ | 80 | * @fsf_req: pointer to struct zfcp_fsf_req |
112 | |||
113 | /* | ||
114 | * function: zfcp_fsf_req_alloc | ||
115 | * | ||
116 | * purpose: Obtains an fsf_req and potentially a qtcb (for all but | ||
117 | * unsolicited requests) via helper functions | ||
118 | * Does some initial fsf request set-up. | ||
119 | * | ||
120 | * returns: pointer to allocated fsf_req if successfull | ||
121 | * NULL otherwise | ||
122 | * | ||
123 | * locks: none | ||
124 | * | ||
125 | */ | ||
126 | static struct zfcp_fsf_req * | ||
127 | zfcp_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 | ||
136 | size = sizeof(struct zfcp_fsf_req_qtcb); | ||
137 | |||
138 | if (likely(pool)) | ||
139 | ptr = mempool_alloc(pool, GFP_ATOMIC); | ||
140 | 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, | ||
145 | GFP_ATOMIC); | ||
146 | } | ||
147 | |||
148 | if (unlikely(!ptr)) | ||
149 | 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 { | ||
156 | fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req; | ||
157 | fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb; | ||
158 | } | ||
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 | */ | 81 | */ |
176 | void | 82 | void zfcp_fsf_req_free(struct zfcp_fsf_req *req) |
177 | zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req) | ||
178 | { | 83 | { |
179 | if (likely(fsf_req->pool)) { | 84 | if (likely(req->pool)) { |
180 | mempool_free(fsf_req, fsf_req->pool); | 85 | mempool_free(req, req->pool); |
181 | return; | 86 | return; |
182 | } | 87 | } |
183 | 88 | ||
184 | if (fsf_req->qtcb) { | 89 | if (req->qtcb) { |
185 | kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req); | 90 | kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req); |
186 | return; | 91 | return; |
187 | } | 92 | } |
188 | |||
189 | kfree(fsf_req); | ||
190 | } | 93 | } |
191 | 94 | ||
192 | /* | 95 | /** |
96 | * zfcp_fsf_req_dismiss_all - dismiss all fsf requests | ||
97 | * @adapter: pointer to struct zfcp_adapter | ||
98 | * | ||
193 | * Never ever call this without shutting down the adapter first. | 99 | * Never ever call this without shutting down the adapter first. |
194 | * Otherwise the adapter would continue using and corrupting s390 storage. | 100 | * Otherwise the adapter would continue using and corrupting s390 storage. |
195 | * Included BUG_ON() call to ensure this is done. | 101 | * Included BUG_ON() call to ensure this is done. |
@@ -197,1815 +103,1359 @@ zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req) | |||
197 | */ | 103 | */ |
198 | void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) | 104 | void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) |
199 | { | 105 | { |
200 | struct zfcp_fsf_req *fsf_req, *tmp; | 106 | struct zfcp_fsf_req *req, *tmp; |
201 | unsigned long flags; | 107 | unsigned long flags; |
202 | LIST_HEAD(remove_queue); | 108 | LIST_HEAD(remove_queue); |
203 | unsigned int i; | 109 | unsigned int i; |
204 | 110 | ||
205 | BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)); | 111 | BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP); |
206 | spin_lock_irqsave(&adapter->req_list_lock, flags); | 112 | spin_lock_irqsave(&adapter->req_list_lock, flags); |
207 | for (i = 0; i < REQUEST_LIST_SIZE; i++) | 113 | for (i = 0; i < REQUEST_LIST_SIZE; i++) |
208 | list_splice_init(&adapter->req_list[i], &remove_queue); | 114 | list_splice_init(&adapter->req_list[i], &remove_queue); |
209 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); | 115 | spin_unlock_irqrestore(&adapter->req_list_lock, flags); |
210 | 116 | ||
211 | list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) { | 117 | list_for_each_entry_safe(req, tmp, &remove_queue, list) { |
212 | list_del(&fsf_req->list); | 118 | list_del(&req->list); |
213 | fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; | 119 | req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; |
214 | zfcp_fsf_req_complete(fsf_req); | 120 | zfcp_fsf_req_complete(req); |
215 | } | 121 | } |
216 | } | 122 | } |
217 | 123 | ||
218 | /* | 124 | static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req) |
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 | * | ||
227 | * context: | ||
228 | */ | ||
229 | int | ||
230 | zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req) | ||
231 | { | 125 | { |
232 | int retval = 0; | 126 | struct fsf_status_read_buffer *sr_buf = req->data; |
233 | int cleanup; | 127 | struct zfcp_adapter *adapter = req->adapter; |
234 | 128 | struct zfcp_port *port; | |
235 | if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { | 129 | int d_id = sr_buf->d_id & ZFCP_DID_MASK; |
236 | /* | 130 | unsigned long flags; |
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; | ||
242 | } else { | ||
243 | del_timer(&fsf_req->timer); | ||
244 | zfcp_fsf_protstatus_eval(fsf_req); | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * fsf_req may be deleted due to waking up functions, so | ||
249 | * cleanup is saved here and used later | ||
250 | */ | ||
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)) { | ||
260 | /* | ||
261 | * lock must not be held here since it will be | ||
262 | * grabed by the called routine, too | ||
263 | */ | ||
264 | zfcp_fsf_req_free(fsf_req); | ||
265 | } else { | ||
266 | /* notify initiator waiting for the requests completion */ | ||
267 | /* | ||
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 | * | ||
291 | * returns: | ||
292 | * | ||
293 | * context: | ||
294 | * | ||
295 | * locks: | ||
296 | */ | ||
297 | static int | ||
298 | zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req) | ||
299 | { | ||
300 | int retval = 0; | ||
301 | struct zfcp_adapter *adapter = fsf_req->adapter; | ||
302 | struct fsf_qtcb *qtcb = fsf_req->qtcb; | ||
303 | union fsf_prot_status_qual *prot_status_qual = | ||
304 | &qtcb->prefix.prot_status_qual; | ||
305 | |||
306 | zfcp_hba_dbf_event_fsf_response(fsf_req); | ||
307 | |||
308 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { | ||
309 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | | ||
310 | ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */ | ||
311 | goto skip_protstatus; | ||
312 | } | ||
313 | |||
314 | /* evaluate FSF Protocol Status */ | ||
315 | switch (qtcb->prefix.prot_status) { | ||
316 | |||
317 | case FSF_PROT_GOOD: | ||
318 | case FSF_PROT_FSF_STATUS_PRESENTED: | ||
319 | break; | ||
320 | |||
321 | case FSF_PROT_QTCB_VERSION_ERROR: | ||
322 | 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]); | ||
328 | zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req); | ||
329 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
330 | break; | ||
331 | |||
332 | case FSF_PROT_SEQ_NUMB_ERROR: | ||
333 | zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req); | ||
334 | 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: | ||
339 | 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"); | ||
342 | zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req); | ||
343 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
344 | break; | ||
345 | |||
346 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: | ||
347 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
348 | atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, | ||
349 | &(adapter->status)); | ||
350 | break; | ||
351 | |||
352 | case FSF_PROT_DUPLICATE_REQUEST_ID: | ||
353 | dev_err(&adapter->ccw_device->dev, | ||
354 | "The request identifier 0x%Lx is ambiguous.\n", | ||
355 | (unsigned long long)qtcb->bottom.support.req_handle); | ||
356 | zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req); | ||
357 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
358 | break; | ||
359 | |||
360 | case FSF_PROT_LINK_DOWN: | ||
361 | zfcp_fsf_link_down_info_eval(fsf_req, 37, | ||
362 | &prot_status_qual->link_down_info); | ||
363 | /* FIXME: reopening adapter now? better wait for link up */ | ||
364 | zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req); | ||
365 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
366 | break; | ||
367 | |||
368 | case FSF_PROT_REEST_QUEUE: | ||
369 | /* All ports should be marked as ready to run again */ | ||
370 | zfcp_erp_modify_adapter_status(adapter, 28, NULL, | ||
371 | ZFCP_STATUS_COMMON_RUNNING, | ||
372 | ZFCP_SET); | ||
373 | zfcp_erp_adapter_reopen(adapter, | ||
374 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | ||
375 | | ZFCP_STATUS_COMMON_ERP_FAILED, | ||
376 | 99, fsf_req); | ||
377 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
378 | break; | ||
379 | |||
380 | case FSF_PROT_ERROR_STATE: | ||
381 | zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req); | ||
382 | fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY; | ||
383 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
384 | break; | ||
385 | |||
386 | default: | ||
387 | 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); | ||
392 | zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req); | ||
393 | 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 | */ | ||
413 | static int | ||
414 | zfcp_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: | ||
425 | 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); | ||
429 | zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req); | ||
430 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
431 | break; | ||
432 | |||
433 | case FSF_ADAPTER_STATUS_AVAILABLE: | ||
434 | zfcp_fsf_fsfstatus_qual_eval(fsf_req); | ||
435 | break; | ||
436 | } | ||
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 | 131 | ||
445 | return retval; | 132 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
133 | list_for_each_entry(port, &adapter->port_list_head, list) | ||
134 | if (port->d_id == d_id) { | ||
135 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
136 | switch (sr_buf->status_subtype) { | ||
137 | case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT: | ||
138 | zfcp_erp_port_reopen(port, 0, 101, req); | ||
139 | break; | ||
140 | case FSF_STATUS_READ_SUB_ERROR_PORT: | ||
141 | zfcp_erp_port_shutdown(port, 0, 122, req); | ||
142 | break; | ||
143 | } | ||
144 | return; | ||
145 | } | ||
146 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
446 | } | 147 | } |
447 | 148 | ||
448 | /* | 149 | static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req) |
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 | */ | ||
456 | static int | ||
457 | zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req) | ||
458 | { | 150 | { |
459 | int retval = 0; | 151 | struct zfcp_adapter *adapter = req->adapter; |
460 | 152 | struct fsf_status_read_buffer *sr_buf = req->data; | |
461 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { | 153 | struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error; |
462 | case FSF_SQ_FCP_RSP_AVAILABLE: | ||
463 | break; | ||
464 | case FSF_SQ_RETRY_IF_POSSIBLE: | ||
465 | /* The SCSI-stack may now issue retries or escalate */ | ||
466 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
467 | break; | ||
468 | case FSF_SQ_COMMAND_ABORTED: | ||
469 | /* Carry the aborted state on to upper layer */ | ||
470 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED; | ||
471 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
472 | break; | ||
473 | case FSF_SQ_NO_RECOM: | ||
474 | dev_err(&fsf_req->adapter->ccw_device->dev, | ||
475 | "No recommendation could be given for a " | ||
476 | "problem on the adapter.\n"); | ||
477 | zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req); | ||
478 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
479 | break; | ||
480 | case FSF_SQ_ULP_PROGRAMMING_ERROR: | ||
481 | 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: | ||
489 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
490 | break; | ||
491 | } | ||
492 | 154 | ||
493 | return retval; | 155 | dev_warn(&adapter->ccw_device->dev, |
156 | "Warning: bit error threshold data " | ||
157 | "received for the adapter: " | ||
158 | "link failures = %i, loss of sync errors = %i, " | ||
159 | "loss of signal errors = %i, " | ||
160 | "primitive sequence errors = %i, " | ||
161 | "invalid transmission word errors = %i, " | ||
162 | "CRC errors = %i).\n", | ||
163 | err->link_failure_error_count, | ||
164 | err->loss_of_sync_error_count, | ||
165 | err->loss_of_signal_error_count, | ||
166 | err->primitive_sequence_error_count, | ||
167 | err->invalid_transmission_word_error_count, | ||
168 | err->crc_error_count); | ||
169 | dev_warn(&adapter->ccw_device->dev, | ||
170 | "Additional bit error threshold data of the adapter: " | ||
171 | "primitive sequence event time-outs = %i, " | ||
172 | "elastic buffer overrun errors = %i, " | ||
173 | "advertised receive buffer-to-buffer credit = %i, " | ||
174 | "current receice buffer-to-buffer credit = %i, " | ||
175 | "advertised transmit buffer-to-buffer credit = %i, " | ||
176 | "current transmit buffer-to-buffer credit = %i).\n", | ||
177 | err->primitive_sequence_event_timeout_count, | ||
178 | err->elastic_buffer_overrun_error_count, | ||
179 | err->advertised_receive_b2b_credit, | ||
180 | err->current_receive_b2b_credit, | ||
181 | err->advertised_transmit_b2b_credit, | ||
182 | err->current_transmit_b2b_credit); | ||
494 | } | 183 | } |
495 | 184 | ||
496 | /** | 185 | static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id, |
497 | * zfcp_fsf_link_down_info_eval - evaluate link down information block | 186 | struct fsf_link_down_info *link_down) |
498 | */ | ||
499 | static void | ||
500 | zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id, | ||
501 | struct fsf_link_down_info *link_down) | ||
502 | { | 187 | { |
503 | struct zfcp_adapter *adapter = fsf_req->adapter; | 188 | struct zfcp_adapter *adapter = req->adapter; |
504 | 189 | ||
505 | if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, | 190 | if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) |
506 | &adapter->status)) | ||
507 | return; | 191 | return; |
508 | 192 | ||
509 | atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); | 193 | atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); |
510 | 194 | ||
511 | if (link_down == NULL) | 195 | if (!link_down) |
512 | goto out; | 196 | goto out; |
513 | 197 | ||
514 | switch (link_down->error_code) { | 198 | switch (link_down->error_code) { |
515 | case FSF_PSQ_LINK_NO_LIGHT: | 199 | case FSF_PSQ_LINK_NO_LIGHT: |
516 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 200 | dev_warn(&req->adapter->ccw_device->dev, |
517 | "The local link is down: " | 201 | "The local link is down: no light detected.\n"); |
518 | "no light detected.\n"); | ||
519 | break; | 202 | break; |
520 | case FSF_PSQ_LINK_WRAP_PLUG: | 203 | case FSF_PSQ_LINK_WRAP_PLUG: |
521 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 204 | dev_warn(&req->adapter->ccw_device->dev, |
522 | "The local link is down: " | 205 | "The local link is down: wrap plug detected.\n"); |
523 | "wrap plug detected.\n"); | ||
524 | break; | 206 | break; |
525 | case FSF_PSQ_LINK_NO_FCP: | 207 | case FSF_PSQ_LINK_NO_FCP: |
526 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 208 | dev_warn(&req->adapter->ccw_device->dev, |
527 | "The local link is down: " | 209 | "The local link is down: " |
528 | "adjacent node on link does not support FCP.\n"); | 210 | "adjacent node on link does not support FCP.\n"); |
529 | break; | 211 | break; |
530 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: | 212 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: |
531 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 213 | dev_warn(&req->adapter->ccw_device->dev, |
532 | "The local link is down: " | 214 | "The local link is down: " |
533 | "firmware update in progress.\n"); | 215 | "firmware update in progress.\n"); |
534 | break; | 216 | break; |
535 | case FSF_PSQ_LINK_INVALID_WWPN: | 217 | case FSF_PSQ_LINK_INVALID_WWPN: |
536 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 218 | dev_warn(&req->adapter->ccw_device->dev, |
537 | "The local link is down: " | 219 | "The local link is down: " |
538 | "duplicate or invalid WWPN detected.\n"); | 220 | "duplicate or invalid WWPN detected.\n"); |
539 | break; | 221 | break; |
540 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: | 222 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: |
541 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 223 | dev_warn(&req->adapter->ccw_device->dev, |
542 | "The local link is down: " | 224 | "The local link is down: " |
543 | "no support for NPIV by Fabric.\n"); | 225 | "no support for NPIV by Fabric.\n"); |
544 | break; | 226 | break; |
545 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: | 227 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: |
546 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 228 | dev_warn(&req->adapter->ccw_device->dev, |
547 | "The local link is down: " | 229 | "The local link is down: " |
548 | "out of resource in FCP daughtercard.\n"); | 230 | "out of resource in FCP daughtercard.\n"); |
549 | break; | 231 | break; |
550 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: | 232 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: |
551 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 233 | dev_warn(&req->adapter->ccw_device->dev, |
552 | "The local link is down: " | 234 | "The local link is down: " |
553 | "out of resource in Fabric.\n"); | 235 | "out of resource in Fabric.\n"); |
554 | break; | 236 | break; |
555 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: | 237 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: |
556 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 238 | dev_warn(&req->adapter->ccw_device->dev, |
557 | "The local link is down: " | 239 | "The local link is down: " |
558 | "unable to login to Fabric.\n"); | 240 | "unable to login to Fabric.\n"); |
559 | break; | 241 | break; |
560 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: | 242 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: |
561 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 243 | dev_warn(&req->adapter->ccw_device->dev, |
562 | "WWPN assignment file corrupted on adapter.\n"); | 244 | "WWPN assignment file corrupted on adapter.\n"); |
563 | break; | 245 | break; |
564 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: | 246 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: |
565 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 247 | dev_warn(&req->adapter->ccw_device->dev, |
566 | "Mode table corrupted on adapter.\n"); | 248 | "Mode table corrupted on adapter.\n"); |
567 | break; | 249 | break; |
568 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: | 250 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: |
569 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 251 | dev_warn(&req->adapter->ccw_device->dev, |
570 | "No WWPN for assignment table on adapter.\n"); | 252 | "No WWPN for assignment table on adapter.\n"); |
571 | break; | 253 | break; |
572 | default: | 254 | default: |
573 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 255 | dev_warn(&req->adapter->ccw_device->dev, |
574 | "The local link to adapter is down.\n"); | 256 | "The local link to adapter is down.\n"); |
575 | } | 257 | } |
258 | out: | ||
259 | zfcp_erp_adapter_failed(adapter, id, req); | ||
260 | } | ||
261 | |||
262 | static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req) | ||
263 | { | ||
264 | struct zfcp_adapter *adapter = req->adapter; | ||
265 | struct fsf_status_read_buffer *sr_buf = req->data; | ||
266 | struct fsf_link_down_info *ldi = | ||
267 | (struct fsf_link_down_info *) &sr_buf->payload; | ||
576 | 268 | ||
577 | out: | 269 | switch (sr_buf->status_subtype) { |
578 | zfcp_erp_adapter_failed(adapter, id, fsf_req); | 270 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: |
271 | dev_warn(&adapter->ccw_device->dev, | ||
272 | "Physical link is down.\n"); | ||
273 | zfcp_fsf_link_down_info_eval(req, 38, ldi); | ||
274 | break; | ||
275 | case FSF_STATUS_READ_SUB_FDISC_FAILED: | ||
276 | dev_warn(&adapter->ccw_device->dev, | ||
277 | "Local link is down " | ||
278 | "due to failed FDISC login.\n"); | ||
279 | zfcp_fsf_link_down_info_eval(req, 39, ldi); | ||
280 | break; | ||
281 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: | ||
282 | dev_warn(&adapter->ccw_device->dev, | ||
283 | "Local link is down " | ||
284 | "due to firmware update on adapter.\n"); | ||
285 | zfcp_fsf_link_down_info_eval(req, 40, NULL); | ||
286 | }; | ||
579 | } | 287 | } |
580 | 288 | ||
581 | /* | 289 | static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req) |
582 | * function: zfcp_fsf_req_dispatch | ||
583 | * | ||
584 | * purpose: calls the appropriate command specific handler | ||
585 | * | ||
586 | * returns: | ||
587 | */ | ||
588 | static int | ||
589 | zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req) | ||
590 | { | 290 | { |
591 | struct zfcp_erp_action *erp_action = fsf_req->erp_action; | 291 | struct zfcp_adapter *adapter = req->adapter; |
592 | int retval = 0; | 292 | struct fsf_status_read_buffer *sr_buf = req->data; |
593 | 293 | ||
294 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { | ||
295 | zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf); | ||
296 | mempool_free(sr_buf, adapter->pool.data_status_read); | ||
297 | zfcp_fsf_req_free(req); | ||
298 | return; | ||
299 | } | ||
594 | 300 | ||
595 | switch (fsf_req->fsf_command) { | 301 | zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf); |
596 | 302 | ||
597 | case FSF_QTCB_FCP_CMND: | 303 | switch (sr_buf->status_type) { |
598 | zfcp_fsf_send_fcp_command_handler(fsf_req); | 304 | case FSF_STATUS_READ_PORT_CLOSED: |
305 | zfcp_fsf_status_read_port_closed(req); | ||
599 | break; | 306 | break; |
600 | 307 | case FSF_STATUS_READ_INCOMING_ELS: | |
601 | case FSF_QTCB_ABORT_FCP_CMND: | 308 | zfcp_fc_incoming_els(req); |
602 | zfcp_fsf_abort_fcp_command_handler(fsf_req); | ||
603 | break; | 309 | break; |
604 | 310 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: | |
605 | case FSF_QTCB_SEND_GENERIC: | ||
606 | zfcp_fsf_send_ct_handler(fsf_req); | ||
607 | break; | 311 | break; |
608 | 312 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: | |
609 | case FSF_QTCB_OPEN_PORT_WITH_DID: | 313 | zfcp_fsf_bit_error_threshold(req); |
610 | zfcp_fsf_open_port_handler(fsf_req); | ||
611 | break; | 314 | break; |
612 | 315 | case FSF_STATUS_READ_LINK_DOWN: | |
613 | case FSF_QTCB_OPEN_LUN: | 316 | zfcp_fsf_status_read_link_down(req); |
614 | zfcp_fsf_open_unit_handler(fsf_req); | ||
615 | break; | 317 | break; |
616 | 318 | case FSF_STATUS_READ_LINK_UP: | |
617 | case FSF_QTCB_CLOSE_LUN: | 319 | dev_info(&adapter->ccw_device->dev, |
618 | zfcp_fsf_close_unit_handler(fsf_req); | 320 | "Local link was replugged.\n"); |
321 | /* All ports should be marked as ready to run again */ | ||
322 | zfcp_erp_modify_adapter_status(adapter, 30, NULL, | ||
323 | ZFCP_STATUS_COMMON_RUNNING, | ||
324 | ZFCP_SET); | ||
325 | zfcp_erp_adapter_reopen(adapter, | ||
326 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | | ||
327 | ZFCP_STATUS_COMMON_ERP_FAILED, | ||
328 | 102, req); | ||
619 | break; | 329 | break; |
620 | 330 | case FSF_STATUS_READ_NOTIFICATION_LOST: | |
621 | case FSF_QTCB_CLOSE_PORT: | 331 | if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED) |
622 | zfcp_fsf_close_port_handler(fsf_req); | 332 | zfcp_erp_adapter_access_changed(adapter, 135, req); |
333 | if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS) | ||
334 | schedule_work(&adapter->scan_work); | ||
623 | break; | 335 | break; |
624 | 336 | case FSF_STATUS_READ_CFDC_UPDATED: | |
625 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: | 337 | zfcp_erp_adapter_access_changed(adapter, 136, req); |
626 | zfcp_fsf_close_physical_port_handler(fsf_req); | ||
627 | break; | 338 | break; |
628 | 339 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: | |
629 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: | 340 | adapter->adapter_features = sr_buf->payload.word[0]; |
630 | zfcp_fsf_exchange_config_data_handler(fsf_req); | ||
631 | break; | 341 | break; |
342 | } | ||
632 | 343 | ||
633 | case FSF_QTCB_EXCHANGE_PORT_DATA: | 344 | mempool_free(sr_buf, adapter->pool.data_status_read); |
634 | zfcp_fsf_exchange_port_data_handler(fsf_req); | 345 | zfcp_fsf_req_free(req); |
635 | break; | ||
636 | 346 | ||
637 | case FSF_QTCB_SEND_ELS: | 347 | atomic_inc(&adapter->stat_miss); |
638 | zfcp_fsf_send_els_handler(fsf_req); | 348 | schedule_work(&adapter->stat_work); |
639 | break; | 349 | } |
640 | 350 | ||
641 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | 351 | static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req) |
642 | zfcp_fsf_control_file_handler(fsf_req); | 352 | { |
353 | switch (req->qtcb->header.fsf_status_qual.word[0]) { | ||
354 | case FSF_SQ_FCP_RSP_AVAILABLE: | ||
355 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | ||
356 | case FSF_SQ_NO_RETRY_POSSIBLE: | ||
357 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | ||
358 | return; | ||
359 | case FSF_SQ_COMMAND_ABORTED: | ||
360 | req->status |= ZFCP_STATUS_FSFREQ_ABORTED; | ||
361 | break; | ||
362 | case FSF_SQ_NO_RECOM: | ||
363 | dev_err(&req->adapter->ccw_device->dev, | ||
364 | "No recommendation could be given for a " | ||
365 | "problem on the adapter.\n"); | ||
366 | zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req); | ||
643 | break; | 367 | break; |
368 | } | ||
369 | /* all non-return stats set FSFREQ_ERROR*/ | ||
370 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
371 | } | ||
644 | 372 | ||
645 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | 373 | static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req) |
646 | zfcp_fsf_control_file_handler(fsf_req); | 374 | { |
375 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) | ||
376 | return; | ||
377 | |||
378 | switch (req->qtcb->header.fsf_status) { | ||
379 | case FSF_UNKNOWN_COMMAND: | ||
380 | dev_err(&req->adapter->ccw_device->dev, | ||
381 | "Command issued by the device driver (0x%x) is " | ||
382 | "not known by the adapter.\n", | ||
383 | req->qtcb->header.fsf_command); | ||
384 | zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req); | ||
385 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
386 | break; | ||
387 | case FSF_ADAPTER_STATUS_AVAILABLE: | ||
388 | zfcp_fsf_fsfstatus_qual_eval(req); | ||
647 | break; | 389 | break; |
648 | } | 390 | } |
391 | } | ||
649 | 392 | ||
650 | if (!erp_action) | 393 | static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req) |
651 | return retval; | 394 | { |
395 | struct zfcp_adapter *adapter = req->adapter; | ||
396 | struct fsf_qtcb *qtcb = req->qtcb; | ||
397 | union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual; | ||
652 | 398 | ||
653 | zfcp_erp_async_handler(erp_action, 0); | 399 | zfcp_hba_dbf_event_fsf_response(req); |
654 | 400 | ||
655 | return retval; | 401 | if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { |
402 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | | ||
403 | ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */ | ||
404 | return; | ||
405 | } | ||
406 | |||
407 | switch (qtcb->prefix.prot_status) { | ||
408 | case FSF_PROT_GOOD: | ||
409 | case FSF_PROT_FSF_STATUS_PRESENTED: | ||
410 | return; | ||
411 | case FSF_PROT_QTCB_VERSION_ERROR: | ||
412 | dev_err(&adapter->ccw_device->dev, | ||
413 | "The QTCB version requested by zfcp (0x%x) is not " | ||
414 | "supported by the FCP adapter (lowest supported " | ||
415 | "0x%x, highest supported 0x%x).\n", | ||
416 | FSF_QTCB_CURRENT_VERSION, psq->word[0], | ||
417 | psq->word[1]); | ||
418 | zfcp_erp_adapter_shutdown(adapter, 0, 117, req); | ||
419 | break; | ||
420 | case FSF_PROT_ERROR_STATE: | ||
421 | case FSF_PROT_SEQ_NUMB_ERROR: | ||
422 | zfcp_erp_adapter_reopen(adapter, 0, 98, req); | ||
423 | req->status |= ZFCP_STATUS_FSFREQ_RETRY; | ||
424 | break; | ||
425 | case FSF_PROT_UNSUPP_QTCB_TYPE: | ||
426 | dev_err(&adapter->ccw_device->dev, | ||
427 | "Packet header type used by the device driver is " | ||
428 | "incompatible with that used on the adapter.\n"); | ||
429 | zfcp_erp_adapter_shutdown(adapter, 0, 118, req); | ||
430 | break; | ||
431 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: | ||
432 | atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, | ||
433 | &adapter->status); | ||
434 | break; | ||
435 | case FSF_PROT_DUPLICATE_REQUEST_ID: | ||
436 | dev_err(&adapter->ccw_device->dev, | ||
437 | "The request identifier 0x%Lx is ambiguous.\n", | ||
438 | (unsigned long long)qtcb->bottom.support.req_handle); | ||
439 | zfcp_erp_adapter_shutdown(adapter, 0, 78, req); | ||
440 | break; | ||
441 | case FSF_PROT_LINK_DOWN: | ||
442 | zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info); | ||
443 | /* FIXME: reopening adapter now? better wait for link up */ | ||
444 | zfcp_erp_adapter_reopen(adapter, 0, 79, req); | ||
445 | break; | ||
446 | case FSF_PROT_REEST_QUEUE: | ||
447 | /* All ports should be marked as ready to run again */ | ||
448 | zfcp_erp_modify_adapter_status(adapter, 28, NULL, | ||
449 | ZFCP_STATUS_COMMON_RUNNING, | ||
450 | ZFCP_SET); | ||
451 | zfcp_erp_adapter_reopen(adapter, | ||
452 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | | ||
453 | ZFCP_STATUS_COMMON_ERP_FAILED, 99, req); | ||
454 | break; | ||
455 | default: | ||
456 | dev_err(&adapter->ccw_device->dev, | ||
457 | "Transfer protocol status information" | ||
458 | "provided by the adapter (0x%x) " | ||
459 | "is not compatible with the device driver.\n", | ||
460 | qtcb->prefix.prot_status); | ||
461 | zfcp_erp_adapter_shutdown(adapter, 0, 119, req); | ||
462 | } | ||
463 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
656 | } | 464 | } |
657 | 465 | ||
658 | /* | 466 | /** |
659 | * function: zfcp_fsf_status_read | 467 | * zfcp_fsf_req_complete - process completion of a FSF request |
660 | * | 468 | * @fsf_req: The FSF request that has been completed. |
661 | * purpose: initiates a Status Read command at the specified adapter | ||
662 | * | 469 | * |
663 | * returns: | 470 | * When a request has been completed either from the FCP adapter, |
471 | * or it has been dismissed due to a queue shutdown, this function | ||
472 | * is called to process the completion status and trigger further | ||
473 | * events related to the FSF request. | ||
664 | */ | 474 | */ |
665 | int | 475 | void zfcp_fsf_req_complete(struct zfcp_fsf_req *req) |
666 | zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags) | ||
667 | { | 476 | { |
668 | struct zfcp_fsf_req *fsf_req; | 477 | if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { |
669 | struct fsf_status_read_buffer *status_buffer; | 478 | zfcp_fsf_status_read_handler(req); |
670 | unsigned long lock_flags; | 479 | return; |
671 | volatile struct qdio_buffer_element *sbale; | 480 | } |
672 | int retval; | ||
673 | |||
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); | ||
679 | if (retval < 0) | ||
680 | goto failed_req_create; | ||
681 | |||
682 | sbale = zfcp_qdio_sbale_req(fsf_req); | ||
683 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; | ||
684 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; | ||
685 | fsf_req->sbale_curr = 2; | ||
686 | |||
687 | retval = -ENOMEM; | ||
688 | status_buffer = | ||
689 | mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); | ||
690 | if (!status_buffer) | ||
691 | goto failed_buf; | ||
692 | memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer)); | ||
693 | fsf_req->data = (unsigned long) status_buffer; | ||
694 | |||
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 | |||
700 | retval = zfcp_fsf_req_send(fsf_req); | ||
701 | if (retval) | ||
702 | goto failed_req_send; | ||
703 | 481 | ||
704 | goto out; | 482 | del_timer(&req->timer); |
483 | zfcp_fsf_protstatus_eval(req); | ||
484 | zfcp_fsf_fsfstatus_eval(req); | ||
485 | req->handler(req); | ||
705 | 486 | ||
706 | failed_req_send: | 487 | if (req->erp_action) |
707 | mempool_free(status_buffer, adapter->pool.data_status_read); | 488 | zfcp_erp_async_handler(req->erp_action, 0); |
489 | req->status |= ZFCP_STATUS_FSFREQ_COMPLETED; | ||
708 | 490 | ||
709 | failed_buf: | 491 | if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP)) |
710 | zfcp_fsf_req_free(fsf_req); | 492 | zfcp_fsf_req_free(req); |
711 | failed_req_create: | 493 | else |
712 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); | 494 | /* notify initiator waiting for the requests completion */ |
713 | out: | 495 | /* |
714 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 496 | * FIXME: Race! We must not access fsf_req here as it might have been |
715 | return retval; | 497 | * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED |
498 | * flag. It's an improbable case. But, we have the same paranoia for | ||
499 | * the cleanup flag already. | ||
500 | * Might better be handled using complete()? | ||
501 | * (setting the flag and doing wakeup ought to be atomic | ||
502 | * with regard to checking the flag as long as waitqueue is | ||
503 | * part of the to be released structure) | ||
504 | */ | ||
505 | wake_up(&req->completion_wq); | ||
716 | } | 506 | } |
717 | 507 | ||
718 | static int | 508 | static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req) |
719 | zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req) | ||
720 | { | 509 | { |
721 | struct fsf_status_read_buffer *status_buffer; | 510 | struct fsf_qtcb_bottom_config *bottom; |
722 | struct zfcp_adapter *adapter; | 511 | struct zfcp_adapter *adapter = req->adapter; |
723 | struct zfcp_port *port; | 512 | struct Scsi_Host *shost = adapter->scsi_host; |
724 | unsigned long flags; | ||
725 | 513 | ||
726 | status_buffer = (struct fsf_status_read_buffer *) fsf_req->data; | 514 | bottom = &req->qtcb->bottom.config; |
727 | adapter = fsf_req->adapter; | ||
728 | 515 | ||
729 | read_lock_irqsave(&zfcp_data.config_lock, flags); | 516 | if (req->data) |
730 | list_for_each_entry(port, &adapter->port_list_head, list) | 517 | memcpy(req->data, bottom, sizeof(*bottom)); |
731 | if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK)) | ||
732 | break; | ||
733 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
734 | 518 | ||
735 | if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) | 519 | fc_host_node_name(shost) = bottom->nport_serv_param.wwnn; |
736 | goto out; | 520 | fc_host_port_name(shost) = bottom->nport_serv_param.wwpn; |
521 | fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK; | ||
522 | fc_host_speed(shost) = bottom->fc_link_speed; | ||
523 | fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; | ||
737 | 524 | ||
738 | switch (status_buffer->status_subtype) { | 525 | adapter->hydra_version = bottom->adapter_type; |
526 | adapter->timer_ticks = bottom->timer_interval; | ||
739 | 527 | ||
740 | case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT: | 528 | if (fc_host_permanent_port_name(shost) == -1) |
741 | zfcp_erp_port_reopen(port, 0, 101, fsf_req); | 529 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); |
742 | break; | ||
743 | 530 | ||
744 | case FSF_STATUS_READ_SUB_ERROR_PORT: | 531 | switch (bottom->fc_topology) { |
745 | zfcp_erp_port_shutdown(port, 0, 122, fsf_req); | 532 | case FSF_TOPO_P2P: |
746 | break; | 533 | adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK; |
534 | adapter->peer_wwpn = bottom->plogi_payload.wwpn; | ||
535 | adapter->peer_wwnn = bottom->plogi_payload.wwnn; | ||
536 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | ||
537 | if (req->erp_action) | ||
538 | dev_info(&adapter->ccw_device->dev, | ||
539 | "Point-to-Point fibrechannel " | ||
540 | "configuration detected.\n"); | ||
541 | break; | ||
542 | case FSF_TOPO_FABRIC: | ||
543 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; | ||
544 | if (req->erp_action) | ||
545 | dev_info(&adapter->ccw_device->dev, | ||
546 | "Switched fabric fibrechannel " | ||
547 | "network detected.\n"); | ||
548 | break; | ||
549 | case FSF_TOPO_AL: | ||
550 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; | ||
551 | dev_err(&adapter->ccw_device->dev, | ||
552 | "Unsupported arbitrated loop fibrechannel " | ||
553 | "topology detected, shutting down " | ||
554 | "adapter.\n"); | ||
555 | zfcp_erp_adapter_shutdown(adapter, 0, 127, req); | ||
556 | return -EIO; | ||
557 | default: | ||
558 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | ||
559 | dev_err(&adapter->ccw_device->dev, | ||
560 | "The fibrechannel topology reported by the" | ||
561 | " adapter is not known by the zfcp driver," | ||
562 | " shutting down adapter.\n"); | ||
563 | zfcp_erp_adapter_shutdown(adapter, 0, 128, req); | ||
564 | return -EIO; | ||
747 | } | 565 | } |
748 | out: | 566 | |
749 | return 0; | 567 | return 0; |
750 | } | 568 | } |
751 | 569 | ||
752 | static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req) | 570 | static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req) |
753 | { | 571 | { |
754 | struct zfcp_adapter *adapter = req->adapter; | 572 | struct zfcp_adapter *adapter = req->adapter; |
755 | struct fsf_status_read_buffer *buf = | 573 | struct fsf_qtcb *qtcb = req->qtcb; |
756 | (struct fsf_status_read_buffer *) req->data; | 574 | struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config; |
757 | struct fsf_bit_error_payload *err = | 575 | struct Scsi_Host *shost = adapter->scsi_host; |
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 | 576 | ||
789 | /* | 577 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
790 | * function: zfcp_fsf_status_read_handler | 578 | return; |
791 | * | ||
792 | * purpose: is called for finished Open Port command | ||
793 | * | ||
794 | * returns: | ||
795 | */ | ||
796 | static int | ||
797 | zfcp_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 = | ||
802 | (struct fsf_status_read_buffer *) fsf_req->data; | ||
803 | |||
804 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { | ||
805 | zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer); | ||
806 | mempool_free(status_buffer, adapter->pool.data_status_read); | ||
807 | zfcp_fsf_req_free(fsf_req); | ||
808 | goto out; | ||
809 | } | ||
810 | 579 | ||
811 | zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer); | 580 | adapter->fsf_lic_version = bottom->lic_version; |
581 | adapter->adapter_features = bottom->adapter_features; | ||
582 | adapter->connection_features = bottom->connection_features; | ||
583 | adapter->peer_wwpn = 0; | ||
584 | adapter->peer_wwnn = 0; | ||
585 | adapter->peer_d_id = 0; | ||
812 | 586 | ||
813 | switch (status_buffer->status_type) { | 587 | switch (qtcb->header.fsf_status) { |
588 | case FSF_GOOD: | ||
589 | if (zfcp_fsf_exchange_config_evaluate(req)) | ||
590 | return; | ||
814 | 591 | ||
815 | case FSF_STATUS_READ_PORT_CLOSED: | 592 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
816 | zfcp_fsf_status_read_port_closed(fsf_req); | 593 | dev_err(&adapter->ccw_device->dev, |
594 | "Maximum QTCB size (%d bytes) allowed by " | ||
595 | "the adapter is lower than the minimum " | ||
596 | "required by the driver (%ld bytes).\n", | ||
597 | bottom->max_qtcb_size, | ||
598 | sizeof(struct fsf_qtcb)); | ||
599 | zfcp_erp_adapter_shutdown(adapter, 0, 129, req); | ||
600 | return; | ||
601 | } | ||
602 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, | ||
603 | &adapter->status); | ||
817 | break; | 604 | break; |
605 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | ||
606 | fc_host_node_name(shost) = 0; | ||
607 | fc_host_port_name(shost) = 0; | ||
608 | fc_host_port_id(shost) = 0; | ||
609 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | ||
610 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | ||
611 | adapter->hydra_version = 0; | ||
818 | 612 | ||
819 | case FSF_STATUS_READ_INCOMING_ELS: | 613 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, |
820 | zfcp_fc_incoming_els(fsf_req); | 614 | &adapter->status); |
821 | break; | ||
822 | 615 | ||
823 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: | 616 | zfcp_fsf_link_down_info_eval(req, 42, |
617 | &qtcb->header.fsf_status_qual.link_down_info); | ||
824 | break; | 618 | break; |
619 | default: | ||
620 | zfcp_erp_adapter_shutdown(adapter, 0, 130, req); | ||
621 | return; | ||
622 | } | ||
825 | 623 | ||
826 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: | 624 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
827 | zfcp_fsf_bit_error_threshold(fsf_req); | 625 | adapter->hardware_version = bottom->hardware_version; |
828 | break; | 626 | memcpy(fc_host_serial_number(shost), bottom->serial_number, |
627 | min(FC_SERIAL_NUMBER_SIZE, 17)); | ||
628 | EBCASC(fc_host_serial_number(shost), | ||
629 | min(FC_SERIAL_NUMBER_SIZE, 17)); | ||
630 | } | ||
829 | 631 | ||
830 | case FSF_STATUS_READ_LINK_DOWN: | 632 | if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) { |
831 | switch (status_buffer->status_subtype) { | 633 | dev_err(&adapter->ccw_device->dev, |
832 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: | 634 | "The adapter only supports newer control block " |
833 | dev_warn(&adapter->ccw_device->dev, | 635 | "versions, try updated device driver.\n"); |
834 | "Physical link is down.\n"); | 636 | zfcp_erp_adapter_shutdown(adapter, 0, 125, req); |
835 | zfcp_fsf_link_down_info_eval(fsf_req, 38, | 637 | return; |
836 | (struct fsf_link_down_info *) | 638 | } |
837 | &status_buffer->payload); | 639 | if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) { |
838 | break; | 640 | dev_err(&adapter->ccw_device->dev, |
839 | case FSF_STATUS_READ_SUB_FDISC_FAILED: | 641 | "The adapter only supports older control block " |
840 | dev_warn(&adapter->ccw_device->dev, | 642 | "versions, consider a microcode upgrade.\n"); |
841 | "Local link is down " | 643 | zfcp_erp_adapter_shutdown(adapter, 0, 126, req); |
842 | "due to failed FDISC login.\n"); | 644 | } |
843 | zfcp_fsf_link_down_info_eval(fsf_req, 39, | 645 | } |
844 | (struct fsf_link_down_info *) | ||
845 | &status_buffer->payload); | ||
846 | break; | ||
847 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: | ||
848 | dev_warn(&adapter->ccw_device->dev, | ||
849 | "Local link is down " | ||
850 | "due to firmware update on adapter.\n"); | ||
851 | zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL); | ||
852 | break; | ||
853 | default: | ||
854 | dev_warn(&adapter->ccw_device->dev, | ||
855 | "Local link is down.\n"); | ||
856 | zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL); | ||
857 | }; | ||
858 | break; | ||
859 | 646 | ||
860 | case FSF_STATUS_READ_LINK_UP: | 647 | static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req) |
861 | dev_info(&adapter->ccw_device->dev, | 648 | { |
862 | "Local link was replugged.\n"); | 649 | struct zfcp_adapter *adapter = req->adapter; |
863 | /* All ports should be marked as ready to run again */ | 650 | struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port; |
864 | zfcp_erp_modify_adapter_status(adapter, 30, NULL, | 651 | struct Scsi_Host *shost = adapter->scsi_host; |
865 | ZFCP_STATUS_COMMON_RUNNING, | ||
866 | ZFCP_SET); | ||
867 | zfcp_erp_adapter_reopen(adapter, | ||
868 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | ||
869 | | ZFCP_STATUS_COMMON_ERP_FAILED, | ||
870 | 102, fsf_req); | ||
871 | break; | ||
872 | 652 | ||
873 | case FSF_STATUS_READ_NOTIFICATION_LOST: | 653 | if (req->data) |
874 | if (status_buffer->status_subtype & | 654 | memcpy(req->data, bottom, sizeof(*bottom)); |
875 | FSF_STATUS_READ_SUB_ACT_UPDATED) | ||
876 | zfcp_erp_adapter_access_changed(adapter, 135, fsf_req); | ||
877 | if (status_buffer->status_subtype & | ||
878 | FSF_STATUS_READ_SUB_INCOMING_ELS) | ||
879 | schedule_work(&adapter->scan_work); | ||
880 | break; | ||
881 | 655 | ||
882 | case FSF_STATUS_READ_CFDC_UPDATED: | 656 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
883 | zfcp_erp_adapter_access_changed(adapter, 136, fsf_req); | 657 | fc_host_permanent_port_name(shost) = bottom->wwpn; |
884 | break; | 658 | else |
659 | fc_host_permanent_port_name(shost) = fc_host_port_name(shost); | ||
660 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; | ||
661 | fc_host_supported_speeds(shost) = bottom->supported_speed; | ||
662 | } | ||
885 | 663 | ||
886 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: | 664 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req) |
887 | adapter->adapter_features = *(u32*) status_buffer->payload; | 665 | { |
666 | struct zfcp_adapter *adapter = req->adapter; | ||
667 | struct fsf_qtcb *qtcb = req->qtcb; | ||
668 | |||
669 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) | ||
670 | return; | ||
671 | |||
672 | switch (qtcb->header.fsf_status) { | ||
673 | case FSF_GOOD: | ||
674 | zfcp_fsf_exchange_port_evaluate(req); | ||
675 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); | ||
676 | break; | ||
677 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | ||
678 | zfcp_fsf_exchange_port_evaluate(req); | ||
679 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); | ||
680 | zfcp_fsf_link_down_info_eval(req, 43, | ||
681 | &qtcb->header.fsf_status_qual.link_down_info); | ||
888 | break; | 682 | break; |
889 | } | 683 | } |
890 | mempool_free(status_buffer, adapter->pool.data_status_read); | 684 | } |
891 | zfcp_fsf_req_free(fsf_req); | ||
892 | /* | ||
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 | */ | ||
906 | 685 | ||
907 | atomic_inc(&adapter->stat_miss); | 686 | static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue) |
908 | schedule_work(&adapter->stat_work); | 687 | { |
909 | out: | 688 | spin_lock(&queue->lock); |
910 | return retval; | 689 | if (atomic_read(&queue->count)) |
690 | return 1; | ||
691 | spin_unlock(&queue->lock); | ||
692 | return 0; | ||
911 | } | 693 | } |
912 | 694 | ||
913 | /* | 695 | static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter) |
914 | * function: zfcp_fsf_abort_fcp_command | 696 | { |
915 | * | 697 | long ret; |
916 | * purpose: tells FSF to abort a running SCSI command | 698 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
917 | * | 699 | |
918 | * returns: address of initiated FSF request | 700 | spin_unlock(&req_q->lock); |
919 | * NULL - request could not be initiated | 701 | ret = wait_event_interruptible_timeout(adapter->request_wq, |
920 | * | 702 | zfcp_fsf_sbal_check(req_q), 5 * HZ); |
921 | * FIXME(design): should be watched by a timeout !!! | 703 | if (ret > 0) |
922 | * FIXME(design) shouldn't this be modified to return an int | 704 | return 0; |
923 | * also...don't know how though | 705 | |
924 | */ | 706 | spin_lock(&req_q->lock); |
925 | struct zfcp_fsf_req * | 707 | return -EIO; |
926 | zfcp_fsf_abort_fcp_command(unsigned long old_req_id, | 708 | } |
927 | struct zfcp_adapter *adapter, | 709 | |
928 | struct zfcp_unit *unit, int req_flags) | 710 | static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool) |
711 | { | ||
712 | struct zfcp_fsf_req *req; | ||
713 | req = mempool_alloc(pool, GFP_ATOMIC); | ||
714 | if (!req) | ||
715 | return NULL; | ||
716 | memset(req, 0, sizeof(*req)); | ||
717 | return req; | ||
718 | } | ||
719 | |||
720 | static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool) | ||
721 | { | ||
722 | struct zfcp_fsf_req_qtcb *qtcb; | ||
723 | |||
724 | if (likely(pool)) | ||
725 | qtcb = mempool_alloc(pool, GFP_ATOMIC); | ||
726 | else | ||
727 | qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache, | ||
728 | GFP_ATOMIC); | ||
729 | if (unlikely(!qtcb)) | ||
730 | return NULL; | ||
731 | |||
732 | memset(qtcb, 0, sizeof(*qtcb)); | ||
733 | qtcb->fsf_req.qtcb = &qtcb->qtcb; | ||
734 | qtcb->fsf_req.pool = pool; | ||
735 | |||
736 | return &qtcb->fsf_req; | ||
737 | } | ||
738 | |||
739 | static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter, | ||
740 | u32 fsf_cmd, int req_flags, | ||
741 | mempool_t *pool) | ||
929 | { | 742 | { |
930 | volatile struct qdio_buffer_element *sbale; | 743 | volatile struct qdio_buffer_element *sbale; |
931 | struct zfcp_fsf_req *fsf_req = NULL; | ||
932 | unsigned long lock_flags; | ||
933 | 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); | ||
939 | if (retval < 0) | ||
940 | goto out; | ||
941 | 744 | ||
942 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, | 745 | struct zfcp_fsf_req *req; |
943 | &unit->status))) | 746 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
944 | goto unit_blocked; | ||
945 | 747 | ||
946 | sbale = zfcp_qdio_sbale_req(fsf_req); | 748 | if (req_flags & ZFCP_REQ_NO_QTCB) |
947 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 749 | req = zfcp_fsf_alloc_noqtcb(pool); |
948 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 750 | else |
751 | req = zfcp_fsf_alloc_qtcb(pool); | ||
752 | |||
753 | if (unlikely(!req)) | ||
754 | return ERR_PTR(-EIO); | ||
949 | 755 | ||
950 | fsf_req->data = (unsigned long) unit; | 756 | if (adapter->req_no == 0) |
757 | adapter->req_no++; | ||
951 | 758 | ||
952 | /* set handles of unit and its parent port in QTCB */ | 759 | INIT_LIST_HEAD(&req->list); |
953 | fsf_req->qtcb->header.lun_handle = unit->handle; | 760 | init_timer(&req->timer); |
954 | fsf_req->qtcb->header.port_handle = unit->port->handle; | 761 | init_waitqueue_head(&req->completion_wq); |
955 | 762 | ||
956 | /* set handle of request which should be aborted */ | 763 | req->adapter = adapter; |
957 | fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id; | 764 | req->fsf_command = fsf_cmd; |
765 | req->req_id = adapter->req_no++; | ||
766 | req->sbal_number = 1; | ||
767 | req->sbal_first = req_q->first; | ||
768 | req->sbal_last = req_q->first; | ||
769 | req->sbale_curr = 1; | ||
958 | 770 | ||
959 | zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT); | 771 | sbale = zfcp_qdio_sbale_req(req); |
960 | retval = zfcp_fsf_req_send(fsf_req); | 772 | sbale[0].addr = (void *) req->req_id; |
961 | if (!retval) | 773 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; |
962 | goto out; | 774 | |
775 | if (likely(req->qtcb)) { | ||
776 | req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no; | ||
777 | req->qtcb->prefix.req_id = req->req_id; | ||
778 | req->qtcb->prefix.ulp_info = 26; | ||
779 | req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command]; | ||
780 | req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; | ||
781 | req->qtcb->header.req_handle = req->req_id; | ||
782 | req->qtcb->header.fsf_command = req->fsf_command; | ||
783 | req->seq_no = adapter->fsf_req_seq_no; | ||
784 | req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; | ||
785 | sbale[1].addr = (void *) req->qtcb; | ||
786 | sbale[1].length = sizeof(struct fsf_qtcb); | ||
787 | } | ||
788 | |||
789 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) { | ||
790 | zfcp_fsf_req_free(req); | ||
791 | return ERR_PTR(-EIO); | ||
792 | } | ||
963 | 793 | ||
964 | unit_blocked: | 794 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) |
965 | zfcp_fsf_req_free(fsf_req); | 795 | req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; |
966 | fsf_req = NULL; | ||
967 | 796 | ||
968 | out: | 797 | return req; |
969 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | ||
970 | return fsf_req; | ||
971 | } | 798 | } |
972 | 799 | ||
973 | /* | 800 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *req) |
974 | * function: zfcp_fsf_abort_fcp_command_handler | 801 | { |
975 | * | 802 | struct zfcp_adapter *adapter = req->adapter; |
976 | * purpose: is called for finished Abort FCP Command request | 803 | struct zfcp_qdio_queue *req_q = &adapter->req_q; |
977 | * | 804 | int idx; |
978 | * returns: | 805 | |
806 | /* put allocated FSF request into hash table */ | ||
807 | spin_lock(&adapter->req_list_lock); | ||
808 | idx = zfcp_reqlist_hash(req->req_id); | ||
809 | list_add_tail(&req->list, &adapter->req_list[idx]); | ||
810 | spin_unlock(&adapter->req_list_lock); | ||
811 | |||
812 | req->issued = get_clock(); | ||
813 | if (zfcp_qdio_send(req)) { | ||
814 | /* Queues are down..... */ | ||
815 | del_timer(&req->timer); | ||
816 | spin_lock(&adapter->req_list_lock); | ||
817 | zfcp_reqlist_remove(adapter, req); | ||
818 | spin_unlock(&adapter->req_list_lock); | ||
819 | /* undo changes in request queue made for this request */ | ||
820 | atomic_add(req->sbal_number, &req_q->count); | ||
821 | req_q->first -= req->sbal_number; | ||
822 | req_q->first += QDIO_MAX_BUFFERS_PER_Q; | ||
823 | req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */ | ||
824 | zfcp_erp_adapter_reopen(adapter, 0, 116, req); | ||
825 | return -EIO; | ||
826 | } | ||
827 | |||
828 | /* Don't increase for unsolicited status */ | ||
829 | if (req->qtcb) | ||
830 | adapter->fsf_req_seq_no++; | ||
831 | |||
832 | return 0; | ||
833 | } | ||
834 | |||
835 | /** | ||
836 | * zfcp_fsf_status_read - send status read request | ||
837 | * @adapter: pointer to struct zfcp_adapter | ||
838 | * @req_flags: request flags | ||
839 | * Returns: 0 on success, ERROR otherwise | ||
979 | */ | 840 | */ |
980 | static int | 841 | int zfcp_fsf_status_read(struct zfcp_adapter *adapter) |
981 | zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req) | ||
982 | { | 842 | { |
983 | int retval = -EINVAL; | 843 | struct zfcp_fsf_req *req; |
984 | struct zfcp_unit *unit; | 844 | struct fsf_status_read_buffer *sr_buf; |
985 | union fsf_status_qual *fsf_stat_qual = | 845 | volatile struct qdio_buffer_element *sbale; |
986 | &new_fsf_req->qtcb->header.fsf_status_qual; | 846 | int retval = -EIO; |
987 | 847 | ||
988 | if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | 848 | spin_lock(&adapter->req_q.lock); |
989 | /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */ | 849 | if (zfcp_fsf_req_sbal_get(adapter)) |
990 | goto skip_fsfstatus; | 850 | goto out; |
851 | |||
852 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS, | ||
853 | ZFCP_REQ_NO_QTCB, | ||
854 | adapter->pool.fsf_req_status_read); | ||
855 | if (unlikely(IS_ERR(req))) { | ||
856 | retval = PTR_ERR(req); | ||
857 | goto out; | ||
858 | } | ||
859 | |||
860 | sbale = zfcp_qdio_sbale_req(req); | ||
861 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; | ||
862 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; | ||
863 | req->sbale_curr = 2; | ||
864 | |||
865 | sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); | ||
866 | if (!sr_buf) { | ||
867 | retval = -ENOMEM; | ||
868 | goto failed_buf; | ||
991 | } | 869 | } |
870 | memset(sr_buf, 0, sizeof(*sr_buf)); | ||
871 | req->data = sr_buf; | ||
872 | sbale = zfcp_qdio_sbale_curr(req); | ||
873 | sbale->addr = (void *) sr_buf; | ||
874 | sbale->length = sizeof(*sr_buf); | ||
992 | 875 | ||
993 | unit = (struct zfcp_unit *) new_fsf_req->data; | 876 | retval = zfcp_fsf_req_send(req); |
877 | if (retval) | ||
878 | goto failed_req_send; | ||
879 | |||
880 | goto out; | ||
881 | |||
882 | failed_req_send: | ||
883 | mempool_free(sr_buf, adapter->pool.data_status_read); | ||
884 | failed_buf: | ||
885 | zfcp_fsf_req_free(req); | ||
886 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); | ||
887 | out: | ||
888 | spin_unlock(&adapter->req_q.lock); | ||
889 | return retval; | ||
890 | } | ||
891 | |||
892 | static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req) | ||
893 | { | ||
894 | struct zfcp_unit *unit = req->data; | ||
895 | union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual; | ||
994 | 896 | ||
995 | /* evaluate FSF status in QTCB */ | 897 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
996 | switch (new_fsf_req->qtcb->header.fsf_status) { | 898 | return; |
997 | 899 | ||
900 | switch (req->qtcb->header.fsf_status) { | ||
998 | case FSF_PORT_HANDLE_NOT_VALID: | 901 | case FSF_PORT_HANDLE_NOT_VALID: |
999 | if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) { | 902 | if (fsq->word[0] == fsq->word[1]) { |
1000 | /* | ||
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 { | ||
1006 | /* Let's hope this sorts out the mess */ | ||
1007 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104, | 903 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104, |
1008 | new_fsf_req); | 904 | req); |
1009 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 905 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1010 | } | 906 | } |
1011 | break; | 907 | break; |
1012 | |||
1013 | case FSF_LUN_HANDLE_NOT_VALID: | 908 | case FSF_LUN_HANDLE_NOT_VALID: |
1014 | if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) { | 909 | if (fsq->word[0] == fsq->word[1]) { |
1015 | /* | 910 | zfcp_erp_port_reopen(unit->port, 0, 105, req); |
1016 | * In this case a command that was sent prior to a unit | 911 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1017 | * reopen was aborted (handles are different). | ||
1018 | * This is fine. | ||
1019 | */ | ||
1020 | } else { | ||
1021 | /* Let's hope this sorts out the mess */ | ||
1022 | zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req); | ||
1023 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1024 | } | 912 | } |
1025 | break; | 913 | break; |
1026 | |||
1027 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: | 914 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: |
1028 | retval = 0; | 915 | req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; |
1029 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; | ||
1030 | break; | 916 | break; |
1031 | |||
1032 | case FSF_PORT_BOXED: | 917 | case FSF_PORT_BOXED: |
1033 | zfcp_erp_port_boxed(unit->port, 47, new_fsf_req); | 918 | zfcp_erp_port_boxed(unit->port, 47, req); |
1034 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | 919 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
1035 | | ZFCP_STATUS_FSFREQ_RETRY; | 920 | ZFCP_STATUS_FSFREQ_RETRY; |
1036 | break; | 921 | break; |
1037 | |||
1038 | case FSF_LUN_BOXED: | 922 | case FSF_LUN_BOXED: |
1039 | zfcp_erp_unit_boxed(unit, 48, new_fsf_req); | 923 | zfcp_erp_unit_boxed(unit, 48, req); |
1040 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | 924 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
1041 | | ZFCP_STATUS_FSFREQ_RETRY; | 925 | ZFCP_STATUS_FSFREQ_RETRY; |
1042 | break; | 926 | break; |
1043 | |||
1044 | case FSF_ADAPTER_STATUS_AVAILABLE: | 927 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1045 | switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) { | 928 | switch (fsq->word[0]) { |
1046 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 929 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
1047 | zfcp_test_link(unit->port); | 930 | zfcp_test_link(unit->port); |
1048 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1049 | break; | ||
1050 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 931 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1051 | /* SCSI stack will escalate */ | 932 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1052 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1053 | break; | 933 | break; |
1054 | } | 934 | } |
1055 | break; | 935 | break; |
1056 | |||
1057 | case FSF_GOOD: | 936 | case FSF_GOOD: |
1058 | retval = 0; | 937 | req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; |
1059 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; | ||
1060 | break; | 938 | break; |
1061 | } | 939 | } |
1062 | skip_fsfstatus: | ||
1063 | return retval; | ||
1064 | } | 940 | } |
1065 | 941 | ||
1066 | /** | 942 | /** |
1067 | * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into | 943 | * zfcp_fsf_abort_fcp_command - abort running SCSI command |
1068 | * one SBALE | 944 | * @old_req_id: unsigned long |
1069 | * Two scatter-gather lists are passed, one for the reqeust and one for the | 945 | * @adapter: pointer to struct zfcp_adapter |
1070 | * response. | 946 | * @unit: pointer to struct zfcp_unit |
947 | * @req_flags: integer specifying the request flags | ||
948 | * Returns: pointer to struct zfcp_fsf_req | ||
949 | * | ||
950 | * FIXME(design): should be watched by a timeout !!! | ||
1071 | */ | 951 | */ |
1072 | static inline int | ||
1073 | zfcp_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 | 952 | ||
1088 | /** | 953 | struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id, |
1089 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) | 954 | struct zfcp_adapter *adapter, |
1090 | * @ct: pointer to struct zfcp_send_ct which conatins all needed data for | 955 | struct zfcp_unit *unit, |
1091 | * the request | 956 | int req_flags) |
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 | */ | ||
1097 | int | ||
1098 | zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, | ||
1099 | struct zfcp_erp_action *erp_action) | ||
1100 | { | 957 | { |
1101 | volatile struct qdio_buffer_element *sbale; | 958 | volatile struct qdio_buffer_element *sbale; |
1102 | struct zfcp_port *port; | 959 | struct zfcp_fsf_req *req = NULL; |
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); | ||
1115 | if (ret < 0) | ||
1116 | goto failed_req; | ||
1117 | |||
1118 | sbale = zfcp_qdio_sbale_req(fsf_req); | ||
1119 | 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; | ||
1129 | } else if (adapter->adapter_features & | ||
1130 | 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, | ||
1134 | ct->req, | ||
1135 | ZFCP_MAX_SBALS_PER_CT_REQ); | ||
1136 | if (bytes <= 0) { | ||
1137 | 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, | ||
1148 | ct->resp, | ||
1149 | ZFCP_MAX_SBALS_PER_CT_REQ); | ||
1150 | if (bytes <= 0) { | ||
1151 | 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 */ | ||
1161 | ret = -EOPNOTSUPP; | ||
1162 | goto failed_send; | ||
1163 | } | ||
1164 | |||
1165 | /* settings in QTCB */ | ||
1166 | fsf_req->qtcb->header.port_handle = port->handle; | ||
1167 | fsf_req->qtcb->bottom.support.service_class = | ||
1168 | ZFCP_FC_SERVICE_CLASS_DEFAULT; | ||
1169 | fsf_req->qtcb->bottom.support.timeout = ct->timeout; | ||
1170 | fsf_req->data = (unsigned long) ct; | ||
1171 | |||
1172 | zfcp_san_dbf_event_ct_request(fsf_req); | ||
1173 | 960 | ||
1174 | if (erp_action) { | 961 | spin_lock(&adapter->req_q.lock); |
1175 | erp_action->fsf_req = fsf_req; | 962 | if (!atomic_read(&adapter->req_q.count)) |
1176 | fsf_req->erp_action = erp_action; | 963 | goto out; |
1177 | zfcp_erp_start_timer(fsf_req); | 964 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND, |
1178 | } else | 965 | req_flags, adapter->pool.fsf_req_abort); |
1179 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); | 966 | if (unlikely(IS_ERR(req))) |
967 | goto out; | ||
1180 | 968 | ||
1181 | ret = zfcp_fsf_req_send(fsf_req); | 969 | if (unlikely(!(atomic_read(&unit->status) & |
1182 | if (ret) | 970 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
1183 | goto failed_send; | 971 | goto out_error_free; |
1184 | 972 | ||
1185 | goto out; | 973 | sbale = zfcp_qdio_sbale_req(req); |
974 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | ||
975 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | ||
1186 | 976 | ||
1187 | failed_send: | 977 | req->data = unit; |
1188 | zfcp_fsf_req_free(fsf_req); | 978 | req->handler = zfcp_fsf_abort_fcp_command_handler; |
1189 | if (erp_action != NULL) { | 979 | req->qtcb->header.lun_handle = unit->handle; |
1190 | erp_action->fsf_req = NULL; | 980 | req->qtcb->header.port_handle = unit->port->handle; |
1191 | } | 981 | req->qtcb->bottom.support.req_handle = (u64) old_req_id; |
1192 | failed_req: | 982 | |
1193 | out: | 983 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
1194 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 984 | if (!zfcp_fsf_req_send(req)) |
1195 | return ret; | 985 | goto out; |
986 | |||
987 | out_error_free: | ||
988 | zfcp_fsf_req_free(req); | ||
989 | req = NULL; | ||
990 | out: | ||
991 | spin_unlock(&adapter->req_q.lock); | ||
992 | return req; | ||
1196 | } | 993 | } |
1197 | 994 | ||
1198 | /** | 995 | static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req) |
1199 | * zfcp_fsf_send_ct_handler - handler for Generic Service requests | ||
1200 | * @fsf_req: pointer to struct zfcp_fsf_req | ||
1201 | * | ||
1202 | * 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. | ||
1206 | */ | ||
1207 | static int | ||
1208 | zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req) | ||
1209 | { | 996 | { |
1210 | struct zfcp_port *port; | 997 | struct zfcp_adapter *adapter = req->adapter; |
1211 | struct zfcp_adapter *adapter; | 998 | struct zfcp_send_ct *send_ct = req->data; |
1212 | struct zfcp_send_ct *send_ct; | 999 | struct zfcp_port *port = send_ct->port; |
1213 | struct fsf_qtcb_header *header; | 1000 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1214 | struct fsf_qtcb_bottom_support *bottom; | ||
1215 | int retval = -EINVAL; | ||
1216 | 1001 | ||
1217 | adapter = fsf_req->adapter; | 1002 | send_ct->status = -EINVAL; |
1218 | send_ct = (struct zfcp_send_ct *) fsf_req->data; | ||
1219 | port = send_ct->port; | ||
1220 | header = &fsf_req->qtcb->header; | ||
1221 | bottom = &fsf_req->qtcb->bottom.support; | ||
1222 | 1003 | ||
1223 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | 1004 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1224 | goto skip_fsfstatus; | 1005 | goto skip_fsfstatus; |
1225 | 1006 | ||
1226 | /* evaluate FSF status in QTCB */ | ||
1227 | switch (header->fsf_status) { | 1007 | switch (header->fsf_status) { |
1228 | |||
1229 | case FSF_GOOD: | 1008 | case FSF_GOOD: |
1230 | zfcp_san_dbf_event_ct_response(fsf_req); | 1009 | zfcp_san_dbf_event_ct_response(req); |
1231 | retval = 0; | 1010 | send_ct->status = 0; |
1232 | break; | 1011 | break; |
1233 | |||
1234 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: | 1012 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
1235 | zfcp_fsf_class_not_supp(fsf_req); | 1013 | zfcp_fsf_class_not_supp(req); |
1236 | break; | 1014 | break; |
1237 | |||
1238 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1015 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1239 | switch (header->fsf_status_qual.word[0]){ | 1016 | switch (header->fsf_status_qual.word[0]){ |
1240 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 1017 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
1241 | /* reopening link to port */ | ||
1242 | zfcp_test_link(port); | 1018 | zfcp_test_link(port); |
1243 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1244 | break; | ||
1245 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 1019 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1246 | /* ERP strategy will escalate */ | 1020 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1247 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1248 | break; | 1021 | break; |
1249 | } | 1022 | } |
1250 | break; | 1023 | break; |
1251 | |||
1252 | case FSF_ACCESS_DENIED: | 1024 | case FSF_ACCESS_DENIED: |
1253 | zfcp_fsf_access_denied_port(fsf_req, port); | 1025 | zfcp_fsf_access_denied_port(req, port); |
1254 | break; | ||
1255 | |||
1256 | case FSF_GENERIC_COMMAND_REJECTED: | ||
1257 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1258 | break; | ||
1259 | |||
1260 | case FSF_PORT_HANDLE_NOT_VALID: | ||
1261 | zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req); | ||
1262 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1263 | break; | 1026 | break; |
1264 | |||
1265 | case FSF_PORT_BOXED: | 1027 | case FSF_PORT_BOXED: |
1266 | zfcp_erp_port_boxed(port, 49, fsf_req); | 1028 | zfcp_erp_port_boxed(port, 49, req); |
1267 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | 1029 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
1268 | | ZFCP_STATUS_FSFREQ_RETRY; | 1030 | ZFCP_STATUS_FSFREQ_RETRY; |
1269 | break; | 1031 | break; |
1270 | 1032 | case FSF_PORT_HANDLE_NOT_VALID: | |
1271 | /* following states should never occure, all cases avoided | 1033 | zfcp_erp_adapter_reopen(adapter, 0, 106, req); |
1272 | in zfcp_fsf_send_ct - but who knows ... */ | 1034 | case FSF_GENERIC_COMMAND_REJECTED: |
1273 | case FSF_PAYLOAD_SIZE_MISMATCH: | 1035 | case FSF_PAYLOAD_SIZE_MISMATCH: |
1274 | case FSF_REQUEST_SIZE_TOO_LARGE: | 1036 | case FSF_REQUEST_SIZE_TOO_LARGE: |
1275 | case FSF_RESPONSE_SIZE_TOO_LARGE: | 1037 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
1276 | case FSF_SBAL_MISMATCH: | 1038 | case FSF_SBAL_MISMATCH: |
1277 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1039 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1278 | break; | ||
1279 | |||
1280 | default: | ||
1281 | break; | 1040 | break; |
1282 | } | 1041 | } |
1283 | 1042 | ||
1284 | skip_fsfstatus: | 1043 | skip_fsfstatus: |
1285 | send_ct->status = retval; | 1044 | if (send_ct->handler) |
1286 | |||
1287 | if (send_ct->handler != NULL) | ||
1288 | send_ct->handler(send_ct->handler_data); | 1045 | send_ct->handler(send_ct->handler_data); |
1046 | } | ||
1289 | 1047 | ||
1290 | return retval; | 1048 | static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req, |
1049 | struct scatterlist *sg_req, | ||
1050 | struct scatterlist *sg_resp, int max_sbals) | ||
1051 | { | ||
1052 | int bytes; | ||
1053 | |||
1054 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, | ||
1055 | sg_req, max_sbals); | ||
1056 | if (bytes <= 0) | ||
1057 | return -ENOMEM; | ||
1058 | req->qtcb->bottom.support.req_buf_length = bytes; | ||
1059 | req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; | ||
1060 | |||
1061 | bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ, | ||
1062 | sg_resp, max_sbals); | ||
1063 | if (bytes <= 0) | ||
1064 | return -ENOMEM; | ||
1065 | req->qtcb->bottom.support.resp_buf_length = bytes; | ||
1066 | |||
1067 | return 0; | ||
1291 | } | 1068 | } |
1292 | 1069 | ||
1293 | /** | 1070 | /** |
1294 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) | 1071 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) |
1295 | * @els: pointer to struct zfcp_send_els which contains all needed data for | 1072 | * @ct: pointer to struct zfcp_send_ct with data for request |
1296 | * the command. | 1073 | * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req |
1074 | * @erp_action: if non-null the Generic Service request sent within ERP | ||
1297 | */ | 1075 | */ |
1298 | int | 1076 | int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, |
1299 | zfcp_fsf_send_els(struct zfcp_send_els *els) | 1077 | struct zfcp_erp_action *erp_action) |
1300 | { | 1078 | { |
1301 | volatile struct qdio_buffer_element *sbale; | 1079 | struct zfcp_port *port = ct->port; |
1302 | struct zfcp_fsf_req *fsf_req; | 1080 | struct zfcp_adapter *adapter = port->adapter; |
1303 | u32 d_id; | 1081 | struct zfcp_fsf_req *req; |
1304 | struct zfcp_adapter *adapter; | 1082 | int ret = -EIO; |
1305 | unsigned long lock_flags; | ||
1306 | int bytes; | ||
1307 | int ret = 0; | ||
1308 | 1083 | ||
1309 | d_id = els->d_id; | 1084 | spin_lock(&adapter->req_q.lock); |
1310 | adapter = els->adapter; | 1085 | if (zfcp_fsf_req_sbal_get(adapter)) |
1086 | goto out; | ||
1311 | 1087 | ||
1312 | ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, | 1088 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC, |
1313 | ZFCP_REQ_AUTO_CLEANUP, | 1089 | ZFCP_REQ_AUTO_CLEANUP, pool); |
1314 | NULL, &lock_flags, &fsf_req); | 1090 | if (unlikely(IS_ERR(req))) { |
1315 | if (ret < 0) | 1091 | ret = PTR_ERR(req); |
1316 | goto failed_req; | 1092 | goto out; |
1317 | |||
1318 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, | ||
1319 | &els->port->status))) { | ||
1320 | ret = -EBUSY; | ||
1321 | goto port_blocked; | ||
1322 | } | 1093 | } |
1323 | 1094 | ||
1324 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1095 | ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp, |
1325 | if (zfcp_use_one_sbal(els->req, els->req_count, | 1096 | FSF_MAX_SBALS_PER_REQ); |
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; | ||
1335 | } else if (adapter->adapter_features & | ||
1336 | 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, | ||
1340 | els->req, | ||
1341 | ZFCP_MAX_SBALS_PER_ELS_REQ); | ||
1342 | if (bytes <= 0) { | ||
1343 | 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, | ||
1354 | els->resp, | ||
1355 | ZFCP_MAX_SBALS_PER_ELS_REQ); | ||
1356 | if (bytes <= 0) { | ||
1357 | 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 */ | ||
1367 | ret = -EOPNOTSUPP; | ||
1368 | goto failed_send; | ||
1369 | } | ||
1370 | |||
1371 | /* settings in QTCB */ | ||
1372 | fsf_req->qtcb->bottom.support.d_id = d_id; | ||
1373 | fsf_req->qtcb->bottom.support.service_class = | ||
1374 | ZFCP_FC_SERVICE_CLASS_DEFAULT; | ||
1375 | fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT; | ||
1376 | fsf_req->data = (unsigned long) els; | ||
1377 | |||
1378 | sbale = zfcp_qdio_sbale_req(fsf_req); | ||
1379 | |||
1380 | zfcp_san_dbf_event_els_request(fsf_req); | ||
1381 | |||
1382 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); | ||
1383 | ret = zfcp_fsf_req_send(fsf_req); | ||
1384 | if (ret) | 1097 | if (ret) |
1385 | goto failed_send; | 1098 | goto failed_send; |
1386 | 1099 | ||
1387 | goto out; | 1100 | req->handler = zfcp_fsf_send_ct_handler; |
1101 | req->qtcb->header.port_handle = port->handle; | ||
1102 | req->qtcb->bottom.support.service_class = FSF_CLASS_3; | ||
1103 | req->qtcb->bottom.support.timeout = ct->timeout; | ||
1104 | req->data = ct; | ||
1388 | 1105 | ||
1389 | port_blocked: | 1106 | zfcp_san_dbf_event_ct_request(req); |
1390 | failed_send: | ||
1391 | zfcp_fsf_req_free(fsf_req); | ||
1392 | 1107 | ||
1393 | failed_req: | 1108 | if (erp_action) { |
1394 | out: | 1109 | erp_action->fsf_req = req; |
1395 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1110 | req->erp_action = erp_action; |
1111 | zfcp_erp_start_timer(req); | ||
1112 | } else | ||
1113 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | ||
1114 | |||
1115 | ret = zfcp_fsf_req_send(req); | ||
1116 | if (ret) | ||
1117 | goto failed_send; | ||
1118 | |||
1119 | goto out; | ||
1396 | 1120 | ||
1397 | return ret; | 1121 | failed_send: |
1122 | zfcp_fsf_req_free(req); | ||
1123 | if (erp_action) | ||
1124 | erp_action->fsf_req = NULL; | ||
1125 | out: | ||
1126 | spin_unlock(&adapter->req_q.lock); | ||
1127 | return ret; | ||
1398 | } | 1128 | } |
1399 | 1129 | ||
1400 | /** | 1130 | static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req) |
1401 | * zfcp_fsf_send_els_handler - handler for ELS commands | ||
1402 | * @fsf_req: pointer to struct zfcp_fsf_req | ||
1403 | * | ||
1404 | * 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. | ||
1408 | */ | ||
1409 | static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req) | ||
1410 | { | 1131 | { |
1411 | struct zfcp_adapter *adapter; | 1132 | struct zfcp_send_els *send_els = req->data; |
1412 | struct zfcp_port *port; | 1133 | struct zfcp_port *port = send_els->port; |
1413 | u32 d_id; | 1134 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1414 | struct fsf_qtcb_header *header; | ||
1415 | struct fsf_qtcb_bottom_support *bottom; | ||
1416 | struct zfcp_send_els *send_els; | ||
1417 | int retval = -EINVAL; | ||
1418 | 1135 | ||
1419 | send_els = (struct zfcp_send_els *) fsf_req->data; | 1136 | send_els->status = -EINVAL; |
1420 | adapter = send_els->adapter; | ||
1421 | port = send_els->port; | ||
1422 | d_id = send_els->d_id; | ||
1423 | header = &fsf_req->qtcb->header; | ||
1424 | bottom = &fsf_req->qtcb->bottom.support; | ||
1425 | 1137 | ||
1426 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | 1138 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1427 | goto skip_fsfstatus; | 1139 | goto skip_fsfstatus; |
1428 | 1140 | ||
1429 | switch (header->fsf_status) { | 1141 | switch (header->fsf_status) { |
1430 | |||
1431 | case FSF_GOOD: | 1142 | case FSF_GOOD: |
1432 | zfcp_san_dbf_event_els_response(fsf_req); | 1143 | zfcp_san_dbf_event_els_response(req); |
1433 | retval = 0; | 1144 | send_els->status = 0; |
1434 | break; | 1145 | break; |
1435 | |||
1436 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: | 1146 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
1437 | zfcp_fsf_class_not_supp(fsf_req); | 1147 | zfcp_fsf_class_not_supp(req); |
1438 | break; | 1148 | break; |
1439 | |||
1440 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1149 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1441 | switch (header->fsf_status_qual.word[0]){ | 1150 | switch (header->fsf_status_qual.word[0]){ |
1442 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 1151 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
1443 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) | 1152 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) |
1444 | zfcp_test_link(port); | 1153 | zfcp_test_link(port); |
1445 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1154 | /*fall through */ |
1446 | break; | ||
1447 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 1155 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1448 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1449 | break; | ||
1450 | case FSF_SQ_RETRY_IF_POSSIBLE: | 1156 | case FSF_SQ_RETRY_IF_POSSIBLE: |
1451 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1157 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1452 | break; | 1158 | break; |
1453 | } | 1159 | } |
1454 | break; | 1160 | break; |
1455 | |||
1456 | case FSF_ELS_COMMAND_REJECTED: | 1161 | case FSF_ELS_COMMAND_REJECTED: |
1457 | case FSF_PAYLOAD_SIZE_MISMATCH: | 1162 | case FSF_PAYLOAD_SIZE_MISMATCH: |
1458 | case FSF_REQUEST_SIZE_TOO_LARGE: | 1163 | case FSF_REQUEST_SIZE_TOO_LARGE: |
1459 | case FSF_RESPONSE_SIZE_TOO_LARGE: | 1164 | case FSF_RESPONSE_SIZE_TOO_LARGE: |
1460 | break; | 1165 | break; |
1461 | |||
1462 | case FSF_SBAL_MISMATCH: | ||
1463 | /* should never occure, avoided in zfcp_fsf_send_els */ | ||
1464 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1465 | break; | ||
1466 | |||
1467 | case FSF_ACCESS_DENIED: | 1166 | case FSF_ACCESS_DENIED: |
1468 | zfcp_fsf_access_denied_port(fsf_req, port); | 1167 | zfcp_fsf_access_denied_port(req, port); |
1469 | break; | 1168 | break; |
1470 | 1169 | case FSF_SBAL_MISMATCH: | |
1170 | /* should never occure, avoided in zfcp_fsf_send_els */ | ||
1171 | /* fall through */ | ||
1471 | default: | 1172 | default: |
1472 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1173 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1473 | break; | 1174 | break; |
1474 | } | 1175 | } |
1475 | |||
1476 | skip_fsfstatus: | 1176 | skip_fsfstatus: |
1477 | send_els->status = retval; | ||
1478 | |||
1479 | if (send_els->handler) | 1177 | if (send_els->handler) |
1480 | send_els->handler(send_els->handler_data); | 1178 | send_els->handler(send_els->handler_data); |
1179 | } | ||
1481 | 1180 | ||
1482 | return retval; | 1181 | /** |
1182 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) | ||
1183 | * @els: pointer to struct zfcp_send_els with data for the command | ||
1184 | */ | ||
1185 | int zfcp_fsf_send_els(struct zfcp_send_els *els) | ||
1186 | { | ||
1187 | struct zfcp_fsf_req *req; | ||
1188 | struct zfcp_adapter *adapter = els->adapter; | ||
1189 | struct fsf_qtcb_bottom_support *bottom; | ||
1190 | int ret = -EIO; | ||
1191 | |||
1192 | if (unlikely(!(atomic_read(&els->port->status) & | ||
1193 | ZFCP_STATUS_COMMON_UNBLOCKED))) | ||
1194 | return -EBUSY; | ||
1195 | |||
1196 | spin_lock(&adapter->req_q.lock); | ||
1197 | if (!atomic_read(&adapter->req_q.count)) | ||
1198 | goto out; | ||
1199 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, | ||
1200 | ZFCP_REQ_AUTO_CLEANUP, NULL); | ||
1201 | if (unlikely(IS_ERR(req))) { | ||
1202 | ret = PTR_ERR(req); | ||
1203 | goto out; | ||
1204 | } | ||
1205 | |||
1206 | ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, | ||
1207 | FSF_MAX_SBALS_PER_ELS_REQ); | ||
1208 | if (ret) | ||
1209 | goto failed_send; | ||
1210 | |||
1211 | bottom = &req->qtcb->bottom.support; | ||
1212 | req->handler = zfcp_fsf_send_els_handler; | ||
1213 | bottom->d_id = els->d_id; | ||
1214 | bottom->service_class = FSF_CLASS_3; | ||
1215 | bottom->timeout = 2 * R_A_TOV; | ||
1216 | req->data = els; | ||
1217 | |||
1218 | zfcp_san_dbf_event_els_request(req); | ||
1219 | |||
1220 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | ||
1221 | ret = zfcp_fsf_req_send(req); | ||
1222 | if (ret) | ||
1223 | goto failed_send; | ||
1224 | |||
1225 | goto out; | ||
1226 | |||
1227 | failed_send: | ||
1228 | zfcp_fsf_req_free(req); | ||
1229 | out: | ||
1230 | spin_unlock(&adapter->req_q.lock); | ||
1231 | return ret; | ||
1483 | } | 1232 | } |
1484 | 1233 | ||
1485 | int | 1234 | int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) |
1486 | zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) | ||
1487 | { | 1235 | { |
1488 | volatile struct qdio_buffer_element *sbale; | 1236 | volatile struct qdio_buffer_element *sbale; |
1489 | struct zfcp_fsf_req *fsf_req; | 1237 | struct zfcp_fsf_req *req; |
1490 | struct zfcp_adapter *adapter = erp_action->adapter; | 1238 | struct zfcp_adapter *adapter = erp_action->adapter; |
1491 | unsigned long lock_flags; | 1239 | int retval = -EIO; |
1492 | int retval; | 1240 | |
1493 | 1241 | spin_lock(&adapter->req_q.lock); | |
1494 | /* setup new FSF request */ | 1242 | if (!atomic_read(&adapter->req_q.count)) |
1495 | retval = zfcp_fsf_req_create(adapter, | 1243 | goto out; |
1496 | FSF_QTCB_EXCHANGE_CONFIG_DATA, | 1244 | req = zfcp_fsf_req_create(adapter, |
1497 | ZFCP_REQ_AUTO_CLEANUP, | 1245 | FSF_QTCB_EXCHANGE_CONFIG_DATA, |
1498 | adapter->pool.fsf_req_erp, | 1246 | ZFCP_REQ_AUTO_CLEANUP, |
1499 | &lock_flags, &fsf_req); | 1247 | adapter->pool.fsf_req_erp); |
1500 | if (retval) { | 1248 | if (unlikely(IS_ERR(req))) { |
1501 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1249 | retval = PTR_ERR(req); |
1502 | return retval; | 1250 | goto out; |
1503 | } | 1251 | } |
1504 | 1252 | ||
1505 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1253 | sbale = zfcp_qdio_sbale_req(req); |
1506 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1254 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1507 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1255 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
1508 | 1256 | ||
1509 | fsf_req->qtcb->bottom.config.feature_selection = | 1257 | req->qtcb->bottom.config.feature_selection = |
1510 | FSF_FEATURE_CFDC | | 1258 | FSF_FEATURE_CFDC | |
1511 | FSF_FEATURE_LUN_SHARING | | 1259 | FSF_FEATURE_LUN_SHARING | |
1512 | FSF_FEATURE_NOTIFICATION_LOST | | 1260 | FSF_FEATURE_NOTIFICATION_LOST | |
1513 | FSF_FEATURE_UPDATE_ALERT; | 1261 | FSF_FEATURE_UPDATE_ALERT; |
1514 | fsf_req->erp_action = erp_action; | 1262 | req->erp_action = erp_action; |
1515 | erp_action->fsf_req = fsf_req; | 1263 | req->handler = zfcp_fsf_exchange_config_data_handler; |
1264 | erp_action->fsf_req = req; | ||
1516 | 1265 | ||
1517 | zfcp_erp_start_timer(fsf_req); | 1266 | zfcp_erp_start_timer(req); |
1518 | retval = zfcp_fsf_req_send(fsf_req); | 1267 | retval = zfcp_fsf_req_send(req); |
1519 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | ||
1520 | if (retval) { | 1268 | if (retval) { |
1521 | zfcp_fsf_req_free(fsf_req); | 1269 | zfcp_fsf_req_free(req); |
1522 | erp_action->fsf_req = NULL; | 1270 | erp_action->fsf_req = NULL; |
1523 | } | 1271 | } |
1524 | 1272 | out: | |
1273 | spin_unlock(&adapter->req_q.lock); | ||
1525 | return retval; | 1274 | return retval; |
1526 | } | 1275 | } |
1527 | 1276 | ||
1528 | int | 1277 | int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, |
1529 | zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter, | 1278 | struct fsf_qtcb_bottom_config *data) |
1530 | struct fsf_qtcb_bottom_config *data) | ||
1531 | { | 1279 | { |
1532 | volatile struct qdio_buffer_element *sbale; | 1280 | volatile struct qdio_buffer_element *sbale; |
1533 | struct zfcp_fsf_req *fsf_req; | 1281 | struct zfcp_fsf_req *req = NULL; |
1534 | unsigned long lock_flags; | 1282 | int retval = -EIO; |
1535 | int retval; | 1283 | |
1536 | 1284 | spin_lock(&adapter->req_q.lock); | |
1537 | /* setup new FSF request */ | 1285 | if (zfcp_fsf_req_sbal_get(adapter)) |
1538 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, | 1286 | goto out; |
1539 | ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags, | 1287 | |
1540 | &fsf_req); | 1288 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA, |
1541 | if (retval) { | 1289 | 0, NULL); |
1542 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1290 | if (unlikely(IS_ERR(req))) { |
1543 | return retval; | 1291 | retval = PTR_ERR(req); |
1292 | goto out; | ||
1544 | } | 1293 | } |
1545 | 1294 | ||
1546 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1295 | sbale = zfcp_qdio_sbale_req(req); |
1547 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1296 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1548 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1297 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
1298 | req->handler = zfcp_fsf_exchange_config_data_handler; | ||
1549 | 1299 | ||
1550 | fsf_req->qtcb->bottom.config.feature_selection = | 1300 | req->qtcb->bottom.config.feature_selection = |
1551 | FSF_FEATURE_CFDC | | 1301 | FSF_FEATURE_CFDC | |
1552 | FSF_FEATURE_LUN_SHARING | | 1302 | FSF_FEATURE_LUN_SHARING | |
1553 | FSF_FEATURE_NOTIFICATION_LOST | | 1303 | FSF_FEATURE_NOTIFICATION_LOST | |
1554 | FSF_FEATURE_UPDATE_ALERT; | 1304 | FSF_FEATURE_UPDATE_ALERT; |
1555 | 1305 | ||
1556 | if (data) | 1306 | if (data) |
1557 | fsf_req->data = (unsigned long) data; | 1307 | req->data = data; |
1558 | 1308 | ||
1559 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); | 1309 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
1560 | retval = zfcp_fsf_req_send(fsf_req); | 1310 | retval = zfcp_fsf_req_send(req); |
1561 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1311 | out: |
1312 | spin_unlock(&adapter->req_q.lock); | ||
1562 | if (!retval) | 1313 | if (!retval) |
1563 | wait_event(fsf_req->completion_wq, | 1314 | wait_event(req->completion_wq, |
1564 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | 1315 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
1565 | 1316 | ||
1566 | zfcp_fsf_req_free(fsf_req); | 1317 | zfcp_fsf_req_free(req); |
1567 | 1318 | ||
1568 | return retval; | 1319 | return retval; |
1569 | } | 1320 | } |
1570 | 1321 | ||
1571 | /** | 1322 | /** |
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 | */ | ||
1578 | static int | ||
1579 | zfcp_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; | ||
1583 | struct Scsi_Host *shost = adapter->scsi_host; | ||
1584 | |||
1585 | bottom = &fsf_req->qtcb->bottom.config; | ||
1586 | adapter->fsf_lic_version = bottom->lic_version; | ||
1587 | adapter->adapter_features = bottom->adapter_features; | ||
1588 | adapter->connection_features = bottom->connection_features; | ||
1589 | adapter->peer_wwpn = 0; | ||
1590 | adapter->peer_wwnn = 0; | ||
1591 | adapter->peer_d_id = 0; | ||
1592 | |||
1593 | if (xchg_ok) { | ||
1594 | |||
1595 | if (fsf_req->data) | ||
1596 | memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data, | ||
1597 | bottom, sizeof (struct fsf_qtcb_bottom_config)); | ||
1598 | |||
1599 | 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; | ||
1603 | fc_host_supported_classes(shost) = | ||
1604 | FC_COS_CLASS2 | FC_COS_CLASS3; | ||
1605 | adapter->hydra_version = bottom->adapter_type; | ||
1606 | adapter->timer_ticks = bottom->timer_interval; | ||
1607 | 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; | ||
1621 | } else { | ||
1622 | 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; | ||
1626 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | ||
1627 | adapter->hydra_version = 0; | ||
1628 | } | ||
1629 | |||
1630 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { | ||
1631 | adapter->hardware_version = bottom->hardware_version; | ||
1632 | 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)); | ||
1636 | } | ||
1637 | |||
1638 | if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) { | ||
1639 | dev_err(&adapter->ccw_device->dev, | ||
1640 | "The adapter only supports newer control block " | ||
1641 | "versions, try updated device driver.\n"); | ||
1642 | zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req); | ||
1643 | return -EIO; | ||
1644 | } | ||
1645 | if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) { | ||
1646 | dev_err(&adapter->ccw_device->dev, | ||
1647 | "The adapter only supports older control block " | ||
1648 | "versions, consider a microcode upgrade.\n"); | ||
1649 | zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req); | ||
1650 | return -EIO; | ||
1651 | } | ||
1652 | return 0; | ||
1653 | } | ||
1654 | |||
1655 | /** | ||
1656 | * function: zfcp_fsf_exchange_config_data_handler | ||
1657 | * | ||
1658 | * purpose: is called for finished Exchange Configuration Data command | ||
1659 | * | ||
1660 | * returns: | ||
1661 | */ | ||
1662 | static int | ||
1663 | zfcp_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; | ||
1667 | struct fsf_qtcb *qtcb = fsf_req->qtcb; | ||
1668 | |||
1669 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | ||
1670 | return -EIO; | ||
1671 | |||
1672 | switch (qtcb->header.fsf_status) { | ||
1673 | |||
1674 | case FSF_GOOD: | ||
1675 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1)) | ||
1676 | return -EIO; | ||
1677 | |||
1678 | switch (fc_host_port_type(adapter->scsi_host)) { | ||
1679 | case FC_PORTTYPE_PTP: | ||
1680 | if (fsf_req->erp_action) | ||
1681 | dev_info(&adapter->ccw_device->dev, | ||
1682 | "Point-to-Point fibrechannel " | ||
1683 | "configuration detected.\n"); | ||
1684 | break; | ||
1685 | case FC_PORTTYPE_NLPORT: | ||
1686 | dev_err(&adapter->ccw_device->dev, | ||
1687 | "Unsupported arbitrated loop fibrechannel " | ||
1688 | "topology detected, shutting down adapter\n"); | ||
1689 | zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req); | ||
1690 | return -EIO; | ||
1691 | case FC_PORTTYPE_NPORT: | ||
1692 | if (fsf_req->erp_action) | ||
1693 | dev_info(&adapter->ccw_device->dev, | ||
1694 | "Switched fabric fibrechannel " | ||
1695 | "network detected.\n"); | ||
1696 | break; | ||
1697 | default: | ||
1698 | 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"); | ||
1702 | zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req); | ||
1703 | return -EIO; | ||
1704 | } | ||
1705 | bottom = &qtcb->bottom.config; | ||
1706 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { | ||
1707 | 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)); | ||
1712 | zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req); | ||
1713 | return -EIO; | ||
1714 | } | ||
1715 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, | ||
1716 | &adapter->status); | ||
1717 | break; | ||
1718 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | ||
1719 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0)) | ||
1720 | return -EIO; | ||
1721 | |||
1722 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, | ||
1723 | &adapter->status); | ||
1724 | |||
1725 | zfcp_fsf_link_down_info_eval(fsf_req, 42, | ||
1726 | &qtcb->header.fsf_status_qual.link_down_info); | ||
1727 | break; | ||
1728 | default: | ||
1729 | zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req); | ||
1730 | return -EIO; | ||
1731 | } | ||
1732 | return 0; | ||
1733 | } | ||
1734 | |||
1735 | /** | ||
1736 | * zfcp_fsf_exchange_port_data - request information about local port | 1323 | * zfcp_fsf_exchange_port_data - request information about local port |
1737 | * @erp_action: ERP action for the adapter for which port data is requested | 1324 | * @erp_action: ERP action for the adapter for which port data is requested |
1325 | * Returns: 0 on success, error otherwise | ||
1738 | */ | 1326 | */ |
1739 | int | 1327 | int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) |
1740 | zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action) | ||
1741 | { | 1328 | { |
1742 | volatile struct qdio_buffer_element *sbale; | 1329 | volatile struct qdio_buffer_element *sbale; |
1743 | struct zfcp_fsf_req *fsf_req; | 1330 | struct zfcp_fsf_req *req; |
1744 | struct zfcp_adapter *adapter = erp_action->adapter; | 1331 | struct zfcp_adapter *adapter = erp_action->adapter; |
1745 | unsigned long lock_flags; | 1332 | int retval = -EIO; |
1746 | int retval; | ||
1747 | 1333 | ||
1748 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) | 1334 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
1749 | return -EOPNOTSUPP; | 1335 | return -EOPNOTSUPP; |
1750 | 1336 | ||
1751 | /* setup new FSF request */ | 1337 | spin_lock(&adapter->req_q.lock); |
1752 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, | 1338 | if (!atomic_read(&adapter->req_q.count)) |
1753 | ZFCP_REQ_AUTO_CLEANUP, | 1339 | goto out; |
1754 | adapter->pool.fsf_req_erp, | 1340 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, |
1755 | &lock_flags, &fsf_req); | 1341 | ZFCP_REQ_AUTO_CLEANUP, |
1756 | if (retval) { | 1342 | adapter->pool.fsf_req_erp); |
1757 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1343 | if (unlikely(IS_ERR(req))) { |
1758 | return retval; | 1344 | retval = PTR_ERR(req); |
1345 | goto out; | ||
1759 | } | 1346 | } |
1760 | 1347 | ||
1761 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1348 | sbale = zfcp_qdio_sbale_req(req); |
1762 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1349 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1763 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1350 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
1764 | 1351 | ||
1765 | erp_action->fsf_req = fsf_req; | 1352 | req->handler = zfcp_fsf_exchange_port_data_handler; |
1766 | fsf_req->erp_action = erp_action; | 1353 | req->erp_action = erp_action; |
1767 | zfcp_erp_start_timer(fsf_req); | 1354 | erp_action->fsf_req = req; |
1768 | |||
1769 | retval = zfcp_fsf_req_send(fsf_req); | ||
1770 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | ||
1771 | 1355 | ||
1356 | zfcp_erp_start_timer(req); | ||
1357 | retval = zfcp_fsf_req_send(req); | ||
1772 | if (retval) { | 1358 | if (retval) { |
1773 | zfcp_fsf_req_free(fsf_req); | 1359 | zfcp_fsf_req_free(req); |
1774 | erp_action->fsf_req = NULL; | 1360 | erp_action->fsf_req = NULL; |
1775 | } | 1361 | } |
1362 | out: | ||
1363 | spin_unlock(&adapter->req_q.lock); | ||
1776 | return retval; | 1364 | return retval; |
1777 | } | 1365 | } |
1778 | 1366 | ||
1779 | |||
1780 | /** | 1367 | /** |
1781 | * zfcp_fsf_exchange_port_data_sync - request information about local port | 1368 | * zfcp_fsf_exchange_port_data_sync - request information about local port |
1782 | * and wait until information is ready | 1369 | * @adapter: pointer to struct zfcp_adapter |
1370 | * @data: pointer to struct fsf_qtcb_bottom_port | ||
1371 | * Returns: 0 on success, error otherwise | ||
1783 | */ | 1372 | */ |
1784 | int | 1373 | int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, |
1785 | zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter, | 1374 | struct fsf_qtcb_bottom_port *data) |
1786 | struct fsf_qtcb_bottom_port *data) | ||
1787 | { | 1375 | { |
1788 | volatile struct qdio_buffer_element *sbale; | 1376 | volatile struct qdio_buffer_element *sbale; |
1789 | struct zfcp_fsf_req *fsf_req; | 1377 | struct zfcp_fsf_req *req = NULL; |
1790 | unsigned long lock_flags; | 1378 | int retval = -EIO; |
1791 | int retval; | ||
1792 | 1379 | ||
1793 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) | 1380 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) |
1794 | return -EOPNOTSUPP; | 1381 | return -EOPNOTSUPP; |
1795 | 1382 | ||
1796 | /* setup new FSF request */ | 1383 | spin_lock(&adapter->req_q.lock); |
1797 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, | 1384 | if (!atomic_read(&adapter->req_q.count)) |
1798 | 0, NULL, &lock_flags, &fsf_req); | 1385 | goto out; |
1799 | if (retval) { | 1386 | |
1800 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1387 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0, |
1801 | return retval; | 1388 | NULL); |
1389 | if (unlikely(IS_ERR(req))) { | ||
1390 | retval = PTR_ERR(req); | ||
1391 | goto out; | ||
1802 | } | 1392 | } |
1803 | 1393 | ||
1804 | if (data) | 1394 | if (data) |
1805 | fsf_req->data = (unsigned long) data; | 1395 | req->data = data; |
1806 | 1396 | ||
1807 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1397 | sbale = zfcp_qdio_sbale_req(req); |
1808 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1398 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
1809 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1399 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
1810 | 1400 | ||
1811 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); | 1401 | req->handler = zfcp_fsf_exchange_port_data_handler; |
1812 | retval = zfcp_fsf_req_send(fsf_req); | 1402 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
1813 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1403 | retval = zfcp_fsf_req_send(req); |
1814 | 1404 | out: | |
1405 | spin_unlock(&adapter->req_q.lock); | ||
1815 | if (!retval) | 1406 | if (!retval) |
1816 | wait_event(fsf_req->completion_wq, | 1407 | wait_event(req->completion_wq, |
1817 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | 1408 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); |
1818 | 1409 | zfcp_fsf_req_free(req); | |
1819 | zfcp_fsf_req_free(fsf_req); | ||
1820 | 1410 | ||
1821 | return retval; | 1411 | return retval; |
1822 | } | 1412 | } |
1823 | 1413 | ||
1824 | /** | 1414 | static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req) |
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 | */ | ||
1829 | static void | ||
1830 | zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok) | ||
1831 | { | ||
1832 | struct zfcp_adapter *adapter; | ||
1833 | struct fsf_qtcb_bottom_port *bottom; | ||
1834 | struct Scsi_Host *shost; | ||
1835 | |||
1836 | adapter = fsf_req->adapter; | ||
1837 | bottom = &fsf_req->qtcb->bottom.port; | ||
1838 | shost = adapter->scsi_host; | ||
1839 | |||
1840 | if (fsf_req->data) | ||
1841 | memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom, | ||
1842 | sizeof(struct fsf_qtcb_bottom_port)); | ||
1843 | |||
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 | } | ||
1851 | |||
1852 | /** | ||
1853 | * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request | ||
1854 | * @fsf_req: pointer to struct zfcp_fsf_req | ||
1855 | */ | ||
1856 | static void | ||
1857 | zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req) | ||
1858 | { | ||
1859 | struct zfcp_adapter *adapter; | ||
1860 | struct fsf_qtcb *qtcb; | ||
1861 | |||
1862 | adapter = fsf_req->adapter; | ||
1863 | qtcb = fsf_req->qtcb; | ||
1864 | |||
1865 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | ||
1866 | return; | ||
1867 | |||
1868 | switch (qtcb->header.fsf_status) { | ||
1869 | case FSF_GOOD: | ||
1870 | zfcp_fsf_exchange_port_evaluate(fsf_req, 1); | ||
1871 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); | ||
1872 | break; | ||
1873 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | ||
1874 | zfcp_fsf_exchange_port_evaluate(fsf_req, 0); | ||
1875 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); | ||
1876 | zfcp_fsf_link_down_info_eval(fsf_req, 43, | ||
1877 | &qtcb->header.fsf_status_qual.link_down_info); | ||
1878 | break; | ||
1879 | } | ||
1880 | } | ||
1881 | |||
1882 | |||
1883 | /* | ||
1884 | * function: zfcp_fsf_open_port | ||
1885 | * | ||
1886 | * purpose: | ||
1887 | * | ||
1888 | * returns: address of initiated FSF request | ||
1889 | * NULL - request could not be initiated | ||
1890 | */ | ||
1891 | int | ||
1892 | zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) | ||
1893 | { | ||
1894 | volatile struct qdio_buffer_element *sbale; | ||
1895 | struct zfcp_fsf_req *fsf_req; | ||
1896 | 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, | ||
1904 | &lock_flags, &fsf_req); | ||
1905 | if (retval < 0) | ||
1906 | goto out; | ||
1907 | |||
1908 | sbale = zfcp_qdio_sbale_req(fsf_req); | ||
1909 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | ||
1910 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | ||
1911 | |||
1912 | fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id; | ||
1913 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status); | ||
1914 | fsf_req->data = (unsigned long) erp_action->port; | ||
1915 | fsf_req->erp_action = erp_action; | ||
1916 | erp_action->fsf_req = fsf_req; | ||
1917 | |||
1918 | zfcp_erp_start_timer(fsf_req); | ||
1919 | retval = zfcp_fsf_req_send(fsf_req); | ||
1920 | if (retval) { | ||
1921 | zfcp_fsf_req_free(fsf_req); | ||
1922 | erp_action->fsf_req = NULL; | ||
1923 | goto out; | ||
1924 | } | ||
1925 | |||
1926 | out: | ||
1927 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); | ||
1928 | return retval; | ||
1929 | } | ||
1930 | |||
1931 | /* | ||
1932 | * function: zfcp_fsf_open_port_handler | ||
1933 | * | ||
1934 | * purpose: is called for finished Open Port command | ||
1935 | * | ||
1936 | * returns: | ||
1937 | */ | ||
1938 | static int | ||
1939 | zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req) | ||
1940 | { | 1415 | { |
1941 | int retval = -EINVAL; | 1416 | struct zfcp_port *port = req->data; |
1942 | struct zfcp_port *port; | 1417 | struct fsf_qtcb_header *header = &req->qtcb->header; |
1943 | struct fsf_plogi *plogi; | 1418 | struct fsf_plogi *plogi; |
1944 | struct fsf_qtcb_header *header; | ||
1945 | |||
1946 | port = (struct zfcp_port *) fsf_req->data; | ||
1947 | header = &fsf_req->qtcb->header; | ||
1948 | 1419 | ||
1949 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | 1420 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
1950 | /* don't change port status in our bookkeeping */ | ||
1951 | goto skip_fsfstatus; | 1421 | goto skip_fsfstatus; |
1952 | } | ||
1953 | 1422 | ||
1954 | /* evaluate FSF status in QTCB */ | ||
1955 | switch (header->fsf_status) { | 1423 | switch (header->fsf_status) { |
1956 | |||
1957 | case FSF_PORT_ALREADY_OPEN: | 1424 | case FSF_PORT_ALREADY_OPEN: |
1958 | /* | ||
1959 | * This is a bug, however operation should continue normally | ||
1960 | * if it is simply ignored | ||
1961 | */ | ||
1962 | break; | 1425 | break; |
1963 | |||
1964 | case FSF_ACCESS_DENIED: | 1426 | case FSF_ACCESS_DENIED: |
1965 | zfcp_fsf_access_denied_port(fsf_req, port); | 1427 | zfcp_fsf_access_denied_port(req, port); |
1966 | break; | 1428 | break; |
1967 | |||
1968 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: | 1429 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: |
1969 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 1430 | dev_warn(&req->adapter->ccw_device->dev, |
1970 | "The adapter is out of resources. The remote port " | 1431 | "The adapter is out of resources. The remote port " |
1971 | "0x%016Lx could not be opened, disabling it.\n", | 1432 | "0x%016Lx could not be opened, disabling it.\n", |
1972 | port->wwpn); | 1433 | port->wwpn); |
1973 | zfcp_erp_port_failed(port, 31, fsf_req); | 1434 | zfcp_erp_port_failed(port, 31, req); |
1974 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1435 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1975 | break; | 1436 | break; |
1976 | |||
1977 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1437 | case FSF_ADAPTER_STATUS_AVAILABLE: |
1978 | switch (header->fsf_status_qual.word[0]) { | 1438 | switch (header->fsf_status_qual.word[0]) { |
1979 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 1439 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
1980 | /* ERP strategy will escalate */ | ||
1981 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1982 | break; | ||
1983 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 1440 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
1984 | /* ERP strategy will escalate */ | 1441 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1985 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
1986 | break; | 1442 | break; |
1987 | case FSF_SQ_NO_RETRY_POSSIBLE: | 1443 | case FSF_SQ_NO_RETRY_POSSIBLE: |
1988 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 1444 | dev_warn(&req->adapter->ccw_device->dev, |
1989 | "The remote port 0x%016Lx could not be " | 1445 | "The remote port 0x%016Lx could not be " |
1990 | "opened. Disabling it.\n", port->wwpn); | 1446 | "opened. Disabling it.\n", port->wwpn); |
1991 | zfcp_erp_port_failed(port, 32, fsf_req); | 1447 | zfcp_erp_port_failed(port, 32, req); |
1992 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1448 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1993 | break; | ||
1994 | default: | ||
1995 | break; | 1449 | break; |
1996 | } | 1450 | } |
1997 | break; | 1451 | break; |
1998 | |||
1999 | case FSF_GOOD: | 1452 | case FSF_GOOD: |
2000 | /* save port handle assigned by FSF */ | ||
2001 | port->handle = header->port_handle; | 1453 | port->handle = header->port_handle; |
2002 | /* mark port as open */ | ||
2003 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | | 1454 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | |
2004 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | 1455 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
2005 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | | 1456 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
2006 | ZFCP_STATUS_COMMON_ACCESS_BOXED, | 1457 | ZFCP_STATUS_COMMON_ACCESS_BOXED, |
2007 | &port->status); | 1458 | &port->status); |
2008 | retval = 0; | ||
2009 | /* check whether D_ID has changed during open */ | 1459 | /* check whether D_ID has changed during open */ |
2010 | /* | 1460 | /* |
2011 | * FIXME: This check is not airtight, as the FCP channel does | 1461 | * FIXME: This check is not airtight, as the FCP channel does |
@@ -2021,227 +1471,168 @@ zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req) | |||
2021 | * another GID_PN straight after a port has been opened. | 1471 | * another GID_PN straight after a port has been opened. |
2022 | * Alternately, an ADISC/PDISC ELS should suffice, as well. | 1472 | * Alternately, an ADISC/PDISC ELS should suffice, as well. |
2023 | */ | 1473 | */ |
2024 | plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els; | 1474 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) |
2025 | if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status)) | 1475 | break; |
2026 | { | 1476 | |
2027 | if (fsf_req->qtcb->bottom.support.els1_length < | 1477 | plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els; |
2028 | sizeof (struct fsf_plogi)) { | 1478 | if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) { |
2029 | /* skip sanity check and assume wwpn is ok */ | 1479 | if (plogi->serv_param.wwpn != port->wwpn) |
2030 | } else { | 1480 | atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID, |
2031 | if (plogi->serv_param.wwpn != port->wwpn) { | 1481 | &port->status); |
2032 | atomic_clear_mask( | 1482 | else { |
2033 | ZFCP_STATUS_PORT_DID_DID, | 1483 | port->wwnn = plogi->serv_param.wwnn; |
2034 | &port->status); | 1484 | zfcp_fc_plogi_evaluate(port, plogi); |
2035 | } else { | ||
2036 | port->wwnn = plogi->serv_param.wwnn; | ||
2037 | zfcp_fc_plogi_evaluate(port, plogi); | ||
2038 | } | ||
2039 | } | 1485 | } |
2040 | } | 1486 | } |
2041 | break; | 1487 | break; |
2042 | |||
2043 | case FSF_UNKNOWN_OP_SUBTYPE: | 1488 | case FSF_UNKNOWN_OP_SUBTYPE: |
2044 | /* should never occure, subtype not set in zfcp_fsf_open_port */ | 1489 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2045 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2046 | break; | ||
2047 | |||
2048 | default: | ||
2049 | break; | 1490 | break; |
2050 | } | 1491 | } |
2051 | 1492 | ||
2052 | skip_fsfstatus: | 1493 | skip_fsfstatus: |
2053 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); | 1494 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); |
2054 | return retval; | ||
2055 | } | 1495 | } |
2056 | 1496 | ||
2057 | /* | 1497 | /** |
2058 | * function: zfcp_fsf_close_port | 1498 | * zfcp_fsf_open_port - create and send open port request |
2059 | * | 1499 | * @erp_action: pointer to struct zfcp_erp_action |
2060 | * purpose: submit FSF command "close port" | 1500 | * Returns: 0 on success, error otherwise |
2061 | * | ||
2062 | * returns: address of initiated FSF request | ||
2063 | * NULL - request could not be initiated | ||
2064 | */ | 1501 | */ |
2065 | int | 1502 | int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) |
2066 | zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) | ||
2067 | { | 1503 | { |
2068 | volatile struct qdio_buffer_element *sbale; | 1504 | volatile struct qdio_buffer_element *sbale; |
2069 | struct zfcp_fsf_req *fsf_req; | 1505 | struct zfcp_adapter *adapter = erp_action->adapter; |
2070 | unsigned long lock_flags; | 1506 | struct zfcp_fsf_req *req; |
2071 | int retval = 0; | 1507 | int retval = -EIO; |
2072 | 1508 | ||
2073 | /* setup new FSF request */ | 1509 | spin_lock(&adapter->req_q.lock); |
2074 | retval = zfcp_fsf_req_create(erp_action->adapter, | 1510 | if (zfcp_fsf_req_sbal_get(adapter)) |
2075 | FSF_QTCB_CLOSE_PORT, | 1511 | goto out; |
2076 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | 1512 | |
2077 | erp_action->adapter->pool.fsf_req_erp, | 1513 | req = zfcp_fsf_req_create(adapter, |
2078 | &lock_flags, &fsf_req); | 1514 | FSF_QTCB_OPEN_PORT_WITH_DID, |
2079 | if (retval < 0) | 1515 | ZFCP_REQ_AUTO_CLEANUP, |
1516 | adapter->pool.fsf_req_erp); | ||
1517 | if (unlikely(IS_ERR(req))) { | ||
1518 | retval = PTR_ERR(req); | ||
2080 | goto out; | 1519 | goto out; |
1520 | } | ||
2081 | 1521 | ||
2082 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1522 | sbale = zfcp_qdio_sbale_req(req); |
2083 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1523 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
2084 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1524 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
2085 | 1525 | ||
2086 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); | 1526 | req->handler = zfcp_fsf_open_port_handler; |
2087 | fsf_req->data = (unsigned long) erp_action->port; | 1527 | req->qtcb->bottom.support.d_id = erp_action->port->d_id; |
2088 | fsf_req->erp_action = erp_action; | 1528 | req->data = erp_action->port; |
2089 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; | 1529 | req->erp_action = erp_action; |
2090 | fsf_req->erp_action = erp_action; | 1530 | erp_action->fsf_req = req; |
2091 | erp_action->fsf_req = fsf_req; | 1531 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status); |
2092 | 1532 | ||
2093 | zfcp_erp_start_timer(fsf_req); | 1533 | zfcp_erp_start_timer(req); |
2094 | retval = zfcp_fsf_req_send(fsf_req); | 1534 | retval = zfcp_fsf_req_send(req); |
2095 | if (retval) { | 1535 | if (retval) { |
2096 | zfcp_fsf_req_free(fsf_req); | 1536 | zfcp_fsf_req_free(req); |
2097 | erp_action->fsf_req = NULL; | 1537 | erp_action->fsf_req = NULL; |
2098 | goto out; | ||
2099 | } | 1538 | } |
2100 | 1539 | out: | |
2101 | out: | 1540 | spin_unlock(&adapter->req_q.lock); |
2102 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); | ||
2103 | return retval; | 1541 | return retval; |
2104 | } | 1542 | } |
2105 | 1543 | ||
2106 | /* | 1544 | static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req) |
2107 | * function: zfcp_fsf_close_port_handler | ||
2108 | * | ||
2109 | * purpose: is called for finished Close Port FSF command | ||
2110 | * | ||
2111 | * returns: | ||
2112 | */ | ||
2113 | static int | ||
2114 | zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req) | ||
2115 | { | 1545 | { |
2116 | int retval = -EINVAL; | 1546 | struct zfcp_port *port = req->data; |
2117 | struct zfcp_port *port; | ||
2118 | |||
2119 | port = (struct zfcp_port *) fsf_req->data; | ||
2120 | 1547 | ||
2121 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | 1548 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
2122 | /* don't change port status in our bookkeeping */ | ||
2123 | goto skip_fsfstatus; | 1549 | goto skip_fsfstatus; |
2124 | } | ||
2125 | |||
2126 | /* evaluate FSF status in QTCB */ | ||
2127 | switch (fsf_req->qtcb->header.fsf_status) { | ||
2128 | 1550 | ||
1551 | switch (req->qtcb->header.fsf_status) { | ||
2129 | case FSF_PORT_HANDLE_NOT_VALID: | 1552 | case FSF_PORT_HANDLE_NOT_VALID: |
2130 | zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req); | 1553 | zfcp_erp_adapter_reopen(port->adapter, 0, 107, req); |
2131 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1554 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2132 | break; | 1555 | break; |
2133 | |||
2134 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1556 | case FSF_ADAPTER_STATUS_AVAILABLE: |
2135 | /* 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; | 1557 | break; |
2140 | |||
2141 | case FSF_GOOD: | 1558 | case FSF_GOOD: |
2142 | zfcp_erp_modify_port_status(port, 33, fsf_req, | 1559 | zfcp_erp_modify_port_status(port, 33, req, |
2143 | ZFCP_STATUS_COMMON_OPEN, | 1560 | ZFCP_STATUS_COMMON_OPEN, |
2144 | ZFCP_CLEAR); | 1561 | ZFCP_CLEAR); |
2145 | retval = 0; | ||
2146 | break; | 1562 | break; |
2147 | } | 1563 | } |
2148 | 1564 | ||
2149 | skip_fsfstatus: | 1565 | skip_fsfstatus: |
2150 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); | 1566 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); |
2151 | return retval; | ||
2152 | } | 1567 | } |
2153 | 1568 | ||
2154 | /* | 1569 | /** |
2155 | * function: zfcp_fsf_close_physical_port | 1570 | * zfcp_fsf_close_port - create and send close port request |
2156 | * | 1571 | * @erp_action: pointer to struct zfcp_erp_action |
2157 | * purpose: submit FSF command "close physical port" | 1572 | * Returns: 0 on success, error otherwise |
2158 | * | ||
2159 | * returns: address of initiated FSF request | ||
2160 | * NULL - request could not be initiated | ||
2161 | */ | 1573 | */ |
2162 | int | 1574 | int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) |
2163 | zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) | ||
2164 | { | 1575 | { |
2165 | volatile struct qdio_buffer_element *sbale; | 1576 | volatile struct qdio_buffer_element *sbale; |
2166 | struct zfcp_fsf_req *fsf_req; | 1577 | struct zfcp_adapter *adapter = erp_action->adapter; |
2167 | unsigned long lock_flags; | 1578 | struct zfcp_fsf_req *req; |
2168 | int retval = 0; | 1579 | int retval = -EIO; |
2169 | 1580 | ||
2170 | /* setup new FSF request */ | 1581 | spin_lock(&adapter->req_q.lock); |
2171 | retval = zfcp_fsf_req_create(erp_action->adapter, | 1582 | if (zfcp_fsf_req_sbal_get(adapter)) |
2172 | FSF_QTCB_CLOSE_PHYSICAL_PORT, | 1583 | goto out; |
2173 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | 1584 | |
2174 | erp_action->adapter->pool.fsf_req_erp, | 1585 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT, |
2175 | &lock_flags, &fsf_req); | 1586 | ZFCP_REQ_AUTO_CLEANUP, |
2176 | if (retval < 0) | 1587 | adapter->pool.fsf_req_erp); |
1588 | if (unlikely(IS_ERR(req))) { | ||
1589 | retval = PTR_ERR(req); | ||
2177 | goto out; | 1590 | goto out; |
1591 | } | ||
2178 | 1592 | ||
2179 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1593 | sbale = zfcp_qdio_sbale_req(req); |
2180 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1594 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
2181 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1595 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
2182 | 1596 | ||
2183 | /* mark port as being closed */ | 1597 | req->handler = zfcp_fsf_close_port_handler; |
2184 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, | 1598 | req->data = erp_action->port; |
2185 | &erp_action->port->status); | 1599 | req->erp_action = erp_action; |
2186 | /* save a pointer to this port */ | 1600 | req->qtcb->header.port_handle = erp_action->port->handle; |
2187 | fsf_req->data = (unsigned long) erp_action->port; | 1601 | erp_action->fsf_req = req; |
2188 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; | 1602 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); |
2189 | fsf_req->erp_action = erp_action; | 1603 | |
2190 | erp_action->fsf_req = fsf_req; | 1604 | zfcp_erp_start_timer(req); |
2191 | 1605 | retval = zfcp_fsf_req_send(req); | |
2192 | zfcp_erp_start_timer(fsf_req); | ||
2193 | retval = zfcp_fsf_req_send(fsf_req); | ||
2194 | if (retval) { | 1606 | if (retval) { |
2195 | zfcp_fsf_req_free(fsf_req); | 1607 | zfcp_fsf_req_free(req); |
2196 | erp_action->fsf_req = NULL; | 1608 | erp_action->fsf_req = NULL; |
2197 | goto out; | ||
2198 | } | 1609 | } |
2199 | 1610 | out: | |
2200 | out: | 1611 | spin_unlock(&adapter->req_q.lock); |
2201 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); | ||
2202 | return retval; | 1612 | return retval; |
2203 | } | 1613 | } |
2204 | 1614 | ||
2205 | /* | 1615 | static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req) |
2206 | * function: zfcp_fsf_close_physical_port_handler | ||
2207 | * | ||
2208 | * purpose: is called for finished Close Physical Port FSF command | ||
2209 | * | ||
2210 | * returns: | ||
2211 | */ | ||
2212 | static int | ||
2213 | zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req) | ||
2214 | { | 1616 | { |
2215 | int retval = -EINVAL; | 1617 | struct zfcp_port *port = req->data; |
2216 | struct zfcp_port *port; | 1618 | struct fsf_qtcb_header *header = &req->qtcb->header; |
2217 | struct zfcp_unit *unit; | 1619 | struct zfcp_unit *unit; |
2218 | struct fsf_qtcb_header *header; | ||
2219 | |||
2220 | port = (struct zfcp_port *) fsf_req->data; | ||
2221 | header = &fsf_req->qtcb->header; | ||
2222 | 1620 | ||
2223 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | 1621 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
2224 | /* don't change port status in our bookkeeping */ | ||
2225 | goto skip_fsfstatus; | 1622 | goto skip_fsfstatus; |
2226 | } | ||
2227 | 1623 | ||
2228 | /* evaluate FSF status in QTCB */ | ||
2229 | switch (header->fsf_status) { | 1624 | switch (header->fsf_status) { |
2230 | |||
2231 | case FSF_PORT_HANDLE_NOT_VALID: | 1625 | case FSF_PORT_HANDLE_NOT_VALID: |
2232 | zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req); | 1626 | zfcp_erp_adapter_reopen(port->adapter, 0, 108, req); |
2233 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1627 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2234 | break; | 1628 | break; |
2235 | |||
2236 | case FSF_ACCESS_DENIED: | 1629 | case FSF_ACCESS_DENIED: |
2237 | zfcp_fsf_access_denied_port(fsf_req, port); | 1630 | zfcp_fsf_access_denied_port(req, port); |
2238 | break; | 1631 | break; |
2239 | |||
2240 | case FSF_PORT_BOXED: | 1632 | case FSF_PORT_BOXED: |
2241 | zfcp_erp_port_boxed(port, 50, fsf_req); | 1633 | zfcp_erp_port_boxed(port, 50, req); |
2242 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | | 1634 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
2243 | ZFCP_STATUS_FSFREQ_RETRY; | 1635 | ZFCP_STATUS_FSFREQ_RETRY; |
2244 | |||
2245 | /* can't use generic zfcp_erp_modify_port_status because | 1636 | /* can't use generic zfcp_erp_modify_port_status because |
2246 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ | 1637 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */ |
2247 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | 1638 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
@@ -2249,120 +1640,88 @@ zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req) | |||
2249 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, | 1640 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
2250 | &unit->status); | 1641 | &unit->status); |
2251 | break; | 1642 | break; |
2252 | |||
2253 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1643 | case FSF_ADAPTER_STATUS_AVAILABLE: |
2254 | switch (header->fsf_status_qual.word[0]) { | 1644 | switch (header->fsf_status_qual.word[0]) { |
2255 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 1645 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
2256 | /* This will now be escalated by ERP */ | 1646 | /* fall through */ |
2257 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2258 | break; | ||
2259 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 1647 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
2260 | /* ERP strategy will escalate */ | 1648 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2261 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2262 | break; | 1649 | break; |
2263 | } | 1650 | } |
2264 | break; | 1651 | break; |
2265 | |||
2266 | case FSF_GOOD: | 1652 | case FSF_GOOD: |
2267 | /* can't use generic zfcp_erp_modify_port_status because | 1653 | /* can't use generic zfcp_erp_modify_port_status because |
2268 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port | 1654 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port |
2269 | */ | 1655 | */ |
2270 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | 1656 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); |
2271 | list_for_each_entry(unit, &port->unit_list_head, list) | 1657 | list_for_each_entry(unit, &port->unit_list_head, list) |
2272 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); | 1658 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
2273 | retval = 0; | 1659 | &unit->status); |
2274 | break; | 1660 | break; |
2275 | } | 1661 | } |
2276 | 1662 | skip_fsfstatus: | |
2277 | skip_fsfstatus: | ||
2278 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); | 1663 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); |
2279 | return retval; | ||
2280 | } | 1664 | } |
2281 | 1665 | ||
2282 | /* | 1666 | /** |
2283 | * function: zfcp_fsf_open_unit | 1667 | * zfcp_fsf_close_physical_port - close physical port |
2284 | * | 1668 | * @erp_action: pointer to struct zfcp_erp_action |
2285 | * purpose: | 1669 | * Returns: 0 on success |
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 | */ | 1670 | */ |
2294 | int | 1671 | int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) |
2295 | zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) | ||
2296 | { | 1672 | { |
2297 | volatile struct qdio_buffer_element *sbale; | 1673 | volatile struct qdio_buffer_element *sbale; |
2298 | struct zfcp_fsf_req *fsf_req; | 1674 | struct zfcp_adapter *adapter = erp_action->adapter; |
2299 | unsigned long lock_flags; | 1675 | struct zfcp_fsf_req *req; |
2300 | int retval = 0; | 1676 | int retval = -EIO; |
2301 | 1677 | ||
2302 | /* setup new FSF request */ | 1678 | spin_lock(&adapter->req_q.lock); |
2303 | retval = zfcp_fsf_req_create(erp_action->adapter, | 1679 | if (zfcp_fsf_req_sbal_get(adapter)) |
2304 | FSF_QTCB_OPEN_LUN, | ||
2305 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | ||
2306 | erp_action->adapter->pool.fsf_req_erp, | ||
2307 | &lock_flags, &fsf_req); | ||
2308 | if (retval < 0) | ||
2309 | goto out; | 1680 | goto out; |
2310 | 1681 | ||
2311 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1682 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT, |
2312 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1683 | ZFCP_REQ_AUTO_CLEANUP, |
2313 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1684 | adapter->pool.fsf_req_erp); |
1685 | if (unlikely(IS_ERR(req))) { | ||
1686 | retval = PTR_ERR(req); | ||
1687 | goto out; | ||
1688 | } | ||
2314 | 1689 | ||
2315 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; | 1690 | sbale = zfcp_qdio_sbale_req(req); |
2316 | fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; | 1691 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
2317 | if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE)) | 1692 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
2318 | fsf_req->qtcb->bottom.support.option = | 1693 | |
2319 | FSF_OPEN_LUN_SUPPRESS_BOXING; | 1694 | req->data = erp_action->port; |
2320 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); | 1695 | req->qtcb->header.port_handle = erp_action->port->handle; |
2321 | fsf_req->data = (unsigned long) erp_action->unit; | 1696 | req->erp_action = erp_action; |
2322 | fsf_req->erp_action = erp_action; | 1697 | req->handler = zfcp_fsf_close_physical_port_handler; |
2323 | erp_action->fsf_req = fsf_req; | 1698 | erp_action->fsf_req = req; |
1699 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, | ||
1700 | &erp_action->port->status); | ||
2324 | 1701 | ||
2325 | zfcp_erp_start_timer(fsf_req); | 1702 | zfcp_erp_start_timer(req); |
2326 | retval = zfcp_fsf_req_send(erp_action->fsf_req); | 1703 | retval = zfcp_fsf_req_send(req); |
2327 | if (retval) { | 1704 | if (retval) { |
2328 | zfcp_fsf_req_free(fsf_req); | 1705 | zfcp_fsf_req_free(req); |
2329 | erp_action->fsf_req = NULL; | 1706 | erp_action->fsf_req = NULL; |
2330 | goto out; | ||
2331 | } | 1707 | } |
2332 | out: | 1708 | out: |
2333 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); | 1709 | spin_unlock(&adapter->req_q.lock); |
2334 | return retval; | 1710 | return retval; |
2335 | } | 1711 | } |
2336 | 1712 | ||
2337 | /* | 1713 | static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req) |
2338 | * function: zfcp_fsf_open_unit_handler | ||
2339 | * | ||
2340 | * purpose: is called for finished Open LUN command | ||
2341 | * | ||
2342 | * returns: | ||
2343 | */ | ||
2344 | static int | ||
2345 | zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) | ||
2346 | { | 1714 | { |
2347 | int retval = -EINVAL; | 1715 | struct zfcp_adapter *adapter = req->adapter; |
2348 | struct zfcp_adapter *adapter; | 1716 | struct zfcp_unit *unit = req->data; |
2349 | struct zfcp_unit *unit; | 1717 | struct fsf_qtcb_header *header = &req->qtcb->header; |
2350 | struct fsf_qtcb_header *header; | 1718 | struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support; |
2351 | struct fsf_qtcb_bottom_support *bottom; | 1719 | struct fsf_queue_designator *queue_designator = |
2352 | struct fsf_queue_designator *queue_designator; | 1720 | &header->fsf_status_qual.fsf_queue_designator; |
2353 | int exclusive, readwrite; | 1721 | int exclusive, readwrite; |
2354 | 1722 | ||
2355 | unit = (struct zfcp_unit *) fsf_req->data; | 1723 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
2356 | |||
2357 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | ||
2358 | /* don't change unit status in our bookkeeping */ | ||
2359 | goto skip_fsfstatus; | 1724 | 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 | 1725 | ||
2367 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | | 1726 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
2368 | ZFCP_STATUS_COMMON_ACCESS_BOXED | | 1727 | ZFCP_STATUS_COMMON_ACCESS_BOXED | |
@@ -2370,32 +1729,25 @@ zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) | |||
2370 | ZFCP_STATUS_UNIT_READONLY, | 1729 | ZFCP_STATUS_UNIT_READONLY, |
2371 | &unit->status); | 1730 | &unit->status); |
2372 | 1731 | ||
2373 | /* evaluate FSF status in QTCB */ | ||
2374 | switch (header->fsf_status) { | 1732 | switch (header->fsf_status) { |
2375 | 1733 | ||
2376 | case FSF_PORT_HANDLE_NOT_VALID: | 1734 | case FSF_PORT_HANDLE_NOT_VALID: |
2377 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req); | 1735 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req); |
2378 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1736 | /* fall through */ |
2379 | break; | ||
2380 | |||
2381 | case FSF_LUN_ALREADY_OPEN: | 1737 | case FSF_LUN_ALREADY_OPEN: |
2382 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2383 | break; | 1738 | break; |
2384 | |||
2385 | case FSF_ACCESS_DENIED: | 1739 | case FSF_ACCESS_DENIED: |
2386 | zfcp_fsf_access_denied_unit(fsf_req, unit); | 1740 | zfcp_fsf_access_denied_unit(req, unit); |
2387 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); | 1741 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
2388 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); | 1742 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
2389 | break; | 1743 | break; |
2390 | |||
2391 | case FSF_PORT_BOXED: | 1744 | case FSF_PORT_BOXED: |
2392 | zfcp_erp_port_boxed(unit->port, 51, fsf_req); | 1745 | zfcp_erp_port_boxed(unit->port, 51, req); |
2393 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | | 1746 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
2394 | ZFCP_STATUS_FSFREQ_RETRY; | 1747 | ZFCP_STATUS_FSFREQ_RETRY; |
2395 | break; | 1748 | break; |
2396 | |||
2397 | case FSF_LUN_SHARING_VIOLATION: | 1749 | case FSF_LUN_SHARING_VIOLATION: |
2398 | if (header->fsf_status_qual.word[0] != 0) { | 1750 | if (header->fsf_status_qual.word[0]) |
2399 | dev_warn(&adapter->ccw_device->dev, | 1751 | dev_warn(&adapter->ccw_device->dev, |
2400 | "FCP-LUN 0x%Lx at the remote port " | 1752 | "FCP-LUN 0x%Lx at the remote port " |
2401 | "with WWPN 0x%Lx " | 1753 | "with WWPN 0x%Lx " |
@@ -2405,47 +1757,37 @@ zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) | |||
2405 | unit->port->wwpn, | 1757 | unit->port->wwpn, |
2406 | queue_designator->hla, | 1758 | queue_designator->hla, |
2407 | queue_designator->cssid); | 1759 | queue_designator->cssid); |
2408 | } else | 1760 | else |
2409 | zfcp_act_eval_err(adapter, | 1761 | zfcp_act_eval_err(adapter, |
2410 | header->fsf_status_qual.word[2]); | 1762 | header->fsf_status_qual.word[2]); |
2411 | zfcp_erp_unit_access_denied(unit, 60, fsf_req); | 1763 | zfcp_erp_unit_access_denied(unit, 60, req); |
2412 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); | 1764 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); |
2413 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); | 1765 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); |
2414 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1766 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2415 | break; | 1767 | break; |
2416 | |||
2417 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: | 1768 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: |
2418 | dev_warn(&fsf_req->adapter->ccw_device->dev, | 1769 | dev_warn(&adapter->ccw_device->dev, |
2419 | "The adapter ran out of resources. There is no " | 1770 | "The adapter ran out of resources. There is no " |
2420 | "handle available for unit 0x%016Lx on port 0x%016Lx.", | 1771 | "handle available for unit 0x%016Lx on port 0x%016Lx.", |
2421 | unit->fcp_lun, unit->port->wwpn); | 1772 | unit->fcp_lun, unit->port->wwpn); |
2422 | zfcp_erp_unit_failed(unit, 34, fsf_req); | 1773 | zfcp_erp_unit_failed(unit, 34, req); |
2423 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1774 | /* fall through */ |
1775 | case FSF_INVALID_COMMAND_OPTION: | ||
1776 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2424 | break; | 1777 | break; |
2425 | |||
2426 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1778 | case FSF_ADAPTER_STATUS_AVAILABLE: |
2427 | switch (header->fsf_status_qual.word[0]) { | 1779 | switch (header->fsf_status_qual.word[0]) { |
2428 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 1780 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
2429 | /* Re-establish link to port */ | ||
2430 | zfcp_test_link(unit->port); | 1781 | zfcp_test_link(unit->port); |
2431 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1782 | /* fall through */ |
2432 | break; | ||
2433 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 1783 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
2434 | /* ERP strategy will escalate */ | 1784 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2435 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2436 | break; | 1785 | break; |
2437 | } | 1786 | } |
2438 | break; | 1787 | break; |
2439 | 1788 | ||
2440 | case FSF_INVALID_COMMAND_OPTION: | ||
2441 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2442 | retval = -EINVAL; | ||
2443 | break; | ||
2444 | |||
2445 | case FSF_GOOD: | 1789 | case FSF_GOOD: |
2446 | /* save LUN handle assigned by FSF */ | ||
2447 | unit->handle = header->lun_handle; | 1790 | unit->handle = header->lun_handle; |
2448 | /* mark unit as open */ | ||
2449 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); | 1791 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
2450 | 1792 | ||
2451 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && | 1793 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && |
@@ -2463,412 +1805,192 @@ zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) | |||
2463 | if (!readwrite) { | 1805 | if (!readwrite) { |
2464 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, | 1806 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, |
2465 | &unit->status); | 1807 | &unit->status); |
2466 | dev_info(&fsf_req->adapter->ccw_device->dev, | 1808 | dev_info(&adapter->ccw_device->dev, |
2467 | "Read-only access for unit 0x%016Lx " | 1809 | "Read-only access for unit 0x%016Lx " |
2468 | "on port 0x%016Lx.\n", | 1810 | "on port 0x%016Lx.\n", |
2469 | unit->fcp_lun, unit->port->wwpn); | 1811 | unit->fcp_lun, unit->port->wwpn); |
2470 | } | 1812 | } |
2471 | 1813 | ||
2472 | if (exclusive && !readwrite) { | 1814 | if (exclusive && !readwrite) { |
2473 | dev_err(&fsf_req->adapter->ccw_device->dev, | 1815 | dev_err(&adapter->ccw_device->dev, |
2474 | "Exclusive access of read-only unit " | 1816 | "Exclusive access of read-only unit " |
2475 | "0x%016Lx on port 0x%016Lx not " | 1817 | "0x%016Lx on port 0x%016Lx not " |
2476 | "supported, disabling unit.\n", | 1818 | "supported, disabling unit.\n", |
2477 | unit->fcp_lun, unit->port->wwpn); | 1819 | unit->fcp_lun, unit->port->wwpn); |
2478 | zfcp_erp_unit_failed(unit, 35, fsf_req); | 1820 | zfcp_erp_unit_failed(unit, 35, req); |
2479 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1821 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2480 | zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req); | 1822 | zfcp_erp_unit_shutdown(unit, 0, 80, req); |
2481 | } else if (!exclusive && readwrite) { | 1823 | } else if (!exclusive && readwrite) { |
2482 | dev_err(&fsf_req->adapter->ccw_device->dev, | 1824 | dev_err(&adapter->ccw_device->dev, |
2483 | "Shared access of read-write unit " | 1825 | "Shared access of read-write unit " |
2484 | "0x%016Lx on port 0x%016Lx not " | 1826 | "0x%016Lx on port 0x%016Lx not " |
2485 | "supported, disabling unit.\n", | 1827 | "supported, disabling unit.\n", |
2486 | unit->fcp_lun, unit->port->wwpn); | 1828 | unit->fcp_lun, unit->port->wwpn); |
2487 | zfcp_erp_unit_failed(unit, 36, fsf_req); | 1829 | zfcp_erp_unit_failed(unit, 36, req); |
2488 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1830 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2489 | zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req); | 1831 | zfcp_erp_unit_shutdown(unit, 0, 81, req); |
2490 | } | 1832 | } |
2491 | } | 1833 | } |
2492 | |||
2493 | retval = 0; | ||
2494 | break; | 1834 | break; |
2495 | } | 1835 | } |
2496 | 1836 | ||
2497 | skip_fsfstatus: | 1837 | skip_fsfstatus: |
2498 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); | 1838 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); |
2499 | return retval; | ||
2500 | } | 1839 | } |
2501 | 1840 | ||
2502 | /* | 1841 | /** |
2503 | * function: zfcp_fsf_close_unit | 1842 | * zfcp_fsf_open_unit - open unit |
2504 | * | 1843 | * @erp_action: pointer to struct zfcp_erp_action |
2505 | * purpose: | 1844 | * Returns: 0 on success, error otherwise |
2506 | * | ||
2507 | * returns: address of fsf_req - request successfully initiated | ||
2508 | * NULL - | ||
2509 | * | ||
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 | */ | 1845 | */ |
2515 | int | 1846 | int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) |
2516 | zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) | ||
2517 | { | 1847 | { |
2518 | volatile struct qdio_buffer_element *sbale; | 1848 | volatile struct qdio_buffer_element *sbale; |
2519 | struct zfcp_fsf_req *fsf_req; | 1849 | struct zfcp_adapter *adapter = erp_action->adapter; |
2520 | unsigned long lock_flags; | 1850 | struct zfcp_fsf_req *req; |
2521 | int retval = 0; | 1851 | int retval = -EIO; |
2522 | 1852 | ||
2523 | /* setup new FSF request */ | 1853 | spin_lock(&adapter->req_q.lock); |
2524 | retval = zfcp_fsf_req_create(erp_action->adapter, | 1854 | if (zfcp_fsf_req_sbal_get(adapter)) |
2525 | FSF_QTCB_CLOSE_LUN, | 1855 | goto out; |
2526 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | 1856 | |
2527 | erp_action->adapter->pool.fsf_req_erp, | 1857 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN, |
2528 | &lock_flags, &fsf_req); | 1858 | ZFCP_REQ_AUTO_CLEANUP, |
2529 | if (retval < 0) | 1859 | adapter->pool.fsf_req_erp); |
1860 | if (unlikely(IS_ERR(req))) { | ||
1861 | retval = PTR_ERR(req); | ||
2530 | goto out; | 1862 | goto out; |
1863 | } | ||
2531 | 1864 | ||
2532 | sbale = zfcp_qdio_sbale_req(fsf_req); | 1865 | sbale = zfcp_qdio_sbale_req(req); |
2533 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | 1866 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
2534 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1867 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
2535 | 1868 | ||
2536 | fsf_req->qtcb->header.port_handle = erp_action->port->handle; | 1869 | req->qtcb->header.port_handle = erp_action->port->handle; |
2537 | fsf_req->qtcb->header.lun_handle = erp_action->unit->handle; | 1870 | req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun; |
2538 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); | 1871 | req->handler = zfcp_fsf_open_unit_handler; |
2539 | fsf_req->data = (unsigned long) erp_action->unit; | 1872 | req->data = erp_action->unit; |
2540 | fsf_req->erp_action = erp_action; | 1873 | req->erp_action = erp_action; |
2541 | erp_action->fsf_req = fsf_req; | 1874 | erp_action->fsf_req = req; |
1875 | |||
1876 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) | ||
1877 | req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; | ||
2542 | 1878 | ||
2543 | zfcp_erp_start_timer(fsf_req); | 1879 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); |
2544 | retval = zfcp_fsf_req_send(erp_action->fsf_req); | 1880 | |
1881 | zfcp_erp_start_timer(req); | ||
1882 | retval = zfcp_fsf_req_send(req); | ||
2545 | if (retval) { | 1883 | if (retval) { |
2546 | zfcp_fsf_req_free(fsf_req); | 1884 | zfcp_fsf_req_free(req); |
2547 | erp_action->fsf_req = NULL; | 1885 | erp_action->fsf_req = NULL; |
2548 | goto out; | ||
2549 | } | 1886 | } |
2550 | 1887 | out: | |
2551 | out: | 1888 | spin_unlock(&adapter->req_q.lock); |
2552 | write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags); | ||
2553 | return retval; | 1889 | return retval; |
2554 | } | 1890 | } |
2555 | 1891 | ||
2556 | /* | 1892 | static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req) |
2557 | * function: zfcp_fsf_close_unit_handler | ||
2558 | * | ||
2559 | * purpose: is called for finished Close LUN FSF command | ||
2560 | * | ||
2561 | * returns: | ||
2562 | */ | ||
2563 | static int | ||
2564 | zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req) | ||
2565 | { | 1893 | { |
2566 | int retval = -EINVAL; | 1894 | struct zfcp_unit *unit = req->data; |
2567 | struct zfcp_unit *unit; | ||
2568 | 1895 | ||
2569 | unit = (struct zfcp_unit *) fsf_req->data; | 1896 | if (req->status & ZFCP_STATUS_FSFREQ_ERROR) |
2570 | |||
2571 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | ||
2572 | /* don't change unit status in our bookkeeping */ | ||
2573 | goto skip_fsfstatus; | 1897 | goto skip_fsfstatus; |
2574 | } | ||
2575 | |||
2576 | /* evaluate FSF status in QTCB */ | ||
2577 | switch (fsf_req->qtcb->header.fsf_status) { | ||
2578 | 1898 | ||
1899 | switch (req->qtcb->header.fsf_status) { | ||
2579 | case FSF_PORT_HANDLE_NOT_VALID: | 1900 | case FSF_PORT_HANDLE_NOT_VALID: |
2580 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req); | 1901 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req); |
2581 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1902 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2582 | break; | 1903 | break; |
2583 | |||
2584 | case FSF_LUN_HANDLE_NOT_VALID: | 1904 | case FSF_LUN_HANDLE_NOT_VALID: |
2585 | zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req); | 1905 | zfcp_erp_port_reopen(unit->port, 0, 111, req); |
2586 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1906 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2587 | break; | 1907 | break; |
2588 | |||
2589 | case FSF_PORT_BOXED: | 1908 | case FSF_PORT_BOXED: |
2590 | zfcp_erp_port_boxed(unit->port, 52, fsf_req); | 1909 | zfcp_erp_port_boxed(unit->port, 52, req); |
2591 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | | 1910 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
2592 | ZFCP_STATUS_FSFREQ_RETRY; | 1911 | ZFCP_STATUS_FSFREQ_RETRY; |
2593 | break; | 1912 | break; |
2594 | |||
2595 | case FSF_ADAPTER_STATUS_AVAILABLE: | 1913 | case FSF_ADAPTER_STATUS_AVAILABLE: |
2596 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { | 1914 | switch (req->qtcb->header.fsf_status_qual.word[0]) { |
2597 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | 1915 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: |
2598 | /* re-establish link to port */ | ||
2599 | zfcp_test_link(unit->port); | 1916 | zfcp_test_link(unit->port); |
2600 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | 1917 | /* fall through */ |
2601 | break; | ||
2602 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | 1918 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: |
2603 | /* ERP strategy will escalate */ | 1919 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
2604 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2605 | break; | ||
2606 | default: | ||
2607 | break; | 1920 | break; |
2608 | } | 1921 | } |
2609 | break; | 1922 | break; |
2610 | |||
2611 | case FSF_GOOD: | 1923 | case FSF_GOOD: |
2612 | /* mark unit as closed */ | ||
2613 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); | 1924 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); |
2614 | retval = 0; | ||
2615 | break; | 1925 | break; |
2616 | } | 1926 | } |
2617 | 1927 | skip_fsfstatus: | |
2618 | skip_fsfstatus: | ||
2619 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); | 1928 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); |
2620 | return retval; | ||
2621 | } | 1929 | } |
2622 | 1930 | ||
2623 | /** | 1931 | /** |
2624 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) | 1932 | * zfcp_fsf_close_unit - close zfcp unit |
2625 | * @adapter: adapter where scsi command is issued | 1933 | * @erp_action: pointer to struct zfcp_unit |
2626 | * @unit: unit where command is sent to | 1934 | * Returns: 0 on success, error otherwise |
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 | */ | 1935 | */ |
2631 | int | 1936 | int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) |
2632 | zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, | ||
2633 | struct zfcp_unit *unit, | ||
2634 | struct scsi_cmnd * scsi_cmnd, | ||
2635 | int use_timer, int req_flags) | ||
2636 | { | 1937 | { |
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); | ||
2649 | if (unlikely(retval < 0)) | ||
2650 | goto failed_req_create; | ||
2651 | |||
2652 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, | ||
2653 | &unit->status))) { | ||
2654 | retval = -EBUSY; | ||
2655 | goto unit_blocked; | ||
2656 | } | ||
2657 | |||
2658 | zfcp_unit_get(unit); | ||
2659 | fsf_req->unit = unit; | ||
2660 | |||
2661 | /* associate FSF request with SCSI request (for look up on abort) */ | ||
2662 | scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id; | ||
2663 | |||
2664 | /* associate SCSI command with FSF request */ | ||
2665 | fsf_req->data = (unsigned long) scsi_cmnd; | ||
2666 | |||
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: | ||
2683 | 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: | ||
2692 | 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: | ||
2697 | 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: | ||
2702 | 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) */ | ||
2711 | fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT; | ||
2712 | |||
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 */ | ||
2726 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) | ||
2727 | fcp_cmnd_iu->add_fcp_cdb_length | ||
2728 | = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; | ||
2729 | /* | ||
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 */ | ||
2741 | real_bytes = zfcp_qdio_sbals_from_sg(fsf_req, sbtype, | ||
2742 | scsi_sglist(scsi_cmnd), | ||
2743 | ZFCP_MAX_SBALS_PER_REQ); | ||
2744 | if (unlikely(real_bytes < 0)) { | ||
2745 | if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) | ||
2746 | retval = -EIO; | ||
2747 | 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); | ||
2753 | zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req); | ||
2754 | retval = -EINVAL; | ||
2755 | } | ||
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 | |||
2762 | if (use_timer) | ||
2763 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); | ||
2764 | |||
2765 | retval = zfcp_fsf_req_send(fsf_req); | ||
2766 | if (unlikely(retval < 0)) | ||
2767 | goto send_failed; | ||
2768 | |||
2769 | goto success; | ||
2770 | |||
2771 | send_failed: | ||
2772 | no_fit: | ||
2773 | failed_scsi_cmnd: | ||
2774 | zfcp_unit_put(unit); | ||
2775 | unit_blocked: | ||
2776 | zfcp_fsf_req_free(fsf_req); | ||
2777 | fsf_req = NULL; | ||
2778 | scsi_cmnd->host_scribble = NULL; | ||
2779 | success: | ||
2780 | failed_req_create: | ||
2781 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | ||
2782 | return retval; | ||
2783 | } | ||
2784 | |||
2785 | struct zfcp_fsf_req * | ||
2786 | zfcp_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; | 1938 | volatile struct qdio_buffer_element *sbale; |
1939 | struct zfcp_adapter *adapter = erp_action->adapter; | ||
1940 | struct zfcp_fsf_req *req; | ||
1941 | int retval = -EIO; | ||
2795 | 1942 | ||
2796 | /* setup new FSF request */ | 1943 | spin_lock(&adapter->req_q.lock); |
2797 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, | 1944 | if (zfcp_fsf_req_sbal_get(adapter)) |
2798 | adapter->pool.fsf_req_scsi, | ||
2799 | &lock_flags, &fsf_req); | ||
2800 | if (retval < 0) | ||
2801 | goto out; | 1945 | goto out; |
1946 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN, | ||
1947 | ZFCP_REQ_AUTO_CLEANUP, | ||
1948 | adapter->pool.fsf_req_erp); | ||
1949 | if (unlikely(IS_ERR(req))) { | ||
1950 | retval = PTR_ERR(req); | ||
1951 | goto out; | ||
1952 | } | ||
2802 | 1953 | ||
2803 | if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED, | 1954 | sbale = zfcp_qdio_sbale_req(req); |
2804 | &unit->status))) | 1955 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; |
2805 | goto unit_blocked; | ||
2806 | |||
2807 | /* | ||
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 | */ | ||
2818 | fsf_req->data = (unsigned long) unit; | ||
2819 | |||
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; | ||
2824 | fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT; | ||
2825 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = | ||
2826 | sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t); | ||
2827 | |||
2828 | sbale = zfcp_qdio_sbale_req(fsf_req); | ||
2829 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; | ||
2830 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | 1956 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; |
2831 | 1957 | ||
2832 | /* set FCP related fields in FCP_CMND IU in QTCB */ | 1958 | req->qtcb->header.port_handle = erp_action->port->handle; |
2833 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) | 1959 | req->qtcb->header.lun_handle = erp_action->unit->handle; |
2834 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); | 1960 | req->handler = zfcp_fsf_close_unit_handler; |
2835 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; | 1961 | req->data = erp_action->unit; |
2836 | fcp_cmnd_iu->task_management_flags = tm_flags; | 1962 | req->erp_action = erp_action; |
2837 | 1963 | erp_action->fsf_req = req; | |
2838 | zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT); | 1964 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); |
2839 | retval = zfcp_fsf_req_send(fsf_req); | ||
2840 | if (!retval) | ||
2841 | goto out; | ||
2842 | |||
2843 | unit_blocked: | ||
2844 | zfcp_fsf_req_free(fsf_req); | ||
2845 | fsf_req = NULL; | ||
2846 | 1965 | ||
2847 | out: | 1966 | zfcp_erp_start_timer(req); |
2848 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | 1967 | retval = zfcp_fsf_req_send(req); |
2849 | return fsf_req; | 1968 | if (retval) { |
1969 | zfcp_fsf_req_free(req); | ||
1970 | erp_action->fsf_req = NULL; | ||
1971 | } | ||
1972 | out: | ||
1973 | spin_unlock(&adapter->req_q.lock); | ||
1974 | return retval; | ||
2850 | } | 1975 | } |
2851 | 1976 | ||
2852 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) | 1977 | static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat) |
2853 | { | 1978 | { |
2854 | lat_rec->sum += lat; | 1979 | lat_rec->sum += lat; |
2855 | if (lat_rec->min > lat) | 1980 | lat_rec->min = min(lat_rec->min, lat); |
2856 | lat_rec->min = lat; | 1981 | lat_rec->max = max(lat_rec->max, lat); |
2857 | if (lat_rec->max < lat) | ||
2858 | lat_rec->max = lat; | ||
2859 | } | 1982 | } |
2860 | 1983 | ||
2861 | static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req) | 1984 | static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req) |
2862 | { | 1985 | { |
2863 | struct fsf_qual_latency_info *lat_inf; | 1986 | struct fsf_qual_latency_info *lat_inf; |
2864 | struct latency_cont *lat; | 1987 | struct latency_cont *lat; |
2865 | struct zfcp_unit *unit; | 1988 | struct zfcp_unit *unit = req->unit; |
2866 | unsigned long flags; | 1989 | unsigned long flags; |
2867 | 1990 | ||
2868 | lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info; | 1991 | lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info; |
2869 | unit = fsf_req->unit; | ||
2870 | 1992 | ||
2871 | switch (fsf_req->qtcb->bottom.io.data_direction) { | 1993 | switch (req->qtcb->bottom.io.data_direction) { |
2872 | case FSF_DATADIR_READ: | 1994 | case FSF_DATADIR_READ: |
2873 | lat = &unit->latencies.read; | 1995 | lat = &unit->latencies.read; |
2874 | break; | 1996 | break; |
@@ -2889,209 +2011,50 @@ static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req) | |||
2889 | spin_unlock_irqrestore(&unit->latencies.lock, flags); | 2011 | spin_unlock_irqrestore(&unit->latencies.lock, flags); |
2890 | } | 2012 | } |
2891 | 2013 | ||
2892 | /* | 2014 | static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req) |
2893 | * function: zfcp_fsf_send_fcp_command_handler | ||
2894 | * | ||
2895 | * purpose: is called for finished Send FCP Command | ||
2896 | * | ||
2897 | * returns: | ||
2898 | */ | ||
2899 | static int | ||
2900 | zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req) | ||
2901 | { | 2015 | { |
2902 | int retval = -EINVAL; | 2016 | struct scsi_cmnd *scpnt = req->data; |
2903 | struct zfcp_unit *unit; | ||
2904 | struct fsf_qtcb_header *header; | ||
2905 | |||
2906 | header = &fsf_req->qtcb->header; | ||
2907 | |||
2908 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) | ||
2909 | unit = (struct zfcp_unit *) fsf_req->data; | ||
2910 | else | ||
2911 | unit = fsf_req->unit; | ||
2912 | |||
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: | ||
2922 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req); | ||
2923 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2924 | break; | ||
2925 | |||
2926 | case FSF_LUN_HANDLE_NOT_VALID: | ||
2927 | zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req); | ||
2928 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2929 | break; | ||
2930 | |||
2931 | case FSF_HANDLE_MISMATCH: | ||
2932 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req); | ||
2933 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2934 | break; | ||
2935 | |||
2936 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: | ||
2937 | zfcp_fsf_class_not_supp(fsf_req); | ||
2938 | break; | ||
2939 | |||
2940 | case FSF_FCPLUN_NOT_VALID: | ||
2941 | zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req); | ||
2942 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2943 | break; | ||
2944 | |||
2945 | case FSF_ACCESS_DENIED: | ||
2946 | zfcp_fsf_access_denied_unit(fsf_req, unit); | ||
2947 | break; | ||
2948 | |||
2949 | case FSF_DIRECTION_INDICATOR_NOT_VALID: | ||
2950 | 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); | ||
2955 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req); | ||
2956 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2957 | break; | ||
2958 | |||
2959 | case FSF_CMND_LENGTH_NOT_VALID: | ||
2960 | 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); | ||
2966 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req); | ||
2967 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2968 | break; | ||
2969 | |||
2970 | case FSF_PORT_BOXED: | ||
2971 | zfcp_erp_port_boxed(unit->port, 53, fsf_req); | ||
2972 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | | ||
2973 | ZFCP_STATUS_FSFREQ_RETRY; | ||
2974 | break; | ||
2975 | |||
2976 | case FSF_LUN_BOXED: | ||
2977 | zfcp_erp_unit_boxed(unit, 54, fsf_req); | ||
2978 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | ||
2979 | | ZFCP_STATUS_FSFREQ_RETRY; | ||
2980 | break; | ||
2981 | |||
2982 | case FSF_ADAPTER_STATUS_AVAILABLE: | ||
2983 | switch (header->fsf_status_qual.word[0]) { | ||
2984 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | ||
2985 | /* re-establish link to port */ | ||
2986 | zfcp_test_link(unit->port); | ||
2987 | break; | ||
2988 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | ||
2989 | /* FIXME(hw) need proper specs for proper action */ | ||
2990 | /* let scsi stack deal with retries and escalation */ | ||
2991 | break; | ||
2992 | } | ||
2993 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2994 | break; | ||
2995 | |||
2996 | case FSF_GOOD: | ||
2997 | break; | ||
2998 | |||
2999 | case FSF_FCP_RSP_AVAILABLE: | ||
3000 | break; | ||
3001 | } | ||
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); | ||
3009 | fsf_req->unit = NULL; | ||
3010 | zfcp_unit_put(unit); | ||
3011 | } | ||
3012 | return retval; | ||
3013 | } | ||
3014 | |||
3015 | /* | ||
3016 | * function: zfcp_fsf_send_fcp_command_task_handler | ||
3017 | * | ||
3018 | * purpose: evaluates FCP_RSP IU | ||
3019 | * | ||
3020 | * returns: | ||
3021 | */ | ||
3022 | static int | ||
3023 | zfcp_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 *) | 2017 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
3028 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | 2018 | &(req->qtcb->bottom.io.fcp_rsp); |
3029 | u32 sns_len; | 2019 | u32 sns_len; |
3030 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; | 2020 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
3031 | unsigned long flags; | 2021 | unsigned long flags; |
3032 | 2022 | ||
3033 | read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); | ||
3034 | scpnt = (struct scsi_cmnd *) fsf_req->data; | ||
3035 | if (unlikely(!scpnt)) | 2023 | if (unlikely(!scpnt)) |
3036 | goto out; | 2024 | return; |
3037 | 2025 | ||
3038 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { | 2026 | read_lock_irqsave(&req->adapter->abort_lock, flags); |
3039 | /* FIXME: (design) mid-layer should handle DID_ABORT like | 2027 | |
3040 | * DID_SOFT_ERROR by retrying the request for devices | 2028 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { |
3041 | * that allow retries. | ||
3042 | */ | ||
3043 | set_host_byte(scpnt, DID_SOFT_ERROR); | 2029 | set_host_byte(scpnt, DID_SOFT_ERROR); |
3044 | set_driver_byte(scpnt, SUGGEST_RETRY); | 2030 | set_driver_byte(scpnt, SUGGEST_RETRY); |
3045 | goto skip_fsfstatus; | 2031 | goto skip_fsfstatus; |
3046 | } | 2032 | } |
3047 | 2033 | ||
3048 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { | 2034 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) { |
3049 | set_host_byte(scpnt, DID_ERROR); | 2035 | set_host_byte(scpnt, DID_ERROR); |
3050 | goto skip_fsfstatus; | 2036 | goto skip_fsfstatus; |
3051 | } | 2037 | } |
3052 | 2038 | ||
3053 | /* set message byte of result in SCSI command */ | ||
3054 | set_msg_byte(scpnt, COMMAND_COMPLETE); | 2039 | set_msg_byte(scpnt, COMMAND_COMPLETE); |
3055 | 2040 | ||
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; | 2041 | scpnt->result |= fcp_rsp_iu->scsi_status; |
3061 | 2042 | ||
3062 | if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) | 2043 | if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) |
3063 | zfcp_fsf_req_latency(fsf_req); | 2044 | zfcp_fsf_req_latency(req); |
3064 | 2045 | ||
3065 | /* check FCP_RSP_INFO */ | ||
3066 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { | 2046 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { |
3067 | switch (fcp_rsp_info[3]) { | 2047 | if (fcp_rsp_info[3] == RSP_CODE_GOOD) |
3068 | case RSP_CODE_GOOD: | ||
3069 | /* ok, continue */ | ||
3070 | set_host_byte(scpnt, DID_OK); | 2048 | set_host_byte(scpnt, DID_OK); |
3071 | break; | 2049 | else { |
3072 | case RSP_CODE_LENGTH_MISMATCH: | ||
3073 | /* hardware bug */ | ||
3074 | set_host_byte(scpnt, DID_ERROR); | ||
3075 | goto skip_fsfstatus; | ||
3076 | case RSP_CODE_FIELD_INVALID: | ||
3077 | /* driver or hardware bug */ | ||
3078 | set_host_byte(scpnt, DID_ERROR); | ||
3079 | goto skip_fsfstatus; | ||
3080 | case RSP_CODE_RO_MISMATCH: | ||
3081 | /* hardware bug */ | ||
3082 | set_host_byte(scpnt, DID_ERROR); | ||
3083 | goto skip_fsfstatus; | ||
3084 | default: | ||
3085 | /* invalid FCP response code */ | ||
3086 | set_host_byte(scpnt, DID_ERROR); | 2050 | set_host_byte(scpnt, DID_ERROR); |
3087 | goto skip_fsfstatus; | 2051 | goto skip_fsfstatus; |
3088 | } | 2052 | } |
3089 | } | 2053 | } |
3090 | 2054 | ||
3091 | /* check for sense data */ | ||
3092 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { | 2055 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { |
3093 | sns_len = FSF_FCP_RSP_SIZE - | 2056 | sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) + |
3094 | sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len; | 2057 | fcp_rsp_iu->fcp_rsp_len; |
3095 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); | 2058 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); |
3096 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); | 2059 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); |
3097 | 2060 | ||
@@ -3099,382 +2062,372 @@ zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req) | |||
3099 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); | 2062 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); |
3100 | } | 2063 | } |
3101 | 2064 | ||
3102 | /* check for underrun */ | ||
3103 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { | 2065 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { |
3104 | scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); | 2066 | scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid); |
3105 | if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < | 2067 | if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) < |
3106 | scpnt->underflow) | 2068 | scpnt->underflow) |
3107 | set_host_byte(scpnt, DID_ERROR); | 2069 | set_host_byte(scpnt, DID_ERROR); |
3108 | } | 2070 | } |
3109 | 2071 | skip_fsfstatus: | |
3110 | skip_fsfstatus: | ||
3111 | if (scpnt->result != 0) | 2072 | if (scpnt->result != 0) |
3112 | zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req); | 2073 | zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req); |
3113 | else if (scpnt->retries > 0) | 2074 | else if (scpnt->retries > 0) |
3114 | zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req); | 2075 | zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req); |
3115 | else | 2076 | else |
3116 | zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req); | 2077 | zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req); |
3117 | 2078 | ||
3118 | /* cleanup pointer (need this especially for abort) */ | ||
3119 | scpnt->host_scribble = NULL; | 2079 | scpnt->host_scribble = NULL; |
3120 | |||
3121 | /* always call back */ | ||
3122 | (scpnt->scsi_done) (scpnt); | 2080 | (scpnt->scsi_done) (scpnt); |
3123 | |||
3124 | /* | 2081 | /* |
3125 | * We must hold this lock until scsi_done has been called. | 2082 | * We must hold this lock until scsi_done has been called. |
3126 | * Otherwise we may call scsi_done after abort regarding this | 2083 | * Otherwise we may call scsi_done after abort regarding this |
3127 | * command has completed. | 2084 | * command has completed. |
3128 | * Note: scsi_done must not block! | 2085 | * Note: scsi_done must not block! |
3129 | */ | 2086 | */ |
3130 | out: | 2087 | read_unlock_irqrestore(&req->adapter->abort_lock, flags); |
3131 | read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags); | ||
3132 | return retval; | ||
3133 | } | 2088 | } |
3134 | 2089 | ||
3135 | /* | 2090 | static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req) |
3136 | * function: zfcp_fsf_send_fcp_command_task_management_handler | ||
3137 | * | ||
3138 | * purpose: evaluates FCP_RSP IU | ||
3139 | * | ||
3140 | * returns: | ||
3141 | */ | ||
3142 | static int | ||
3143 | zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req) | ||
3144 | { | 2091 | { |
3145 | int retval = 0; | ||
3146 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) | 2092 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
3147 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | 2093 | &(req->qtcb->bottom.io.fcp_rsp); |
3148 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; | 2094 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
3149 | 2095 | ||
3150 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | 2096 | if ((fcp_rsp_info[3] != RSP_CODE_GOOD) || |
3151 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | 2097 | (req->status & ZFCP_STATUS_FSFREQ_ERROR)) |
2098 | req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | ||
2099 | } | ||
2100 | |||
2101 | |||
2102 | static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req) | ||
2103 | { | ||
2104 | struct zfcp_unit *unit; | ||
2105 | struct fsf_qtcb_header *header = &req->qtcb->header; | ||
2106 | |||
2107 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) | ||
2108 | unit = req->data; | ||
2109 | else | ||
2110 | unit = req->unit; | ||
2111 | |||
2112 | if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) | ||
3152 | goto skip_fsfstatus; | 2113 | goto skip_fsfstatus; |
3153 | } | ||
3154 | 2114 | ||
3155 | /* check FCP_RSP_INFO */ | 2115 | switch (header->fsf_status) { |
3156 | switch (fcp_rsp_info[3]) { | 2116 | case FSF_HANDLE_MISMATCH: |
3157 | case RSP_CODE_GOOD: | 2117 | case FSF_PORT_HANDLE_NOT_VALID: |
3158 | /* ok, continue */ | 2118 | zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req); |
2119 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
3159 | break; | 2120 | break; |
3160 | case RSP_CODE_TASKMAN_UNSUPP: | 2121 | case FSF_FCPLUN_NOT_VALID: |
3161 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP; | 2122 | case FSF_LUN_HANDLE_NOT_VALID: |
2123 | zfcp_erp_port_reopen(unit->port, 0, 113, req); | ||
2124 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
3162 | break; | 2125 | break; |
3163 | case RSP_CODE_TASKMAN_FAILED: | 2126 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: |
3164 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | 2127 | zfcp_fsf_class_not_supp(req); |
2128 | break; | ||
2129 | case FSF_ACCESS_DENIED: | ||
2130 | zfcp_fsf_access_denied_unit(req, unit); | ||
2131 | break; | ||
2132 | case FSF_DIRECTION_INDICATOR_NOT_VALID: | ||
2133 | dev_err(&req->adapter->ccw_device->dev, | ||
2134 | "Invalid data direction (%d) given for unit " | ||
2135 | "0x%016Lx on port 0x%016Lx, shutting down " | ||
2136 | "adapter.\n", | ||
2137 | req->qtcb->bottom.io.data_direction, | ||
2138 | unit->fcp_lun, unit->port->wwpn); | ||
2139 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req); | ||
2140 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2141 | break; | ||
2142 | case FSF_CMND_LENGTH_NOT_VALID: | ||
2143 | dev_err(&req->adapter->ccw_device->dev, | ||
2144 | "An invalid control-data-block length field (%d) " | ||
2145 | "was found in a command for unit 0x%016Lx on port " | ||
2146 | "0x%016Lx. Shutting down adapter.\n", | ||
2147 | req->qtcb->bottom.io.fcp_cmnd_length, | ||
2148 | unit->fcp_lun, unit->port->wwpn); | ||
2149 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req); | ||
2150 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
2151 | break; | ||
2152 | case FSF_PORT_BOXED: | ||
2153 | zfcp_erp_port_boxed(unit->port, 53, req); | ||
2154 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | | ||
2155 | ZFCP_STATUS_FSFREQ_RETRY; | ||
2156 | break; | ||
2157 | case FSF_LUN_BOXED: | ||
2158 | zfcp_erp_unit_boxed(unit, 54, req); | ||
2159 | req->status |= ZFCP_STATUS_FSFREQ_ERROR | | ||
2160 | ZFCP_STATUS_FSFREQ_RETRY; | ||
2161 | break; | ||
2162 | case FSF_ADAPTER_STATUS_AVAILABLE: | ||
2163 | if (header->fsf_status_qual.word[0] == | ||
2164 | FSF_SQ_INVOKE_LINK_TEST_PROCEDURE) | ||
2165 | zfcp_test_link(unit->port); | ||
2166 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
3165 | break; | 2167 | break; |
3166 | default: | ||
3167 | /* invalid FCP response code */ | ||
3168 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | ||
3169 | } | 2168 | } |
3170 | 2169 | skip_fsfstatus: | |
3171 | skip_fsfstatus: | 2170 | if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) |
3172 | return retval; | 2171 | zfcp_fsf_send_fcp_ctm_handler(req); |
2172 | else { | ||
2173 | zfcp_fsf_send_fcp_command_task_handler(req); | ||
2174 | req->unit = NULL; | ||
2175 | zfcp_unit_put(unit); | ||
2176 | } | ||
3173 | } | 2177 | } |
3174 | 2178 | ||
3175 | 2179 | /** | |
3176 | /* | 2180 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) |
3177 | * function: zfcp_fsf_control_file | 2181 | * @adapter: adapter where scsi command is issued |
3178 | * | 2182 | * @unit: unit where command is sent to |
3179 | * purpose: Initiator of the control file upload/download FSF requests | 2183 | * @scsi_cmnd: scsi command to be sent |
3180 | * | 2184 | * @timer: timer to be started when request is initiated |
3181 | * returns: 0 - FSF request is successfuly created and queued | 2185 | * @req_flags: flags for fsf_request |
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 | */ | 2186 | */ |
3187 | struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter, | 2187 | int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, |
3188 | struct zfcp_fsf_cfdc *fsf_cfdc) | 2188 | struct zfcp_unit *unit, |
2189 | struct scsi_cmnd *scsi_cmnd, | ||
2190 | int use_timer, int req_flags) | ||
3189 | { | 2191 | { |
3190 | struct zfcp_fsf_req *fsf_req; | 2192 | struct zfcp_fsf_req *req; |
3191 | struct fsf_qtcb_bottom_support *bottom; | 2193 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
3192 | volatile struct qdio_buffer_element *sbale; | 2194 | unsigned int sbtype; |
3193 | unsigned long lock_flags; | 2195 | int real_bytes, retval = -EIO; |
3194 | int direction; | ||
3195 | int retval; | ||
3196 | int bytes; | ||
3197 | 2196 | ||
3198 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) | 2197 | if (unlikely(!(atomic_read(&unit->status) & |
3199 | return ERR_PTR(-EOPNOTSUPP); | 2198 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
2199 | return -EBUSY; | ||
3200 | 2200 | ||
3201 | switch (fsf_cfdc->command) { | 2201 | spin_lock(&adapter->req_q.lock); |
3202 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | 2202 | if (!atomic_read(&adapter->req_q.count)) |
3203 | direction = SBAL_FLAGS0_TYPE_WRITE; | 2203 | goto out; |
2204 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, | ||
2205 | adapter->pool.fsf_req_scsi); | ||
2206 | if (unlikely(IS_ERR(req))) { | ||
2207 | retval = PTR_ERR(req); | ||
2208 | goto out; | ||
2209 | } | ||
2210 | |||
2211 | zfcp_unit_get(unit); | ||
2212 | req->unit = unit; | ||
2213 | req->data = scsi_cmnd; | ||
2214 | req->handler = zfcp_fsf_send_fcp_command_handler; | ||
2215 | req->qtcb->header.lun_handle = unit->handle; | ||
2216 | req->qtcb->header.port_handle = unit->port->handle; | ||
2217 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; | ||
2218 | |||
2219 | scsi_cmnd->host_scribble = (unsigned char *) req->req_id; | ||
2220 | |||
2221 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd); | ||
2222 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; | ||
2223 | /* | ||
2224 | * set depending on data direction: | ||
2225 | * data direction bits in SBALE (SB Type) | ||
2226 | * data direction bits in QTCB | ||
2227 | * data direction bits in FCP_CMND IU | ||
2228 | */ | ||
2229 | switch (scsi_cmnd->sc_data_direction) { | ||
2230 | case DMA_NONE: | ||
2231 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; | ||
2232 | sbtype = SBAL_FLAGS0_TYPE_READ; | ||
3204 | break; | 2233 | break; |
3205 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | 2234 | case DMA_FROM_DEVICE: |
3206 | direction = SBAL_FLAGS0_TYPE_READ; | 2235 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; |
2236 | sbtype = SBAL_FLAGS0_TYPE_READ; | ||
2237 | fcp_cmnd_iu->rddata = 1; | ||
2238 | break; | ||
2239 | case DMA_TO_DEVICE: | ||
2240 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; | ||
2241 | sbtype = SBAL_FLAGS0_TYPE_WRITE; | ||
2242 | fcp_cmnd_iu->wddata = 1; | ||
3207 | break; | 2243 | break; |
2244 | case DMA_BIDIRECTIONAL: | ||
3208 | default: | 2245 | default: |
3209 | return ERR_PTR(-EINVAL); | 2246 | retval = -EIO; |
2247 | goto failed_scsi_cmnd; | ||
3210 | } | 2248 | } |
3211 | 2249 | ||
3212 | retval = zfcp_fsf_req_create(adapter, fsf_cfdc->command, | 2250 | if (likely((scsi_cmnd->device->simple_tags) || |
3213 | ZFCP_WAIT_FOR_SBAL, | 2251 | ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) && |
3214 | NULL, &lock_flags, &fsf_req); | 2252 | (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED)))) |
3215 | if (retval < 0) { | 2253 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; |
3216 | retval = -EPERM; | 2254 | else |
3217 | goto unlock_queue_lock; | 2255 | fcp_cmnd_iu->task_attribute = UNTAGGED; |
3218 | } | ||
3219 | 2256 | ||
3220 | sbale = zfcp_qdio_sbale_req(fsf_req); | 2257 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) |
3221 | sbale[0].flags |= direction; | 2258 | fcp_cmnd_iu->add_fcp_cdb_length = |
2259 | (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; | ||
3222 | 2260 | ||
3223 | bottom = &fsf_req->qtcb->bottom.support; | 2261 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); |
3224 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; | ||
3225 | bottom->option = fsf_cfdc->option; | ||
3226 | 2262 | ||
3227 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction, | 2263 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + |
3228 | fsf_cfdc->sg, | 2264 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t); |
3229 | ZFCP_MAX_SBALS_PER_REQ); | ||
3230 | if (bytes != ZFCP_CFDC_MAX_SIZE) { | ||
3231 | retval = -ENOMEM; | ||
3232 | goto free_fsf_req; | ||
3233 | } | ||
3234 | 2265 | ||
3235 | zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT); | 2266 | real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype, |
3236 | retval = zfcp_fsf_req_send(fsf_req); | 2267 | scsi_sglist(scsi_cmnd), |
3237 | if (retval < 0) { | 2268 | FSF_MAX_SBALS_PER_REQ); |
3238 | retval = -EPERM; | 2269 | if (unlikely(real_bytes < 0)) { |
3239 | goto free_fsf_req; | 2270 | if (req->sbal_number < FSF_MAX_SBALS_PER_REQ) |
2271 | retval = -EIO; | ||
2272 | else { | ||
2273 | dev_err(&adapter->ccw_device->dev, | ||
2274 | "SCSI request too large. " | ||
2275 | "Shutting down unit 0x%016Lx on port " | ||
2276 | "0x%016Lx.\n", unit->fcp_lun, | ||
2277 | unit->port->wwpn); | ||
2278 | zfcp_erp_unit_shutdown(unit, 0, 131, req); | ||
2279 | retval = -EINVAL; | ||
2280 | } | ||
2281 | goto failed_scsi_cmnd; | ||
3240 | } | 2282 | } |
3241 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | ||
3242 | |||
3243 | wait_event(fsf_req->completion_wq, | ||
3244 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | ||
3245 | 2283 | ||
3246 | return fsf_req; | 2284 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); |
3247 | 2285 | ||
3248 | free_fsf_req: | 2286 | if (use_timer) |
3249 | zfcp_fsf_req_free(fsf_req); | 2287 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); |
3250 | unlock_queue_lock: | ||
3251 | write_unlock_irqrestore(&adapter->req_q.lock, lock_flags); | ||
3252 | return ERR_PTR(retval); | ||
3253 | } | ||
3254 | 2288 | ||
3255 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req) | 2289 | retval = zfcp_fsf_req_send(req); |
3256 | { | 2290 | if (unlikely(retval)) |
3257 | if (fsf_req->qtcb->header.fsf_status != FSF_GOOD) | 2291 | goto failed_scsi_cmnd; |
3258 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | ||
3259 | } | ||
3260 | 2292 | ||
3261 | static inline int | 2293 | goto out; |
3262 | zfcp_fsf_req_sbal_check(unsigned long *flags, | ||
3263 | struct zfcp_qdio_queue *queue, int needed) | ||
3264 | { | ||
3265 | write_lock_irqsave(&queue->lock, *flags); | ||
3266 | if (likely(atomic_read(&queue->count) >= needed)) | ||
3267 | return 1; | ||
3268 | write_unlock_irqrestore(&queue->lock, *flags); | ||
3269 | return 0; | ||
3270 | } | ||
3271 | 2294 | ||
3272 | /* | 2295 | failed_scsi_cmnd: |
3273 | * set qtcb pointer in fsf_req and initialize QTCB | 2296 | zfcp_unit_put(unit); |
3274 | */ | 2297 | zfcp_fsf_req_free(req); |
3275 | static void | 2298 | scsi_cmnd->host_scribble = NULL; |
3276 | zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req) | 2299 | out: |
3277 | { | 2300 | spin_unlock(&adapter->req_q.lock); |
3278 | if (likely(fsf_req->qtcb != NULL)) { | 2301 | return retval; |
3279 | 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; | ||
3282 | fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION; | ||
3283 | fsf_req->qtcb->prefix.qtcb_type = | ||
3284 | fsf_qtcb_type[fsf_req->fsf_command]; | ||
3285 | fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION; | ||
3286 | fsf_req->qtcb->header.req_handle = fsf_req->req_id; | ||
3287 | fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command; | ||
3288 | } | ||
3289 | } | 2302 | } |
3290 | 2303 | ||
3291 | /** | 2304 | /** |
3292 | * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue | 2305 | * zfcp_fsf_send_fcp_ctm - send SCSI task management command |
3293 | * @adapter: adapter for which request queue is examined | 2306 | * @adapter: pointer to struct zfcp-adapter |
3294 | * @req_flags: flags indicating whether to wait for needed SBAL or not | 2307 | * @unit: pointer to struct zfcp_unit |
3295 | * @lock_flags: lock_flags if queue_lock is taken | 2308 | * @tm_flags: unsigned byte for task management flags |
3296 | * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS | 2309 | * @req_flags: int request flags |
3297 | * Locks: lock adapter->req_q->lock on success | 2310 | * Returns: on success pointer to struct fsf_req, NULL otherwise |
3298 | */ | ||
3299 | static int | ||
3300 | zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags, | ||
3301 | unsigned long *lock_flags) | ||
3302 | { | ||
3303 | long ret; | ||
3304 | struct zfcp_qdio_queue *req_q = &adapter->req_q; | ||
3305 | |||
3306 | if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) { | ||
3307 | ret = wait_event_interruptible_timeout(adapter->request_wq, | ||
3308 | zfcp_fsf_req_sbal_check(lock_flags, req_q, 1), | ||
3309 | ZFCP_SBAL_TIMEOUT); | ||
3310 | if (ret < 0) | ||
3311 | return ret; | ||
3312 | if (!ret) | ||
3313 | return -EIO; | ||
3314 | } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_q, 1)) | ||
3315 | 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 | */ | 2311 | */ |
3336 | int | 2312 | struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter, |
3337 | zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags, | 2313 | struct zfcp_unit *unit, |
3338 | mempool_t *pool, unsigned long *lock_flags, | 2314 | u8 tm_flags, int req_flags) |
3339 | struct zfcp_fsf_req **fsf_req_p) | ||
3340 | { | 2315 | { |
3341 | volatile struct qdio_buffer_element *sbale; | 2316 | volatile struct qdio_buffer_element *sbale; |
3342 | struct zfcp_fsf_req *fsf_req = NULL; | 2317 | struct zfcp_fsf_req *req = NULL; |
3343 | int ret = 0; | 2318 | struct fcp_cmnd_iu *fcp_cmnd_iu; |
3344 | struct zfcp_qdio_queue *req_q = &adapter->req_q; | ||
3345 | |||
3346 | /* allocate new FSF request */ | ||
3347 | fsf_req = zfcp_fsf_req_alloc(pool, req_flags); | ||
3348 | if (unlikely(!fsf_req)) { | ||
3349 | ret = -ENOMEM; | ||
3350 | goto failed_fsf_req; | ||
3351 | } | ||
3352 | |||
3353 | fsf_req->adapter = adapter; | ||
3354 | fsf_req->fsf_command = fsf_cmd; | ||
3355 | INIT_LIST_HEAD(&fsf_req->list); | ||
3356 | init_timer(&fsf_req->timer); | ||
3357 | |||
3358 | /* initialize waitqueue which may be used to wait on | ||
3359 | this request completion */ | ||
3360 | init_waitqueue_head(&fsf_req->completion_wq); | ||
3361 | |||
3362 | ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags); | ||
3363 | if (ret < 0) | ||
3364 | goto failed_sbals; | ||
3365 | |||
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); | ||
3372 | |||
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)) { | ||
3379 | write_unlock_irqrestore(&req_q->lock, *lock_flags); | ||
3380 | ret = -EIO; | ||
3381 | goto failed_sbals; | ||
3382 | } | ||
3383 | 2319 | ||
3384 | if (fsf_req->qtcb) { | 2320 | if (unlikely(!(atomic_read(&unit->status) & |
3385 | fsf_req->seq_no = adapter->fsf_req_seq_no; | 2321 | ZFCP_STATUS_COMMON_UNBLOCKED))) |
3386 | fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; | 2322 | return NULL; |
3387 | } | ||
3388 | fsf_req->sbal_number = 1; | ||
3389 | fsf_req->sbal_first = req_q->first; | ||
3390 | fsf_req->sbal_last = req_q->first; | ||
3391 | fsf_req->sbale_curr = 1; | ||
3392 | 2323 | ||
3393 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) { | 2324 | spin_lock(&adapter->req_q.lock); |
3394 | fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; | 2325 | if (!atomic_read(&adapter->req_q.count)) |
3395 | } | 2326 | goto out; |
2327 | req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, | ||
2328 | adapter->pool.fsf_req_scsi); | ||
2329 | if (unlikely(IS_ERR(req))) | ||
2330 | goto out; | ||
3396 | 2331 | ||
3397 | sbale = zfcp_qdio_sbale_req(fsf_req); | 2332 | req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; |
2333 | req->data = unit; | ||
2334 | req->handler = zfcp_fsf_send_fcp_command_handler; | ||
2335 | req->qtcb->header.lun_handle = unit->handle; | ||
2336 | req->qtcb->header.port_handle = unit->port->handle; | ||
2337 | req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; | ||
2338 | req->qtcb->bottom.io.service_class = FSF_CLASS_3; | ||
2339 | req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) + | ||
2340 | sizeof(fcp_dl_t); | ||
2341 | |||
2342 | sbale = zfcp_qdio_sbale_req(req); | ||
2343 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; | ||
2344 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | ||
3398 | 2345 | ||
3399 | /* setup common SBALE fields */ | 2346 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd; |
3400 | sbale[0].addr = (void *) fsf_req->req_id; | 2347 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; |
3401 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; | 2348 | fcp_cmnd_iu->task_management_flags = tm_flags; |
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 | 2349 | ||
3407 | goto success; | 2350 | zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT); |
2351 | if (!zfcp_fsf_req_send(req)) | ||
2352 | goto out; | ||
3408 | 2353 | ||
3409 | failed_sbals: | 2354 | zfcp_fsf_req_free(req); |
3410 | /* dequeue new FSF request previously enqueued */ | 2355 | req = NULL; |
3411 | zfcp_fsf_req_free(fsf_req); | 2356 | out: |
3412 | fsf_req = NULL; | 2357 | spin_unlock(&adapter->req_q.lock); |
2358 | return req; | ||
2359 | } | ||
3413 | 2360 | ||
3414 | failed_fsf_req: | 2361 | static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req) |
3415 | write_lock_irqsave(&req_q->lock, *lock_flags); | 2362 | { |
3416 | success: | 2363 | if (req->qtcb->header.fsf_status != FSF_GOOD) |
3417 | *fsf_req_p = fsf_req; | 2364 | req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3418 | return ret; | ||
3419 | } | 2365 | } |
3420 | 2366 | ||
3421 | /* | 2367 | /** |
3422 | * function: zfcp_fsf_req_send | 2368 | * zfcp_fsf_control_file - control file upload/download |
3423 | * | 2369 | * @adapter: pointer to struct zfcp_adapter |
3424 | * purpose: start transfer of FSF request via QDIO | 2370 | * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc |
3425 | * | 2371 | * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise |
3426 | * returns: 0 - request transfer succesfully started | ||
3427 | * !0 - start of request transfer failed | ||
3428 | */ | 2372 | */ |
3429 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req) | 2373 | struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter, |
2374 | struct zfcp_fsf_cfdc *fsf_cfdc) | ||
3430 | { | 2375 | { |
3431 | struct zfcp_adapter *adapter; | ||
3432 | struct zfcp_qdio_queue *req_q; | ||
3433 | volatile struct qdio_buffer_element *sbale; | 2376 | volatile struct qdio_buffer_element *sbale; |
3434 | int inc_seq_no; | 2377 | struct zfcp_fsf_req *req = NULL; |
3435 | int retval = 0; | 2378 | struct fsf_qtcb_bottom_support *bottom; |
2379 | int direction, retval = -EIO, bytes; | ||
3436 | 2380 | ||
3437 | adapter = fsf_req->adapter; | 2381 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) |
3438 | req_q = &adapter->req_q; | 2382 | return ERR_PTR(-EOPNOTSUPP); |
3439 | 2383 | ||
3440 | sbale = zfcp_qdio_sbale_req(fsf_req); | 2384 | switch (fsf_cfdc->command) { |
2385 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | ||
2386 | direction = SBAL_FLAGS0_TYPE_WRITE; | ||
2387 | break; | ||
2388 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | ||
2389 | direction = SBAL_FLAGS0_TYPE_READ; | ||
2390 | break; | ||
2391 | default: | ||
2392 | return ERR_PTR(-EINVAL); | ||
2393 | } | ||
3441 | 2394 | ||
3442 | /* put allocated FSF request into hash table */ | 2395 | spin_lock(&adapter->req_q.lock); |
3443 | spin_lock(&adapter->req_list_lock); | 2396 | if (zfcp_fsf_req_sbal_get(adapter)) |
3444 | zfcp_reqlist_add(adapter, fsf_req); | 2397 | goto out; |
3445 | spin_unlock(&adapter->req_list_lock); | ||
3446 | 2398 | ||
3447 | inc_seq_no = (fsf_req->qtcb != NULL); | 2399 | req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL); |
2400 | if (unlikely(IS_ERR(req))) { | ||
2401 | retval = -EPERM; | ||
2402 | goto out; | ||
2403 | } | ||
3448 | 2404 | ||
3449 | fsf_req->issued = get_clock(); | 2405 | req->handler = zfcp_fsf_control_file_handler; |
3450 | 2406 | ||
3451 | retval = zfcp_qdio_send(fsf_req); | 2407 | sbale = zfcp_qdio_sbale_req(req); |
2408 | sbale[0].flags |= direction; | ||
3452 | 2409 | ||
3453 | if (unlikely(retval)) { | 2410 | bottom = &req->qtcb->bottom.support; |
3454 | /* Queues are down..... */ | 2411 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; |
3455 | del_timer(&fsf_req->timer); | 2412 | bottom->option = fsf_cfdc->option; |
3456 | spin_lock(&adapter->req_list_lock); | ||
3457 | zfcp_reqlist_remove(adapter, fsf_req); | ||
3458 | spin_unlock(&adapter->req_list_lock); | ||
3459 | /* undo changes in request queue made for this request */ | ||
3460 | 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; | ||
3464 | zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req); | ||
3465 | retval = -EIO; | ||
3466 | } else { | ||
3467 | /* | ||
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 | */ | ||
3474 | 2413 | ||
3475 | /* Don't increase for unsolicited status */ | 2414 | bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg, |
3476 | if (inc_seq_no) | 2415 | FSF_MAX_SBALS_PER_REQ); |
3477 | adapter->fsf_req_seq_no++; | 2416 | if (bytes != ZFCP_CFDC_MAX_SIZE) { |
2417 | retval = -ENOMEM; | ||
2418 | zfcp_fsf_req_free(req); | ||
2419 | goto out; | ||
3478 | } | 2420 | } |
3479 | return retval; | 2421 | |
2422 | zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); | ||
2423 | retval = zfcp_fsf_req_send(req); | ||
2424 | out: | ||
2425 | spin_unlock(&adapter->req_q.lock); | ||
2426 | |||
2427 | if (!retval) { | ||
2428 | wait_event(req->completion_wq, | ||
2429 | req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | ||
2430 | return req; | ||
2431 | } | ||
2432 | return ERR_PTR(retval); | ||
3480 | } | 2433 | } |