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