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