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" | |
57 | #include "scic_remote_device.h" | |
58 | #include "scic_io_request.h" | |
59 | #include "scic_task_request.h" | |
60 | #include "scic_port.h" | |
61 | #include "task.h" | |
62 | #include "request.h" | |
63 | #include "sata.h" | |
64 | #include "scu_completion_codes.h" | |
65 | ||
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 | ||
117 | /** | |
118 | * isci_smp_request_build() - This function builds the smp request object. | |
119 | * @isci_host: This parameter specifies the ISCI host object | |
120 | * @request: This parameter points to the isci_request object allocated in the | |
121 | * request construct function. | |
122 | * @sci_device: This parameter is the handle for the sci core's remote device | |
123 | * object that is the destination for this request. | |
124 | * | |
125 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
126 | */ | |
127 | static enum sci_status isci_smp_request_build( | |
128 | struct isci_request *request) | |
129 | { | |
130 | enum sci_status status = SCI_FAILURE; | |
131 | struct sas_task *task = isci_request_access_task(request); | |
132 | ||
133 | void *command_iu_address = | |
134 | scic_io_request_get_command_iu_address( | |
135 | request->sci_request_handle | |
136 | ); | |
137 | ||
138 | dev_dbg(&request->isci_host->pdev->dev, | |
139 | "%s: request = %p\n", | |
140 | __func__, | |
141 | request); | |
142 | dev_dbg(&request->isci_host->pdev->dev, | |
143 | "%s: smp_req len = %d\n", | |
144 | __func__, | |
145 | task->smp_task.smp_req.length); | |
146 | ||
147 | /* copy the smp_command to the address; */ | |
148 | sg_copy_to_buffer(&task->smp_task.smp_req, 1, | |
149 | (char *)command_iu_address, | |
150 | sizeof(struct smp_request) | |
151 | ); | |
152 | ||
153 | status = scic_io_request_construct_smp(request->sci_request_handle); | |
154 | if (status != SCI_SUCCESS) | |
155 | dev_warn(&request->isci_host->pdev->dev, | |
156 | "%s: scic_io_request_construct_smp failed with " | |
157 | "status = %d\n", | |
158 | __func__, | |
159 | status); | |
160 | ||
161 | return status; | |
162 | } | |
163 | ||
164 | /** | |
165 | * isci_io_request_build() - This function builds the io request object. | |
166 | * @isci_host: This parameter specifies the ISCI host object | |
167 | * @request: This parameter points to the isci_request object allocated in the | |
168 | * request construct function. | |
169 | * @sci_device: This parameter is the handle for the sci core's remote device | |
170 | * object that is the destination for this request. | |
171 | * | |
172 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
173 | */ | |
174 | static enum sci_status isci_io_request_build( | |
175 | struct isci_host *isci_host, | |
176 | struct isci_request *request, | |
177 | struct isci_remote_device *isci_device) | |
178 | { | |
179 | struct smp_discover_response_protocols dev_protocols; | |
180 | enum sci_status status = SCI_SUCCESS; | |
181 | struct sas_task *task = isci_request_access_task(request); | |
3a97eec6 | 182 | struct scic_sds_remote_device *sci_device = to_sci_dev(isci_device); |
6f231dda DW |
183 | |
184 | dev_dbg(&isci_host->pdev->dev, | |
185 | "%s: isci_device = 0x%p; request = %p, " | |
186 | "num_scatter = %d\n", | |
187 | __func__, | |
188 | isci_device, | |
189 | request, | |
190 | task->num_scatter); | |
191 | ||
192 | /* map the sgl addresses, if present. | |
193 | * libata does the mapping for sata devices | |
194 | * before we get the request. | |
195 | */ | |
196 | if (task->num_scatter && | |
197 | !sas_protocol_ata(task->task_proto) && | |
198 | !(SAS_PROTOCOL_SMP & task->task_proto)) { | |
199 | ||
200 | request->num_sg_entries = dma_map_sg( | |
201 | &isci_host->pdev->dev, | |
202 | task->scatter, | |
203 | task->num_scatter, | |
204 | task->data_dir | |
205 | ); | |
206 | ||
207 | if (request->num_sg_entries == 0) | |
208 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
209 | } | |
210 | ||
211 | /* build the common request object. For now, | |
212 | * we will let the core allocate the IO tag. | |
213 | */ | |
214 | status = scic_io_request_construct( | |
215 | isci_host->core_controller, | |
216 | sci_device, | |
217 | SCI_CONTROLLER_INVALID_IO_TAG, | |
218 | request, | |
219 | request->sci_request_mem_ptr, | |
220 | (struct scic_sds_request **)&request->sci_request_handle | |
221 | ); | |
222 | ||
223 | if (status != SCI_SUCCESS) { | |
224 | dev_warn(&isci_host->pdev->dev, | |
225 | "%s: failed request construct\n", | |
226 | __func__); | |
227 | return SCI_FAILURE; | |
228 | } | |
229 | ||
230 | sci_object_set_association(request->sci_request_handle, request); | |
231 | ||
232 | /* Determine protocol and call the appropriate basic constructor */ | |
233 | scic_remote_device_get_protocols(sci_device, &dev_protocols); | |
234 | if (dev_protocols.u.bits.attached_ssp_target) | |
235 | status = isci_request_ssp_request_construct(request); | |
236 | else if (dev_protocols.u.bits.attached_stp_target) | |
237 | status = isci_request_stp_request_construct(request); | |
238 | else if (dev_protocols.u.bits.attached_smp_target) | |
239 | status = isci_smp_request_build(request); | |
240 | else { | |
241 | dev_warn(&isci_host->pdev->dev, | |
242 | "%s: unknown protocol\n", __func__); | |
243 | return SCI_FAILURE; | |
244 | } | |
245 | ||
246 | return SCI_SUCCESS; | |
247 | } | |
248 | ||
249 | ||
250 | /** | |
251 | * isci_request_alloc_core() - This function gets the request object from the | |
252 | * isci_host dma cache. | |
253 | * @isci_host: This parameter specifies the ISCI host object | |
254 | * @isci_request: This parameter will contain the pointer to the new | |
255 | * isci_request object. | |
256 | * @isci_device: This parameter is the pointer to the isci remote device object | |
257 | * that is the destination for this request. | |
258 | * @gfp_flags: This parameter specifies the os allocation flags. | |
259 | * | |
260 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
261 | */ | |
262 | static int isci_request_alloc_core( | |
263 | struct isci_host *isci_host, | |
264 | struct isci_request **isci_request, | |
265 | struct isci_remote_device *isci_device, | |
266 | gfp_t gfp_flags) | |
267 | { | |
268 | int ret = 0; | |
269 | dma_addr_t handle; | |
270 | struct isci_request *request; | |
271 | ||
272 | ||
273 | /* get pointer to dma memory. This actually points | |
274 | * to both the isci_remote_device object and the | |
275 | * sci object. The isci object is at the beginning | |
276 | * of the memory allocated here. | |
277 | */ | |
278 | request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle); | |
279 | if (!request) { | |
280 | dev_warn(&isci_host->pdev->dev, | |
281 | "%s: dma_pool_alloc returned NULL\n", __func__); | |
282 | return -ENOMEM; | |
283 | } | |
284 | ||
285 | /* initialize the request object. */ | |
286 | spin_lock_init(&request->state_lock); | |
6f231dda DW |
287 | request->sci_request_mem_ptr = ((u8 *)request) + |
288 | sizeof(struct isci_request); | |
289 | request->request_daddr = handle; | |
290 | request->isci_host = isci_host; | |
291 | request->isci_device = isci_device; | |
292 | request->io_request_completion = NULL; | |
293 | ||
294 | request->request_alloc_size = isci_host->dma_pool_alloc_size; | |
295 | request->num_sg_entries = 0; | |
296 | ||
297 | request->complete_in_target = false; | |
298 | ||
299 | INIT_LIST_HEAD(&request->completed_node); | |
300 | INIT_LIST_HEAD(&request->dev_node); | |
301 | ||
302 | *isci_request = request; | |
83f5eeef | 303 | isci_request_change_state(request, allocated); |
6f231dda DW |
304 | |
305 | return ret; | |
306 | } | |
307 | ||
308 | static int isci_request_alloc_io( | |
309 | struct isci_host *isci_host, | |
310 | struct sas_task *task, | |
311 | struct isci_request **isci_request, | |
312 | struct isci_remote_device *isci_device, | |
313 | gfp_t gfp_flags) | |
314 | { | |
315 | int retval = isci_request_alloc_core(isci_host, isci_request, | |
316 | isci_device, gfp_flags); | |
317 | ||
318 | if (!retval) { | |
319 | (*isci_request)->ttype_ptr.io_task_ptr = task; | |
320 | (*isci_request)->ttype = io_task; | |
321 | ||
322 | task->lldd_task = *isci_request; | |
323 | } | |
324 | return retval; | |
325 | } | |
326 | ||
327 | /** | |
328 | * isci_request_alloc_tmf() - This function gets the request object from the | |
329 | * isci_host dma cache and initializes the relevant fields as a sas_task. | |
330 | * @isci_host: This parameter specifies the ISCI host object | |
331 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
332 | * @isci_request: This parameter will contain the pointer to the new | |
333 | * isci_request object. | |
334 | * @isci_device: This parameter is the pointer to the isci remote device object | |
335 | * that is the destination for this request. | |
336 | * @gfp_flags: This parameter specifies the os allocation flags. | |
337 | * | |
338 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
339 | */ | |
340 | int isci_request_alloc_tmf( | |
341 | struct isci_host *isci_host, | |
342 | struct isci_tmf *isci_tmf, | |
343 | struct isci_request **isci_request, | |
344 | struct isci_remote_device *isci_device, | |
345 | gfp_t gfp_flags) | |
346 | { | |
347 | int retval = isci_request_alloc_core(isci_host, isci_request, | |
348 | isci_device, gfp_flags); | |
349 | ||
350 | if (!retval) { | |
351 | ||
352 | (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf; | |
353 | (*isci_request)->ttype = tmf_task; | |
354 | } | |
355 | return retval; | |
356 | } | |
357 | ||
358 | /** | |
359 | * isci_request_signal_device_reset() - This function will set the "device | |
360 | * needs target reset" flag in the given sas_tasks' task_state_flags, and | |
361 | * then cause the task to be added into the SCSI error handler queue which | |
362 | * will eventually be escalated to a target reset. | |
363 | * | |
364 | * | |
365 | */ | |
366 | static void isci_request_signal_device_reset( | |
367 | struct isci_request *isci_request) | |
368 | { | |
369 | unsigned long flags; | |
370 | struct sas_task *task = isci_request_access_task(isci_request); | |
371 | ||
372 | dev_dbg(&isci_request->isci_host->pdev->dev, | |
373 | "%s: request=%p, task=%p\n", __func__, isci_request, task); | |
374 | ||
375 | spin_lock_irqsave(&task->task_state_lock, flags); | |
376 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | |
377 | spin_unlock_irqrestore(&task->task_state_lock, flags); | |
378 | ||
379 | /* Cause this task to be scheduled in the SCSI error handler | |
380 | * thread. | |
381 | */ | |
382 | sas_task_abort(task); | |
383 | } | |
384 | ||
385 | /** | |
386 | * isci_request_execute() - This function allocates the isci_request object, | |
387 | * all fills in some common fields. | |
388 | * @isci_host: This parameter specifies the ISCI host object | |
389 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
390 | * @isci_request: This parameter will contain the pointer to the new | |
391 | * isci_request object. | |
392 | * @gfp_flags: This parameter specifies the os allocation flags. | |
393 | * | |
394 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
395 | */ | |
396 | int isci_request_execute( | |
397 | struct isci_host *isci_host, | |
398 | struct sas_task *task, | |
399 | struct isci_request **isci_request, | |
400 | gfp_t gfp_flags) | |
401 | { | |
402 | int ret = 0; | |
403 | struct scic_sds_remote_device *sci_device; | |
404 | enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; | |
405 | struct isci_remote_device *isci_device; | |
406 | struct isci_request *request; | |
407 | unsigned long flags; | |
408 | ||
409 | isci_device = isci_dev_from_domain_dev(task->dev); | |
3a97eec6 | 410 | sci_device = to_sci_dev(isci_device); |
6f231dda DW |
411 | |
412 | /* do common allocation and init of request object. */ | |
413 | ret = isci_request_alloc_io( | |
414 | isci_host, | |
415 | task, | |
416 | &request, | |
417 | isci_device, | |
418 | gfp_flags | |
419 | ); | |
420 | ||
421 | if (ret) | |
422 | goto out; | |
423 | ||
424 | status = isci_io_request_build(isci_host, request, isci_device); | |
425 | if (status == SCI_SUCCESS) { | |
426 | ||
427 | spin_lock_irqsave(&isci_host->scic_lock, flags); | |
428 | ||
429 | /* send the request, let the core assign the IO TAG. */ | |
430 | status = scic_controller_start_io( | |
431 | isci_host->core_controller, | |
432 | sci_device, | |
433 | request->sci_request_handle, | |
434 | SCI_CONTROLLER_INVALID_IO_TAG | |
435 | ); | |
436 | ||
437 | if (status == SCI_SUCCESS || | |
438 | status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | |
439 | ||
440 | /* Either I/O started OK, or the core has signaled that | |
441 | * the device needs a target reset. | |
442 | * | |
443 | * In either case, hold onto the I/O for later. | |
444 | * | |
445 | * Update it's status and add it to the list in the | |
446 | * remote device object. | |
447 | */ | |
448 | isci_request_change_state(request, started); | |
449 | list_add(&request->dev_node, | |
450 | &isci_device->reqs_in_process); | |
451 | ||
c4b9e24c | 452 | if (status == SCI_SUCCESS) { |
1fad9e93 JS |
453 | /* Save the tag for possible task mgmt later. */ |
454 | request->io_tag = scic_io_request_get_io_tag( | |
455 | request->sci_request_handle); | |
c4b9e24c | 456 | } |
6f231dda DW |
457 | } else |
458 | dev_warn(&isci_host->pdev->dev, | |
459 | "%s: failed request start\n", | |
460 | __func__); | |
461 | ||
462 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); | |
463 | ||
c4b9e24c JS |
464 | if (status == |
465 | SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | |
466 | /* Signal libsas that we need the SCSI error | |
467 | * handler thread to work on this I/O and that | |
468 | * we want a device reset. | |
469 | */ | |
470 | isci_request_signal_device_reset(request); | |
471 | ||
472 | /* Change the status, since we are holding | |
473 | * the I/O until it is managed by the SCSI | |
474 | * error handler. | |
475 | */ | |
476 | status = SCI_SUCCESS; | |
477 | } | |
478 | ||
6f231dda DW |
479 | } else |
480 | dev_warn(&isci_host->pdev->dev, | |
481 | "%s: request_construct failed - status = 0x%x\n", | |
482 | __func__, | |
483 | status); | |
484 | ||
485 | out: | |
486 | if (status != SCI_SUCCESS) { | |
487 | ||
488 | /* release dma memory on failure. */ | |
489 | isci_request_free(isci_host, request); | |
490 | request = NULL; | |
491 | ret = SCI_FAILURE; | |
492 | } | |
493 | ||
494 | *isci_request = request; | |
495 | return ret; | |
496 | } | |
497 | ||
498 | ||
499 | /** | |
500 | * isci_request_process_response_iu() - This function sets the status and | |
501 | * response iu, in the task struct, from the request object for the upper | |
502 | * layer driver. | |
503 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
504 | * @resp_iu: This parameter points to the response iu of the completed request. | |
505 | * @dev: This parameter specifies the linux device struct. | |
506 | * | |
507 | * none. | |
508 | */ | |
509 | static void isci_request_process_response_iu( | |
510 | struct sas_task *task, | |
511 | struct ssp_response_iu *resp_iu, | |
512 | struct device *dev) | |
513 | { | |
514 | dev_dbg(dev, | |
515 | "%s: resp_iu = %p " | |
516 | "resp_iu->status = 0x%x,\nresp_iu->datapres = %d " | |
517 | "resp_iu->response_data_len = %x, " | |
518 | "resp_iu->sense_data_len = %x\nrepsonse data: ", | |
519 | __func__, | |
520 | resp_iu, | |
521 | resp_iu->status, | |
522 | resp_iu->datapres, | |
523 | resp_iu->response_data_len, | |
524 | resp_iu->sense_data_len); | |
525 | ||
526 | task->task_status.stat = resp_iu->status; | |
527 | ||
528 | /* libsas updates the task status fields based on the response iu. */ | |
529 | sas_ssp_task_response(dev, task, resp_iu); | |
530 | } | |
531 | ||
532 | /** | |
533 | * isci_request_set_open_reject_status() - This function prepares the I/O | |
534 | * completion for OPEN_REJECT conditions. | |
535 | * @request: This parameter is the completed isci_request object. | |
536 | * @response_ptr: This parameter specifies the service response for the I/O. | |
537 | * @status_ptr: This parameter specifies the exec status for the I/O. | |
538 | * @complete_to_host_ptr: This parameter specifies the action to be taken by | |
539 | * the LLDD with respect to completing this request or forcing an abort | |
540 | * condition on the I/O. | |
541 | * @open_rej_reason: This parameter specifies the encoded reason for the | |
542 | * abandon-class reject. | |
543 | * | |
544 | * none. | |
545 | */ | |
546 | static void isci_request_set_open_reject_status( | |
547 | struct isci_request *request, | |
548 | struct sas_task *task, | |
549 | enum service_response *response_ptr, | |
550 | enum exec_status *status_ptr, | |
551 | enum isci_completion_selection *complete_to_host_ptr, | |
552 | enum sas_open_rej_reason open_rej_reason) | |
553 | { | |
554 | /* Task in the target is done. */ | |
555 | request->complete_in_target = true; | |
556 | *response_ptr = SAS_TASK_UNDELIVERED; | |
557 | *status_ptr = SAS_OPEN_REJECT; | |
558 | *complete_to_host_ptr = isci_perform_normal_io_completion; | |
559 | task->task_status.open_rej_reason = open_rej_reason; | |
560 | } | |
561 | ||
562 | /** | |
563 | * isci_request_handle_controller_specific_errors() - This function decodes | |
564 | * controller-specific I/O completion error conditions. | |
565 | * @request: This parameter is the completed isci_request object. | |
566 | * @response_ptr: This parameter specifies the service response for the I/O. | |
567 | * @status_ptr: This parameter specifies the exec status for the I/O. | |
568 | * @complete_to_host_ptr: This parameter specifies the action to be taken by | |
569 | * the LLDD with respect to completing this request or forcing an abort | |
570 | * condition on the I/O. | |
571 | * | |
572 | * none. | |
573 | */ | |
574 | static void isci_request_handle_controller_specific_errors( | |
575 | struct isci_remote_device *isci_device, | |
576 | struct isci_request *request, | |
577 | struct sas_task *task, | |
578 | enum service_response *response_ptr, | |
579 | enum exec_status *status_ptr, | |
580 | enum isci_completion_selection *complete_to_host_ptr) | |
581 | { | |
582 | unsigned int cstatus; | |
583 | ||
584 | cstatus = scic_request_get_controller_status( | |
585 | request->sci_request_handle | |
586 | ); | |
587 | ||
588 | dev_dbg(&request->isci_host->pdev->dev, | |
589 | "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR " | |
590 | "- controller status = 0x%x\n", | |
591 | __func__, request, cstatus); | |
592 | ||
593 | /* Decode the controller-specific errors; most | |
594 | * important is to recognize those conditions in which | |
595 | * the target may still have a task outstanding that | |
596 | * must be aborted. | |
597 | * | |
598 | * Note that there are SCU completion codes being | |
599 | * named in the decode below for which SCIC has already | |
600 | * done work to handle them in a way other than as | |
601 | * a controller-specific completion code; these are left | |
602 | * in the decode below for completeness sake. | |
603 | */ | |
604 | switch (cstatus) { | |
605 | case SCU_TASK_DONE_DMASETUP_DIRERR: | |
606 | /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */ | |
607 | case SCU_TASK_DONE_XFERCNT_ERR: | |
608 | /* Also SCU_TASK_DONE_SMP_UFI_ERR: */ | |
609 | if (task->task_proto == SAS_PROTOCOL_SMP) { | |
610 | /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */ | |
611 | *response_ptr = SAS_TASK_COMPLETE; | |
612 | ||
613 | /* See if the device has been/is being stopped. Note | |
614 | * that we ignore the quiesce state, since we are | |
615 | * concerned about the actual device state. | |
616 | */ | |
617 | if ((isci_device->status == isci_stopping) || | |
618 | (isci_device->status == isci_stopped)) | |
619 | *status_ptr = SAS_DEVICE_UNKNOWN; | |
620 | else | |
621 | *status_ptr = SAS_ABORTED_TASK; | |
622 | ||
623 | request->complete_in_target = true; | |
624 | ||
625 | *complete_to_host_ptr = | |
626 | isci_perform_normal_io_completion; | |
627 | } else { | |
628 | /* Task in the target is not done. */ | |
629 | *response_ptr = SAS_TASK_UNDELIVERED; | |
630 | ||
631 | if ((isci_device->status == isci_stopping) || | |
632 | (isci_device->status == isci_stopped)) | |
633 | *status_ptr = SAS_DEVICE_UNKNOWN; | |
634 | else | |
635 | *status_ptr = SAM_STAT_TASK_ABORTED; | |
636 | ||
637 | request->complete_in_target = false; | |
638 | ||
639 | *complete_to_host_ptr = | |
640 | isci_perform_error_io_completion; | |
641 | } | |
642 | ||
643 | break; | |
644 | ||
645 | case SCU_TASK_DONE_CRC_ERR: | |
646 | case SCU_TASK_DONE_NAK_CMD_ERR: | |
647 | case SCU_TASK_DONE_EXCESS_DATA: | |
648 | case SCU_TASK_DONE_UNEXP_FIS: | |
649 | /* Also SCU_TASK_DONE_UNEXP_RESP: */ | |
650 | case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */ | |
651 | case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */ | |
652 | case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */ | |
653 | /* These are conditions in which the target | |
654 | * has completed the task, so that no cleanup | |
655 | * is necessary. | |
656 | */ | |
657 | *response_ptr = SAS_TASK_COMPLETE; | |
658 | ||
659 | /* See if the device has been/is being stopped. Note | |
660 | * that we ignore the quiesce state, since we are | |
661 | * concerned about the actual device state. | |
662 | */ | |
663 | if ((isci_device->status == isci_stopping) || | |
664 | (isci_device->status == isci_stopped)) | |
665 | *status_ptr = SAS_DEVICE_UNKNOWN; | |
666 | else | |
667 | *status_ptr = SAS_ABORTED_TASK; | |
668 | ||
669 | request->complete_in_target = true; | |
670 | ||
671 | *complete_to_host_ptr = isci_perform_normal_io_completion; | |
672 | break; | |
673 | ||
674 | ||
675 | /* Note that the only open reject completion codes seen here will be | |
676 | * abandon-class codes; all others are automatically retried in the SCU. | |
677 | */ | |
678 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | |
679 | ||
680 | isci_request_set_open_reject_status( | |
681 | request, task, response_ptr, status_ptr, | |
682 | complete_to_host_ptr, SAS_OREJ_WRONG_DEST); | |
683 | break; | |
684 | ||
685 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | |
686 | ||
687 | /* Note - the return of AB0 will change when | |
688 | * libsas implements detection of zone violations. | |
689 | */ | |
690 | isci_request_set_open_reject_status( | |
691 | request, task, response_ptr, status_ptr, | |
692 | complete_to_host_ptr, SAS_OREJ_RESV_AB0); | |
693 | break; | |
694 | ||
695 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | |
696 | ||
697 | isci_request_set_open_reject_status( | |
698 | request, task, response_ptr, status_ptr, | |
699 | complete_to_host_ptr, SAS_OREJ_RESV_AB1); | |
700 | break; | |
701 | ||
702 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | |
703 | ||
704 | isci_request_set_open_reject_status( | |
705 | request, task, response_ptr, status_ptr, | |
706 | complete_to_host_ptr, SAS_OREJ_RESV_AB2); | |
707 | break; | |
708 | ||
709 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | |
710 | ||
711 | isci_request_set_open_reject_status( | |
712 | request, task, response_ptr, status_ptr, | |
713 | complete_to_host_ptr, SAS_OREJ_RESV_AB3); | |
714 | break; | |
715 | ||
716 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | |
717 | ||
718 | isci_request_set_open_reject_status( | |
719 | request, task, response_ptr, status_ptr, | |
720 | complete_to_host_ptr, SAS_OREJ_BAD_DEST); | |
721 | break; | |
722 | ||
723 | case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | |
724 | ||
725 | isci_request_set_open_reject_status( | |
726 | request, task, response_ptr, status_ptr, | |
727 | complete_to_host_ptr, SAS_OREJ_STP_NORES); | |
728 | break; | |
729 | ||
730 | case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | |
731 | ||
732 | isci_request_set_open_reject_status( | |
733 | request, task, response_ptr, status_ptr, | |
734 | complete_to_host_ptr, SAS_OREJ_EPROTO); | |
735 | break; | |
736 | ||
737 | case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | |
738 | ||
739 | isci_request_set_open_reject_status( | |
740 | request, task, response_ptr, status_ptr, | |
741 | complete_to_host_ptr, SAS_OREJ_CONN_RATE); | |
742 | break; | |
743 | ||
744 | case SCU_TASK_DONE_LL_R_ERR: | |
745 | /* Also SCU_TASK_DONE_ACK_NAK_TO: */ | |
746 | case SCU_TASK_DONE_LL_PERR: | |
747 | case SCU_TASK_DONE_LL_SY_TERM: | |
748 | /* Also SCU_TASK_DONE_NAK_ERR:*/ | |
749 | case SCU_TASK_DONE_LL_LF_TERM: | |
750 | /* Also SCU_TASK_DONE_DATA_LEN_ERR: */ | |
751 | case SCU_TASK_DONE_LL_ABORT_ERR: | |
752 | case SCU_TASK_DONE_SEQ_INV_TYPE: | |
753 | /* Also SCU_TASK_DONE_UNEXP_XR: */ | |
754 | case SCU_TASK_DONE_XR_IU_LEN_ERR: | |
755 | case SCU_TASK_DONE_INV_FIS_LEN: | |
756 | /* Also SCU_TASK_DONE_XR_WD_LEN: */ | |
757 | case SCU_TASK_DONE_SDMA_ERR: | |
758 | case SCU_TASK_DONE_OFFSET_ERR: | |
759 | case SCU_TASK_DONE_MAX_PLD_ERR: | |
760 | case SCU_TASK_DONE_LF_ERR: | |
761 | case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */ | |
762 | case SCU_TASK_DONE_SMP_LL_RX_ERR: | |
763 | case SCU_TASK_DONE_UNEXP_DATA: | |
764 | case SCU_TASK_DONE_UNEXP_SDBFIS: | |
765 | case SCU_TASK_DONE_REG_ERR: | |
766 | case SCU_TASK_DONE_SDB_ERR: | |
767 | case SCU_TASK_DONE_TASK_ABORT: | |
768 | default: | |
769 | /* Task in the target is not done. */ | |
770 | *response_ptr = SAS_TASK_UNDELIVERED; | |
771 | *status_ptr = SAM_STAT_TASK_ABORTED; | |
772 | request->complete_in_target = false; | |
773 | ||
774 | *complete_to_host_ptr = isci_perform_error_io_completion; | |
775 | break; | |
776 | } | |
777 | } | |
778 | ||
779 | /** | |
780 | * isci_task_save_for_upper_layer_completion() - This function saves the | |
781 | * request for later completion to the upper layer driver. | |
782 | * @host: This parameter is a pointer to the host on which the the request | |
783 | * should be queued (either as an error or success). | |
784 | * @request: This parameter is the completed request. | |
785 | * @response: This parameter is the response code for the completed task. | |
786 | * @status: This parameter is the status code for the completed task. | |
787 | * | |
788 | * none. | |
789 | */ | |
790 | static void isci_task_save_for_upper_layer_completion( | |
791 | struct isci_host *host, | |
792 | struct isci_request *request, | |
793 | enum service_response response, | |
794 | enum exec_status status, | |
795 | enum isci_completion_selection task_notification_selection) | |
796 | { | |
797 | struct sas_task *task = isci_request_access_task(request); | |
798 | ||
ec6c9638 JS |
799 | task_notification_selection |
800 | = isci_task_set_completion_status(task, response, status, | |
801 | task_notification_selection); | |
6f231dda DW |
802 | |
803 | /* Tasks aborted specifically by a call to the lldd_abort_task | |
804 | * function should not be completed to the host in the regular path. | |
805 | */ | |
806 | switch (task_notification_selection) { | |
807 | ||
808 | case isci_perform_normal_io_completion: | |
809 | ||
810 | /* Normal notification (task_done) */ | |
811 | dev_dbg(&host->pdev->dev, | |
aa145102 | 812 | "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
813 | __func__, |
814 | task, | |
aa145102 JS |
815 | task->task_status.resp, response, |
816 | task->task_status.stat, status); | |
6f231dda DW |
817 | /* Add to the completed list. */ |
818 | list_add(&request->completed_node, | |
819 | &host->requests_to_complete); | |
ec6c9638 JS |
820 | |
821 | /* Take the request off the device's pending request list. */ | |
822 | list_del_init(&request->dev_node); | |
6f231dda DW |
823 | break; |
824 | ||
825 | case isci_perform_aborted_io_completion: | |
a5fde225 JS |
826 | /* No notification to libsas because this request is |
827 | * already in the abort path. | |
6f231dda DW |
828 | */ |
829 | dev_warn(&host->pdev->dev, | |
aa145102 | 830 | "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
831 | __func__, |
832 | task, | |
aa145102 JS |
833 | task->task_status.resp, response, |
834 | task->task_status.stat, status); | |
a5fde225 JS |
835 | |
836 | /* Wake up whatever process was waiting for this | |
837 | * request to complete. | |
838 | */ | |
839 | WARN_ON(request->io_request_completion == NULL); | |
840 | ||
841 | if (request->io_request_completion != NULL) { | |
842 | ||
843 | /* Signal whoever is waiting that this | |
844 | * request is complete. | |
845 | */ | |
846 | complete(request->io_request_completion); | |
847 | } | |
6f231dda DW |
848 | break; |
849 | ||
850 | case isci_perform_error_io_completion: | |
851 | /* Use sas_task_abort */ | |
852 | dev_warn(&host->pdev->dev, | |
aa145102 | 853 | "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
854 | __func__, |
855 | task, | |
aa145102 JS |
856 | task->task_status.resp, response, |
857 | task->task_status.stat, status); | |
6f231dda DW |
858 | /* Add to the aborted list. */ |
859 | list_add(&request->completed_node, | |
11b00c19 | 860 | &host->requests_to_errorback); |
6f231dda DW |
861 | break; |
862 | ||
863 | default: | |
864 | dev_warn(&host->pdev->dev, | |
aa145102 | 865 | "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n", |
6f231dda DW |
866 | __func__, |
867 | task, | |
aa145102 JS |
868 | task->task_status.resp, response, |
869 | task->task_status.stat, status); | |
6f231dda | 870 | |
a5fde225 | 871 | /* Add to the error to libsas list. */ |
6f231dda | 872 | list_add(&request->completed_node, |
11b00c19 | 873 | &host->requests_to_errorback); |
6f231dda DW |
874 | break; |
875 | } | |
876 | } | |
877 | ||
878 | /** | |
879 | * isci_request_io_request_complete() - This function is called by the sci core | |
880 | * when an io request completes. | |
881 | * @isci_host: This parameter specifies the ISCI host object | |
882 | * @request: This parameter is the completed isci_request object. | |
883 | * @completion_status: This parameter specifies the completion status from the | |
884 | * sci core. | |
885 | * | |
886 | * none. | |
887 | */ | |
888 | void isci_request_io_request_complete( | |
889 | struct isci_host *isci_host, | |
890 | struct isci_request *request, | |
891 | enum sci_io_status completion_status) | |
892 | { | |
893 | struct sas_task *task = isci_request_access_task(request); | |
894 | struct ssp_response_iu *resp_iu; | |
895 | void *resp_buf; | |
896 | unsigned long task_flags; | |
6f231dda DW |
897 | struct isci_remote_device *isci_device = request->isci_device; |
898 | enum service_response response = SAS_TASK_UNDELIVERED; | |
899 | enum exec_status status = SAS_ABORTED_TASK; | |
900 | enum isci_request_status request_status; | |
901 | enum isci_completion_selection complete_to_host | |
902 | = isci_perform_normal_io_completion; | |
903 | ||
904 | dev_dbg(&isci_host->pdev->dev, | |
905 | "%s: request = %p, task = %p,\n" | |
906 | "task->data_dir = %d completion_status = 0x%x\n", | |
907 | __func__, | |
908 | request, | |
909 | task, | |
910 | task->data_dir, | |
911 | completion_status); | |
912 | ||
a5fde225 | 913 | spin_lock(&request->state_lock); |
6f231dda | 914 | request_status = isci_request_get_state(request); |
6f231dda DW |
915 | |
916 | /* Decode the request status. Note that if the request has been | |
917 | * aborted by a task management function, we don't care | |
918 | * what the status is. | |
919 | */ | |
920 | switch (request_status) { | |
921 | ||
922 | case aborted: | |
923 | /* "aborted" indicates that the request was aborted by a task | |
924 | * management function, since once a task management request is | |
925 | * perfomed by the device, the request only completes because | |
926 | * of the subsequent driver terminate. | |
927 | * | |
928 | * Aborted also means an external thread is explicitly managing | |
929 | * this request, so that we do not complete it up the stack. | |
930 | * | |
931 | * The target is still there (since the TMF was successful). | |
932 | */ | |
933 | request->complete_in_target = true; | |
934 | response = SAS_TASK_COMPLETE; | |
935 | ||
936 | /* See if the device has been/is being stopped. Note | |
937 | * that we ignore the quiesce state, since we are | |
938 | * concerned about the actual device state. | |
939 | */ | |
940 | if ((isci_device->status == isci_stopping) | |
941 | || (isci_device->status == isci_stopped) | |
942 | ) | |
943 | status = SAS_DEVICE_UNKNOWN; | |
944 | else | |
945 | status = SAS_ABORTED_TASK; | |
946 | ||
947 | complete_to_host = isci_perform_aborted_io_completion; | |
948 | /* This was an aborted request. */ | |
a5fde225 JS |
949 | |
950 | spin_unlock(&request->state_lock); | |
6f231dda DW |
951 | break; |
952 | ||
953 | case aborting: | |
954 | /* aborting means that the task management function tried and | |
955 | * failed to abort the request. We need to note the request | |
956 | * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the | |
957 | * target as down. | |
958 | * | |
959 | * Aborting also means an external thread is explicitly managing | |
960 | * this request, so that we do not complete it up the stack. | |
961 | */ | |
962 | request->complete_in_target = true; | |
963 | response = SAS_TASK_UNDELIVERED; | |
964 | ||
965 | if ((isci_device->status == isci_stopping) || | |
966 | (isci_device->status == isci_stopped)) | |
967 | /* The device has been /is being stopped. Note that | |
968 | * we ignore the quiesce state, since we are | |
969 | * concerned about the actual device state. | |
970 | */ | |
971 | status = SAS_DEVICE_UNKNOWN; | |
972 | else | |
973 | status = SAS_PHY_DOWN; | |
974 | ||
975 | complete_to_host = isci_perform_aborted_io_completion; | |
976 | ||
977 | /* This was an aborted request. */ | |
a5fde225 JS |
978 | |
979 | spin_unlock(&request->state_lock); | |
6f231dda DW |
980 | break; |
981 | ||
982 | case terminating: | |
983 | ||
984 | /* This was an terminated request. This happens when | |
985 | * the I/O is being terminated because of an action on | |
986 | * the device (reset, tear down, etc.), and the I/O needs | |
987 | * to be completed up the stack. | |
988 | */ | |
989 | request->complete_in_target = true; | |
990 | response = SAS_TASK_UNDELIVERED; | |
991 | ||
992 | /* See if the device has been/is being stopped. Note | |
993 | * that we ignore the quiesce state, since we are | |
994 | * concerned about the actual device state. | |
995 | */ | |
996 | if ((isci_device->status == isci_stopping) || | |
997 | (isci_device->status == isci_stopped)) | |
998 | status = SAS_DEVICE_UNKNOWN; | |
999 | else | |
1000 | status = SAS_ABORTED_TASK; | |
1001 | ||
a5fde225 | 1002 | complete_to_host = isci_perform_aborted_io_completion; |
6f231dda DW |
1003 | |
1004 | /* This was a terminated request. */ | |
a5fde225 JS |
1005 | |
1006 | spin_unlock(&request->state_lock); | |
6f231dda DW |
1007 | break; |
1008 | ||
1009 | default: | |
1010 | ||
a5fde225 JS |
1011 | /* The request is done from an SCU HW perspective. */ |
1012 | request->status = completed; | |
1013 | ||
1014 | spin_unlock(&request->state_lock); | |
1015 | ||
6f231dda DW |
1016 | /* This is an active request being completed from the core. */ |
1017 | switch (completion_status) { | |
1018 | ||
1019 | case SCI_IO_FAILURE_RESPONSE_VALID: | |
1020 | dev_dbg(&isci_host->pdev->dev, | |
1021 | "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", | |
1022 | __func__, | |
1023 | request, | |
1024 | task); | |
1025 | ||
1026 | if (sas_protocol_ata(task->task_proto)) { | |
1027 | resp_buf | |
1028 | = scic_stp_io_request_get_d2h_reg_address( | |
1029 | request->sci_request_handle | |
1030 | ); | |
1031 | isci_request_process_stp_response(task, | |
1032 | resp_buf | |
1033 | ); | |
1034 | ||
1035 | } else if (SAS_PROTOCOL_SSP == task->task_proto) { | |
1036 | ||
1037 | /* crack the iu response buffer. */ | |
1038 | resp_iu | |
1039 | = scic_io_request_get_response_iu_address( | |
1040 | request->sci_request_handle | |
1041 | ); | |
1042 | ||
1043 | isci_request_process_response_iu(task, resp_iu, | |
1044 | &isci_host->pdev->dev | |
1045 | ); | |
1046 | ||
1047 | } else if (SAS_PROTOCOL_SMP == task->task_proto) { | |
1048 | ||
1049 | dev_err(&isci_host->pdev->dev, | |
1050 | "%s: SCI_IO_FAILURE_RESPONSE_VALID: " | |
1051 | "SAS_PROTOCOL_SMP protocol\n", | |
1052 | __func__); | |
1053 | ||
1054 | } else | |
1055 | dev_err(&isci_host->pdev->dev, | |
1056 | "%s: unknown protocol\n", __func__); | |
1057 | ||
1058 | /* use the task status set in the task struct by the | |
1059 | * isci_request_process_response_iu call. | |
1060 | */ | |
1061 | request->complete_in_target = true; | |
1062 | response = task->task_status.resp; | |
1063 | status = task->task_status.stat; | |
1064 | break; | |
1065 | ||
1066 | case SCI_IO_SUCCESS: | |
1067 | case SCI_IO_SUCCESS_IO_DONE_EARLY: | |
1068 | ||
1069 | response = SAS_TASK_COMPLETE; | |
1070 | status = SAM_STAT_GOOD; | |
1071 | request->complete_in_target = true; | |
1072 | ||
1073 | if (task->task_proto == SAS_PROTOCOL_SMP) { | |
1074 | ||
1075 | u8 *command_iu_address | |
1076 | = scic_io_request_get_command_iu_address( | |
1077 | request->sci_request_handle | |
1078 | ); | |
1079 | ||
1080 | dev_dbg(&isci_host->pdev->dev, | |
1081 | "%s: SMP protocol completion\n", | |
1082 | __func__); | |
1083 | ||
1084 | sg_copy_from_buffer( | |
1085 | &task->smp_task.smp_resp, 1, | |
1086 | command_iu_address | |
1087 | + sizeof(struct smp_request), | |
1088 | sizeof(struct smp_resp) | |
1089 | ); | |
1090 | } else if (completion_status | |
1091 | == SCI_IO_SUCCESS_IO_DONE_EARLY) { | |
1092 | ||
1093 | /* This was an SSP / STP / SATA transfer. | |
1094 | * There is a possibility that less data than | |
1095 | * the maximum was transferred. | |
1096 | */ | |
1097 | u32 transferred_length | |
1098 | = scic_io_request_get_number_of_bytes_transferred( | |
1099 | request->sci_request_handle); | |
1100 | ||
1101 | task->task_status.residual | |
1102 | = task->total_xfer_len - transferred_length; | |
1103 | ||
1104 | /* If there were residual bytes, call this an | |
1105 | * underrun. | |
1106 | */ | |
1107 | if (task->task_status.residual != 0) | |
1108 | status = SAS_DATA_UNDERRUN; | |
1109 | ||
1110 | dev_dbg(&isci_host->pdev->dev, | |
1111 | "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", | |
1112 | __func__, | |
1113 | status); | |
1114 | ||
1115 | } else | |
1116 | dev_dbg(&isci_host->pdev->dev, | |
1117 | "%s: SCI_IO_SUCCESS\n", | |
1118 | __func__); | |
1119 | ||
1120 | break; | |
1121 | ||
1122 | case SCI_IO_FAILURE_TERMINATED: | |
1123 | dev_dbg(&isci_host->pdev->dev, | |
1124 | "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", | |
1125 | __func__, | |
1126 | request, | |
1127 | task); | |
1128 | ||
1129 | /* The request was terminated explicitly. No handling | |
1130 | * is needed in the SCSI error handler path. | |
1131 | */ | |
1132 | request->complete_in_target = true; | |
1133 | response = SAS_TASK_UNDELIVERED; | |
1134 | ||
1135 | /* See if the device has been/is being stopped. Note | |
1136 | * that we ignore the quiesce state, since we are | |
1137 | * concerned about the actual device state. | |
1138 | */ | |
1139 | if ((isci_device->status == isci_stopping) || | |
1140 | (isci_device->status == isci_stopped)) | |
1141 | status = SAS_DEVICE_UNKNOWN; | |
1142 | else | |
1143 | status = SAS_ABORTED_TASK; | |
1144 | ||
1145 | complete_to_host = isci_perform_normal_io_completion; | |
1146 | break; | |
1147 | ||
1148 | case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: | |
1149 | ||
1150 | isci_request_handle_controller_specific_errors( | |
1151 | isci_device, request, task, &response, &status, | |
1152 | &complete_to_host); | |
1153 | ||
1154 | break; | |
1155 | ||
1156 | case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: | |
1157 | /* This is a special case, in that the I/O completion | |
1158 | * is telling us that the device needs a reset. | |
1159 | * In order for the device reset condition to be | |
1160 | * noticed, the I/O has to be handled in the error | |
1161 | * handler. Set the reset flag and cause the | |
1162 | * SCSI error thread to be scheduled. | |
1163 | */ | |
1164 | spin_lock_irqsave(&task->task_state_lock, task_flags); | |
1165 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | |
1166 | spin_unlock_irqrestore(&task->task_state_lock, task_flags); | |
1167 | ||
aa145102 JS |
1168 | /* Fail the I/O. */ |
1169 | response = SAS_TASK_UNDELIVERED; | |
1170 | status = SAM_STAT_TASK_ABORTED; | |
1171 | ||
6f231dda DW |
1172 | complete_to_host = isci_perform_error_io_completion; |
1173 | request->complete_in_target = false; | |
1174 | break; | |
1175 | ||
1176 | default: | |
1177 | /* Catch any otherwise unhandled error codes here. */ | |
1178 | dev_warn(&isci_host->pdev->dev, | |
1179 | "%s: invalid completion code: 0x%x - " | |
1180 | "isci_request = %p\n", | |
1181 | __func__, completion_status, request); | |
1182 | ||
1183 | response = SAS_TASK_UNDELIVERED; | |
1184 | ||
1185 | /* See if the device has been/is being stopped. Note | |
1186 | * that we ignore the quiesce state, since we are | |
1187 | * concerned about the actual device state. | |
1188 | */ | |
1189 | if ((isci_device->status == isci_stopping) || | |
1190 | (isci_device->status == isci_stopped)) | |
1191 | status = SAS_DEVICE_UNKNOWN; | |
1192 | else | |
1193 | status = SAS_ABORTED_TASK; | |
1194 | ||
1195 | complete_to_host = isci_perform_error_io_completion; | |
1196 | request->complete_in_target = false; | |
1197 | break; | |
1198 | } | |
1199 | break; | |
1200 | } | |
1201 | ||
1202 | isci_request_unmap_sgl(request, isci_host->pdev); | |
1203 | ||
1204 | /* Put the completed request on the correct list */ | |
1205 | isci_task_save_for_upper_layer_completion(isci_host, request, response, | |
1206 | status, complete_to_host | |
1207 | ); | |
1208 | ||
1209 | /* complete the io request to the core. */ | |
1210 | scic_controller_complete_io( | |
1211 | isci_host->core_controller, | |
3a97eec6 | 1212 | to_sci_dev(isci_device), |
6f231dda DW |
1213 | request->sci_request_handle |
1214 | ); | |
1215 | /* NULL the request handle so it cannot be completed or | |
1216 | * terminated again, and to cause any calls into abort | |
1217 | * task to recognize the already completed case. | |
1218 | */ | |
1219 | request->sci_request_handle = NULL; | |
1220 | ||
6f231dda DW |
1221 | isci_host_can_dequeue(isci_host, 1); |
1222 | } | |
1223 | ||
1224 | /** | |
1225 | * isci_request_io_request_get_transfer_length() - This function is called by | |
1226 | * the sci core to retrieve the transfer length for a given request. | |
1227 | * @request: This parameter is the isci_request object. | |
1228 | * | |
1229 | * length of transfer for specified request. | |
1230 | */ | |
1231 | u32 isci_request_io_request_get_transfer_length(struct isci_request *request) | |
1232 | { | |
1233 | struct sas_task *task = isci_request_access_task(request); | |
1234 | ||
1235 | dev_dbg(&request->isci_host->pdev->dev, | |
1236 | "%s: total_xfer_len: %d\n", | |
1237 | __func__, | |
1238 | task->total_xfer_len); | |
1239 | return task->total_xfer_len; | |
1240 | } | |
1241 | ||
1242 | ||
1243 | /** | |
1244 | * isci_request_io_request_get_data_direction() - This function is called by | |
1245 | * the sci core to retrieve the data direction for a given request. | |
1246 | * @request: This parameter is the isci_request object. | |
1247 | * | |
1248 | * data direction for specified request. | |
1249 | */ | |
82d29928 | 1250 | enum dma_data_direction isci_request_io_request_get_data_direction( |
6f231dda DW |
1251 | struct isci_request *request) |
1252 | { | |
1253 | struct sas_task *task = isci_request_access_task(request); | |
6f231dda | 1254 | |
82d29928 | 1255 | return task->data_dir; |
6f231dda DW |
1256 | } |
1257 | ||
1258 | /** | |
1259 | * isci_request_sge_get_address_field() - This function is called by the sci | |
1260 | * core to retrieve the address field contents for a given sge. | |
1261 | * @request: This parameter is the isci_request object. | |
1262 | * @sge_address: This parameter is the sge. | |
1263 | * | |
1264 | * physical address in the specified sge. | |
1265 | */ | |
6f231dda DW |
1266 | |
1267 | ||
1268 | /** | |
1269 | * isci_request_sge_get_length_field() - This function is called by the sci | |
1270 | * core to retrieve the length field contents for a given sge. | |
1271 | * @request: This parameter is the isci_request object. | |
1272 | * @sge_address: This parameter is the sge. | |
1273 | * | |
1274 | * length field value in the specified sge. | |
1275 | */ | |
6f231dda DW |
1276 | |
1277 | ||
1278 | /** | |
1279 | * isci_request_ssp_io_request_get_cdb_address() - This function is called by | |
1280 | * the sci core to retrieve the cdb address for a given request. | |
1281 | * @request: This parameter is the isci_request object. | |
1282 | * | |
1283 | * cdb address for specified request. | |
1284 | */ | |
1285 | void *isci_request_ssp_io_request_get_cdb_address( | |
1286 | struct isci_request *request) | |
1287 | { | |
1288 | struct sas_task *task = isci_request_access_task(request); | |
1289 | ||
1290 | dev_dbg(&request->isci_host->pdev->dev, | |
1291 | "%s: request->task->ssp_task.cdb = %p\n", | |
1292 | __func__, | |
1293 | task->ssp_task.cdb); | |
1294 | return task->ssp_task.cdb; | |
1295 | } | |
1296 | ||
1297 | ||
1298 | /** | |
1299 | * isci_request_ssp_io_request_get_cdb_length() - This function is called by | |
1300 | * the sci core to retrieve the cdb length for a given request. | |
1301 | * @request: This parameter is the isci_request object. | |
1302 | * | |
1303 | * cdb length for specified request. | |
1304 | */ | |
1305 | u32 isci_request_ssp_io_request_get_cdb_length( | |
1306 | struct isci_request *request) | |
1307 | { | |
1308 | return 16; | |
1309 | } | |
1310 | ||
1311 | ||
1312 | /** | |
1313 | * isci_request_ssp_io_request_get_lun() - This function is called by the sci | |
1314 | * core to retrieve the lun for a given request. | |
1315 | * @request: This parameter is the isci_request object. | |
1316 | * | |
1317 | * lun for specified request. | |
1318 | */ | |
1319 | u32 isci_request_ssp_io_request_get_lun( | |
1320 | struct isci_request *request) | |
1321 | { | |
1322 | struct sas_task *task = isci_request_access_task(request); | |
1323 | ||
1324 | #ifdef DEBUG | |
1325 | int i; | |
1326 | ||
1327 | for (i = 0; i < 8; i++) | |
1328 | dev_dbg(&request->isci_host->pdev->dev, | |
83f5eeef DW |
1329 | "%s: task->ssp_task.LUN[%d] = %x\n", |
1330 | __func__, i, task->ssp_task.LUN[i]); | |
6f231dda DW |
1331 | |
1332 | #endif | |
1333 | ||
1334 | return task->ssp_task.LUN[0]; | |
1335 | } | |
1336 | ||
1337 | ||
1338 | /** | |
1339 | * isci_request_ssp_io_request_get_task_attribute() - This function is called | |
1340 | * by the sci core to retrieve the task attribute for a given request. | |
1341 | * @request: This parameter is the isci_request object. | |
1342 | * | |
1343 | * task attribute for specified request. | |
1344 | */ | |
1345 | u32 isci_request_ssp_io_request_get_task_attribute( | |
1346 | struct isci_request *request) | |
1347 | { | |
1348 | struct sas_task *task = isci_request_access_task(request); | |
1349 | ||
1350 | dev_dbg(&request->isci_host->pdev->dev, | |
1351 | "%s: request->task->ssp_task.task_attr = %x\n", | |
1352 | __func__, | |
1353 | task->ssp_task.task_attr); | |
1354 | ||
1355 | return task->ssp_task.task_attr; | |
1356 | } | |
1357 | ||
1358 | ||
1359 | /** | |
1360 | * isci_request_ssp_io_request_get_command_priority() - This function is called | |
1361 | * by the sci core to retrieve the command priority for a given request. | |
1362 | * @request: This parameter is the isci_request object. | |
1363 | * | |
1364 | * command priority for specified request. | |
1365 | */ | |
1366 | u32 isci_request_ssp_io_request_get_command_priority( | |
1367 | struct isci_request *request) | |
1368 | { | |
1369 | struct sas_task *task = isci_request_access_task(request); | |
1370 | ||
1371 | dev_dbg(&request->isci_host->pdev->dev, | |
1372 | "%s: request->task->ssp_task.task_prio = %x\n", | |
1373 | __func__, | |
1374 | task->ssp_task.task_prio); | |
1375 | ||
1376 | return task->ssp_task.task_prio; | |
1377 | } |