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 <linux/completion.h> |
| 57 | #include "scic_task_request.h" |
| 58 | #include "scic_remote_device.h" |
| 59 | #include "scic_io_request.h" |
| 60 | #include "scic_sds_remote_device.h" |
| 61 | #include "scic_sds_remote_node_context.h" |
| 62 | #include "isci.h" |
| 63 | #include "request.h" |
| 64 | #include "sata.h" |
| 65 | #include "task.h" |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * isci_task_execute_task() - This function is one of the SAS Domain Template |
| 70 | * functions. This function is called by libsas to send a task down to |
| 71 | * hardware. |
| 72 | * @task: This parameter specifies the SAS task to send. |
| 73 | * @num: This parameter specifies the number of tasks to queue. |
| 74 | * @gfp_flags: This parameter specifies the context of this call. |
| 75 | * |
| 76 | * status, zero indicates success. |
| 77 | */ |
| 78 | int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags) |
| 79 | { |
| 80 | struct isci_host *isci_host; |
| 81 | struct isci_request *request = NULL; |
| 82 | struct isci_remote_device *device; |
| 83 | unsigned long flags; |
| 84 | unsigned long quiesce_flags = 0; |
| 85 | int ret; |
| 86 | enum sci_status status; |
| 87 | |
| 88 | |
| 89 | dev_dbg(task->dev->port->ha->dev, "%s: num=%d\n", __func__, num); |
| 90 | |
| 91 | if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { |
| 92 | |
| 93 | isci_task_complete_for_upper_layer( |
| 94 | task, |
| 95 | SAS_TASK_UNDELIVERED, |
| 96 | SAM_STAT_TASK_ABORTED, |
| 97 | isci_perform_normal_io_completion |
| 98 | ); |
| 99 | |
| 100 | return 0; /* The I/O was accepted (and failed). */ |
| 101 | } |
| 102 | if ((task->dev == NULL) || (task->dev->port == NULL)) { |
| 103 | |
| 104 | /* Indicate SAS_TASK_UNDELIVERED, so that the scsi midlayer |
| 105 | * removes the target. |
| 106 | */ |
| 107 | isci_task_complete_for_upper_layer( |
| 108 | task, |
| 109 | SAS_TASK_UNDELIVERED, |
| 110 | SAS_DEVICE_UNKNOWN, |
| 111 | isci_perform_normal_io_completion |
| 112 | ); |
| 113 | return 0; /* The I/O was accepted (and failed). */ |
| 114 | } |
| 115 | isci_host = isci_host_from_sas_ha(task->dev->port->ha); |
| 116 | |
| 117 | /* Check if we have room for more tasks */ |
| 118 | ret = isci_host_can_queue(isci_host, num); |
| 119 | |
| 120 | if (ret) { |
| 121 | dev_warn(task->dev->port->ha->dev, "%s: queue full\n", __func__); |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | do { |
| 126 | dev_dbg(task->dev->port->ha->dev, |
| 127 | "task = %p, num = %d; dev = %p; cmd = %p\n", |
| 128 | task, num, task->dev, task->uldd_task); |
| 129 | |
| 130 | if ((task->dev == NULL) || (task->dev->port == NULL)) { |
| 131 | dev_warn(task->dev->port->ha->dev, |
| 132 | "%s: task %p's port or dev == NULL!\n", |
| 133 | __func__, task); |
| 134 | |
| 135 | /* Indicate SAS_TASK_UNDELIVERED, so that the scsi |
| 136 | * midlayer removes the target. |
| 137 | */ |
| 138 | isci_task_complete_for_upper_layer( |
| 139 | task, |
| 140 | SAS_TASK_UNDELIVERED, |
| 141 | SAS_DEVICE_UNKNOWN, |
| 142 | isci_perform_normal_io_completion |
| 143 | ); |
| 144 | /* We don't have a valid host reference, so we |
| 145 | * can't control the host queueing condition. |
| 146 | */ |
| 147 | continue; |
| 148 | } |
| 149 | |
| 150 | device = isci_dev_from_domain_dev(task->dev); |
| 151 | |
| 152 | isci_host = isci_host_from_sas_ha(task->dev->port->ha); |
| 153 | |
| 154 | /* check if the controller hasn't started or if the device |
| 155 | * is ready but not accepting IO. |
| 156 | */ |
| 157 | if (device) { |
| 158 | |
| 159 | spin_lock_irqsave(&device->host_quiesce_lock, |
| 160 | quiesce_flags); |
| 161 | } |
| 162 | /* From this point onward, any process that needs to guarantee |
| 163 | * that there is no kernel I/O being started will have to wait |
| 164 | * for the quiesce spinlock. |
| 165 | */ |
| 166 | |
| 167 | if (isci_host_get_state(isci_host) == isci_starting || |
| 168 | (device && ((isci_remote_device_get_state(device) == isci_ready) || |
| 169 | (isci_remote_device_get_state(device) == isci_host_quiesce)))) { |
| 170 | |
| 171 | /* Forces a retry from scsi mid layer. */ |
| 172 | dev_warn(task->dev->port->ha->dev, |
| 173 | "%s: task %p: isci_host->status = %d, " |
| 174 | "device = %p\n", |
| 175 | __func__, |
| 176 | task, |
| 177 | isci_host_get_state(isci_host), |
| 178 | device); |
| 179 | |
| 180 | if (device) |
| 181 | dev_dbg(task->dev->port->ha->dev, |
| 182 | "%s: device->status = 0x%x\n", |
| 183 | __func__, |
| 184 | isci_remote_device_get_state(device)); |
| 185 | |
| 186 | /* Indicate QUEUE_FULL so that the scsi midlayer |
| 187 | * retries. |
| 188 | */ |
| 189 | isci_task_complete_for_upper_layer( |
| 190 | task, |
| 191 | SAS_TASK_COMPLETE, |
| 192 | SAS_QUEUE_FULL, |
| 193 | isci_perform_normal_io_completion |
| 194 | ); |
| 195 | isci_host_can_dequeue(isci_host, 1); |
| 196 | } |
| 197 | /* the device is going down... */ |
| 198 | else if (!device || (isci_ready_for_io != isci_remote_device_get_state(device))) { |
| 199 | |
| 200 | dev_dbg(task->dev->port->ha->dev, |
| 201 | "%s: task %p: isci_host->status = %d, " |
| 202 | "device = %p\n", |
| 203 | __func__, |
| 204 | task, |
| 205 | isci_host_get_state(isci_host), |
| 206 | device); |
| 207 | |
| 208 | if (device) |
| 209 | dev_dbg(task->dev->port->ha->dev, |
| 210 | "%s: device->status = 0x%x\n", |
| 211 | __func__, |
| 212 | isci_remote_device_get_state(device)); |
| 213 | |
| 214 | /* Indicate SAS_TASK_UNDELIVERED, so that the scsi |
| 215 | * midlayer removes the target. |
| 216 | */ |
| 217 | isci_task_complete_for_upper_layer( |
| 218 | task, |
| 219 | SAS_TASK_UNDELIVERED, |
| 220 | SAS_DEVICE_UNKNOWN, |
| 221 | isci_perform_normal_io_completion |
| 222 | ); |
| 223 | isci_host_can_dequeue(isci_host, 1); |
| 224 | |
| 225 | } else { |
| 226 | /* build and send the request. */ |
| 227 | status = isci_request_execute(isci_host, task, &request, |
| 228 | gfp_flags); |
| 229 | |
| 230 | if (status == SCI_SUCCESS) { |
| 231 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 232 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
| 233 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 234 | } else { |
| 235 | /* Indicate QUEUE_FULL so that the scsi |
| 236 | * midlayer retries. if the request |
| 237 | * failed for remote device reasons, |
| 238 | * it gets returned as |
| 239 | * SAS_TASK_UNDELIVERED next time |
| 240 | * through. |
| 241 | */ |
| 242 | isci_task_complete_for_upper_layer( |
| 243 | task, |
| 244 | SAS_TASK_COMPLETE, |
| 245 | SAS_QUEUE_FULL, |
| 246 | isci_perform_normal_io_completion |
| 247 | ); |
| 248 | isci_host_can_dequeue(isci_host, 1); |
| 249 | } |
| 250 | } |
| 251 | if (device) { |
| 252 | spin_unlock_irqrestore(&device->host_quiesce_lock, |
| 253 | quiesce_flags |
| 254 | ); |
| 255 | } |
| 256 | task = list_entry(task->list.next, struct sas_task, list); |
| 257 | } while (--num > 0); |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | |
| 263 | /** |
| 264 | * isci_task_request_build() - This function builds the task request object. |
| 265 | * @isci_host: This parameter specifies the ISCI host object |
| 266 | * @request: This parameter points to the isci_request object allocated in the |
| 267 | * request construct function. |
| 268 | * @tmf: This parameter is the task management struct to be built |
| 269 | * |
| 270 | * SCI_SUCCESS on successfull completion, or specific failure code. |
| 271 | */ |
| 272 | static enum sci_status isci_task_request_build( |
| 273 | struct isci_host *isci_host, |
| 274 | struct isci_request **isci_request, |
| 275 | struct isci_tmf *isci_tmf) |
| 276 | { |
| 277 | struct scic_sds_remote_device *sci_device; |
| 278 | enum sci_status status = SCI_FAILURE; |
| 279 | struct isci_request *request; |
| 280 | struct isci_remote_device *isci_device; |
| 281 | /* struct sci_sas_identify_address_frame_protocols dev_protocols; */ |
| 282 | struct smp_discover_response_protocols dev_protocols; |
| 283 | |
| 284 | |
| 285 | dev_dbg(&isci_host->pdev->dev, |
| 286 | "%s: isci_tmf = %p\n", __func__, isci_tmf); |
| 287 | |
| 288 | isci_device = isci_tmf->device; |
| 289 | sci_device = isci_device->sci_device_handle; |
| 290 | |
| 291 | /* do common allocation and init of request object. */ |
| 292 | status = isci_request_alloc_tmf( |
| 293 | isci_host, |
| 294 | isci_tmf, |
| 295 | &request, |
| 296 | isci_device, |
| 297 | GFP_ATOMIC |
| 298 | ); |
| 299 | |
| 300 | if (status != SCI_SUCCESS) |
| 301 | goto out; |
| 302 | |
| 303 | /* let the core do it's construct. */ |
| 304 | status = scic_task_request_construct( |
| 305 | isci_host->core_controller, |
| 306 | sci_device, |
| 307 | SCI_CONTROLLER_INVALID_IO_TAG, |
| 308 | request, |
| 309 | request->sci_request_mem_ptr, |
| 310 | &request->sci_request_handle |
| 311 | ); |
| 312 | |
| 313 | if (status != SCI_SUCCESS) { |
| 314 | dev_warn(&isci_host->pdev->dev, |
| 315 | "%s: scic_task_request_construct failed - " |
| 316 | "status = 0x%x\n", |
| 317 | __func__, |
| 318 | status); |
| 319 | goto errout; |
| 320 | } |
| 321 | |
| 322 | sci_object_set_association( |
| 323 | request->sci_request_handle, |
| 324 | request |
| 325 | ); |
| 326 | |
| 327 | scic_remote_device_get_protocols( |
| 328 | sci_device, |
| 329 | &dev_protocols |
| 330 | ); |
| 331 | |
| 332 | /* let the core do it's protocol |
| 333 | * specific construction. |
| 334 | */ |
| 335 | if (dev_protocols.u.bits.attached_ssp_target) { |
| 336 | |
| 337 | isci_tmf->proto = SAS_PROTOCOL_SSP; |
| 338 | status = scic_task_request_construct_ssp( |
| 339 | request->sci_request_handle |
| 340 | ); |
| 341 | if (status != SCI_SUCCESS) |
| 342 | goto errout; |
| 343 | } |
| 344 | |
| 345 | if (dev_protocols.u.bits.attached_stp_target) { |
| 346 | |
| 347 | isci_tmf->proto = SAS_PROTOCOL_SATA; |
| 348 | status = isci_sata_management_task_request_build(request); |
| 349 | |
| 350 | if (status != SCI_SUCCESS) |
| 351 | goto errout; |
| 352 | } |
| 353 | |
| 354 | goto out; |
| 355 | |
| 356 | errout: |
| 357 | |
| 358 | /* release the dma memory if we fail. */ |
| 359 | isci_request_free(isci_host, request); |
| 360 | request = NULL; |
| 361 | |
| 362 | out: |
| 363 | *isci_request = request; |
| 364 | return status; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * isci_tmf_timeout_cb() - This function is called as a kernel callback when |
| 369 | * the timeout period for the TMF has expired. |
| 370 | * |
| 371 | * |
| 372 | */ |
| 373 | static void isci_tmf_timeout_cb(void *tmf_request_arg) |
| 374 | { |
| 375 | struct isci_request *request = (struct isci_request *)tmf_request_arg; |
| 376 | struct isci_tmf *tmf = isci_request_access_tmf(request); |
| 377 | enum sci_status status; |
| 378 | |
| 379 | BUG_ON(request->ttype != tmf_task); |
| 380 | |
| 381 | /* This task management request has timed-out. Terminate the request |
| 382 | * so that the request eventually completes to the requestor in the |
| 383 | * request completion callback path. |
| 384 | */ |
| 385 | /* Note - the timer callback function itself has provided spinlock |
| 386 | * exclusion from the start and completion paths. No need to take |
| 387 | * the request->isci_host->scic_lock here. |
| 388 | */ |
| 389 | |
| 390 | if (tmf->timeout_timer != NULL) { |
| 391 | /* Call the users callback, if any. */ |
| 392 | if (tmf->cb_state_func != NULL) |
| 393 | tmf->cb_state_func(isci_tmf_timed_out, tmf, |
| 394 | tmf->cb_data); |
| 395 | |
| 396 | /* Terminate the TMF transmit request. */ |
| 397 | status = scic_controller_terminate_request( |
| 398 | request->isci_host->core_controller, |
| 399 | request->isci_device->sci_device_handle, |
| 400 | request->sci_request_handle |
| 401 | ); |
| 402 | |
| 403 | dev_dbg(&request->isci_host->pdev->dev, |
| 404 | "%s: tmf_request = %p; tmf = %p; status = %d\n", |
| 405 | __func__, request, tmf, status); |
| 406 | } else |
| 407 | dev_dbg(&request->isci_host->pdev->dev, |
| 408 | "%s: timer already canceled! " |
| 409 | "tmf_request = %p; tmf = %p\n", |
| 410 | __func__, request, tmf); |
| 411 | |
| 412 | /* No need to unlock since the caller to this callback is doing it for |
| 413 | * us. |
| 414 | * request->isci_host->scic_lock |
| 415 | */ |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * isci_task_execute_tmf() - This function builds and sends a task request, |
| 420 | * then waits for the completion. |
| 421 | * @isci_host: This parameter specifies the ISCI host object |
| 422 | * @tmf: This parameter is the pointer to the task management structure for |
| 423 | * this request. |
| 424 | * @timeout_ms: This parameter specifies the timeout period for the task |
| 425 | * management request. |
| 426 | * |
| 427 | * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes |
| 428 | * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED. |
| 429 | */ |
| 430 | int isci_task_execute_tmf( |
| 431 | struct isci_host *isci_host, |
| 432 | struct isci_tmf *tmf, |
| 433 | unsigned long timeout_ms) |
| 434 | { |
| 435 | DECLARE_COMPLETION_ONSTACK(completion); |
| 436 | enum sci_status status = SCI_FAILURE; |
| 437 | struct scic_sds_remote_device *sci_device; |
| 438 | struct isci_remote_device *isci_device = tmf->device; |
| 439 | struct isci_request *request; |
| 440 | int ret = TMF_RESP_FUNC_FAILED; |
| 441 | unsigned long flags; |
| 442 | |
| 443 | /* sanity check, return TMF_RESP_FUNC_FAILED |
| 444 | * if the device is not there and ready. |
| 445 | */ |
| 446 | if (!isci_device || |
| 447 | ((isci_ready_for_io != isci_remote_device_get_state(isci_device)) && |
| 448 | (isci_host_quiesce != isci_remote_device_get_state(isci_device)))) { |
| 449 | dev_dbg(&isci_host->pdev->dev, |
| 450 | "%s: isci_device = %p not ready (%d)\n", |
| 451 | __func__, |
| 452 | isci_device, |
| 453 | isci_remote_device_get_state(isci_device)); |
| 454 | return TMF_RESP_FUNC_FAILED; |
| 455 | } else |
| 456 | dev_dbg(&isci_host->pdev->dev, |
| 457 | "%s: isci_device = %p\n", |
| 458 | __func__, isci_device); |
| 459 | |
| 460 | sci_device = isci_device->sci_device_handle; |
| 461 | |
| 462 | /* Assign the pointer to the TMF's completion kernel wait structure. */ |
| 463 | tmf->complete = &completion; |
| 464 | |
| 465 | isci_task_request_build( |
| 466 | isci_host, |
| 467 | &request, |
| 468 | tmf |
| 469 | ); |
| 470 | |
| 471 | if (!request) { |
| 472 | dev_warn(&isci_host->pdev->dev, |
| 473 | "%s: isci_task_request_build failed\n", |
| 474 | __func__); |
| 475 | return TMF_RESP_FUNC_FAILED; |
| 476 | } |
| 477 | |
| 478 | /* Allocate the TMF timeout timer. */ |
| 479 | tmf->timeout_timer = isci_timer_create( |
| 480 | &isci_host->timer_list_struct, |
| 481 | isci_host, |
| 482 | request, |
| 483 | isci_tmf_timeout_cb |
| 484 | ); |
| 485 | |
| 486 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 487 | |
| 488 | /* Start the timer. */ |
| 489 | if (tmf->timeout_timer) |
| 490 | isci_timer_start(tmf->timeout_timer, timeout_ms); |
| 491 | else |
| 492 | dev_warn(&isci_host->pdev->dev, |
| 493 | "%s: isci_timer_create failed!!!!\n", |
| 494 | __func__); |
| 495 | |
| 496 | /* start the TMF io. */ |
| 497 | status = scic_controller_start_task( |
| 498 | isci_host->core_controller, |
| 499 | sci_device, |
| 500 | request->sci_request_handle, |
| 501 | SCI_CONTROLLER_INVALID_IO_TAG |
| 502 | ); |
| 503 | |
| 504 | if (status != SCI_SUCCESS) { |
| 505 | dev_warn(&isci_host->pdev->dev, |
| 506 | "%s: start_io failed - status = 0x%x, request = %p\n", |
| 507 | __func__, |
| 508 | status, |
| 509 | request); |
| 510 | goto cleanup_request; |
| 511 | } |
| 512 | |
| 513 | /* Call the users callback, if any. */ |
| 514 | if (tmf->cb_state_func != NULL) |
| 515 | tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data); |
| 516 | |
| 517 | /* Change the state of the TMF-bearing request to "started". */ |
| 518 | isci_request_change_state(request, started); |
| 519 | |
| 520 | /* add the request to the remote device request list. */ |
| 521 | list_add(&request->dev_node, &isci_device->reqs_in_process); |
| 522 | |
| 523 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 524 | |
| 525 | /* Wait for the TMF to complete, or a timeout. */ |
| 526 | wait_for_completion(&completion); |
| 527 | |
| 528 | isci_print_tmf(tmf); |
| 529 | |
| 530 | if (tmf->status == SCI_SUCCESS) |
| 531 | ret = TMF_RESP_FUNC_COMPLETE; |
| 532 | else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) { |
| 533 | dev_dbg(&isci_host->pdev->dev, |
| 534 | "%s: tmf.status == " |
| 535 | "SCI_FAILURE_IO_RESPONSE_VALID\n", |
| 536 | __func__); |
| 537 | ret = TMF_RESP_FUNC_COMPLETE; |
| 538 | } |
| 539 | /* Else - leave the default "failed" status alone. */ |
| 540 | |
| 541 | dev_dbg(&isci_host->pdev->dev, |
| 542 | "%s: completed request = %p\n", |
| 543 | __func__, |
| 544 | request); |
| 545 | |
| 546 | if (request->io_request_completion != NULL) { |
| 547 | |
| 548 | /* The fact that this is non-NULL for a TMF request |
| 549 | * means there is a thread waiting for this TMF to |
| 550 | * finish. |
| 551 | */ |
| 552 | complete(request->io_request_completion); |
| 553 | } |
| 554 | |
| 555 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 556 | |
| 557 | cleanup_request: |
| 558 | |
| 559 | /* Clean up the timer if needed. */ |
| 560 | if (tmf->timeout_timer) { |
| 561 | isci_timer_stop(tmf->timeout_timer); |
| 562 | isci_timer_free(&isci_host->timer_list_struct, |
| 563 | tmf->timeout_timer); |
| 564 | tmf->timeout_timer = NULL; |
| 565 | } |
| 566 | |
| 567 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 568 | |
| 569 | isci_request_free(isci_host, request); |
| 570 | |
| 571 | return ret; |
| 572 | } |
| 573 | |
| 574 | void isci_task_build_tmf( |
| 575 | struct isci_tmf *tmf, |
| 576 | struct isci_remote_device *isci_device, |
| 577 | enum isci_tmf_function_codes code, |
| 578 | void (*tmf_sent_cb)(enum isci_tmf_cb_state, |
| 579 | struct isci_tmf *, |
| 580 | void *), |
| 581 | void *cb_data) |
| 582 | { |
| 583 | dev_dbg(&isci_device->isci_port->isci_host->pdev->dev, |
| 584 | "%s: isci_device = %p\n", __func__, isci_device); |
| 585 | |
| 586 | memset(tmf, 0, sizeof(*tmf)); |
| 587 | |
| 588 | tmf->device = isci_device; |
| 589 | tmf->tmf_code = code; |
| 590 | tmf->timeout_timer = NULL; |
| 591 | tmf->cb_state_func = tmf_sent_cb; |
| 592 | tmf->cb_data = cb_data; |
| 593 | } |
| 594 | |
| 595 | static struct isci_request *isci_task_get_request_from_task( |
| 596 | struct sas_task *task, |
| 597 | struct isci_host **isci_host, |
| 598 | struct isci_remote_device **isci_device) |
| 599 | { |
| 600 | |
| 601 | struct isci_request *request = NULL; |
| 602 | unsigned long flags; |
| 603 | |
| 604 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 605 | |
| 606 | request = task->lldd_task; |
| 607 | |
| 608 | /* If task is already done, the request isn't valid */ |
| 609 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE) && |
| 610 | (task->task_state_flags & SAS_TASK_AT_INITIATOR) && |
| 611 | (request != NULL)) { |
| 612 | |
| 613 | if (isci_host != NULL) |
| 614 | *isci_host = request->isci_host; |
| 615 | |
| 616 | if (isci_device != NULL) |
| 617 | *isci_device = request->isci_device; |
| 618 | } |
| 619 | |
| 620 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 621 | |
| 622 | return request; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * isci_task_validate_request_to_abort() - This function checks the given I/O |
| 627 | * against the "started" state. If the request is still "started", it's |
| 628 | * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD |
| 629 | * BEFORE CALLING THIS FUNCTION. |
| 630 | * @isci_request: This parameter specifies the request object to control. |
| 631 | * @isci_host: This parameter specifies the ISCI host object |
| 632 | * @isci_device: This is the device to which the request is pending. |
| 633 | * @aborted_io_completion: This is a completion structure that will be added to |
| 634 | * the request in case it is changed to aborting; this completion is |
| 635 | * triggered when the request is fully completed. |
| 636 | * |
| 637 | * Either "started" on successful change of the task status to "aborted", or |
| 638 | * "unallocated" if the task cannot be controlled. |
| 639 | */ |
| 640 | static enum isci_request_status isci_task_validate_request_to_abort( |
| 641 | struct isci_request *isci_request, |
| 642 | struct isci_host *isci_host, |
| 643 | struct isci_remote_device *isci_device, |
| 644 | struct completion *aborted_io_completion) |
| 645 | { |
| 646 | enum isci_request_status old_state = unallocated; |
| 647 | |
| 648 | /* Only abort the task if it's in the |
| 649 | * device's request_in_process list |
| 650 | */ |
| 651 | if (isci_request && !list_empty(&isci_request->dev_node)) { |
| 652 | old_state = isci_request_change_started_to_aborted( |
| 653 | isci_request, aborted_io_completion); |
| 654 | |
| 655 | /* Only abort requests in the started state. */ |
| 656 | if (old_state != started) |
| 657 | old_state = unallocated; |
| 658 | } |
| 659 | |
| 660 | return old_state; |
| 661 | } |
| 662 | |
| 663 | static void isci_request_cleanup_completed_loiterer( |
| 664 | struct isci_host *isci_host, |
| 665 | struct isci_remote_device *isci_device, |
| 666 | struct isci_request *isci_request) |
| 667 | { |
| 668 | struct sas_task *task = isci_request_access_task(isci_request); |
| 669 | unsigned long flags; |
| 670 | |
| 671 | dev_dbg(&isci_host->pdev->dev, |
| 672 | "%s: isci_device=%p, request=%p, task=%p\n", |
| 673 | __func__, isci_device, isci_request, |
| 674 | isci_request->ttype_ptr.io_task_ptr); |
| 675 | |
| 676 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 677 | list_del_init(&isci_request->dev_node); |
| 678 | if (task != NULL) |
| 679 | task->lldd_task = NULL; |
| 680 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 681 | |
| 682 | isci_request_free(isci_host, isci_request); |
| 683 | } |
| 684 | /** |
| 685 | * isci_terminate_request_core() - This function will terminate the given |
| 686 | * request, and wait for it to complete. This function must only be called |
| 687 | * from a thread that can wait. Note that the request is terminated and |
| 688 | * completed (back to the host, if started there). |
| 689 | * @isci_host: This SCU. |
| 690 | * @isci_device: The target. |
| 691 | * @isci_request: The I/O request to be terminated. |
| 692 | * |
| 693 | * |
| 694 | */ |
| 695 | static void isci_terminate_request_core( |
| 696 | struct isci_host *isci_host, |
| 697 | struct isci_remote_device *isci_device, |
| 698 | struct isci_request *isci_request, |
| 699 | struct completion *request_completion) |
| 700 | { |
| 701 | enum sci_status status = SCI_SUCCESS; |
| 702 | bool was_terminated = false; |
| 703 | bool needs_cleanup_handling = false; |
| 704 | enum isci_request_status request_status; |
| 705 | unsigned long flags; |
| 706 | |
| 707 | dev_dbg(&isci_host->pdev->dev, |
| 708 | "%s: device = %p; request = %p\n", |
| 709 | __func__, isci_device, isci_request); |
| 710 | |
| 711 | /* Peek at the current status of the request. This will tell |
| 712 | * us if there was special handling on the request such that it |
| 713 | * needs to be detached and freed here. |
| 714 | */ |
| 715 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 716 | request_status = isci_request_get_state(isci_request); |
| 717 | |
| 718 | /* TMFs are in their own thread */ |
| 719 | if ((isci_request->ttype == io_task) && |
| 720 | ((request_status == aborted) || |
| 721 | (request_status == aborting) || |
| 722 | (request_status == terminating))) |
| 723 | /* The completion routine won't free a request in |
| 724 | * the aborted/aborting/terminating state, so we do |
| 725 | * it here. |
| 726 | */ |
| 727 | needs_cleanup_handling = true; |
| 728 | |
| 729 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 730 | |
| 731 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 732 | /* Make sure the request wasn't just sitting around signalling |
| 733 | * device condition (if the request handle is NULL, then the |
| 734 | * request completed but needed additional handling here). |
| 735 | */ |
| 736 | if (isci_request->sci_request_handle != NULL) { |
| 737 | was_terminated = true; |
| 738 | status = scic_controller_terminate_request( |
| 739 | isci_host->core_controller, |
| 740 | isci_device->sci_device_handle, |
| 741 | isci_request->sci_request_handle |
| 742 | ); |
| 743 | } |
| 744 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 745 | |
| 746 | /* |
| 747 | * The only time the request to terminate will |
| 748 | * fail is when the io request is completed and |
| 749 | * being aborted. |
| 750 | */ |
| 751 | if (status != SCI_SUCCESS) |
| 752 | dev_err(&isci_host->pdev->dev, |
| 753 | "%s: scic_controller_terminate_request" |
| 754 | " returned = 0x%x\n", |
| 755 | __func__, |
| 756 | status); |
| 757 | else { |
| 758 | if (was_terminated) { |
| 759 | dev_dbg(&isci_host->pdev->dev, |
| 760 | "%s: before completion wait (%p)\n", |
| 761 | __func__, |
| 762 | request_completion); |
| 763 | |
| 764 | /* Wait here for the request to complete. */ |
| 765 | wait_for_completion(request_completion); |
| 766 | |
| 767 | dev_dbg(&isci_host->pdev->dev, |
| 768 | "%s: after completion wait (%p)\n", |
| 769 | __func__, |
| 770 | request_completion); |
| 771 | } |
| 772 | |
| 773 | if (needs_cleanup_handling) |
| 774 | isci_request_cleanup_completed_loiterer( |
| 775 | isci_host, isci_device, isci_request |
| 776 | ); |
| 777 | } |
| 778 | } |
| 779 | static void isci_terminate_request( |
| 780 | struct isci_host *isci_host, |
| 781 | struct isci_remote_device *isci_device, |
| 782 | struct isci_request *isci_request, |
| 783 | enum isci_request_status new_request_state) |
| 784 | { |
| 785 | enum isci_request_status old_state; |
| 786 | |
| 787 | DECLARE_COMPLETION_ONSTACK(request_completion); |
| 788 | unsigned long flags; |
| 789 | |
| 790 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 791 | |
| 792 | /* Change state to "new_request_state" if it is currently "started" */ |
| 793 | old_state = isci_request_change_started_to_newstate( |
| 794 | isci_request, |
| 795 | &request_completion, |
| 796 | new_request_state |
| 797 | ); |
| 798 | |
| 799 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 800 | |
| 801 | if (old_state == started) |
| 802 | /* This request was not already being aborted. If it had been, |
| 803 | * then the aborting I/O (ie. the TMF request) would not be in |
| 804 | * the aborting state, and thus would be terminated here. Note |
| 805 | * that since the TMF completion's call to the kernel function |
| 806 | * "complete()" does not happen until the pending I/O request |
| 807 | * terminate fully completes, we do not have to implement a |
| 808 | * special wait here for already aborting requests - the |
| 809 | * termination of the TMF request will force the request |
| 810 | * to finish it's already started terminate. |
| 811 | */ |
| 812 | isci_terminate_request_core(isci_host, isci_device, |
| 813 | isci_request, &request_completion); |
| 814 | } |
| 815 | |
| 816 | /** |
| 817 | * isci_terminate_pending_requests() - This function will change the all of the |
| 818 | * requests on the given device's state to "aborting", will terminate the |
| 819 | * requests, and wait for them to complete. This function must only be |
| 820 | * called from a thread that can wait. Note that the requests are all |
| 821 | * terminated and completed (back to the host, if started there). |
| 822 | * @isci_host: This parameter specifies SCU. |
| 823 | * @isci_device: This parameter specifies the target. |
| 824 | * |
| 825 | * |
| 826 | */ |
| 827 | void isci_terminate_pending_requests( |
| 828 | struct isci_host *isci_host, |
| 829 | struct isci_remote_device *isci_device, |
| 830 | enum isci_request_status new_request_state) |
| 831 | { |
| 832 | struct isci_request *isci_request; |
| 833 | struct sas_task *task; |
| 834 | bool done = false; |
| 835 | unsigned long flags; |
| 836 | |
| 837 | dev_dbg(&isci_host->pdev->dev, |
| 838 | "%s: isci_device = %p (new request state = %d)\n", |
| 839 | __func__, isci_device, new_request_state); |
| 840 | |
| 841 | #define ISCI_TERMINATE_SHOW_PENDING_REQUESTS |
| 842 | #ifdef ISCI_TERMINATE_SHOW_PENDING_REQUESTS |
| 843 | { |
| 844 | struct isci_request *request; |
| 845 | |
| 846 | /* Only abort the task if it's in the |
| 847 | * device's request_in_process list |
| 848 | */ |
| 849 | list_for_each_entry(request, |
| 850 | &isci_device->reqs_in_process, |
| 851 | dev_node) |
| 852 | dev_dbg(&isci_host->pdev->dev, |
| 853 | "%s: isci_device = %p; request is on " |
| 854 | "reqs_in_process list: %p\n", |
| 855 | __func__, isci_device, request); |
| 856 | } |
| 857 | #endif /* ISCI_TERMINATE_SHOW_PENDING_REQUESTS */ |
| 858 | |
| 859 | /* Clean up all pending requests. */ |
| 860 | do { |
| 861 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 862 | |
| 863 | if (list_empty(&isci_device->reqs_in_process)) { |
| 864 | |
| 865 | done = true; |
| 866 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 867 | |
| 868 | dev_dbg(&isci_host->pdev->dev, |
| 869 | "%s: isci_device = %p; done.\n", |
| 870 | __func__, isci_device); |
| 871 | } else { |
| 872 | /* The list was not empty - grab the first request. */ |
| 873 | isci_request = list_first_entry( |
| 874 | &isci_device->reqs_in_process, |
| 875 | struct isci_request, dev_node |
| 876 | ); |
| 877 | /* Note that we are not expecting to have to control |
| 878 | * the target to abort the request. |
| 879 | */ |
| 880 | isci_request->complete_in_target = true; |
| 881 | |
| 882 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 883 | |
| 884 | /* Get the libsas task reference. */ |
| 885 | task = isci_request_access_task(isci_request); |
| 886 | |
| 887 | dev_dbg(&isci_host->pdev->dev, |
| 888 | "%s: isci_device=%p request=%p; task=%p\n", |
| 889 | __func__, isci_device, isci_request, task); |
| 890 | |
| 891 | /* Mark all still pending I/O with the selected next |
| 892 | * state. |
| 893 | */ |
| 894 | isci_terminate_request(isci_host, isci_device, |
| 895 | isci_request, new_request_state |
| 896 | ); |
| 897 | |
| 898 | /* Set the 'done' state on the task. */ |
| 899 | if (task) |
| 900 | isci_task_all_done(task); |
| 901 | } |
| 902 | } while (!done); |
| 903 | } |
| 904 | |
| 905 | /** |
| 906 | * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain |
| 907 | * Template functions. |
| 908 | * @lun: This parameter specifies the lun to be reset. |
| 909 | * |
| 910 | * status, zero indicates success. |
| 911 | */ |
| 912 | static int isci_task_send_lu_reset_sas( |
| 913 | struct isci_host *isci_host, |
| 914 | struct isci_remote_device *isci_device, |
| 915 | u8 *lun) |
| 916 | { |
| 917 | struct isci_tmf tmf; |
| 918 | int ret = TMF_RESP_FUNC_FAILED; |
| 919 | |
| 920 | dev_dbg(&isci_host->pdev->dev, |
| 921 | "%s: isci_host = %p, isci_device = %p\n", |
| 922 | __func__, isci_host, isci_device); |
| 923 | /* Send the LUN reset to the target. By the time the call returns, |
| 924 | * the TMF has fully exected in the target (in which case the return |
| 925 | * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or |
| 926 | * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED"). |
| 927 | */ |
| 928 | isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_lun_reset, NULL, |
| 929 | NULL); |
| 930 | |
| 931 | #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */ |
| 932 | ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_LU_RESET_TIMEOUT_MS); |
| 933 | |
| 934 | if (ret == TMF_RESP_FUNC_COMPLETE) |
| 935 | dev_dbg(&isci_host->pdev->dev, |
| 936 | "%s: %p: TMF_LU_RESET passed\n", |
| 937 | __func__, isci_device); |
| 938 | else |
| 939 | dev_dbg(&isci_host->pdev->dev, |
| 940 | "%s: %p: TMF_LU_RESET failed (%x)\n", |
| 941 | __func__, isci_device, ret); |
| 942 | |
| 943 | return ret; |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * isci_task_lu_reset() - This function is one of the SAS Domain Template |
| 948 | * functions. This is one of the Task Management functoins called by libsas, |
| 949 | * to reset the given lun. Note the assumption that while this call is |
| 950 | * executing, no I/O will be sent by the host to the device. |
| 951 | * @lun: This parameter specifies the lun to be reset. |
| 952 | * |
| 953 | * status, zero indicates success. |
| 954 | */ |
| 955 | int isci_task_lu_reset( |
| 956 | struct domain_device *domain_device, |
| 957 | u8 *lun) |
| 958 | { |
| 959 | struct isci_host *isci_host = NULL; |
| 960 | struct isci_remote_device *isci_device = NULL; |
| 961 | int ret; |
| 962 | bool device_stopping = false; |
| 963 | |
| 964 | if (domain_device == NULL) { |
| 965 | pr_warn("%s: domain_device == NULL\n", __func__); |
| 966 | return TMF_RESP_FUNC_FAILED; |
| 967 | } |
| 968 | |
| 969 | isci_device = isci_dev_from_domain_dev(domain_device); |
| 970 | |
| 971 | if (domain_device->port != NULL) |
| 972 | isci_host = isci_host_from_sas_ha(domain_device->port->ha); |
| 973 | |
| 974 | pr_debug("%s: domain_device=%p, isci_host=%p; isci_device=%p\n", |
| 975 | __func__, domain_device, isci_host, isci_device); |
| 976 | |
| 977 | if (isci_device != NULL) |
| 978 | device_stopping = (isci_device->status == isci_stopping) |
| 979 | || (isci_device->status == isci_stopped); |
| 980 | |
| 981 | /* If there is a device reset pending on any request in the |
| 982 | * device's list, fail this LUN reset request in order to |
| 983 | * escalate to the device reset. |
| 984 | */ |
| 985 | if ((isci_device == NULL) || |
| 986 | (isci_host == NULL) || |
| 987 | ((isci_host != NULL) && |
| 988 | (isci_device != NULL) && |
| 989 | (device_stopping || |
| 990 | (isci_device_is_reset_pending(isci_host, isci_device))))) { |
| 991 | dev_warn(&isci_host->pdev->dev, |
| 992 | "%s: No dev (%p), no host (%p), or " |
| 993 | "RESET PENDING: domain_device=%p\n", |
| 994 | __func__, isci_device, isci_host, domain_device); |
| 995 | return TMF_RESP_FUNC_FAILED; |
| 996 | } |
| 997 | |
| 998 | /* Stop I/O to the remote device. */ |
| 999 | isci_device_set_host_quiesce_lock_state(isci_device, true); |
| 1000 | |
| 1001 | /* Send the task management part of the reset. */ |
| 1002 | if (sas_protocol_ata(domain_device->tproto)) { |
| 1003 | ret = isci_task_send_lu_reset_sata( |
| 1004 | isci_host, isci_device, lun |
| 1005 | ); |
| 1006 | } else |
| 1007 | ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun); |
| 1008 | |
| 1009 | /* If the LUN reset worked, all the I/O can now be terminated. */ |
| 1010 | if (ret == TMF_RESP_FUNC_COMPLETE) |
| 1011 | /* Terminate all I/O now. */ |
| 1012 | isci_terminate_pending_requests(isci_host, |
| 1013 | isci_device, |
| 1014 | terminating); |
| 1015 | |
| 1016 | /* Resume I/O to the remote device. */ |
| 1017 | isci_device_set_host_quiesce_lock_state(isci_device, false); |
| 1018 | |
| 1019 | return ret; |
| 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | /* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */ |
| 1024 | int isci_task_clear_nexus_port(struct asd_sas_port *port) |
| 1025 | { |
| 1026 | return TMF_RESP_FUNC_FAILED; |
| 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | |
| 1031 | int isci_task_clear_nexus_ha(struct sas_ha_struct *ha) |
| 1032 | { |
| 1033 | return TMF_RESP_FUNC_FAILED; |
| 1034 | } |
| 1035 | |
| 1036 | int isci_task_I_T_nexus_reset(struct domain_device *dev) |
| 1037 | { |
| 1038 | return TMF_RESP_FUNC_FAILED; |
| 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | /* Task Management Functions. Must be called from process context. */ |
| 1043 | |
| 1044 | /** |
| 1045 | * isci_abort_task_process_cb() - This is a helper function for the abort task |
| 1046 | * TMF command. It manages the request state with respect to the successful |
| 1047 | * transmission / completion of the abort task request. |
| 1048 | * @cb_state: This parameter specifies when this function was called - after |
| 1049 | * the TMF request has been started and after it has timed-out. |
| 1050 | * @tmf: This parameter specifies the TMF in progress. |
| 1051 | * |
| 1052 | * |
| 1053 | */ |
| 1054 | static void isci_abort_task_process_cb( |
| 1055 | enum isci_tmf_cb_state cb_state, |
| 1056 | struct isci_tmf *tmf, |
| 1057 | void *cb_data) |
| 1058 | { |
| 1059 | struct isci_request *old_request; |
| 1060 | |
| 1061 | old_request = (struct isci_request *)cb_data; |
| 1062 | |
| 1063 | dev_dbg(&old_request->isci_host->pdev->dev, |
| 1064 | "%s: tmf=%p, old_request=%p\n", |
| 1065 | __func__, tmf, old_request); |
| 1066 | |
| 1067 | switch (cb_state) { |
| 1068 | |
| 1069 | case isci_tmf_started: |
| 1070 | /* The TMF has been started. Nothing to do here, since the |
| 1071 | * request state was already set to "aborted" by the abort |
| 1072 | * task function. |
| 1073 | */ |
| 1074 | BUG_ON(old_request->status != aborted); |
| 1075 | break; |
| 1076 | |
| 1077 | case isci_tmf_timed_out: |
| 1078 | |
| 1079 | /* Set the task's state to "aborting", since the abort task |
| 1080 | * function thread set it to "aborted" (above) in anticipation |
| 1081 | * of the task management request working correctly. Since the |
| 1082 | * timeout has now fired, the TMF request failed. We set the |
| 1083 | * state such that the request completion will indicate the |
| 1084 | * device is no longer present. |
| 1085 | */ |
| 1086 | isci_request_change_state(old_request, aborting); |
| 1087 | break; |
| 1088 | |
| 1089 | default: |
| 1090 | dev_err(&old_request->isci_host->pdev->dev, |
| 1091 | "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n", |
| 1092 | __func__, cb_state, tmf, old_request); |
| 1093 | break; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * isci_task_abort_task() - This function is one of the SAS Domain Template |
| 1099 | * functions. This function is called by libsas to abort a specified task. |
| 1100 | * @task: This parameter specifies the SAS task to abort. |
| 1101 | * |
| 1102 | * status, zero indicates success. |
| 1103 | */ |
| 1104 | int isci_task_abort_task(struct sas_task *task) |
| 1105 | { |
| 1106 | DECLARE_COMPLETION_ONSTACK(aborted_io_completion); |
| 1107 | struct isci_request *old_request = NULL; |
| 1108 | struct isci_remote_device *isci_device = NULL; |
| 1109 | struct isci_host *isci_host = NULL; |
| 1110 | struct isci_tmf tmf; |
| 1111 | int ret = TMF_RESP_FUNC_FAILED; |
| 1112 | unsigned long flags; |
| 1113 | bool any_dev_reset, device_stopping; |
| 1114 | |
| 1115 | /* Get the isci_request reference from the task. Note that |
| 1116 | * this check does not depend on the pending request list |
| 1117 | * in the device, because tasks driving resets may land here |
| 1118 | * after completion in the core. |
| 1119 | */ |
| 1120 | old_request = isci_task_get_request_from_task(task, &isci_host, |
| 1121 | &isci_device); |
| 1122 | |
| 1123 | dev_dbg(&isci_host->pdev->dev, |
| 1124 | "%s: task = %p\n", __func__, task); |
| 1125 | |
| 1126 | /* Check if the device has been / is currently being removed. |
| 1127 | * If so, no task management will be done, and the I/O will |
| 1128 | * be terminated. |
| 1129 | */ |
| 1130 | device_stopping = (isci_device->status == isci_stopping) |
| 1131 | || (isci_device->status == isci_stopped); |
| 1132 | |
| 1133 | #ifdef NOMORE |
| 1134 | /* This abort task function is the first stop of the libsas error |
| 1135 | * handler thread. Since libsas is executing in a thread with a |
| 1136 | * referernce to the "task" parameter, that task cannot be completed |
| 1137 | * directly back to the upper layers. In order to make sure that |
| 1138 | * the task is managed correctly if this abort task fails, set the |
| 1139 | * "SAS_TASK_STATE_ABORTED" bit now such that completions up the |
| 1140 | * stack will be intercepted and only allowed to happen in the |
| 1141 | * libsas SCSI error handler thread. |
| 1142 | */ |
| 1143 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 1144 | task->task_state_flags |= SAS_TASK_STATE_ABORTED; |
| 1145 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1146 | #endif /* NOMORE */ |
| 1147 | |
| 1148 | /* This version of the driver will fail abort requests for |
| 1149 | * SATA/STP. Failing the abort request this way will cause the |
| 1150 | * SCSI error handler thread to escalate to LUN reset |
| 1151 | */ |
| 1152 | if (sas_protocol_ata(task->task_proto) && !device_stopping) { |
| 1153 | dev_warn(&isci_host->pdev->dev, |
| 1154 | " task %p is for a STP/SATA device;" |
| 1155 | " returning TMF_RESP_FUNC_FAILED\n" |
| 1156 | " to cause a LUN reset...\n", task); |
| 1157 | return TMF_RESP_FUNC_FAILED; |
| 1158 | } |
| 1159 | |
| 1160 | dev_dbg(&isci_host->pdev->dev, |
| 1161 | "%s: old_request == %p\n", __func__, old_request); |
| 1162 | |
| 1163 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 1164 | |
| 1165 | /* Don't do resets to stopping devices. */ |
| 1166 | if (device_stopping) |
| 1167 | task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; |
| 1168 | |
| 1169 | /* See if there is a pending device reset for this device. */ |
| 1170 | any_dev_reset = task->task_state_flags & SAS_TASK_NEED_DEV_RESET; |
| 1171 | |
| 1172 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1173 | |
| 1174 | if ((isci_device != NULL) && !device_stopping) |
| 1175 | any_dev_reset = any_dev_reset |
| 1176 | || isci_device_is_reset_pending(isci_host, |
| 1177 | isci_device |
| 1178 | ); |
| 1179 | |
| 1180 | /* If the extraction of the request reference from the task |
| 1181 | * failed, then the request has been completed (or if there is a |
| 1182 | * pending reset then this abort request function must be failed |
| 1183 | * in order to escalate to the target reset). |
| 1184 | */ |
| 1185 | if ((old_request == NULL) || |
| 1186 | ((old_request != NULL) && |
| 1187 | (old_request->sci_request_handle == NULL) && |
| 1188 | (old_request->complete_in_target)) || |
| 1189 | any_dev_reset) { |
| 1190 | |
| 1191 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 1192 | |
| 1193 | /* If the device reset task flag is set, fail the task |
| 1194 | * management request. Otherwise, the original request |
| 1195 | * has completed. |
| 1196 | */ |
| 1197 | if (any_dev_reset) { |
| 1198 | |
| 1199 | /* Turn off the task's DONE to make sure this |
| 1200 | * task is escalated to a target reset. |
| 1201 | */ |
| 1202 | task->task_state_flags &= ~SAS_TASK_STATE_DONE; |
| 1203 | |
| 1204 | /* Fail the task management request in order to |
| 1205 | * escalate to the target reset. |
| 1206 | */ |
| 1207 | ret = TMF_RESP_FUNC_FAILED; |
| 1208 | |
| 1209 | dev_dbg(&isci_host->pdev->dev, |
| 1210 | "%s: Failing task abort in order to " |
| 1211 | "escalate to target reset because\n" |
| 1212 | "SAS_TASK_NEED_DEV_RESET is set for " |
| 1213 | "task %p on dev %p\n", |
| 1214 | __func__, task, isci_device); |
| 1215 | |
| 1216 | } else { |
| 1217 | ret = TMF_RESP_FUNC_COMPLETE; |
| 1218 | |
| 1219 | dev_dbg(&isci_host->pdev->dev, |
| 1220 | "%s: abort task not needed for %p\n", |
| 1221 | __func__, task); |
| 1222 | |
| 1223 | /* The request has already completed and there |
| 1224 | * is nothing to do here other than to set the task |
| 1225 | * done bit, and indicate that the task abort function |
| 1226 | * was sucessful. |
| 1227 | */ |
| 1228 | isci_set_task_doneflags(task); |
| 1229 | |
| 1230 | /* Set the abort bit to make sure that libsas sticks the |
| 1231 | * task in the completed task queue. |
| 1232 | */ |
| 1233 | /* task->task_state_flags |= SAS_TASK_STATE_ABORTED; */ |
| 1234 | |
| 1235 | /* Check for the situation where the request was |
| 1236 | * left around on the device list but the |
| 1237 | * request already completed. |
| 1238 | */ |
| 1239 | if (old_request && !old_request->sci_request_handle) { |
| 1240 | |
| 1241 | isci_request_cleanup_completed_loiterer( |
| 1242 | isci_host, isci_device, old_request |
| 1243 | ); |
| 1244 | } |
| 1245 | } |
| 1246 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
| 1247 | |
| 1248 | return ret; |
| 1249 | } |
| 1250 | |
| 1251 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 1252 | |
| 1253 | /* Sanity check the request status, and set the I/O kernel completion |
| 1254 | * struct that will be triggered when the request completes. |
| 1255 | */ |
| 1256 | if (isci_task_validate_request_to_abort( |
| 1257 | old_request, |
| 1258 | isci_host, |
| 1259 | isci_device, |
| 1260 | &aborted_io_completion) |
| 1261 | == unallocated) { |
| 1262 | dev_dbg(&isci_host->pdev->dev, |
| 1263 | "%s: old_request not valid for device = %p\n", |
| 1264 | __func__, |
| 1265 | isci_device); |
| 1266 | old_request = NULL; |
| 1267 | } |
| 1268 | |
| 1269 | if (!old_request) { |
| 1270 | |
| 1271 | /* There is no isci_request attached to the sas_task. |
| 1272 | * It must have been completed and detached. |
| 1273 | */ |
| 1274 | dev_dbg(&isci_host->pdev->dev, |
| 1275 | "%s: old_request == NULL\n", |
| 1276 | __func__); |
| 1277 | |
| 1278 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1279 | |
| 1280 | /* Set the state on the task. */ |
| 1281 | isci_task_all_done(task); |
| 1282 | |
| 1283 | return TMF_RESP_FUNC_COMPLETE; |
| 1284 | } |
| 1285 | if (task->task_proto == SAS_PROTOCOL_SMP || device_stopping) { |
| 1286 | |
| 1287 | if (device_stopping) |
| 1288 | dev_dbg(&isci_host->pdev->dev, |
| 1289 | "%s: device is stopping, thus no TMF\n", |
| 1290 | __func__); |
| 1291 | else |
| 1292 | dev_dbg(&isci_host->pdev->dev, |
| 1293 | "%s: request is SMP, thus no TMF\n", |
| 1294 | __func__); |
| 1295 | |
| 1296 | old_request->complete_in_target = true; |
| 1297 | |
| 1298 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1299 | |
| 1300 | /* Set the state on the task. */ |
| 1301 | isci_task_all_done(task); |
| 1302 | |
| 1303 | ret = TMF_RESP_FUNC_COMPLETE; |
| 1304 | |
| 1305 | /* Stopping and SMP devices are not sent a TMF, and are not |
| 1306 | * reset, but the outstanding I/O request is terminated here. |
| 1307 | * |
| 1308 | * Clean up the request on our side, and wait for the aborted |
| 1309 | * I/O to complete. |
| 1310 | */ |
| 1311 | isci_terminate_request_core(isci_host, isci_device, old_request, |
| 1312 | &aborted_io_completion); |
| 1313 | } else { |
| 1314 | /* Fill in the tmf stucture */ |
| 1315 | isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_task_abort, |
| 1316 | isci_abort_task_process_cb, old_request); |
| 1317 | |
| 1318 | tmf.io_tag = scic_io_request_get_io_tag( |
| 1319 | old_request->sci_request_handle |
| 1320 | ); |
| 1321 | |
| 1322 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1323 | |
| 1324 | #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */ |
| 1325 | ret = isci_task_execute_tmf(isci_host, &tmf, |
| 1326 | ISCI_ABORT_TASK_TIMEOUT_MS); |
| 1327 | |
| 1328 | if (ret == TMF_RESP_FUNC_COMPLETE) { |
| 1329 | old_request->complete_in_target = true; |
| 1330 | |
| 1331 | /* Clean up the request on our side, and wait for the aborted I/O to |
| 1332 | * complete. |
| 1333 | */ |
| 1334 | isci_terminate_request_core(isci_host, isci_device, old_request, |
| 1335 | &aborted_io_completion); |
| 1336 | |
| 1337 | /* Set the state on the task. */ |
| 1338 | isci_task_all_done(task); |
| 1339 | } else |
| 1340 | dev_err(&isci_host->pdev->dev, |
| 1341 | "%s: isci_task_send_tmf failed\n", |
| 1342 | __func__); |
| 1343 | } |
| 1344 | |
| 1345 | return ret; |
| 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * isci_task_abort_task_set() - This function is one of the SAS Domain Template |
| 1350 | * functions. This is one of the Task Management functoins called by libsas, |
| 1351 | * to abort all task for the given lun. |
| 1352 | * @d_device: This parameter specifies the domain device associated with this |
| 1353 | * request. |
| 1354 | * @lun: This parameter specifies the lun associated with this request. |
| 1355 | * |
| 1356 | * status, zero indicates success. |
| 1357 | */ |
| 1358 | int isci_task_abort_task_set( |
| 1359 | struct domain_device *d_device, |
| 1360 | u8 *lun) |
| 1361 | { |
| 1362 | return TMF_RESP_FUNC_FAILED; |
| 1363 | } |
| 1364 | |
| 1365 | |
| 1366 | /** |
| 1367 | * isci_task_clear_aca() - This function is one of the SAS Domain Template |
| 1368 | * functions. This is one of the Task Management functoins called by libsas. |
| 1369 | * @d_device: This parameter specifies the domain device associated with this |
| 1370 | * request. |
| 1371 | * @lun: This parameter specifies the lun associated with this request. |
| 1372 | * |
| 1373 | * status, zero indicates success. |
| 1374 | */ |
| 1375 | int isci_task_clear_aca( |
| 1376 | struct domain_device *d_device, |
| 1377 | u8 *lun) |
| 1378 | { |
| 1379 | return TMF_RESP_FUNC_FAILED; |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | /** |
| 1385 | * isci_task_clear_task_set() - This function is one of the SAS Domain Template |
| 1386 | * functions. This is one of the Task Management functoins called by libsas. |
| 1387 | * @d_device: This parameter specifies the domain device associated with this |
| 1388 | * request. |
| 1389 | * @lun: This parameter specifies the lun associated with this request. |
| 1390 | * |
| 1391 | * status, zero indicates success. |
| 1392 | */ |
| 1393 | int isci_task_clear_task_set( |
| 1394 | struct domain_device *d_device, |
| 1395 | u8 *lun) |
| 1396 | { |
| 1397 | return TMF_RESP_FUNC_FAILED; |
| 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | /** |
| 1402 | * isci_task_query_task() - This function is implemented to cause libsas to |
| 1403 | * correctly escalate the failed abort to a LUN or target reset (this is |
| 1404 | * because sas_scsi_find_task libsas function does not correctly interpret |
| 1405 | * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is |
| 1406 | * returned, libsas turns this into a LUN reset; when FUNC_FAILED is |
| 1407 | * returned, libsas will turn this into a target reset |
| 1408 | * @task: This parameter specifies the sas task being queried. |
| 1409 | * @lun: This parameter specifies the lun associated with this request. |
| 1410 | * |
| 1411 | * status, zero indicates success. |
| 1412 | */ |
| 1413 | int isci_task_query_task( |
| 1414 | struct sas_task *task) |
| 1415 | { |
| 1416 | /* See if there is a pending device reset for this device. */ |
| 1417 | if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) |
| 1418 | return TMF_RESP_FUNC_FAILED; |
| 1419 | else |
| 1420 | return TMF_RESP_FUNC_SUCC; |
| 1421 | } |
| 1422 | |
| 1423 | /** |
| 1424 | * isci_task_request_complete() - This function is called by the sci core when |
| 1425 | * an task request completes. |
| 1426 | * @isci_host: This parameter specifies the ISCI host object |
| 1427 | * @request: This parameter is the completed isci_request object. |
| 1428 | * @completion_status: This parameter specifies the completion status from the |
| 1429 | * sci core. |
| 1430 | * |
| 1431 | * none. |
| 1432 | */ |
| 1433 | void isci_task_request_complete( |
| 1434 | struct isci_host *isci_host, |
| 1435 | struct isci_request *request, |
| 1436 | enum sci_task_status completion_status) |
| 1437 | { |
| 1438 | struct isci_remote_device *isci_device = request->isci_device; |
| 1439 | enum isci_request_status old_state; |
| 1440 | struct isci_tmf *tmf = isci_request_access_tmf(request); |
| 1441 | struct completion *tmf_complete; |
| 1442 | |
| 1443 | dev_dbg(&isci_host->pdev->dev, |
| 1444 | "%s: request = %p, status=%d\n", |
| 1445 | __func__, request, completion_status); |
| 1446 | |
| 1447 | old_state = isci_request_change_state(request, completed); |
| 1448 | |
| 1449 | tmf->status = completion_status; |
| 1450 | request->complete_in_target = true; |
| 1451 | |
| 1452 | if (SAS_PROTOCOL_SSP == tmf->proto) { |
| 1453 | |
| 1454 | memcpy(&tmf->resp.resp_iu, |
| 1455 | scic_io_request_get_response_iu_address( |
| 1456 | request->sci_request_handle |
| 1457 | ), |
| 1458 | sizeof(struct sci_ssp_response_iu)); |
| 1459 | |
| 1460 | } else if (SAS_PROTOCOL_SATA == tmf->proto) { |
| 1461 | |
| 1462 | memcpy(&tmf->resp.d2h_fis, |
| 1463 | scic_stp_io_request_get_d2h_reg_address( |
| 1464 | request->sci_request_handle |
| 1465 | ), |
| 1466 | sizeof(struct sata_fis_reg_d2h) |
| 1467 | ); |
| 1468 | } |
| 1469 | |
| 1470 | /* Manage the timer if it is still running. */ |
| 1471 | if (tmf->timeout_timer) { |
| 1472 | |
| 1473 | isci_timer_stop(tmf->timeout_timer); |
| 1474 | isci_timer_free(&isci_host->timer_list_struct, |
| 1475 | tmf->timeout_timer); |
| 1476 | tmf->timeout_timer = NULL; |
| 1477 | } |
| 1478 | |
| 1479 | /* PRINT_TMF( ((struct isci_tmf *)request->task)); */ |
| 1480 | tmf_complete = tmf->complete; |
| 1481 | |
| 1482 | scic_controller_complete_task( |
| 1483 | isci_host->core_controller, |
| 1484 | isci_device->sci_device_handle, |
| 1485 | request->sci_request_handle |
| 1486 | ); |
| 1487 | /* NULL the request handle to make sure it cannot be terminated |
| 1488 | * or completed again. |
| 1489 | */ |
| 1490 | request->sci_request_handle = NULL; |
| 1491 | |
| 1492 | isci_request_change_state(request, unallocated); |
| 1493 | list_del_init(&request->dev_node); |
| 1494 | |
| 1495 | /* The task management part completes last. */ |
| 1496 | complete(tmf_complete); |
| 1497 | } |
| 1498 | |
| 1499 | |
| 1500 | /** |
| 1501 | * isci_task_ssp_request_get_lun() - This function is called by the sci core to |
| 1502 | * retrieve the lun for a given task request. |
| 1503 | * @request: This parameter is the isci_request object. |
| 1504 | * |
| 1505 | * lun for specified task request. |
| 1506 | */ |
| 1507 | u32 isci_task_ssp_request_get_lun(struct isci_request *request) |
| 1508 | { |
| 1509 | struct isci_tmf *isci_tmf = isci_request_access_tmf(request); |
| 1510 | |
| 1511 | dev_dbg(&request->isci_host->pdev->dev, |
| 1512 | "%s: lun = %d\n", __func__, isci_tmf->lun[0]); |
| 1513 | /* @todo: build lun from array of bytes to 32 bit */ |
| 1514 | return isci_tmf->lun[0]; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * isci_task_ssp_request_get_function() - This function is called by the sci |
| 1519 | * core to retrieve the function for a given task request. |
| 1520 | * @request: This parameter is the isci_request object. |
| 1521 | * |
| 1522 | * function code for specified task request. |
| 1523 | */ |
| 1524 | u8 isci_task_ssp_request_get_function(struct isci_request *request) |
| 1525 | { |
| 1526 | struct isci_tmf *isci_tmf = isci_request_access_tmf(request); |
| 1527 | |
| 1528 | dev_dbg(&request->isci_host->pdev->dev, |
| 1529 | "%s: func = %d\n", __func__, isci_tmf->tmf_code); |
| 1530 | |
| 1531 | return isci_tmf->tmf_code; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by |
| 1536 | * the sci core to retrieve the io tag for a given task request. |
| 1537 | * @request: This parameter is the isci_request object. |
| 1538 | * |
| 1539 | * io tag for specified task request. |
| 1540 | */ |
| 1541 | u16 isci_task_ssp_request_get_io_tag_to_manage(struct isci_request *request) |
| 1542 | { |
| 1543 | u16 io_tag = SCI_CONTROLLER_INVALID_IO_TAG; |
| 1544 | |
| 1545 | if (tmf_task == request->ttype) { |
| 1546 | struct isci_tmf *tmf = isci_request_access_tmf(request); |
| 1547 | io_tag = tmf->io_tag; |
| 1548 | } |
| 1549 | |
| 1550 | dev_dbg(&request->isci_host->pdev->dev, |
| 1551 | "%s: request = %p, io_tag = %d\n", |
| 1552 | __func__, request, io_tag); |
| 1553 | |
| 1554 | return io_tag; |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * isci_task_ssp_request_get_response_data_address() - This function is called |
| 1559 | * by the sci core to retrieve the response data address for a given task |
| 1560 | * request. |
| 1561 | * @request: This parameter is the isci_request object. |
| 1562 | * |
| 1563 | * response data address for specified task request. |
| 1564 | */ |
| 1565 | void *isci_task_ssp_request_get_response_data_address( |
| 1566 | struct isci_request *request) |
| 1567 | { |
| 1568 | struct isci_tmf *isci_tmf = isci_request_access_tmf(request); |
| 1569 | |
| 1570 | return &isci_tmf->resp.resp_iu; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * isci_task_ssp_request_get_response_data_length() - This function is called |
| 1575 | * by the sci core to retrieve the response data length for a given task |
| 1576 | * request. |
| 1577 | * @request: This parameter is the isci_request object. |
| 1578 | * |
| 1579 | * response data length for specified task request. |
| 1580 | */ |
| 1581 | u32 isci_task_ssp_request_get_response_data_length( |
| 1582 | struct isci_request *request) |
| 1583 | { |
| 1584 | struct isci_tmf *isci_tmf = isci_request_access_tmf(request); |
| 1585 | |
| 1586 | return sizeof(isci_tmf->resp.resp_iu); |
| 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * isci_bus_reset_handler() - This function performs a target reset of the |
| 1591 | * device referenced by "cmd'. This function is exported through the |
| 1592 | * "struct scsi_host_template" structure such that it is called when an I/O |
| 1593 | * recovery process has escalated to a target reset. Note that this function |
| 1594 | * is called from the scsi error handler event thread, so may block on calls. |
| 1595 | * @scsi_cmd: This parameter specifies the target to be reset. |
| 1596 | * |
| 1597 | * SUCCESS if the reset process was successful, else FAILED. |
| 1598 | */ |
| 1599 | int isci_bus_reset_handler(struct scsi_cmnd *cmd) |
| 1600 | { |
| 1601 | unsigned long flags = 0; |
| 1602 | struct isci_host *isci_host = NULL; |
| 1603 | enum sci_status status; |
| 1604 | int base_status; |
| 1605 | struct isci_remote_device *isci_dev |
| 1606 | = isci_dev_from_domain_dev( |
| 1607 | sdev_to_domain_dev(cmd->device)); |
| 1608 | |
| 1609 | dev_dbg(&cmd->device->sdev_gendev, |
| 1610 | "%s: cmd %p, isci_dev %p\n", |
| 1611 | __func__, cmd, isci_dev); |
| 1612 | |
| 1613 | if (!isci_dev) { |
| 1614 | dev_warn(&cmd->device->sdev_gendev, |
| 1615 | "%s: isci_dev is GONE!\n", |
| 1616 | __func__); |
| 1617 | |
| 1618 | return TMF_RESP_FUNC_COMPLETE; /* Nothing to reset. */ |
| 1619 | } |
| 1620 | |
| 1621 | if (isci_dev->isci_port != NULL) |
| 1622 | isci_host = isci_dev->isci_port->isci_host; |
| 1623 | |
| 1624 | if (isci_host != NULL) |
| 1625 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 1626 | |
| 1627 | status = scic_remote_device_reset(isci_dev->sci_device_handle); |
| 1628 | if (status != SCI_SUCCESS) { |
| 1629 | |
| 1630 | if (isci_host != NULL) |
| 1631 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1632 | |
| 1633 | scmd_printk(KERN_WARNING, cmd, |
| 1634 | "%s: scic_remote_device_reset(%p) returned %d!\n", |
| 1635 | __func__, isci_dev, status); |
| 1636 | |
| 1637 | return TMF_RESP_FUNC_FAILED; |
| 1638 | } |
| 1639 | if (isci_host != NULL) |
| 1640 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1641 | |
| 1642 | /* Stop I/O to the remote device. */ |
| 1643 | isci_device_set_host_quiesce_lock_state(isci_dev, true); |
| 1644 | |
| 1645 | /* Make sure all pending requests are able to be fully terminated. */ |
| 1646 | isci_device_clear_reset_pending(isci_dev); |
| 1647 | |
| 1648 | /* Terminate in-progress I/O now. */ |
| 1649 | isci_remote_device_nuke_requests(isci_dev); |
| 1650 | |
| 1651 | /* Call into the libsas default handler (which calls sas_phy_reset). */ |
| 1652 | base_status = sas_eh_bus_reset_handler(cmd); |
| 1653 | |
| 1654 | if (base_status != SUCCESS) { |
| 1655 | |
| 1656 | /* There can be cases where the resets to individual devices |
| 1657 | * behind an expander will fail because of an unplug of the |
| 1658 | * expander itself. |
| 1659 | */ |
| 1660 | scmd_printk(KERN_WARNING, cmd, |
| 1661 | "%s: sas_eh_bus_reset_handler(%p) returned %d!\n", |
| 1662 | __func__, cmd, base_status); |
| 1663 | } |
| 1664 | |
| 1665 | /* WHAT TO DO HERE IF sas_phy_reset FAILS? */ |
| 1666 | |
| 1667 | if (isci_host != NULL) |
| 1668 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 1669 | status |
| 1670 | = scic_remote_device_reset_complete(isci_dev->sci_device_handle); |
| 1671 | |
| 1672 | if (isci_host != NULL) |
| 1673 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1674 | |
| 1675 | if (status != SCI_SUCCESS) { |
| 1676 | scmd_printk(KERN_WARNING, cmd, |
| 1677 | "%s: scic_remote_device_reset_complete(%p) " |
| 1678 | "returned %d!\n", |
| 1679 | __func__, isci_dev, status); |
| 1680 | } |
| 1681 | /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */ |
| 1682 | |
| 1683 | dev_dbg(&cmd->device->sdev_gendev, |
| 1684 | "%s: cmd %p, isci_dev %p complete.\n", |
| 1685 | __func__, cmd, isci_dev); |
| 1686 | |
| 1687 | /* Resume I/O to the remote device. */ |
| 1688 | isci_device_set_host_quiesce_lock_state(isci_dev, false); |
| 1689 | |
| 1690 | return TMF_RESP_FUNC_COMPLETE; |
| 1691 | } |