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