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