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