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