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