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