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