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