]>
Commit | Line | Data |
---|---|---|
6f231dda DW |
1 | /* |
2 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
3 | * redistributing this file, you may do so under either license. | |
4 | * | |
5 | * GPL LICENSE SUMMARY | |
6 | * | |
7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of version 2 of the GNU General Public License as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * BSD LICENSE | |
25 | * | |
26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * | |
33 | * * Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * * Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in | |
37 | * the documentation and/or other materials provided with the | |
38 | * distribution. | |
39 | * * Neither the name of Intel Corporation nor the names of its | |
40 | * contributors may be used to endorse or promote products derived | |
41 | * from this software without specific prior written permission. | |
42 | * | |
43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
54 | */ | |
55 | ||
3d2d7525 | 56 | #include <scsi/scsi_cmnd.h> |
6f231dda | 57 | #include "isci.h" |
6f231dda DW |
58 | #include "task.h" |
59 | #include "request.h" | |
6f231dda | 60 | #include "scu_completion_codes.h" |
5dec6f4e | 61 | #include "scu_event_codes.h" |
2ec53eb4 | 62 | #include "sas.h" |
6f231dda | 63 | |
d7a0ccdd DW |
64 | #undef C |
65 | #define C(a) (#a) | |
66 | const char *req_state_name(enum sci_base_request_states state) | |
67 | { | |
68 | static const char * const strings[] = REQUEST_STATES; | |
69 | ||
70 | return strings[state]; | |
71 | } | |
72 | #undef C | |
73 | ||
5076a1a9 | 74 | static struct scu_sgl_element_pair *to_sgl_element_pair(struct isci_request *ireq, |
312e0c24 DW |
75 | int idx) |
76 | { | |
77 | if (idx == 0) | |
5076a1a9 | 78 | return &ireq->tc->sgl_pair_ab; |
312e0c24 | 79 | else if (idx == 1) |
5076a1a9 | 80 | return &ireq->tc->sgl_pair_cd; |
312e0c24 DW |
81 | else if (idx < 0) |
82 | return NULL; | |
83 | else | |
5076a1a9 | 84 | return &ireq->sg_table[idx - 2]; |
312e0c24 | 85 | } |
f1f52e75 | 86 | |
d9dcb4ba | 87 | static dma_addr_t to_sgl_element_pair_dma(struct isci_host *ihost, |
5076a1a9 | 88 | struct isci_request *ireq, u32 idx) |
312e0c24 DW |
89 | { |
90 | u32 offset; | |
f1f52e75 | 91 | |
312e0c24 | 92 | if (idx == 0) { |
5076a1a9 | 93 | offset = (void *) &ireq->tc->sgl_pair_ab - |
d9dcb4ba | 94 | (void *) &ihost->task_context_table[0]; |
abec912d | 95 | return ihost->tc_dma + offset; |
312e0c24 | 96 | } else if (idx == 1) { |
5076a1a9 | 97 | offset = (void *) &ireq->tc->sgl_pair_cd - |
d9dcb4ba | 98 | (void *) &ihost->task_context_table[0]; |
abec912d | 99 | return ihost->tc_dma + offset; |
f1f52e75 | 100 | } |
6f231dda | 101 | |
89a7301f | 102 | return sci_io_request_get_dma_addr(ireq, &ireq->sg_table[idx - 2]); |
312e0c24 DW |
103 | } |
104 | ||
105 | static void init_sgl_element(struct scu_sgl_element *e, struct scatterlist *sg) | |
106 | { | |
107 | e->length = sg_dma_len(sg); | |
108 | e->address_upper = upper_32_bits(sg_dma_address(sg)); | |
109 | e->address_lower = lower_32_bits(sg_dma_address(sg)); | |
110 | e->address_modifier = 0; | |
6f231dda DW |
111 | } |
112 | ||
89a7301f | 113 | static void sci_request_build_sgl(struct isci_request *ireq) |
6f231dda | 114 | { |
d9dcb4ba | 115 | struct isci_host *ihost = ireq->isci_host; |
5076a1a9 | 116 | struct sas_task *task = isci_request_access_task(ireq); |
f1f52e75 DW |
117 | struct scatterlist *sg = NULL; |
118 | dma_addr_t dma_addr; | |
119 | u32 sg_idx = 0; | |
120 | struct scu_sgl_element_pair *scu_sg = NULL; | |
121 | struct scu_sgl_element_pair *prev_sg = NULL; | |
122 | ||
123 | if (task->num_scatter > 0) { | |
124 | sg = task->scatter; | |
125 | ||
126 | while (sg) { | |
5076a1a9 | 127 | scu_sg = to_sgl_element_pair(ireq, sg_idx); |
312e0c24 | 128 | init_sgl_element(&scu_sg->A, sg); |
f1f52e75 | 129 | sg = sg_next(sg); |
f1f52e75 | 130 | if (sg) { |
312e0c24 | 131 | init_sgl_element(&scu_sg->B, sg); |
f1f52e75 DW |
132 | sg = sg_next(sg); |
133 | } else | |
312e0c24 | 134 | memset(&scu_sg->B, 0, sizeof(scu_sg->B)); |
f1f52e75 DW |
135 | |
136 | if (prev_sg) { | |
d9dcb4ba | 137 | dma_addr = to_sgl_element_pair_dma(ihost, |
5076a1a9 | 138 | ireq, |
312e0c24 | 139 | sg_idx); |
f1f52e75 DW |
140 | |
141 | prev_sg->next_pair_upper = | |
142 | upper_32_bits(dma_addr); | |
143 | prev_sg->next_pair_lower = | |
144 | lower_32_bits(dma_addr); | |
145 | } | |
146 | ||
147 | prev_sg = scu_sg; | |
148 | sg_idx++; | |
149 | } | |
150 | } else { /* handle when no sg */ | |
5076a1a9 | 151 | scu_sg = to_sgl_element_pair(ireq, sg_idx); |
6f231dda | 152 | |
d9dcb4ba | 153 | dma_addr = dma_map_single(&ihost->pdev->dev, |
f1f52e75 DW |
154 | task->scatter, |
155 | task->total_xfer_len, | |
156 | task->data_dir); | |
6f231dda | 157 | |
5076a1a9 | 158 | ireq->zero_scatter_daddr = dma_addr; |
6f231dda | 159 | |
f1f52e75 DW |
160 | scu_sg->A.length = task->total_xfer_len; |
161 | scu_sg->A.address_upper = upper_32_bits(dma_addr); | |
162 | scu_sg->A.address_lower = lower_32_bits(dma_addr); | |
163 | } | |
6f231dda | 164 | |
f1f52e75 DW |
165 | if (scu_sg) { |
166 | scu_sg->next_pair_upper = 0; | |
167 | scu_sg->next_pair_lower = 0; | |
6f231dda | 168 | } |
f1f52e75 | 169 | } |
6f231dda | 170 | |
89a7301f | 171 | static void sci_io_request_build_ssp_command_iu(struct isci_request *ireq) |
6f231dda | 172 | { |
f1f52e75 | 173 | struct ssp_cmd_iu *cmd_iu; |
2ec53eb4 | 174 | struct sas_task *task = isci_request_access_task(ireq); |
6f231dda | 175 | |
5076a1a9 | 176 | cmd_iu = &ireq->ssp.cmd; |
6f231dda | 177 | |
f1f52e75 DW |
178 | memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8); |
179 | cmd_iu->add_cdb_len = 0; | |
180 | cmd_iu->_r_a = 0; | |
181 | cmd_iu->_r_b = 0; | |
182 | cmd_iu->en_fburst = 0; /* unsupported */ | |
183 | cmd_iu->task_prio = task->ssp_task.task_prio; | |
184 | cmd_iu->task_attr = task->ssp_task.task_attr; | |
185 | cmd_iu->_r_c = 0; | |
6f231dda | 186 | |
f1f52e75 DW |
187 | sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cdb, |
188 | sizeof(task->ssp_task.cdb) / sizeof(u32)); | |
189 | } | |
6f231dda | 190 | |
89a7301f | 191 | static void sci_task_request_build_ssp_task_iu(struct isci_request *ireq) |
f1f52e75 DW |
192 | { |
193 | struct ssp_task_iu *task_iu; | |
f1f52e75 DW |
194 | struct sas_task *task = isci_request_access_task(ireq); |
195 | struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq); | |
6f231dda | 196 | |
5076a1a9 | 197 | task_iu = &ireq->ssp.tmf; |
f1f52e75 DW |
198 | |
199 | memset(task_iu, 0, sizeof(struct ssp_task_iu)); | |
200 | ||
201 | memcpy(task_iu->LUN, task->ssp_task.LUN, 8); | |
202 | ||
203 | task_iu->task_func = isci_tmf->tmf_code; | |
204 | task_iu->task_tag = | |
3b34c169 | 205 | (test_bit(IREQ_TMF, &ireq->flags)) ? |
f1f52e75 DW |
206 | isci_tmf->io_tag : |
207 | SCI_CONTROLLER_INVALID_IO_TAG; | |
6f231dda DW |
208 | } |
209 | ||
210 | /** | |
f1f52e75 DW |
211 | * This method is will fill in the SCU Task Context for any type of SSP request. |
212 | * @sci_req: | |
213 | * @task_context: | |
6f231dda | 214 | * |
6f231dda | 215 | */ |
f1f52e75 | 216 | static void scu_ssp_reqeust_construct_task_context( |
5076a1a9 | 217 | struct isci_request *ireq, |
f1f52e75 | 218 | struct scu_task_context *task_context) |
6f231dda | 219 | { |
f1f52e75 | 220 | dma_addr_t dma_addr; |
78a6f06e | 221 | struct isci_remote_device *idev; |
ffe191c9 | 222 | struct isci_port *iport; |
f1f52e75 | 223 | |
34a99158 DW |
224 | idev = ireq->target_device; |
225 | iport = idev->owning_port; | |
f1f52e75 DW |
226 | |
227 | /* Fill in the TC with the its required data */ | |
228 | task_context->abort = 0; | |
229 | task_context->priority = 0; | |
230 | task_context->initiator_request = 1; | |
78a6f06e | 231 | task_context->connection_rate = idev->connection_rate; |
34a99158 DW |
232 | task_context->protocol_engine_index = ISCI_PEG; |
233 | task_context->logical_port_index = iport->physical_port_index; | |
f1f52e75 DW |
234 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP; |
235 | task_context->valid = SCU_TASK_CONTEXT_VALID; | |
236 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; | |
237 | ||
34a99158 | 238 | task_context->remote_node_index = idev->rnc.remote_node_index; |
f1f52e75 DW |
239 | task_context->command_code = 0; |
240 | ||
241 | task_context->link_layer_control = 0; | |
242 | task_context->do_not_dma_ssp_good_response = 1; | |
243 | task_context->strict_ordering = 0; | |
244 | task_context->control_frame = 0; | |
245 | task_context->timeout_enable = 0; | |
246 | task_context->block_guard_enable = 0; | |
247 | ||
248 | task_context->address_modifier = 0; | |
249 | ||
5076a1a9 | 250 | /* task_context->type.ssp.tag = ireq->io_tag; */ |
f1f52e75 DW |
251 | task_context->task_phase = 0x01; |
252 | ||
5076a1a9 | 253 | ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | |
34a99158 DW |
254 | (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | |
255 | (iport->physical_port_index << | |
ffe191c9 DW |
256 | SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | |
257 | ISCI_TAG_TCI(ireq->io_tag)); | |
6f231dda | 258 | |
f1f52e75 DW |
259 | /* |
260 | * Copy the physical address for the command buffer to the | |
261 | * SCU Task Context | |
262 | */ | |
89a7301f | 263 | dma_addr = sci_io_request_get_dma_addr(ireq, &ireq->ssp.cmd); |
6f231dda | 264 | |
f1f52e75 DW |
265 | task_context->command_iu_upper = upper_32_bits(dma_addr); |
266 | task_context->command_iu_lower = lower_32_bits(dma_addr); | |
267 | ||
268 | /* | |
269 | * Copy the physical address for the response buffer to the | |
270 | * SCU Task Context | |
6f231dda | 271 | */ |
89a7301f | 272 | dma_addr = sci_io_request_get_dma_addr(ireq, &ireq->ssp.rsp); |
6f231dda | 273 | |
f1f52e75 DW |
274 | task_context->response_iu_upper = upper_32_bits(dma_addr); |
275 | task_context->response_iu_lower = lower_32_bits(dma_addr); | |
276 | } | |
6f231dda | 277 | |
3d2d7525 DJ |
278 | static u8 scu_bg_blk_size(struct scsi_device *sdp) |
279 | { | |
280 | switch (sdp->sector_size) { | |
281 | case 512: | |
282 | return 0; | |
283 | case 1024: | |
284 | return 1; | |
285 | case 4096: | |
286 | return 3; | |
287 | default: | |
288 | return 0xff; | |
289 | } | |
290 | } | |
291 | ||
292 | static u32 scu_dif_bytes(u32 len, u32 sector_size) | |
293 | { | |
294 | return (len >> ilog2(sector_size)) * 8; | |
295 | } | |
296 | ||
297 | static void scu_ssp_ireq_dif_insert(struct isci_request *ireq, u8 type, u8 op) | |
298 | { | |
299 | struct scu_task_context *tc = ireq->tc; | |
300 | struct scsi_cmnd *scmd = ireq->ttype_ptr.io_task_ptr->uldd_task; | |
301 | u8 blk_sz = scu_bg_blk_size(scmd->device); | |
302 | ||
303 | tc->block_guard_enable = 1; | |
304 | tc->blk_prot_en = 1; | |
305 | tc->blk_sz = blk_sz; | |
306 | /* DIF write insert */ | |
307 | tc->blk_prot_func = 0x2; | |
308 | ||
309 | tc->transfer_length_bytes += scu_dif_bytes(tc->transfer_length_bytes, | |
310 | scmd->device->sector_size); | |
311 | ||
312 | /* always init to 0, used by hw */ | |
313 | tc->interm_crc_val = 0; | |
314 | ||
315 | tc->init_crc_seed = 0; | |
316 | tc->app_tag_verify = 0; | |
317 | tc->app_tag_gen = 0; | |
318 | tc->ref_tag_seed_verify = 0; | |
319 | ||
320 | /* always init to same as bg_blk_sz */ | |
321 | tc->UD_bytes_immed_val = scmd->device->sector_size; | |
322 | ||
323 | tc->reserved_DC_0 = 0; | |
324 | ||
325 | /* always init to 8 */ | |
326 | tc->DIF_bytes_immed_val = 8; | |
327 | ||
328 | tc->reserved_DC_1 = 0; | |
329 | tc->bgc_blk_sz = scmd->device->sector_size; | |
330 | tc->reserved_E0_0 = 0; | |
331 | tc->app_tag_gen_mask = 0; | |
332 | ||
333 | /** setup block guard control **/ | |
334 | tc->bgctl = 0; | |
335 | ||
336 | /* DIF write insert */ | |
337 | tc->bgctl_f.op = 0x2; | |
338 | ||
339 | tc->app_tag_verify_mask = 0; | |
340 | ||
341 | /* must init to 0 for hw */ | |
342 | tc->blk_guard_err = 0; | |
343 | ||
344 | tc->reserved_E8_0 = 0; | |
345 | ||
346 | if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2)) | |
347 | tc->ref_tag_seed_gen = scsi_get_lba(scmd) & 0xffffffff; | |
348 | else if (type & SCSI_PROT_DIF_TYPE3) | |
349 | tc->ref_tag_seed_gen = 0; | |
350 | } | |
351 | ||
352 | static void scu_ssp_ireq_dif_strip(struct isci_request *ireq, u8 type, u8 op) | |
353 | { | |
354 | struct scu_task_context *tc = ireq->tc; | |
355 | struct scsi_cmnd *scmd = ireq->ttype_ptr.io_task_ptr->uldd_task; | |
356 | u8 blk_sz = scu_bg_blk_size(scmd->device); | |
357 | ||
358 | tc->block_guard_enable = 1; | |
359 | tc->blk_prot_en = 1; | |
360 | tc->blk_sz = blk_sz; | |
361 | /* DIF read strip */ | |
362 | tc->blk_prot_func = 0x1; | |
363 | ||
364 | tc->transfer_length_bytes += scu_dif_bytes(tc->transfer_length_bytes, | |
365 | scmd->device->sector_size); | |
366 | ||
367 | /* always init to 0, used by hw */ | |
368 | tc->interm_crc_val = 0; | |
369 | ||
370 | tc->init_crc_seed = 0; | |
371 | tc->app_tag_verify = 0; | |
372 | tc->app_tag_gen = 0; | |
373 | ||
374 | if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2)) | |
375 | tc->ref_tag_seed_verify = scsi_get_lba(scmd) & 0xffffffff; | |
376 | else if (type & SCSI_PROT_DIF_TYPE3) | |
377 | tc->ref_tag_seed_verify = 0; | |
378 | ||
379 | /* always init to same as bg_blk_sz */ | |
380 | tc->UD_bytes_immed_val = scmd->device->sector_size; | |
381 | ||
382 | tc->reserved_DC_0 = 0; | |
383 | ||
384 | /* always init to 8 */ | |
385 | tc->DIF_bytes_immed_val = 8; | |
386 | ||
387 | tc->reserved_DC_1 = 0; | |
388 | tc->bgc_blk_sz = scmd->device->sector_size; | |
389 | tc->reserved_E0_0 = 0; | |
390 | tc->app_tag_gen_mask = 0; | |
391 | ||
392 | /** setup block guard control **/ | |
393 | tc->bgctl = 0; | |
394 | ||
395 | /* DIF read strip */ | |
396 | tc->bgctl_f.crc_verify = 1; | |
397 | tc->bgctl_f.op = 0x1; | |
398 | if ((type & SCSI_PROT_DIF_TYPE1) || (type & SCSI_PROT_DIF_TYPE2)) { | |
399 | tc->bgctl_f.ref_tag_chk = 1; | |
400 | tc->bgctl_f.app_f_detect = 1; | |
401 | } else if (type & SCSI_PROT_DIF_TYPE3) | |
402 | tc->bgctl_f.app_ref_f_detect = 1; | |
403 | ||
404 | tc->app_tag_verify_mask = 0; | |
405 | ||
406 | /* must init to 0 for hw */ | |
407 | tc->blk_guard_err = 0; | |
408 | ||
409 | tc->reserved_E8_0 = 0; | |
410 | tc->ref_tag_seed_gen = 0; | |
411 | } | |
412 | ||
f1f52e75 DW |
413 | /** |
414 | * This method is will fill in the SCU Task Context for a SSP IO request. | |
415 | * @sci_req: | |
416 | * | |
417 | */ | |
5076a1a9 | 418 | static void scu_ssp_io_request_construct_task_context(struct isci_request *ireq, |
312e0c24 DW |
419 | enum dma_data_direction dir, |
420 | u32 len) | |
f1f52e75 | 421 | { |
5076a1a9 | 422 | struct scu_task_context *task_context = ireq->tc; |
3d2d7525 DJ |
423 | struct sas_task *sas_task = ireq->ttype_ptr.io_task_ptr; |
424 | struct scsi_cmnd *scmd = sas_task->uldd_task; | |
425 | u8 prot_type = scsi_get_prot_type(scmd); | |
426 | u8 prot_op = scsi_get_prot_op(scmd); | |
6f231dda | 427 | |
5076a1a9 | 428 | scu_ssp_reqeust_construct_task_context(ireq, task_context); |
6f231dda | 429 | |
f1f52e75 DW |
430 | task_context->ssp_command_iu_length = |
431 | sizeof(struct ssp_cmd_iu) / sizeof(u32); | |
432 | task_context->type.ssp.frame_type = SSP_COMMAND; | |
433 | ||
434 | switch (dir) { | |
435 | case DMA_FROM_DEVICE: | |
436 | case DMA_NONE: | |
437 | default: | |
438 | task_context->task_type = SCU_TASK_TYPE_IOREAD; | |
a1a113b0 | 439 | break; |
f1f52e75 DW |
440 | case DMA_TO_DEVICE: |
441 | task_context->task_type = SCU_TASK_TYPE_IOWRITE; | |
a1a113b0 | 442 | break; |
6f231dda DW |
443 | } |
444 | ||
f1f52e75 DW |
445 | task_context->transfer_length_bytes = len; |
446 | ||
447 | if (task_context->transfer_length_bytes > 0) | |
89a7301f | 448 | sci_request_build_sgl(ireq); |
3d2d7525 DJ |
449 | |
450 | if (prot_type != SCSI_PROT_DIF_TYPE0) { | |
451 | if (prot_op == SCSI_PROT_READ_STRIP) | |
452 | scu_ssp_ireq_dif_strip(ireq, prot_type, prot_op); | |
453 | else if (prot_op == SCSI_PROT_WRITE_INSERT) | |
454 | scu_ssp_ireq_dif_insert(ireq, prot_type, prot_op); | |
455 | } | |
6f231dda DW |
456 | } |
457 | ||
6f231dda | 458 | /** |
f1f52e75 DW |
459 | * This method will fill in the SCU Task Context for a SSP Task request. The |
460 | * following important settings are utilized: -# priority == | |
461 | * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued | |
462 | * ahead of other task destined for the same Remote Node. -# task_type == | |
463 | * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type | |
464 | * (i.e. non-raw frame) is being utilized to perform task management. -# | |
465 | * control_frame == 1. This ensures that the proper endianess is set so | |
466 | * that the bytes are transmitted in the right order for a task frame. | |
467 | * @sci_req: This parameter specifies the task request object being | |
468 | * constructed. | |
6f231dda | 469 | * |
6f231dda | 470 | */ |
5076a1a9 | 471 | static void scu_ssp_task_request_construct_task_context(struct isci_request *ireq) |
6f231dda | 472 | { |
5076a1a9 | 473 | struct scu_task_context *task_context = ireq->tc; |
6f231dda | 474 | |
5076a1a9 | 475 | scu_ssp_reqeust_construct_task_context(ireq, task_context); |
6f231dda | 476 | |
f1f52e75 DW |
477 | task_context->control_frame = 1; |
478 | task_context->priority = SCU_TASK_PRIORITY_HIGH; | |
479 | task_context->task_type = SCU_TASK_TYPE_RAW_FRAME; | |
480 | task_context->transfer_length_bytes = 0; | |
481 | task_context->type.ssp.frame_type = SSP_TASK; | |
482 | task_context->ssp_command_iu_length = | |
483 | sizeof(struct ssp_task_iu) / sizeof(u32); | |
6f231dda DW |
484 | } |
485 | ||
5dec6f4e DW |
486 | /** |
487 | * This method is will fill in the SCU Task Context for any type of SATA | |
488 | * request. This is called from the various SATA constructors. | |
489 | * @sci_req: The general IO request object which is to be used in | |
490 | * constructing the SCU task context. | |
491 | * @task_context: The buffer pointer for the SCU task context which is being | |
492 | * constructed. | |
493 | * | |
494 | * The general io request construction is complete. The buffer assignment for | |
495 | * the command buffer is complete. none Revisit task context construction to | |
496 | * determine what is common for SSP/SMP/STP task context structures. | |
497 | */ | |
498 | static void scu_sata_reqeust_construct_task_context( | |
5076a1a9 | 499 | struct isci_request *ireq, |
5dec6f4e DW |
500 | struct scu_task_context *task_context) |
501 | { | |
502 | dma_addr_t dma_addr; | |
78a6f06e | 503 | struct isci_remote_device *idev; |
ffe191c9 | 504 | struct isci_port *iport; |
5dec6f4e | 505 | |
34a99158 DW |
506 | idev = ireq->target_device; |
507 | iport = idev->owning_port; | |
5dec6f4e DW |
508 | |
509 | /* Fill in the TC with the its required data */ | |
510 | task_context->abort = 0; | |
511 | task_context->priority = SCU_TASK_PRIORITY_NORMAL; | |
512 | task_context->initiator_request = 1; | |
78a6f06e | 513 | task_context->connection_rate = idev->connection_rate; |
34a99158 DW |
514 | task_context->protocol_engine_index = ISCI_PEG; |
515 | task_context->logical_port_index = iport->physical_port_index; | |
5dec6f4e DW |
516 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP; |
517 | task_context->valid = SCU_TASK_CONTEXT_VALID; | |
518 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; | |
519 | ||
34a99158 | 520 | task_context->remote_node_index = idev->rnc.remote_node_index; |
5dec6f4e DW |
521 | task_context->command_code = 0; |
522 | ||
523 | task_context->link_layer_control = 0; | |
524 | task_context->do_not_dma_ssp_good_response = 1; | |
525 | task_context->strict_ordering = 0; | |
526 | task_context->control_frame = 0; | |
527 | task_context->timeout_enable = 0; | |
528 | task_context->block_guard_enable = 0; | |
529 | ||
530 | task_context->address_modifier = 0; | |
531 | task_context->task_phase = 0x01; | |
532 | ||
533 | task_context->ssp_command_iu_length = | |
534 | (sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32); | |
535 | ||
536 | /* Set the first word of the H2D REG FIS */ | |
5076a1a9 | 537 | task_context->type.words[0] = *(u32 *)&ireq->stp.cmd; |
5dec6f4e | 538 | |
5076a1a9 | 539 | ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | |
34a99158 DW |
540 | (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | |
541 | (iport->physical_port_index << | |
542 | SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | | |
543 | ISCI_TAG_TCI(ireq->io_tag)); | |
5dec6f4e DW |
544 | /* |
545 | * Copy the physical address for the command buffer to the SCU Task | |
546 | * Context. We must offset the command buffer by 4 bytes because the | |
547 | * first 4 bytes are transfered in the body of the TC. | |
548 | */ | |
89a7301f | 549 | dma_addr = sci_io_request_get_dma_addr(ireq, |
5076a1a9 | 550 | ((char *) &ireq->stp.cmd) + |
5dec6f4e DW |
551 | sizeof(u32)); |
552 | ||
553 | task_context->command_iu_upper = upper_32_bits(dma_addr); | |
554 | task_context->command_iu_lower = lower_32_bits(dma_addr); | |
555 | ||
556 | /* SATA Requests do not have a response buffer */ | |
557 | task_context->response_iu_upper = 0; | |
558 | task_context->response_iu_lower = 0; | |
559 | } | |
560 | ||
5076a1a9 | 561 | static void scu_stp_raw_request_construct_task_context(struct isci_request *ireq) |
5dec6f4e | 562 | { |
5076a1a9 | 563 | struct scu_task_context *task_context = ireq->tc; |
5dec6f4e | 564 | |
5076a1a9 | 565 | scu_sata_reqeust_construct_task_context(ireq, task_context); |
5dec6f4e DW |
566 | |
567 | task_context->control_frame = 0; | |
568 | task_context->priority = SCU_TASK_PRIORITY_NORMAL; | |
569 | task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME; | |
570 | task_context->type.stp.fis_type = FIS_REGH2D; | |
571 | task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32); | |
572 | } | |
573 | ||
89a7301f | 574 | static enum sci_status sci_stp_pio_request_construct(struct isci_request *ireq, |
5076a1a9 | 575 | bool copy_rx_frame) |
5dec6f4e | 576 | { |
5076a1a9 | 577 | struct isci_stp_request *stp_req = &ireq->stp.req; |
5dec6f4e | 578 | |
5076a1a9 | 579 | scu_stp_raw_request_construct_task_context(ireq); |
5dec6f4e | 580 | |
ba7cb223 DW |
581 | stp_req->status = 0; |
582 | stp_req->sgl.offset = 0; | |
583 | stp_req->sgl.set = SCU_SGL_ELEMENT_PAIR_A; | |
5dec6f4e DW |
584 | |
585 | if (copy_rx_frame) { | |
89a7301f | 586 | sci_request_build_sgl(ireq); |
ba7cb223 | 587 | stp_req->sgl.index = 0; |
5dec6f4e DW |
588 | } else { |
589 | /* The user does not want the data copied to the SGL buffer location */ | |
ba7cb223 | 590 | stp_req->sgl.index = -1; |
5dec6f4e | 591 | } |
6f231dda | 592 | |
5dec6f4e DW |
593 | return SCI_SUCCESS; |
594 | } | |
6f231dda DW |
595 | |
596 | /** | |
6f231dda | 597 | * |
5dec6f4e DW |
598 | * @sci_req: This parameter specifies the request to be constructed as an |
599 | * optimized request. | |
600 | * @optimized_task_type: This parameter specifies whether the request is to be | |
601 | * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A | |
602 | * value of 1 indicates NCQ. | |
603 | * | |
604 | * This method will perform request construction common to all types of STP | |
605 | * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method | |
606 | * returns an indication as to whether the construction was successful. | |
6f231dda | 607 | */ |
89a7301f | 608 | static void sci_stp_optimized_request_construct(struct isci_request *ireq, |
5dec6f4e DW |
609 | u8 optimized_task_type, |
610 | u32 len, | |
611 | enum dma_data_direction dir) | |
612 | { | |
5076a1a9 | 613 | struct scu_task_context *task_context = ireq->tc; |
5dec6f4e DW |
614 | |
615 | /* Build the STP task context structure */ | |
5076a1a9 | 616 | scu_sata_reqeust_construct_task_context(ireq, task_context); |
5dec6f4e DW |
617 | |
618 | /* Copy over the SGL elements */ | |
89a7301f | 619 | sci_request_build_sgl(ireq); |
5dec6f4e DW |
620 | |
621 | /* Copy over the number of bytes to be transfered */ | |
622 | task_context->transfer_length_bytes = len; | |
623 | ||
624 | if (dir == DMA_TO_DEVICE) { | |
625 | /* | |
626 | * The difference between the DMA IN and DMA OUT request task type | |
627 | * values are consistent with the difference between FPDMA READ | |
628 | * and FPDMA WRITE values. Add the supplied task type parameter | |
629 | * to this difference to set the task type properly for this | |
630 | * DATA OUT (WRITE) case. */ | |
631 | task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT | |
632 | - SCU_TASK_TYPE_DMA_IN); | |
633 | } else { | |
634 | /* | |
635 | * For the DATA IN (READ) case, simply save the supplied | |
636 | * optimized task type. */ | |
637 | task_context->task_type = optimized_task_type; | |
638 | } | |
639 | } | |
640 | ||
b50102d3 DW |
641 | static void sci_atapi_construct(struct isci_request *ireq) |
642 | { | |
643 | struct host_to_dev_fis *h2d_fis = &ireq->stp.cmd; | |
644 | struct sas_task *task; | |
645 | ||
646 | /* To simplify the implementation we take advantage of the | |
647 | * silicon's partial acceleration of atapi protocol (dma data | |
648 | * transfers), so we promote all commands to dma protocol. This | |
649 | * breaks compatibility with ATA_HORKAGE_ATAPI_MOD16_DMA drives. | |
650 | */ | |
651 | h2d_fis->features |= ATAPI_PKT_DMA; | |
652 | ||
653 | scu_stp_raw_request_construct_task_context(ireq); | |
654 | ||
655 | task = isci_request_access_task(ireq); | |
656 | if (task->data_dir == DMA_NONE) | |
657 | task->total_xfer_len = 0; | |
5dec6f4e | 658 | |
b50102d3 DW |
659 | /* clear the response so we can detect arrivial of an |
660 | * unsolicited h2d fis | |
661 | */ | |
662 | ireq->stp.rsp.fis_type = 0; | |
663 | } | |
5dec6f4e | 664 | |
f1f52e75 | 665 | static enum sci_status |
89a7301f | 666 | sci_io_request_construct_sata(struct isci_request *ireq, |
f1f52e75 DW |
667 | u32 len, |
668 | enum dma_data_direction dir, | |
669 | bool copy) | |
6f231dda | 670 | { |
f1f52e75 | 671 | enum sci_status status = SCI_SUCCESS; |
f1f52e75 | 672 | struct sas_task *task = isci_request_access_task(ireq); |
b50102d3 | 673 | struct domain_device *dev = ireq->target_device->domain_dev; |
6f231dda | 674 | |
f1f52e75 | 675 | /* check for management protocols */ |
3b34c169 | 676 | if (test_bit(IREQ_TMF, &ireq->flags)) { |
f1f52e75 | 677 | struct isci_tmf *tmf = isci_request_access_tmf(ireq); |
6f231dda | 678 | |
43a5ab15 DW |
679 | dev_err(&ireq->owning_controller->pdev->dev, |
680 | "%s: Request 0x%p received un-handled SAT " | |
681 | "management protocol 0x%x.\n", | |
682 | __func__, ireq, tmf->tmf_code); | |
f1f52e75 | 683 | |
43a5ab15 | 684 | return SCI_FAILURE; |
6f231dda | 685 | } |
6f231dda | 686 | |
f1f52e75 | 687 | if (!sas_protocol_ata(task->task_proto)) { |
d9dcb4ba | 688 | dev_err(&ireq->owning_controller->pdev->dev, |
f1f52e75 DW |
689 | "%s: Non-ATA protocol in SATA path: 0x%x\n", |
690 | __func__, | |
691 | task->task_proto); | |
692 | return SCI_FAILURE; | |
693 | ||
694 | } | |
695 | ||
b50102d3 DW |
696 | /* ATAPI */ |
697 | if (dev->sata_dev.command_set == ATAPI_COMMAND_SET && | |
698 | task->ata_task.fis.command == ATA_CMD_PACKET) { | |
699 | sci_atapi_construct(ireq); | |
700 | return SCI_SUCCESS; | |
701 | } | |
702 | ||
f1f52e75 | 703 | /* non data */ |
5dec6f4e | 704 | if (task->data_dir == DMA_NONE) { |
5076a1a9 | 705 | scu_stp_raw_request_construct_task_context(ireq); |
5dec6f4e DW |
706 | return SCI_SUCCESS; |
707 | } | |
f1f52e75 DW |
708 | |
709 | /* NCQ */ | |
5dec6f4e | 710 | if (task->ata_task.use_ncq) { |
89a7301f | 711 | sci_stp_optimized_request_construct(ireq, |
5dec6f4e DW |
712 | SCU_TASK_TYPE_FPDMAQ_READ, |
713 | len, dir); | |
714 | return SCI_SUCCESS; | |
715 | } | |
f1f52e75 DW |
716 | |
717 | /* DMA */ | |
5dec6f4e | 718 | if (task->ata_task.dma_xfer) { |
89a7301f | 719 | sci_stp_optimized_request_construct(ireq, |
5dec6f4e DW |
720 | SCU_TASK_TYPE_DMA_IN, |
721 | len, dir); | |
722 | return SCI_SUCCESS; | |
723 | } else /* PIO */ | |
89a7301f | 724 | return sci_stp_pio_request_construct(ireq, copy); |
f1f52e75 DW |
725 | |
726 | return status; | |
727 | } | |
728 | ||
89a7301f | 729 | static enum sci_status sci_io_request_construct_basic_ssp(struct isci_request *ireq) |
6f231dda | 730 | { |
f1f52e75 | 731 | struct sas_task *task = isci_request_access_task(ireq); |
6f231dda | 732 | |
c79dd80d | 733 | ireq->protocol = SAS_PROTOCOL_SSP; |
6f231dda | 734 | |
5076a1a9 | 735 | scu_ssp_io_request_construct_task_context(ireq, |
f1f52e75 DW |
736 | task->data_dir, |
737 | task->total_xfer_len); | |
6f231dda | 738 | |
89a7301f | 739 | sci_io_request_build_ssp_command_iu(ireq); |
6f231dda | 740 | |
5076a1a9 | 741 | sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); |
ce4f75de | 742 | |
f1f52e75 DW |
743 | return SCI_SUCCESS; |
744 | } | |
6f231dda | 745 | |
89a7301f | 746 | enum sci_status sci_task_request_construct_ssp( |
5076a1a9 | 747 | struct isci_request *ireq) |
f1f52e75 DW |
748 | { |
749 | /* Construct the SSP Task SCU Task Context */ | |
5076a1a9 | 750 | scu_ssp_task_request_construct_task_context(ireq); |
6f231dda | 751 | |
f1f52e75 | 752 | /* Fill in the SSP Task IU */ |
89a7301f | 753 | sci_task_request_build_ssp_task_iu(ireq); |
c4b9e24c | 754 | |
5076a1a9 | 755 | sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); |
67ea838d | 756 | |
f1f52e75 DW |
757 | return SCI_SUCCESS; |
758 | } | |
67ea838d | 759 | |
89a7301f | 760 | static enum sci_status sci_io_request_construct_basic_sata(struct isci_request *ireq) |
f1f52e75 DW |
761 | { |
762 | enum sci_status status; | |
f1f52e75 | 763 | bool copy = false; |
5076a1a9 | 764 | struct sas_task *task = isci_request_access_task(ireq); |
6f231dda | 765 | |
c79dd80d | 766 | ireq->protocol = SAS_PROTOCOL_STP; |
6f231dda | 767 | |
f1f52e75 DW |
768 | copy = (task->data_dir == DMA_NONE) ? false : true; |
769 | ||
89a7301f | 770 | status = sci_io_request_construct_sata(ireq, |
f1f52e75 DW |
771 | task->total_xfer_len, |
772 | task->data_dir, | |
773 | copy); | |
774 | ||
775 | if (status == SCI_SUCCESS) | |
5076a1a9 | 776 | sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); |
f1f52e75 DW |
777 | |
778 | return status; | |
6f231dda DW |
779 | } |
780 | ||
6f231dda | 781 | /** |
f1f52e75 | 782 | * sci_req_tx_bytes - bytes transferred when reply underruns request |
b50102d3 | 783 | * @ireq: request that was terminated early |
6f231dda | 784 | */ |
f1f52e75 | 785 | #define SCU_TASK_CONTEXT_SRAM 0x200000 |
5076a1a9 | 786 | static u32 sci_req_tx_bytes(struct isci_request *ireq) |
6f231dda | 787 | { |
d9dcb4ba | 788 | struct isci_host *ihost = ireq->owning_controller; |
f1f52e75 DW |
789 | u32 ret_val = 0; |
790 | ||
d9dcb4ba DW |
791 | if (readl(&ihost->smu_registers->address_modifier) == 0) { |
792 | void __iomem *scu_reg_base = ihost->scu_registers; | |
f1f52e75 DW |
793 | |
794 | /* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where | |
795 | * BAR1 is the scu_registers | |
796 | * 0x20002C = 0x200000 + 0x2c | |
797 | * = start of task context SRAM + offset of (type.ssp.data_offset) | |
89a7301f | 798 | * TCi is the io_tag of struct sci_request |
f1f52e75 DW |
799 | */ |
800 | ret_val = readl(scu_reg_base + | |
801 | (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) + | |
5076a1a9 | 802 | ((sizeof(struct scu_task_context)) * ISCI_TAG_TCI(ireq->io_tag))); |
f1f52e75 DW |
803 | } |
804 | ||
805 | return ret_val; | |
806 | } | |
807 | ||
89a7301f | 808 | enum sci_status sci_request_start(struct isci_request *ireq) |
f1f52e75 | 809 | { |
f4636a7b | 810 | enum sci_base_request_states state; |
5076a1a9 | 811 | struct scu_task_context *tc = ireq->tc; |
d9dcb4ba | 812 | struct isci_host *ihost = ireq->owning_controller; |
f4636a7b | 813 | |
5076a1a9 | 814 | state = ireq->sm.current_state_id; |
e301370a | 815 | if (state != SCI_REQ_CONSTRUCTED) { |
d9dcb4ba | 816 | dev_warn(&ihost->pdev->dev, |
f4636a7b PS |
817 | "%s: SCIC IO Request requested to start while in wrong " |
818 | "state %d\n", __func__, state); | |
819 | return SCI_FAILURE_INVALID_STATE; | |
820 | } | |
f1f52e75 | 821 | |
5076a1a9 | 822 | tc->task_index = ISCI_TAG_TCI(ireq->io_tag); |
f4636a7b | 823 | |
312e0c24 DW |
824 | switch (tc->protocol_type) { |
825 | case SCU_TASK_CONTEXT_PROTOCOL_SMP: | |
826 | case SCU_TASK_CONTEXT_PROTOCOL_SSP: | |
827 | /* SSP/SMP Frame */ | |
5076a1a9 | 828 | tc->type.ssp.tag = ireq->io_tag; |
312e0c24 DW |
829 | tc->type.ssp.target_port_transfer_tag = 0xFFFF; |
830 | break; | |
f4636a7b | 831 | |
312e0c24 DW |
832 | case SCU_TASK_CONTEXT_PROTOCOL_STP: |
833 | /* STP/SATA Frame | |
5076a1a9 | 834 | * tc->type.stp.ncq_tag = ireq->ncq_tag; |
312e0c24 DW |
835 | */ |
836 | break; | |
f4636a7b | 837 | |
312e0c24 DW |
838 | case SCU_TASK_CONTEXT_PROTOCOL_NONE: |
839 | /* / @todo When do we set no protocol type? */ | |
840 | break; | |
f4636a7b | 841 | |
312e0c24 DW |
842 | default: |
843 | /* This should never happen since we build the IO | |
844 | * requests */ | |
845 | break; | |
846 | } | |
f4636a7b | 847 | |
312e0c24 | 848 | /* Add to the post_context the io tag value */ |
5076a1a9 | 849 | ireq->post_context |= ISCI_TAG_TCI(ireq->io_tag); |
f4636a7b | 850 | |
312e0c24 | 851 | /* Everything is good go ahead and change state */ |
5076a1a9 | 852 | sci_change_state(&ireq->sm, SCI_REQ_STARTED); |
f4636a7b | 853 | |
312e0c24 | 854 | return SCI_SUCCESS; |
f1f52e75 DW |
855 | } |
856 | ||
857 | enum sci_status | |
89a7301f | 858 | sci_io_request_terminate(struct isci_request *ireq) |
f1f52e75 | 859 | { |
f00e6ba4 | 860 | enum sci_base_request_states state; |
f1f52e75 | 861 | |
5076a1a9 | 862 | state = ireq->sm.current_state_id; |
f00e6ba4 DW |
863 | |
864 | switch (state) { | |
e301370a | 865 | case SCI_REQ_CONSTRUCTED: |
726980d5 JS |
866 | /* Set to make sure no HW terminate posting is done: */ |
867 | set_bit(IREQ_TC_ABORT_POSTED, &ireq->flags); | |
34a99158 DW |
868 | ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; |
869 | ireq->sci_status = SCI_FAILURE_IO_TERMINATED; | |
5076a1a9 | 870 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
f00e6ba4 | 871 | return SCI_SUCCESS; |
e301370a EN |
872 | case SCI_REQ_STARTED: |
873 | case SCI_REQ_TASK_WAIT_TC_COMP: | |
874 | case SCI_REQ_SMP_WAIT_RESP: | |
875 | case SCI_REQ_SMP_WAIT_TC_COMP: | |
876 | case SCI_REQ_STP_UDMA_WAIT_TC_COMP: | |
877 | case SCI_REQ_STP_UDMA_WAIT_D2H: | |
878 | case SCI_REQ_STP_NON_DATA_WAIT_H2D: | |
879 | case SCI_REQ_STP_NON_DATA_WAIT_D2H: | |
880 | case SCI_REQ_STP_PIO_WAIT_H2D: | |
881 | case SCI_REQ_STP_PIO_WAIT_FRAME: | |
882 | case SCI_REQ_STP_PIO_DATA_IN: | |
883 | case SCI_REQ_STP_PIO_DATA_OUT: | |
b50102d3 DW |
884 | case SCI_REQ_ATAPI_WAIT_H2D: |
885 | case SCI_REQ_ATAPI_WAIT_PIO_SETUP: | |
886 | case SCI_REQ_ATAPI_WAIT_D2H: | |
887 | case SCI_REQ_ATAPI_WAIT_TC_COMP: | |
726980d5 | 888 | /* Fall through and change state to ABORTING... */ |
e301370a | 889 | case SCI_REQ_TASK_WAIT_TC_RESP: |
39ea2c5b JS |
890 | /* The task frame was already confirmed to have been |
891 | * sent by the SCU HW. Since the state machine is | |
892 | * now only waiting for the task response itself, | |
893 | * abort the request and complete it immediately | |
894 | * and don't wait for the task response. | |
895 | */ | |
5076a1a9 | 896 | sci_change_state(&ireq->sm, SCI_REQ_ABORTING); |
726980d5 | 897 | /* Fall through and handle like ABORTING... */ |
e301370a | 898 | case SCI_REQ_ABORTING: |
726980d5 JS |
899 | if (!isci_remote_device_is_safe_to_abort(ireq->target_device)) |
900 | set_bit(IREQ_PENDING_ABORT, &ireq->flags); | |
901 | else | |
902 | clear_bit(IREQ_PENDING_ABORT, &ireq->flags); | |
903 | /* If the request is only waiting on the remote device | |
904 | * suspension, return SUCCESS so the caller will wait too. | |
39ea2c5b | 905 | */ |
726980d5 | 906 | return SCI_SUCCESS; |
e301370a | 907 | case SCI_REQ_COMPLETED: |
f00e6ba4 | 908 | default: |
d9dcb4ba | 909 | dev_warn(&ireq->owning_controller->pdev->dev, |
f00e6ba4 | 910 | "%s: SCIC IO Request requested to abort while in wrong " |
726980d5 | 911 | "state %d\n", __func__, ireq->sm.current_state_id); |
f00e6ba4 DW |
912 | break; |
913 | } | |
6f231dda | 914 | |
f1f52e75 DW |
915 | return SCI_FAILURE_INVALID_STATE; |
916 | } | |
6f231dda | 917 | |
89a7301f | 918 | enum sci_status sci_request_complete(struct isci_request *ireq) |
f1f52e75 | 919 | { |
79e2b6b2 | 920 | enum sci_base_request_states state; |
d9dcb4ba | 921 | struct isci_host *ihost = ireq->owning_controller; |
79e2b6b2 | 922 | |
5076a1a9 | 923 | state = ireq->sm.current_state_id; |
e301370a | 924 | if (WARN_ONCE(state != SCI_REQ_COMPLETED, |
d7a0ccdd DW |
925 | "isci: request completion from wrong state (%s)\n", |
926 | req_state_name(state))) | |
79e2b6b2 | 927 | return SCI_FAILURE_INVALID_STATE; |
f1f52e75 | 928 | |
5076a1a9 | 929 | if (ireq->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) |
89a7301f | 930 | sci_controller_release_frame(ihost, |
5076a1a9 | 931 | ireq->saved_rx_frame_index); |
79e2b6b2 DW |
932 | |
933 | /* XXX can we just stop the machine and remove the 'final' state? */ | |
5076a1a9 | 934 | sci_change_state(&ireq->sm, SCI_REQ_FINAL); |
79e2b6b2 DW |
935 | return SCI_SUCCESS; |
936 | } | |
937 | ||
89a7301f | 938 | enum sci_status sci_io_request_event_handler(struct isci_request *ireq, |
79e2b6b2 DW |
939 | u32 event_code) |
940 | { | |
941 | enum sci_base_request_states state; | |
d9dcb4ba | 942 | struct isci_host *ihost = ireq->owning_controller; |
79e2b6b2 | 943 | |
5076a1a9 | 944 | state = ireq->sm.current_state_id; |
79e2b6b2 | 945 | |
e301370a | 946 | if (state != SCI_REQ_STP_PIO_DATA_IN) { |
d7a0ccdd DW |
947 | dev_warn(&ihost->pdev->dev, "%s: (%x) in wrong state %s\n", |
948 | __func__, event_code, req_state_name(state)); | |
79e2b6b2 DW |
949 | |
950 | return SCI_FAILURE_INVALID_STATE; | |
951 | } | |
952 | ||
953 | switch (scu_get_event_specifier(event_code)) { | |
954 | case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT: | |
955 | /* We are waiting for data and the SCU has R_ERR the data frame. | |
956 | * Go back to waiting for the D2H Register FIS | |
957 | */ | |
5076a1a9 | 958 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); |
79e2b6b2 DW |
959 | return SCI_SUCCESS; |
960 | default: | |
d9dcb4ba | 961 | dev_err(&ihost->pdev->dev, |
79e2b6b2 DW |
962 | "%s: pio request unexpected event %#x\n", |
963 | __func__, event_code); | |
964 | ||
965 | /* TODO Should we fail the PIO request when we get an | |
966 | * unexpected event? | |
967 | */ | |
968 | return SCI_FAILURE; | |
969 | } | |
6f231dda DW |
970 | } |
971 | ||
f1f52e75 DW |
972 | /* |
973 | * This function copies response data for requests returning response data | |
974 | * instead of sense data. | |
975 | * @sci_req: This parameter specifies the request object for which to copy | |
976 | * the response data. | |
6f231dda | 977 | */ |
89a7301f | 978 | static void sci_io_request_copy_response(struct isci_request *ireq) |
6f231dda | 979 | { |
f1f52e75 DW |
980 | void *resp_buf; |
981 | u32 len; | |
982 | struct ssp_response_iu *ssp_response; | |
f1f52e75 | 983 | struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq); |
6f231dda | 984 | |
5076a1a9 | 985 | ssp_response = &ireq->ssp.rsp; |
6f231dda | 986 | |
f1f52e75 | 987 | resp_buf = &isci_tmf->resp.resp_iu; |
6f231dda | 988 | |
f1f52e75 DW |
989 | len = min_t(u32, |
990 | SSP_RESP_IU_MAX_SIZE, | |
991 | be32_to_cpu(ssp_response->response_data_len)); | |
6f231dda | 992 | |
f1f52e75 DW |
993 | memcpy(resp_buf, ssp_response->resp_data, len); |
994 | } | |
6f231dda | 995 | |
e301370a | 996 | static enum sci_status |
5076a1a9 | 997 | request_started_state_tc_event(struct isci_request *ireq, |
e301370a | 998 | u32 completion_code) |
f1f52e75 | 999 | { |
f1f52e75 | 1000 | struct ssp_response_iu *resp_iu; |
a7e255a3 | 1001 | u8 datapres; |
6f231dda | 1002 | |
a7e255a3 DW |
1003 | /* TODO: Any SDMA return code of other than 0 is bad decode 0x003C0000 |
1004 | * to determine SDMA status | |
f1f52e75 DW |
1005 | */ |
1006 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1007 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
34a99158 DW |
1008 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1009 | ireq->sci_status = SCI_SUCCESS; | |
6f231dda | 1010 | break; |
a7e255a3 DW |
1011 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP): { |
1012 | /* There are times when the SCU hardware will return an early | |
f1f52e75 DW |
1013 | * response because the io request specified more data than is |
1014 | * returned by the target device (mode pages, inquiry data, | |
1015 | * etc.). We must check the response stats to see if this is | |
1016 | * truly a failed request or a good request that just got | |
1017 | * completed early. | |
1018 | */ | |
5076a1a9 | 1019 | struct ssp_response_iu *resp = &ireq->ssp.rsp; |
f1f52e75 DW |
1020 | ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32); |
1021 | ||
5076a1a9 DW |
1022 | sci_swab32_cpy(&ireq->ssp.rsp, |
1023 | &ireq->ssp.rsp, | |
f1f52e75 DW |
1024 | word_cnt); |
1025 | ||
1026 | if (resp->status == 0) { | |
34a99158 DW |
1027 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1028 | ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY; | |
f1f52e75 | 1029 | } else { |
34a99158 DW |
1030 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1031 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
f1f52e75 | 1032 | } |
a7e255a3 | 1033 | break; |
f1f52e75 | 1034 | } |
a7e255a3 | 1035 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE): { |
f1f52e75 | 1036 | ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32); |
6f231dda | 1037 | |
5076a1a9 DW |
1038 | sci_swab32_cpy(&ireq->ssp.rsp, |
1039 | &ireq->ssp.rsp, | |
f1f52e75 | 1040 | word_cnt); |
6f231dda | 1041 | |
34a99158 DW |
1042 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1043 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
6f231dda | 1044 | break; |
f1f52e75 | 1045 | } |
6f231dda | 1046 | |
f1f52e75 | 1047 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR): |
a7e255a3 | 1048 | /* TODO With TASK_DONE_RESP_LEN_ERR is the response frame |
f1f52e75 DW |
1049 | * guaranteed to be received before this completion status is |
1050 | * posted? | |
1051 | */ | |
5076a1a9 | 1052 | resp_iu = &ireq->ssp.rsp; |
f1f52e75 DW |
1053 | datapres = resp_iu->datapres; |
1054 | ||
a7e255a3 | 1055 | if (datapres == 1 || datapres == 2) { |
34a99158 DW |
1056 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1057 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
1058 | } else { | |
1059 | ireq->scu_status = SCU_TASK_DONE_GOOD; | |
1060 | ireq->sci_status = SCI_SUCCESS; | |
1061 | } | |
6f231dda | 1062 | break; |
f1f52e75 DW |
1063 | /* only stp device gets suspended. */ |
1064 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO): | |
1065 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR): | |
1066 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR): | |
1067 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR): | |
1068 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR): | |
1069 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN): | |
1070 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR): | |
1071 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP): | |
1072 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS): | |
1073 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR): | |
1074 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR): | |
c79dd80d | 1075 | if (ireq->protocol == SAS_PROTOCOL_STP) { |
34a99158 DW |
1076 | ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> |
1077 | SCU_COMPLETION_TL_STATUS_SHIFT; | |
1078 | ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; | |
f1f52e75 | 1079 | } else { |
34a99158 DW |
1080 | ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> |
1081 | SCU_COMPLETION_TL_STATUS_SHIFT; | |
1082 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
f1f52e75 | 1083 | } |
6f231dda DW |
1084 | break; |
1085 | ||
f1f52e75 DW |
1086 | /* both stp/ssp device gets suspended */ |
1087 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR): | |
1088 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION): | |
1089 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1): | |
1090 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2): | |
1091 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3): | |
1092 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION): | |
1093 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION): | |
1094 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY): | |
1095 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED): | |
1096 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED): | |
34a99158 DW |
1097 | ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> |
1098 | SCU_COMPLETION_TL_STATUS_SHIFT; | |
1099 | ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; | |
6f231dda DW |
1100 | break; |
1101 | ||
f1f52e75 DW |
1102 | /* neither ssp nor stp gets suspended. */ |
1103 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR): | |
1104 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR): | |
1105 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR): | |
1106 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR): | |
1107 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR): | |
1108 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA): | |
1109 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR): | |
1110 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR): | |
1111 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR): | |
1112 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR): | |
1113 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA): | |
1114 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL): | |
1115 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV): | |
1116 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV): | |
1117 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND): | |
6f231dda | 1118 | default: |
34a99158 DW |
1119 | ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> |
1120 | SCU_COMPLETION_TL_STATUS_SHIFT; | |
1121 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
6f231dda DW |
1122 | break; |
1123 | } | |
f1f52e75 DW |
1124 | |
1125 | /* | |
1126 | * TODO: This is probably wrong for ACK/NAK timeout conditions | |
1127 | */ | |
1128 | ||
1129 | /* In all cases we will treat this as the completion of the IO req. */ | |
5076a1a9 | 1130 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
f1f52e75 | 1131 | return SCI_SUCCESS; |
6f231dda DW |
1132 | } |
1133 | ||
e301370a | 1134 | static enum sci_status |
5076a1a9 | 1135 | request_aborting_state_tc_event(struct isci_request *ireq, |
e301370a | 1136 | u32 completion_code) |
f1f52e75 DW |
1137 | { |
1138 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1139 | case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT): | |
1140 | case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT): | |
34a99158 DW |
1141 | ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; |
1142 | ireq->sci_status = SCI_FAILURE_IO_TERMINATED; | |
5076a1a9 | 1143 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
f1f52e75 DW |
1144 | break; |
1145 | ||
1146 | default: | |
a7e255a3 DW |
1147 | /* Unless we get some strange error wait for the task abort to complete |
1148 | * TODO: Should there be a state change for this completion? | |
1149 | */ | |
6f231dda DW |
1150 | break; |
1151 | } | |
f1f52e75 DW |
1152 | |
1153 | return SCI_SUCCESS; | |
1154 | } | |
1155 | ||
5076a1a9 | 1156 | static enum sci_status ssp_task_request_await_tc_event(struct isci_request *ireq, |
a7e255a3 | 1157 | u32 completion_code) |
f139303d DW |
1158 | { |
1159 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1160 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
34a99158 DW |
1161 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1162 | ireq->sci_status = SCI_SUCCESS; | |
5076a1a9 | 1163 | sci_change_state(&ireq->sm, SCI_REQ_TASK_WAIT_TC_RESP); |
f139303d | 1164 | break; |
f139303d | 1165 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO): |
a7e255a3 DW |
1166 | /* Currently, the decision is to simply allow the task request |
1167 | * to timeout if the task IU wasn't received successfully. | |
1168 | * There is a potential for receiving multiple task responses if | |
1169 | * we decide to send the task IU again. | |
1170 | */ | |
d9dcb4ba | 1171 | dev_warn(&ireq->owning_controller->pdev->dev, |
f139303d | 1172 | "%s: TaskRequest:0x%p CompletionCode:%x - " |
5076a1a9 | 1173 | "ACK/NAK timeout\n", __func__, ireq, |
f139303d DW |
1174 | completion_code); |
1175 | ||
5076a1a9 | 1176 | sci_change_state(&ireq->sm, SCI_REQ_TASK_WAIT_TC_RESP); |
f139303d | 1177 | break; |
f139303d | 1178 | default: |
e301370a EN |
1179 | /* |
1180 | * All other completion status cause the IO to be complete. | |
1181 | * If a NAK was received, then it is up to the user to retry | |
1182 | * the request. | |
a7e255a3 | 1183 | */ |
34a99158 DW |
1184 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
1185 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1186 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
f139303d DW |
1187 | break; |
1188 | } | |
1189 | ||
1190 | return SCI_SUCCESS; | |
1191 | } | |
1192 | ||
e301370a | 1193 | static enum sci_status |
5076a1a9 | 1194 | smp_request_await_response_tc_event(struct isci_request *ireq, |
e301370a | 1195 | u32 completion_code) |
c72086e3 DW |
1196 | { |
1197 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1198 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
a7e255a3 DW |
1199 | /* In the AWAIT RESPONSE state, any TC completion is |
1200 | * unexpected. but if the TC has success status, we | |
1201 | * complete the IO anyway. | |
1202 | */ | |
34a99158 DW |
1203 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1204 | ireq->sci_status = SCI_SUCCESS; | |
5076a1a9 | 1205 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
c72086e3 | 1206 | break; |
c72086e3 DW |
1207 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR): |
1208 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR): | |
1209 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR): | |
1210 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR): | |
a7e255a3 DW |
1211 | /* These status has been seen in a specific LSI |
1212 | * expander, which sometimes is not able to send smp | |
1213 | * response within 2 ms. This causes our hardware break | |
1214 | * the connection and set TC completion with one of | |
1215 | * these SMP_XXX_XX_ERR status. For these type of error, | |
d9dcb4ba | 1216 | * we ask ihost user to retry the request. |
a7e255a3 | 1217 | */ |
34a99158 DW |
1218 | ireq->scu_status = SCU_TASK_DONE_SMP_RESP_TO_ERR; |
1219 | ireq->sci_status = SCI_FAILURE_RETRY_REQUIRED; | |
5076a1a9 | 1220 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
c72086e3 | 1221 | break; |
c72086e3 | 1222 | default: |
a7e255a3 DW |
1223 | /* All other completion status cause the IO to be complete. If a NAK |
1224 | * was received, then it is up to the user to retry the request | |
1225 | */ | |
34a99158 DW |
1226 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
1227 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1228 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
c72086e3 DW |
1229 | break; |
1230 | } | |
1231 | ||
1232 | return SCI_SUCCESS; | |
1233 | } | |
1234 | ||
e301370a | 1235 | static enum sci_status |
5076a1a9 | 1236 | smp_request_await_tc_event(struct isci_request *ireq, |
e301370a | 1237 | u32 completion_code) |
5dec6f4e DW |
1238 | { |
1239 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1240 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
34a99158 DW |
1241 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1242 | ireq->sci_status = SCI_SUCCESS; | |
5076a1a9 | 1243 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
5dec6f4e | 1244 | break; |
5dec6f4e | 1245 | default: |
a7e255a3 DW |
1246 | /* All other completion status cause the IO to be |
1247 | * complete. If a NAK was received, then it is up to | |
1248 | * the user to retry the request. | |
1249 | */ | |
34a99158 DW |
1250 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
1251 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1252 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
5dec6f4e DW |
1253 | break; |
1254 | } | |
1255 | ||
1256 | return SCI_SUCCESS; | |
1257 | } | |
1258 | ||
ba7cb223 | 1259 | static struct scu_sgl_element *pio_sgl_next(struct isci_stp_request *stp_req) |
5dec6f4e | 1260 | { |
312e0c24 DW |
1261 | struct scu_sgl_element *sgl; |
1262 | struct scu_sgl_element_pair *sgl_pair; | |
5076a1a9 | 1263 | struct isci_request *ireq = to_ireq(stp_req); |
ba7cb223 | 1264 | struct isci_stp_pio_sgl *pio_sgl = &stp_req->sgl; |
5dec6f4e | 1265 | |
5076a1a9 | 1266 | sgl_pair = to_sgl_element_pair(ireq, pio_sgl->index); |
312e0c24 DW |
1267 | if (!sgl_pair) |
1268 | sgl = NULL; | |
ba7cb223 | 1269 | else if (pio_sgl->set == SCU_SGL_ELEMENT_PAIR_A) { |
312e0c24 DW |
1270 | if (sgl_pair->B.address_lower == 0 && |
1271 | sgl_pair->B.address_upper == 0) { | |
1272 | sgl = NULL; | |
5dec6f4e | 1273 | } else { |
ba7cb223 | 1274 | pio_sgl->set = SCU_SGL_ELEMENT_PAIR_B; |
312e0c24 | 1275 | sgl = &sgl_pair->B; |
5dec6f4e DW |
1276 | } |
1277 | } else { | |
312e0c24 DW |
1278 | if (sgl_pair->next_pair_lower == 0 && |
1279 | sgl_pair->next_pair_upper == 0) { | |
1280 | sgl = NULL; | |
5dec6f4e | 1281 | } else { |
ba7cb223 DW |
1282 | pio_sgl->index++; |
1283 | pio_sgl->set = SCU_SGL_ELEMENT_PAIR_A; | |
5076a1a9 | 1284 | sgl_pair = to_sgl_element_pair(ireq, pio_sgl->index); |
312e0c24 | 1285 | sgl = &sgl_pair->A; |
5dec6f4e DW |
1286 | } |
1287 | } | |
1288 | ||
312e0c24 | 1289 | return sgl; |
5dec6f4e DW |
1290 | } |
1291 | ||
e301370a | 1292 | static enum sci_status |
5076a1a9 | 1293 | stp_request_non_data_await_h2d_tc_event(struct isci_request *ireq, |
e301370a | 1294 | u32 completion_code) |
5dec6f4e DW |
1295 | { |
1296 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1297 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
34a99158 DW |
1298 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1299 | ireq->sci_status = SCI_SUCCESS; | |
5076a1a9 | 1300 | sci_change_state(&ireq->sm, SCI_REQ_STP_NON_DATA_WAIT_D2H); |
5dec6f4e DW |
1301 | break; |
1302 | ||
1303 | default: | |
a7e255a3 DW |
1304 | /* All other completion status cause the IO to be |
1305 | * complete. If a NAK was received, then it is up to | |
1306 | * the user to retry the request. | |
1307 | */ | |
34a99158 DW |
1308 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
1309 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1310 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
5dec6f4e DW |
1311 | break; |
1312 | } | |
1313 | ||
1314 | return SCI_SUCCESS; | |
1315 | } | |
1316 | ||
5dec6f4e DW |
1317 | #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */ |
1318 | ||
1319 | /* transmit DATA_FIS from (current sgl + offset) for input | |
1320 | * parameter length. current sgl and offset is alreay stored in the IO request | |
1321 | */ | |
89a7301f | 1322 | static enum sci_status sci_stp_request_pio_data_out_trasmit_data_frame( |
5076a1a9 | 1323 | struct isci_request *ireq, |
5dec6f4e DW |
1324 | u32 length) |
1325 | { | |
5076a1a9 DW |
1326 | struct isci_stp_request *stp_req = &ireq->stp.req; |
1327 | struct scu_task_context *task_context = ireq->tc; | |
312e0c24 | 1328 | struct scu_sgl_element_pair *sgl_pair; |
5dec6f4e DW |
1329 | struct scu_sgl_element *current_sgl; |
1330 | ||
1331 | /* Recycle the TC and reconstruct it for sending out DATA FIS containing | |
1332 | * for the data from current_sgl+offset for the input length | |
1333 | */ | |
5076a1a9 | 1334 | sgl_pair = to_sgl_element_pair(ireq, stp_req->sgl.index); |
ba7cb223 | 1335 | if (stp_req->sgl.set == SCU_SGL_ELEMENT_PAIR_A) |
312e0c24 | 1336 | current_sgl = &sgl_pair->A; |
5dec6f4e | 1337 | else |
312e0c24 | 1338 | current_sgl = &sgl_pair->B; |
5dec6f4e DW |
1339 | |
1340 | /* update the TC */ | |
1341 | task_context->command_iu_upper = current_sgl->address_upper; | |
1342 | task_context->command_iu_lower = current_sgl->address_lower; | |
1343 | task_context->transfer_length_bytes = length; | |
1344 | task_context->type.stp.fis_type = FIS_DATA; | |
1345 | ||
1346 | /* send the new TC out. */ | |
89a7301f | 1347 | return sci_controller_continue_io(ireq); |
5dec6f4e DW |
1348 | } |
1349 | ||
89a7301f | 1350 | static enum sci_status sci_stp_request_pio_data_out_transmit_data(struct isci_request *ireq) |
5dec6f4e | 1351 | { |
5076a1a9 | 1352 | struct isci_stp_request *stp_req = &ireq->stp.req; |
312e0c24 | 1353 | struct scu_sgl_element_pair *sgl_pair; |
b50102d3 | 1354 | enum sci_status status = SCI_SUCCESS; |
ba7cb223 | 1355 | struct scu_sgl_element *sgl; |
ba7cb223 DW |
1356 | u32 offset; |
1357 | u32 len = 0; | |
5dec6f4e | 1358 | |
ba7cb223 | 1359 | offset = stp_req->sgl.offset; |
5076a1a9 | 1360 | sgl_pair = to_sgl_element_pair(ireq, stp_req->sgl.index); |
312e0c24 DW |
1361 | if (WARN_ONCE(!sgl_pair, "%s: null sgl element", __func__)) |
1362 | return SCI_FAILURE; | |
5dec6f4e | 1363 | |
ba7cb223 DW |
1364 | if (stp_req->sgl.set == SCU_SGL_ELEMENT_PAIR_A) { |
1365 | sgl = &sgl_pair->A; | |
1366 | len = sgl_pair->A.length - offset; | |
5dec6f4e | 1367 | } else { |
ba7cb223 DW |
1368 | sgl = &sgl_pair->B; |
1369 | len = sgl_pair->B.length - offset; | |
5dec6f4e DW |
1370 | } |
1371 | ||
ba7cb223 DW |
1372 | if (stp_req->pio_len == 0) |
1373 | return SCI_SUCCESS; | |
5dec6f4e | 1374 | |
ba7cb223 | 1375 | if (stp_req->pio_len >= len) { |
89a7301f | 1376 | status = sci_stp_request_pio_data_out_trasmit_data_frame(ireq, len); |
ba7cb223 DW |
1377 | if (status != SCI_SUCCESS) |
1378 | return status; | |
1379 | stp_req->pio_len -= len; | |
1380 | ||
1381 | /* update the current sgl, offset and save for future */ | |
1382 | sgl = pio_sgl_next(stp_req); | |
1383 | offset = 0; | |
1384 | } else if (stp_req->pio_len < len) { | |
89a7301f | 1385 | sci_stp_request_pio_data_out_trasmit_data_frame(ireq, stp_req->pio_len); |
ba7cb223 DW |
1386 | |
1387 | /* Sgl offset will be adjusted and saved for future */ | |
1388 | offset += stp_req->pio_len; | |
1389 | sgl->address_lower += stp_req->pio_len; | |
1390 | stp_req->pio_len = 0; | |
5dec6f4e DW |
1391 | } |
1392 | ||
ba7cb223 | 1393 | stp_req->sgl.offset = offset; |
5dec6f4e DW |
1394 | |
1395 | return status; | |
1396 | } | |
1397 | ||
1398 | /** | |
1399 | * | |
1400 | * @stp_request: The request that is used for the SGL processing. | |
1401 | * @data_buffer: The buffer of data to be copied. | |
1402 | * @length: The length of the data transfer. | |
1403 | * | |
1404 | * Copy the data from the buffer for the length specified to the IO reqeust SGL | |
1405 | * specified data region. enum sci_status | |
1406 | */ | |
1407 | static enum sci_status | |
89a7301f | 1408 | sci_stp_request_pio_data_in_copy_data_buffer(struct isci_stp_request *stp_req, |
b50102d3 | 1409 | u8 *data_buf, u32 len) |
5dec6f4e | 1410 | { |
5dec6f4e DW |
1411 | struct isci_request *ireq; |
1412 | u8 *src_addr; | |
1413 | int copy_len; | |
1414 | struct sas_task *task; | |
1415 | struct scatterlist *sg; | |
1416 | void *kaddr; | |
1417 | int total_len = len; | |
1418 | ||
5076a1a9 | 1419 | ireq = to_ireq(stp_req); |
5dec6f4e DW |
1420 | task = isci_request_access_task(ireq); |
1421 | src_addr = data_buf; | |
1422 | ||
1423 | if (task->num_scatter > 0) { | |
1424 | sg = task->scatter; | |
1425 | ||
1426 | while (total_len > 0) { | |
1427 | struct page *page = sg_page(sg); | |
1428 | ||
1429 | copy_len = min_t(int, total_len, sg_dma_len(sg)); | |
77dfce07 | 1430 | kaddr = kmap_atomic(page); |
5dec6f4e | 1431 | memcpy(kaddr + sg->offset, src_addr, copy_len); |
77dfce07 | 1432 | kunmap_atomic(kaddr); |
5dec6f4e DW |
1433 | total_len -= copy_len; |
1434 | src_addr += copy_len; | |
1435 | sg = sg_next(sg); | |
1436 | } | |
1437 | } else { | |
1438 | BUG_ON(task->total_xfer_len < total_len); | |
1439 | memcpy(task->scatter, src_addr, total_len); | |
1440 | } | |
1441 | ||
1442 | return SCI_SUCCESS; | |
1443 | } | |
1444 | ||
1445 | /** | |
1446 | * | |
1447 | * @sci_req: The PIO DATA IN request that is to receive the data. | |
1448 | * @data_buffer: The buffer to copy from. | |
1449 | * | |
1450 | * Copy the data buffer to the io request data region. enum sci_status | |
1451 | */ | |
89a7301f | 1452 | static enum sci_status sci_stp_request_pio_data_in_copy_data( |
ba7cb223 | 1453 | struct isci_stp_request *stp_req, |
5dec6f4e DW |
1454 | u8 *data_buffer) |
1455 | { | |
1456 | enum sci_status status; | |
1457 | ||
1458 | /* | |
1459 | * If there is less than 1K remaining in the transfer request | |
1460 | * copy just the data for the transfer */ | |
ba7cb223 | 1461 | if (stp_req->pio_len < SCU_MAX_FRAME_BUFFER_SIZE) { |
89a7301f | 1462 | status = sci_stp_request_pio_data_in_copy_data_buffer( |
ba7cb223 | 1463 | stp_req, data_buffer, stp_req->pio_len); |
5dec6f4e DW |
1464 | |
1465 | if (status == SCI_SUCCESS) | |
ba7cb223 | 1466 | stp_req->pio_len = 0; |
5dec6f4e DW |
1467 | } else { |
1468 | /* We are transfering the whole frame so copy */ | |
89a7301f | 1469 | status = sci_stp_request_pio_data_in_copy_data_buffer( |
ba7cb223 | 1470 | stp_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE); |
5dec6f4e DW |
1471 | |
1472 | if (status == SCI_SUCCESS) | |
ba7cb223 | 1473 | stp_req->pio_len -= SCU_MAX_FRAME_BUFFER_SIZE; |
5dec6f4e DW |
1474 | } |
1475 | ||
1476 | return status; | |
1477 | } | |
1478 | ||
e301370a | 1479 | static enum sci_status |
5076a1a9 | 1480 | stp_request_pio_await_h2d_completion_tc_event(struct isci_request *ireq, |
e301370a | 1481 | u32 completion_code) |
5dec6f4e DW |
1482 | { |
1483 | enum sci_status status = SCI_SUCCESS; | |
1484 | ||
1485 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
1486 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
34a99158 DW |
1487 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1488 | ireq->sci_status = SCI_SUCCESS; | |
5076a1a9 | 1489 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); |
5dec6f4e DW |
1490 | break; |
1491 | ||
1492 | default: | |
a7e255a3 DW |
1493 | /* All other completion status cause the IO to be |
1494 | * complete. If a NAK was received, then it is up to | |
1495 | * the user to retry the request. | |
1496 | */ | |
34a99158 DW |
1497 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
1498 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1499 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
5dec6f4e DW |
1500 | break; |
1501 | } | |
1502 | ||
1503 | return status; | |
1504 | } | |
1505 | ||
e301370a | 1506 | static enum sci_status |
5076a1a9 | 1507 | pio_data_out_tx_done_tc_event(struct isci_request *ireq, |
e301370a | 1508 | u32 completion_code) |
5dec6f4e | 1509 | { |
d1c637c3 DW |
1510 | enum sci_status status = SCI_SUCCESS; |
1511 | bool all_frames_transferred = false; | |
5076a1a9 | 1512 | struct isci_stp_request *stp_req = &ireq->stp.req; |
5dec6f4e | 1513 | |
d1c637c3 DW |
1514 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { |
1515 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
1516 | /* Transmit data */ | |
ba7cb223 | 1517 | if (stp_req->pio_len != 0) { |
89a7301f | 1518 | status = sci_stp_request_pio_data_out_transmit_data(ireq); |
d1c637c3 | 1519 | if (status == SCI_SUCCESS) { |
ba7cb223 | 1520 | if (stp_req->pio_len == 0) |
d1c637c3 DW |
1521 | all_frames_transferred = true; |
1522 | } | |
ba7cb223 | 1523 | } else if (stp_req->pio_len == 0) { |
d1c637c3 DW |
1524 | /* |
1525 | * this will happen if the all data is written at the | |
1526 | * first time after the pio setup fis is received | |
5dec6f4e | 1527 | */ |
d1c637c3 | 1528 | all_frames_transferred = true; |
5dec6f4e DW |
1529 | } |
1530 | ||
d1c637c3 DW |
1531 | /* all data transferred. */ |
1532 | if (all_frames_transferred) { | |
1533 | /* | |
e301370a | 1534 | * Change the state to SCI_REQ_STP_PIO_DATA_IN |
d1c637c3 | 1535 | * and wait for PIO_SETUP fis / or D2H REg fis. */ |
5076a1a9 | 1536 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); |
d1c637c3 | 1537 | } |
5dec6f4e | 1538 | break; |
e301370a | 1539 | |
5dec6f4e | 1540 | default: |
d1c637c3 | 1541 | /* |
e301370a EN |
1542 | * All other completion status cause the IO to be complete. |
1543 | * If a NAK was received, then it is up to the user to retry | |
1544 | * the request. | |
1545 | */ | |
34a99158 DW |
1546 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
1547 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1548 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
5dec6f4e DW |
1549 | break; |
1550 | } | |
1551 | ||
1552 | return status; | |
1553 | } | |
1554 | ||
89a7301f | 1555 | static enum sci_status sci_stp_request_udma_general_frame_handler(struct isci_request *ireq, |
5dec6f4e DW |
1556 | u32 frame_index) |
1557 | { | |
d9dcb4ba | 1558 | struct isci_host *ihost = ireq->owning_controller; |
5dec6f4e DW |
1559 | struct dev_to_host_fis *frame_header; |
1560 | enum sci_status status; | |
1561 | u32 *frame_buffer; | |
1562 | ||
89a7301f | 1563 | status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
5dec6f4e DW |
1564 | frame_index, |
1565 | (void **)&frame_header); | |
1566 | ||
1567 | if ((status == SCI_SUCCESS) && | |
1568 | (frame_header->fis_type == FIS_REGD2H)) { | |
89a7301f | 1569 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
5dec6f4e DW |
1570 | frame_index, |
1571 | (void **)&frame_buffer); | |
1572 | ||
89a7301f | 1573 | sci_controller_copy_sata_response(&ireq->stp.rsp, |
5dec6f4e DW |
1574 | frame_header, |
1575 | frame_buffer); | |
1576 | } | |
1577 | ||
89a7301f | 1578 | sci_controller_release_frame(ihost, frame_index); |
5dec6f4e DW |
1579 | |
1580 | return status; | |
1581 | } | |
1582 | ||
b50102d3 DW |
1583 | static enum sci_status process_unsolicited_fis(struct isci_request *ireq, |
1584 | u32 frame_index) | |
1585 | { | |
1586 | struct isci_host *ihost = ireq->owning_controller; | |
1587 | enum sci_status status; | |
1588 | struct dev_to_host_fis *frame_header; | |
1589 | u32 *frame_buffer; | |
1590 | ||
1591 | status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, | |
1592 | frame_index, | |
1593 | (void **)&frame_header); | |
1594 | ||
1595 | if (status != SCI_SUCCESS) | |
1596 | return status; | |
1597 | ||
1598 | if (frame_header->fis_type != FIS_REGD2H) { | |
1599 | dev_err(&ireq->isci_host->pdev->dev, | |
1600 | "%s ERROR: invalid fis type 0x%X\n", | |
1601 | __func__, frame_header->fis_type); | |
1602 | return SCI_FAILURE; | |
1603 | } | |
1604 | ||
1605 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, | |
1606 | frame_index, | |
1607 | (void **)&frame_buffer); | |
1608 | ||
1609 | sci_controller_copy_sata_response(&ireq->stp.rsp, | |
1610 | (u32 *)frame_header, | |
1611 | frame_buffer); | |
1612 | ||
1613 | /* Frame has been decoded return it to the controller */ | |
1614 | sci_controller_release_frame(ihost, frame_index); | |
1615 | ||
1616 | return status; | |
1617 | } | |
1618 | ||
1619 | static enum sci_status atapi_d2h_reg_frame_handler(struct isci_request *ireq, | |
1620 | u32 frame_index) | |
1621 | { | |
1622 | struct sas_task *task = isci_request_access_task(ireq); | |
1623 | enum sci_status status; | |
1624 | ||
1625 | status = process_unsolicited_fis(ireq, frame_index); | |
1626 | ||
1627 | if (status == SCI_SUCCESS) { | |
1628 | if (ireq->stp.rsp.status & ATA_ERR) | |
1629 | status = SCI_IO_FAILURE_RESPONSE_VALID; | |
1630 | } else { | |
1631 | status = SCI_IO_FAILURE_RESPONSE_VALID; | |
1632 | } | |
1633 | ||
1634 | if (status != SCI_SUCCESS) { | |
1635 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | |
1636 | ireq->sci_status = status; | |
1637 | } else { | |
1638 | ireq->scu_status = SCU_TASK_DONE_GOOD; | |
1639 | ireq->sci_status = SCI_SUCCESS; | |
1640 | } | |
1641 | ||
1642 | /* the d2h ufi is the end of non-data commands */ | |
1643 | if (task->data_dir == DMA_NONE) | |
1644 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
1645 | ||
1646 | return status; | |
1647 | } | |
1648 | ||
1649 | static void scu_atapi_reconstruct_raw_frame_task_context(struct isci_request *ireq) | |
1650 | { | |
1651 | struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev); | |
1652 | void *atapi_cdb = ireq->ttype_ptr.io_task_ptr->ata_task.atapi_packet; | |
1653 | struct scu_task_context *task_context = ireq->tc; | |
1654 | ||
1655 | /* fill in the SCU Task Context for a DATA fis containing CDB in Raw Frame | |
1656 | * type. The TC for previous Packet fis was already there, we only need to | |
1657 | * change the H2D fis content. | |
1658 | */ | |
1659 | memset(&ireq->stp.cmd, 0, sizeof(struct host_to_dev_fis)); | |
1660 | memcpy(((u8 *)&ireq->stp.cmd + sizeof(u32)), atapi_cdb, ATAPI_CDB_LEN); | |
1661 | memset(&(task_context->type.stp), 0, sizeof(struct stp_task_context)); | |
1662 | task_context->type.stp.fis_type = FIS_DATA; | |
1663 | task_context->transfer_length_bytes = dev->cdb_len; | |
1664 | } | |
1665 | ||
1666 | static void scu_atapi_construct_task_context(struct isci_request *ireq) | |
1667 | { | |
1668 | struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev); | |
1669 | struct sas_task *task = isci_request_access_task(ireq); | |
1670 | struct scu_task_context *task_context = ireq->tc; | |
1671 | int cdb_len = dev->cdb_len; | |
1672 | ||
1673 | /* reference: SSTL 1.13.4.2 | |
1674 | * task_type, sata_direction | |
1675 | */ | |
1676 | if (task->data_dir == DMA_TO_DEVICE) { | |
1677 | task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_OUT; | |
1678 | task_context->sata_direction = 0; | |
1679 | } else { | |
1680 | /* todo: for NO_DATA command, we need to send out raw frame. */ | |
1681 | task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_IN; | |
1682 | task_context->sata_direction = 1; | |
1683 | } | |
1684 | ||
1685 | memset(&task_context->type.stp, 0, sizeof(task_context->type.stp)); | |
1686 | task_context->type.stp.fis_type = FIS_DATA; | |
1687 | ||
1688 | memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); | |
1689 | memcpy(&ireq->stp.cmd.lbal, task->ata_task.atapi_packet, cdb_len); | |
1690 | task_context->ssp_command_iu_length = cdb_len / sizeof(u32); | |
1691 | ||
1692 | /* task phase is set to TX_CMD */ | |
1693 | task_context->task_phase = 0x1; | |
1694 | ||
1695 | /* retry counter */ | |
1696 | task_context->stp_retry_count = 0; | |
1697 | ||
1698 | /* data transfer size. */ | |
1699 | task_context->transfer_length_bytes = task->total_xfer_len; | |
1700 | ||
1701 | /* setup sgl */ | |
1702 | sci_request_build_sgl(ireq); | |
1703 | } | |
1704 | ||
e301370a | 1705 | enum sci_status |
89a7301f | 1706 | sci_io_request_frame_handler(struct isci_request *ireq, |
e301370a | 1707 | u32 frame_index) |
d1c637c3 | 1708 | { |
d9dcb4ba | 1709 | struct isci_host *ihost = ireq->owning_controller; |
5076a1a9 | 1710 | struct isci_stp_request *stp_req = &ireq->stp.req; |
d1c637c3 DW |
1711 | enum sci_base_request_states state; |
1712 | enum sci_status status; | |
1713 | ssize_t word_cnt; | |
1714 | ||
5076a1a9 | 1715 | state = ireq->sm.current_state_id; |
d1c637c3 | 1716 | switch (state) { |
e301370a | 1717 | case SCI_REQ_STARTED: { |
d1c637c3 DW |
1718 | struct ssp_frame_hdr ssp_hdr; |
1719 | void *frame_header; | |
1720 | ||
89a7301f | 1721 | sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
d1c637c3 DW |
1722 | frame_index, |
1723 | &frame_header); | |
1724 | ||
1725 | word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32); | |
1726 | sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt); | |
1727 | ||
1728 | if (ssp_hdr.frame_type == SSP_RESPONSE) { | |
1729 | struct ssp_response_iu *resp_iu; | |
1730 | ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32); | |
1731 | ||
89a7301f | 1732 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
d1c637c3 DW |
1733 | frame_index, |
1734 | (void **)&resp_iu); | |
1735 | ||
5076a1a9 | 1736 | sci_swab32_cpy(&ireq->ssp.rsp, resp_iu, word_cnt); |
d1c637c3 | 1737 | |
5076a1a9 | 1738 | resp_iu = &ireq->ssp.rsp; |
d1c637c3 DW |
1739 | |
1740 | if (resp_iu->datapres == 0x01 || | |
1741 | resp_iu->datapres == 0x02) { | |
34a99158 DW |
1742 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1743 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
1744 | } else { | |
1745 | ireq->scu_status = SCU_TASK_DONE_GOOD; | |
1746 | ireq->sci_status = SCI_SUCCESS; | |
1747 | } | |
d1c637c3 DW |
1748 | } else { |
1749 | /* not a response frame, why did it get forwarded? */ | |
d9dcb4ba | 1750 | dev_err(&ihost->pdev->dev, |
d1c637c3 | 1751 | "%s: SCIC IO Request 0x%p received unexpected " |
5076a1a9 | 1752 | "frame %d type 0x%02x\n", __func__, ireq, |
d1c637c3 DW |
1753 | frame_index, ssp_hdr.frame_type); |
1754 | } | |
1755 | ||
1756 | /* | |
e301370a EN |
1757 | * In any case we are done with this frame buffer return it to |
1758 | * the controller | |
d1c637c3 | 1759 | */ |
89a7301f | 1760 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
1761 | |
1762 | return SCI_SUCCESS; | |
1763 | } | |
e301370a EN |
1764 | |
1765 | case SCI_REQ_TASK_WAIT_TC_RESP: | |
89a7301f | 1766 | sci_io_request_copy_response(ireq); |
5076a1a9 | 1767 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
89a7301f | 1768 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 | 1769 | return SCI_SUCCESS; |
e301370a EN |
1770 | |
1771 | case SCI_REQ_SMP_WAIT_RESP: { | |
54b5e3a4 DW |
1772 | struct sas_task *task = isci_request_access_task(ireq); |
1773 | struct scatterlist *sg = &task->smp_task.smp_resp; | |
1774 | void *frame_header, *kaddr; | |
1775 | u8 *rsp; | |
d1c637c3 | 1776 | |
89a7301f | 1777 | sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
54b5e3a4 DW |
1778 | frame_index, |
1779 | &frame_header); | |
77dfce07 | 1780 | kaddr = kmap_atomic(sg_page(sg)); |
54b5e3a4 DW |
1781 | rsp = kaddr + sg->offset; |
1782 | sci_swab32_cpy(rsp, frame_header, 1); | |
d1c637c3 | 1783 | |
54b5e3a4 | 1784 | if (rsp[0] == SMP_RESPONSE) { |
d1c637c3 DW |
1785 | void *smp_resp; |
1786 | ||
89a7301f | 1787 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
54b5e3a4 DW |
1788 | frame_index, |
1789 | &smp_resp); | |
d1c637c3 | 1790 | |
54b5e3a4 DW |
1791 | word_cnt = (sg->length/4)-1; |
1792 | if (word_cnt > 0) | |
1793 | word_cnt = min_t(unsigned int, word_cnt, | |
1794 | SCU_UNSOLICITED_FRAME_BUFFER_SIZE/4); | |
1795 | sci_swab32_cpy(rsp + 4, smp_resp, word_cnt); | |
d1c637c3 | 1796 | |
34a99158 DW |
1797 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
1798 | ireq->sci_status = SCI_SUCCESS; | |
5076a1a9 | 1799 | sci_change_state(&ireq->sm, SCI_REQ_SMP_WAIT_TC_COMP); |
d1c637c3 | 1800 | } else { |
e301370a EN |
1801 | /* |
1802 | * This was not a response frame why did it get | |
1803 | * forwarded? | |
1804 | */ | |
d9dcb4ba | 1805 | dev_err(&ihost->pdev->dev, |
e301370a EN |
1806 | "%s: SCIC SMP Request 0x%p received unexpected " |
1807 | "frame %d type 0x%02x\n", | |
1808 | __func__, | |
5076a1a9 | 1809 | ireq, |
e301370a | 1810 | frame_index, |
54b5e3a4 | 1811 | rsp[0]); |
d1c637c3 | 1812 | |
34a99158 DW |
1813 | ireq->scu_status = SCU_TASK_DONE_SMP_FRM_TYPE_ERR; |
1814 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
5076a1a9 | 1815 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
d1c637c3 | 1816 | } |
77dfce07 | 1817 | kunmap_atomic(kaddr); |
d1c637c3 | 1818 | |
89a7301f | 1819 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
1820 | |
1821 | return SCI_SUCCESS; | |
1822 | } | |
e301370a EN |
1823 | |
1824 | case SCI_REQ_STP_UDMA_WAIT_TC_COMP: | |
89a7301f | 1825 | return sci_stp_request_udma_general_frame_handler(ireq, |
e301370a EN |
1826 | frame_index); |
1827 | ||
1828 | case SCI_REQ_STP_UDMA_WAIT_D2H: | |
d1c637c3 | 1829 | /* Use the general frame handler to copy the resposne data */ |
34a99158 | 1830 | status = sci_stp_request_udma_general_frame_handler(ireq, frame_index); |
d1c637c3 DW |
1831 | |
1832 | if (status != SCI_SUCCESS) | |
1833 | return status; | |
1834 | ||
34a99158 DW |
1835 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1836 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
1837 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
d1c637c3 | 1838 | return SCI_SUCCESS; |
e301370a EN |
1839 | |
1840 | case SCI_REQ_STP_NON_DATA_WAIT_D2H: { | |
d1c637c3 DW |
1841 | struct dev_to_host_fis *frame_header; |
1842 | u32 *frame_buffer; | |
1843 | ||
89a7301f | 1844 | status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
d1c637c3 DW |
1845 | frame_index, |
1846 | (void **)&frame_header); | |
1847 | ||
1848 | if (status != SCI_SUCCESS) { | |
d9dcb4ba | 1849 | dev_err(&ihost->pdev->dev, |
e301370a EN |
1850 | "%s: SCIC IO Request 0x%p could not get frame " |
1851 | "header for frame index %d, status %x\n", | |
1852 | __func__, | |
1853 | stp_req, | |
1854 | frame_index, | |
1855 | status); | |
d1c637c3 DW |
1856 | |
1857 | return status; | |
1858 | } | |
1859 | ||
1860 | switch (frame_header->fis_type) { | |
1861 | case FIS_REGD2H: | |
89a7301f | 1862 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
d1c637c3 DW |
1863 | frame_index, |
1864 | (void **)&frame_buffer); | |
1865 | ||
89a7301f | 1866 | sci_controller_copy_sata_response(&ireq->stp.rsp, |
d1c637c3 DW |
1867 | frame_header, |
1868 | frame_buffer); | |
1869 | ||
1870 | /* The command has completed with error */ | |
34a99158 DW |
1871 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1872 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
d1c637c3 DW |
1873 | break; |
1874 | ||
1875 | default: | |
d9dcb4ba | 1876 | dev_warn(&ihost->pdev->dev, |
d1c637c3 DW |
1877 | "%s: IO Request:0x%p Frame Id:%d protocol " |
1878 | "violation occurred\n", __func__, stp_req, | |
1879 | frame_index); | |
1880 | ||
34a99158 DW |
1881 | ireq->scu_status = SCU_TASK_DONE_UNEXP_FIS; |
1882 | ireq->sci_status = SCI_FAILURE_PROTOCOL_VIOLATION; | |
d1c637c3 DW |
1883 | break; |
1884 | } | |
1885 | ||
5076a1a9 | 1886 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
d1c637c3 DW |
1887 | |
1888 | /* Frame has been decoded return it to the controller */ | |
89a7301f | 1889 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
1890 | |
1891 | return status; | |
1892 | } | |
e301370a EN |
1893 | |
1894 | case SCI_REQ_STP_PIO_WAIT_FRAME: { | |
d1c637c3 DW |
1895 | struct sas_task *task = isci_request_access_task(ireq); |
1896 | struct dev_to_host_fis *frame_header; | |
1897 | u32 *frame_buffer; | |
1898 | ||
89a7301f | 1899 | status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
d1c637c3 DW |
1900 | frame_index, |
1901 | (void **)&frame_header); | |
1902 | ||
1903 | if (status != SCI_SUCCESS) { | |
d9dcb4ba | 1904 | dev_err(&ihost->pdev->dev, |
e301370a EN |
1905 | "%s: SCIC IO Request 0x%p could not get frame " |
1906 | "header for frame index %d, status %x\n", | |
d1c637c3 DW |
1907 | __func__, stp_req, frame_index, status); |
1908 | return status; | |
1909 | } | |
1910 | ||
1911 | switch (frame_header->fis_type) { | |
1912 | case FIS_PIO_SETUP: | |
1913 | /* Get from the frame buffer the PIO Setup Data */ | |
89a7301f | 1914 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
d1c637c3 DW |
1915 | frame_index, |
1916 | (void **)&frame_buffer); | |
1917 | ||
e301370a EN |
1918 | /* Get the data from the PIO Setup The SCU Hardware |
1919 | * returns first word in the frame_header and the rest | |
1920 | * of the data is in the frame buffer so we need to | |
1921 | * back up one dword | |
d1c637c3 DW |
1922 | */ |
1923 | ||
1924 | /* transfer_count: first 16bits in the 4th dword */ | |
ba7cb223 | 1925 | stp_req->pio_len = frame_buffer[3] & 0xffff; |
d1c637c3 | 1926 | |
ba7cb223 DW |
1927 | /* status: 4th byte in the 3rd dword */ |
1928 | stp_req->status = (frame_buffer[2] >> 24) & 0xff; | |
d1c637c3 | 1929 | |
89a7301f | 1930 | sci_controller_copy_sata_response(&ireq->stp.rsp, |
d1c637c3 DW |
1931 | frame_header, |
1932 | frame_buffer); | |
1933 | ||
5076a1a9 | 1934 | ireq->stp.rsp.status = stp_req->status; |
d1c637c3 DW |
1935 | |
1936 | /* The next state is dependent on whether the | |
1937 | * request was PIO Data-in or Data out | |
1938 | */ | |
1939 | if (task->data_dir == DMA_FROM_DEVICE) { | |
5076a1a9 | 1940 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_DATA_IN); |
d1c637c3 DW |
1941 | } else if (task->data_dir == DMA_TO_DEVICE) { |
1942 | /* Transmit data */ | |
89a7301f | 1943 | status = sci_stp_request_pio_data_out_transmit_data(ireq); |
d1c637c3 DW |
1944 | if (status != SCI_SUCCESS) |
1945 | break; | |
5076a1a9 | 1946 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_DATA_OUT); |
d1c637c3 DW |
1947 | } |
1948 | break; | |
e301370a | 1949 | |
d1c637c3 | 1950 | case FIS_SETDEVBITS: |
5076a1a9 | 1951 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); |
d1c637c3 | 1952 | break; |
e301370a | 1953 | |
d1c637c3 DW |
1954 | case FIS_REGD2H: |
1955 | if (frame_header->status & ATA_BUSY) { | |
e301370a EN |
1956 | /* |
1957 | * Now why is the drive sending a D2H Register | |
1958 | * FIS when it is still busy? Do nothing since | |
1959 | * we are still in the right state. | |
d1c637c3 | 1960 | */ |
d9dcb4ba | 1961 | dev_dbg(&ihost->pdev->dev, |
d1c637c3 DW |
1962 | "%s: SCIC PIO Request 0x%p received " |
1963 | "D2H Register FIS with BSY status " | |
e301370a EN |
1964 | "0x%x\n", |
1965 | __func__, | |
1966 | stp_req, | |
d1c637c3 DW |
1967 | frame_header->status); |
1968 | break; | |
1969 | } | |
1970 | ||
89a7301f | 1971 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
d1c637c3 DW |
1972 | frame_index, |
1973 | (void **)&frame_buffer); | |
1974 | ||
89a7301f | 1975 | sci_controller_copy_sata_response(&ireq->stp.req, |
d1c637c3 DW |
1976 | frame_header, |
1977 | frame_buffer); | |
1978 | ||
34a99158 DW |
1979 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
1980 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
5076a1a9 | 1981 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
d1c637c3 | 1982 | break; |
e301370a | 1983 | |
d1c637c3 DW |
1984 | default: |
1985 | /* FIXME: what do we do here? */ | |
1986 | break; | |
1987 | } | |
1988 | ||
1989 | /* Frame is decoded return it to the controller */ | |
89a7301f | 1990 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
1991 | |
1992 | return status; | |
1993 | } | |
e301370a EN |
1994 | |
1995 | case SCI_REQ_STP_PIO_DATA_IN: { | |
d1c637c3 DW |
1996 | struct dev_to_host_fis *frame_header; |
1997 | struct sata_fis_data *frame_buffer; | |
1998 | ||
89a7301f | 1999 | status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, |
d1c637c3 DW |
2000 | frame_index, |
2001 | (void **)&frame_header); | |
2002 | ||
2003 | if (status != SCI_SUCCESS) { | |
d9dcb4ba | 2004 | dev_err(&ihost->pdev->dev, |
e301370a EN |
2005 | "%s: SCIC IO Request 0x%p could not get frame " |
2006 | "header for frame index %d, status %x\n", | |
2007 | __func__, | |
2008 | stp_req, | |
2009 | frame_index, | |
2010 | status); | |
d1c637c3 DW |
2011 | return status; |
2012 | } | |
2013 | ||
2014 | if (frame_header->fis_type != FIS_DATA) { | |
d9dcb4ba | 2015 | dev_err(&ihost->pdev->dev, |
d1c637c3 DW |
2016 | "%s: SCIC PIO Request 0x%p received frame %d " |
2017 | "with fis type 0x%02x when expecting a data " | |
e301370a EN |
2018 | "fis.\n", |
2019 | __func__, | |
2020 | stp_req, | |
2021 | frame_index, | |
d1c637c3 DW |
2022 | frame_header->fis_type); |
2023 | ||
34a99158 DW |
2024 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
2025 | ireq->sci_status = SCI_FAILURE_IO_REQUIRES_SCSI_ABORT; | |
5076a1a9 | 2026 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
d1c637c3 DW |
2027 | |
2028 | /* Frame is decoded return it to the controller */ | |
89a7301f | 2029 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
2030 | return status; |
2031 | } | |
2032 | ||
ba7cb223 | 2033 | if (stp_req->sgl.index < 0) { |
5076a1a9 | 2034 | ireq->saved_rx_frame_index = frame_index; |
ba7cb223 | 2035 | stp_req->pio_len = 0; |
d1c637c3 | 2036 | } else { |
89a7301f | 2037 | sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, |
d1c637c3 DW |
2038 | frame_index, |
2039 | (void **)&frame_buffer); | |
2040 | ||
89a7301f | 2041 | status = sci_stp_request_pio_data_in_copy_data(stp_req, |
d1c637c3 DW |
2042 | (u8 *)frame_buffer); |
2043 | ||
2044 | /* Frame is decoded return it to the controller */ | |
89a7301f | 2045 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
2046 | } |
2047 | ||
2048 | /* Check for the end of the transfer, are there more | |
2049 | * bytes remaining for this data transfer | |
2050 | */ | |
ba7cb223 | 2051 | if (status != SCI_SUCCESS || stp_req->pio_len != 0) |
d1c637c3 DW |
2052 | return status; |
2053 | ||
ba7cb223 | 2054 | if ((stp_req->status & ATA_BUSY) == 0) { |
34a99158 DW |
2055 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
2056 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
5076a1a9 | 2057 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); |
d1c637c3 | 2058 | } else { |
5076a1a9 | 2059 | sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); |
d1c637c3 DW |
2060 | } |
2061 | return status; | |
2062 | } | |
e301370a | 2063 | |
b50102d3 DW |
2064 | case SCI_REQ_ATAPI_WAIT_PIO_SETUP: { |
2065 | struct sas_task *task = isci_request_access_task(ireq); | |
2066 | ||
2067 | sci_controller_release_frame(ihost, frame_index); | |
2068 | ireq->target_device->working_request = ireq; | |
2069 | if (task->data_dir == DMA_NONE) { | |
2070 | sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_TC_COMP); | |
2071 | scu_atapi_reconstruct_raw_frame_task_context(ireq); | |
2072 | } else { | |
2073 | sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H); | |
2074 | scu_atapi_construct_task_context(ireq); | |
2075 | } | |
2076 | ||
2077 | sci_controller_continue_io(ireq); | |
2078 | return SCI_SUCCESS; | |
2079 | } | |
2080 | case SCI_REQ_ATAPI_WAIT_D2H: | |
2081 | return atapi_d2h_reg_frame_handler(ireq, frame_index); | |
e301370a EN |
2082 | case SCI_REQ_ABORTING: |
2083 | /* | |
2084 | * TODO: Is it even possible to get an unsolicited frame in the | |
d1c637c3 DW |
2085 | * aborting state? |
2086 | */ | |
89a7301f | 2087 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 | 2088 | return SCI_SUCCESS; |
e301370a | 2089 | |
d1c637c3 | 2090 | default: |
d9dcb4ba | 2091 | dev_warn(&ihost->pdev->dev, |
e301370a EN |
2092 | "%s: SCIC IO Request given unexpected frame %x while " |
2093 | "in state %d\n", | |
2094 | __func__, | |
2095 | frame_index, | |
2096 | state); | |
d1c637c3 | 2097 | |
89a7301f | 2098 | sci_controller_release_frame(ihost, frame_index); |
d1c637c3 DW |
2099 | return SCI_FAILURE_INVALID_STATE; |
2100 | } | |
2101 | } | |
2102 | ||
5076a1a9 | 2103 | static enum sci_status stp_request_udma_await_tc_event(struct isci_request *ireq, |
a7e255a3 | 2104 | u32 completion_code) |
5dec6f4e DW |
2105 | { |
2106 | enum sci_status status = SCI_SUCCESS; | |
2107 | ||
2108 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
2109 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
34a99158 DW |
2110 | ireq->scu_status = SCU_TASK_DONE_GOOD; |
2111 | ireq->sci_status = SCI_SUCCESS; | |
2112 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
5dec6f4e DW |
2113 | break; |
2114 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS): | |
2115 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR): | |
a7e255a3 DW |
2116 | /* We must check ther response buffer to see if the D2H |
2117 | * Register FIS was received before we got the TC | |
2118 | * completion. | |
2119 | */ | |
5076a1a9 | 2120 | if (ireq->stp.rsp.fis_type == FIS_REGD2H) { |
87805162 JS |
2121 | sci_remote_device_suspend(ireq->target_device, |
2122 | SCI_SW_SUSPEND_NORMAL); | |
2123 | ||
34a99158 DW |
2124 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; |
2125 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
2126 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
5dec6f4e | 2127 | } else { |
a7e255a3 DW |
2128 | /* If we have an error completion status for the |
2129 | * TC then we can expect a D2H register FIS from | |
2130 | * the device so we must change state to wait | |
2131 | * for it | |
2132 | */ | |
5076a1a9 | 2133 | sci_change_state(&ireq->sm, SCI_REQ_STP_UDMA_WAIT_D2H); |
5dec6f4e DW |
2134 | } |
2135 | break; | |
2136 | ||
a7e255a3 DW |
2137 | /* TODO Check to see if any of these completion status need to |
2138 | * wait for the device to host register fis. | |
2139 | */ | |
2140 | /* TODO We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR | |
2141 | * - this comes only for B0 | |
2142 | */ | |
5dec6f4e DW |
2143 | default: |
2144 | /* All other completion status cause the IO to be complete. */ | |
34a99158 DW |
2145 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); |
2146 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
2147 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
5dec6f4e DW |
2148 | break; |
2149 | } | |
2150 | ||
2151 | return status; | |
2152 | } | |
2153 | ||
b50102d3 DW |
2154 | static enum sci_status atapi_raw_completion(struct isci_request *ireq, u32 completion_code, |
2155 | enum sci_base_request_states next) | |
2156 | { | |
2157 | enum sci_status status = SCI_SUCCESS; | |
2158 | ||
2159 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
2160 | case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD): | |
2161 | ireq->scu_status = SCU_TASK_DONE_GOOD; | |
2162 | ireq->sci_status = SCI_SUCCESS; | |
2163 | sci_change_state(&ireq->sm, next); | |
2164 | break; | |
2165 | default: | |
2166 | /* All other completion status cause the IO to be complete. | |
2167 | * If a NAK was received, then it is up to the user to retry | |
2168 | * the request. | |
2169 | */ | |
2170 | ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); | |
2171 | ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; | |
2172 | ||
2173 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
2174 | break; | |
2175 | } | |
2176 | ||
2177 | return status; | |
2178 | } | |
2179 | ||
2180 | static enum sci_status atapi_data_tc_completion_handler(struct isci_request *ireq, | |
2181 | u32 completion_code) | |
2182 | { | |
2183 | struct isci_remote_device *idev = ireq->target_device; | |
2184 | struct dev_to_host_fis *d2h = &ireq->stp.rsp; | |
2185 | enum sci_status status = SCI_SUCCESS; | |
2186 | ||
2187 | switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) { | |
2188 | case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT): | |
2189 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
2190 | break; | |
2191 | ||
2192 | case (SCU_TASK_DONE_UNEXP_FIS << SCU_COMPLETION_TL_STATUS_SHIFT): { | |
2193 | u16 len = sci_req_tx_bytes(ireq); | |
2194 | ||
2195 | /* likely non-error data underrrun, workaround missing | |
2196 | * d2h frame from the controller | |
2197 | */ | |
2198 | if (d2h->fis_type != FIS_REGD2H) { | |
2199 | d2h->fis_type = FIS_REGD2H; | |
2200 | d2h->flags = (1 << 6); | |
2201 | d2h->status = 0x50; | |
2202 | d2h->error = 0; | |
2203 | d2h->lbal = 0; | |
2204 | d2h->byte_count_low = len & 0xff; | |
2205 | d2h->byte_count_high = len >> 8; | |
2206 | d2h->device = 0xa0; | |
2207 | d2h->lbal_exp = 0; | |
2208 | d2h->lbam_exp = 0; | |
2209 | d2h->lbah_exp = 0; | |
2210 | d2h->_r_a = 0; | |
2211 | d2h->sector_count = 0x3; | |
2212 | d2h->sector_count_exp = 0; | |
2213 | d2h->_r_b = 0; | |
2214 | d2h->_r_c = 0; | |
2215 | d2h->_r_d = 0; | |
2216 | } | |
2217 | ||
2218 | ireq->scu_status = SCU_TASK_DONE_GOOD; | |
2219 | ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY; | |
2220 | status = ireq->sci_status; | |
2221 | ||
2222 | /* the hw will have suspended the rnc, so complete the | |
2223 | * request upon pending resume | |
2224 | */ | |
2225 | sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); | |
2226 | break; | |
2227 | } | |
2228 | case (SCU_TASK_DONE_EXCESS_DATA << SCU_COMPLETION_TL_STATUS_SHIFT): | |
2229 | /* In this case, there is no UF coming after. | |
2230 | * compelte the IO now. | |
2231 | */ | |
2232 | ireq->scu_status = SCU_TASK_DONE_GOOD; | |
2233 | ireq->sci_status = SCI_SUCCESS; | |
2234 | sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); | |
2235 | break; | |
2236 | ||
2237 | default: | |
2238 | if (d2h->fis_type == FIS_REGD2H) { | |
2239 | /* UF received change the device state to ATAPI_ERROR */ | |
2240 | status = ireq->sci_status; | |
2241 | sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); | |
2242 | } else { | |
2243 | /* If receiving any non-sucess TC status, no UF | |
2244 | * received yet, then an UF for the status fis | |
2245 | * is coming after (XXX: suspect this is | |
2246 | * actually a protocol error or a bug like the | |
2247 | * DONE_UNEXP_FIS case) | |
2248 | */ | |
2249 | ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; | |
2250 | ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; | |
2251 | ||
2252 | sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H); | |
2253 | } | |
2254 | break; | |
2255 | } | |
2256 | ||
2257 | return status; | |
2258 | } | |
2259 | ||
ac78ed0f JS |
2260 | static int sci_request_smp_completion_status_is_tx_suspend( |
2261 | unsigned int completion_status) | |
2262 | { | |
2263 | switch (completion_status) { | |
2264 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | |
2265 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | |
2266 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | |
2267 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | |
2268 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | |
2269 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | |
2270 | return 1; | |
2271 | } | |
2272 | return 0; | |
2273 | } | |
2274 | ||
2275 | static int sci_request_smp_completion_status_is_tx_rx_suspend( | |
2276 | unsigned int completion_status) | |
2277 | { | |
2278 | return 0; /* There are no Tx/Rx SMP suspend conditions. */ | |
2279 | } | |
2280 | ||
2281 | static int sci_request_ssp_completion_status_is_tx_suspend( | |
2282 | unsigned int completion_status) | |
2283 | { | |
2284 | switch (completion_status) { | |
2285 | case SCU_TASK_DONE_TX_RAW_CMD_ERR: | |
2286 | case SCU_TASK_DONE_LF_ERR: | |
2287 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | |
2288 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | |
2289 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | |
2290 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | |
2291 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | |
2292 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | |
2293 | case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | |
2294 | case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | |
2295 | case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | |
2296 | return 1; | |
2297 | } | |
2298 | return 0; | |
2299 | } | |
2300 | ||
2301 | static int sci_request_ssp_completion_status_is_tx_rx_suspend( | |
2302 | unsigned int completion_status) | |
2303 | { | |
2304 | return 0; /* There are no Tx/Rx SSP suspend conditions. */ | |
2305 | } | |
2306 | ||
2307 | static int sci_request_stpsata_completion_status_is_tx_suspend( | |
2308 | unsigned int completion_status) | |
2309 | { | |
2310 | switch (completion_status) { | |
2311 | case SCU_TASK_DONE_TX_RAW_CMD_ERR: | |
2312 | case SCU_TASK_DONE_LL_R_ERR: | |
2313 | case SCU_TASK_DONE_LL_PERR: | |
2314 | case SCU_TASK_DONE_REG_ERR: | |
2315 | case SCU_TASK_DONE_SDB_ERR: | |
2316 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | |
2317 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: | |
2318 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: | |
2319 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: | |
2320 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: | |
2321 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: | |
2322 | case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: | |
2323 | case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: | |
2324 | case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: | |
2325 | return 1; | |
2326 | } | |
2327 | return 0; | |
2328 | } | |
2329 | ||
2330 | ||
2331 | static int sci_request_stpsata_completion_status_is_tx_rx_suspend( | |
2332 | unsigned int completion_status) | |
2333 | { | |
2334 | switch (completion_status) { | |
2335 | case SCU_TASK_DONE_LF_ERR: | |
2336 | case SCU_TASK_DONE_LL_SY_TERM: | |
2337 | case SCU_TASK_DONE_LL_LF_TERM: | |
2338 | case SCU_TASK_DONE_BREAK_RCVD: | |
2339 | case SCU_TASK_DONE_INV_FIS_LEN: | |
2340 | case SCU_TASK_DONE_UNEXP_FIS: | |
2341 | case SCU_TASK_DONE_UNEXP_SDBFIS: | |
2342 | case SCU_TASK_DONE_MAX_PLD_ERR: | |
2343 | return 1; | |
2344 | } | |
2345 | return 0; | |
2346 | } | |
2347 | ||
2348 | static void sci_request_handle_suspending_completions( | |
2349 | struct isci_request *ireq, | |
2350 | u32 completion_code) | |
2351 | { | |
2352 | int is_tx = 0; | |
2353 | int is_tx_rx = 0; | |
2354 | ||
2355 | switch (ireq->protocol) { | |
2356 | case SAS_PROTOCOL_SMP: | |
2357 | is_tx = sci_request_smp_completion_status_is_tx_suspend( | |
2358 | completion_code); | |
2359 | is_tx_rx = sci_request_smp_completion_status_is_tx_rx_suspend( | |
2360 | completion_code); | |
2361 | break; | |
2362 | case SAS_PROTOCOL_SSP: | |
2363 | is_tx = sci_request_ssp_completion_status_is_tx_suspend( | |
2364 | completion_code); | |
2365 | is_tx_rx = sci_request_ssp_completion_status_is_tx_rx_suspend( | |
2366 | completion_code); | |
2367 | break; | |
2368 | case SAS_PROTOCOL_STP: | |
2369 | is_tx = sci_request_stpsata_completion_status_is_tx_suspend( | |
2370 | completion_code); | |
2371 | is_tx_rx = | |
2372 | sci_request_stpsata_completion_status_is_tx_rx_suspend( | |
2373 | completion_code); | |
2374 | break; | |
2375 | default: | |
2376 | dev_warn(&ireq->isci_host->pdev->dev, | |
2377 | "%s: request %p has no valid protocol\n", | |
2378 | __func__, ireq); | |
2379 | break; | |
2380 | } | |
2381 | if (is_tx || is_tx_rx) { | |
2382 | BUG_ON(is_tx && is_tx_rx); | |
2383 | ||
2384 | sci_remote_node_context_suspend( | |
2385 | &ireq->target_device->rnc, | |
c94fc1ad | 2386 | SCI_HW_SUSPEND, |
ac78ed0f | 2387 | (is_tx_rx) ? SCU_EVENT_TL_RNC_SUSPEND_TX_RX |
447bfbce | 2388 | : SCU_EVENT_TL_RNC_SUSPEND_TX); |
ac78ed0f JS |
2389 | } |
2390 | } | |
2391 | ||
a7e255a3 | 2392 | enum sci_status |
89a7301f | 2393 | sci_io_request_tc_completion(struct isci_request *ireq, |
ac78ed0f | 2394 | u32 completion_code) |
a7e255a3 DW |
2395 | { |
2396 | enum sci_base_request_states state; | |
d9dcb4ba | 2397 | struct isci_host *ihost = ireq->owning_controller; |
a7e255a3 | 2398 | |
5076a1a9 | 2399 | state = ireq->sm.current_state_id; |
a7e255a3 | 2400 | |
ac78ed0f JS |
2401 | /* Decode those completions that signal upcoming suspension events. */ |
2402 | sci_request_handle_suspending_completions( | |
2403 | ireq, SCU_GET_COMPLETION_TL_STATUS(completion_code)); | |
2404 | ||
a7e255a3 | 2405 | switch (state) { |
e301370a | 2406 | case SCI_REQ_STARTED: |
5076a1a9 | 2407 | return request_started_state_tc_event(ireq, completion_code); |
e301370a EN |
2408 | |
2409 | case SCI_REQ_TASK_WAIT_TC_COMP: | |
5076a1a9 | 2410 | return ssp_task_request_await_tc_event(ireq, |
e301370a EN |
2411 | completion_code); |
2412 | ||
2413 | case SCI_REQ_SMP_WAIT_RESP: | |
5076a1a9 | 2414 | return smp_request_await_response_tc_event(ireq, |
e301370a EN |
2415 | completion_code); |
2416 | ||
2417 | case SCI_REQ_SMP_WAIT_TC_COMP: | |
5076a1a9 | 2418 | return smp_request_await_tc_event(ireq, completion_code); |
e301370a EN |
2419 | |
2420 | case SCI_REQ_STP_UDMA_WAIT_TC_COMP: | |
5076a1a9 | 2421 | return stp_request_udma_await_tc_event(ireq, |
e301370a EN |
2422 | completion_code); |
2423 | ||
2424 | case SCI_REQ_STP_NON_DATA_WAIT_H2D: | |
5076a1a9 | 2425 | return stp_request_non_data_await_h2d_tc_event(ireq, |
e301370a EN |
2426 | completion_code); |
2427 | ||
2428 | case SCI_REQ_STP_PIO_WAIT_H2D: | |
5076a1a9 | 2429 | return stp_request_pio_await_h2d_completion_tc_event(ireq, |
e301370a EN |
2430 | completion_code); |
2431 | ||
2432 | case SCI_REQ_STP_PIO_DATA_OUT: | |
5076a1a9 | 2433 | return pio_data_out_tx_done_tc_event(ireq, completion_code); |
e301370a | 2434 | |
e301370a | 2435 | case SCI_REQ_ABORTING: |
5076a1a9 | 2436 | return request_aborting_state_tc_event(ireq, |
e301370a EN |
2437 | completion_code); |
2438 | ||
b50102d3 DW |
2439 | case SCI_REQ_ATAPI_WAIT_H2D: |
2440 | return atapi_raw_completion(ireq, completion_code, | |
2441 | SCI_REQ_ATAPI_WAIT_PIO_SETUP); | |
2442 | ||
2443 | case SCI_REQ_ATAPI_WAIT_TC_COMP: | |
2444 | return atapi_raw_completion(ireq, completion_code, | |
2445 | SCI_REQ_ATAPI_WAIT_D2H); | |
2446 | ||
2447 | case SCI_REQ_ATAPI_WAIT_D2H: | |
2448 | return atapi_data_tc_completion_handler(ireq, completion_code); | |
2449 | ||
e301370a | 2450 | default: |
d7a0ccdd DW |
2451 | dev_warn(&ihost->pdev->dev, "%s: %x in wrong state %s\n", |
2452 | __func__, completion_code, req_state_name(state)); | |
e301370a | 2453 | return SCI_FAILURE_INVALID_STATE; |
a7e255a3 DW |
2454 | } |
2455 | } | |
2456 | ||
6f231dda | 2457 | /** |
f1f52e75 DW |
2458 | * isci_request_process_response_iu() - This function sets the status and |
2459 | * response iu, in the task struct, from the request object for the upper | |
2460 | * layer driver. | |
2461 | * @sas_task: This parameter is the task struct from the upper layer driver. | |
2462 | * @resp_iu: This parameter points to the response iu of the completed request. | |
2463 | * @dev: This parameter specifies the linux device struct. | |
6f231dda DW |
2464 | * |
2465 | * none. | |
2466 | */ | |
f1f52e75 DW |
2467 | static void isci_request_process_response_iu( |
2468 | struct sas_task *task, | |
2469 | struct ssp_response_iu *resp_iu, | |
2470 | struct device *dev) | |
6f231dda | 2471 | { |
f1f52e75 DW |
2472 | dev_dbg(dev, |
2473 | "%s: resp_iu = %p " | |
2474 | "resp_iu->status = 0x%x,\nresp_iu->datapres = %d " | |
2475 | "resp_iu->response_data_len = %x, " | |
2476 | "resp_iu->sense_data_len = %x\nrepsonse data: ", | |
6f231dda | 2477 | __func__, |
f1f52e75 DW |
2478 | resp_iu, |
2479 | resp_iu->status, | |
2480 | resp_iu->datapres, | |
2481 | resp_iu->response_data_len, | |
2482 | resp_iu->sense_data_len); | |
6f231dda | 2483 | |
f1f52e75 | 2484 | task->task_status.stat = resp_iu->status; |
6f231dda | 2485 | |
f1f52e75 DW |
2486 | /* libsas updates the task status fields based on the response iu. */ |
2487 | sas_ssp_task_response(dev, task, resp_iu); | |
2488 | } | |
6f231dda | 2489 | |
f1f52e75 DW |
2490 | /** |
2491 | * isci_request_set_open_reject_status() - This function prepares the I/O | |
2492 | * completion for OPEN_REJECT conditions. | |
2493 | * @request: This parameter is the completed isci_request object. | |
2494 | * @response_ptr: This parameter specifies the service response for the I/O. | |
2495 | * @status_ptr: This parameter specifies the exec status for the I/O. | |
f1f52e75 DW |
2496 | * @open_rej_reason: This parameter specifies the encoded reason for the |
2497 | * abandon-class reject. | |
2498 | * | |
2499 | * none. | |
2500 | */ | |
2501 | static void isci_request_set_open_reject_status( | |
2502 | struct isci_request *request, | |
2503 | struct sas_task *task, | |
2504 | enum service_response *response_ptr, | |
2505 | enum exec_status *status_ptr, | |
f1f52e75 DW |
2506 | enum sas_open_rej_reason open_rej_reason) |
2507 | { | |
2508 | /* Task in the target is done. */ | |
38d8879b | 2509 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
f1f52e75 DW |
2510 | *response_ptr = SAS_TASK_UNDELIVERED; |
2511 | *status_ptr = SAS_OPEN_REJECT; | |
f1f52e75 DW |
2512 | task->task_status.open_rej_reason = open_rej_reason; |
2513 | } | |
6f231dda | 2514 | |
f1f52e75 DW |
2515 | /** |
2516 | * isci_request_handle_controller_specific_errors() - This function decodes | |
2517 | * controller-specific I/O completion error conditions. | |
2518 | * @request: This parameter is the completed isci_request object. | |
2519 | * @response_ptr: This parameter specifies the service response for the I/O. | |
2520 | * @status_ptr: This parameter specifies the exec status for the I/O. | |
f1f52e75 DW |
2521 | * |
2522 | * none. | |
2523 | */ | |
2524 | static void isci_request_handle_controller_specific_errors( | |
209fae14 | 2525 | struct isci_remote_device *idev, |
f1f52e75 DW |
2526 | struct isci_request *request, |
2527 | struct sas_task *task, | |
2528 | enum service_response *response_ptr, | |
14aaa9f0 | 2529 | enum exec_status *status_ptr) |
f1f52e75 DW |
2530 | { |
2531 | unsigned int cstatus; | |
6f231dda | 2532 | |
5076a1a9 | 2533 | cstatus = request->scu_status; |
a5fde225 | 2534 | |
f1f52e75 DW |
2535 | dev_dbg(&request->isci_host->pdev->dev, |
2536 | "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR " | |
2537 | "- controller status = 0x%x\n", | |
2538 | __func__, request, cstatus); | |
6f231dda | 2539 | |
f1f52e75 DW |
2540 | /* Decode the controller-specific errors; most |
2541 | * important is to recognize those conditions in which | |
2542 | * the target may still have a task outstanding that | |
2543 | * must be aborted. | |
2544 | * | |
2545 | * Note that there are SCU completion codes being | |
2546 | * named in the decode below for which SCIC has already | |
2547 | * done work to handle them in a way other than as | |
2548 | * a controller-specific completion code; these are left | |
2549 | * in the decode below for completeness sake. | |
2550 | */ | |
2551 | switch (cstatus) { | |
2552 | case SCU_TASK_DONE_DMASETUP_DIRERR: | |
2553 | /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */ | |
2554 | case SCU_TASK_DONE_XFERCNT_ERR: | |
2555 | /* Also SCU_TASK_DONE_SMP_UFI_ERR: */ | |
2556 | if (task->task_proto == SAS_PROTOCOL_SMP) { | |
2557 | /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */ | |
2558 | *response_ptr = SAS_TASK_COMPLETE; | |
6f231dda | 2559 | |
f1f52e75 DW |
2560 | /* See if the device has been/is being stopped. Note |
2561 | * that we ignore the quiesce state, since we are | |
6f231dda DW |
2562 | * concerned about the actual device state. |
2563 | */ | |
209fae14 | 2564 | if (!idev) |
f1f52e75 DW |
2565 | *status_ptr = SAS_DEVICE_UNKNOWN; |
2566 | else | |
2567 | *status_ptr = SAS_ABORTED_TASK; | |
6f231dda | 2568 | |
38d8879b | 2569 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
f1f52e75 DW |
2570 | } else { |
2571 | /* Task in the target is not done. */ | |
2572 | *response_ptr = SAS_TASK_UNDELIVERED; | |
a5fde225 | 2573 | |
209fae14 | 2574 | if (!idev) |
f1f52e75 DW |
2575 | *status_ptr = SAS_DEVICE_UNKNOWN; |
2576 | else | |
2577 | *status_ptr = SAM_STAT_TASK_ABORTED; | |
6f231dda | 2578 | |
38d8879b | 2579 | clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
f1f52e75 DW |
2580 | } |
2581 | ||
2582 | break; | |
2583 | ||
2584 | case SCU_TASK_DONE_CRC_ERR: | |
2585 | case SCU_TASK_DONE_NAK_CMD_ERR: | |
2586 | case SCU_TASK_DONE_EXCESS_DATA: | |
2587 | case SCU_TASK_DONE_UNEXP_FIS: | |
2588 | /* Also SCU_TASK_DONE_UNEXP_RESP: */ | |
2589 | case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */ | |
2590 | case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */ | |
2591 | case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */ | |
2592 | /* These are conditions in which the target | |
2593 | * has completed the task, so that no cleanup | |
2594 | * is necessary. | |
6f231dda | 2595 | */ |
f1f52e75 | 2596 | *response_ptr = SAS_TASK_COMPLETE; |
6f231dda DW |
2597 | |
2598 | /* See if the device has been/is being stopped. Note | |
2599 | * that we ignore the quiesce state, since we are | |
2600 | * concerned about the actual device state. | |
2601 | */ | |
209fae14 | 2602 | if (!idev) |
f1f52e75 | 2603 | *status_ptr = SAS_DEVICE_UNKNOWN; |
6f231dda | 2604 | else |
f1f52e75 | 2605 | *status_ptr = SAS_ABORTED_TASK; |
6f231dda | 2606 | |
38d8879b | 2607 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
6f231dda DW |
2608 | break; |
2609 | ||
6f231dda | 2610 | |
f1f52e75 DW |
2611 | /* Note that the only open reject completion codes seen here will be |
2612 | * abandon-class codes; all others are automatically retried in the SCU. | |
2613 | */ | |
2614 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: | |
a5fde225 | 2615 | |
f1f52e75 DW |
2616 | isci_request_set_open_reject_status( |
2617 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2618 | SAS_OREJ_WRONG_DEST); |
f1f52e75 | 2619 | break; |
a5fde225 | 2620 | |
f1f52e75 | 2621 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: |
6f231dda | 2622 | |
f1f52e75 DW |
2623 | /* Note - the return of AB0 will change when |
2624 | * libsas implements detection of zone violations. | |
2625 | */ | |
2626 | isci_request_set_open_reject_status( | |
2627 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2628 | SAS_OREJ_RESV_AB0); |
f1f52e75 | 2629 | break; |
6f231dda | 2630 | |
f1f52e75 | 2631 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: |
6f231dda | 2632 | |
f1f52e75 DW |
2633 | isci_request_set_open_reject_status( |
2634 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2635 | SAS_OREJ_RESV_AB1); |
f1f52e75 | 2636 | break; |
6f231dda | 2637 | |
f1f52e75 | 2638 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: |
6f231dda | 2639 | |
f1f52e75 DW |
2640 | isci_request_set_open_reject_status( |
2641 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2642 | SAS_OREJ_RESV_AB2); |
f1f52e75 | 2643 | break; |
6f231dda | 2644 | |
f1f52e75 | 2645 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: |
6f231dda | 2646 | |
f1f52e75 DW |
2647 | isci_request_set_open_reject_status( |
2648 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2649 | SAS_OREJ_RESV_AB3); |
f1f52e75 | 2650 | break; |
6f231dda | 2651 | |
f1f52e75 | 2652 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: |
6f231dda | 2653 | |
f1f52e75 DW |
2654 | isci_request_set_open_reject_status( |
2655 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2656 | SAS_OREJ_BAD_DEST); |
f1f52e75 | 2657 | break; |
6f231dda | 2658 | |
f1f52e75 | 2659 | case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: |
6f231dda | 2660 | |
f1f52e75 DW |
2661 | isci_request_set_open_reject_status( |
2662 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2663 | SAS_OREJ_STP_NORES); |
f1f52e75 | 2664 | break; |
6f231dda | 2665 | |
f1f52e75 | 2666 | case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: |
6f231dda | 2667 | |
f1f52e75 DW |
2668 | isci_request_set_open_reject_status( |
2669 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2670 | SAS_OREJ_EPROTO); |
f1f52e75 | 2671 | break; |
6f231dda | 2672 | |
f1f52e75 | 2673 | case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: |
6f231dda | 2674 | |
f1f52e75 DW |
2675 | isci_request_set_open_reject_status( |
2676 | request, task, response_ptr, status_ptr, | |
14aaa9f0 | 2677 | SAS_OREJ_CONN_RATE); |
f1f52e75 | 2678 | break; |
6f231dda | 2679 | |
f1f52e75 DW |
2680 | case SCU_TASK_DONE_LL_R_ERR: |
2681 | /* Also SCU_TASK_DONE_ACK_NAK_TO: */ | |
2682 | case SCU_TASK_DONE_LL_PERR: | |
2683 | case SCU_TASK_DONE_LL_SY_TERM: | |
2684 | /* Also SCU_TASK_DONE_NAK_ERR:*/ | |
2685 | case SCU_TASK_DONE_LL_LF_TERM: | |
2686 | /* Also SCU_TASK_DONE_DATA_LEN_ERR: */ | |
2687 | case SCU_TASK_DONE_LL_ABORT_ERR: | |
2688 | case SCU_TASK_DONE_SEQ_INV_TYPE: | |
2689 | /* Also SCU_TASK_DONE_UNEXP_XR: */ | |
2690 | case SCU_TASK_DONE_XR_IU_LEN_ERR: | |
2691 | case SCU_TASK_DONE_INV_FIS_LEN: | |
2692 | /* Also SCU_TASK_DONE_XR_WD_LEN: */ | |
2693 | case SCU_TASK_DONE_SDMA_ERR: | |
2694 | case SCU_TASK_DONE_OFFSET_ERR: | |
2695 | case SCU_TASK_DONE_MAX_PLD_ERR: | |
2696 | case SCU_TASK_DONE_LF_ERR: | |
2697 | case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */ | |
2698 | case SCU_TASK_DONE_SMP_LL_RX_ERR: | |
2699 | case SCU_TASK_DONE_UNEXP_DATA: | |
2700 | case SCU_TASK_DONE_UNEXP_SDBFIS: | |
2701 | case SCU_TASK_DONE_REG_ERR: | |
2702 | case SCU_TASK_DONE_SDB_ERR: | |
2703 | case SCU_TASK_DONE_TASK_ABORT: | |
2704 | default: | |
2705 | /* Task in the target is not done. */ | |
2706 | *response_ptr = SAS_TASK_UNDELIVERED; | |
2707 | *status_ptr = SAM_STAT_TASK_ABORTED; | |
6f231dda | 2708 | |
14aaa9f0 | 2709 | if (task->task_proto == SAS_PROTOCOL_SMP) |
38d8879b | 2710 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
14aaa9f0 | 2711 | else |
38d8879b | 2712 | clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
f1f52e75 DW |
2713 | break; |
2714 | } | |
2715 | } | |
2716 | ||
1a878284 | 2717 | static void isci_process_stp_response(struct sas_task *task, struct dev_to_host_fis *fis) |
16ba7709 | 2718 | { |
16ba7709 DW |
2719 | struct task_status_struct *ts = &task->task_status; |
2720 | struct ata_task_resp *resp = (void *)&ts->buf[0]; | |
2721 | ||
1a878284 DW |
2722 | resp->frame_len = sizeof(*fis); |
2723 | memcpy(resp->ending_fis, fis, sizeof(*fis)); | |
16ba7709 DW |
2724 | ts->buf_valid_size = sizeof(*resp); |
2725 | ||
1a878284 | 2726 | /* If the device fault bit is set in the status register, then |
16ba7709 DW |
2727 | * set the sense data and return. |
2728 | */ | |
1a878284 | 2729 | if (fis->status & ATA_DF) |
16ba7709 | 2730 | ts->stat = SAS_PROTO_RESPONSE; |
b50102d3 DW |
2731 | else if (fis->status & ATA_ERR) |
2732 | ts->stat = SAM_STAT_CHECK_CONDITION; | |
16ba7709 DW |
2733 | else |
2734 | ts->stat = SAM_STAT_GOOD; | |
2735 | ||
2736 | ts->resp = SAS_TASK_COMPLETE; | |
2737 | } | |
2738 | ||
d9dcb4ba | 2739 | static void isci_request_io_request_complete(struct isci_host *ihost, |
f1f52e75 DW |
2740 | struct isci_request *request, |
2741 | enum sci_io_status completion_status) | |
2742 | { | |
2743 | struct sas_task *task = isci_request_access_task(request); | |
2744 | struct ssp_response_iu *resp_iu; | |
f1f52e75 | 2745 | unsigned long task_flags; |
0e2e2799 JS |
2746 | struct isci_remote_device *idev = request->target_device; |
2747 | enum service_response response = SAS_TASK_UNDELIVERED; | |
2748 | enum exec_status status = SAS_ABORTED_TASK; | |
f1f52e75 | 2749 | |
d9dcb4ba | 2750 | dev_dbg(&ihost->pdev->dev, |
f8381807 | 2751 | "%s: request = %p, task = %p, " |
f1f52e75 | 2752 | "task->data_dir = %d completion_status = 0x%x\n", |
f8381807 | 2753 | __func__, request, task, task->data_dir, completion_status); |
f1f52e75 | 2754 | |
14aaa9f0 | 2755 | /* The request is done from an SCU HW perspective. */ |
f1f52e75 | 2756 | |
14aaa9f0 JS |
2757 | /* This is an active request being completed from the core. */ |
2758 | switch (completion_status) { | |
f1f52e75 | 2759 | |
14aaa9f0 JS |
2760 | case SCI_IO_FAILURE_RESPONSE_VALID: |
2761 | dev_dbg(&ihost->pdev->dev, | |
2762 | "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", | |
2763 | __func__, request, task); | |
f1f52e75 | 2764 | |
14aaa9f0 JS |
2765 | if (sas_protocol_ata(task->task_proto)) { |
2766 | isci_process_stp_response(task, &request->stp.rsp); | |
2767 | } else if (SAS_PROTOCOL_SSP == task->task_proto) { | |
f1f52e75 | 2768 | |
14aaa9f0 JS |
2769 | /* crack the iu response buffer. */ |
2770 | resp_iu = &request->ssp.rsp; | |
2771 | isci_request_process_response_iu(task, resp_iu, | |
2772 | &ihost->pdev->dev); | |
f1f52e75 | 2773 | |
14aaa9f0 | 2774 | } else if (SAS_PROTOCOL_SMP == task->task_proto) { |
f1f52e75 | 2775 | |
14aaa9f0 JS |
2776 | dev_err(&ihost->pdev->dev, |
2777 | "%s: SCI_IO_FAILURE_RESPONSE_VALID: " | |
2778 | "SAS_PROTOCOL_SMP protocol\n", | |
2779 | __func__); | |
f1f52e75 | 2780 | |
14aaa9f0 JS |
2781 | } else |
2782 | dev_err(&ihost->pdev->dev, | |
2783 | "%s: unknown protocol\n", __func__); | |
f1f52e75 | 2784 | |
14aaa9f0 JS |
2785 | /* use the task status set in the task struct by the |
2786 | * isci_request_process_response_iu call. | |
2787 | */ | |
2788 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | |
2789 | response = task->task_status.resp; | |
2790 | status = task->task_status.stat; | |
f1f52e75 DW |
2791 | break; |
2792 | ||
14aaa9f0 JS |
2793 | case SCI_IO_SUCCESS: |
2794 | case SCI_IO_SUCCESS_IO_DONE_EARLY: | |
f1f52e75 | 2795 | |
14aaa9f0 JS |
2796 | response = SAS_TASK_COMPLETE; |
2797 | status = SAM_STAT_GOOD; | |
38d8879b | 2798 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
f1f52e75 | 2799 | |
14aaa9f0 | 2800 | if (completion_status == SCI_IO_SUCCESS_IO_DONE_EARLY) { |
f1f52e75 | 2801 | |
14aaa9f0 JS |
2802 | /* This was an SSP / STP / SATA transfer. |
2803 | * There is a possibility that less data than | |
2804 | * the maximum was transferred. | |
2805 | */ | |
2806 | u32 transferred_length = sci_req_tx_bytes(request); | |
f1f52e75 | 2807 | |
14aaa9f0 JS |
2808 | task->task_status.residual |
2809 | = task->total_xfer_len - transferred_length; | |
f1f52e75 | 2810 | |
14aaa9f0 JS |
2811 | /* If there were residual bytes, call this an |
2812 | * underrun. | |
2813 | */ | |
2814 | if (task->task_status.residual != 0) | |
2815 | status = SAS_DATA_UNDERRUN; | |
f1f52e75 | 2816 | |
d9dcb4ba | 2817 | dev_dbg(&ihost->pdev->dev, |
14aaa9f0 JS |
2818 | "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", |
2819 | __func__, status); | |
f1f52e75 | 2820 | |
14aaa9f0 JS |
2821 | } else |
2822 | dev_dbg(&ihost->pdev->dev, "%s: SCI_IO_SUCCESS\n", | |
2823 | __func__); | |
2824 | break; | |
f1f52e75 | 2825 | |
14aaa9f0 | 2826 | case SCI_IO_FAILURE_TERMINATED: |
f1f52e75 | 2827 | |
14aaa9f0 JS |
2828 | dev_dbg(&ihost->pdev->dev, |
2829 | "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", | |
2830 | __func__, request, task); | |
f1f52e75 | 2831 | |
14aaa9f0 | 2832 | /* The request was terminated explicitly. */ |
e3c84dfd | 2833 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
14aaa9f0 | 2834 | response = SAS_TASK_UNDELIVERED; |
f1f52e75 | 2835 | |
14aaa9f0 JS |
2836 | /* See if the device has been/is being stopped. Note |
2837 | * that we ignore the quiesce state, since we are | |
2838 | * concerned about the actual device state. | |
2839 | */ | |
2840 | if (!idev) | |
2841 | status = SAS_DEVICE_UNKNOWN; | |
2842 | else | |
2843 | status = SAS_ABORTED_TASK; | |
2844 | break; | |
f1f52e75 | 2845 | |
14aaa9f0 | 2846 | case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: |
f1f52e75 | 2847 | |
14aaa9f0 JS |
2848 | isci_request_handle_controller_specific_errors(idev, request, |
2849 | task, &response, | |
2850 | &status); | |
2851 | break; | |
f1f52e75 | 2852 | |
14aaa9f0 JS |
2853 | case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: |
2854 | /* This is a special case, in that the I/O completion | |
2855 | * is telling us that the device needs a reset. | |
2856 | * In order for the device reset condition to be | |
2857 | * noticed, the I/O has to be handled in the error | |
2858 | * handler. Set the reset flag and cause the | |
2859 | * SCSI error thread to be scheduled. | |
2860 | */ | |
2861 | spin_lock_irqsave(&task->task_state_lock, task_flags); | |
2862 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | |
2863 | spin_unlock_irqrestore(&task->task_state_lock, task_flags); | |
f1f52e75 | 2864 | |
14aaa9f0 JS |
2865 | /* Fail the I/O. */ |
2866 | response = SAS_TASK_UNDELIVERED; | |
2867 | status = SAM_STAT_TASK_ABORTED; | |
f1f52e75 | 2868 | |
14aaa9f0 JS |
2869 | clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
2870 | break; | |
f1f52e75 | 2871 | |
14aaa9f0 | 2872 | case SCI_FAILURE_RETRY_REQUIRED: |
f1f52e75 | 2873 | |
14aaa9f0 JS |
2874 | /* Fail the I/O so it can be retried. */ |
2875 | response = SAS_TASK_UNDELIVERED; | |
2876 | if (!idev) | |
2877 | status = SAS_DEVICE_UNKNOWN; | |
2878 | else | |
2879 | status = SAS_ABORTED_TASK; | |
f1f52e75 | 2880 | |
14aaa9f0 JS |
2881 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
2882 | break; | |
6f231dda | 2883 | |
f1f52e75 | 2884 | |
14aaa9f0 JS |
2885 | default: |
2886 | /* Catch any otherwise unhandled error codes here. */ | |
2887 | dev_dbg(&ihost->pdev->dev, | |
2888 | "%s: invalid completion code: 0x%x - " | |
2889 | "isci_request = %p\n", | |
2890 | __func__, completion_status, request); | |
f1f52e75 | 2891 | |
14aaa9f0 | 2892 | response = SAS_TASK_UNDELIVERED; |
cde76fbf | 2893 | |
14aaa9f0 JS |
2894 | /* See if the device has been/is being stopped. Note |
2895 | * that we ignore the quiesce state, since we are | |
2896 | * concerned about the actual device state. | |
2897 | */ | |
2898 | if (!idev) | |
2899 | status = SAS_DEVICE_UNKNOWN; | |
2900 | else | |
2901 | status = SAS_ABORTED_TASK; | |
cde76fbf | 2902 | |
14aaa9f0 | 2903 | if (SAS_PROTOCOL_SMP == task->task_proto) |
38d8879b | 2904 | set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); |
14aaa9f0 JS |
2905 | else |
2906 | clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); | |
f1f52e75 DW |
2907 | break; |
2908 | } | |
2909 | ||
ddcc7e34 DW |
2910 | switch (task->task_proto) { |
2911 | case SAS_PROTOCOL_SSP: | |
2912 | if (task->data_dir == DMA_NONE) | |
2913 | break; | |
2914 | if (task->num_scatter == 0) | |
2915 | /* 0 indicates a single dma address */ | |
d9dcb4ba | 2916 | dma_unmap_single(&ihost->pdev->dev, |
ddcc7e34 DW |
2917 | request->zero_scatter_daddr, |
2918 | task->total_xfer_len, task->data_dir); | |
2919 | else /* unmap the sgl dma addresses */ | |
d9dcb4ba | 2920 | dma_unmap_sg(&ihost->pdev->dev, task->scatter, |
ddcc7e34 DW |
2921 | request->num_sg_entries, task->data_dir); |
2922 | break; | |
e9bf7095 DW |
2923 | case SAS_PROTOCOL_SMP: { |
2924 | struct scatterlist *sg = &task->smp_task.smp_req; | |
2925 | struct smp_req *smp_req; | |
2926 | void *kaddr; | |
2927 | ||
d9dcb4ba | 2928 | dma_unmap_sg(&ihost->pdev->dev, sg, 1, DMA_TO_DEVICE); |
e9bf7095 DW |
2929 | |
2930 | /* need to swab it back in case the command buffer is re-used */ | |
77dfce07 | 2931 | kaddr = kmap_atomic(sg_page(sg)); |
e9bf7095 DW |
2932 | smp_req = kaddr + sg->offset; |
2933 | sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32)); | |
77dfce07 | 2934 | kunmap_atomic(kaddr); |
e9bf7095 DW |
2935 | break; |
2936 | } | |
ddcc7e34 DW |
2937 | default: |
2938 | break; | |
2939 | } | |
f1f52e75 | 2940 | |
14aaa9f0 JS |
2941 | spin_lock_irqsave(&task->task_state_lock, task_flags); |
2942 | ||
2943 | task->task_status.resp = response; | |
2944 | task->task_status.stat = status; | |
2945 | ||
2946 | if (test_bit(IREQ_COMPLETE_IN_TARGET, &request->flags)) { | |
2947 | /* Normal notification (task_done) */ | |
2948 | task->task_state_flags |= SAS_TASK_STATE_DONE; | |
2949 | task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | | |
2950 | SAS_TASK_STATE_PENDING); | |
2951 | } | |
2952 | spin_unlock_irqrestore(&task->task_state_lock, task_flags); | |
2953 | ||
f1f52e75 | 2954 | /* complete the io request to the core. */ |
89a7301f | 2955 | sci_controller_complete_io(ihost, request->target_device, request); |
209fae14 | 2956 | |
f1f52e75 DW |
2957 | /* set terminated handle so it cannot be completed or |
2958 | * terminated again, and to cause any calls into abort | |
2959 | * task to recognize the already completed case. | |
2960 | */ | |
38d8879b | 2961 | set_bit(IREQ_TERMINATED, &request->flags); |
f8381807 JS |
2962 | |
2963 | ireq_done(ihost, request, task); | |
f1f52e75 DW |
2964 | } |
2965 | ||
89a7301f | 2966 | static void sci_request_started_state_enter(struct sci_base_state_machine *sm) |
f1f52e75 | 2967 | { |
5076a1a9 | 2968 | struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); |
78a6f06e | 2969 | struct domain_device *dev = ireq->target_device->domain_dev; |
b50102d3 | 2970 | enum sci_base_request_states state; |
c72086e3 DW |
2971 | struct sas_task *task; |
2972 | ||
2973 | /* XXX as hch said always creating an internal sas_task for tmf | |
2974 | * requests would simplify the driver | |
2975 | */ | |
3b34c169 | 2976 | task = (test_bit(IREQ_TMF, &ireq->flags)) ? NULL : isci_request_access_task(ireq); |
f1f52e75 | 2977 | |
5dec6f4e DW |
2978 | /* all unaccelerated request types (non ssp or ncq) handled with |
2979 | * substates | |
f139303d | 2980 | */ |
c72086e3 | 2981 | if (!task && dev->dev_type == SAS_END_DEV) { |
b50102d3 | 2982 | state = SCI_REQ_TASK_WAIT_TC_COMP; |
c72086e3 | 2983 | } else if (task && task->task_proto == SAS_PROTOCOL_SMP) { |
b50102d3 | 2984 | state = SCI_REQ_SMP_WAIT_RESP; |
5dec6f4e DW |
2985 | } else if (task && sas_protocol_ata(task->task_proto) && |
2986 | !task->ata_task.use_ncq) { | |
b50102d3 DW |
2987 | if (dev->sata_dev.command_set == ATAPI_COMMAND_SET && |
2988 | task->ata_task.fis.command == ATA_CMD_PACKET) { | |
2989 | state = SCI_REQ_ATAPI_WAIT_H2D; | |
2990 | } else if (task->data_dir == DMA_NONE) { | |
e301370a | 2991 | state = SCI_REQ_STP_NON_DATA_WAIT_H2D; |
b50102d3 | 2992 | } else if (task->ata_task.dma_xfer) { |
e301370a | 2993 | state = SCI_REQ_STP_UDMA_WAIT_TC_COMP; |
b50102d3 | 2994 | } else /* PIO */ { |
e301370a | 2995 | state = SCI_REQ_STP_PIO_WAIT_H2D; |
b50102d3 DW |
2996 | } |
2997 | } else { | |
2998 | /* SSP or NCQ are fully accelerated, no substates */ | |
2999 | return; | |
c72086e3 | 3000 | } |
b50102d3 | 3001 | sci_change_state(sm, state); |
f1f52e75 DW |
3002 | } |
3003 | ||
89a7301f | 3004 | static void sci_request_completed_state_enter(struct sci_base_state_machine *sm) |
f1f52e75 | 3005 | { |
5076a1a9 | 3006 | struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); |
d9dcb4ba | 3007 | struct isci_host *ihost = ireq->owning_controller; |
f1f52e75 | 3008 | |
f1f52e75 | 3009 | /* Tell the SCI_USER that the IO request is complete */ |
38d8879b | 3010 | if (!test_bit(IREQ_TMF, &ireq->flags)) |
f1f52e75 | 3011 | isci_request_io_request_complete(ihost, ireq, |
5076a1a9 | 3012 | ireq->sci_status); |
f1f52e75 | 3013 | else |
5076a1a9 | 3014 | isci_task_request_complete(ihost, ireq, ireq->sci_status); |
f1f52e75 DW |
3015 | } |
3016 | ||
89a7301f | 3017 | static void sci_request_aborting_state_enter(struct sci_base_state_machine *sm) |
f1f52e75 | 3018 | { |
5076a1a9 | 3019 | struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); |
f1f52e75 DW |
3020 | |
3021 | /* Setting the abort bit in the Task Context is required by the silicon. */ | |
5076a1a9 | 3022 | ireq->tc->abort = 1; |
c72086e3 DW |
3023 | } |
3024 | ||
89a7301f | 3025 | static void sci_stp_request_started_non_data_await_h2d_completion_enter(struct sci_base_state_machine *sm) |
5dec6f4e | 3026 | { |
5076a1a9 | 3027 | struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); |
5dec6f4e | 3028 | |
34a99158 | 3029 | ireq->target_device->working_request = ireq; |
5dec6f4e DW |
3030 | } |
3031 | ||
89a7301f | 3032 | static void sci_stp_request_started_pio_await_h2d_completion_enter(struct sci_base_state_machine *sm) |
5dec6f4e | 3033 | { |
5076a1a9 | 3034 | struct isci_request *ireq = container_of(sm, typeof(*ireq), sm); |
5dec6f4e | 3035 | |
34a99158 | 3036 | ireq->target_device->working_request = ireq; |
5dec6f4e DW |
3037 | } |
3038 | ||
89a7301f | 3039 | static const struct sci_base_state sci_request_state_table[] = { |
e301370a EN |
3040 | [SCI_REQ_INIT] = { }, |
3041 | [SCI_REQ_CONSTRUCTED] = { }, | |
3042 | [SCI_REQ_STARTED] = { | |
89a7301f | 3043 | .enter_state = sci_request_started_state_enter, |
5dec6f4e | 3044 | }, |
e301370a | 3045 | [SCI_REQ_STP_NON_DATA_WAIT_H2D] = { |
89a7301f | 3046 | .enter_state = sci_stp_request_started_non_data_await_h2d_completion_enter, |
5dec6f4e | 3047 | }, |
e301370a EN |
3048 | [SCI_REQ_STP_NON_DATA_WAIT_D2H] = { }, |
3049 | [SCI_REQ_STP_PIO_WAIT_H2D] = { | |
89a7301f | 3050 | .enter_state = sci_stp_request_started_pio_await_h2d_completion_enter, |
5dec6f4e | 3051 | }, |
e301370a EN |
3052 | [SCI_REQ_STP_PIO_WAIT_FRAME] = { }, |
3053 | [SCI_REQ_STP_PIO_DATA_IN] = { }, | |
3054 | [SCI_REQ_STP_PIO_DATA_OUT] = { }, | |
3055 | [SCI_REQ_STP_UDMA_WAIT_TC_COMP] = { }, | |
3056 | [SCI_REQ_STP_UDMA_WAIT_D2H] = { }, | |
e301370a EN |
3057 | [SCI_REQ_TASK_WAIT_TC_COMP] = { }, |
3058 | [SCI_REQ_TASK_WAIT_TC_RESP] = { }, | |
3059 | [SCI_REQ_SMP_WAIT_RESP] = { }, | |
3060 | [SCI_REQ_SMP_WAIT_TC_COMP] = { }, | |
b50102d3 DW |
3061 | [SCI_REQ_ATAPI_WAIT_H2D] = { }, |
3062 | [SCI_REQ_ATAPI_WAIT_PIO_SETUP] = { }, | |
3063 | [SCI_REQ_ATAPI_WAIT_D2H] = { }, | |
3064 | [SCI_REQ_ATAPI_WAIT_TC_COMP] = { }, | |
e301370a | 3065 | [SCI_REQ_COMPLETED] = { |
89a7301f | 3066 | .enter_state = sci_request_completed_state_enter, |
f1f52e75 | 3067 | }, |
e301370a | 3068 | [SCI_REQ_ABORTING] = { |
89a7301f | 3069 | .enter_state = sci_request_aborting_state_enter, |
f1f52e75 | 3070 | }, |
e301370a | 3071 | [SCI_REQ_FINAL] = { }, |
f1f52e75 DW |
3072 | }; |
3073 | ||
e301370a | 3074 | static void |
89a7301f | 3075 | sci_general_request_construct(struct isci_host *ihost, |
78a6f06e | 3076 | struct isci_remote_device *idev, |
5076a1a9 | 3077 | struct isci_request *ireq) |
f1f52e75 | 3078 | { |
89a7301f | 3079 | sci_init_sm(&ireq->sm, sci_request_state_table, SCI_REQ_INIT); |
f1f52e75 | 3080 | |
78a6f06e | 3081 | ireq->target_device = idev; |
c79dd80d | 3082 | ireq->protocol = SAS_PROTOCOL_NONE; |
5076a1a9 | 3083 | ireq->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX; |
f1f52e75 | 3084 | |
5076a1a9 DW |
3085 | ireq->sci_status = SCI_SUCCESS; |
3086 | ireq->scu_status = 0; | |
3087 | ireq->post_context = 0xFFFFFFFF; | |
f1f52e75 DW |
3088 | } |
3089 | ||
3090 | static enum sci_status | |
89a7301f | 3091 | sci_io_request_construct(struct isci_host *ihost, |
78a6f06e | 3092 | struct isci_remote_device *idev, |
5076a1a9 | 3093 | struct isci_request *ireq) |
f1f52e75 | 3094 | { |
78a6f06e | 3095 | struct domain_device *dev = idev->domain_dev; |
f1f52e75 DW |
3096 | enum sci_status status = SCI_SUCCESS; |
3097 | ||
3098 | /* Build the common part of the request */ | |
89a7301f | 3099 | sci_general_request_construct(ihost, idev, ireq); |
f1f52e75 | 3100 | |
78a6f06e | 3101 | if (idev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) |
f1f52e75 DW |
3102 | return SCI_FAILURE_INVALID_REMOTE_DEVICE; |
3103 | ||
3104 | if (dev->dev_type == SAS_END_DEV) | |
c72086e3 | 3105 | /* pass */; |
11cc5183 | 3106 | else if (dev_is_sata(dev)) |
5076a1a9 | 3107 | memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); |
c72086e3 | 3108 | else if (dev_is_expander(dev)) |
e9bf7095 | 3109 | /* pass */; |
c72086e3 DW |
3110 | else |
3111 | return SCI_FAILURE_UNSUPPORTED_PROTOCOL; | |
f1f52e75 | 3112 | |
5076a1a9 | 3113 | memset(ireq->tc, 0, offsetof(struct scu_task_context, sgl_pair_ab)); |
f1f52e75 DW |
3114 | |
3115 | return status; | |
3116 | } | |
3117 | ||
89a7301f | 3118 | enum sci_status sci_task_request_construct(struct isci_host *ihost, |
78a6f06e | 3119 | struct isci_remote_device *idev, |
5076a1a9 | 3120 | u16 io_tag, struct isci_request *ireq) |
f1f52e75 | 3121 | { |
78a6f06e | 3122 | struct domain_device *dev = idev->domain_dev; |
f1f52e75 DW |
3123 | enum sci_status status = SCI_SUCCESS; |
3124 | ||
3125 | /* Build the common part of the request */ | |
89a7301f | 3126 | sci_general_request_construct(ihost, idev, ireq); |
f1f52e75 | 3127 | |
11cc5183 | 3128 | if (dev->dev_type == SAS_END_DEV || dev_is_sata(dev)) { |
5076a1a9 DW |
3129 | set_bit(IREQ_TMF, &ireq->flags); |
3130 | memset(ireq->tc, 0, sizeof(struct scu_task_context)); | |
28de92be JS |
3131 | |
3132 | /* Set the protocol indicator. */ | |
3133 | if (dev_is_sata(dev)) | |
3134 | ireq->protocol = SAS_PROTOCOL_STP; | |
3135 | else | |
3136 | ireq->protocol = SAS_PROTOCOL_SSP; | |
c72086e3 DW |
3137 | } else |
3138 | status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; | |
f1f52e75 DW |
3139 | |
3140 | return status; | |
3141 | } | |
3142 | ||
3143 | static enum sci_status isci_request_ssp_request_construct( | |
3144 | struct isci_request *request) | |
3145 | { | |
3146 | enum sci_status status; | |
3147 | ||
3148 | dev_dbg(&request->isci_host->pdev->dev, | |
3149 | "%s: request = %p\n", | |
3150 | __func__, | |
3151 | request); | |
89a7301f | 3152 | status = sci_io_request_construct_basic_ssp(request); |
f1f52e75 DW |
3153 | return status; |
3154 | } | |
3155 | ||
16ba7709 | 3156 | static enum sci_status isci_request_stp_request_construct(struct isci_request *ireq) |
f1f52e75 | 3157 | { |
16ba7709 DW |
3158 | struct sas_task *task = isci_request_access_task(ireq); |
3159 | struct host_to_dev_fis *fis = &ireq->stp.cmd; | |
3160 | struct ata_queued_cmd *qc = task->uldd_task; | |
f1f52e75 | 3161 | enum sci_status status; |
f1f52e75 | 3162 | |
16ba7709 DW |
3163 | dev_dbg(&ireq->isci_host->pdev->dev, |
3164 | "%s: ireq = %p\n", | |
f1f52e75 | 3165 | __func__, |
16ba7709 | 3166 | ireq); |
f1f52e75 | 3167 | |
16ba7709 DW |
3168 | memcpy(fis, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); |
3169 | if (!task->ata_task.device_control_reg_update) | |
3170 | fis->flags |= 0x80; | |
3171 | fis->flags &= 0xF0; | |
f1f52e75 | 3172 | |
16ba7709 | 3173 | status = sci_io_request_construct_basic_sata(ireq); |
f1f52e75 | 3174 | |
16ba7709 DW |
3175 | if (qc && (qc->tf.command == ATA_CMD_FPDMA_WRITE || |
3176 | qc->tf.command == ATA_CMD_FPDMA_READ)) { | |
3177 | fis->sector_count = qc->tag << 3; | |
3178 | ireq->tc->type.stp.ncq_tag = qc->tag; | |
f1f52e75 DW |
3179 | } |
3180 | ||
3181 | return status; | |
3182 | } | |
3183 | ||
e9bf7095 | 3184 | static enum sci_status |
89a7301f | 3185 | sci_io_request_construct_smp(struct device *dev, |
5076a1a9 | 3186 | struct isci_request *ireq, |
e9bf7095 | 3187 | struct sas_task *task) |
c72086e3 | 3188 | { |
e9bf7095 | 3189 | struct scatterlist *sg = &task->smp_task.smp_req; |
78a6f06e | 3190 | struct isci_remote_device *idev; |
c72086e3 | 3191 | struct scu_task_context *task_context; |
ffe191c9 | 3192 | struct isci_port *iport; |
e9bf7095 DW |
3193 | struct smp_req *smp_req; |
3194 | void *kaddr; | |
3195 | u8 req_len; | |
3196 | u32 cmd; | |
3197 | ||
77dfce07 | 3198 | kaddr = kmap_atomic(sg_page(sg)); |
e9bf7095 DW |
3199 | smp_req = kaddr + sg->offset; |
3200 | /* | |
3201 | * Look at the SMP requests' header fields; for certain SAS 1.x SMP | |
3202 | * functions under SAS 2.0, a zero request length really indicates | |
3203 | * a non-zero default length. | |
3204 | */ | |
3205 | if (smp_req->req_len == 0) { | |
3206 | switch (smp_req->func) { | |
3207 | case SMP_DISCOVER: | |
3208 | case SMP_REPORT_PHY_ERR_LOG: | |
3209 | case SMP_REPORT_PHY_SATA: | |
3210 | case SMP_REPORT_ROUTE_INFO: | |
3211 | smp_req->req_len = 2; | |
3212 | break; | |
3213 | case SMP_CONF_ROUTE_INFO: | |
3214 | case SMP_PHY_CONTROL: | |
3215 | case SMP_PHY_TEST_FUNCTION: | |
3216 | smp_req->req_len = 9; | |
3217 | break; | |
3218 | /* Default - zero is a valid default for 2.0. */ | |
3219 | } | |
3220 | } | |
3221 | req_len = smp_req->req_len; | |
3222 | sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32)); | |
3223 | cmd = *(u32 *) smp_req; | |
77dfce07 | 3224 | kunmap_atomic(kaddr); |
e9bf7095 DW |
3225 | |
3226 | if (!dma_map_sg(dev, sg, 1, DMA_TO_DEVICE)) | |
3227 | return SCI_FAILURE; | |
3228 | ||
c79dd80d | 3229 | ireq->protocol = SAS_PROTOCOL_SMP; |
c72086e3 DW |
3230 | |
3231 | /* byte swap the smp request. */ | |
c72086e3 | 3232 | |
5076a1a9 | 3233 | task_context = ireq->tc; |
c72086e3 | 3234 | |
34a99158 DW |
3235 | idev = ireq->target_device; |
3236 | iport = idev->owning_port; | |
c72086e3 DW |
3237 | |
3238 | /* | |
3239 | * Fill in the TC with the its required data | |
3240 | * 00h | |
3241 | */ | |
3242 | task_context->priority = 0; | |
3243 | task_context->initiator_request = 1; | |
78a6f06e | 3244 | task_context->connection_rate = idev->connection_rate; |
34a99158 DW |
3245 | task_context->protocol_engine_index = ISCI_PEG; |
3246 | task_context->logical_port_index = iport->physical_port_index; | |
c72086e3 DW |
3247 | task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP; |
3248 | task_context->abort = 0; | |
3249 | task_context->valid = SCU_TASK_CONTEXT_VALID; | |
3250 | task_context->context_type = SCU_TASK_CONTEXT_TYPE; | |
3251 | ||
3252 | /* 04h */ | |
78a6f06e | 3253 | task_context->remote_node_index = idev->rnc.remote_node_index; |
c72086e3 DW |
3254 | task_context->command_code = 0; |
3255 | task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST; | |
3256 | ||
3257 | /* 08h */ | |
3258 | task_context->link_layer_control = 0; | |
3259 | task_context->do_not_dma_ssp_good_response = 1; | |
3260 | task_context->strict_ordering = 0; | |
3261 | task_context->control_frame = 1; | |
3262 | task_context->timeout_enable = 0; | |
3263 | task_context->block_guard_enable = 0; | |
3264 | ||
3265 | /* 0ch */ | |
3266 | task_context->address_modifier = 0; | |
3267 | ||
3268 | /* 10h */ | |
77d67385 | 3269 | task_context->ssp_command_iu_length = req_len; |
c72086e3 DW |
3270 | |
3271 | /* 14h */ | |
3272 | task_context->transfer_length_bytes = 0; | |
3273 | ||
3274 | /* | |
3275 | * 18h ~ 30h, protocol specific | |
3276 | * since commandIU has been build by framework at this point, we just | |
3277 | * copy the frist DWord from command IU to this location. */ | |
e9bf7095 | 3278 | memcpy(&task_context->type.smp, &cmd, sizeof(u32)); |
c72086e3 DW |
3279 | |
3280 | /* | |
3281 | * 40h | |
3282 | * "For SMP you could program it to zero. We would prefer that way | |
3283 | * so that done code will be consistent." - Venki | |
3284 | */ | |
3285 | task_context->task_phase = 0; | |
3286 | ||
5076a1a9 | 3287 | ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | |
34a99158 DW |
3288 | (ISCI_PEG << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) | |
3289 | (iport->physical_port_index << | |
3290 | SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) | | |
3291 | ISCI_TAG_TCI(ireq->io_tag)); | |
c72086e3 DW |
3292 | /* |
3293 | * Copy the physical address for the command buffer to the SCU Task | |
3294 | * Context command buffer should not contain command header. | |
3295 | */ | |
e9bf7095 DW |
3296 | task_context->command_iu_upper = upper_32_bits(sg_dma_address(sg)); |
3297 | task_context->command_iu_lower = lower_32_bits(sg_dma_address(sg) + sizeof(u32)); | |
c72086e3 DW |
3298 | |
3299 | /* SMP response comes as UF, so no need to set response IU address. */ | |
3300 | task_context->response_iu_upper = 0; | |
3301 | task_context->response_iu_lower = 0; | |
c72086e3 | 3302 | |
5076a1a9 | 3303 | sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); |
c72086e3 DW |
3304 | |
3305 | return SCI_SUCCESS; | |
3306 | } | |
3307 | ||
f1f52e75 DW |
3308 | /* |
3309 | * isci_smp_request_build() - This function builds the smp request. | |
3310 | * @ireq: This parameter points to the isci_request allocated in the | |
3311 | * request construct function. | |
3312 | * | |
3313 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
3314 | */ | |
3315 | static enum sci_status isci_smp_request_build(struct isci_request *ireq) | |
3316 | { | |
f1f52e75 | 3317 | struct sas_task *task = isci_request_access_task(ireq); |
e9bf7095 | 3318 | struct device *dev = &ireq->isci_host->pdev->dev; |
e9bf7095 | 3319 | enum sci_status status = SCI_FAILURE; |
f1f52e75 | 3320 | |
89a7301f | 3321 | status = sci_io_request_construct_smp(dev, ireq, task); |
f1f52e75 | 3322 | if (status != SCI_SUCCESS) |
a8a0a133 | 3323 | dev_dbg(&ireq->isci_host->pdev->dev, |
f1f52e75 DW |
3324 | "%s: failed with status = %d\n", |
3325 | __func__, | |
3326 | status); | |
3327 | ||
3328 | return status; | |
3329 | } | |
3330 | ||
3331 | /** | |
3332 | * isci_io_request_build() - This function builds the io request object. | |
d9dcb4ba | 3333 | * @ihost: This parameter specifies the ISCI host object |
f1f52e75 DW |
3334 | * @request: This parameter points to the isci_request object allocated in the |
3335 | * request construct function. | |
3336 | * @sci_device: This parameter is the handle for the sci core's remote device | |
3337 | * object that is the destination for this request. | |
3338 | * | |
3339 | * SCI_SUCCESS on successfull completion, or specific failure code. | |
3340 | */ | |
d9dcb4ba | 3341 | static enum sci_status isci_io_request_build(struct isci_host *ihost, |
312e0c24 | 3342 | struct isci_request *request, |
78a6f06e | 3343 | struct isci_remote_device *idev) |
f1f52e75 DW |
3344 | { |
3345 | enum sci_status status = SCI_SUCCESS; | |
3346 | struct sas_task *task = isci_request_access_task(request); | |
f1f52e75 | 3347 | |
d9dcb4ba | 3348 | dev_dbg(&ihost->pdev->dev, |
78a6f06e | 3349 | "%s: idev = 0x%p; request = %p, " |
f1f52e75 DW |
3350 | "num_scatter = %d\n", |
3351 | __func__, | |
78a6f06e | 3352 | idev, |
f1f52e75 DW |
3353 | request, |
3354 | task->num_scatter); | |
3355 | ||
3356 | /* map the sgl addresses, if present. | |
3357 | * libata does the mapping for sata devices | |
3358 | * before we get the request. | |
3359 | */ | |
3360 | if (task->num_scatter && | |
3361 | !sas_protocol_ata(task->task_proto) && | |
3362 | !(SAS_PROTOCOL_SMP & task->task_proto)) { | |
3363 | ||
3364 | request->num_sg_entries = dma_map_sg( | |
d9dcb4ba | 3365 | &ihost->pdev->dev, |
f1f52e75 DW |
3366 | task->scatter, |
3367 | task->num_scatter, | |
3368 | task->data_dir | |
3369 | ); | |
3370 | ||
3371 | if (request->num_sg_entries == 0) | |
3372 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; | |
3373 | } | |
3374 | ||
89a7301f | 3375 | status = sci_io_request_construct(ihost, idev, request); |
f1f52e75 DW |
3376 | |
3377 | if (status != SCI_SUCCESS) { | |
a8a0a133 | 3378 | dev_dbg(&ihost->pdev->dev, |
f1f52e75 DW |
3379 | "%s: failed request construct\n", |
3380 | __func__); | |
3381 | return SCI_FAILURE; | |
3382 | } | |
3383 | ||
3384 | switch (task->task_proto) { | |
3385 | case SAS_PROTOCOL_SMP: | |
3386 | status = isci_smp_request_build(request); | |
3387 | break; | |
3388 | case SAS_PROTOCOL_SSP: | |
3389 | status = isci_request_ssp_request_construct(request); | |
3390 | break; | |
3391 | case SAS_PROTOCOL_SATA: | |
3392 | case SAS_PROTOCOL_STP: | |
3393 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: | |
3394 | status = isci_request_stp_request_construct(request); | |
3395 | break; | |
3396 | default: | |
a8a0a133 | 3397 | dev_dbg(&ihost->pdev->dev, |
f1f52e75 DW |
3398 | "%s: unknown protocol\n", __func__); |
3399 | return SCI_FAILURE; | |
3400 | } | |
3401 | ||
3402 | return SCI_SUCCESS; | |
3403 | } | |
3404 | ||
db056250 | 3405 | static struct isci_request *isci_request_from_tag(struct isci_host *ihost, u16 tag) |
f1f52e75 | 3406 | { |
0d0cf14c | 3407 | struct isci_request *ireq; |
aa145102 | 3408 | |
db056250 | 3409 | ireq = ihost->reqs[ISCI_TAG_TCI(tag)]; |
5076a1a9 | 3410 | ireq->io_tag = tag; |
0d0cf14c | 3411 | ireq->io_request_completion = NULL; |
38d8879b | 3412 | ireq->flags = 0; |
0d0cf14c | 3413 | ireq->num_sg_entries = 0; |
f1f52e75 | 3414 | |
0d0cf14c | 3415 | return ireq; |
f1f52e75 DW |
3416 | } |
3417 | ||
db056250 DW |
3418 | static struct isci_request *isci_io_request_from_tag(struct isci_host *ihost, |
3419 | struct sas_task *task, | |
3420 | u16 tag) | |
f1f52e75 | 3421 | { |
0d0cf14c | 3422 | struct isci_request *ireq; |
f1f52e75 | 3423 | |
db056250 DW |
3424 | ireq = isci_request_from_tag(ihost, tag); |
3425 | ireq->ttype_ptr.io_task_ptr = task; | |
3b34c169 | 3426 | clear_bit(IREQ_TMF, &ireq->flags); |
db056250 DW |
3427 | task->lldd_task = ireq; |
3428 | ||
0d0cf14c | 3429 | return ireq; |
f1f52e75 | 3430 | } |
6f231dda | 3431 | |
db056250 DW |
3432 | struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost, |
3433 | struct isci_tmf *isci_tmf, | |
3434 | u16 tag) | |
f1f52e75 | 3435 | { |
0d0cf14c | 3436 | struct isci_request *ireq; |
6f231dda | 3437 | |
db056250 DW |
3438 | ireq = isci_request_from_tag(ihost, tag); |
3439 | ireq->ttype_ptr.tmf_task_ptr = isci_tmf; | |
3b34c169 | 3440 | set_bit(IREQ_TMF, &ireq->flags); |
db056250 | 3441 | |
0d0cf14c | 3442 | return ireq; |
f1f52e75 DW |
3443 | } |
3444 | ||
209fae14 | 3445 | int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev, |
db056250 | 3446 | struct sas_task *task, u16 tag) |
f1f52e75 | 3447 | { |
f1f52e75 | 3448 | enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
0d0cf14c | 3449 | struct isci_request *ireq; |
f1f52e75 | 3450 | unsigned long flags; |
0d0cf14c | 3451 | int ret = 0; |
f1f52e75 | 3452 | |
f1f52e75 | 3453 | /* do common allocation and init of request object. */ |
db056250 | 3454 | ireq = isci_io_request_from_tag(ihost, task, tag); |
f1f52e75 | 3455 | |
db056250 | 3456 | status = isci_io_request_build(ihost, ireq, idev); |
f1f52e75 | 3457 | if (status != SCI_SUCCESS) { |
a8a0a133 | 3458 | dev_dbg(&ihost->pdev->dev, |
f1f52e75 DW |
3459 | "%s: request_construct failed - status = 0x%x\n", |
3460 | __func__, | |
3461 | status); | |
db056250 | 3462 | return status; |
f1f52e75 DW |
3463 | } |
3464 | ||
0d0cf14c | 3465 | spin_lock_irqsave(&ihost->scic_lock, flags); |
f1f52e75 | 3466 | |
9274f45e JS |
3467 | if (test_bit(IDEV_IO_NCQERROR, &idev->flags)) { |
3468 | ||
3469 | if (isci_task_is_ncq_recovery(task)) { | |
3470 | ||
3471 | /* The device is in an NCQ recovery state. Issue the | |
3472 | * request on the task side. Note that it will | |
3473 | * complete on the I/O request side because the | |
3474 | * request was built that way (ie. | |
3475 | * ireq->is_task_management_request is false). | |
3476 | */ | |
89a7301f | 3477 | status = sci_controller_start_task(ihost, |
78a6f06e | 3478 | idev, |
5076a1a9 | 3479 | ireq); |
9274f45e JS |
3480 | } else { |
3481 | status = SCI_FAILURE; | |
3482 | } | |
3483 | } else { | |
9274f45e | 3484 | /* send the request, let the core assign the IO TAG. */ |
89a7301f | 3485 | status = sci_controller_start_io(ihost, idev, |
5076a1a9 | 3486 | ireq); |
9274f45e | 3487 | } |
312e0c24 | 3488 | |
f1f52e75 DW |
3489 | if (status != SCI_SUCCESS && |
3490 | status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | |
a8a0a133 | 3491 | dev_dbg(&ihost->pdev->dev, |
f1f52e75 DW |
3492 | "%s: failed request start (0x%x)\n", |
3493 | __func__, status); | |
0d0cf14c | 3494 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
db056250 | 3495 | return status; |
f1f52e75 | 3496 | } |
f1f52e75 DW |
3497 | /* Either I/O started OK, or the core has signaled that |
3498 | * the device needs a target reset. | |
6f231dda | 3499 | */ |
14aaa9f0 | 3500 | if (status != SCI_SUCCESS) { |
f1f52e75 DW |
3501 | /* The request did not really start in the |
3502 | * hardware, so clear the request handle | |
3503 | * here so no terminations will be done. | |
3504 | */ | |
38d8879b | 3505 | set_bit(IREQ_TERMINATED, &ireq->flags); |
f1f52e75 | 3506 | } |
0d0cf14c | 3507 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
f1f52e75 DW |
3508 | |
3509 | if (status == | |
3510 | SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { | |
3511 | /* Signal libsas that we need the SCSI error | |
312e0c24 DW |
3512 | * handler thread to work on this I/O and that |
3513 | * we want a device reset. | |
3514 | */ | |
f1f52e75 DW |
3515 | spin_lock_irqsave(&task->task_state_lock, flags); |
3516 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; | |
3517 | spin_unlock_irqrestore(&task->task_state_lock, flags); | |
3518 | ||
3519 | /* Cause this task to be scheduled in the SCSI error | |
312e0c24 DW |
3520 | * handler thread. |
3521 | */ | |
312d3e56 | 3522 | sas_task_abort(task); |
f1f52e75 DW |
3523 | |
3524 | /* Change the status, since we are holding | |
312e0c24 DW |
3525 | * the I/O until it is managed by the SCSI |
3526 | * error handler. | |
3527 | */ | |
f1f52e75 DW |
3528 | status = SCI_SUCCESS; |
3529 | } | |
3530 | ||
f1f52e75 | 3531 | return ret; |
6f231dda | 3532 | } |