Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 3 | * redistributing this file, you may do so under either license. |
| 4 | * |
| 5 | * GPL LICENSE SUMMARY |
| 6 | * |
| 7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * BSD LICENSE |
| 25 | * |
| 26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 27 | * All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source and binary forms, with or without |
| 30 | * modification, are permitted provided that the following conditions |
| 31 | * are met: |
| 32 | * |
| 33 | * * Redistributions of source code must retain the above copyright |
| 34 | * notice, this list of conditions and the following disclaimer. |
| 35 | * * Redistributions in binary form must reproduce the above copyright |
| 36 | * notice, this list of conditions and the following disclaimer in |
| 37 | * the documentation and/or other materials provided with the |
| 38 | * distribution. |
| 39 | * * Neither the name of Intel Corporation nor the names of its |
| 40 | * contributors may be used to endorse or promote products derived |
| 41 | * from this software without specific prior written permission. |
| 42 | * |
| 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 54 | */ |
| 55 | |
| 56 | #include "isci.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #include "scic_io_request.h" |
| 58 | #include "scic_task_request.h" |
| 59 | #include "scic_port.h" |
| 60 | #include "task.h" |
| 61 | #include "request.h" |
| 62 | #include "sata.h" |
| 63 | #include "scu_completion_codes.h" |
Maciej Patelczyk | 890cae9 | 2011-04-28 22:06:31 +0000 | [diff] [blame^] | 64 | #include "core/scic_sds_request.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 65 | |
| 66 | static enum sci_status isci_request_ssp_request_construct( |
| 67 | struct isci_request *request) |
| 68 | { |
| 69 | enum sci_status status; |
| 70 | |
| 71 | dev_dbg(&request->isci_host->pdev->dev, |
| 72 | "%s: request = %p\n", |
| 73 | __func__, |
| 74 | request); |
| 75 | status = scic_io_request_construct_basic_ssp( |
| 76 | request->sci_request_handle |
| 77 | ); |
| 78 | return status; |
| 79 | } |
| 80 | |
| 81 | static enum sci_status isci_request_stp_request_construct( |
| 82 | struct isci_request *request) |
| 83 | { |
| 84 | struct sas_task *task = isci_request_access_task(request); |
| 85 | enum sci_status status; |
| 86 | struct host_to_dev_fis *register_fis; |
| 87 | |
| 88 | dev_dbg(&request->isci_host->pdev->dev, |
| 89 | "%s: request = %p\n", |
| 90 | __func__, |
| 91 | request); |
| 92 | |
| 93 | /* Get the host_to_dev_fis from the core and copy |
| 94 | * the fis from the task into it. |
| 95 | */ |
| 96 | register_fis = isci_sata_task_to_fis_copy(task); |
| 97 | |
| 98 | status = scic_io_request_construct_basic_sata( |
| 99 | request->sci_request_handle |
| 100 | ); |
| 101 | |
| 102 | /* Set the ncq tag in the fis, from the queue |
| 103 | * command in the task. |
| 104 | */ |
| 105 | if (isci_sata_is_task_ncq(task)) { |
| 106 | |
| 107 | isci_sata_set_ncq_tag( |
| 108 | register_fis, |
| 109 | task |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | return status; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * isci_smp_request_build() - This function builds the smp request object. |
| 118 | * @isci_host: This parameter specifies the ISCI host object |
| 119 | * @request: This parameter points to the isci_request object allocated in the |
| 120 | * request construct function. |
| 121 | * @sci_device: This parameter is the handle for the sci core's remote device |
| 122 | * object that is the destination for this request. |
| 123 | * |
| 124 | * SCI_SUCCESS on successfull completion, or specific failure code. |
| 125 | */ |
| 126 | static enum sci_status isci_smp_request_build( |
| 127 | struct isci_request *request) |
| 128 | { |
| 129 | enum sci_status status = SCI_FAILURE; |
| 130 | struct sas_task *task = isci_request_access_task(request); |
| 131 | |
| 132 | void *command_iu_address = |
| 133 | scic_io_request_get_command_iu_address( |
| 134 | request->sci_request_handle |
| 135 | ); |
| 136 | |
| 137 | dev_dbg(&request->isci_host->pdev->dev, |
| 138 | "%s: request = %p\n", |
| 139 | __func__, |
| 140 | request); |
| 141 | dev_dbg(&request->isci_host->pdev->dev, |
| 142 | "%s: smp_req len = %d\n", |
| 143 | __func__, |
| 144 | task->smp_task.smp_req.length); |
| 145 | |
| 146 | /* copy the smp_command to the address; */ |
| 147 | sg_copy_to_buffer(&task->smp_task.smp_req, 1, |
| 148 | (char *)command_iu_address, |
| 149 | sizeof(struct smp_request) |
| 150 | ); |
| 151 | |
| 152 | status = scic_io_request_construct_smp(request->sci_request_handle); |
| 153 | if (status != SCI_SUCCESS) |
| 154 | dev_warn(&request->isci_host->pdev->dev, |
| 155 | "%s: scic_io_request_construct_smp failed with " |
| 156 | "status = %d\n", |
| 157 | __func__, |
| 158 | status); |
| 159 | |
| 160 | return status; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * isci_io_request_build() - This function builds the io request object. |
| 165 | * @isci_host: This parameter specifies the ISCI host object |
| 166 | * @request: This parameter points to the isci_request object allocated in the |
| 167 | * request construct function. |
| 168 | * @sci_device: This parameter is the handle for the sci core's remote device |
| 169 | * object that is the destination for this request. |
| 170 | * |
| 171 | * SCI_SUCCESS on successfull completion, or specific failure code. |
| 172 | */ |
| 173 | static enum sci_status isci_io_request_build( |
| 174 | struct isci_host *isci_host, |
| 175 | struct isci_request *request, |
| 176 | struct isci_remote_device *isci_device) |
| 177 | { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 178 | enum sci_status status = SCI_SUCCESS; |
| 179 | struct sas_task *task = isci_request_access_task(request); |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 180 | struct scic_sds_remote_device *sci_device = &isci_device->sci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 181 | |
| 182 | dev_dbg(&isci_host->pdev->dev, |
| 183 | "%s: isci_device = 0x%p; request = %p, " |
| 184 | "num_scatter = %d\n", |
| 185 | __func__, |
| 186 | isci_device, |
| 187 | request, |
| 188 | task->num_scatter); |
| 189 | |
| 190 | /* map the sgl addresses, if present. |
| 191 | * libata does the mapping for sata devices |
| 192 | * before we get the request. |
| 193 | */ |
| 194 | if (task->num_scatter && |
| 195 | !sas_protocol_ata(task->task_proto) && |
| 196 | !(SAS_PROTOCOL_SMP & task->task_proto)) { |
| 197 | |
| 198 | request->num_sg_entries = dma_map_sg( |
| 199 | &isci_host->pdev->dev, |
| 200 | task->scatter, |
| 201 | task->num_scatter, |
| 202 | task->data_dir |
| 203 | ); |
| 204 | |
| 205 | if (request->num_sg_entries == 0) |
| 206 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; |
| 207 | } |
| 208 | |
| 209 | /* build the common request object. For now, |
| 210 | * we will let the core allocate the IO tag. |
| 211 | */ |
| 212 | status = scic_io_request_construct( |
| 213 | isci_host->core_controller, |
| 214 | sci_device, |
| 215 | SCI_CONTROLLER_INVALID_IO_TAG, |
| 216 | request, |
| 217 | request->sci_request_mem_ptr, |
| 218 | (struct scic_sds_request **)&request->sci_request_handle |
| 219 | ); |
| 220 | |
| 221 | if (status != SCI_SUCCESS) { |
| 222 | dev_warn(&isci_host->pdev->dev, |
| 223 | "%s: failed request construct\n", |
| 224 | __func__); |
| 225 | return SCI_FAILURE; |
| 226 | } |
| 227 | |
Maciej Patelczyk | 890cae9 | 2011-04-28 22:06:31 +0000 | [diff] [blame^] | 228 | request->sci_request_handle->ireq = request; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 229 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 230 | switch (task->task_proto) { |
| 231 | case SAS_PROTOCOL_SMP: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 232 | status = isci_smp_request_build(request); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 233 | break; |
| 234 | case SAS_PROTOCOL_SSP: |
| 235 | status = isci_request_ssp_request_construct(request); |
| 236 | break; |
| 237 | case SAS_PROTOCOL_SATA: |
| 238 | case SAS_PROTOCOL_STP: |
| 239 | case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP: |
| 240 | status = isci_request_stp_request_construct(request); |
| 241 | break; |
| 242 | default: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 243 | dev_warn(&isci_host->pdev->dev, |
| 244 | "%s: unknown protocol\n", __func__); |
| 245 | return SCI_FAILURE; |
| 246 | } |
| 247 | |
| 248 | return SCI_SUCCESS; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /** |
| 253 | * isci_request_alloc_core() - This function gets the request object from the |
| 254 | * isci_host dma cache. |
| 255 | * @isci_host: This parameter specifies the ISCI host object |
| 256 | * @isci_request: This parameter will contain the pointer to the new |
| 257 | * isci_request object. |
| 258 | * @isci_device: This parameter is the pointer to the isci remote device object |
| 259 | * that is the destination for this request. |
| 260 | * @gfp_flags: This parameter specifies the os allocation flags. |
| 261 | * |
| 262 | * SCI_SUCCESS on successfull completion, or specific failure code. |
| 263 | */ |
| 264 | static int isci_request_alloc_core( |
| 265 | struct isci_host *isci_host, |
| 266 | struct isci_request **isci_request, |
| 267 | struct isci_remote_device *isci_device, |
| 268 | gfp_t gfp_flags) |
| 269 | { |
| 270 | int ret = 0; |
| 271 | dma_addr_t handle; |
| 272 | struct isci_request *request; |
| 273 | |
| 274 | |
| 275 | /* get pointer to dma memory. This actually points |
| 276 | * to both the isci_remote_device object and the |
| 277 | * sci object. The isci object is at the beginning |
| 278 | * of the memory allocated here. |
| 279 | */ |
| 280 | request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle); |
| 281 | if (!request) { |
| 282 | dev_warn(&isci_host->pdev->dev, |
| 283 | "%s: dma_pool_alloc returned NULL\n", __func__); |
| 284 | return -ENOMEM; |
| 285 | } |
| 286 | |
| 287 | /* initialize the request object. */ |
| 288 | spin_lock_init(&request->state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 289 | request->sci_request_mem_ptr = ((u8 *)request) + |
| 290 | sizeof(struct isci_request); |
| 291 | request->request_daddr = handle; |
| 292 | request->isci_host = isci_host; |
| 293 | request->isci_device = isci_device; |
| 294 | request->io_request_completion = NULL; |
| 295 | |
| 296 | request->request_alloc_size = isci_host->dma_pool_alloc_size; |
| 297 | request->num_sg_entries = 0; |
| 298 | |
| 299 | request->complete_in_target = false; |
| 300 | |
| 301 | INIT_LIST_HEAD(&request->completed_node); |
| 302 | INIT_LIST_HEAD(&request->dev_node); |
| 303 | |
| 304 | *isci_request = request; |
Dan Williams | 83f5eee | 2011-02-18 09:25:15 -0800 | [diff] [blame] | 305 | isci_request_change_state(request, allocated); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 306 | |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | static int isci_request_alloc_io( |
| 311 | struct isci_host *isci_host, |
| 312 | struct sas_task *task, |
| 313 | struct isci_request **isci_request, |
| 314 | struct isci_remote_device *isci_device, |
| 315 | gfp_t gfp_flags) |
| 316 | { |
| 317 | int retval = isci_request_alloc_core(isci_host, isci_request, |
| 318 | isci_device, gfp_flags); |
| 319 | |
| 320 | if (!retval) { |
| 321 | (*isci_request)->ttype_ptr.io_task_ptr = task; |
| 322 | (*isci_request)->ttype = io_task; |
| 323 | |
| 324 | task->lldd_task = *isci_request; |
| 325 | } |
| 326 | return retval; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * isci_request_alloc_tmf() - This function gets the request object from the |
| 331 | * isci_host dma cache and initializes the relevant fields as a sas_task. |
| 332 | * @isci_host: This parameter specifies the ISCI host object |
| 333 | * @sas_task: This parameter is the task struct from the upper layer driver. |
| 334 | * @isci_request: This parameter will contain the pointer to the new |
| 335 | * isci_request object. |
| 336 | * @isci_device: This parameter is the pointer to the isci remote device object |
| 337 | * that is the destination for this request. |
| 338 | * @gfp_flags: This parameter specifies the os allocation flags. |
| 339 | * |
| 340 | * SCI_SUCCESS on successfull completion, or specific failure code. |
| 341 | */ |
| 342 | int isci_request_alloc_tmf( |
| 343 | struct isci_host *isci_host, |
| 344 | struct isci_tmf *isci_tmf, |
| 345 | struct isci_request **isci_request, |
| 346 | struct isci_remote_device *isci_device, |
| 347 | gfp_t gfp_flags) |
| 348 | { |
| 349 | int retval = isci_request_alloc_core(isci_host, isci_request, |
| 350 | isci_device, gfp_flags); |
| 351 | |
| 352 | if (!retval) { |
| 353 | |
| 354 | (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf; |
| 355 | (*isci_request)->ttype = tmf_task; |
| 356 | } |
| 357 | return retval; |
| 358 | } |
| 359 | |
| 360 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 361 | * isci_request_execute() - This function allocates the isci_request object, |
| 362 | * all fills in some common fields. |
| 363 | * @isci_host: This parameter specifies the ISCI host object |
| 364 | * @sas_task: This parameter is the task struct from the upper layer driver. |
| 365 | * @isci_request: This parameter will contain the pointer to the new |
| 366 | * isci_request object. |
| 367 | * @gfp_flags: This parameter specifies the os allocation flags. |
| 368 | * |
| 369 | * SCI_SUCCESS on successfull completion, or specific failure code. |
| 370 | */ |
| 371 | int isci_request_execute( |
| 372 | struct isci_host *isci_host, |
| 373 | struct sas_task *task, |
| 374 | struct isci_request **isci_request, |
| 375 | gfp_t gfp_flags) |
| 376 | { |
| 377 | int ret = 0; |
| 378 | struct scic_sds_remote_device *sci_device; |
| 379 | enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
| 380 | struct isci_remote_device *isci_device; |
| 381 | struct isci_request *request; |
| 382 | unsigned long flags; |
| 383 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 384 | isci_device = task->dev->lldd_dev; |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 385 | sci_device = &isci_device->sci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 386 | |
| 387 | /* do common allocation and init of request object. */ |
| 388 | ret = isci_request_alloc_io( |
| 389 | isci_host, |
| 390 | task, |
| 391 | &request, |
| 392 | isci_device, |
| 393 | gfp_flags |
| 394 | ); |
| 395 | |
| 396 | if (ret) |
| 397 | goto out; |
| 398 | |
| 399 | status = isci_io_request_build(isci_host, request, isci_device); |
| 400 | if (status == SCI_SUCCESS) { |
| 401 | |
| 402 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 403 | |
| 404 | /* send the request, let the core assign the IO TAG. */ |
| 405 | status = scic_controller_start_io( |
| 406 | isci_host->core_controller, |
| 407 | sci_device, |
| 408 | request->sci_request_handle, |
| 409 | SCI_CONTROLLER_INVALID_IO_TAG |
| 410 | ); |
| 411 | |
| 412 | if (status == SCI_SUCCESS || |
| 413 | status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { |
| 414 | |
| 415 | /* Either I/O started OK, or the core has signaled that |
| 416 | * the device needs a target reset. |
| 417 | * |
| 418 | * In either case, hold onto the I/O for later. |
| 419 | * |
| 420 | * Update it's status and add it to the list in the |
| 421 | * remote device object. |
| 422 | */ |
| 423 | isci_request_change_state(request, started); |
| 424 | list_add(&request->dev_node, |
| 425 | &isci_device->reqs_in_process); |
| 426 | |
Jeff Skirvin | c4b9e24 | 2011-03-16 09:41:59 -0700 | [diff] [blame] | 427 | if (status == SCI_SUCCESS) { |
Jeff Skirvin | 1fad9e9 | 2011-03-04 14:06:46 -0800 | [diff] [blame] | 428 | /* Save the tag for possible task mgmt later. */ |
| 429 | request->io_tag = scic_io_request_get_io_tag( |
| 430 | request->sci_request_handle); |
Jeff Skirvin | ce4f75d | 2011-03-31 13:10:36 -0700 | [diff] [blame] | 431 | } else { |
| 432 | /* The request did not really start in the |
| 433 | * hardware, so clear the request handle |
| 434 | * here so no terminations will be done. |
| 435 | */ |
| 436 | request->sci_request_handle = NULL; |
Jeff Skirvin | c4b9e24 | 2011-03-16 09:41:59 -0700 | [diff] [blame] | 437 | } |
Jeff Skirvin | ce4f75d | 2011-03-31 13:10:36 -0700 | [diff] [blame] | 438 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 439 | } else |
| 440 | dev_warn(&isci_host->pdev->dev, |
Jeff Skirvin | ce4f75d | 2011-03-31 13:10:36 -0700 | [diff] [blame] | 441 | "%s: failed request start (0x%x)\n", |
| 442 | __func__, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 443 | |
| 444 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 445 | |
Jeff Skirvin | c4b9e24 | 2011-03-16 09:41:59 -0700 | [diff] [blame] | 446 | if (status == |
| 447 | SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { |
| 448 | /* Signal libsas that we need the SCSI error |
| 449 | * handler thread to work on this I/O and that |
| 450 | * we want a device reset. |
| 451 | */ |
Jeff Skirvin | ce4f75d | 2011-03-31 13:10:36 -0700 | [diff] [blame] | 452 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 453 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; |
| 454 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 455 | |
Jeff Skirvin | ed8a72d | 2011-03-31 13:10:40 -0700 | [diff] [blame] | 456 | /* Cause this task to be scheduled in the SCSI error |
| 457 | * handler thread. |
Jeff Skirvin | ce4f75d | 2011-03-31 13:10:36 -0700 | [diff] [blame] | 458 | */ |
Jeff Skirvin | ed8a72d | 2011-03-31 13:10:40 -0700 | [diff] [blame] | 459 | isci_execpath_callback(isci_host, task, |
| 460 | sas_task_abort); |
Jeff Skirvin | c4b9e24 | 2011-03-16 09:41:59 -0700 | [diff] [blame] | 461 | |
| 462 | /* Change the status, since we are holding |
| 463 | * the I/O until it is managed by the SCSI |
| 464 | * error handler. |
| 465 | */ |
| 466 | status = SCI_SUCCESS; |
| 467 | } |
| 468 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 469 | } else |
| 470 | dev_warn(&isci_host->pdev->dev, |
| 471 | "%s: request_construct failed - status = 0x%x\n", |
| 472 | __func__, |
| 473 | status); |
| 474 | |
| 475 | out: |
| 476 | if (status != SCI_SUCCESS) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 477 | /* release dma memory on failure. */ |
| 478 | isci_request_free(isci_host, request); |
| 479 | request = NULL; |
| 480 | ret = SCI_FAILURE; |
| 481 | } |
| 482 | |
| 483 | *isci_request = request; |
| 484 | return ret; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | /** |
| 489 | * isci_request_process_response_iu() - This function sets the status and |
| 490 | * response iu, in the task struct, from the request object for the upper |
| 491 | * layer driver. |
| 492 | * @sas_task: This parameter is the task struct from the upper layer driver. |
| 493 | * @resp_iu: This parameter points to the response iu of the completed request. |
| 494 | * @dev: This parameter specifies the linux device struct. |
| 495 | * |
| 496 | * none. |
| 497 | */ |
| 498 | static void isci_request_process_response_iu( |
| 499 | struct sas_task *task, |
| 500 | struct ssp_response_iu *resp_iu, |
| 501 | struct device *dev) |
| 502 | { |
| 503 | dev_dbg(dev, |
| 504 | "%s: resp_iu = %p " |
| 505 | "resp_iu->status = 0x%x,\nresp_iu->datapres = %d " |
| 506 | "resp_iu->response_data_len = %x, " |
| 507 | "resp_iu->sense_data_len = %x\nrepsonse data: ", |
| 508 | __func__, |
| 509 | resp_iu, |
| 510 | resp_iu->status, |
| 511 | resp_iu->datapres, |
| 512 | resp_iu->response_data_len, |
| 513 | resp_iu->sense_data_len); |
| 514 | |
| 515 | task->task_status.stat = resp_iu->status; |
| 516 | |
| 517 | /* libsas updates the task status fields based on the response iu. */ |
| 518 | sas_ssp_task_response(dev, task, resp_iu); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * isci_request_set_open_reject_status() - This function prepares the I/O |
| 523 | * completion for OPEN_REJECT conditions. |
| 524 | * @request: This parameter is the completed isci_request object. |
| 525 | * @response_ptr: This parameter specifies the service response for the I/O. |
| 526 | * @status_ptr: This parameter specifies the exec status for the I/O. |
| 527 | * @complete_to_host_ptr: This parameter specifies the action to be taken by |
| 528 | * the LLDD with respect to completing this request or forcing an abort |
| 529 | * condition on the I/O. |
| 530 | * @open_rej_reason: This parameter specifies the encoded reason for the |
| 531 | * abandon-class reject. |
| 532 | * |
| 533 | * none. |
| 534 | */ |
| 535 | static void isci_request_set_open_reject_status( |
| 536 | struct isci_request *request, |
| 537 | struct sas_task *task, |
| 538 | enum service_response *response_ptr, |
| 539 | enum exec_status *status_ptr, |
| 540 | enum isci_completion_selection *complete_to_host_ptr, |
| 541 | enum sas_open_rej_reason open_rej_reason) |
| 542 | { |
| 543 | /* Task in the target is done. */ |
| 544 | request->complete_in_target = true; |
| 545 | *response_ptr = SAS_TASK_UNDELIVERED; |
| 546 | *status_ptr = SAS_OPEN_REJECT; |
| 547 | *complete_to_host_ptr = isci_perform_normal_io_completion; |
| 548 | task->task_status.open_rej_reason = open_rej_reason; |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * isci_request_handle_controller_specific_errors() - This function decodes |
| 553 | * controller-specific I/O completion error conditions. |
| 554 | * @request: This parameter is the completed isci_request object. |
| 555 | * @response_ptr: This parameter specifies the service response for the I/O. |
| 556 | * @status_ptr: This parameter specifies the exec status for the I/O. |
| 557 | * @complete_to_host_ptr: This parameter specifies the action to be taken by |
| 558 | * the LLDD with respect to completing this request or forcing an abort |
| 559 | * condition on the I/O. |
| 560 | * |
| 561 | * none. |
| 562 | */ |
| 563 | static void isci_request_handle_controller_specific_errors( |
| 564 | struct isci_remote_device *isci_device, |
| 565 | struct isci_request *request, |
| 566 | struct sas_task *task, |
| 567 | enum service_response *response_ptr, |
| 568 | enum exec_status *status_ptr, |
| 569 | enum isci_completion_selection *complete_to_host_ptr) |
| 570 | { |
| 571 | unsigned int cstatus; |
| 572 | |
| 573 | cstatus = scic_request_get_controller_status( |
| 574 | request->sci_request_handle |
| 575 | ); |
| 576 | |
| 577 | dev_dbg(&request->isci_host->pdev->dev, |
| 578 | "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR " |
| 579 | "- controller status = 0x%x\n", |
| 580 | __func__, request, cstatus); |
| 581 | |
| 582 | /* Decode the controller-specific errors; most |
| 583 | * important is to recognize those conditions in which |
| 584 | * the target may still have a task outstanding that |
| 585 | * must be aborted. |
| 586 | * |
| 587 | * Note that there are SCU completion codes being |
| 588 | * named in the decode below for which SCIC has already |
| 589 | * done work to handle them in a way other than as |
| 590 | * a controller-specific completion code; these are left |
| 591 | * in the decode below for completeness sake. |
| 592 | */ |
| 593 | switch (cstatus) { |
| 594 | case SCU_TASK_DONE_DMASETUP_DIRERR: |
| 595 | /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */ |
| 596 | case SCU_TASK_DONE_XFERCNT_ERR: |
| 597 | /* Also SCU_TASK_DONE_SMP_UFI_ERR: */ |
| 598 | if (task->task_proto == SAS_PROTOCOL_SMP) { |
| 599 | /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */ |
| 600 | *response_ptr = SAS_TASK_COMPLETE; |
| 601 | |
| 602 | /* See if the device has been/is being stopped. Note |
| 603 | * that we ignore the quiesce state, since we are |
| 604 | * concerned about the actual device state. |
| 605 | */ |
| 606 | if ((isci_device->status == isci_stopping) || |
| 607 | (isci_device->status == isci_stopped)) |
| 608 | *status_ptr = SAS_DEVICE_UNKNOWN; |
| 609 | else |
| 610 | *status_ptr = SAS_ABORTED_TASK; |
| 611 | |
| 612 | request->complete_in_target = true; |
| 613 | |
| 614 | *complete_to_host_ptr = |
| 615 | isci_perform_normal_io_completion; |
| 616 | } else { |
| 617 | /* Task in the target is not done. */ |
| 618 | *response_ptr = SAS_TASK_UNDELIVERED; |
| 619 | |
| 620 | if ((isci_device->status == isci_stopping) || |
| 621 | (isci_device->status == isci_stopped)) |
| 622 | *status_ptr = SAS_DEVICE_UNKNOWN; |
| 623 | else |
| 624 | *status_ptr = SAM_STAT_TASK_ABORTED; |
| 625 | |
| 626 | request->complete_in_target = false; |
| 627 | |
| 628 | *complete_to_host_ptr = |
| 629 | isci_perform_error_io_completion; |
| 630 | } |
| 631 | |
| 632 | break; |
| 633 | |
| 634 | case SCU_TASK_DONE_CRC_ERR: |
| 635 | case SCU_TASK_DONE_NAK_CMD_ERR: |
| 636 | case SCU_TASK_DONE_EXCESS_DATA: |
| 637 | case SCU_TASK_DONE_UNEXP_FIS: |
| 638 | /* Also SCU_TASK_DONE_UNEXP_RESP: */ |
| 639 | case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */ |
| 640 | case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */ |
| 641 | case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */ |
| 642 | /* These are conditions in which the target |
| 643 | * has completed the task, so that no cleanup |
| 644 | * is necessary. |
| 645 | */ |
| 646 | *response_ptr = SAS_TASK_COMPLETE; |
| 647 | |
| 648 | /* See if the device has been/is being stopped. Note |
| 649 | * that we ignore the quiesce state, since we are |
| 650 | * concerned about the actual device state. |
| 651 | */ |
| 652 | if ((isci_device->status == isci_stopping) || |
| 653 | (isci_device->status == isci_stopped)) |
| 654 | *status_ptr = SAS_DEVICE_UNKNOWN; |
| 655 | else |
| 656 | *status_ptr = SAS_ABORTED_TASK; |
| 657 | |
| 658 | request->complete_in_target = true; |
| 659 | |
| 660 | *complete_to_host_ptr = isci_perform_normal_io_completion; |
| 661 | break; |
| 662 | |
| 663 | |
| 664 | /* Note that the only open reject completion codes seen here will be |
| 665 | * abandon-class codes; all others are automatically retried in the SCU. |
| 666 | */ |
| 667 | case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION: |
| 668 | |
| 669 | isci_request_set_open_reject_status( |
| 670 | request, task, response_ptr, status_ptr, |
| 671 | complete_to_host_ptr, SAS_OREJ_WRONG_DEST); |
| 672 | break; |
| 673 | |
| 674 | case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION: |
| 675 | |
| 676 | /* Note - the return of AB0 will change when |
| 677 | * libsas implements detection of zone violations. |
| 678 | */ |
| 679 | isci_request_set_open_reject_status( |
| 680 | request, task, response_ptr, status_ptr, |
| 681 | complete_to_host_ptr, SAS_OREJ_RESV_AB0); |
| 682 | break; |
| 683 | |
| 684 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1: |
| 685 | |
| 686 | isci_request_set_open_reject_status( |
| 687 | request, task, response_ptr, status_ptr, |
| 688 | complete_to_host_ptr, SAS_OREJ_RESV_AB1); |
| 689 | break; |
| 690 | |
| 691 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2: |
| 692 | |
| 693 | isci_request_set_open_reject_status( |
| 694 | request, task, response_ptr, status_ptr, |
| 695 | complete_to_host_ptr, SAS_OREJ_RESV_AB2); |
| 696 | break; |
| 697 | |
| 698 | case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3: |
| 699 | |
| 700 | isci_request_set_open_reject_status( |
| 701 | request, task, response_ptr, status_ptr, |
| 702 | complete_to_host_ptr, SAS_OREJ_RESV_AB3); |
| 703 | break; |
| 704 | |
| 705 | case SCU_TASK_OPEN_REJECT_BAD_DESTINATION: |
| 706 | |
| 707 | isci_request_set_open_reject_status( |
| 708 | request, task, response_ptr, status_ptr, |
| 709 | complete_to_host_ptr, SAS_OREJ_BAD_DEST); |
| 710 | break; |
| 711 | |
| 712 | case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY: |
| 713 | |
| 714 | isci_request_set_open_reject_status( |
| 715 | request, task, response_ptr, status_ptr, |
| 716 | complete_to_host_ptr, SAS_OREJ_STP_NORES); |
| 717 | break; |
| 718 | |
| 719 | case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED: |
| 720 | |
| 721 | isci_request_set_open_reject_status( |
| 722 | request, task, response_ptr, status_ptr, |
| 723 | complete_to_host_ptr, SAS_OREJ_EPROTO); |
| 724 | break; |
| 725 | |
| 726 | case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED: |
| 727 | |
| 728 | isci_request_set_open_reject_status( |
| 729 | request, task, response_ptr, status_ptr, |
| 730 | complete_to_host_ptr, SAS_OREJ_CONN_RATE); |
| 731 | break; |
| 732 | |
| 733 | case SCU_TASK_DONE_LL_R_ERR: |
| 734 | /* Also SCU_TASK_DONE_ACK_NAK_TO: */ |
| 735 | case SCU_TASK_DONE_LL_PERR: |
| 736 | case SCU_TASK_DONE_LL_SY_TERM: |
| 737 | /* Also SCU_TASK_DONE_NAK_ERR:*/ |
| 738 | case SCU_TASK_DONE_LL_LF_TERM: |
| 739 | /* Also SCU_TASK_DONE_DATA_LEN_ERR: */ |
| 740 | case SCU_TASK_DONE_LL_ABORT_ERR: |
| 741 | case SCU_TASK_DONE_SEQ_INV_TYPE: |
| 742 | /* Also SCU_TASK_DONE_UNEXP_XR: */ |
| 743 | case SCU_TASK_DONE_XR_IU_LEN_ERR: |
| 744 | case SCU_TASK_DONE_INV_FIS_LEN: |
| 745 | /* Also SCU_TASK_DONE_XR_WD_LEN: */ |
| 746 | case SCU_TASK_DONE_SDMA_ERR: |
| 747 | case SCU_TASK_DONE_OFFSET_ERR: |
| 748 | case SCU_TASK_DONE_MAX_PLD_ERR: |
| 749 | case SCU_TASK_DONE_LF_ERR: |
| 750 | case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */ |
| 751 | case SCU_TASK_DONE_SMP_LL_RX_ERR: |
| 752 | case SCU_TASK_DONE_UNEXP_DATA: |
| 753 | case SCU_TASK_DONE_UNEXP_SDBFIS: |
| 754 | case SCU_TASK_DONE_REG_ERR: |
| 755 | case SCU_TASK_DONE_SDB_ERR: |
| 756 | case SCU_TASK_DONE_TASK_ABORT: |
| 757 | default: |
| 758 | /* Task in the target is not done. */ |
| 759 | *response_ptr = SAS_TASK_UNDELIVERED; |
| 760 | *status_ptr = SAM_STAT_TASK_ABORTED; |
| 761 | request->complete_in_target = false; |
| 762 | |
| 763 | *complete_to_host_ptr = isci_perform_error_io_completion; |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * isci_task_save_for_upper_layer_completion() - This function saves the |
| 770 | * request for later completion to the upper layer driver. |
| 771 | * @host: This parameter is a pointer to the host on which the the request |
| 772 | * should be queued (either as an error or success). |
| 773 | * @request: This parameter is the completed request. |
| 774 | * @response: This parameter is the response code for the completed task. |
| 775 | * @status: This parameter is the status code for the completed task. |
| 776 | * |
| 777 | * none. |
| 778 | */ |
| 779 | static void isci_task_save_for_upper_layer_completion( |
| 780 | struct isci_host *host, |
| 781 | struct isci_request *request, |
| 782 | enum service_response response, |
| 783 | enum exec_status status, |
| 784 | enum isci_completion_selection task_notification_selection) |
| 785 | { |
| 786 | struct sas_task *task = isci_request_access_task(request); |
| 787 | |
Jeff Skirvin | ec6c963 | 2011-03-04 14:06:44 -0800 | [diff] [blame] | 788 | task_notification_selection |
| 789 | = isci_task_set_completion_status(task, response, status, |
| 790 | task_notification_selection); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 791 | |
| 792 | /* Tasks aborted specifically by a call to the lldd_abort_task |
| 793 | * function should not be completed to the host in the regular path. |
| 794 | */ |
| 795 | switch (task_notification_selection) { |
| 796 | |
| 797 | case isci_perform_normal_io_completion: |
| 798 | |
| 799 | /* Normal notification (task_done) */ |
| 800 | dev_dbg(&host->pdev->dev, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 801 | "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n", |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 802 | __func__, |
| 803 | task, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 804 | task->task_status.resp, response, |
| 805 | task->task_status.stat, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 806 | /* Add to the completed list. */ |
| 807 | list_add(&request->completed_node, |
| 808 | &host->requests_to_complete); |
Jeff Skirvin | ec6c963 | 2011-03-04 14:06:44 -0800 | [diff] [blame] | 809 | |
| 810 | /* Take the request off the device's pending request list. */ |
| 811 | list_del_init(&request->dev_node); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 812 | break; |
| 813 | |
| 814 | case isci_perform_aborted_io_completion: |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 815 | /* No notification to libsas because this request is |
| 816 | * already in the abort path. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 817 | */ |
| 818 | dev_warn(&host->pdev->dev, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 819 | "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n", |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 820 | __func__, |
| 821 | task, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 822 | task->task_status.resp, response, |
| 823 | task->task_status.stat, status); |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 824 | |
| 825 | /* Wake up whatever process was waiting for this |
| 826 | * request to complete. |
| 827 | */ |
| 828 | WARN_ON(request->io_request_completion == NULL); |
| 829 | |
| 830 | if (request->io_request_completion != NULL) { |
| 831 | |
| 832 | /* Signal whoever is waiting that this |
| 833 | * request is complete. |
| 834 | */ |
| 835 | complete(request->io_request_completion); |
| 836 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case isci_perform_error_io_completion: |
| 840 | /* Use sas_task_abort */ |
| 841 | dev_warn(&host->pdev->dev, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 842 | "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n", |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 843 | __func__, |
| 844 | task, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 845 | task->task_status.resp, response, |
| 846 | task->task_status.stat, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 847 | /* Add to the aborted list. */ |
| 848 | list_add(&request->completed_node, |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 849 | &host->requests_to_errorback); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | default: |
| 853 | dev_warn(&host->pdev->dev, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 854 | "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n", |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 855 | __func__, |
| 856 | task, |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 857 | task->task_status.resp, response, |
| 858 | task->task_status.stat, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 859 | |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 860 | /* Add to the error to libsas list. */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 861 | list_add(&request->completed_node, |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 862 | &host->requests_to_errorback); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /** |
| 868 | * isci_request_io_request_complete() - This function is called by the sci core |
| 869 | * when an io request completes. |
| 870 | * @isci_host: This parameter specifies the ISCI host object |
| 871 | * @request: This parameter is the completed isci_request object. |
| 872 | * @completion_status: This parameter specifies the completion status from the |
| 873 | * sci core. |
| 874 | * |
| 875 | * none. |
| 876 | */ |
| 877 | void isci_request_io_request_complete( |
| 878 | struct isci_host *isci_host, |
| 879 | struct isci_request *request, |
| 880 | enum sci_io_status completion_status) |
| 881 | { |
| 882 | struct sas_task *task = isci_request_access_task(request); |
| 883 | struct ssp_response_iu *resp_iu; |
| 884 | void *resp_buf; |
| 885 | unsigned long task_flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 886 | struct isci_remote_device *isci_device = request->isci_device; |
| 887 | enum service_response response = SAS_TASK_UNDELIVERED; |
| 888 | enum exec_status status = SAS_ABORTED_TASK; |
| 889 | enum isci_request_status request_status; |
| 890 | enum isci_completion_selection complete_to_host |
| 891 | = isci_perform_normal_io_completion; |
| 892 | |
| 893 | dev_dbg(&isci_host->pdev->dev, |
| 894 | "%s: request = %p, task = %p,\n" |
| 895 | "task->data_dir = %d completion_status = 0x%x\n", |
| 896 | __func__, |
| 897 | request, |
| 898 | task, |
| 899 | task->data_dir, |
| 900 | completion_status); |
| 901 | |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 902 | spin_lock(&request->state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 903 | request_status = isci_request_get_state(request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 904 | |
| 905 | /* Decode the request status. Note that if the request has been |
| 906 | * aborted by a task management function, we don't care |
| 907 | * what the status is. |
| 908 | */ |
| 909 | switch (request_status) { |
| 910 | |
| 911 | case aborted: |
| 912 | /* "aborted" indicates that the request was aborted by a task |
| 913 | * management function, since once a task management request is |
| 914 | * perfomed by the device, the request only completes because |
| 915 | * of the subsequent driver terminate. |
| 916 | * |
| 917 | * Aborted also means an external thread is explicitly managing |
| 918 | * this request, so that we do not complete it up the stack. |
| 919 | * |
| 920 | * The target is still there (since the TMF was successful). |
| 921 | */ |
| 922 | request->complete_in_target = true; |
| 923 | response = SAS_TASK_COMPLETE; |
| 924 | |
| 925 | /* See if the device has been/is being stopped. Note |
| 926 | * that we ignore the quiesce state, since we are |
| 927 | * concerned about the actual device state. |
| 928 | */ |
| 929 | if ((isci_device->status == isci_stopping) |
| 930 | || (isci_device->status == isci_stopped) |
| 931 | ) |
| 932 | status = SAS_DEVICE_UNKNOWN; |
| 933 | else |
| 934 | status = SAS_ABORTED_TASK; |
| 935 | |
| 936 | complete_to_host = isci_perform_aborted_io_completion; |
| 937 | /* This was an aborted request. */ |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 938 | |
| 939 | spin_unlock(&request->state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 940 | break; |
| 941 | |
| 942 | case aborting: |
| 943 | /* aborting means that the task management function tried and |
| 944 | * failed to abort the request. We need to note the request |
| 945 | * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the |
| 946 | * target as down. |
| 947 | * |
| 948 | * Aborting also means an external thread is explicitly managing |
| 949 | * this request, so that we do not complete it up the stack. |
| 950 | */ |
| 951 | request->complete_in_target = true; |
| 952 | response = SAS_TASK_UNDELIVERED; |
| 953 | |
| 954 | if ((isci_device->status == isci_stopping) || |
| 955 | (isci_device->status == isci_stopped)) |
| 956 | /* The device has been /is being stopped. Note that |
| 957 | * we ignore the quiesce state, since we are |
| 958 | * concerned about the actual device state. |
| 959 | */ |
| 960 | status = SAS_DEVICE_UNKNOWN; |
| 961 | else |
| 962 | status = SAS_PHY_DOWN; |
| 963 | |
| 964 | complete_to_host = isci_perform_aborted_io_completion; |
| 965 | |
| 966 | /* This was an aborted request. */ |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 967 | |
| 968 | spin_unlock(&request->state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 969 | break; |
| 970 | |
| 971 | case terminating: |
| 972 | |
| 973 | /* This was an terminated request. This happens when |
| 974 | * the I/O is being terminated because of an action on |
| 975 | * the device (reset, tear down, etc.), and the I/O needs |
| 976 | * to be completed up the stack. |
| 977 | */ |
| 978 | request->complete_in_target = true; |
| 979 | response = SAS_TASK_UNDELIVERED; |
| 980 | |
| 981 | /* See if the device has been/is being stopped. Note |
| 982 | * that we ignore the quiesce state, since we are |
| 983 | * concerned about the actual device state. |
| 984 | */ |
| 985 | if ((isci_device->status == isci_stopping) || |
| 986 | (isci_device->status == isci_stopped)) |
| 987 | status = SAS_DEVICE_UNKNOWN; |
| 988 | else |
| 989 | status = SAS_ABORTED_TASK; |
| 990 | |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 991 | complete_to_host = isci_perform_aborted_io_completion; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 992 | |
| 993 | /* This was a terminated request. */ |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 994 | |
| 995 | spin_unlock(&request->state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 996 | break; |
| 997 | |
| 998 | default: |
| 999 | |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 1000 | /* The request is done from an SCU HW perspective. */ |
| 1001 | request->status = completed; |
| 1002 | |
| 1003 | spin_unlock(&request->state_lock); |
| 1004 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1005 | /* This is an active request being completed from the core. */ |
| 1006 | switch (completion_status) { |
| 1007 | |
| 1008 | case SCI_IO_FAILURE_RESPONSE_VALID: |
| 1009 | dev_dbg(&isci_host->pdev->dev, |
| 1010 | "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n", |
| 1011 | __func__, |
| 1012 | request, |
| 1013 | task); |
| 1014 | |
| 1015 | if (sas_protocol_ata(task->task_proto)) { |
| 1016 | resp_buf |
| 1017 | = scic_stp_io_request_get_d2h_reg_address( |
| 1018 | request->sci_request_handle |
| 1019 | ); |
| 1020 | isci_request_process_stp_response(task, |
| 1021 | resp_buf |
| 1022 | ); |
| 1023 | |
| 1024 | } else if (SAS_PROTOCOL_SSP == task->task_proto) { |
| 1025 | |
| 1026 | /* crack the iu response buffer. */ |
| 1027 | resp_iu |
| 1028 | = scic_io_request_get_response_iu_address( |
| 1029 | request->sci_request_handle |
| 1030 | ); |
| 1031 | |
| 1032 | isci_request_process_response_iu(task, resp_iu, |
| 1033 | &isci_host->pdev->dev |
| 1034 | ); |
| 1035 | |
| 1036 | } else if (SAS_PROTOCOL_SMP == task->task_proto) { |
| 1037 | |
| 1038 | dev_err(&isci_host->pdev->dev, |
| 1039 | "%s: SCI_IO_FAILURE_RESPONSE_VALID: " |
| 1040 | "SAS_PROTOCOL_SMP protocol\n", |
| 1041 | __func__); |
| 1042 | |
| 1043 | } else |
| 1044 | dev_err(&isci_host->pdev->dev, |
| 1045 | "%s: unknown protocol\n", __func__); |
| 1046 | |
| 1047 | /* use the task status set in the task struct by the |
| 1048 | * isci_request_process_response_iu call. |
| 1049 | */ |
| 1050 | request->complete_in_target = true; |
| 1051 | response = task->task_status.resp; |
| 1052 | status = task->task_status.stat; |
| 1053 | break; |
| 1054 | |
| 1055 | case SCI_IO_SUCCESS: |
| 1056 | case SCI_IO_SUCCESS_IO_DONE_EARLY: |
| 1057 | |
| 1058 | response = SAS_TASK_COMPLETE; |
| 1059 | status = SAM_STAT_GOOD; |
| 1060 | request->complete_in_target = true; |
| 1061 | |
| 1062 | if (task->task_proto == SAS_PROTOCOL_SMP) { |
| 1063 | |
| 1064 | u8 *command_iu_address |
| 1065 | = scic_io_request_get_command_iu_address( |
| 1066 | request->sci_request_handle |
| 1067 | ); |
| 1068 | |
| 1069 | dev_dbg(&isci_host->pdev->dev, |
| 1070 | "%s: SMP protocol completion\n", |
| 1071 | __func__); |
| 1072 | |
| 1073 | sg_copy_from_buffer( |
| 1074 | &task->smp_task.smp_resp, 1, |
| 1075 | command_iu_address |
| 1076 | + sizeof(struct smp_request), |
| 1077 | sizeof(struct smp_resp) |
| 1078 | ); |
| 1079 | } else if (completion_status |
| 1080 | == SCI_IO_SUCCESS_IO_DONE_EARLY) { |
| 1081 | |
| 1082 | /* This was an SSP / STP / SATA transfer. |
| 1083 | * There is a possibility that less data than |
| 1084 | * the maximum was transferred. |
| 1085 | */ |
| 1086 | u32 transferred_length |
| 1087 | = scic_io_request_get_number_of_bytes_transferred( |
| 1088 | request->sci_request_handle); |
| 1089 | |
| 1090 | task->task_status.residual |
| 1091 | = task->total_xfer_len - transferred_length; |
| 1092 | |
| 1093 | /* If there were residual bytes, call this an |
| 1094 | * underrun. |
| 1095 | */ |
| 1096 | if (task->task_status.residual != 0) |
| 1097 | status = SAS_DATA_UNDERRUN; |
| 1098 | |
| 1099 | dev_dbg(&isci_host->pdev->dev, |
| 1100 | "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n", |
| 1101 | __func__, |
| 1102 | status); |
| 1103 | |
| 1104 | } else |
| 1105 | dev_dbg(&isci_host->pdev->dev, |
| 1106 | "%s: SCI_IO_SUCCESS\n", |
| 1107 | __func__); |
| 1108 | |
| 1109 | break; |
| 1110 | |
| 1111 | case SCI_IO_FAILURE_TERMINATED: |
| 1112 | dev_dbg(&isci_host->pdev->dev, |
| 1113 | "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n", |
| 1114 | __func__, |
| 1115 | request, |
| 1116 | task); |
| 1117 | |
| 1118 | /* The request was terminated explicitly. No handling |
| 1119 | * is needed in the SCSI error handler path. |
| 1120 | */ |
| 1121 | request->complete_in_target = true; |
| 1122 | response = SAS_TASK_UNDELIVERED; |
| 1123 | |
| 1124 | /* See if the device has been/is being stopped. Note |
| 1125 | * that we ignore the quiesce state, since we are |
| 1126 | * concerned about the actual device state. |
| 1127 | */ |
| 1128 | if ((isci_device->status == isci_stopping) || |
| 1129 | (isci_device->status == isci_stopped)) |
| 1130 | status = SAS_DEVICE_UNKNOWN; |
| 1131 | else |
| 1132 | status = SAS_ABORTED_TASK; |
| 1133 | |
| 1134 | complete_to_host = isci_perform_normal_io_completion; |
| 1135 | break; |
| 1136 | |
| 1137 | case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR: |
| 1138 | |
| 1139 | isci_request_handle_controller_specific_errors( |
| 1140 | isci_device, request, task, &response, &status, |
| 1141 | &complete_to_host); |
| 1142 | |
| 1143 | break; |
| 1144 | |
| 1145 | case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED: |
| 1146 | /* This is a special case, in that the I/O completion |
| 1147 | * is telling us that the device needs a reset. |
| 1148 | * In order for the device reset condition to be |
| 1149 | * noticed, the I/O has to be handled in the error |
| 1150 | * handler. Set the reset flag and cause the |
| 1151 | * SCSI error thread to be scheduled. |
| 1152 | */ |
| 1153 | spin_lock_irqsave(&task->task_state_lock, task_flags); |
| 1154 | task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; |
| 1155 | spin_unlock_irqrestore(&task->task_state_lock, task_flags); |
| 1156 | |
Jeff Skirvin | aa14510 | 2011-03-07 16:40:47 -0700 | [diff] [blame] | 1157 | /* Fail the I/O. */ |
| 1158 | response = SAS_TASK_UNDELIVERED; |
| 1159 | status = SAM_STAT_TASK_ABORTED; |
| 1160 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1161 | complete_to_host = isci_perform_error_io_completion; |
| 1162 | request->complete_in_target = false; |
| 1163 | break; |
| 1164 | |
| 1165 | default: |
| 1166 | /* Catch any otherwise unhandled error codes here. */ |
| 1167 | dev_warn(&isci_host->pdev->dev, |
| 1168 | "%s: invalid completion code: 0x%x - " |
| 1169 | "isci_request = %p\n", |
| 1170 | __func__, completion_status, request); |
| 1171 | |
| 1172 | response = SAS_TASK_UNDELIVERED; |
| 1173 | |
| 1174 | /* See if the device has been/is being stopped. Note |
| 1175 | * that we ignore the quiesce state, since we are |
| 1176 | * concerned about the actual device state. |
| 1177 | */ |
| 1178 | if ((isci_device->status == isci_stopping) || |
| 1179 | (isci_device->status == isci_stopped)) |
| 1180 | status = SAS_DEVICE_UNKNOWN; |
| 1181 | else |
| 1182 | status = SAS_ABORTED_TASK; |
| 1183 | |
| 1184 | complete_to_host = isci_perform_error_io_completion; |
| 1185 | request->complete_in_target = false; |
| 1186 | break; |
| 1187 | } |
| 1188 | break; |
| 1189 | } |
| 1190 | |
| 1191 | isci_request_unmap_sgl(request, isci_host->pdev); |
| 1192 | |
| 1193 | /* Put the completed request on the correct list */ |
| 1194 | isci_task_save_for_upper_layer_completion(isci_host, request, response, |
| 1195 | status, complete_to_host |
| 1196 | ); |
| 1197 | |
| 1198 | /* complete the io request to the core. */ |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1199 | scic_controller_complete_io(isci_host->core_controller, |
| 1200 | &isci_device->sci, |
| 1201 | request->sci_request_handle); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1202 | /* NULL the request handle so it cannot be completed or |
| 1203 | * terminated again, and to cause any calls into abort |
| 1204 | * task to recognize the already completed case. |
| 1205 | */ |
| 1206 | request->sci_request_handle = NULL; |
| 1207 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1208 | isci_host_can_dequeue(isci_host, 1); |
| 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * isci_request_io_request_get_transfer_length() - This function is called by |
| 1213 | * the sci core to retrieve the transfer length for a given request. |
| 1214 | * @request: This parameter is the isci_request object. |
| 1215 | * |
| 1216 | * length of transfer for specified request. |
| 1217 | */ |
| 1218 | u32 isci_request_io_request_get_transfer_length(struct isci_request *request) |
| 1219 | { |
| 1220 | struct sas_task *task = isci_request_access_task(request); |
| 1221 | |
| 1222 | dev_dbg(&request->isci_host->pdev->dev, |
| 1223 | "%s: total_xfer_len: %d\n", |
| 1224 | __func__, |
| 1225 | task->total_xfer_len); |
| 1226 | return task->total_xfer_len; |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | /** |
| 1231 | * isci_request_io_request_get_data_direction() - This function is called by |
| 1232 | * the sci core to retrieve the data direction for a given request. |
| 1233 | * @request: This parameter is the isci_request object. |
| 1234 | * |
| 1235 | * data direction for specified request. |
| 1236 | */ |
Dan Williams | 82d2992 | 2011-02-08 17:53:10 -0800 | [diff] [blame] | 1237 | enum dma_data_direction isci_request_io_request_get_data_direction( |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1238 | struct isci_request *request) |
| 1239 | { |
| 1240 | struct sas_task *task = isci_request_access_task(request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1241 | |
Dan Williams | 82d2992 | 2011-02-08 17:53:10 -0800 | [diff] [blame] | 1242 | return task->data_dir; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | /** |
| 1246 | * isci_request_sge_get_address_field() - This function is called by the sci |
| 1247 | * core to retrieve the address field contents for a given sge. |
| 1248 | * @request: This parameter is the isci_request object. |
| 1249 | * @sge_address: This parameter is the sge. |
| 1250 | * |
| 1251 | * physical address in the specified sge. |
| 1252 | */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1253 | |
| 1254 | |
| 1255 | /** |
| 1256 | * isci_request_sge_get_length_field() - This function is called by the sci |
| 1257 | * core to retrieve the length field contents for a given sge. |
| 1258 | * @request: This parameter is the isci_request object. |
| 1259 | * @sge_address: This parameter is the sge. |
| 1260 | * |
| 1261 | * length field value in the specified sge. |
| 1262 | */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1263 | |
| 1264 | |
| 1265 | /** |
| 1266 | * isci_request_ssp_io_request_get_cdb_address() - This function is called by |
| 1267 | * the sci core to retrieve the cdb address for a given request. |
| 1268 | * @request: This parameter is the isci_request object. |
| 1269 | * |
| 1270 | * cdb address for specified request. |
| 1271 | */ |
| 1272 | void *isci_request_ssp_io_request_get_cdb_address( |
| 1273 | struct isci_request *request) |
| 1274 | { |
| 1275 | struct sas_task *task = isci_request_access_task(request); |
| 1276 | |
| 1277 | dev_dbg(&request->isci_host->pdev->dev, |
| 1278 | "%s: request->task->ssp_task.cdb = %p\n", |
| 1279 | __func__, |
| 1280 | task->ssp_task.cdb); |
| 1281 | return task->ssp_task.cdb; |
| 1282 | } |
| 1283 | |
| 1284 | |
| 1285 | /** |
| 1286 | * isci_request_ssp_io_request_get_cdb_length() - This function is called by |
| 1287 | * the sci core to retrieve the cdb length for a given request. |
| 1288 | * @request: This parameter is the isci_request object. |
| 1289 | * |
| 1290 | * cdb length for specified request. |
| 1291 | */ |
| 1292 | u32 isci_request_ssp_io_request_get_cdb_length( |
| 1293 | struct isci_request *request) |
| 1294 | { |
| 1295 | return 16; |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | /** |
| 1300 | * isci_request_ssp_io_request_get_lun() - This function is called by the sci |
| 1301 | * core to retrieve the lun for a given request. |
| 1302 | * @request: This parameter is the isci_request object. |
| 1303 | * |
| 1304 | * lun for specified request. |
| 1305 | */ |
| 1306 | u32 isci_request_ssp_io_request_get_lun( |
| 1307 | struct isci_request *request) |
| 1308 | { |
| 1309 | struct sas_task *task = isci_request_access_task(request); |
| 1310 | |
| 1311 | #ifdef DEBUG |
| 1312 | int i; |
| 1313 | |
| 1314 | for (i = 0; i < 8; i++) |
| 1315 | dev_dbg(&request->isci_host->pdev->dev, |
Dan Williams | 83f5eee | 2011-02-18 09:25:15 -0800 | [diff] [blame] | 1316 | "%s: task->ssp_task.LUN[%d] = %x\n", |
| 1317 | __func__, i, task->ssp_task.LUN[i]); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1318 | |
| 1319 | #endif |
| 1320 | |
| 1321 | return task->ssp_task.LUN[0]; |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | /** |
| 1326 | * isci_request_ssp_io_request_get_task_attribute() - This function is called |
| 1327 | * by the sci core to retrieve the task attribute for a given request. |
| 1328 | * @request: This parameter is the isci_request object. |
| 1329 | * |
| 1330 | * task attribute for specified request. |
| 1331 | */ |
| 1332 | u32 isci_request_ssp_io_request_get_task_attribute( |
| 1333 | struct isci_request *request) |
| 1334 | { |
| 1335 | struct sas_task *task = isci_request_access_task(request); |
| 1336 | |
| 1337 | dev_dbg(&request->isci_host->pdev->dev, |
| 1338 | "%s: request->task->ssp_task.task_attr = %x\n", |
| 1339 | __func__, |
| 1340 | task->ssp_task.task_attr); |
| 1341 | |
| 1342 | return task->ssp_task.task_attr; |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | /** |
| 1347 | * isci_request_ssp_io_request_get_command_priority() - This function is called |
| 1348 | * by the sci core to retrieve the command priority for a given request. |
| 1349 | * @request: This parameter is the isci_request object. |
| 1350 | * |
| 1351 | * command priority for specified request. |
| 1352 | */ |
| 1353 | u32 isci_request_ssp_io_request_get_command_priority( |
| 1354 | struct isci_request *request) |
| 1355 | { |
| 1356 | struct sas_task *task = isci_request_access_task(request); |
| 1357 | |
| 1358 | dev_dbg(&request->isci_host->pdev->dev, |
| 1359 | "%s: request->task->ssp_task.task_prio = %x\n", |
| 1360 | __func__, |
| 1361 | task->ssp_task.task_prio); |
| 1362 | |
| 1363 | return task->ssp_task.task_prio; |
| 1364 | } |