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