Commit | Line | Data |
---|---|---|
6f231dda DW |
1 | /* |
2 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
3 | * redistributing this file, you may do so under either license. | |
4 | * | |
5 | * GPL LICENSE SUMMARY | |
6 | * | |
7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of version 2 of the GNU General Public License as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * BSD LICENSE | |
25 | * | |
26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * | |
33 | * * Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * * Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in | |
37 | * the documentation and/or other materials provided with the | |
38 | * distribution. | |
39 | * * Neither the name of Intel Corporation nor the names of its | |
40 | * contributors may be used to endorse or promote products derived | |
41 | * from this software without specific prior written permission. | |
42 | * | |
43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
54 | */ | |
55 | ||
56 | #include "isci.h" | |
6f231dda DW |
57 | #include "scic_io_request.h" |
58 | #include "scic_task_request.h" | |
59 | #include "scic_port.h" | |
60 | #include "task.h" | |
61 | #include "request.h" | |
62 | #include "sata.h" | |
63 | #include "scu_completion_codes.h" | |
2ec53eb4 DJ |
64 | #include "scic_sds_request.h" |
65 | #include "sas.h" | |
6f231dda DW |
66 | |
67 | static enum sci_status isci_request_ssp_request_construct( | |
68 | struct isci_request *request) | |
69 | { | |
70 | enum sci_status status; | |
71 | ||
72 | dev_dbg(&request->isci_host->pdev->dev, | |
73 | "%s: request = %p\n", | |
74 | __func__, | |
75 | request); | |
76 | status = scic_io_request_construct_basic_ssp( | |
77 | request->sci_request_handle | |
78 | ); | |
79 | return status; | |
80 | } | |
81 | ||
82 | static enum sci_status isci_request_stp_request_construct( | |
83 | struct isci_request *request) | |
84 | { | |
85 | struct sas_task *task = isci_request_access_task(request); | |
86 | enum sci_status status; | |
87 | struct host_to_dev_fis *register_fis; | |
88 | ||
89 | dev_dbg(&request->isci_host->pdev->dev, | |
90 | "%s: request = %p\n", | |
91 | __func__, | |
92 | request); | |
93 | ||
94 | /* Get the host_to_dev_fis from the core and copy | |
95 | * the fis from the task into it. | |
96 | */ | |
97 | register_fis = isci_sata_task_to_fis_copy(task); | |
98 | ||
99 | status = scic_io_request_construct_basic_sata( | |
100 | request->sci_request_handle | |
101 | ); | |
102 | ||
103 | /* Set the ncq tag in the fis, from the queue | |
104 | * command in the task. | |
105 | */ | |
106 | if (isci_sata_is_task_ncq(task)) { | |
107 | ||
108 | isci_sata_set_ncq_tag( | |
109 | register_fis, | |
110 | task | |
111 | ); | |
112 | } | |
113 | ||
114 | return status; | |
115 | } | |
116 | ||
2ec53eb4 DJ |
117 | /* |
118 | * isci_smp_request_build() - This function builds the smp request. | |
119 | * @ireq: This parameter points to the isci_request allocated in the | |
6f231dda | 120 | * request construct function. |
6f231dda DW |
121 | * |
122 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
123 | */ | |
2ec53eb4 | 124 | static enum sci_status isci_smp_request_build(struct isci_request *ireq) |
6f231dda DW |
125 | { |
126 | enum sci_status status = SCI_FAILURE; | |
2ec53eb4 DJ |
127 | struct sas_task *task = isci_request_access_task(ireq); |
128 | struct scic_sds_request *sci_req = ireq->sci_request_handle; | |
129 | void *cmd_iu = sci_req->command_buffer; | |
6f231dda | 130 | |
2ec53eb4 DJ |
131 | dev_dbg(&ireq->isci_host->pdev->dev, |
132 | "%s: request = %p\n", __func__, ireq); | |
6f231dda | 133 | |
2ec53eb4 | 134 | dev_dbg(&ireq->isci_host->pdev->dev, |
6f231dda DW |
135 | "%s: smp_req len = %d\n", |
136 | __func__, | |
137 | task->smp_task.smp_req.length); | |
138 | ||
139 | /* copy the smp_command to the address; */ | |
140 | sg_copy_to_buffer(&task->smp_task.smp_req, 1, | |
2ec53eb4 DJ |
141 | (char *)cmd_iu, |
142 | sizeof(struct smp_req)); | |
6f231dda | 143 | |
2ec53eb4 | 144 | status = scic_io_request_construct_smp(sci_req); |
6f231dda | 145 | if (status != SCI_SUCCESS) |
2ec53eb4 DJ |
146 | dev_warn(&ireq->isci_host->pdev->dev, |
147 | "%s: failed with status = %d\n", | |
6f231dda DW |
148 | __func__, |
149 | status); | |
150 | ||
151 | return status; | |
152 | } | |
153 | ||
154 | /** | |
155 | * isci_io_request_build() - This function builds the io request object. | |
156 | * @isci_host: This parameter specifies the ISCI host object | |
157 | * @request: This parameter points to the isci_request object allocated in the | |
158 | * request construct function. | |
159 | * @sci_device: This parameter is the handle for the sci core's remote device | |
160 | * object that is the destination for this request. | |
161 | * | |
162 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
163 | */ | |
164 | static enum sci_status isci_io_request_build( | |
165 | struct isci_host *isci_host, | |
166 | struct isci_request *request, | |
167 | struct isci_remote_device *isci_device) | |
168 | { | |
6f231dda DW |
169 | enum sci_status status = SCI_SUCCESS; |
170 | struct sas_task *task = isci_request_access_task(request); | |
57f20f4e | 171 | struct scic_sds_remote_device *sci_device = &isci_device->sci; |
6f231dda DW |
172 | |
173 | dev_dbg(&isci_host->pdev->dev, | |
174 | "%s: isci_device = 0x%p; request = %p, " | |
175 | "num_scatter = %d\n", | |
176 | __func__, | |
177 | isci_device, | |
178 | request, | |
179 | task->num_scatter); | |
180 | ||
181 | /* map the sgl addresses, if present. | |
182 | * libata does the mapping for sata devices | |
183 | * before we get the request. | |
184 | */ | |
185 | if (task->num_scatter && | |
186 | !sas_protocol_ata(task->task_proto) && | |
187 | !(SAS_PROTOCOL_SMP & task->task_proto)) { | |
188 | ||
189 | request->num_sg_entries = dma_map_sg( | |
190 | &isci_host->pdev->dev, | |
191 | task->scatter, | |
192 | task->num_scatter, | |
193 | task->data_dir | |
194 | ); | |
195 | ||
196 | if (request->num_sg_entries == 0) | |
197 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
198 | } | |
199 | ||
200 | /* build the common request object. For now, | |
201 | * we will let the core allocate the IO tag. | |
202 | */ | |
0d84366f DW |
203 | status = scic_io_request_construct(&isci_host->sci, sci_device, |
204 | SCI_CONTROLLER_INVALID_IO_TAG, | |
205 | request, request->sci_req, | |
206 | &request->sci_request_handle); | |
6f231dda DW |
207 | |
208 | if (status != SCI_SUCCESS) { | |
209 | dev_warn(&isci_host->pdev->dev, | |
210 | "%s: failed request construct\n", | |
211 | __func__); | |
212 | return SCI_FAILURE; | |
213 | } | |
214 | ||
890cae9b | 215 | request->sci_request_handle->ireq = request; |
6f231dda | 216 | |
a1a113b0 DW |
217 | switch (task->task_proto) { |
218 | case SAS_PROTOCOL_SMP: | |
219 | status = isci_smp_request_build(request); | |
220 | break; | |
221 | case SAS_PROTOCOL_SSP: | |
6f231dda | 222 | status = isci_request_ssp_request_construct(request); |
a1a113b0 DW |
223 | break; |
224 | case SAS_PROTOCOL_SATA: | |
225 | case SAS_PROTOCOL_STP: | |
226 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
6f231dda | 227 | status = isci_request_stp_request_construct(request); |
a1a113b0 DW |
228 | break; |
229 | default: | |
6f231dda DW |
230 | dev_warn(&isci_host->pdev->dev, |
231 | "%s: unknown protocol\n", __func__); | |
232 | return SCI_FAILURE; | |
233 | } | |
234 | ||
235 | return SCI_SUCCESS; | |
236 | } | |
237 | ||
238 | ||
239 | /** | |
240 | * isci_request_alloc_core() - This function gets the request object from the | |
241 | * isci_host dma cache. | |
242 | * @isci_host: This parameter specifies the ISCI host object | |
243 | * @isci_request: This parameter will contain the pointer to the new | |
244 | * isci_request object. | |
245 | * @isci_device: This parameter is the pointer to the isci remote device object | |
246 | * that is the destination for this request. | |
247 | * @gfp_flags: This parameter specifies the os allocation flags. | |
248 | * | |
249 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
250 | */ | |
251 | static int isci_request_alloc_core( | |
252 | struct isci_host *isci_host, | |
253 | struct isci_request **isci_request, | |
254 | struct isci_remote_device *isci_device, | |
255 | gfp_t gfp_flags) | |
256 | { | |
257 | int ret = 0; | |
258 | dma_addr_t handle; | |
259 | struct isci_request *request; | |
260 | ||
261 | ||
262 | /* get pointer to dma memory. This actually points | |
263 | * to both the isci_remote_device object and the | |
264 | * sci object. The isci object is at the beginning | |
265 | * of the memory allocated here. | |
266 | */ | |
267 | request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle); | |
268 | if (!request) { | |
269 | dev_warn(&isci_host->pdev->dev, | |
270 | "%s: dma_pool_alloc returned NULL\n", __func__); | |
271 | return -ENOMEM; | |
272 | } | |
273 | ||
274 | /* initialize the request object. */ | |
275 | spin_lock_init(&request->state_lock); | |
6f231dda DW |
276 | request->request_daddr = handle; |
277 | request->isci_host = isci_host; | |
278 | request->isci_device = isci_device; | |
279 | request->io_request_completion = NULL; | |
280 | ||
281 | request->request_alloc_size = isci_host->dma_pool_alloc_size; | |
282 | request->num_sg_entries = 0; | |
283 | ||
284 | request->complete_in_target = false; | |
285 | ||
286 | INIT_LIST_HEAD(&request->completed_node); | |
287 | INIT_LIST_HEAD(&request->dev_node); | |
288 | ||
289 | *isci_request = request; | |
83f5eeef | 290 | isci_request_change_state(request, allocated); |
6f231dda DW |
291 | |
292 | return ret; | |
293 | } | |
294 | ||
295 | static int isci_request_alloc_io( | |
296 | struct isci_host *isci_host, | |
297 | struct sas_task *task, | |
298 | struct isci_request **isci_request, | |
299 | struct isci_remote_device *isci_device, | |
300 | gfp_t gfp_flags) | |
301 | { | |
302 | int retval = isci_request_alloc_core(isci_host, isci_request, | |
303 | isci_device, gfp_flags); | |
304 | ||
305 | if (!retval) { | |
306 | (*isci_request)->ttype_ptr.io_task_ptr = task; | |
307 | (*isci_request)->ttype = io_task; | |
308 | ||
309 | task->lldd_task = *isci_request; | |
310 | } | |
311 | return retval; | |
312 | } | |
313 | ||
314 | /** | |
315 | * isci_request_alloc_tmf() - This function gets the request object from the | |
316 | * isci_host dma cache and initializes the relevant fields as a sas_task. | |
317 | * @isci_host: This parameter specifies the ISCI host object | |
318 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
319 | * @isci_request: This parameter will contain the pointer to the new | |
320 | * isci_request object. | |
321 | * @isci_device: This parameter is the pointer to the isci remote device object | |
322 | * that is the destination for this request. | |
323 | * @gfp_flags: This parameter specifies the os allocation flags. | |
324 | * | |
325 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
326 | */ | |
327 | int isci_request_alloc_tmf( | |
328 | struct isci_host *isci_host, | |
329 | struct isci_tmf *isci_tmf, | |
330 | struct isci_request **isci_request, | |
331 | struct isci_remote_device *isci_device, | |
332 | gfp_t gfp_flags) | |
333 | { | |
334 | int retval = isci_request_alloc_core(isci_host, isci_request, | |
335 | isci_device, gfp_flags); | |
336 | ||
337 | if (!retval) { | |
338 | ||
339 | (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf; | |
340 | (*isci_request)->ttype = tmf_task; | |
341 | } | |
342 | return retval; | |
343 | } | |
344 | ||
6f231dda DW |
345 | /** |
346 | * isci_request_execute() - This function allocates the isci_request object, | |
347 | * all fills in some common fields. | |
348 | * @isci_host: This parameter specifies the ISCI host object | |
349 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
350 | * @isci_request: This parameter will contain the pointer to the new | |
351 | * isci_request object. | |
352 | * @gfp_flags: This parameter specifies the os allocation flags. | |
353 | * | |
354 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
355 | */ | |
356 | int isci_request_execute( | |
357 | struct isci_host *isci_host, | |
358 | struct sas_task *task, | |
359 | struct isci_request **isci_request, | |
360 | gfp_t gfp_flags) | |
361 | { | |
362 | int ret = 0; | |
363 | struct scic_sds_remote_device *sci_device; | |
364 | enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; | |
365 | struct isci_remote_device *isci_device; | |
366 | struct isci_request *request; | |
367 | unsigned long flags; | |
368 | ||
4393aa4e | 369 | isci_device = task->dev->lldd_dev; |
57f20f4e | 370 | sci_device = &isci_device->sci; |
6f231dda DW |
371 | |
372 | /* do common allocation and init of request object. */ | |
373 | ret = isci_request_alloc_io( | |
374 | isci_host, | |
375 | task, | |
376 | &request, | |
377 | isci_device, | |
378 | gfp_flags | |
379 | ); | |
380 | ||
381 | if (ret) | |
382 | goto out; | |
383 | ||
384 | status = isci_io_request_build(isci_host, request, isci_device); | |
385 | if (status == SCI_SUCCESS) { | |
386 | ||
387 | spin_lock_irqsave(&isci_host->scic_lock, flags); | |
388 | ||
389 | /* send the request, let the core assign the IO TAG. */ | |
390 | status = scic_controller_start_io( | |
cc3dbd0a | 391 | &isci_host->sci, |
6f231dda DW |
392 | sci_device, |
393 | request->sci_request_handle, | |
394 | SCI_CONTROLLER_INVALID_IO_TAG | |
395 | ); | |
396 | ||
397 | if (status == SCI_SUCCESS || | |
398 | status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | |
399 | ||
400 | /* Either I/O started OK, or the core has signaled that | |
401 | * the device needs a target reset. | |
402 | * | |
403 | * In either case, hold onto the I/O for later. | |
404 | * | |
405 | * Update it's status and add it to the list in the | |
406 | * remote device object. | |
407 | */ | |
408 | isci_request_change_state(request, started); | |
409 | list_add(&request->dev_node, | |
410 | &isci_device->reqs_in_process); | |
411 | ||
c4b9e24c | 412 | if (status == SCI_SUCCESS) { |
1fad9e93 JS |
413 | /* Save the tag for possible task mgmt later. */ |
414 | request->io_tag = scic_io_request_get_io_tag( | |
415 | request->sci_request_handle); | |
ce4f75de JS |
416 | } else { |
417 | /* The request did not really start in the | |
418 | * hardware, so clear the request handle | |
419 | * here so no terminations will be done. | |
420 | */ | |
421 | request->sci_request_handle = NULL; | |
c4b9e24c | 422 | } |
ce4f75de | 423 | |
6f231dda DW |
424 | } else |
425 | dev_warn(&isci_host->pdev->dev, | |
ce4f75de JS |
426 | "%s: failed request start (0x%x)\n", |
427 | __func__, status); | |
6f231dda DW |
428 | |
429 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); | |
430 | ||
c4b9e24c JS |
431 | if (status == |
432 | SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | |
433 | /* Signal libsas that we need the SCSI error | |
434 | * handler thread to work on this I/O and that | |
435 | * we want a device reset. | |
436 | */ | |
ce4f75de JS |
437 | spin_lock_irqsave(&task->task_state_lock, flags); |
438 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | |
439 | spin_unlock_irqrestore(&task->task_state_lock, flags); | |
440 | ||
ed8a72d1 JS |
441 | /* Cause this task to be scheduled in the SCSI error |
442 | * handler thread. | |
ce4f75de | 443 | */ |
ed8a72d1 JS |
444 | isci_execpath_callback(isci_host, task, |
445 | sas_task_abort); | |
c4b9e24c JS |
446 | |
447 | /* Change the status, since we are holding | |
448 | * the I/O until it is managed by the SCSI | |
449 | * error handler. | |
450 | */ | |
451 | status = SCI_SUCCESS; | |
452 | } | |
453 | ||
6f231dda DW |
454 | } else |
455 | dev_warn(&isci_host->pdev->dev, | |
456 | "%s: request_construct failed - status = 0x%x\n", | |
457 | __func__, | |
458 | status); | |
459 | ||
460 | out: | |
461 | if (status != SCI_SUCCESS) { | |
6f231dda DW |
462 | /* release dma memory on failure. */ |
463 | isci_request_free(isci_host, request); | |
464 | request = NULL; | |
465 | ret = SCI_FAILURE; | |
466 | } | |
467 | ||
468 | *isci_request = request; | |
469 | return ret; | |
470 | } | |
471 | ||
472 | ||
473 | /** | |
474 | * isci_request_process_response_iu() - This function sets the status and | |
475 | * response iu, in the task struct, from the request object for the upper | |
476 | * layer driver. | |
477 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
478 | * @resp_iu: This parameter points to the response iu of the completed request. | |
479 | * @dev: This parameter specifies the linux device struct. | |
480 | * | |
481 | * none. | |
482 | */ | |
483 | static void isci_request_process_response_iu( | |
484 | struct sas_task *task, | |
485 | struct ssp_response_iu *resp_iu, | |
486 | struct device *dev) | |
487 | { | |
488 | dev_dbg(dev, | |
489 | "%s: resp_iu = %p " | |
490 | "resp_iu->status = 0x%x,\nresp_iu->datapres = %d " | |
491 | "resp_iu->response_data_len = %x, " | |
492 | "resp_iu->sense_data_len = %x\nrepsonse data: ", | |
493 | __func__, | |
494 | resp_iu, | |
495 | resp_iu->status, | |
496 | resp_iu->datapres, | |
497 | resp_iu->response_data_len, | |
498 | resp_iu->sense_data_len); | |
499 | ||
500 | task->task_status.stat = resp_iu->status; | |
501 | ||
502 | /* libsas updates the task status fields based on the response iu. */ | |
503 | sas_ssp_task_response(dev, task, resp_iu); | |
504 | } | |
505 | ||
506 | /** | |
507 | * isci_request_set_open_reject_status() - This function prepares the I/O | |
508 | * completion for OPEN_REJECT conditions. | |
509 | * @request: This parameter is the completed isci_request object. | |
510 | * @response_ptr: This parameter specifies the service response for the I/O. | |
511 | * @status_ptr: This parameter specifies the exec status for the I/O. | |
512 | * @complete_to_host_ptr: This parameter specifies the action to be taken by | |
513 | * the LLDD with respect to completing this request or forcing an abort | |
514 | * condition on the I/O. | |
515 | * @open_rej_reason: This parameter specifies the encoded reason for the | |
516 | * abandon-class reject. | |
517 | * | |
518 | * none. | |
519 | */ | |
520 | static void isci_request_set_open_reject_status( | |
521 | struct isci_request *request, | |
522 | struct sas_task *task, | |
523 | enum service_response *response_ptr, | |
524 | enum exec_status *status_ptr, | |
525 | enum isci_completion_selection *complete_to_host_ptr, | |
526 | enum sas_open_rej_reason open_rej_reason) | |
527 | { | |
528 | /* Task in the target is done. */ | |
529 | request->complete_in_target = true; | |
530 | *response_ptr = SAS_TASK_UNDELIVERED; | |
531 | *status_ptr = SAS_OPEN_REJECT; | |
532 | *complete_to_host_ptr = isci_perform_normal_io_completion; | |
533 | task->task_status.open_rej_reason = open_rej_reason; | |
534 | } | |
535 | ||
536 | /** | |
537 | * isci_request_handle_controller_specific_errors() - This function decodes | |
538 | * controller-specific I/O completion error conditions. | |
539 | * @request: This parameter is the completed isci_request object. | |
540 | * @response_ptr: This parameter specifies the service response for the I/O. | |
541 | * @status_ptr: This parameter specifies the exec status for the I/O. | |
542 | * @complete_to_host_ptr: This parameter specifies the action to be taken by | |
543 | * the LLDD with respect to completing this request or forcing an abort | |
544 | * condition on the I/O. | |
545 | * | |
546 | * none. | |
547 | */ | |
548 | static void isci_request_handle_controller_specific_errors( | |
549 | struct isci_remote_device *isci_device, | |
550 | struct isci_request *request, | |
551 | struct sas_task *task, | |
552 | enum service_response *response_ptr, | |
553 | enum exec_status *status_ptr, | |
554 | enum isci_completion_selection *complete_to_host_ptr) | |
555 | { | |
556 | unsigned int cstatus; | |
557 | ||
558 | cstatus = scic_request_get_controller_status( | |
559 | request->sci_request_handle | |
560 | ); | |
561 | ||
562 | dev_dbg(&request->isci_host->pdev->dev, | |
563 | "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR " | |
564 | "- controller status = 0x%x\n", | |
565 | __func__, request, cstatus); | |
566 | ||
567 | /* Decode the controller-specific errors; most | |
568 | * important is to recognize those conditions in which | |
569 | * the target may still have a task outstanding that | |
570 | * must be aborted. | |
571 | * | |
572 | * Note that there are SCU completion codes being | |
573 | * named in the decode below for which SCIC has already | |
574 | * done work to handle them in a way other than as | |
575 | * a controller-specific completion code; these are left | |
576 | * in the decode below for completeness sake. | |
577 | */ | |
578 | switch (cstatus) { | |
579 | case SCU_TASK_DONE_DMASETUP_DIRERR: | |
580 | /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */ | |
581 | case SCU_TASK_DONE_XFERCNT_ERR: | |
582 | /* Also SCU_TASK_DONE_SMP_UFI_ERR: */ | |
583 | if (task->task_proto == SAS_PROTOCOL_SMP) { | |
584 | /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */ | |
585 | *response_ptr = SAS_TASK_COMPLETE; | |
586 | ||
587 | /* See if the device has been/is being stopped. Note | |
588 | * that we ignore the quiesce state, since we are | |
589 | * concerned about the actual device state. | |
590 | */ | |
591 | if ((isci_device->status == isci_stopping) || | |
592 | (isci_device->status == isci_stopped)) | |
593 | *status_ptr = SAS_DEVICE_UNKNOWN; | |
594 | else | |
595 | *status_ptr = SAS_ABORTED_TASK; | |
596 | ||
597 | request->complete_in_target = true; | |
598 | ||
599 | *complete_to_host_ptr = | |
600 | isci_perform_normal_io_completion; | |
601 | } else { | |
602 | /* Task in the target is not done. */ | |
603 | *response_ptr = SAS_TASK_UNDELIVERED; | |
604 | ||
605 | if ((isci_device->status == isci_stopping) || | |
606 | (isci_device->status == isci_stopped)) | |
607 | *status_ptr = SAS_DEVICE_UNKNOWN; | |
608 | else | |
609 | *status_ptr = SAM_STAT_TASK_ABORTED; | |
610 | ||
611 | request->complete_in_target = false; | |
612 | ||
613 | *complete_to_host_ptr = | |
614 | isci_perform_error_io_completion; | |
615 | } | |
616 | ||
617 | break; | |
618 | ||
619 | case SCU_TASK_DONE_CRC_ERR: | |
620 | case SCU_TASK_DONE_NAK_CMD_ERR: | |
621 | case SCU_TASK_DONE_EXCESS_DATA: | |
622 | case SCU_TASK_DONE_UNEXP_FIS: | |
623 | /* Also SCU_TASK_DONE_UNEXP_RESP: */ | |
624 | case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */ | |
625 | case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */ | |
626 | case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */ | |
627 | /* These are conditions in which the target | |
628 | * has completed the task, so that no cleanup | |
629 | * is necessary. | |
630 | */ | |
631 | *response_ptr = SAS_TASK_COMPLETE; | |
632 | ||
633 | /* See if the device has been/is being stopped. Note | |
634 | * that we ignore the quiesce state, since we are | |
635 | * concerned about the actual device state. | |
636 | */ | |
637 | if ((isci_device->status == isci_stopping) || | |
638 | (isci_device->status == isci_stopped)) | |
639 | *status_ptr = SAS_DEVICE_UNKNOWN; | |
640 | else | |
641 | *status_ptr = SAS_ABORTED_TASK; | |
642 | ||
643 | request->complete_in_target = true; | |
644 | ||
645 | *complete_to_host_ptr = isci_perform_normal_io_completion; | |
646 | break; | |
647 | ||
648 | ||
649 | /* Note that the only open reject completion codes seen here will be | |
650 | * abandon-class codes; all others are automatically retried in the SCU. | |
651 | */ | |
652 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | |
653 | ||
654 | isci_request_set_open_reject_status( | |
655 | request, task, response_ptr, status_ptr, | |
656 | complete_to_host_ptr, SAS_OREJ_WRONG_DEST); | |
657 | break; | |
658 | ||
659 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | |
660 | ||
661 | /* Note - the return of AB0 will change when | |
662 | * libsas implements detection of zone violations. | |
663 | */ | |
664 | isci_request_set_open_reject_status( | |
665 | request, task, response_ptr, status_ptr, | |
666 | complete_to_host_ptr, SAS_OREJ_RESV_AB0); | |
667 | break; | |
668 | ||
669 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | |
670 | ||
671 | isci_request_set_open_reject_status( | |
672 | request, task, response_ptr, status_ptr, | |
673 | complete_to_host_ptr, SAS_OREJ_RESV_AB1); | |
674 | break; | |
675 | ||
676 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | |
677 | ||
678 | isci_request_set_open_reject_status( | |
679 | request, task, response_ptr, status_ptr, | |
680 | complete_to_host_ptr, SAS_OREJ_RESV_AB2); | |
681 | break; | |
682 | ||
683 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | |
684 | ||
685 | isci_request_set_open_reject_status( | |
686 | request, task, response_ptr, status_ptr, | |
687 | complete_to_host_ptr, SAS_OREJ_RESV_AB3); | |
688 | break; | |
689 | ||
690 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | |
691 | ||
692 | isci_request_set_open_reject_status( | |
693 | request, task, response_ptr, status_ptr, | |
694 | complete_to_host_ptr, SAS_OREJ_BAD_DEST); | |
695 | break; | |
696 | ||
697 | case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | |
698 | ||
699 | isci_request_set_open_reject_status( | |
700 | request, task, response_ptr, status_ptr, | |
701 | complete_to_host_ptr, SAS_OREJ_STP_NORES); | |
702 | break; | |
703 | ||
704 | case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | |
705 | ||
706 | isci_request_set_open_reject_status( | |
707 | request, task, response_ptr, status_ptr, | |
708 | complete_to_host_ptr, SAS_OREJ_EPROTO); | |
709 | break; | |
710 | ||
711 | case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | |
712 | ||
713 | isci_request_set_open_reject_status( | |
714 | request, task, response_ptr, status_ptr, | |
715 | complete_to_host_ptr, SAS_OREJ_CONN_RATE); | |
716 | break; | |
717 | ||
718 | case SCU_TASK_DONE_LL_R_ERR: | |
719 | /* Also SCU_TASK_DONE_ACK_NAK_TO: */ | |
720 | case SCU_TASK_DONE_LL_PERR: | |
721 | case SCU_TASK_DONE_LL_SY_TERM: | |
722 | /* Also SCU_TASK_DONE_NAK_ERR:*/ | |
723 | case SCU_TASK_DONE_LL_LF_TERM: | |
724 | /* Also SCU_TASK_DONE_DATA_LEN_ERR: */ | |
725 | case SCU_TASK_DONE_LL_ABORT_ERR: | |
726 | case SCU_TASK_DONE_SEQ_INV_TYPE: | |
727 | /* Also SCU_TASK_DONE_UNEXP_XR: */ | |
728 | case SCU_TASK_DONE_XR_IU_LEN_ERR: | |
729 | case SCU_TASK_DONE_INV_FIS_LEN: | |
730 | /* Also SCU_TASK_DONE_XR_WD_LEN: */ | |
731 | case SCU_TASK_DONE_SDMA_ERR: | |
732 | case SCU_TASK_DONE_OFFSET_ERR: | |
733 | case SCU_TASK_DONE_MAX_PLD_ERR: | |
734 | case SCU_TASK_DONE_LF_ERR: | |
735 | case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */ | |
736 | case SCU_TASK_DONE_SMP_LL_RX_ERR: | |
737 | case SCU_TASK_DONE_UNEXP_DATA: | |
738 | case SCU_TASK_DONE_UNEXP_SDBFIS: | |
739 | case SCU_TASK_DONE_REG_ERR: | |
740 | case SCU_TASK_DONE_SDB_ERR: | |
741 | case SCU_TASK_DONE_TASK_ABORT: | |
742 | default: | |
743 | /* Task in the target is not done. */ | |
744 | *response_ptr = SAS_TASK_UNDELIVERED; | |
745 | *status_ptr = SAM_STAT_TASK_ABORTED; | |
746 | request->complete_in_target = false; | |
747 | ||
748 | *complete_to_host_ptr = isci_perform_error_io_completion; | |
749 | break; | |
750 | } | |
751 | } | |
752 | ||
753 | /** | |
754 | * isci_task_save_for_upper_layer_completion() - This function saves the | |
755 | * request for later completion to the upper layer driver. | |
756 | * @host: This parameter is a pointer to the host on which the the request | |
757 | * should be queued (either as an error or success). | |
758 | * @request: This parameter is the completed request. | |
759 | * @response: This parameter is the response code for the completed task. | |
760 | * @status: This parameter is the status code for the completed task. | |
761 | * | |
762 | * none. | |
763 | */ | |
764 | static void isci_task_save_for_upper_layer_completion( | |
765 | struct isci_host *host, | |
766 | struct isci_request *request, | |
767 | enum service_response response, | |
768 | enum exec_status status, | |
769 | enum isci_completion_selection task_notification_selection) | |
770 | { | |
771 | struct sas_task *task = isci_request_access_task(request); | |
772 | ||
ec6c9638 JS |
773 | task_notification_selection |
774 | = isci_task_set_completion_status(task, response, status, | |
775 | task_notification_selection); | |
6f231dda DW |
776 | |
777 | /* Tasks aborted specifically by a call to the lldd_abort_task | |
778 | * function should not be completed to the host in the regular path. | |
779 | */ | |
780 | switch (task_notification_selection) { | |
781 | ||
782 | case isci_perform_normal_io_completion: | |
783 | ||
784 | /* Normal notification (task_done) */ | |
785 | dev_dbg(&host->pdev->dev, | |
aa145102 | 786 | "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
787 | __func__, |
788 | task, | |
aa145102 JS |
789 | task->task_status.resp, response, |
790 | task->task_status.stat, status); | |
6f231dda DW |
791 | /* Add to the completed list. */ |
792 | list_add(&request->completed_node, | |
793 | &host->requests_to_complete); | |
ec6c9638 JS |
794 | |
795 | /* Take the request off the device's pending request list. */ | |
796 | list_del_init(&request->dev_node); | |
6f231dda DW |
797 | break; |
798 | ||
799 | case isci_perform_aborted_io_completion: | |
a5fde225 JS |
800 | /* No notification to libsas because this request is |
801 | * already in the abort path. | |
6f231dda DW |
802 | */ |
803 | dev_warn(&host->pdev->dev, | |
aa145102 | 804 | "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
805 | __func__, |
806 | task, | |
aa145102 JS |
807 | task->task_status.resp, response, |
808 | task->task_status.stat, status); | |
a5fde225 JS |
809 | |
810 | /* Wake up whatever process was waiting for this | |
811 | * request to complete. | |
812 | */ | |
813 | WARN_ON(request->io_request_completion == NULL); | |
814 | ||
815 | if (request->io_request_completion != NULL) { | |
816 | ||
817 | /* Signal whoever is waiting that this | |
818 | * request is complete. | |
819 | */ | |
820 | complete(request->io_request_completion); | |
821 | } | |
6f231dda DW |
822 | break; |
823 | ||
824 | case isci_perform_error_io_completion: | |
825 | /* Use sas_task_abort */ | |
826 | dev_warn(&host->pdev->dev, | |
aa145102 | 827 | "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
828 | __func__, |
829 | task, | |
aa145102 JS |
830 | task->task_status.resp, response, |
831 | task->task_status.stat, status); | |
6f231dda DW |
832 | /* Add to the aborted list. */ |
833 | list_add(&request->completed_node, | |
11b00c19 | 834 | &host->requests_to_errorback); |
6f231dda DW |
835 | break; |
836 | ||
837 | default: | |
838 | dev_warn(&host->pdev->dev, | |
aa145102 | 839 | "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
840 | __func__, |
841 | task, | |
aa145102 JS |
842 | task->task_status.resp, response, |
843 | task->task_status.stat, status); | |
6f231dda | 844 | |
a5fde225 | 845 | /* Add to the error to libsas list. */ |
6f231dda | 846 | list_add(&request->completed_node, |
11b00c19 | 847 | &host->requests_to_errorback); |
6f231dda DW |
848 | break; |
849 | } | |
850 | } | |
851 | ||
852 | /** | |
853 | * isci_request_io_request_complete() - This function is called by the sci core | |
854 | * when an io request completes. | |
855 | * @isci_host: This parameter specifies the ISCI host object | |
856 | * @request: This parameter is the completed isci_request object. | |
857 | * @completion_status: This parameter specifies the completion status from the | |
858 | * sci core. | |
859 | * | |
860 | * none. | |
861 | */ | |
862 | void isci_request_io_request_complete( | |
863 | struct isci_host *isci_host, | |
864 | struct isci_request *request, | |
865 | enum sci_io_status completion_status) | |
866 | { | |
867 | struct sas_task *task = isci_request_access_task(request); | |
868 | struct ssp_response_iu *resp_iu; | |
869 | void *resp_buf; | |
870 | unsigned long task_flags; | |
6f231dda DW |
871 | struct isci_remote_device *isci_device = request->isci_device; |
872 | enum service_response response = SAS_TASK_UNDELIVERED; | |
873 | enum exec_status status = SAS_ABORTED_TASK; | |
874 | enum isci_request_status request_status; | |
875 | enum isci_completion_selection complete_to_host | |
876 | = isci_perform_normal_io_completion; | |
877 | ||
878 | dev_dbg(&isci_host->pdev->dev, | |
879 | "%s: request = %p, task = %p,\n" | |
880 | "task->data_dir = %d completion_status = 0x%x\n", | |
881 | __func__, | |
882 | request, | |
883 | task, | |
884 | task->data_dir, | |
885 | completion_status); | |
886 | ||
a5fde225 | 887 | spin_lock(&request->state_lock); |
6f231dda | 888 | request_status = isci_request_get_state(request); |
6f231dda DW |
889 | |
890 | /* Decode the request status. Note that if the request has been | |
891 | * aborted by a task management function, we don't care | |
892 | * what the status is. | |
893 | */ | |
894 | switch (request_status) { | |
895 | ||
896 | case aborted: | |
897 | /* "aborted" indicates that the request was aborted by a task | |
898 | * management function, since once a task management request is | |
899 | * perfomed by the device, the request only completes because | |
900 | * of the subsequent driver terminate. | |
901 | * | |
902 | * Aborted also means an external thread is explicitly managing | |
903 | * this request, so that we do not complete it up the stack. | |
904 | * | |
905 | * The target is still there (since the TMF was successful). | |
906 | */ | |
907 | request->complete_in_target = true; | |
908 | response = SAS_TASK_COMPLETE; | |
909 | ||
910 | /* See if the device has been/is being stopped. Note | |
911 | * that we ignore the quiesce state, since we are | |
912 | * concerned about the actual device state. | |
913 | */ | |
914 | if ((isci_device->status == isci_stopping) | |
915 | || (isci_device->status == isci_stopped) | |
916 | ) | |
917 | status = SAS_DEVICE_UNKNOWN; | |
918 | else | |
919 | status = SAS_ABORTED_TASK; | |
920 | ||
921 | complete_to_host = isci_perform_aborted_io_completion; | |
922 | /* This was an aborted request. */ | |
a5fde225 JS |
923 | |
924 | spin_unlock(&request->state_lock); | |
6f231dda DW |
925 | break; |
926 | ||
927 | case aborting: | |
928 | /* aborting means that the task management function tried and | |
929 | * failed to abort the request. We need to note the request | |
930 | * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the | |
931 | * target as down. | |
932 | * | |
933 | * Aborting also means an external thread is explicitly managing | |
934 | * this request, so that we do not complete it up the stack. | |
935 | */ | |
936 | request->complete_in_target = true; | |
937 | response = SAS_TASK_UNDELIVERED; | |
938 | ||
939 | if ((isci_device->status == isci_stopping) || | |
940 | (isci_device->status == isci_stopped)) | |
941 | /* The device has been /is being stopped. Note that | |
942 | * we ignore the quiesce state, since we are | |
943 | * concerned about the actual device state. | |
944 | */ | |
945 | status = SAS_DEVICE_UNKNOWN; | |
946 | else | |
947 | status = SAS_PHY_DOWN; | |
948 | ||
949 | complete_to_host = isci_perform_aborted_io_completion; | |
950 | ||
951 | /* This was an aborted request. */ | |
a5fde225 JS |
952 | |
953 | spin_unlock(&request->state_lock); | |
6f231dda DW |
954 | break; |
955 | ||
956 | case terminating: | |
957 | ||
958 | /* This was an terminated request. This happens when | |
959 | * the I/O is being terminated because of an action on | |
960 | * the device (reset, tear down, etc.), and the I/O needs | |
961 | * to be completed up the stack. | |
962 | */ | |
963 | request->complete_in_target = true; | |
964 | response = SAS_TASK_UNDELIVERED; | |
965 | ||
966 | /* See if the device has been/is being stopped. Note | |
967 | * that we ignore the quiesce state, since we are | |
968 | * concerned about the actual device state. | |
969 | */ | |
970 | if ((isci_device->status == isci_stopping) || | |
971 | (isci_device->status == isci_stopped)) | |
972 | status = SAS_DEVICE_UNKNOWN; | |
973 | else | |
974 | status = SAS_ABORTED_TASK; | |
975 | ||
a5fde225 | 976 | complete_to_host = isci_perform_aborted_io_completion; |
6f231dda DW |
977 | |
978 | /* This was a terminated request. */ | |
a5fde225 JS |
979 | |
980 | spin_unlock(&request->state_lock); | |
6f231dda DW |
981 | break; |
982 | ||
983 | default: | |
984 | ||
a5fde225 JS |
985 | /* The request is done from an SCU HW perspective. */ |
986 | request->status = completed; | |
987 | ||
988 | spin_unlock(&request->state_lock); | |
989 | ||
6f231dda DW |
990 | /* This is an active request being completed from the core. */ |
991 | switch (completion_status) { | |
992 | ||
993 | case SCI_IO_FAILURE_RESPONSE_VALID: | |
994 | dev_dbg(&isci_host->pdev->dev, | |
995 | "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", | |
996 | __func__, | |
997 | request, | |
998 | task); | |
999 | ||
1000 | if (sas_protocol_ata(task->task_proto)) { | |
1001 | resp_buf | |
1002 | = scic_stp_io_request_get_d2h_reg_address( | |
1003 | request->sci_request_handle | |
1004 | ); | |
1005 | isci_request_process_stp_response(task, | |
1006 | resp_buf | |
1007 | ); | |
1008 | ||
1009 | } else if (SAS_PROTOCOL_SSP == task->task_proto) { | |
1010 | ||
1011 | /* crack the iu response buffer. */ | |
1012 | resp_iu | |
1013 | = scic_io_request_get_response_iu_address( | |
1014 | request->sci_request_handle | |
1015 | ); | |
1016 | ||
1017 | isci_request_process_response_iu(task, resp_iu, | |
1018 | &isci_host->pdev->dev | |
1019 | ); | |
1020 | ||
1021 | } else if (SAS_PROTOCOL_SMP == task->task_proto) { | |
1022 | ||
1023 | dev_err(&isci_host->pdev->dev, | |
1024 | "%s: SCI_IO_FAILURE_RESPONSE_VALID: " | |
1025 | "SAS_PROTOCOL_SMP protocol\n", | |
1026 | __func__); | |
1027 | ||
1028 | } else | |
1029 | dev_err(&isci_host->pdev->dev, | |
1030 | "%s: unknown protocol\n", __func__); | |
1031 | ||
1032 | /* use the task status set in the task struct by the | |
1033 | * isci_request_process_response_iu call. | |
1034 | */ | |
1035 | request->complete_in_target = true; | |
1036 | response = task->task_status.resp; | |
1037 | status = task->task_status.stat; | |
1038 | break; | |
1039 | ||
1040 | case SCI_IO_SUCCESS: | |
1041 | case SCI_IO_SUCCESS_IO_DONE_EARLY: | |
1042 | ||
1043 | response = SAS_TASK_COMPLETE; | |
1044 | status = SAM_STAT_GOOD; | |
1045 | request->complete_in_target = true; | |
1046 | ||
1047 | if (task->task_proto == SAS_PROTOCOL_SMP) { | |
1048 | ||
1049 | u8 *command_iu_address | |
1050 | = scic_io_request_get_command_iu_address( | |
1051 | request->sci_request_handle | |
1052 | ); | |
1053 | ||
1054 | dev_dbg(&isci_host->pdev->dev, | |
1055 | "%s: SMP protocol completion\n", | |
1056 | __func__); | |
1057 | ||
1058 | sg_copy_from_buffer( | |
1059 | &task->smp_task.smp_resp, 1, | |
1060 | command_iu_address | |
2ec53eb4 DJ |
1061 | + sizeof(struct smp_req), |
1062 | sizeof(struct smp_resp)); | |
6f231dda DW |
1063 | } else if (completion_status |
1064 | == SCI_IO_SUCCESS_IO_DONE_EARLY) { | |
1065 | ||
1066 | /* This was an SSP / STP / SATA transfer. | |
1067 | * There is a possibility that less data than | |
1068 | * the maximum was transferred. | |
1069 | */ | |
1070 | u32 transferred_length | |
1071 | = scic_io_request_get_number_of_bytes_transferred( | |
1072 | request->sci_request_handle); | |
1073 | ||
1074 | task->task_status.residual | |
1075 | = task->total_xfer_len - transferred_length; | |
1076 | ||
1077 | /* If there were residual bytes, call this an | |
1078 | * underrun. | |
1079 | */ | |
1080 | if (task->task_status.residual != 0) | |
1081 | status = SAS_DATA_UNDERRUN; | |
1082 | ||
1083 | dev_dbg(&isci_host->pdev->dev, | |
1084 | "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", | |
1085 | __func__, | |
1086 | status); | |
1087 | ||
1088 | } else | |
1089 | dev_dbg(&isci_host->pdev->dev, | |
1090 | "%s: SCI_IO_SUCCESS\n", | |
1091 | __func__); | |
1092 | ||
1093 | break; | |
1094 | ||
1095 | case SCI_IO_FAILURE_TERMINATED: | |
1096 | dev_dbg(&isci_host->pdev->dev, | |
1097 | "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", | |
1098 | __func__, | |
1099 | request, | |
1100 | task); | |
1101 | ||
1102 | /* The request was terminated explicitly. No handling | |
1103 | * is needed in the SCSI error handler path. | |
1104 | */ | |
1105 | request->complete_in_target = true; | |
1106 | response = SAS_TASK_UNDELIVERED; | |
1107 | ||
1108 | /* See if the device has been/is being stopped. Note | |
1109 | * that we ignore the quiesce state, since we are | |
1110 | * concerned about the actual device state. | |
1111 | */ | |
1112 | if ((isci_device->status == isci_stopping) || | |
1113 | (isci_device->status == isci_stopped)) | |
1114 | status = SAS_DEVICE_UNKNOWN; | |
1115 | else | |
1116 | status = SAS_ABORTED_TASK; | |
1117 | ||
1118 | complete_to_host = isci_perform_normal_io_completion; | |
1119 | break; | |
1120 | ||
1121 | case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: | |
1122 | ||
1123 | isci_request_handle_controller_specific_errors( | |
1124 | isci_device, request, task, &response, &status, | |
1125 | &complete_to_host); | |
1126 | ||
1127 | break; | |
1128 | ||
1129 | case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: | |
1130 | /* This is a special case, in that the I/O completion | |
1131 | * is telling us that the device needs a reset. | |
1132 | * In order for the device reset condition to be | |
1133 | * noticed, the I/O has to be handled in the error | |
1134 | * handler. Set the reset flag and cause the | |
1135 | * SCSI error thread to be scheduled. | |
1136 | */ | |
1137 | spin_lock_irqsave(&task->task_state_lock, task_flags); | |
1138 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | |
1139 | spin_unlock_irqrestore(&task->task_state_lock, task_flags); | |
1140 | ||
aa145102 JS |
1141 | /* Fail the I/O. */ |
1142 | response = SAS_TASK_UNDELIVERED; | |
1143 | status = SAM_STAT_TASK_ABORTED; | |
1144 | ||
6f231dda DW |
1145 | complete_to_host = isci_perform_error_io_completion; |
1146 | request->complete_in_target = false; | |
1147 | break; | |
1148 | ||
1149 | default: | |
1150 | /* Catch any otherwise unhandled error codes here. */ | |
1151 | dev_warn(&isci_host->pdev->dev, | |
1152 | "%s: invalid completion code: 0x%x - " | |
1153 | "isci_request = %p\n", | |
1154 | __func__, completion_status, request); | |
1155 | ||
1156 | response = SAS_TASK_UNDELIVERED; | |
1157 | ||
1158 | /* See if the device has been/is being stopped. Note | |
1159 | * that we ignore the quiesce state, since we are | |
1160 | * concerned about the actual device state. | |
1161 | */ | |
1162 | if ((isci_device->status == isci_stopping) || | |
1163 | (isci_device->status == isci_stopped)) | |
1164 | status = SAS_DEVICE_UNKNOWN; | |
1165 | else | |
1166 | status = SAS_ABORTED_TASK; | |
1167 | ||
1168 | complete_to_host = isci_perform_error_io_completion; | |
1169 | request->complete_in_target = false; | |
1170 | break; | |
1171 | } | |
1172 | break; | |
1173 | } | |
1174 | ||
1175 | isci_request_unmap_sgl(request, isci_host->pdev); | |
1176 | ||
1177 | /* Put the completed request on the correct list */ | |
1178 | isci_task_save_for_upper_layer_completion(isci_host, request, response, | |
1179 | status, complete_to_host | |
1180 | ); | |
1181 | ||
1182 | /* complete the io request to the core. */ | |
cc3dbd0a | 1183 | scic_controller_complete_io(&isci_host->sci, |
57f20f4e DW |
1184 | &isci_device->sci, |
1185 | request->sci_request_handle); | |
6f231dda DW |
1186 | /* NULL the request handle so it cannot be completed or |
1187 | * terminated again, and to cause any calls into abort | |
1188 | * task to recognize the already completed case. | |
1189 | */ | |
1190 | request->sci_request_handle = NULL; | |
1191 | ||
6f231dda DW |
1192 | isci_host_can_dequeue(isci_host, 1); |
1193 | } |