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