blob: 55859d5331b13a58b2f109a3f8732d4237db4edc [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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"
Dan Williams6f231dd2011-07-02 22:56:22 -070057#include "task.h"
58#include "request.h"
59#include "sata.h"
60#include "scu_completion_codes.h"
Dan Williams5dec6f42011-05-10 02:28:49 -070061#include "scu_event_codes.h"
Dave Jiang2ec53eb2011-05-04 18:01:22 -070062#include "sas.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070063
Dan Williams312e0c22011-06-28 13:47:09 -070064static struct scu_sgl_element_pair *to_sgl_element_pair(struct scic_sds_request *sci_req,
65 int idx)
66{
67 if (idx == 0)
68 return &sci_req->tc->sgl_pair_ab;
69 else if (idx == 1)
70 return &sci_req->tc->sgl_pair_cd;
71 else if (idx < 0)
72 return NULL;
73 else
74 return &sci_req->sg_table[idx - 2];
Dan Williams6f231dd2011-07-02 22:56:22 -070075}
76
Dan Williams312e0c22011-06-28 13:47:09 -070077static dma_addr_t to_sgl_element_pair_dma(struct scic_sds_controller *scic,
78 struct scic_sds_request *sci_req, u32 idx)
79{
80 u32 offset;
81
82 if (idx == 0) {
83 offset = (void *) &sci_req->tc->sgl_pair_ab -
84 (void *) &scic->task_context_table[0];
85 return scic->task_context_dma + offset;
86 } else if (idx == 1) {
87 offset = (void *) &sci_req->tc->sgl_pair_cd -
88 (void *) &scic->task_context_table[0];
89 return scic->task_context_dma + offset;
90 }
91
92 return scic_io_request_get_dma_addr(sci_req, &sci_req->sg_table[idx - 2]);
93}
94
95static void init_sgl_element(struct scu_sgl_element *e, struct scatterlist *sg)
96{
97 e->length = sg_dma_len(sg);
98 e->address_upper = upper_32_bits(sg_dma_address(sg));
99 e->address_lower = lower_32_bits(sg_dma_address(sg));
100 e->address_modifier = 0;
101}
102
Dan Williams5dec6f42011-05-10 02:28:49 -0700103static void scic_sds_request_build_sgl(struct scic_sds_request *sds_request)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700104{
105 struct isci_request *isci_request = sci_req_to_ireq(sds_request);
106 struct isci_host *isci_host = isci_request->isci_host;
Dan Williams312e0c22011-06-28 13:47:09 -0700107 struct scic_sds_controller *scic = &isci_host->sci;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700108 struct sas_task *task = isci_request_access_task(isci_request);
109 struct scatterlist *sg = NULL;
110 dma_addr_t dma_addr;
111 u32 sg_idx = 0;
112 struct scu_sgl_element_pair *scu_sg = NULL;
113 struct scu_sgl_element_pair *prev_sg = NULL;
114
115 if (task->num_scatter > 0) {
116 sg = task->scatter;
117
118 while (sg) {
Dan Williams312e0c22011-06-28 13:47:09 -0700119 scu_sg = to_sgl_element_pair(sds_request, sg_idx);
120 init_sgl_element(&scu_sg->A, sg);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700121 sg = sg_next(sg);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700122 if (sg) {
Dan Williams312e0c22011-06-28 13:47:09 -0700123 init_sgl_element(&scu_sg->B, sg);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700124 sg = sg_next(sg);
125 } else
Dan Williams312e0c22011-06-28 13:47:09 -0700126 memset(&scu_sg->B, 0, sizeof(scu_sg->B));
Dan Williamsf1f52e72011-05-10 02:28:45 -0700127
128 if (prev_sg) {
Dan Williams312e0c22011-06-28 13:47:09 -0700129 dma_addr = to_sgl_element_pair_dma(scic,
130 sds_request,
131 sg_idx);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700132
133 prev_sg->next_pair_upper =
134 upper_32_bits(dma_addr);
135 prev_sg->next_pair_lower =
136 lower_32_bits(dma_addr);
137 }
138
139 prev_sg = scu_sg;
140 sg_idx++;
141 }
142 } else { /* handle when no sg */
Dan Williams312e0c22011-06-28 13:47:09 -0700143 scu_sg = to_sgl_element_pair(sds_request, sg_idx);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700144
145 dma_addr = dma_map_single(&isci_host->pdev->dev,
146 task->scatter,
147 task->total_xfer_len,
148 task->data_dir);
149
150 isci_request->zero_scatter_daddr = dma_addr;
151
152 scu_sg->A.length = task->total_xfer_len;
153 scu_sg->A.address_upper = upper_32_bits(dma_addr);
154 scu_sg->A.address_lower = lower_32_bits(dma_addr);
155 }
156
157 if (scu_sg) {
158 scu_sg->next_pair_upper = 0;
159 scu_sg->next_pair_lower = 0;
160 }
161}
162
Dan Williamsf1f52e72011-05-10 02:28:45 -0700163static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request *sci_req)
164{
165 struct ssp_cmd_iu *cmd_iu;
166 struct isci_request *ireq = sci_req_to_ireq(sci_req);
167 struct sas_task *task = isci_request_access_task(ireq);
168
169 cmd_iu = &sci_req->ssp.cmd;
170
171 memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8);
172 cmd_iu->add_cdb_len = 0;
173 cmd_iu->_r_a = 0;
174 cmd_iu->_r_b = 0;
175 cmd_iu->en_fburst = 0; /* unsupported */
176 cmd_iu->task_prio = task->ssp_task.task_prio;
177 cmd_iu->task_attr = task->ssp_task.task_attr;
178 cmd_iu->_r_c = 0;
179
180 sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cdb,
181 sizeof(task->ssp_task.cdb) / sizeof(u32));
182}
183
184static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request *sci_req)
185{
186 struct ssp_task_iu *task_iu;
187 struct isci_request *ireq = sci_req_to_ireq(sci_req);
188 struct sas_task *task = isci_request_access_task(ireq);
189 struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
190
191 task_iu = &sci_req->ssp.tmf;
192
193 memset(task_iu, 0, sizeof(struct ssp_task_iu));
194
195 memcpy(task_iu->LUN, task->ssp_task.LUN, 8);
196
197 task_iu->task_func = isci_tmf->tmf_code;
198 task_iu->task_tag =
199 (ireq->ttype == tmf_task) ?
200 isci_tmf->io_tag :
201 SCI_CONTROLLER_INVALID_IO_TAG;
202}
203
204/**
205 * This method is will fill in the SCU Task Context for any type of SSP request.
206 * @sci_req:
207 * @task_context:
208 *
209 */
210static void scu_ssp_reqeust_construct_task_context(
211 struct scic_sds_request *sds_request,
212 struct scu_task_context *task_context)
213{
214 dma_addr_t dma_addr;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700215 struct scic_sds_remote_device *target_device;
216 struct scic_sds_port *target_port;
217
Dan Williamsf1f52e72011-05-10 02:28:45 -0700218 target_device = scic_sds_request_get_device(sds_request);
219 target_port = scic_sds_request_get_port(sds_request);
220
221 /* Fill in the TC with the its required data */
222 task_context->abort = 0;
223 task_context->priority = 0;
224 task_context->initiator_request = 1;
225 task_context->connection_rate = target_device->connection_rate;
226 task_context->protocol_engine_index =
227 scic_sds_controller_get_protocol_engine_group(controller);
228 task_context->logical_port_index =
229 scic_sds_port_get_index(target_port);
230 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
231 task_context->valid = SCU_TASK_CONTEXT_VALID;
232 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
233
234 task_context->remote_node_index =
235 scic_sds_remote_device_get_index(sds_request->target_device);
236 task_context->command_code = 0;
237
238 task_context->link_layer_control = 0;
239 task_context->do_not_dma_ssp_good_response = 1;
240 task_context->strict_ordering = 0;
241 task_context->control_frame = 0;
242 task_context->timeout_enable = 0;
243 task_context->block_guard_enable = 0;
244
245 task_context->address_modifier = 0;
246
247 /* task_context->type.ssp.tag = sci_req->io_tag; */
248 task_context->task_phase = 0x01;
249
Dan Williams312e0c22011-06-28 13:47:09 -0700250 sds_request->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
251 (scic_sds_controller_get_protocol_engine_group(controller) <<
252 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
253 (scic_sds_port_get_index(target_port) <<
254 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
255 ISCI_TAG_TCI(sds_request->io_tag));
Dan Williamsf1f52e72011-05-10 02:28:45 -0700256
257 /*
258 * Copy the physical address for the command buffer to the
259 * SCU Task Context
260 */
261 dma_addr = scic_io_request_get_dma_addr(sds_request,
262 &sds_request->ssp.cmd);
263
264 task_context->command_iu_upper = upper_32_bits(dma_addr);
265 task_context->command_iu_lower = lower_32_bits(dma_addr);
266
267 /*
268 * Copy the physical address for the response buffer to the
269 * SCU Task Context
270 */
271 dma_addr = scic_io_request_get_dma_addr(sds_request,
272 &sds_request->ssp.rsp);
273
274 task_context->response_iu_upper = upper_32_bits(dma_addr);
275 task_context->response_iu_lower = lower_32_bits(dma_addr);
276}
277
278/**
279 * This method is will fill in the SCU Task Context for a SSP IO request.
280 * @sci_req:
281 *
282 */
Dan Williams312e0c22011-06-28 13:47:09 -0700283static void scu_ssp_io_request_construct_task_context(struct scic_sds_request *sci_req,
284 enum dma_data_direction dir,
285 u32 len)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700286{
Dan Williams312e0c22011-06-28 13:47:09 -0700287 struct scu_task_context *task_context = sci_req->tc;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700288
289 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
290
291 task_context->ssp_command_iu_length =
292 sizeof(struct ssp_cmd_iu) / sizeof(u32);
293 task_context->type.ssp.frame_type = SSP_COMMAND;
294
295 switch (dir) {
296 case DMA_FROM_DEVICE:
297 case DMA_NONE:
298 default:
299 task_context->task_type = SCU_TASK_TYPE_IOREAD;
300 break;
301 case DMA_TO_DEVICE:
302 task_context->task_type = SCU_TASK_TYPE_IOWRITE;
303 break;
304 }
305
306 task_context->transfer_length_bytes = len;
307
308 if (task_context->transfer_length_bytes > 0)
309 scic_sds_request_build_sgl(sci_req);
310}
311
Dan Williamsf1f52e72011-05-10 02:28:45 -0700312/**
313 * This method will fill in the SCU Task Context for a SSP Task request. The
314 * following important settings are utilized: -# priority ==
315 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
316 * ahead of other task destined for the same Remote Node. -# task_type ==
317 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
318 * (i.e. non-raw frame) is being utilized to perform task management. -#
319 * control_frame == 1. This ensures that the proper endianess is set so
320 * that the bytes are transmitted in the right order for a task frame.
321 * @sci_req: This parameter specifies the task request object being
322 * constructed.
323 *
324 */
Dan Williams312e0c22011-06-28 13:47:09 -0700325static void scu_ssp_task_request_construct_task_context(struct scic_sds_request *sci_req)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700326{
Dan Williams312e0c22011-06-28 13:47:09 -0700327 struct scu_task_context *task_context = sci_req->tc;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700328
329 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
330
331 task_context->control_frame = 1;
332 task_context->priority = SCU_TASK_PRIORITY_HIGH;
333 task_context->task_type = SCU_TASK_TYPE_RAW_FRAME;
334 task_context->transfer_length_bytes = 0;
335 task_context->type.ssp.frame_type = SSP_TASK;
336 task_context->ssp_command_iu_length =
337 sizeof(struct ssp_task_iu) / sizeof(u32);
338}
339
Dan Williamsf1f52e72011-05-10 02:28:45 -0700340/**
Dan Williams5dec6f42011-05-10 02:28:49 -0700341 * This method is will fill in the SCU Task Context for any type of SATA
342 * request. This is called from the various SATA constructors.
343 * @sci_req: The general IO request object which is to be used in
344 * constructing the SCU task context.
345 * @task_context: The buffer pointer for the SCU task context which is being
346 * constructed.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700347 *
Dan Williams5dec6f42011-05-10 02:28:49 -0700348 * The general io request construction is complete. The buffer assignment for
349 * the command buffer is complete. none Revisit task context construction to
350 * determine what is common for SSP/SMP/STP task context structures.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700351 */
Dan Williams5dec6f42011-05-10 02:28:49 -0700352static void scu_sata_reqeust_construct_task_context(
353 struct scic_sds_request *sci_req,
354 struct scu_task_context *task_context)
355{
356 dma_addr_t dma_addr;
Dan Williams5dec6f42011-05-10 02:28:49 -0700357 struct scic_sds_remote_device *target_device;
358 struct scic_sds_port *target_port;
359
Dan Williams5dec6f42011-05-10 02:28:49 -0700360 target_device = scic_sds_request_get_device(sci_req);
361 target_port = scic_sds_request_get_port(sci_req);
362
363 /* Fill in the TC with the its required data */
364 task_context->abort = 0;
365 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
366 task_context->initiator_request = 1;
367 task_context->connection_rate = target_device->connection_rate;
368 task_context->protocol_engine_index =
369 scic_sds_controller_get_protocol_engine_group(controller);
370 task_context->logical_port_index =
371 scic_sds_port_get_index(target_port);
372 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP;
373 task_context->valid = SCU_TASK_CONTEXT_VALID;
374 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
375
376 task_context->remote_node_index =
377 scic_sds_remote_device_get_index(sci_req->target_device);
378 task_context->command_code = 0;
379
380 task_context->link_layer_control = 0;
381 task_context->do_not_dma_ssp_good_response = 1;
382 task_context->strict_ordering = 0;
383 task_context->control_frame = 0;
384 task_context->timeout_enable = 0;
385 task_context->block_guard_enable = 0;
386
387 task_context->address_modifier = 0;
388 task_context->task_phase = 0x01;
389
390 task_context->ssp_command_iu_length =
391 (sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32);
392
393 /* Set the first word of the H2D REG FIS */
394 task_context->type.words[0] = *(u32 *)&sci_req->stp.cmd;
395
Dan Williams312e0c22011-06-28 13:47:09 -0700396 sci_req->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
397 (scic_sds_controller_get_protocol_engine_group(controller) <<
398 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
399 (scic_sds_port_get_index(target_port) <<
400 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
401 ISCI_TAG_TCI(sci_req->io_tag));
Dan Williams5dec6f42011-05-10 02:28:49 -0700402 /*
403 * Copy the physical address for the command buffer to the SCU Task
404 * Context. We must offset the command buffer by 4 bytes because the
405 * first 4 bytes are transfered in the body of the TC.
406 */
407 dma_addr = scic_io_request_get_dma_addr(sci_req,
408 ((char *) &sci_req->stp.cmd) +
409 sizeof(u32));
410
411 task_context->command_iu_upper = upper_32_bits(dma_addr);
412 task_context->command_iu_lower = lower_32_bits(dma_addr);
413
414 /* SATA Requests do not have a response buffer */
415 task_context->response_iu_upper = 0;
416 task_context->response_iu_lower = 0;
417}
418
Dan Williams312e0c22011-06-28 13:47:09 -0700419static void scu_stp_raw_request_construct_task_context(struct scic_sds_request *sci_req)
Dan Williams5dec6f42011-05-10 02:28:49 -0700420{
Dan Williams312e0c22011-06-28 13:47:09 -0700421 struct scu_task_context *task_context = sci_req->tc;
Dan Williams5dec6f42011-05-10 02:28:49 -0700422
423 scu_sata_reqeust_construct_task_context(sci_req, task_context);
424
425 task_context->control_frame = 0;
426 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
427 task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME;
428 task_context->type.stp.fis_type = FIS_REGH2D;
429 task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32);
430}
431
432static enum sci_status
433scic_sds_stp_pio_request_construct(struct scic_sds_request *sci_req,
434 bool copy_rx_frame)
435{
436 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
437 struct scic_sds_stp_pio_request *pio = &stp_req->type.pio;
438
Dan Williams312e0c22011-06-28 13:47:09 -0700439 scu_stp_raw_request_construct_task_context(sci_req);
Dan Williams5dec6f42011-05-10 02:28:49 -0700440
441 pio->current_transfer_bytes = 0;
442 pio->ending_error = 0;
443 pio->ending_status = 0;
444
445 pio->request_current.sgl_offset = 0;
446 pio->request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
447
448 if (copy_rx_frame) {
449 scic_sds_request_build_sgl(sci_req);
Dan Williams312e0c22011-06-28 13:47:09 -0700450 pio->request_current.sgl_index = 0;
Dan Williams5dec6f42011-05-10 02:28:49 -0700451 } else {
452 /* The user does not want the data copied to the SGL buffer location */
Dan Williams312e0c22011-06-28 13:47:09 -0700453 pio->request_current.sgl_index = -1;
Dan Williams5dec6f42011-05-10 02:28:49 -0700454 }
455
456 return SCI_SUCCESS;
457}
458
459/**
460 *
461 * @sci_req: This parameter specifies the request to be constructed as an
462 * optimized request.
463 * @optimized_task_type: This parameter specifies whether the request is to be
464 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
465 * value of 1 indicates NCQ.
466 *
467 * This method will perform request construction common to all types of STP
468 * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
469 * returns an indication as to whether the construction was successful.
470 */
471static void scic_sds_stp_optimized_request_construct(struct scic_sds_request *sci_req,
472 u8 optimized_task_type,
473 u32 len,
474 enum dma_data_direction dir)
475{
Dan Williams312e0c22011-06-28 13:47:09 -0700476 struct scu_task_context *task_context = sci_req->tc;
Dan Williams5dec6f42011-05-10 02:28:49 -0700477
478 /* Build the STP task context structure */
479 scu_sata_reqeust_construct_task_context(sci_req, task_context);
480
481 /* Copy over the SGL elements */
482 scic_sds_request_build_sgl(sci_req);
483
484 /* Copy over the number of bytes to be transfered */
485 task_context->transfer_length_bytes = len;
486
487 if (dir == DMA_TO_DEVICE) {
488 /*
489 * The difference between the DMA IN and DMA OUT request task type
490 * values are consistent with the difference between FPDMA READ
491 * and FPDMA WRITE values. Add the supplied task type parameter
492 * to this difference to set the task type properly for this
493 * DATA OUT (WRITE) case. */
494 task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT
495 - SCU_TASK_TYPE_DMA_IN);
496 } else {
497 /*
498 * For the DATA IN (READ) case, simply save the supplied
499 * optimized task type. */
500 task_context->task_type = optimized_task_type;
501 }
502}
503
504
505
Dan Williamsf1f52e72011-05-10 02:28:45 -0700506static enum sci_status
507scic_io_request_construct_sata(struct scic_sds_request *sci_req,
508 u32 len,
509 enum dma_data_direction dir,
510 bool copy)
Dan Williams6f231dd2011-07-02 22:56:22 -0700511{
Dan Williams6f231dd2011-07-02 22:56:22 -0700512 enum sci_status status = SCI_SUCCESS;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700513 struct isci_request *ireq = sci_req_to_ireq(sci_req);
514 struct sas_task *task = isci_request_access_task(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700515
Dan Williamsf1f52e72011-05-10 02:28:45 -0700516 /* check for management protocols */
517 if (ireq->ttype == tmf_task) {
518 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700519
Dan Williamsf1f52e72011-05-10 02:28:45 -0700520 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
Dan Williams5dec6f42011-05-10 02:28:49 -0700521 tmf->tmf_code == isci_tmf_sata_srst_low) {
Dan Williams312e0c22011-06-28 13:47:09 -0700522 scu_stp_raw_request_construct_task_context(sci_req);
Dan Williams5dec6f42011-05-10 02:28:49 -0700523 return SCI_SUCCESS;
524 } else {
Dan Williamsf1f52e72011-05-10 02:28:45 -0700525 dev_err(scic_to_dev(sci_req->owning_controller),
526 "%s: Request 0x%p received un-handled SAT "
527 "management protocol 0x%x.\n",
528 __func__, sci_req, tmf->tmf_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700529
Dan Williamsf1f52e72011-05-10 02:28:45 -0700530 return SCI_FAILURE;
531 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700532 }
533
Dan Williamsf1f52e72011-05-10 02:28:45 -0700534 if (!sas_protocol_ata(task->task_proto)) {
535 dev_err(scic_to_dev(sci_req->owning_controller),
536 "%s: Non-ATA protocol in SATA path: 0x%x\n",
537 __func__,
538 task->task_proto);
Dan Williams6f231dd2011-07-02 22:56:22 -0700539 return SCI_FAILURE;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700540
Dan Williams6f231dd2011-07-02 22:56:22 -0700541 }
542
Dan Williamsf1f52e72011-05-10 02:28:45 -0700543 /* non data */
Dan Williams5dec6f42011-05-10 02:28:49 -0700544 if (task->data_dir == DMA_NONE) {
Dan Williams312e0c22011-06-28 13:47:09 -0700545 scu_stp_raw_request_construct_task_context(sci_req);
Dan Williams5dec6f42011-05-10 02:28:49 -0700546 return SCI_SUCCESS;
547 }
Dan Williamsf1f52e72011-05-10 02:28:45 -0700548
549 /* NCQ */
Dan Williams5dec6f42011-05-10 02:28:49 -0700550 if (task->ata_task.use_ncq) {
551 scic_sds_stp_optimized_request_construct(sci_req,
552 SCU_TASK_TYPE_FPDMAQ_READ,
553 len, dir);
554 return SCI_SUCCESS;
555 }
Dan Williamsf1f52e72011-05-10 02:28:45 -0700556
557 /* DMA */
Dan Williams5dec6f42011-05-10 02:28:49 -0700558 if (task->ata_task.dma_xfer) {
559 scic_sds_stp_optimized_request_construct(sci_req,
560 SCU_TASK_TYPE_DMA_IN,
561 len, dir);
562 return SCI_SUCCESS;
563 } else /* PIO */
Dan Williamsf1f52e72011-05-10 02:28:45 -0700564 return scic_sds_stp_pio_request_construct(sci_req, copy);
565
566 return status;
567}
568
569static enum sci_status scic_io_request_construct_basic_ssp(struct scic_sds_request *sci_req)
570{
571 struct isci_request *ireq = sci_req_to_ireq(sci_req);
572 struct sas_task *task = isci_request_access_task(ireq);
573
574 sci_req->protocol = SCIC_SSP_PROTOCOL;
575
576 scu_ssp_io_request_construct_task_context(sci_req,
577 task->data_dir,
578 task->total_xfer_len);
579
580 scic_sds_io_request_build_ssp_command_iu(sci_req);
581
Edmund Nadolskie3013702011-06-02 00:10:43 +0000582 sci_change_state(&sci_req->sm, SCI_REQ_CONSTRUCTED);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700583
584 return SCI_SUCCESS;
585}
586
587enum sci_status scic_task_request_construct_ssp(
588 struct scic_sds_request *sci_req)
589{
590 /* Construct the SSP Task SCU Task Context */
591 scu_ssp_task_request_construct_task_context(sci_req);
592
593 /* Fill in the SSP Task IU */
594 scic_sds_task_request_build_ssp_task_iu(sci_req);
595
Edmund Nadolskie3013702011-06-02 00:10:43 +0000596 sci_change_state(&sci_req->sm, SCI_REQ_CONSTRUCTED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700597
598 return SCI_SUCCESS;
599}
600
Dan Williamsf1f52e72011-05-10 02:28:45 -0700601static enum sci_status scic_io_request_construct_basic_sata(struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700602{
Dan Williamsf1f52e72011-05-10 02:28:45 -0700603 enum sci_status status;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700604 bool copy = false;
605 struct isci_request *isci_request = sci_req_to_ireq(sci_req);
606 struct sas_task *task = isci_request_access_task(isci_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700607
Dan Williamsf1f52e72011-05-10 02:28:45 -0700608 sci_req->protocol = SCIC_STP_PROTOCOL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700609
Dan Williamsf1f52e72011-05-10 02:28:45 -0700610 copy = (task->data_dir == DMA_NONE) ? false : true;
Dan Williams6f231dd2011-07-02 22:56:22 -0700611
Dan Williamsf1f52e72011-05-10 02:28:45 -0700612 status = scic_io_request_construct_sata(sci_req,
613 task->total_xfer_len,
614 task->data_dir,
615 copy);
Dan Williams6f231dd2011-07-02 22:56:22 -0700616
Dan Williamsf1f52e72011-05-10 02:28:45 -0700617 if (status == SCI_SUCCESS)
Edmund Nadolskie3013702011-06-02 00:10:43 +0000618 sci_change_state(&sci_req->sm, SCI_REQ_CONSTRUCTED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700619
Dan Williamsf1f52e72011-05-10 02:28:45 -0700620 return status;
Dan Williams6f231dd2011-07-02 22:56:22 -0700621}
622
Dan Williamsf1f52e72011-05-10 02:28:45 -0700623enum sci_status scic_task_request_construct_sata(struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700624{
Dan Williamsf1f52e72011-05-10 02:28:45 -0700625 enum sci_status status = SCI_SUCCESS;
626 struct isci_request *ireq = sci_req_to_ireq(sci_req);
Dan Williams6f231dd2011-07-02 22:56:22 -0700627
Dan Williamsf1f52e72011-05-10 02:28:45 -0700628 /* check for management protocols */
629 if (ireq->ttype == tmf_task) {
630 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700631
Dan Williamsf1f52e72011-05-10 02:28:45 -0700632 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
633 tmf->tmf_code == isci_tmf_sata_srst_low) {
Dan Williams312e0c22011-06-28 13:47:09 -0700634 scu_stp_raw_request_construct_task_context(sci_req);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700635 } else {
636 dev_err(scic_to_dev(sci_req->owning_controller),
637 "%s: Request 0x%p received un-handled SAT "
638 "Protocol 0x%x.\n",
639 __func__, sci_req, tmf->tmf_code);
640
641 return SCI_FAILURE;
642 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700643 }
Dan Williamsf1f52e72011-05-10 02:28:45 -0700644
Dan Williams5dec6f42011-05-10 02:28:49 -0700645 if (status != SCI_SUCCESS)
646 return status;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000647 sci_change_state(&sci_req->sm, SCI_REQ_CONSTRUCTED);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700648
649 return status;
Dan Williams6f231dd2011-07-02 22:56:22 -0700650}
651
652/**
Dan Williamsf1f52e72011-05-10 02:28:45 -0700653 * sci_req_tx_bytes - bytes transferred when reply underruns request
654 * @sci_req: request that was terminated early
Dan Williams6f231dd2011-07-02 22:56:22 -0700655 */
Dan Williamsf1f52e72011-05-10 02:28:45 -0700656#define SCU_TASK_CONTEXT_SRAM 0x200000
657static u32 sci_req_tx_bytes(struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700658{
Dan Williamsf1f52e72011-05-10 02:28:45 -0700659 struct scic_sds_controller *scic = sci_req->owning_controller;
660 u32 ret_val = 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700661
Dan Williamsf1f52e72011-05-10 02:28:45 -0700662 if (readl(&scic->smu_registers->address_modifier) == 0) {
663 void __iomem *scu_reg_base = scic->scu_registers;
Dan Williams6f231dd2011-07-02 22:56:22 -0700664
Dan Williamsf1f52e72011-05-10 02:28:45 -0700665 /* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
666 * BAR1 is the scu_registers
667 * 0x20002C = 0x200000 + 0x2c
668 * = start of task context SRAM + offset of (type.ssp.data_offset)
669 * TCi is the io_tag of struct scic_sds_request
Dan Williams67ea8382011-05-08 11:47:15 -0700670 */
Dan Williamsf1f52e72011-05-10 02:28:45 -0700671 ret_val = readl(scu_reg_base +
672 (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) +
Dan Williamsdd047c82011-06-09 11:06:58 -0700673 ((sizeof(struct scu_task_context)) * ISCI_TAG_TCI(sci_req->io_tag)));
Dan Williams67ea8382011-05-08 11:47:15 -0700674 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700675
Dan Williamsf1f52e72011-05-10 02:28:45 -0700676 return ret_val;
Dan Williams6f231dd2011-07-02 22:56:22 -0700677}
678
Piotr Sawickif4636a72011-05-10 23:50:32 +0000679enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700680{
Piotr Sawickif4636a72011-05-10 23:50:32 +0000681 enum sci_base_request_states state;
Dan Williams312e0c22011-06-28 13:47:09 -0700682 struct scu_task_context *tc = sci_req->tc;
683 struct scic_sds_controller *scic = sci_req->owning_controller;
Piotr Sawickif4636a72011-05-10 23:50:32 +0000684
Edmund Nadolskie3013702011-06-02 00:10:43 +0000685 state = sci_req->sm.current_state_id;
686 if (state != SCI_REQ_CONSTRUCTED) {
Piotr Sawickif4636a72011-05-10 23:50:32 +0000687 dev_warn(scic_to_dev(scic),
688 "%s: SCIC IO Request requested to start while in wrong "
689 "state %d\n", __func__, state);
690 return SCI_FAILURE_INVALID_STATE;
691 }
Dan Williamsf1f52e72011-05-10 02:28:45 -0700692
Dan Williams312e0c22011-06-28 13:47:09 -0700693 tc->task_index = ISCI_TAG_TCI(sci_req->io_tag);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700694
Dan Williams312e0c22011-06-28 13:47:09 -0700695 switch (tc->protocol_type) {
696 case SCU_TASK_CONTEXT_PROTOCOL_SMP:
697 case SCU_TASK_CONTEXT_PROTOCOL_SSP:
698 /* SSP/SMP Frame */
699 tc->type.ssp.tag = sci_req->io_tag;
700 tc->type.ssp.target_port_transfer_tag = 0xFFFF;
701 break;
Piotr Sawickif4636a72011-05-10 23:50:32 +0000702
Dan Williams312e0c22011-06-28 13:47:09 -0700703 case SCU_TASK_CONTEXT_PROTOCOL_STP:
704 /* STP/SATA Frame
705 * tc->type.stp.ncq_tag = sci_req->ncq_tag;
706 */
707 break;
Piotr Sawickif4636a72011-05-10 23:50:32 +0000708
Dan Williams312e0c22011-06-28 13:47:09 -0700709 case SCU_TASK_CONTEXT_PROTOCOL_NONE:
710 /* / @todo When do we set no protocol type? */
711 break;
Piotr Sawickif4636a72011-05-10 23:50:32 +0000712
Dan Williams312e0c22011-06-28 13:47:09 -0700713 default:
714 /* This should never happen since we build the IO
715 * requests */
716 break;
Piotr Sawickif4636a72011-05-10 23:50:32 +0000717 }
718
Dan Williams312e0c22011-06-28 13:47:09 -0700719 /* Add to the post_context the io tag value */
720 sci_req->post_context |= ISCI_TAG_TCI(sci_req->io_tag);
721
722 /* Everything is good go ahead and change state */
723 sci_change_state(&sci_req->sm, SCI_REQ_STARTED);
724
725 return SCI_SUCCESS;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700726}
727
728enum sci_status
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700729scic_sds_io_request_terminate(struct scic_sds_request *sci_req)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700730{
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700731 enum sci_base_request_states state;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700732
Edmund Nadolskie3013702011-06-02 00:10:43 +0000733 state = sci_req->sm.current_state_id;
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700734
735 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000736 case SCI_REQ_CONSTRUCTED:
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700737 scic_sds_request_set_status(sci_req,
738 SCU_TASK_DONE_TASK_ABORT,
739 SCI_FAILURE_IO_TERMINATED);
740
Edmund Nadolskie3013702011-06-02 00:10:43 +0000741 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700742 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000743 case SCI_REQ_STARTED:
744 case SCI_REQ_TASK_WAIT_TC_COMP:
745 case SCI_REQ_SMP_WAIT_RESP:
746 case SCI_REQ_SMP_WAIT_TC_COMP:
747 case SCI_REQ_STP_UDMA_WAIT_TC_COMP:
748 case SCI_REQ_STP_UDMA_WAIT_D2H:
749 case SCI_REQ_STP_NON_DATA_WAIT_H2D:
750 case SCI_REQ_STP_NON_DATA_WAIT_D2H:
751 case SCI_REQ_STP_PIO_WAIT_H2D:
752 case SCI_REQ_STP_PIO_WAIT_FRAME:
753 case SCI_REQ_STP_PIO_DATA_IN:
754 case SCI_REQ_STP_PIO_DATA_OUT:
755 case SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED:
756 case SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG:
757 case SCI_REQ_STP_SOFT_RESET_WAIT_D2H:
758 sci_change_state(&sci_req->sm, SCI_REQ_ABORTING);
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700759 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000760 case SCI_REQ_TASK_WAIT_TC_RESP:
761 sci_change_state(&sci_req->sm, SCI_REQ_ABORTING);
762 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700763 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000764 case SCI_REQ_ABORTING:
765 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700766 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +0000767 case SCI_REQ_COMPLETED:
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700768 default:
769 dev_warn(scic_to_dev(sci_req->owning_controller),
770 "%s: SCIC IO Request requested to abort while in wrong "
771 "state %d\n",
772 __func__,
Edmund Nadolskie3013702011-06-02 00:10:43 +0000773 sci_req->sm.current_state_id);
Dan Williamsf00e6ba2011-05-10 02:39:11 -0700774 break;
775 }
Dan Williamsf1f52e72011-05-10 02:28:45 -0700776
777 return SCI_FAILURE_INVALID_STATE;
778}
779
Dan Williams79e2b6b2011-05-11 08:29:56 -0700780enum sci_status scic_sds_request_complete(struct scic_sds_request *sci_req)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700781{
Dan Williams79e2b6b2011-05-11 08:29:56 -0700782 enum sci_base_request_states state;
783 struct scic_sds_controller *scic = sci_req->owning_controller;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700784
Edmund Nadolskie3013702011-06-02 00:10:43 +0000785 state = sci_req->sm.current_state_id;
786 if (WARN_ONCE(state != SCI_REQ_COMPLETED,
Dan Williams79e2b6b2011-05-11 08:29:56 -0700787 "isci: request completion from wrong state (%d)\n", state))
788 return SCI_FAILURE_INVALID_STATE;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700789
Dan Williams79e2b6b2011-05-11 08:29:56 -0700790 if (sci_req->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX)
791 scic_sds_controller_release_frame(scic,
792 sci_req->saved_rx_frame_index);
793
794 /* XXX can we just stop the machine and remove the 'final' state? */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000795 sci_change_state(&sci_req->sm, SCI_REQ_FINAL);
Dan Williams79e2b6b2011-05-11 08:29:56 -0700796 return SCI_SUCCESS;
797}
798
799enum sci_status scic_sds_io_request_event_handler(struct scic_sds_request *sci_req,
800 u32 event_code)
801{
802 enum sci_base_request_states state;
803 struct scic_sds_controller *scic = sci_req->owning_controller;
804
Edmund Nadolskie3013702011-06-02 00:10:43 +0000805 state = sci_req->sm.current_state_id;
Dan Williams79e2b6b2011-05-11 08:29:56 -0700806
Edmund Nadolskie3013702011-06-02 00:10:43 +0000807 if (state != SCI_REQ_STP_PIO_DATA_IN) {
Dan Williams79e2b6b2011-05-11 08:29:56 -0700808 dev_warn(scic_to_dev(scic), "%s: (%x) in wrong state %d\n",
809 __func__, event_code, state);
810
811 return SCI_FAILURE_INVALID_STATE;
812 }
813
814 switch (scu_get_event_specifier(event_code)) {
815 case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
816 /* We are waiting for data and the SCU has R_ERR the data frame.
817 * Go back to waiting for the D2H Register FIS
818 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000819 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_WAIT_FRAME);
Dan Williams79e2b6b2011-05-11 08:29:56 -0700820 return SCI_SUCCESS;
821 default:
822 dev_err(scic_to_dev(scic),
823 "%s: pio request unexpected event %#x\n",
824 __func__, event_code);
825
826 /* TODO Should we fail the PIO request when we get an
827 * unexpected event?
828 */
829 return SCI_FAILURE;
830 }
Dan Williamsf1f52e72011-05-10 02:28:45 -0700831}
832
Dan Williamsf1f52e72011-05-10 02:28:45 -0700833/*
834 * This function copies response data for requests returning response data
835 * instead of sense data.
836 * @sci_req: This parameter specifies the request object for which to copy
837 * the response data.
838 */
Dan Williamsf1393032011-05-10 02:28:47 -0700839static void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700840{
841 void *resp_buf;
842 u32 len;
843 struct ssp_response_iu *ssp_response;
844 struct isci_request *ireq = sci_req_to_ireq(sci_req);
845 struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
846
847 ssp_response = &sci_req->ssp.rsp;
848
849 resp_buf = &isci_tmf->resp.resp_iu;
850
851 len = min_t(u32,
852 SSP_RESP_IU_MAX_SIZE,
853 be32_to_cpu(ssp_response->response_data_len));
854
855 memcpy(resp_buf, ssp_response->resp_data, len);
856}
857
Edmund Nadolskie3013702011-06-02 00:10:43 +0000858static enum sci_status
859request_started_state_tc_event(struct scic_sds_request *sci_req,
860 u32 completion_code)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700861{
Dan Williamsf1f52e72011-05-10 02:28:45 -0700862 struct ssp_response_iu *resp_iu;
Dan Williamsa7e255a2011-05-11 08:27:47 -0700863 u8 datapres;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700864
Dan Williamsa7e255a2011-05-11 08:27:47 -0700865 /* TODO: Any SDMA return code of other than 0 is bad decode 0x003C0000
866 * to determine SDMA status
Dan Williamsf1f52e72011-05-10 02:28:45 -0700867 */
868 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
869 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
870 scic_sds_request_set_status(sci_req,
871 SCU_TASK_DONE_GOOD,
872 SCI_SUCCESS);
873 break;
Dan Williamsa7e255a2011-05-11 08:27:47 -0700874 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP): {
875 /* There are times when the SCU hardware will return an early
Dan Williamsf1f52e72011-05-10 02:28:45 -0700876 * response because the io request specified more data than is
877 * returned by the target device (mode pages, inquiry data,
878 * etc.). We must check the response stats to see if this is
879 * truly a failed request or a good request that just got
880 * completed early.
881 */
882 struct ssp_response_iu *resp = &sci_req->ssp.rsp;
883 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
884
885 sci_swab32_cpy(&sci_req->ssp.rsp,
886 &sci_req->ssp.rsp,
887 word_cnt);
888
889 if (resp->status == 0) {
Dan Williamsa7e255a2011-05-11 08:27:47 -0700890 scic_sds_request_set_status(sci_req,
891 SCU_TASK_DONE_GOOD,
892 SCI_SUCCESS_IO_DONE_EARLY);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700893 } else {
Dan Williamsa7e255a2011-05-11 08:27:47 -0700894 scic_sds_request_set_status(sci_req,
895 SCU_TASK_DONE_CHECK_RESPONSE,
896 SCI_FAILURE_IO_RESPONSE_VALID);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700897 }
Dan Williamsa7e255a2011-05-11 08:27:47 -0700898 break;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700899 }
Dan Williamsa7e255a2011-05-11 08:27:47 -0700900 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE): {
Dan Williamsf1f52e72011-05-10 02:28:45 -0700901 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
902
903 sci_swab32_cpy(&sci_req->ssp.rsp,
904 &sci_req->ssp.rsp,
905 word_cnt);
906
907 scic_sds_request_set_status(sci_req,
908 SCU_TASK_DONE_CHECK_RESPONSE,
909 SCI_FAILURE_IO_RESPONSE_VALID);
910 break;
911 }
912
913 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
Dan Williamsa7e255a2011-05-11 08:27:47 -0700914 /* TODO With TASK_DONE_RESP_LEN_ERR is the response frame
Dan Williamsf1f52e72011-05-10 02:28:45 -0700915 * guaranteed to be received before this completion status is
916 * posted?
917 */
918 resp_iu = &sci_req->ssp.rsp;
919 datapres = resp_iu->datapres;
920
Dan Williamsa7e255a2011-05-11 08:27:47 -0700921 if (datapres == 1 || datapres == 2) {
922 scic_sds_request_set_status(sci_req,
923 SCU_TASK_DONE_CHECK_RESPONSE,
924 SCI_FAILURE_IO_RESPONSE_VALID);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700925 } else
Dan Williamsa7e255a2011-05-11 08:27:47 -0700926 scic_sds_request_set_status(sci_req,
927 SCU_TASK_DONE_GOOD,
928 SCI_SUCCESS);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700929 break;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700930 /* only stp device gets suspended. */
931 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
932 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
933 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
934 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
935 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
936 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
937 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
938 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
939 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
940 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
941 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
942 if (sci_req->protocol == SCIC_STP_PROTOCOL) {
Dan Williamsa7e255a2011-05-11 08:27:47 -0700943 scic_sds_request_set_status(sci_req,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700944 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
945 SCU_COMPLETION_TL_STATUS_SHIFT,
946 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
947 } else {
Dan Williamsa7e255a2011-05-11 08:27:47 -0700948 scic_sds_request_set_status(sci_req,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700949 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
950 SCU_COMPLETION_TL_STATUS_SHIFT,
951 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
952 }
953 break;
954
955 /* both stp/ssp device gets suspended */
956 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
957 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
958 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
959 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
960 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
961 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
962 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
963 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
964 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
965 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
Dan Williamsa7e255a2011-05-11 08:27:47 -0700966 scic_sds_request_set_status(sci_req,
967 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
968 SCU_COMPLETION_TL_STATUS_SHIFT,
969 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700970 break;
971
972 /* neither ssp nor stp gets suspended. */
973 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
974 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
975 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
976 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
977 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
978 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
979 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
980 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
981 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
982 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
983 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
984 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
985 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
986 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
987 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
988 default:
989 scic_sds_request_set_status(
990 sci_req,
991 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
992 SCU_COMPLETION_TL_STATUS_SHIFT,
993 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
994 break;
995 }
996
997 /*
998 * TODO: This is probably wrong for ACK/NAK timeout conditions
999 */
1000
1001 /* In all cases we will treat this as the completion of the IO req. */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001002 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsf1f52e72011-05-10 02:28:45 -07001003 return SCI_SUCCESS;
1004}
1005
Edmund Nadolskie3013702011-06-02 00:10:43 +00001006static enum sci_status
1007request_aborting_state_tc_event(struct scic_sds_request *sci_req,
1008 u32 completion_code)
Dan Williamsf1f52e72011-05-10 02:28:45 -07001009{
1010 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1011 case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
1012 case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
Dan Williamsa7e255a2011-05-11 08:27:47 -07001013 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_TASK_ABORT,
1014 SCI_FAILURE_IO_TERMINATED);
Dan Williamsf1f52e72011-05-10 02:28:45 -07001015
Edmund Nadolskie3013702011-06-02 00:10:43 +00001016 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsf1f52e72011-05-10 02:28:45 -07001017 break;
1018
1019 default:
Dan Williamsa7e255a2011-05-11 08:27:47 -07001020 /* Unless we get some strange error wait for the task abort to complete
1021 * TODO: Should there be a state change for this completion?
1022 */
Dan Williamsf1f52e72011-05-10 02:28:45 -07001023 break;
1024 }
1025
1026 return SCI_SUCCESS;
1027}
1028
Dan Williamsa7e255a2011-05-11 08:27:47 -07001029static enum sci_status ssp_task_request_await_tc_event(struct scic_sds_request *sci_req,
1030 u32 completion_code)
Dan Williamsf1393032011-05-10 02:28:47 -07001031{
1032 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1033 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1034 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1035 SCI_SUCCESS);
1036
Edmund Nadolskie3013702011-06-02 00:10:43 +00001037 sci_change_state(&sci_req->sm, SCI_REQ_TASK_WAIT_TC_RESP);
Dan Williamsf1393032011-05-10 02:28:47 -07001038 break;
Dan Williamsf1393032011-05-10 02:28:47 -07001039 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
Dan Williamsa7e255a2011-05-11 08:27:47 -07001040 /* Currently, the decision is to simply allow the task request
1041 * to timeout if the task IU wasn't received successfully.
1042 * There is a potential for receiving multiple task responses if
1043 * we decide to send the task IU again.
1044 */
Dan Williamsf1393032011-05-10 02:28:47 -07001045 dev_warn(scic_to_dev(sci_req->owning_controller),
1046 "%s: TaskRequest:0x%p CompletionCode:%x - "
Dan Williamsa7e255a2011-05-11 08:27:47 -07001047 "ACK/NAK timeout\n", __func__, sci_req,
Dan Williamsf1393032011-05-10 02:28:47 -07001048 completion_code);
1049
Edmund Nadolskie3013702011-06-02 00:10:43 +00001050 sci_change_state(&sci_req->sm, SCI_REQ_TASK_WAIT_TC_RESP);
Dan Williamsf1393032011-05-10 02:28:47 -07001051 break;
Dan Williamsf1393032011-05-10 02:28:47 -07001052 default:
Edmund Nadolskie3013702011-06-02 00:10:43 +00001053 /*
1054 * All other completion status cause the IO to be complete.
1055 * If a NAK was received, then it is up to the user to retry
1056 * the request.
Dan Williamsa7e255a2011-05-11 08:27:47 -07001057 */
1058 scic_sds_request_set_status(sci_req,
Dan Williamsf1393032011-05-10 02:28:47 -07001059 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
Dan Williamsa7e255a2011-05-11 08:27:47 -07001060 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williamsf1393032011-05-10 02:28:47 -07001061
Edmund Nadolskie3013702011-06-02 00:10:43 +00001062 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsf1393032011-05-10 02:28:47 -07001063 break;
1064 }
1065
1066 return SCI_SUCCESS;
1067}
1068
Edmund Nadolskie3013702011-06-02 00:10:43 +00001069static enum sci_status
1070smp_request_await_response_tc_event(struct scic_sds_request *sci_req,
1071 u32 completion_code)
Dan Williamsc72086e2011-05-10 02:28:48 -07001072{
1073 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1074 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
Dan Williamsa7e255a2011-05-11 08:27:47 -07001075 /* In the AWAIT RESPONSE state, any TC completion is
1076 * unexpected. but if the TC has success status, we
1077 * complete the IO anyway.
1078 */
Dan Williams5dec6f42011-05-10 02:28:49 -07001079 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1080 SCI_SUCCESS);
Dan Williamsc72086e2011-05-10 02:28:48 -07001081
Edmund Nadolskie3013702011-06-02 00:10:43 +00001082 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsc72086e2011-05-10 02:28:48 -07001083 break;
1084
1085 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
1086 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
1087 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
1088 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
Dan Williamsa7e255a2011-05-11 08:27:47 -07001089 /* These status has been seen in a specific LSI
1090 * expander, which sometimes is not able to send smp
1091 * response within 2 ms. This causes our hardware break
1092 * the connection and set TC completion with one of
1093 * these SMP_XXX_XX_ERR status. For these type of error,
1094 * we ask scic user to retry the request.
1095 */
Dan Williams5dec6f42011-05-10 02:28:49 -07001096 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR,
1097 SCI_FAILURE_RETRY_REQUIRED);
Dan Williamsc72086e2011-05-10 02:28:48 -07001098
Edmund Nadolskie3013702011-06-02 00:10:43 +00001099 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsc72086e2011-05-10 02:28:48 -07001100 break;
1101
1102 default:
Dan Williamsa7e255a2011-05-11 08:27:47 -07001103 /* All other completion status cause the IO to be complete. If a NAK
1104 * was received, then it is up to the user to retry the request
1105 */
1106 scic_sds_request_set_status(sci_req,
1107 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1108 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williamsc72086e2011-05-10 02:28:48 -07001109
Edmund Nadolskie3013702011-06-02 00:10:43 +00001110 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsc72086e2011-05-10 02:28:48 -07001111 break;
1112 }
1113
1114 return SCI_SUCCESS;
1115}
1116
Edmund Nadolskie3013702011-06-02 00:10:43 +00001117static enum sci_status
1118smp_request_await_tc_event(struct scic_sds_request *sci_req,
1119 u32 completion_code)
Dan Williamsc72086e2011-05-10 02:28:48 -07001120{
1121 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1122 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
Dan Williams5dec6f42011-05-10 02:28:49 -07001123 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1124 SCI_SUCCESS);
Dan Williamsc72086e2011-05-10 02:28:48 -07001125
Edmund Nadolskie3013702011-06-02 00:10:43 +00001126 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsc72086e2011-05-10 02:28:48 -07001127 break;
Dan Williamsc72086e2011-05-10 02:28:48 -07001128 default:
Dan Williamsa7e255a2011-05-11 08:27:47 -07001129 /* All other completion status cause the IO to be
1130 * complete. If a NAK was received, then it is up to
1131 * the user to retry the request.
1132 */
1133 scic_sds_request_set_status(sci_req,
1134 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1135 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williamsc72086e2011-05-10 02:28:48 -07001136
Edmund Nadolskie3013702011-06-02 00:10:43 +00001137 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsc72086e2011-05-10 02:28:48 -07001138 break;
1139 }
1140
1141 return SCI_SUCCESS;
1142}
1143
Dan Williams5dec6f42011-05-10 02:28:49 -07001144void scic_stp_io_request_set_ncq_tag(struct scic_sds_request *req,
1145 u16 ncq_tag)
1146{
1147 /**
1148 * @note This could be made to return an error to the user if the user
1149 * attempts to set the NCQ tag in the wrong state.
1150 */
Dan Williams312e0c22011-06-28 13:47:09 -07001151 req->tc->type.stp.ncq_tag = ncq_tag;
Dan Williams5dec6f42011-05-10 02:28:49 -07001152}
1153
Dan Williams312e0c22011-06-28 13:47:09 -07001154static struct scu_sgl_element *pio_sgl_next(struct scic_sds_stp_request *stp_req)
Dan Williams5dec6f42011-05-10 02:28:49 -07001155{
Dan Williams312e0c22011-06-28 13:47:09 -07001156 struct scu_sgl_element *sgl;
1157 struct scu_sgl_element_pair *sgl_pair;
Dan Williams5dec6f42011-05-10 02:28:49 -07001158 struct scic_sds_request *sci_req = to_sci_req(stp_req);
1159 struct scic_sds_request_pio_sgl *pio_sgl = &stp_req->type.pio.request_current;
1160
Dan Williams312e0c22011-06-28 13:47:09 -07001161 sgl_pair = to_sgl_element_pair(sci_req, pio_sgl->sgl_index);
1162 if (!sgl_pair)
1163 sgl = NULL;
1164 else if (pio_sgl->sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
1165 if (sgl_pair->B.address_lower == 0 &&
1166 sgl_pair->B.address_upper == 0) {
1167 sgl = NULL;
Dan Williams5dec6f42011-05-10 02:28:49 -07001168 } else {
1169 pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_B;
Dan Williams312e0c22011-06-28 13:47:09 -07001170 sgl = &sgl_pair->B;
Dan Williams5dec6f42011-05-10 02:28:49 -07001171 }
1172 } else {
Dan Williams312e0c22011-06-28 13:47:09 -07001173 if (sgl_pair->next_pair_lower == 0 &&
1174 sgl_pair->next_pair_upper == 0) {
1175 sgl = NULL;
Dan Williams5dec6f42011-05-10 02:28:49 -07001176 } else {
Dan Williams312e0c22011-06-28 13:47:09 -07001177 pio_sgl->sgl_index++;
Dan Williams5dec6f42011-05-10 02:28:49 -07001178 pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_A;
Dan Williams312e0c22011-06-28 13:47:09 -07001179 sgl_pair = to_sgl_element_pair(sci_req, pio_sgl->sgl_index);
1180 sgl = &sgl_pair->A;
Dan Williams5dec6f42011-05-10 02:28:49 -07001181 }
1182 }
1183
Dan Williams312e0c22011-06-28 13:47:09 -07001184 return sgl;
Dan Williams5dec6f42011-05-10 02:28:49 -07001185}
1186
Edmund Nadolskie3013702011-06-02 00:10:43 +00001187static enum sci_status
1188stp_request_non_data_await_h2d_tc_event(struct scic_sds_request *sci_req,
1189 u32 completion_code)
Dan Williams5dec6f42011-05-10 02:28:49 -07001190{
1191 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1192 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
Dan Williamsa7e255a2011-05-11 08:27:47 -07001193 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1194 SCI_SUCCESS);
Dan Williams5dec6f42011-05-10 02:28:49 -07001195
Edmund Nadolskie3013702011-06-02 00:10:43 +00001196 sci_change_state(&sci_req->sm, SCI_REQ_STP_NON_DATA_WAIT_D2H);
Dan Williams5dec6f42011-05-10 02:28:49 -07001197 break;
1198
1199 default:
Dan Williamsa7e255a2011-05-11 08:27:47 -07001200 /* All other completion status cause the IO to be
1201 * complete. If a NAK was received, then it is up to
1202 * the user to retry the request.
1203 */
1204 scic_sds_request_set_status(sci_req,
1205 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1206 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williams5dec6f42011-05-10 02:28:49 -07001207
Edmund Nadolskie3013702011-06-02 00:10:43 +00001208 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williams5dec6f42011-05-10 02:28:49 -07001209 break;
1210 }
1211
1212 return SCI_SUCCESS;
1213}
1214
Dan Williams5dec6f42011-05-10 02:28:49 -07001215#define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
1216
1217/* transmit DATA_FIS from (current sgl + offset) for input
1218 * parameter length. current sgl and offset is alreay stored in the IO request
1219 */
1220static enum sci_status scic_sds_stp_request_pio_data_out_trasmit_data_frame(
1221 struct scic_sds_request *sci_req,
1222 u32 length)
1223{
Dan Williams5dec6f42011-05-10 02:28:49 -07001224 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
Dan Williams312e0c22011-06-28 13:47:09 -07001225 struct scu_task_context *task_context = sci_req->tc;
1226 struct scu_sgl_element_pair *sgl_pair;
Dan Williams5dec6f42011-05-10 02:28:49 -07001227 struct scu_sgl_element *current_sgl;
1228
1229 /* Recycle the TC and reconstruct it for sending out DATA FIS containing
1230 * for the data from current_sgl+offset for the input length
1231 */
Dan Williams312e0c22011-06-28 13:47:09 -07001232 sgl_pair = to_sgl_element_pair(sci_req, stp_req->type.pio.request_current.sgl_index);
Dan Williams5dec6f42011-05-10 02:28:49 -07001233 if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
Dan Williams312e0c22011-06-28 13:47:09 -07001234 current_sgl = &sgl_pair->A;
Dan Williams5dec6f42011-05-10 02:28:49 -07001235 else
Dan Williams312e0c22011-06-28 13:47:09 -07001236 current_sgl = &sgl_pair->B;
Dan Williams5dec6f42011-05-10 02:28:49 -07001237
1238 /* update the TC */
1239 task_context->command_iu_upper = current_sgl->address_upper;
1240 task_context->command_iu_lower = current_sgl->address_lower;
1241 task_context->transfer_length_bytes = length;
1242 task_context->type.stp.fis_type = FIS_DATA;
1243
1244 /* send the new TC out. */
1245 return scic_controller_continue_io(sci_req);
1246}
1247
1248static enum sci_status scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request *sci_req)
1249{
1250
1251 struct scu_sgl_element *current_sgl;
1252 u32 sgl_offset;
1253 u32 remaining_bytes_in_current_sgl = 0;
1254 enum sci_status status = SCI_SUCCESS;
1255 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
Dan Williams312e0c22011-06-28 13:47:09 -07001256 struct scu_sgl_element_pair *sgl_pair;
Dan Williams5dec6f42011-05-10 02:28:49 -07001257
1258 sgl_offset = stp_req->type.pio.request_current.sgl_offset;
Dan Williams312e0c22011-06-28 13:47:09 -07001259 sgl_pair = to_sgl_element_pair(sci_req, stp_req->type.pio.request_current.sgl_index);
1260 if (WARN_ONCE(!sgl_pair, "%s: null sgl element", __func__))
1261 return SCI_FAILURE;
Dan Williams5dec6f42011-05-10 02:28:49 -07001262
1263 if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
Dan Williams312e0c22011-06-28 13:47:09 -07001264 current_sgl = &sgl_pair->A;
1265 remaining_bytes_in_current_sgl = sgl_pair->A.length - sgl_offset;
Dan Williams5dec6f42011-05-10 02:28:49 -07001266 } else {
Dan Williams312e0c22011-06-28 13:47:09 -07001267 current_sgl = &sgl_pair->B;
1268 remaining_bytes_in_current_sgl = sgl_pair->B.length - sgl_offset;
Dan Williams5dec6f42011-05-10 02:28:49 -07001269 }
1270
Dan Williams5dec6f42011-05-10 02:28:49 -07001271 if (stp_req->type.pio.pio_transfer_bytes > 0) {
1272 if (stp_req->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl) {
1273 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
1274 status = scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, remaining_bytes_in_current_sgl);
1275 if (status == SCI_SUCCESS) {
1276 stp_req->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
1277
1278 /* update the current sgl, sgl_offset and save for future */
Dan Williams312e0c22011-06-28 13:47:09 -07001279 current_sgl = pio_sgl_next(stp_req);
Dan Williams5dec6f42011-05-10 02:28:49 -07001280 sgl_offset = 0;
1281 }
1282 } else if (stp_req->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl) {
1283 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
1284 scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, stp_req->type.pio.pio_transfer_bytes);
1285
1286 if (status == SCI_SUCCESS) {
1287 /* Sgl offset will be adjusted and saved for future */
1288 sgl_offset += stp_req->type.pio.pio_transfer_bytes;
1289 current_sgl->address_lower += stp_req->type.pio.pio_transfer_bytes;
1290 stp_req->type.pio.pio_transfer_bytes = 0;
1291 }
1292 }
1293 }
1294
1295 if (status == SCI_SUCCESS) {
1296 stp_req->type.pio.request_current.sgl_offset = sgl_offset;
1297 }
1298
1299 return status;
1300}
1301
1302/**
1303 *
1304 * @stp_request: The request that is used for the SGL processing.
1305 * @data_buffer: The buffer of data to be copied.
1306 * @length: The length of the data transfer.
1307 *
1308 * Copy the data from the buffer for the length specified to the IO reqeust SGL
1309 * specified data region. enum sci_status
1310 */
1311static enum sci_status
1312scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request *stp_req,
1313 u8 *data_buf, u32 len)
1314{
1315 struct scic_sds_request *sci_req;
1316 struct isci_request *ireq;
1317 u8 *src_addr;
1318 int copy_len;
1319 struct sas_task *task;
1320 struct scatterlist *sg;
1321 void *kaddr;
1322 int total_len = len;
1323
1324 sci_req = to_sci_req(stp_req);
1325 ireq = sci_req_to_ireq(sci_req);
1326 task = isci_request_access_task(ireq);
1327 src_addr = data_buf;
1328
1329 if (task->num_scatter > 0) {
1330 sg = task->scatter;
1331
1332 while (total_len > 0) {
1333 struct page *page = sg_page(sg);
1334
1335 copy_len = min_t(int, total_len, sg_dma_len(sg));
1336 kaddr = kmap_atomic(page, KM_IRQ0);
1337 memcpy(kaddr + sg->offset, src_addr, copy_len);
1338 kunmap_atomic(kaddr, KM_IRQ0);
1339 total_len -= copy_len;
1340 src_addr += copy_len;
1341 sg = sg_next(sg);
1342 }
1343 } else {
1344 BUG_ON(task->total_xfer_len < total_len);
1345 memcpy(task->scatter, src_addr, total_len);
1346 }
1347
1348 return SCI_SUCCESS;
1349}
1350
1351/**
1352 *
1353 * @sci_req: The PIO DATA IN request that is to receive the data.
1354 * @data_buffer: The buffer to copy from.
1355 *
1356 * Copy the data buffer to the io request data region. enum sci_status
1357 */
1358static enum sci_status scic_sds_stp_request_pio_data_in_copy_data(
1359 struct scic_sds_stp_request *sci_req,
1360 u8 *data_buffer)
1361{
1362 enum sci_status status;
1363
1364 /*
1365 * If there is less than 1K remaining in the transfer request
1366 * copy just the data for the transfer */
1367 if (sci_req->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE) {
1368 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
1369 sci_req, data_buffer, sci_req->type.pio.pio_transfer_bytes);
1370
1371 if (status == SCI_SUCCESS)
1372 sci_req->type.pio.pio_transfer_bytes = 0;
1373 } else {
1374 /* We are transfering the whole frame so copy */
1375 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
1376 sci_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
1377
1378 if (status == SCI_SUCCESS)
1379 sci_req->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
1380 }
1381
1382 return status;
1383}
1384
Edmund Nadolskie3013702011-06-02 00:10:43 +00001385static enum sci_status
1386stp_request_pio_await_h2d_completion_tc_event(struct scic_sds_request *sci_req,
1387 u32 completion_code)
Dan Williams5dec6f42011-05-10 02:28:49 -07001388{
1389 enum sci_status status = SCI_SUCCESS;
1390
1391 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1392 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
Edmund Nadolskie3013702011-06-02 00:10:43 +00001393 scic_sds_request_set_status(sci_req,
1394 SCU_TASK_DONE_GOOD,
1395 SCI_SUCCESS);
Dan Williams5dec6f42011-05-10 02:28:49 -07001396
Edmund Nadolskie3013702011-06-02 00:10:43 +00001397 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_WAIT_FRAME);
Dan Williams5dec6f42011-05-10 02:28:49 -07001398 break;
1399
1400 default:
Dan Williamsa7e255a2011-05-11 08:27:47 -07001401 /* All other completion status cause the IO to be
1402 * complete. If a NAK was received, then it is up to
1403 * the user to retry the request.
1404 */
1405 scic_sds_request_set_status(sci_req,
1406 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1407 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williams5dec6f42011-05-10 02:28:49 -07001408
Edmund Nadolskie3013702011-06-02 00:10:43 +00001409 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williams5dec6f42011-05-10 02:28:49 -07001410 break;
1411 }
1412
1413 return status;
1414}
1415
Edmund Nadolskie3013702011-06-02 00:10:43 +00001416static enum sci_status
1417pio_data_out_tx_done_tc_event(struct scic_sds_request *sci_req,
1418 u32 completion_code)
Dan Williams5dec6f42011-05-10 02:28:49 -07001419{
1420 enum sci_status status = SCI_SUCCESS;
1421 bool all_frames_transferred = false;
1422 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1423
1424 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1425 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1426 /* Transmit data */
1427 if (stp_req->type.pio.pio_transfer_bytes != 0) {
1428 status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
1429 if (status == SCI_SUCCESS) {
1430 if (stp_req->type.pio.pio_transfer_bytes == 0)
1431 all_frames_transferred = true;
1432 }
1433 } else if (stp_req->type.pio.pio_transfer_bytes == 0) {
1434 /*
1435 * this will happen if the all data is written at the
1436 * first time after the pio setup fis is received
1437 */
1438 all_frames_transferred = true;
1439 }
1440
1441 /* all data transferred. */
1442 if (all_frames_transferred) {
1443 /*
Edmund Nadolskie3013702011-06-02 00:10:43 +00001444 * Change the state to SCI_REQ_STP_PIO_DATA_IN
Dan Williams5dec6f42011-05-10 02:28:49 -07001445 * and wait for PIO_SETUP fis / or D2H REg fis. */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001446 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_WAIT_FRAME);
Dan Williams5dec6f42011-05-10 02:28:49 -07001447 }
1448 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001449
Dan Williams5dec6f42011-05-10 02:28:49 -07001450 default:
1451 /*
Edmund Nadolskie3013702011-06-02 00:10:43 +00001452 * All other completion status cause the IO to be complete.
1453 * If a NAK was received, then it is up to the user to retry
1454 * the request.
1455 */
Dan Williams5dec6f42011-05-10 02:28:49 -07001456 scic_sds_request_set_status(
1457 sci_req,
1458 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001459 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williams5dec6f42011-05-10 02:28:49 -07001460
Edmund Nadolskie3013702011-06-02 00:10:43 +00001461 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williams5dec6f42011-05-10 02:28:49 -07001462 break;
1463 }
1464
1465 return status;
1466}
1467
Dan Williams5dec6f42011-05-10 02:28:49 -07001468static void scic_sds_stp_request_udma_complete_request(
1469 struct scic_sds_request *request,
1470 u32 scu_status,
1471 enum sci_status sci_status)
1472{
1473 scic_sds_request_set_status(request, scu_status, sci_status);
Edmund Nadolskie3013702011-06-02 00:10:43 +00001474 sci_change_state(&request->sm, SCI_REQ_COMPLETED);
Dan Williams5dec6f42011-05-10 02:28:49 -07001475}
1476
1477static enum sci_status scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request *sci_req,
1478 u32 frame_index)
1479{
1480 struct scic_sds_controller *scic = sci_req->owning_controller;
1481 struct dev_to_host_fis *frame_header;
1482 enum sci_status status;
1483 u32 *frame_buffer;
1484
1485 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1486 frame_index,
1487 (void **)&frame_header);
1488
1489 if ((status == SCI_SUCCESS) &&
1490 (frame_header->fis_type == FIS_REGD2H)) {
1491 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1492 frame_index,
1493 (void **)&frame_buffer);
1494
1495 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1496 frame_header,
1497 frame_buffer);
1498 }
1499
1500 scic_sds_controller_release_frame(scic, frame_index);
1501
1502 return status;
1503}
1504
Edmund Nadolskie3013702011-06-02 00:10:43 +00001505enum sci_status
1506scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req,
1507 u32 frame_index)
Dan Williamsd1c637c32011-05-11 08:27:47 -07001508{
1509 struct scic_sds_controller *scic = sci_req->owning_controller;
1510 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1511 enum sci_base_request_states state;
1512 enum sci_status status;
1513 ssize_t word_cnt;
1514
Edmund Nadolskie3013702011-06-02 00:10:43 +00001515 state = sci_req->sm.current_state_id;
Dan Williamsd1c637c32011-05-11 08:27:47 -07001516 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001517 case SCI_REQ_STARTED: {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001518 struct ssp_frame_hdr ssp_hdr;
1519 void *frame_header;
1520
1521 scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1522 frame_index,
1523 &frame_header);
1524
1525 word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32);
1526 sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt);
1527
1528 if (ssp_hdr.frame_type == SSP_RESPONSE) {
1529 struct ssp_response_iu *resp_iu;
1530 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1531
1532 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1533 frame_index,
1534 (void **)&resp_iu);
1535
1536 sci_swab32_cpy(&sci_req->ssp.rsp, resp_iu, word_cnt);
1537
1538 resp_iu = &sci_req->ssp.rsp;
1539
1540 if (resp_iu->datapres == 0x01 ||
1541 resp_iu->datapres == 0x02) {
1542 scic_sds_request_set_status(sci_req,
1543 SCU_TASK_DONE_CHECK_RESPONSE,
1544 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1545 } else
1546 scic_sds_request_set_status(sci_req,
1547 SCU_TASK_DONE_GOOD,
1548 SCI_SUCCESS);
1549 } else {
1550 /* not a response frame, why did it get forwarded? */
1551 dev_err(scic_to_dev(scic),
1552 "%s: SCIC IO Request 0x%p received unexpected "
1553 "frame %d type 0x%02x\n", __func__, sci_req,
1554 frame_index, ssp_hdr.frame_type);
1555 }
1556
1557 /*
Edmund Nadolskie3013702011-06-02 00:10:43 +00001558 * In any case we are done with this frame buffer return it to
1559 * the controller
Dan Williamsd1c637c32011-05-11 08:27:47 -07001560 */
1561 scic_sds_controller_release_frame(scic, frame_index);
1562
1563 return SCI_SUCCESS;
1564 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001565
1566 case SCI_REQ_TASK_WAIT_TC_RESP:
Dan Williamsd1c637c32011-05-11 08:27:47 -07001567 scic_sds_io_request_copy_response(sci_req);
Edmund Nadolskie3013702011-06-02 00:10:43 +00001568 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001569 scic_sds_controller_release_frame(scic,frame_index);
1570 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001571
1572 case SCI_REQ_SMP_WAIT_RESP: {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001573 struct smp_resp *rsp_hdr = &sci_req->smp.rsp;
1574 void *frame_header;
1575
1576 scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1577 frame_index,
1578 &frame_header);
1579
1580 /* byte swap the header. */
1581 word_cnt = SMP_RESP_HDR_SZ / sizeof(u32);
1582 sci_swab32_cpy(rsp_hdr, frame_header, word_cnt);
1583
1584 if (rsp_hdr->frame_type == SMP_RESPONSE) {
1585 void *smp_resp;
1586
1587 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1588 frame_index,
1589 &smp_resp);
1590
Dan Williams5edc3342011-06-16 17:20:35 -07001591 word_cnt = (sizeof(struct smp_resp) - SMP_RESP_HDR_SZ) /
Dan Williamsd1c637c32011-05-11 08:27:47 -07001592 sizeof(u32);
1593
1594 sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ,
1595 smp_resp, word_cnt);
1596
1597 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1598 SCI_SUCCESS);
1599
Edmund Nadolskie3013702011-06-02 00:10:43 +00001600 sci_change_state(&sci_req->sm, SCI_REQ_SMP_WAIT_TC_COMP);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001601 } else {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001602 /*
1603 * This was not a response frame why did it get
1604 * forwarded?
1605 */
Dan Williamsd1c637c32011-05-11 08:27:47 -07001606 dev_err(scic_to_dev(scic),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001607 "%s: SCIC SMP Request 0x%p received unexpected "
1608 "frame %d type 0x%02x\n",
1609 __func__,
1610 sci_req,
1611 frame_index,
1612 rsp_hdr->frame_type);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001613
1614 scic_sds_request_set_status(sci_req,
1615 SCU_TASK_DONE_SMP_FRM_TYPE_ERR,
1616 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1617
Edmund Nadolskie3013702011-06-02 00:10:43 +00001618 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001619 }
1620
1621 scic_sds_controller_release_frame(scic, frame_index);
1622
1623 return SCI_SUCCESS;
1624 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001625
1626 case SCI_REQ_STP_UDMA_WAIT_TC_COMP:
1627 return scic_sds_stp_request_udma_general_frame_handler(sci_req,
1628 frame_index);
1629
1630 case SCI_REQ_STP_UDMA_WAIT_D2H:
Dan Williamsd1c637c32011-05-11 08:27:47 -07001631 /* Use the general frame handler to copy the resposne data */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001632 status = scic_sds_stp_request_udma_general_frame_handler(sci_req,
1633 frame_index);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001634
1635 if (status != SCI_SUCCESS)
1636 return status;
1637
1638 scic_sds_stp_request_udma_complete_request(sci_req,
1639 SCU_TASK_DONE_CHECK_RESPONSE,
1640 SCI_FAILURE_IO_RESPONSE_VALID);
Edmund Nadolskie3013702011-06-02 00:10:43 +00001641
Dan Williamsd1c637c32011-05-11 08:27:47 -07001642 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001643
1644 case SCI_REQ_STP_NON_DATA_WAIT_D2H: {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001645 struct dev_to_host_fis *frame_header;
1646 u32 *frame_buffer;
1647
1648 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1649 frame_index,
1650 (void **)&frame_header);
1651
1652 if (status != SCI_SUCCESS) {
1653 dev_err(scic_to_dev(scic),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001654 "%s: SCIC IO Request 0x%p could not get frame "
1655 "header for frame index %d, status %x\n",
1656 __func__,
1657 stp_req,
1658 frame_index,
1659 status);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001660
1661 return status;
1662 }
1663
1664 switch (frame_header->fis_type) {
1665 case FIS_REGD2H:
1666 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1667 frame_index,
1668 (void **)&frame_buffer);
1669
1670 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1671 frame_header,
1672 frame_buffer);
1673
1674 /* The command has completed with error */
1675 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_CHECK_RESPONSE,
1676 SCI_FAILURE_IO_RESPONSE_VALID);
1677 break;
1678
1679 default:
1680 dev_warn(scic_to_dev(scic),
1681 "%s: IO Request:0x%p Frame Id:%d protocol "
1682 "violation occurred\n", __func__, stp_req,
1683 frame_index);
1684
1685 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
1686 SCI_FAILURE_PROTOCOL_VIOLATION);
1687 break;
1688 }
1689
Edmund Nadolskie3013702011-06-02 00:10:43 +00001690 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001691
1692 /* Frame has been decoded return it to the controller */
1693 scic_sds_controller_release_frame(scic, frame_index);
1694
1695 return status;
1696 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001697
1698 case SCI_REQ_STP_PIO_WAIT_FRAME: {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001699 struct isci_request *ireq = sci_req_to_ireq(sci_req);
1700 struct sas_task *task = isci_request_access_task(ireq);
1701 struct dev_to_host_fis *frame_header;
1702 u32 *frame_buffer;
1703
1704 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1705 frame_index,
1706 (void **)&frame_header);
1707
1708 if (status != SCI_SUCCESS) {
1709 dev_err(scic_to_dev(scic),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001710 "%s: SCIC IO Request 0x%p could not get frame "
1711 "header for frame index %d, status %x\n",
Dan Williamsd1c637c32011-05-11 08:27:47 -07001712 __func__, stp_req, frame_index, status);
1713 return status;
1714 }
1715
1716 switch (frame_header->fis_type) {
1717 case FIS_PIO_SETUP:
1718 /* Get from the frame buffer the PIO Setup Data */
1719 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1720 frame_index,
1721 (void **)&frame_buffer);
1722
Edmund Nadolskie3013702011-06-02 00:10:43 +00001723 /* Get the data from the PIO Setup The SCU Hardware
1724 * returns first word in the frame_header and the rest
1725 * of the data is in the frame buffer so we need to
1726 * back up one dword
Dan Williamsd1c637c32011-05-11 08:27:47 -07001727 */
1728
1729 /* transfer_count: first 16bits in the 4th dword */
1730 stp_req->type.pio.pio_transfer_bytes = frame_buffer[3] & 0xffff;
1731
1732 /* ending_status: 4th byte in the 3rd dword */
1733 stp_req->type.pio.ending_status = (frame_buffer[2] >> 24) & 0xff;
1734
1735 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1736 frame_header,
1737 frame_buffer);
1738
1739 sci_req->stp.rsp.status = stp_req->type.pio.ending_status;
1740
1741 /* The next state is dependent on whether the
1742 * request was PIO Data-in or Data out
1743 */
1744 if (task->data_dir == DMA_FROM_DEVICE) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001745 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_DATA_IN);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001746 } else if (task->data_dir == DMA_TO_DEVICE) {
1747 /* Transmit data */
1748 status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
1749 if (status != SCI_SUCCESS)
1750 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001751 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_DATA_OUT);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001752 }
1753 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001754
Dan Williamsd1c637c32011-05-11 08:27:47 -07001755 case FIS_SETDEVBITS:
Edmund Nadolskie3013702011-06-02 00:10:43 +00001756 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_WAIT_FRAME);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001757 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001758
Dan Williamsd1c637c32011-05-11 08:27:47 -07001759 case FIS_REGD2H:
1760 if (frame_header->status & ATA_BUSY) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001761 /*
1762 * Now why is the drive sending a D2H Register
1763 * FIS when it is still busy? Do nothing since
1764 * we are still in the right state.
Dan Williamsd1c637c32011-05-11 08:27:47 -07001765 */
1766 dev_dbg(scic_to_dev(scic),
1767 "%s: SCIC PIO Request 0x%p received "
1768 "D2H Register FIS with BSY status "
Edmund Nadolskie3013702011-06-02 00:10:43 +00001769 "0x%x\n",
1770 __func__,
1771 stp_req,
Dan Williamsd1c637c32011-05-11 08:27:47 -07001772 frame_header->status);
1773 break;
1774 }
1775
1776 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1777 frame_index,
1778 (void **)&frame_buffer);
1779
1780 scic_sds_controller_copy_sata_response(&sci_req->stp.req,
1781 frame_header,
1782 frame_buffer);
1783
1784 scic_sds_request_set_status(sci_req,
1785 SCU_TASK_DONE_CHECK_RESPONSE,
1786 SCI_FAILURE_IO_RESPONSE_VALID);
1787
Edmund Nadolskie3013702011-06-02 00:10:43 +00001788 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001789 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001790
Dan Williamsd1c637c32011-05-11 08:27:47 -07001791 default:
1792 /* FIXME: what do we do here? */
1793 break;
1794 }
1795
1796 /* Frame is decoded return it to the controller */
1797 scic_sds_controller_release_frame(scic, frame_index);
1798
1799 return status;
1800 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001801
1802 case SCI_REQ_STP_PIO_DATA_IN: {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001803 struct dev_to_host_fis *frame_header;
1804 struct sata_fis_data *frame_buffer;
1805
1806 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1807 frame_index,
1808 (void **)&frame_header);
1809
1810 if (status != SCI_SUCCESS) {
1811 dev_err(scic_to_dev(scic),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001812 "%s: SCIC IO Request 0x%p could not get frame "
1813 "header for frame index %d, status %x\n",
1814 __func__,
1815 stp_req,
1816 frame_index,
1817 status);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001818 return status;
1819 }
1820
1821 if (frame_header->fis_type != FIS_DATA) {
1822 dev_err(scic_to_dev(scic),
1823 "%s: SCIC PIO Request 0x%p received frame %d "
1824 "with fis type 0x%02x when expecting a data "
Edmund Nadolskie3013702011-06-02 00:10:43 +00001825 "fis.\n",
1826 __func__,
1827 stp_req,
1828 frame_index,
Dan Williamsd1c637c32011-05-11 08:27:47 -07001829 frame_header->fis_type);
1830
1831 scic_sds_request_set_status(sci_req,
1832 SCU_TASK_DONE_GOOD,
1833 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT);
1834
Edmund Nadolskie3013702011-06-02 00:10:43 +00001835 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001836
1837 /* Frame is decoded return it to the controller */
1838 scic_sds_controller_release_frame(scic, frame_index);
1839 return status;
1840 }
1841
Dan Williams312e0c22011-06-28 13:47:09 -07001842 if (stp_req->type.pio.request_current.sgl_index < 0) {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001843 sci_req->saved_rx_frame_index = frame_index;
1844 stp_req->type.pio.pio_transfer_bytes = 0;
1845 } else {
1846 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1847 frame_index,
1848 (void **)&frame_buffer);
1849
1850 status = scic_sds_stp_request_pio_data_in_copy_data(stp_req,
1851 (u8 *)frame_buffer);
1852
1853 /* Frame is decoded return it to the controller */
1854 scic_sds_controller_release_frame(scic, frame_index);
1855 }
1856
1857 /* Check for the end of the transfer, are there more
1858 * bytes remaining for this data transfer
1859 */
1860 if (status != SCI_SUCCESS ||
1861 stp_req->type.pio.pio_transfer_bytes != 0)
1862 return status;
1863
1864 if ((stp_req->type.pio.ending_status & ATA_BUSY) == 0) {
1865 scic_sds_request_set_status(sci_req,
1866 SCU_TASK_DONE_CHECK_RESPONSE,
1867 SCI_FAILURE_IO_RESPONSE_VALID);
1868
Edmund Nadolskie3013702011-06-02 00:10:43 +00001869 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001870 } else {
Edmund Nadolskie3013702011-06-02 00:10:43 +00001871 sci_change_state(&sci_req->sm, SCI_REQ_STP_PIO_WAIT_FRAME);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001872 }
1873 return status;
1874 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001875
1876 case SCI_REQ_STP_SOFT_RESET_WAIT_D2H: {
Dan Williamsd1c637c32011-05-11 08:27:47 -07001877 struct dev_to_host_fis *frame_header;
1878 u32 *frame_buffer;
1879
1880 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1881 frame_index,
1882 (void **)&frame_header);
1883 if (status != SCI_SUCCESS) {
1884 dev_err(scic_to_dev(scic),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001885 "%s: SCIC IO Request 0x%p could not get frame "
1886 "header for frame index %d, status %x\n",
1887 __func__,
1888 stp_req,
1889 frame_index,
1890 status);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001891 return status;
1892 }
1893
1894 switch (frame_header->fis_type) {
1895 case FIS_REGD2H:
1896 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1897 frame_index,
1898 (void **)&frame_buffer);
1899
1900 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1901 frame_header,
1902 frame_buffer);
1903
1904 /* The command has completed with error */
1905 scic_sds_request_set_status(sci_req,
1906 SCU_TASK_DONE_CHECK_RESPONSE,
1907 SCI_FAILURE_IO_RESPONSE_VALID);
1908 break;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001909
Dan Williamsd1c637c32011-05-11 08:27:47 -07001910 default:
1911 dev_warn(scic_to_dev(scic),
1912 "%s: IO Request:0x%p Frame Id:%d protocol "
Edmund Nadolskie3013702011-06-02 00:10:43 +00001913 "violation occurred\n",
1914 __func__,
1915 stp_req,
Dan Williamsd1c637c32011-05-11 08:27:47 -07001916 frame_index);
1917
Edmund Nadolskie3013702011-06-02 00:10:43 +00001918 scic_sds_request_set_status(sci_req,
1919 SCU_TASK_DONE_UNEXP_FIS,
Dan Williamsd1c637c32011-05-11 08:27:47 -07001920 SCI_FAILURE_PROTOCOL_VIOLATION);
1921 break;
1922 }
1923
Edmund Nadolskie3013702011-06-02 00:10:43 +00001924 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001925
1926 /* Frame has been decoded return it to the controller */
1927 scic_sds_controller_release_frame(scic, frame_index);
1928
1929 return status;
1930 }
Edmund Nadolskie3013702011-06-02 00:10:43 +00001931 case SCI_REQ_ABORTING:
1932 /*
1933 * TODO: Is it even possible to get an unsolicited frame in the
Dan Williamsd1c637c32011-05-11 08:27:47 -07001934 * aborting state?
1935 */
1936 scic_sds_controller_release_frame(scic, frame_index);
1937 return SCI_SUCCESS;
Edmund Nadolskie3013702011-06-02 00:10:43 +00001938
Dan Williamsd1c637c32011-05-11 08:27:47 -07001939 default:
1940 dev_warn(scic_to_dev(scic),
Edmund Nadolskie3013702011-06-02 00:10:43 +00001941 "%s: SCIC IO Request given unexpected frame %x while "
1942 "in state %d\n",
1943 __func__,
1944 frame_index,
1945 state);
Dan Williamsd1c637c32011-05-11 08:27:47 -07001946
1947 scic_sds_controller_release_frame(scic, frame_index);
1948 return SCI_FAILURE_INVALID_STATE;
1949 }
1950}
1951
Dan Williamsa7e255a2011-05-11 08:27:47 -07001952static enum sci_status stp_request_udma_await_tc_event(struct scic_sds_request *sci_req,
1953 u32 completion_code)
Dan Williams5dec6f42011-05-10 02:28:49 -07001954{
1955 enum sci_status status = SCI_SUCCESS;
1956
1957 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1958 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1959 scic_sds_stp_request_udma_complete_request(sci_req,
1960 SCU_TASK_DONE_GOOD,
1961 SCI_SUCCESS);
1962 break;
1963 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
1964 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
Dan Williamsa7e255a2011-05-11 08:27:47 -07001965 /* We must check ther response buffer to see if the D2H
1966 * Register FIS was received before we got the TC
1967 * completion.
1968 */
Dan Williams5dec6f42011-05-10 02:28:49 -07001969 if (sci_req->stp.rsp.fis_type == FIS_REGD2H) {
1970 scic_sds_remote_device_suspend(sci_req->target_device,
1971 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
1972
1973 scic_sds_stp_request_udma_complete_request(sci_req,
1974 SCU_TASK_DONE_CHECK_RESPONSE,
1975 SCI_FAILURE_IO_RESPONSE_VALID);
1976 } else {
Dan Williamsa7e255a2011-05-11 08:27:47 -07001977 /* If we have an error completion status for the
1978 * TC then we can expect a D2H register FIS from
1979 * the device so we must change state to wait
1980 * for it
1981 */
Edmund Nadolskie3013702011-06-02 00:10:43 +00001982 sci_change_state(&sci_req->sm, SCI_REQ_STP_UDMA_WAIT_D2H);
Dan Williams5dec6f42011-05-10 02:28:49 -07001983 }
1984 break;
1985
Dan Williamsa7e255a2011-05-11 08:27:47 -07001986 /* TODO Check to see if any of these completion status need to
1987 * wait for the device to host register fis.
1988 */
1989 /* TODO We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR
1990 * - this comes only for B0
1991 */
Dan Williams5dec6f42011-05-10 02:28:49 -07001992 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
1993 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1994 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
1995 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
1996 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
1997 scic_sds_remote_device_suspend(sci_req->target_device,
1998 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
1999 /* Fall through to the default case */
2000 default:
2001 /* All other completion status cause the IO to be complete. */
2002 scic_sds_stp_request_udma_complete_request(sci_req,
2003 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2004 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
2005 break;
2006 }
2007
2008 return status;
2009}
2010
Edmund Nadolskie3013702011-06-02 00:10:43 +00002011static enum sci_status
2012stp_request_soft_reset_await_h2d_asserted_tc_event(struct scic_sds_request *sci_req,
2013 u32 completion_code)
Dan Williams5dec6f42011-05-10 02:28:49 -07002014{
2015 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
2016 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
Dan Williamsa7e255a2011-05-11 08:27:47 -07002017 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
2018 SCI_SUCCESS);
Dan Williams5dec6f42011-05-10 02:28:49 -07002019
Edmund Nadolskie3013702011-06-02 00:10:43 +00002020 sci_change_state(&sci_req->sm, SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG);
Dan Williams5dec6f42011-05-10 02:28:49 -07002021 break;
2022
2023 default:
2024 /*
Edmund Nadolskie3013702011-06-02 00:10:43 +00002025 * All other completion status cause the IO to be complete.
2026 * If a NAK was received, then it is up to the user to retry
2027 * the request.
2028 */
Dan Williamsa7e255a2011-05-11 08:27:47 -07002029 scic_sds_request_set_status(sci_req,
Edmund Nadolskie3013702011-06-02 00:10:43 +00002030 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2031 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williams5dec6f42011-05-10 02:28:49 -07002032
Edmund Nadolskie3013702011-06-02 00:10:43 +00002033 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williams5dec6f42011-05-10 02:28:49 -07002034 break;
2035 }
2036
2037 return SCI_SUCCESS;
2038}
2039
Edmund Nadolskie3013702011-06-02 00:10:43 +00002040static enum sci_status
2041stp_request_soft_reset_await_h2d_diagnostic_tc_event(struct scic_sds_request *sci_req,
2042 u32 completion_code)
Dan Williams5dec6f42011-05-10 02:28:49 -07002043{
2044 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
2045 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2046 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
2047 SCI_SUCCESS);
2048
Edmund Nadolskie3013702011-06-02 00:10:43 +00002049 sci_change_state(&sci_req->sm, SCI_REQ_STP_SOFT_RESET_WAIT_D2H);
Dan Williams5dec6f42011-05-10 02:28:49 -07002050 break;
2051
2052 default:
Dan Williamsa7e255a2011-05-11 08:27:47 -07002053 /* All other completion status cause the IO to be complete. If
2054 * a NAK was received, then it is up to the user to retry the
2055 * request.
2056 */
2057 scic_sds_request_set_status(sci_req,
Dan Williams5dec6f42011-05-10 02:28:49 -07002058 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
Dan Williamsa7e255a2011-05-11 08:27:47 -07002059 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williams5dec6f42011-05-10 02:28:49 -07002060
Edmund Nadolskie3013702011-06-02 00:10:43 +00002061 sci_change_state(&sci_req->sm, SCI_REQ_COMPLETED);
Dan Williams5dec6f42011-05-10 02:28:49 -07002062 break;
2063 }
2064
2065 return SCI_SUCCESS;
2066}
2067
Dan Williamsa7e255a2011-05-11 08:27:47 -07002068enum sci_status
Edmund Nadolskie3013702011-06-02 00:10:43 +00002069scic_sds_io_request_tc_completion(struct scic_sds_request *sci_req,
2070 u32 completion_code)
Dan Williamsa7e255a2011-05-11 08:27:47 -07002071{
2072 enum sci_base_request_states state;
2073 struct scic_sds_controller *scic = sci_req->owning_controller;
2074
Edmund Nadolskie3013702011-06-02 00:10:43 +00002075 state = sci_req->sm.current_state_id;
Dan Williamsa7e255a2011-05-11 08:27:47 -07002076
2077 switch (state) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00002078 case SCI_REQ_STARTED:
2079 return request_started_state_tc_event(sci_req, completion_code);
2080
2081 case SCI_REQ_TASK_WAIT_TC_COMP:
2082 return ssp_task_request_await_tc_event(sci_req,
2083 completion_code);
2084
2085 case SCI_REQ_SMP_WAIT_RESP:
2086 return smp_request_await_response_tc_event(sci_req,
2087 completion_code);
2088
2089 case SCI_REQ_SMP_WAIT_TC_COMP:
2090 return smp_request_await_tc_event(sci_req, completion_code);
2091
2092 case SCI_REQ_STP_UDMA_WAIT_TC_COMP:
2093 return stp_request_udma_await_tc_event(sci_req,
2094 completion_code);
2095
2096 case SCI_REQ_STP_NON_DATA_WAIT_H2D:
2097 return stp_request_non_data_await_h2d_tc_event(sci_req,
2098 completion_code);
2099
2100 case SCI_REQ_STP_PIO_WAIT_H2D:
2101 return stp_request_pio_await_h2d_completion_tc_event(sci_req,
2102 completion_code);
2103
2104 case SCI_REQ_STP_PIO_DATA_OUT:
2105 return pio_data_out_tx_done_tc_event(sci_req, completion_code);
2106
2107 case SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED:
2108 return stp_request_soft_reset_await_h2d_asserted_tc_event(sci_req,
2109 completion_code);
2110
2111 case SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG:
2112 return stp_request_soft_reset_await_h2d_diagnostic_tc_event(sci_req,
2113 completion_code);
2114
2115 case SCI_REQ_ABORTING:
2116 return request_aborting_state_tc_event(sci_req,
2117 completion_code);
2118
2119 default:
2120 dev_warn(scic_to_dev(scic),
2121 "%s: SCIC IO Request given task completion "
2122 "notification %x while in wrong state %d\n",
2123 __func__,
2124 completion_code,
2125 state);
2126 return SCI_FAILURE_INVALID_STATE;
Dan Williamsa7e255a2011-05-11 08:27:47 -07002127 }
2128}
2129
Dan Williams6f231dd2011-07-02 22:56:22 -07002130/**
2131 * isci_request_process_response_iu() - This function sets the status and
2132 * response iu, in the task struct, from the request object for the upper
2133 * layer driver.
2134 * @sas_task: This parameter is the task struct from the upper layer driver.
2135 * @resp_iu: This parameter points to the response iu of the completed request.
2136 * @dev: This parameter specifies the linux device struct.
2137 *
2138 * none.
2139 */
2140static void isci_request_process_response_iu(
2141 struct sas_task *task,
2142 struct ssp_response_iu *resp_iu,
2143 struct device *dev)
2144{
2145 dev_dbg(dev,
2146 "%s: resp_iu = %p "
2147 "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
2148 "resp_iu->response_data_len = %x, "
2149 "resp_iu->sense_data_len = %x\nrepsonse data: ",
2150 __func__,
2151 resp_iu,
2152 resp_iu->status,
2153 resp_iu->datapres,
2154 resp_iu->response_data_len,
2155 resp_iu->sense_data_len);
2156
2157 task->task_status.stat = resp_iu->status;
2158
2159 /* libsas updates the task status fields based on the response iu. */
2160 sas_ssp_task_response(dev, task, resp_iu);
2161}
2162
2163/**
2164 * isci_request_set_open_reject_status() - This function prepares the I/O
2165 * completion for OPEN_REJECT conditions.
2166 * @request: This parameter is the completed isci_request object.
2167 * @response_ptr: This parameter specifies the service response for the I/O.
2168 * @status_ptr: This parameter specifies the exec status for the I/O.
2169 * @complete_to_host_ptr: This parameter specifies the action to be taken by
2170 * the LLDD with respect to completing this request or forcing an abort
2171 * condition on the I/O.
2172 * @open_rej_reason: This parameter specifies the encoded reason for the
2173 * abandon-class reject.
2174 *
2175 * none.
2176 */
2177static void isci_request_set_open_reject_status(
2178 struct isci_request *request,
2179 struct sas_task *task,
2180 enum service_response *response_ptr,
2181 enum exec_status *status_ptr,
2182 enum isci_completion_selection *complete_to_host_ptr,
2183 enum sas_open_rej_reason open_rej_reason)
2184{
2185 /* Task in the target is done. */
2186 request->complete_in_target = true;
2187 *response_ptr = SAS_TASK_UNDELIVERED;
2188 *status_ptr = SAS_OPEN_REJECT;
2189 *complete_to_host_ptr = isci_perform_normal_io_completion;
2190 task->task_status.open_rej_reason = open_rej_reason;
2191}
2192
2193/**
2194 * isci_request_handle_controller_specific_errors() - This function decodes
2195 * controller-specific I/O completion error conditions.
2196 * @request: This parameter is the completed isci_request object.
2197 * @response_ptr: This parameter specifies the service response for the I/O.
2198 * @status_ptr: This parameter specifies the exec status for the I/O.
2199 * @complete_to_host_ptr: This parameter specifies the action to be taken by
2200 * the LLDD with respect to completing this request or forcing an abort
2201 * condition on the I/O.
2202 *
2203 * none.
2204 */
2205static void isci_request_handle_controller_specific_errors(
Dan Williams209fae12011-06-13 17:39:44 -07002206 struct isci_remote_device *idev,
Dan Williams6f231dd2011-07-02 22:56:22 -07002207 struct isci_request *request,
2208 struct sas_task *task,
2209 enum service_response *response_ptr,
2210 enum exec_status *status_ptr,
2211 enum isci_completion_selection *complete_to_host_ptr)
2212{
2213 unsigned int cstatus;
2214
Dan Williamsf1f52e72011-05-10 02:28:45 -07002215 cstatus = request->sci.scu_status;
Dan Williams6f231dd2011-07-02 22:56:22 -07002216
2217 dev_dbg(&request->isci_host->pdev->dev,
2218 "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
2219 "- controller status = 0x%x\n",
2220 __func__, request, cstatus);
2221
2222 /* Decode the controller-specific errors; most
2223 * important is to recognize those conditions in which
2224 * the target may still have a task outstanding that
2225 * must be aborted.
2226 *
2227 * Note that there are SCU completion codes being
2228 * named in the decode below for which SCIC has already
2229 * done work to handle them in a way other than as
2230 * a controller-specific completion code; these are left
2231 * in the decode below for completeness sake.
2232 */
2233 switch (cstatus) {
2234 case SCU_TASK_DONE_DMASETUP_DIRERR:
2235 /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
2236 case SCU_TASK_DONE_XFERCNT_ERR:
2237 /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
2238 if (task->task_proto == SAS_PROTOCOL_SMP) {
2239 /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
2240 *response_ptr = SAS_TASK_COMPLETE;
2241
2242 /* See if the device has been/is being stopped. Note
2243 * that we ignore the quiesce state, since we are
2244 * concerned about the actual device state.
2245 */
Dan Williams209fae12011-06-13 17:39:44 -07002246 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002247 *status_ptr = SAS_DEVICE_UNKNOWN;
2248 else
2249 *status_ptr = SAS_ABORTED_TASK;
2250
2251 request->complete_in_target = true;
2252
2253 *complete_to_host_ptr =
2254 isci_perform_normal_io_completion;
2255 } else {
2256 /* Task in the target is not done. */
2257 *response_ptr = SAS_TASK_UNDELIVERED;
2258
Dan Williams209fae12011-06-13 17:39:44 -07002259 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002260 *status_ptr = SAS_DEVICE_UNKNOWN;
2261 else
2262 *status_ptr = SAM_STAT_TASK_ABORTED;
2263
2264 request->complete_in_target = false;
2265
2266 *complete_to_host_ptr =
2267 isci_perform_error_io_completion;
2268 }
2269
2270 break;
2271
2272 case SCU_TASK_DONE_CRC_ERR:
2273 case SCU_TASK_DONE_NAK_CMD_ERR:
2274 case SCU_TASK_DONE_EXCESS_DATA:
2275 case SCU_TASK_DONE_UNEXP_FIS:
2276 /* Also SCU_TASK_DONE_UNEXP_RESP: */
2277 case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
2278 case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
2279 case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
2280 /* These are conditions in which the target
2281 * has completed the task, so that no cleanup
2282 * is necessary.
2283 */
2284 *response_ptr = SAS_TASK_COMPLETE;
2285
2286 /* See if the device has been/is being stopped. Note
2287 * that we ignore the quiesce state, since we are
2288 * concerned about the actual device state.
2289 */
Dan Williams209fae12011-06-13 17:39:44 -07002290 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002291 *status_ptr = SAS_DEVICE_UNKNOWN;
2292 else
2293 *status_ptr = SAS_ABORTED_TASK;
2294
2295 request->complete_in_target = true;
2296
2297 *complete_to_host_ptr = isci_perform_normal_io_completion;
2298 break;
2299
2300
2301 /* Note that the only open reject completion codes seen here will be
2302 * abandon-class codes; all others are automatically retried in the SCU.
2303 */
2304 case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
2305
2306 isci_request_set_open_reject_status(
2307 request, task, response_ptr, status_ptr,
2308 complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
2309 break;
2310
2311 case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
2312
2313 /* Note - the return of AB0 will change when
2314 * libsas implements detection of zone violations.
2315 */
2316 isci_request_set_open_reject_status(
2317 request, task, response_ptr, status_ptr,
2318 complete_to_host_ptr, SAS_OREJ_RESV_AB0);
2319 break;
2320
2321 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
2322
2323 isci_request_set_open_reject_status(
2324 request, task, response_ptr, status_ptr,
2325 complete_to_host_ptr, SAS_OREJ_RESV_AB1);
2326 break;
2327
2328 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
2329
2330 isci_request_set_open_reject_status(
2331 request, task, response_ptr, status_ptr,
2332 complete_to_host_ptr, SAS_OREJ_RESV_AB2);
2333 break;
2334
2335 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
2336
2337 isci_request_set_open_reject_status(
2338 request, task, response_ptr, status_ptr,
2339 complete_to_host_ptr, SAS_OREJ_RESV_AB3);
2340 break;
2341
2342 case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
2343
2344 isci_request_set_open_reject_status(
2345 request, task, response_ptr, status_ptr,
2346 complete_to_host_ptr, SAS_OREJ_BAD_DEST);
2347 break;
2348
2349 case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
2350
2351 isci_request_set_open_reject_status(
2352 request, task, response_ptr, status_ptr,
2353 complete_to_host_ptr, SAS_OREJ_STP_NORES);
2354 break;
2355
2356 case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
2357
2358 isci_request_set_open_reject_status(
2359 request, task, response_ptr, status_ptr,
2360 complete_to_host_ptr, SAS_OREJ_EPROTO);
2361 break;
2362
2363 case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
2364
2365 isci_request_set_open_reject_status(
2366 request, task, response_ptr, status_ptr,
2367 complete_to_host_ptr, SAS_OREJ_CONN_RATE);
2368 break;
2369
2370 case SCU_TASK_DONE_LL_R_ERR:
2371 /* Also SCU_TASK_DONE_ACK_NAK_TO: */
2372 case SCU_TASK_DONE_LL_PERR:
2373 case SCU_TASK_DONE_LL_SY_TERM:
2374 /* Also SCU_TASK_DONE_NAK_ERR:*/
2375 case SCU_TASK_DONE_LL_LF_TERM:
2376 /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
2377 case SCU_TASK_DONE_LL_ABORT_ERR:
2378 case SCU_TASK_DONE_SEQ_INV_TYPE:
2379 /* Also SCU_TASK_DONE_UNEXP_XR: */
2380 case SCU_TASK_DONE_XR_IU_LEN_ERR:
2381 case SCU_TASK_DONE_INV_FIS_LEN:
2382 /* Also SCU_TASK_DONE_XR_WD_LEN: */
2383 case SCU_TASK_DONE_SDMA_ERR:
2384 case SCU_TASK_DONE_OFFSET_ERR:
2385 case SCU_TASK_DONE_MAX_PLD_ERR:
2386 case SCU_TASK_DONE_LF_ERR:
2387 case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
2388 case SCU_TASK_DONE_SMP_LL_RX_ERR:
2389 case SCU_TASK_DONE_UNEXP_DATA:
2390 case SCU_TASK_DONE_UNEXP_SDBFIS:
2391 case SCU_TASK_DONE_REG_ERR:
2392 case SCU_TASK_DONE_SDB_ERR:
2393 case SCU_TASK_DONE_TASK_ABORT:
2394 default:
2395 /* Task in the target is not done. */
2396 *response_ptr = SAS_TASK_UNDELIVERED;
2397 *status_ptr = SAM_STAT_TASK_ABORTED;
Dan Williams6f231dd2011-07-02 22:56:22 -07002398
Jeff Skirvincde76fb2011-06-20 14:09:06 -07002399 if (task->task_proto == SAS_PROTOCOL_SMP) {
2400 request->complete_in_target = true;
2401
2402 *complete_to_host_ptr = isci_perform_normal_io_completion;
2403 } else {
2404 request->complete_in_target = false;
2405
2406 *complete_to_host_ptr = isci_perform_error_io_completion;
2407 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002408 break;
2409 }
2410}
2411
2412/**
2413 * isci_task_save_for_upper_layer_completion() - This function saves the
2414 * request for later completion to the upper layer driver.
2415 * @host: This parameter is a pointer to the host on which the the request
2416 * should be queued (either as an error or success).
2417 * @request: This parameter is the completed request.
2418 * @response: This parameter is the response code for the completed task.
2419 * @status: This parameter is the status code for the completed task.
2420 *
2421 * none.
2422 */
2423static void isci_task_save_for_upper_layer_completion(
2424 struct isci_host *host,
2425 struct isci_request *request,
2426 enum service_response response,
2427 enum exec_status status,
2428 enum isci_completion_selection task_notification_selection)
2429{
2430 struct sas_task *task = isci_request_access_task(request);
2431
Jeff Skirvinec6c9632011-03-04 14:06:44 -08002432 task_notification_selection
2433 = isci_task_set_completion_status(task, response, status,
2434 task_notification_selection);
Dan Williams6f231dd2011-07-02 22:56:22 -07002435
2436 /* Tasks aborted specifically by a call to the lldd_abort_task
2437 * function should not be completed to the host in the regular path.
2438 */
2439 switch (task_notification_selection) {
2440
2441 case isci_perform_normal_io_completion:
2442
2443 /* Normal notification (task_done) */
2444 dev_dbg(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002445 "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07002446 __func__,
2447 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002448 task->task_status.resp, response,
2449 task->task_status.stat, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002450 /* Add to the completed list. */
2451 list_add(&request->completed_node,
2452 &host->requests_to_complete);
Jeff Skirvinec6c9632011-03-04 14:06:44 -08002453
2454 /* Take the request off the device's pending request list. */
2455 list_del_init(&request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -07002456 break;
2457
2458 case isci_perform_aborted_io_completion:
Jeff Skirvina5fde222011-03-04 14:06:42 -08002459 /* No notification to libsas because this request is
2460 * already in the abort path.
Dan Williams6f231dd2011-07-02 22:56:22 -07002461 */
2462 dev_warn(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002463 "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07002464 __func__,
2465 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002466 task->task_status.resp, response,
2467 task->task_status.stat, status);
Jeff Skirvina5fde222011-03-04 14:06:42 -08002468
2469 /* Wake up whatever process was waiting for this
2470 * request to complete.
2471 */
2472 WARN_ON(request->io_request_completion == NULL);
2473
2474 if (request->io_request_completion != NULL) {
2475
2476 /* Signal whoever is waiting that this
2477 * request is complete.
2478 */
2479 complete(request->io_request_completion);
2480 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002481 break;
2482
2483 case isci_perform_error_io_completion:
2484 /* Use sas_task_abort */
2485 dev_warn(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002486 "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07002487 __func__,
2488 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002489 task->task_status.resp, response,
2490 task->task_status.stat, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002491 /* Add to the aborted list. */
2492 list_add(&request->completed_node,
Jeff Skirvin11b00c12011-03-04 14:06:40 -08002493 &host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -07002494 break;
2495
2496 default:
2497 dev_warn(&host->pdev->dev,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002498 "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07002499 __func__,
2500 task,
Jeff Skirvinaa145102011-03-07 16:40:47 -07002501 task->task_status.resp, response,
2502 task->task_status.stat, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002503
Jeff Skirvina5fde222011-03-04 14:06:42 -08002504 /* Add to the error to libsas list. */
Dan Williams6f231dd2011-07-02 22:56:22 -07002505 list_add(&request->completed_node,
Jeff Skirvin11b00c12011-03-04 14:06:40 -08002506 &host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -07002507 break;
2508 }
2509}
2510
Dan Williamsf1f52e72011-05-10 02:28:45 -07002511static void isci_request_io_request_complete(struct isci_host *isci_host,
2512 struct isci_request *request,
2513 enum sci_io_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -07002514{
2515 struct sas_task *task = isci_request_access_task(request);
2516 struct ssp_response_iu *resp_iu;
2517 void *resp_buf;
2518 unsigned long task_flags;
Dan Williams209fae12011-06-13 17:39:44 -07002519 struct isci_remote_device *idev = isci_lookup_device(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002520 enum service_response response = SAS_TASK_UNDELIVERED;
2521 enum exec_status status = SAS_ABORTED_TASK;
2522 enum isci_request_status request_status;
2523 enum isci_completion_selection complete_to_host
2524 = isci_perform_normal_io_completion;
2525
2526 dev_dbg(&isci_host->pdev->dev,
2527 "%s: request = %p, task = %p,\n"
2528 "task->data_dir = %d completion_status = 0x%x\n",
2529 __func__,
2530 request,
2531 task,
2532 task->data_dir,
2533 completion_status);
2534
Jeff Skirvina5fde222011-03-04 14:06:42 -08002535 spin_lock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002536 request_status = isci_request_get_state(request);
Dan Williams6f231dd2011-07-02 22:56:22 -07002537
2538 /* Decode the request status. Note that if the request has been
2539 * aborted by a task management function, we don't care
2540 * what the status is.
2541 */
2542 switch (request_status) {
2543
2544 case aborted:
2545 /* "aborted" indicates that the request was aborted by a task
2546 * management function, since once a task management request is
2547 * perfomed by the device, the request only completes because
2548 * of the subsequent driver terminate.
2549 *
2550 * Aborted also means an external thread is explicitly managing
2551 * this request, so that we do not complete it up the stack.
2552 *
2553 * The target is still there (since the TMF was successful).
2554 */
2555 request->complete_in_target = true;
2556 response = SAS_TASK_COMPLETE;
2557
2558 /* See if the device has been/is being stopped. Note
2559 * that we ignore the quiesce state, since we are
2560 * concerned about the actual device state.
2561 */
Dan Williams209fae12011-06-13 17:39:44 -07002562 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002563 status = SAS_DEVICE_UNKNOWN;
2564 else
2565 status = SAS_ABORTED_TASK;
2566
2567 complete_to_host = isci_perform_aborted_io_completion;
2568 /* This was an aborted request. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08002569
2570 spin_unlock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002571 break;
2572
2573 case aborting:
2574 /* aborting means that the task management function tried and
2575 * failed to abort the request. We need to note the request
2576 * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
2577 * target as down.
2578 *
2579 * Aborting also means an external thread is explicitly managing
2580 * this request, so that we do not complete it up the stack.
2581 */
2582 request->complete_in_target = true;
2583 response = SAS_TASK_UNDELIVERED;
2584
Dan Williams209fae12011-06-13 17:39:44 -07002585 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002586 /* The device has been /is being stopped. Note that
2587 * we ignore the quiesce state, since we are
2588 * concerned about the actual device state.
2589 */
2590 status = SAS_DEVICE_UNKNOWN;
2591 else
2592 status = SAS_PHY_DOWN;
2593
2594 complete_to_host = isci_perform_aborted_io_completion;
2595
2596 /* This was an aborted request. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08002597
2598 spin_unlock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002599 break;
2600
2601 case terminating:
2602
2603 /* This was an terminated request. This happens when
2604 * the I/O is being terminated because of an action on
2605 * the device (reset, tear down, etc.), and the I/O needs
2606 * to be completed up the stack.
2607 */
2608 request->complete_in_target = true;
2609 response = SAS_TASK_UNDELIVERED;
2610
2611 /* See if the device has been/is being stopped. Note
2612 * that we ignore the quiesce state, since we are
2613 * concerned about the actual device state.
2614 */
Dan Williams209fae12011-06-13 17:39:44 -07002615 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002616 status = SAS_DEVICE_UNKNOWN;
2617 else
2618 status = SAS_ABORTED_TASK;
2619
Jeff Skirvina5fde222011-03-04 14:06:42 -08002620 complete_to_host = isci_perform_aborted_io_completion;
Dan Williams6f231dd2011-07-02 22:56:22 -07002621
2622 /* This was a terminated request. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08002623
2624 spin_unlock(&request->state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002625 break;
2626
Jeff Skirvin77c852f2011-06-20 14:09:16 -07002627 case dead:
2628 /* This was a terminated request that timed-out during the
2629 * termination process. There is no task to complete to
2630 * libsas.
2631 */
2632 complete_to_host = isci_perform_normal_io_completion;
2633 spin_unlock(&request->state_lock);
2634 break;
2635
Dan Williams6f231dd2011-07-02 22:56:22 -07002636 default:
2637
Jeff Skirvina5fde222011-03-04 14:06:42 -08002638 /* The request is done from an SCU HW perspective. */
2639 request->status = completed;
2640
2641 spin_unlock(&request->state_lock);
2642
Dan Williams6f231dd2011-07-02 22:56:22 -07002643 /* This is an active request being completed from the core. */
2644 switch (completion_status) {
2645
2646 case SCI_IO_FAILURE_RESPONSE_VALID:
2647 dev_dbg(&isci_host->pdev->dev,
2648 "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
2649 __func__,
2650 request,
2651 task);
2652
2653 if (sas_protocol_ata(task->task_proto)) {
Dan Williams67ea8382011-05-08 11:47:15 -07002654 resp_buf = &request->sci.stp.rsp;
Dan Williams6f231dd2011-07-02 22:56:22 -07002655 isci_request_process_stp_response(task,
Dan Williamsb7645812011-05-08 02:35:32 -07002656 resp_buf);
Dan Williams6f231dd2011-07-02 22:56:22 -07002657 } else if (SAS_PROTOCOL_SSP == task->task_proto) {
2658
2659 /* crack the iu response buffer. */
Dan Williams67ea8382011-05-08 11:47:15 -07002660 resp_iu = &request->sci.ssp.rsp;
Dan Williams6f231dd2011-07-02 22:56:22 -07002661 isci_request_process_response_iu(task, resp_iu,
Dan Williamsb7645812011-05-08 02:35:32 -07002662 &isci_host->pdev->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002663
2664 } else if (SAS_PROTOCOL_SMP == task->task_proto) {
2665
2666 dev_err(&isci_host->pdev->dev,
2667 "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
2668 "SAS_PROTOCOL_SMP protocol\n",
2669 __func__);
2670
2671 } else
2672 dev_err(&isci_host->pdev->dev,
2673 "%s: unknown protocol\n", __func__);
2674
2675 /* use the task status set in the task struct by the
2676 * isci_request_process_response_iu call.
2677 */
2678 request->complete_in_target = true;
2679 response = task->task_status.resp;
2680 status = task->task_status.stat;
2681 break;
2682
2683 case SCI_IO_SUCCESS:
2684 case SCI_IO_SUCCESS_IO_DONE_EARLY:
2685
2686 response = SAS_TASK_COMPLETE;
2687 status = SAM_STAT_GOOD;
2688 request->complete_in_target = true;
2689
2690 if (task->task_proto == SAS_PROTOCOL_SMP) {
Dan Williams67ea8382011-05-08 11:47:15 -07002691 void *rsp = &request->sci.smp.rsp;
Dan Williams6f231dd2011-07-02 22:56:22 -07002692
2693 dev_dbg(&isci_host->pdev->dev,
2694 "%s: SMP protocol completion\n",
2695 __func__);
2696
2697 sg_copy_from_buffer(
2698 &task->smp_task.smp_resp, 1,
Dan Williamsb7645812011-05-08 02:35:32 -07002699 rsp, sizeof(struct smp_resp));
Dan Williams6f231dd2011-07-02 22:56:22 -07002700 } else if (completion_status
2701 == SCI_IO_SUCCESS_IO_DONE_EARLY) {
2702
2703 /* This was an SSP / STP / SATA transfer.
2704 * There is a possibility that less data than
2705 * the maximum was transferred.
2706 */
Dan Williamsf1f52e72011-05-10 02:28:45 -07002707 u32 transferred_length = sci_req_tx_bytes(&request->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07002708
2709 task->task_status.residual
2710 = task->total_xfer_len - transferred_length;
2711
2712 /* If there were residual bytes, call this an
2713 * underrun.
2714 */
2715 if (task->task_status.residual != 0)
2716 status = SAS_DATA_UNDERRUN;
2717
2718 dev_dbg(&isci_host->pdev->dev,
2719 "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
2720 __func__,
2721 status);
2722
2723 } else
2724 dev_dbg(&isci_host->pdev->dev,
2725 "%s: SCI_IO_SUCCESS\n",
2726 __func__);
2727
2728 break;
2729
2730 case SCI_IO_FAILURE_TERMINATED:
2731 dev_dbg(&isci_host->pdev->dev,
2732 "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
2733 __func__,
2734 request,
2735 task);
2736
2737 /* The request was terminated explicitly. No handling
2738 * is needed in the SCSI error handler path.
2739 */
2740 request->complete_in_target = true;
2741 response = SAS_TASK_UNDELIVERED;
2742
2743 /* See if the device has been/is being stopped. Note
2744 * that we ignore the quiesce state, since we are
2745 * concerned about the actual device state.
2746 */
Dan Williams209fae12011-06-13 17:39:44 -07002747 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002748 status = SAS_DEVICE_UNKNOWN;
2749 else
2750 status = SAS_ABORTED_TASK;
2751
2752 complete_to_host = isci_perform_normal_io_completion;
2753 break;
2754
2755 case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
2756
2757 isci_request_handle_controller_specific_errors(
Dan Williams209fae12011-06-13 17:39:44 -07002758 idev, request, task, &response, &status,
Dan Williams6f231dd2011-07-02 22:56:22 -07002759 &complete_to_host);
2760
2761 break;
2762
2763 case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
2764 /* This is a special case, in that the I/O completion
2765 * is telling us that the device needs a reset.
2766 * In order for the device reset condition to be
2767 * noticed, the I/O has to be handled in the error
2768 * handler. Set the reset flag and cause the
2769 * SCSI error thread to be scheduled.
2770 */
2771 spin_lock_irqsave(&task->task_state_lock, task_flags);
2772 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
2773 spin_unlock_irqrestore(&task->task_state_lock, task_flags);
2774
Jeff Skirvinaa145102011-03-07 16:40:47 -07002775 /* Fail the I/O. */
2776 response = SAS_TASK_UNDELIVERED;
2777 status = SAM_STAT_TASK_ABORTED;
2778
Dan Williams6f231dd2011-07-02 22:56:22 -07002779 complete_to_host = isci_perform_error_io_completion;
2780 request->complete_in_target = false;
2781 break;
2782
Jeff Skirvincde76fb2011-06-20 14:09:06 -07002783 case SCI_FAILURE_RETRY_REQUIRED:
2784
2785 /* Fail the I/O so it can be retried. */
2786 response = SAS_TASK_UNDELIVERED;
Dan Williams209fae12011-06-13 17:39:44 -07002787 if (!idev)
Jeff Skirvincde76fb2011-06-20 14:09:06 -07002788 status = SAS_DEVICE_UNKNOWN;
2789 else
2790 status = SAS_ABORTED_TASK;
2791
2792 complete_to_host = isci_perform_normal_io_completion;
2793 request->complete_in_target = true;
2794 break;
2795
2796
Dan Williams6f231dd2011-07-02 22:56:22 -07002797 default:
2798 /* Catch any otherwise unhandled error codes here. */
2799 dev_warn(&isci_host->pdev->dev,
2800 "%s: invalid completion code: 0x%x - "
2801 "isci_request = %p\n",
2802 __func__, completion_status, request);
2803
2804 response = SAS_TASK_UNDELIVERED;
2805
2806 /* See if the device has been/is being stopped. Note
2807 * that we ignore the quiesce state, since we are
2808 * concerned about the actual device state.
2809 */
Dan Williams209fae12011-06-13 17:39:44 -07002810 if (!idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002811 status = SAS_DEVICE_UNKNOWN;
2812 else
2813 status = SAS_ABORTED_TASK;
2814
Jeff Skirvincde76fb2011-06-20 14:09:06 -07002815 if (SAS_PROTOCOL_SMP == task->task_proto) {
2816 request->complete_in_target = true;
2817 complete_to_host = isci_perform_normal_io_completion;
2818 } else {
2819 request->complete_in_target = false;
2820 complete_to_host = isci_perform_error_io_completion;
2821 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002822 break;
2823 }
2824 break;
2825 }
2826
Dan Williamsddcc7e32011-06-17 10:40:43 -07002827 switch (task->task_proto) {
2828 case SAS_PROTOCOL_SSP:
2829 if (task->data_dir == DMA_NONE)
2830 break;
2831 if (task->num_scatter == 0)
2832 /* 0 indicates a single dma address */
2833 dma_unmap_single(&isci_host->pdev->dev,
2834 request->zero_scatter_daddr,
2835 task->total_xfer_len, task->data_dir);
2836 else /* unmap the sgl dma addresses */
2837 dma_unmap_sg(&isci_host->pdev->dev, task->scatter,
2838 request->num_sg_entries, task->data_dir);
2839 break;
Dan Williamse9bf7092011-06-16 16:59:56 -07002840 case SAS_PROTOCOL_SMP: {
2841 struct scatterlist *sg = &task->smp_task.smp_req;
2842 struct smp_req *smp_req;
2843 void *kaddr;
2844
2845 dma_unmap_sg(&isci_host->pdev->dev, sg, 1, DMA_TO_DEVICE);
2846
2847 /* need to swab it back in case the command buffer is re-used */
2848 kaddr = kmap_atomic(sg_page(sg), KM_IRQ0);
2849 smp_req = kaddr + sg->offset;
2850 sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32));
2851 kunmap_atomic(kaddr, KM_IRQ0);
2852 break;
2853 }
Dan Williamsddcc7e32011-06-17 10:40:43 -07002854 default:
2855 break;
2856 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002857
2858 /* Put the completed request on the correct list */
2859 isci_task_save_for_upper_layer_completion(isci_host, request, response,
2860 status, complete_to_host
2861 );
2862
2863 /* complete the io request to the core. */
Artur Wojcikcc3dbd02011-05-04 07:58:16 +00002864 scic_controller_complete_io(&isci_host->sci,
Dan Williams209fae12011-06-13 17:39:44 -07002865 request->sci.target_device,
Dan Williams67ea8382011-05-08 11:47:15 -07002866 &request->sci);
Dan Williams209fae12011-06-13 17:39:44 -07002867 isci_put_device(idev);
2868
Dan Williams67ea8382011-05-08 11:47:15 -07002869 /* set terminated handle so it cannot be completed or
Dan Williams6f231dd2011-07-02 22:56:22 -07002870 * terminated again, and to cause any calls into abort
2871 * task to recognize the already completed case.
2872 */
Dan Williams67ea8382011-05-08 11:47:15 -07002873 request->terminated = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07002874}
Dan Williamsf1f52e72011-05-10 02:28:45 -07002875
Dan Williams9269e0e2011-05-12 07:42:17 -07002876static void scic_sds_request_started_state_enter(struct sci_base_state_machine *sm)
Dan Williamsf1f52e72011-05-10 02:28:45 -07002877{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002878 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williamsf1393032011-05-10 02:28:47 -07002879 struct isci_request *ireq = sci_req_to_ireq(sci_req);
2880 struct domain_device *dev = sci_dev_to_domain(sci_req->target_device);
Dan Williamsc72086e2011-05-10 02:28:48 -07002881 struct sas_task *task;
2882
2883 /* XXX as hch said always creating an internal sas_task for tmf
2884 * requests would simplify the driver
2885 */
2886 task = ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL;
Dan Williamsf1f52e72011-05-10 02:28:45 -07002887
Dan Williams5dec6f42011-05-10 02:28:49 -07002888 /* all unaccelerated request types (non ssp or ncq) handled with
2889 * substates
Dan Williamsf1393032011-05-10 02:28:47 -07002890 */
Dan Williamsc72086e2011-05-10 02:28:48 -07002891 if (!task && dev->dev_type == SAS_END_DEV) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00002892 sci_change_state(sm, SCI_REQ_TASK_WAIT_TC_COMP);
Dan Williams5dec6f42011-05-10 02:28:49 -07002893 } else if (!task &&
2894 (isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_high ||
2895 isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_low)) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00002896 sci_change_state(sm, SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED);
Dan Williamsc72086e2011-05-10 02:28:48 -07002897 } else if (task && task->task_proto == SAS_PROTOCOL_SMP) {
Edmund Nadolskie3013702011-06-02 00:10:43 +00002898 sci_change_state(sm, SCI_REQ_SMP_WAIT_RESP);
Dan Williams5dec6f42011-05-10 02:28:49 -07002899 } else if (task && sas_protocol_ata(task->task_proto) &&
2900 !task->ata_task.use_ncq) {
2901 u32 state;
2902
2903 if (task->data_dir == DMA_NONE)
Edmund Nadolskie3013702011-06-02 00:10:43 +00002904 state = SCI_REQ_STP_NON_DATA_WAIT_H2D;
Dan Williams5dec6f42011-05-10 02:28:49 -07002905 else if (task->ata_task.dma_xfer)
Edmund Nadolskie3013702011-06-02 00:10:43 +00002906 state = SCI_REQ_STP_UDMA_WAIT_TC_COMP;
Dan Williams5dec6f42011-05-10 02:28:49 -07002907 else /* PIO */
Edmund Nadolskie3013702011-06-02 00:10:43 +00002908 state = SCI_REQ_STP_PIO_WAIT_H2D;
Dan Williams5dec6f42011-05-10 02:28:49 -07002909
Edmund Nadolskie3013702011-06-02 00:10:43 +00002910 sci_change_state(sm, state);
Dan Williamsc72086e2011-05-10 02:28:48 -07002911 }
Dan Williamsf1f52e72011-05-10 02:28:45 -07002912}
2913
Dan Williams9269e0e2011-05-12 07:42:17 -07002914static void scic_sds_request_completed_state_enter(struct sci_base_state_machine *sm)
Dan Williamsf1f52e72011-05-10 02:28:45 -07002915{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002916 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williams79e2b6b2011-05-11 08:29:56 -07002917 struct scic_sds_controller *scic = sci_req->owning_controller;
Dan Williamsf1f52e72011-05-10 02:28:45 -07002918 struct isci_host *ihost = scic_to_ihost(scic);
2919 struct isci_request *ireq = sci_req_to_ireq(sci_req);
2920
Dan Williamsf1f52e72011-05-10 02:28:45 -07002921 /* Tell the SCI_USER that the IO request is complete */
2922 if (sci_req->is_task_management_request == false)
2923 isci_request_io_request_complete(ihost, ireq,
2924 sci_req->sci_status);
2925 else
2926 isci_task_request_complete(ihost, ireq, sci_req->sci_status);
2927}
2928
Dan Williams9269e0e2011-05-12 07:42:17 -07002929static void scic_sds_request_aborting_state_enter(struct sci_base_state_machine *sm)
Dan Williamsf1f52e72011-05-10 02:28:45 -07002930{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002931 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williamsf1f52e72011-05-10 02:28:45 -07002932
2933 /* Setting the abort bit in the Task Context is required by the silicon. */
Dan Williams312e0c22011-06-28 13:47:09 -07002934 sci_req->tc->abort = 1;
Dan Williamsc72086e2011-05-10 02:28:48 -07002935}
2936
Dan Williams9269e0e2011-05-12 07:42:17 -07002937static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(struct sci_base_state_machine *sm)
Dan Williams5dec6f42011-05-10 02:28:49 -07002938{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002939 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williams5dec6f42011-05-10 02:28:49 -07002940
Dan Williams79e2b6b2011-05-11 08:29:56 -07002941 scic_sds_remote_device_set_working_request(sci_req->target_device,
2942 sci_req);
Dan Williams5dec6f42011-05-10 02:28:49 -07002943}
2944
Dan Williams9269e0e2011-05-12 07:42:17 -07002945static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(struct sci_base_state_machine *sm)
Dan Williams5dec6f42011-05-10 02:28:49 -07002946{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002947 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williams5dec6f42011-05-10 02:28:49 -07002948
Dan Williams79e2b6b2011-05-11 08:29:56 -07002949 scic_sds_remote_device_set_working_request(sci_req->target_device,
2950 sci_req);
Dan Williams5dec6f42011-05-10 02:28:49 -07002951}
2952
Dan Williams9269e0e2011-05-12 07:42:17 -07002953static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(struct sci_base_state_machine *sm)
Dan Williams5dec6f42011-05-10 02:28:49 -07002954{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002955 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williams5dec6f42011-05-10 02:28:49 -07002956
Dan Williams79e2b6b2011-05-11 08:29:56 -07002957 scic_sds_remote_device_set_working_request(sci_req->target_device,
2958 sci_req);
Dan Williams5dec6f42011-05-10 02:28:49 -07002959}
2960
Dan Williams9269e0e2011-05-12 07:42:17 -07002961static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(struct sci_base_state_machine *sm)
Dan Williams5dec6f42011-05-10 02:28:49 -07002962{
Edmund Nadolskie3013702011-06-02 00:10:43 +00002963 struct scic_sds_request *sci_req = container_of(sm, typeof(*sci_req), sm);
Dan Williams312e0c22011-06-28 13:47:09 -07002964 struct scu_task_context *tc = sci_req->tc;
Dan Williams5dec6f42011-05-10 02:28:49 -07002965 struct host_to_dev_fis *h2d_fis;
2966 enum sci_status status;
2967
2968 /* Clear the SRST bit */
2969 h2d_fis = &sci_req->stp.cmd;
2970 h2d_fis->control = 0;
2971
2972 /* Clear the TC control bit */
Dan Williams312e0c22011-06-28 13:47:09 -07002973 tc->control_frame = 0;
Dan Williams5dec6f42011-05-10 02:28:49 -07002974
2975 status = scic_controller_continue_io(sci_req);
Dan Williams79e2b6b2011-05-11 08:29:56 -07002976 WARN_ONCE(status != SCI_SUCCESS, "isci: continue io failure\n");
Dan Williams5dec6f42011-05-10 02:28:49 -07002977}
2978
Dan Williamsf1f52e72011-05-10 02:28:45 -07002979static const struct sci_base_state scic_sds_request_state_table[] = {
Edmund Nadolskie3013702011-06-02 00:10:43 +00002980 [SCI_REQ_INIT] = { },
2981 [SCI_REQ_CONSTRUCTED] = { },
2982 [SCI_REQ_STARTED] = {
Dan Williamsf1f52e72011-05-10 02:28:45 -07002983 .enter_state = scic_sds_request_started_state_enter,
Dan Williams5dec6f42011-05-10 02:28:49 -07002984 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00002985 [SCI_REQ_STP_NON_DATA_WAIT_H2D] = {
Dan Williams5dec6f42011-05-10 02:28:49 -07002986 .enter_state = scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
2987 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00002988 [SCI_REQ_STP_NON_DATA_WAIT_D2H] = { },
2989 [SCI_REQ_STP_PIO_WAIT_H2D] = {
Dan Williams5dec6f42011-05-10 02:28:49 -07002990 .enter_state = scic_sds_stp_request_started_pio_await_h2d_completion_enter,
2991 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00002992 [SCI_REQ_STP_PIO_WAIT_FRAME] = { },
2993 [SCI_REQ_STP_PIO_DATA_IN] = { },
2994 [SCI_REQ_STP_PIO_DATA_OUT] = { },
2995 [SCI_REQ_STP_UDMA_WAIT_TC_COMP] = { },
2996 [SCI_REQ_STP_UDMA_WAIT_D2H] = { },
2997 [SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED] = {
Dan Williams5dec6f42011-05-10 02:28:49 -07002998 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
2999 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00003000 [SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG] = {
Dan Williams5dec6f42011-05-10 02:28:49 -07003001 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
3002 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00003003 [SCI_REQ_STP_SOFT_RESET_WAIT_D2H] = { },
3004 [SCI_REQ_TASK_WAIT_TC_COMP] = { },
3005 [SCI_REQ_TASK_WAIT_TC_RESP] = { },
3006 [SCI_REQ_SMP_WAIT_RESP] = { },
3007 [SCI_REQ_SMP_WAIT_TC_COMP] = { },
3008 [SCI_REQ_COMPLETED] = {
Dan Williamsf1f52e72011-05-10 02:28:45 -07003009 .enter_state = scic_sds_request_completed_state_enter,
3010 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00003011 [SCI_REQ_ABORTING] = {
Dan Williamsf1f52e72011-05-10 02:28:45 -07003012 .enter_state = scic_sds_request_aborting_state_enter,
3013 },
Edmund Nadolskie3013702011-06-02 00:10:43 +00003014 [SCI_REQ_FINAL] = { },
Dan Williamsf1f52e72011-05-10 02:28:45 -07003015};
3016
Edmund Nadolskie3013702011-06-02 00:10:43 +00003017static void
3018scic_sds_general_request_construct(struct scic_sds_controller *scic,
3019 struct scic_sds_remote_device *sci_dev,
3020 u16 io_tag,
3021 struct scic_sds_request *sci_req)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003022{
Edmund Nadolski12ef6542011-06-02 00:10:50 +00003023 sci_init_sm(&sci_req->sm, scic_sds_request_state_table, SCI_REQ_INIT);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003024
3025 sci_req->io_tag = io_tag;
3026 sci_req->owning_controller = scic;
3027 sci_req->target_device = sci_dev;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003028 sci_req->protocol = SCIC_NO_PROTOCOL;
3029 sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003030
3031 sci_req->sci_status = SCI_SUCCESS;
3032 sci_req->scu_status = 0;
3033 sci_req->post_context = 0xFFFFFFFF;
Dan Williams312e0c22011-06-28 13:47:09 -07003034 sci_req->tc = &scic->task_context_table[ISCI_TAG_TCI(io_tag)];
Dan Williamsf1f52e72011-05-10 02:28:45 -07003035
3036 sci_req->is_task_management_request = false;
Dan Williams312e0c22011-06-28 13:47:09 -07003037 WARN_ONCE(io_tag == SCI_CONTROLLER_INVALID_IO_TAG, "straggling invalid tag usage\n");
Dan Williamsf1f52e72011-05-10 02:28:45 -07003038}
3039
3040static enum sci_status
3041scic_io_request_construct(struct scic_sds_controller *scic,
3042 struct scic_sds_remote_device *sci_dev,
3043 u16 io_tag, struct scic_sds_request *sci_req)
3044{
3045 struct domain_device *dev = sci_dev_to_domain(sci_dev);
3046 enum sci_status status = SCI_SUCCESS;
3047
3048 /* Build the common part of the request */
3049 scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
3050
Dan Williamsc72086e2011-05-10 02:28:48 -07003051 if (sci_dev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003052 return SCI_FAILURE_INVALID_REMOTE_DEVICE;
3053
3054 if (dev->dev_type == SAS_END_DEV)
Dan Williamsc72086e2011-05-10 02:28:48 -07003055 /* pass */;
3056 else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
Dan Williamsf1f52e72011-05-10 02:28:45 -07003057 memset(&sci_req->stp.cmd, 0, sizeof(sci_req->stp.cmd));
Dan Williamsc72086e2011-05-10 02:28:48 -07003058 else if (dev_is_expander(dev))
Dan Williamse9bf7092011-06-16 16:59:56 -07003059 /* pass */;
Dan Williamsc72086e2011-05-10 02:28:48 -07003060 else
3061 return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003062
Dan Williams312e0c22011-06-28 13:47:09 -07003063 memset(sci_req->tc, 0, offsetof(struct scu_task_context, sgl_pair_ab));
Dan Williamsf1f52e72011-05-10 02:28:45 -07003064
3065 return status;
3066}
3067
3068enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
3069 struct scic_sds_remote_device *sci_dev,
3070 u16 io_tag, struct scic_sds_request *sci_req)
3071{
3072 struct domain_device *dev = sci_dev_to_domain(sci_dev);
3073 enum sci_status status = SCI_SUCCESS;
3074
3075 /* Build the common part of the request */
3076 scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
3077
Dan Williamsc72086e2011-05-10 02:28:48 -07003078 if (dev->dev_type == SAS_END_DEV ||
3079 dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williamsf1f52e72011-05-10 02:28:45 -07003080 sci_req->is_task_management_request = true;
Dan Williams312e0c22011-06-28 13:47:09 -07003081 memset(sci_req->tc, 0, sizeof(struct scu_task_context));
Dan Williamsc72086e2011-05-10 02:28:48 -07003082 } else
3083 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003084
3085 return status;
3086}
3087
3088static enum sci_status isci_request_ssp_request_construct(
3089 struct isci_request *request)
3090{
3091 enum sci_status status;
3092
3093 dev_dbg(&request->isci_host->pdev->dev,
3094 "%s: request = %p\n",
3095 __func__,
3096 request);
3097 status = scic_io_request_construct_basic_ssp(&request->sci);
3098 return status;
3099}
3100
3101static enum sci_status isci_request_stp_request_construct(
3102 struct isci_request *request)
3103{
3104 struct sas_task *task = isci_request_access_task(request);
3105 enum sci_status status;
3106 struct host_to_dev_fis *register_fis;
3107
3108 dev_dbg(&request->isci_host->pdev->dev,
3109 "%s: request = %p\n",
3110 __func__,
3111 request);
3112
3113 /* Get the host_to_dev_fis from the core and copy
3114 * the fis from the task into it.
3115 */
3116 register_fis = isci_sata_task_to_fis_copy(task);
3117
3118 status = scic_io_request_construct_basic_sata(&request->sci);
3119
3120 /* Set the ncq tag in the fis, from the queue
3121 * command in the task.
3122 */
3123 if (isci_sata_is_task_ncq(task)) {
3124
3125 isci_sata_set_ncq_tag(
3126 register_fis,
3127 task
3128 );
3129 }
3130
3131 return status;
3132}
3133
Dan Williamse9bf7092011-06-16 16:59:56 -07003134static enum sci_status
3135scic_io_request_construct_smp(struct device *dev,
3136 struct scic_sds_request *sci_req,
3137 struct sas_task *task)
Dan Williamsc72086e2011-05-10 02:28:48 -07003138{
Dan Williamse9bf7092011-06-16 16:59:56 -07003139 struct scatterlist *sg = &task->smp_task.smp_req;
Dan Williamsc72086e2011-05-10 02:28:48 -07003140 struct scic_sds_remote_device *sci_dev;
Dan Williamsc72086e2011-05-10 02:28:48 -07003141 struct scu_task_context *task_context;
Dan Williamse9bf7092011-06-16 16:59:56 -07003142 struct scic_sds_port *sci_port;
3143 struct smp_req *smp_req;
3144 void *kaddr;
3145 u8 req_len;
3146 u32 cmd;
3147
3148 kaddr = kmap_atomic(sg_page(sg), KM_IRQ0);
3149 smp_req = kaddr + sg->offset;
3150 /*
3151 * Look at the SMP requests' header fields; for certain SAS 1.x SMP
3152 * functions under SAS 2.0, a zero request length really indicates
3153 * a non-zero default length.
3154 */
3155 if (smp_req->req_len == 0) {
3156 switch (smp_req->func) {
3157 case SMP_DISCOVER:
3158 case SMP_REPORT_PHY_ERR_LOG:
3159 case SMP_REPORT_PHY_SATA:
3160 case SMP_REPORT_ROUTE_INFO:
3161 smp_req->req_len = 2;
3162 break;
3163 case SMP_CONF_ROUTE_INFO:
3164 case SMP_PHY_CONTROL:
3165 case SMP_PHY_TEST_FUNCTION:
3166 smp_req->req_len = 9;
3167 break;
3168 /* Default - zero is a valid default for 2.0. */
3169 }
3170 }
3171 req_len = smp_req->req_len;
3172 sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32));
3173 cmd = *(u32 *) smp_req;
3174 kunmap_atomic(kaddr, KM_IRQ0);
3175
3176 if (!dma_map_sg(dev, sg, 1, DMA_TO_DEVICE))
3177 return SCI_FAILURE;
3178
3179 sci_req->protocol = SCIC_SMP_PROTOCOL;
Dan Williamsc72086e2011-05-10 02:28:48 -07003180
3181 /* byte swap the smp request. */
Dan Williamsc72086e2011-05-10 02:28:48 -07003182
Dan Williams312e0c22011-06-28 13:47:09 -07003183 task_context = sci_req->tc;
Dan Williamsc72086e2011-05-10 02:28:48 -07003184
Dan Williamsc72086e2011-05-10 02:28:48 -07003185 sci_dev = scic_sds_request_get_device(sci_req);
3186 sci_port = scic_sds_request_get_port(sci_req);
3187
3188 /*
3189 * Fill in the TC with the its required data
3190 * 00h
3191 */
3192 task_context->priority = 0;
3193 task_context->initiator_request = 1;
3194 task_context->connection_rate = sci_dev->connection_rate;
3195 task_context->protocol_engine_index =
3196 scic_sds_controller_get_protocol_engine_group(scic);
3197 task_context->logical_port_index = scic_sds_port_get_index(sci_port);
3198 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP;
3199 task_context->abort = 0;
3200 task_context->valid = SCU_TASK_CONTEXT_VALID;
3201 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
3202
3203 /* 04h */
3204 task_context->remote_node_index = sci_dev->rnc.remote_node_index;
3205 task_context->command_code = 0;
3206 task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST;
3207
3208 /* 08h */
3209 task_context->link_layer_control = 0;
3210 task_context->do_not_dma_ssp_good_response = 1;
3211 task_context->strict_ordering = 0;
3212 task_context->control_frame = 1;
3213 task_context->timeout_enable = 0;
3214 task_context->block_guard_enable = 0;
3215
3216 /* 0ch */
3217 task_context->address_modifier = 0;
3218
3219 /* 10h */
Dave Jiang77d67382011-05-25 02:21:57 +00003220 task_context->ssp_command_iu_length = req_len;
Dan Williamsc72086e2011-05-10 02:28:48 -07003221
3222 /* 14h */
3223 task_context->transfer_length_bytes = 0;
3224
3225 /*
3226 * 18h ~ 30h, protocol specific
3227 * since commandIU has been build by framework at this point, we just
3228 * copy the frist DWord from command IU to this location. */
Dan Williamse9bf7092011-06-16 16:59:56 -07003229 memcpy(&task_context->type.smp, &cmd, sizeof(u32));
Dan Williamsc72086e2011-05-10 02:28:48 -07003230
3231 /*
3232 * 40h
3233 * "For SMP you could program it to zero. We would prefer that way
3234 * so that done code will be consistent." - Venki
3235 */
3236 task_context->task_phase = 0;
3237
Dan Williams312e0c22011-06-28 13:47:09 -07003238 sci_req->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
3239 (scic_sds_controller_get_protocol_engine_group(scic) <<
3240 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
3241 (scic_sds_port_get_index(sci_port) <<
3242 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
3243 ISCI_TAG_TCI(sci_req->io_tag));
Dan Williamsc72086e2011-05-10 02:28:48 -07003244 /*
3245 * Copy the physical address for the command buffer to the SCU Task
3246 * Context command buffer should not contain command header.
3247 */
Dan Williamse9bf7092011-06-16 16:59:56 -07003248 task_context->command_iu_upper = upper_32_bits(sg_dma_address(sg));
3249 task_context->command_iu_lower = lower_32_bits(sg_dma_address(sg) + sizeof(u32));
Dan Williamsc72086e2011-05-10 02:28:48 -07003250
3251 /* SMP response comes as UF, so no need to set response IU address. */
3252 task_context->response_iu_upper = 0;
3253 task_context->response_iu_lower = 0;
Dan Williamsc72086e2011-05-10 02:28:48 -07003254
Edmund Nadolskie3013702011-06-02 00:10:43 +00003255 sci_change_state(&sci_req->sm, SCI_REQ_CONSTRUCTED);
Dan Williamsc72086e2011-05-10 02:28:48 -07003256
3257 return SCI_SUCCESS;
3258}
3259
3260/*
Dan Williamsf1f52e72011-05-10 02:28:45 -07003261 * isci_smp_request_build() - This function builds the smp request.
3262 * @ireq: This parameter points to the isci_request allocated in the
3263 * request construct function.
3264 *
3265 * SCI_SUCCESS on successfull completion, or specific failure code.
3266 */
3267static enum sci_status isci_smp_request_build(struct isci_request *ireq)
3268{
Dan Williamsf1f52e72011-05-10 02:28:45 -07003269 struct sas_task *task = isci_request_access_task(ireq);
Dan Williamse9bf7092011-06-16 16:59:56 -07003270 struct device *dev = &ireq->isci_host->pdev->dev;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003271 struct scic_sds_request *sci_req = &ireq->sci;
Dan Williamse9bf7092011-06-16 16:59:56 -07003272 enum sci_status status = SCI_FAILURE;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003273
Dan Williamse9bf7092011-06-16 16:59:56 -07003274 status = scic_io_request_construct_smp(dev, sci_req, task);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003275 if (status != SCI_SUCCESS)
3276 dev_warn(&ireq->isci_host->pdev->dev,
3277 "%s: failed with status = %d\n",
3278 __func__,
3279 status);
3280
3281 return status;
3282}
3283
3284/**
3285 * isci_io_request_build() - This function builds the io request object.
3286 * @isci_host: This parameter specifies the ISCI host object
3287 * @request: This parameter points to the isci_request object allocated in the
3288 * request construct function.
3289 * @sci_device: This parameter is the handle for the sci core's remote device
3290 * object that is the destination for this request.
3291 *
3292 * SCI_SUCCESS on successfull completion, or specific failure code.
3293 */
Dan Williams312e0c22011-06-28 13:47:09 -07003294static enum sci_status isci_io_request_build(struct isci_host *isci_host,
3295 struct isci_request *request,
3296 struct isci_remote_device *isci_device,
3297 u16 tag)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003298{
3299 enum sci_status status = SCI_SUCCESS;
3300 struct sas_task *task = isci_request_access_task(request);
3301 struct scic_sds_remote_device *sci_device = &isci_device->sci;
3302
3303 dev_dbg(&isci_host->pdev->dev,
3304 "%s: isci_device = 0x%p; request = %p, "
3305 "num_scatter = %d\n",
3306 __func__,
3307 isci_device,
3308 request,
3309 task->num_scatter);
3310
3311 /* map the sgl addresses, if present.
3312 * libata does the mapping for sata devices
3313 * before we get the request.
3314 */
3315 if (task->num_scatter &&
3316 !sas_protocol_ata(task->task_proto) &&
3317 !(SAS_PROTOCOL_SMP & task->task_proto)) {
3318
3319 request->num_sg_entries = dma_map_sg(
3320 &isci_host->pdev->dev,
3321 task->scatter,
3322 task->num_scatter,
3323 task->data_dir
3324 );
3325
3326 if (request->num_sg_entries == 0)
3327 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
3328 }
3329
3330 /* build the common request object. For now,
3331 * we will let the core allocate the IO tag.
3332 */
3333 status = scic_io_request_construct(&isci_host->sci, sci_device,
Dan Williams312e0c22011-06-28 13:47:09 -07003334 tag, &request->sci);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003335
3336 if (status != SCI_SUCCESS) {
3337 dev_warn(&isci_host->pdev->dev,
3338 "%s: failed request construct\n",
3339 __func__);
3340 return SCI_FAILURE;
3341 }
3342
3343 switch (task->task_proto) {
3344 case SAS_PROTOCOL_SMP:
3345 status = isci_smp_request_build(request);
3346 break;
3347 case SAS_PROTOCOL_SSP:
3348 status = isci_request_ssp_request_construct(request);
3349 break;
3350 case SAS_PROTOCOL_SATA:
3351 case SAS_PROTOCOL_STP:
3352 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
3353 status = isci_request_stp_request_construct(request);
3354 break;
3355 default:
3356 dev_warn(&isci_host->pdev->dev,
3357 "%s: unknown protocol\n", __func__);
3358 return SCI_FAILURE;
3359 }
3360
3361 return SCI_SUCCESS;
3362}
3363
Dan Williams0d0cf142011-06-13 00:51:30 -07003364static struct isci_request *isci_request_alloc_core(struct isci_host *ihost,
Dan Williams0d0cf142011-06-13 00:51:30 -07003365 gfp_t gfp_flags)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003366{
Dan Williamsf1f52e72011-05-10 02:28:45 -07003367 dma_addr_t handle;
Dan Williams0d0cf142011-06-13 00:51:30 -07003368 struct isci_request *ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003369
Dan Williams0d0cf142011-06-13 00:51:30 -07003370 ireq = dma_pool_alloc(ihost->dma_pool, gfp_flags, &handle);
3371 if (!ireq) {
3372 dev_warn(&ihost->pdev->dev,
Dan Williamsf1f52e72011-05-10 02:28:45 -07003373 "%s: dma_pool_alloc returned NULL\n", __func__);
Dan Williams0d0cf142011-06-13 00:51:30 -07003374 return NULL;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003375 }
3376
3377 /* initialize the request object. */
Dan Williams0d0cf142011-06-13 00:51:30 -07003378 spin_lock_init(&ireq->state_lock);
3379 ireq->request_daddr = handle;
3380 ireq->isci_host = ihost;
Dan Williams0d0cf142011-06-13 00:51:30 -07003381 ireq->io_request_completion = NULL;
3382 ireq->terminated = false;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003383
Dan Williams0d0cf142011-06-13 00:51:30 -07003384 ireq->num_sg_entries = 0;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003385
Dan Williams0d0cf142011-06-13 00:51:30 -07003386 ireq->complete_in_target = false;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003387
Dan Williams0d0cf142011-06-13 00:51:30 -07003388 INIT_LIST_HEAD(&ireq->completed_node);
3389 INIT_LIST_HEAD(&ireq->dev_node);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003390
Dan Williams0d0cf142011-06-13 00:51:30 -07003391 isci_request_change_state(ireq, allocated);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003392
Dan Williams0d0cf142011-06-13 00:51:30 -07003393 return ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003394}
3395
Dan Williams0d0cf142011-06-13 00:51:30 -07003396static struct isci_request *isci_request_alloc_io(struct isci_host *ihost,
3397 struct sas_task *task,
Dan Williams0d0cf142011-06-13 00:51:30 -07003398 gfp_t gfp_flags)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003399{
Dan Williams0d0cf142011-06-13 00:51:30 -07003400 struct isci_request *ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003401
Dan Williams209fae12011-06-13 17:39:44 -07003402 ireq = isci_request_alloc_core(ihost, gfp_flags);
Dan Williams0d0cf142011-06-13 00:51:30 -07003403 if (ireq) {
3404 ireq->ttype_ptr.io_task_ptr = task;
3405 ireq->ttype = io_task;
3406 task->lldd_task = ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003407 }
Dan Williams0d0cf142011-06-13 00:51:30 -07003408 return ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003409}
3410
Dan Williams0d0cf142011-06-13 00:51:30 -07003411struct isci_request *isci_request_alloc_tmf(struct isci_host *ihost,
3412 struct isci_tmf *isci_tmf,
Dan Williams0d0cf142011-06-13 00:51:30 -07003413 gfp_t gfp_flags)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003414{
Dan Williams0d0cf142011-06-13 00:51:30 -07003415 struct isci_request *ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003416
Dan Williams209fae12011-06-13 17:39:44 -07003417 ireq = isci_request_alloc_core(ihost, gfp_flags);
Dan Williams0d0cf142011-06-13 00:51:30 -07003418 if (ireq) {
3419 ireq->ttype_ptr.tmf_task_ptr = isci_tmf;
3420 ireq->ttype = tmf_task;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003421 }
Dan Williams0d0cf142011-06-13 00:51:30 -07003422 return ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003423}
3424
Dan Williams209fae12011-06-13 17:39:44 -07003425int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
Dan Williams312e0c22011-06-28 13:47:09 -07003426 struct sas_task *task, u16 tag, gfp_t gfp_flags)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003427{
Dan Williamsf1f52e72011-05-10 02:28:45 -07003428 enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williams0d0cf142011-06-13 00:51:30 -07003429 struct isci_request *ireq;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003430 unsigned long flags;
Dan Williams0d0cf142011-06-13 00:51:30 -07003431 int ret = 0;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003432
Dan Williamsf1f52e72011-05-10 02:28:45 -07003433 /* do common allocation and init of request object. */
Dan Williams209fae12011-06-13 17:39:44 -07003434 ireq = isci_request_alloc_io(ihost, task, gfp_flags);
Dan Williams0d0cf142011-06-13 00:51:30 -07003435 if (!ireq)
Dan Williamsf1f52e72011-05-10 02:28:45 -07003436 goto out;
3437
Dan Williams312e0c22011-06-28 13:47:09 -07003438 status = isci_io_request_build(ihost, ireq, idev, tag);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003439 if (status != SCI_SUCCESS) {
Dan Williams0d0cf142011-06-13 00:51:30 -07003440 dev_warn(&ihost->pdev->dev,
Dan Williamsf1f52e72011-05-10 02:28:45 -07003441 "%s: request_construct failed - status = 0x%x\n",
3442 __func__,
3443 status);
3444 goto out;
3445 }
3446
Dan Williams0d0cf142011-06-13 00:51:30 -07003447 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003448
Jeff Skirvin9274f452011-06-23 17:09:02 -07003449 if (test_bit(IDEV_IO_NCQERROR, &idev->flags)) {
3450
3451 if (isci_task_is_ncq_recovery(task)) {
3452
3453 /* The device is in an NCQ recovery state. Issue the
3454 * request on the task side. Note that it will
3455 * complete on the I/O request side because the
3456 * request was built that way (ie.
3457 * ireq->is_task_management_request is false).
3458 */
3459 status = scic_controller_start_task(&ihost->sci,
3460 &idev->sci,
Dan Williams312e0c22011-06-28 13:47:09 -07003461 &ireq->sci);
Jeff Skirvin9274f452011-06-23 17:09:02 -07003462 } else {
3463 status = SCI_FAILURE;
3464 }
3465 } else {
Jeff Skirvin9274f452011-06-23 17:09:02 -07003466 /* send the request, let the core assign the IO TAG. */
3467 status = scic_controller_start_io(&ihost->sci, &idev->sci,
Dan Williams312e0c22011-06-28 13:47:09 -07003468 &ireq->sci);
Jeff Skirvin9274f452011-06-23 17:09:02 -07003469 }
Dan Williams312e0c22011-06-28 13:47:09 -07003470
Dan Williamsf1f52e72011-05-10 02:28:45 -07003471 if (status != SCI_SUCCESS &&
3472 status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
Dan Williams0d0cf142011-06-13 00:51:30 -07003473 dev_warn(&ihost->pdev->dev,
Dan Williamsf1f52e72011-05-10 02:28:45 -07003474 "%s: failed request start (0x%x)\n",
3475 __func__, status);
Dan Williams0d0cf142011-06-13 00:51:30 -07003476 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003477 goto out;
3478 }
3479
3480 /* Either I/O started OK, or the core has signaled that
3481 * the device needs a target reset.
3482 *
3483 * In either case, hold onto the I/O for later.
3484 *
3485 * Update it's status and add it to the list in the
3486 * remote device object.
3487 */
Dan Williams0d0cf142011-06-13 00:51:30 -07003488 list_add(&ireq->dev_node, &idev->reqs_in_process);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003489
3490 if (status == SCI_SUCCESS) {
3491 /* Save the tag for possible task mgmt later. */
Dan Williams0d0cf142011-06-13 00:51:30 -07003492 ireq->io_tag = ireq->sci.io_tag;
3493 isci_request_change_state(ireq, started);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003494 } else {
3495 /* The request did not really start in the
3496 * hardware, so clear the request handle
3497 * here so no terminations will be done.
3498 */
Dan Williams0d0cf142011-06-13 00:51:30 -07003499 ireq->terminated = true;
3500 isci_request_change_state(ireq, completed);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003501 }
Dan Williams0d0cf142011-06-13 00:51:30 -07003502 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsf1f52e72011-05-10 02:28:45 -07003503
3504 if (status ==
3505 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
3506 /* Signal libsas that we need the SCSI error
Dan Williams312e0c22011-06-28 13:47:09 -07003507 * handler thread to work on this I/O and that
3508 * we want a device reset.
3509 */
Dan Williamsf1f52e72011-05-10 02:28:45 -07003510 spin_lock_irqsave(&task->task_state_lock, flags);
3511 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
3512 spin_unlock_irqrestore(&task->task_state_lock, flags);
3513
3514 /* Cause this task to be scheduled in the SCSI error
Dan Williams312e0c22011-06-28 13:47:09 -07003515 * handler thread.
3516 */
Dan Williams0d0cf142011-06-13 00:51:30 -07003517 isci_execpath_callback(ihost, task,
Dan Williamsf1f52e72011-05-10 02:28:45 -07003518 sas_task_abort);
3519
3520 /* Change the status, since we are holding
Dan Williams312e0c22011-06-28 13:47:09 -07003521 * the I/O until it is managed by the SCSI
3522 * error handler.
3523 */
Dan Williamsf1f52e72011-05-10 02:28:45 -07003524 status = SCI_SUCCESS;
3525 }
3526
3527 out:
3528 if (status != SCI_SUCCESS) {
3529 /* release dma memory on failure. */
Dan Williams0d0cf142011-06-13 00:51:30 -07003530 isci_request_free(ihost, ireq);
3531 ireq = NULL;
Dan Williamsf1f52e72011-05-10 02:28:45 -07003532 ret = SCI_FAILURE;
3533 }
3534
Dan Williamsf1f52e72011-05-10 02:28:45 -07003535 return ret;
3536}