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