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 | { |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 81 | unsigned long flags; |
Dan Williams | 1077a57 | 2011-03-11 10:13:51 -0800 | [diff] [blame] | 82 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 83 | /* Normal notification (task_done) */ |
| 84 | dev_dbg(&ihost->pdev->dev, "%s: task = %p, response=%d, status=%d\n", |
| 85 | __func__, task, response, status); |
Dan Williams | 50e7f9b | 2011-03-09 21:27:46 -0800 | [diff] [blame] | 86 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 87 | spin_lock_irqsave(&task->task_state_lock, flags); |
Dan Williams | 50e7f9b | 2011-03-09 21:27:46 -0800 | [diff] [blame] | 88 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 89 | task->task_status.resp = response; |
| 90 | task->task_status.stat = status; |
Dan Williams | 50e7f9b | 2011-03-09 21:27:46 -0800 | [diff] [blame] | 91 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 92 | /* Normal notification (task_done) */ |
| 93 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 94 | task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | |
| 95 | SAS_TASK_STATE_PENDING); |
| 96 | task->lldd_task = NULL; |
| 97 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Dan Williams | 50e7f9b | 2011-03-09 21:27:46 -0800 | [diff] [blame] | 98 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 99 | task->task_done(task); |
Dan Williams | 50e7f9b | 2011-03-09 21:27:46 -0800 | [diff] [blame] | 100 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 101 | |
Dan Williams | 1077a57 | 2011-03-11 10:13:51 -0800 | [diff] [blame] | 102 | #define for_each_sas_task(num, task) \ |
| 103 | for (; num > 0; num--,\ |
| 104 | task = list_entry(task->list.next, struct sas_task, list)) |
| 105 | |
Jeff Skirvin | 9274f45 | 2011-06-23 17:09:02 -0700 | [diff] [blame] | 106 | |
| 107 | static inline int isci_device_io_ready(struct isci_remote_device *idev, |
| 108 | struct sas_task *task) |
| 109 | { |
| 110 | return idev ? test_bit(IDEV_IO_READY, &idev->flags) || |
| 111 | (test_bit(IDEV_IO_NCQERROR, &idev->flags) && |
| 112 | isci_task_is_ncq_recovery(task)) |
| 113 | : 0; |
| 114 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 115 | /** |
| 116 | * isci_task_execute_task() - This function is one of the SAS Domain Template |
| 117 | * functions. This function is called by libsas to send a task down to |
| 118 | * hardware. |
| 119 | * @task: This parameter specifies the SAS task to send. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 120 | * @gfp_flags: This parameter specifies the context of this call. |
| 121 | * |
| 122 | * status, zero indicates success. |
| 123 | */ |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 124 | int isci_task_execute_task(struct sas_task *task, gfp_t gfp_flags) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 125 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 126 | struct isci_host *ihost = dev_to_ihost(task->dev); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 127 | struct isci_remote_device *idev; |
Dan Williams | f208826 | 2011-06-16 11:26:12 -0700 | [diff] [blame] | 128 | unsigned long flags; |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 129 | enum sci_status status = SCI_FAILURE; |
Dan Williams | f208826 | 2011-06-16 11:26:12 -0700 | [diff] [blame] | 130 | bool io_ready; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 131 | u16 tag; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 132 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 133 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 134 | idev = isci_lookup_device(task->dev); |
| 135 | io_ready = isci_device_io_ready(idev, task); |
| 136 | tag = isci_alloc_tag(ihost); |
| 137 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 138 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 139 | dev_dbg(&ihost->pdev->dev, |
| 140 | "task: %p, dev: %p idev: %p:%#lx cmd = %p\n", |
| 141 | task, task->dev, idev, idev ? idev->flags : 0, |
| 142 | task->uldd_task); |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 143 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 144 | if (!idev) { |
| 145 | isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED, |
| 146 | SAS_DEVICE_UNKNOWN); |
| 147 | } else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) { |
| 148 | /* Indicate QUEUE_FULL so that the scsi midlayer |
| 149 | * retries. |
| 150 | */ |
| 151 | isci_task_refuse(ihost, task, SAS_TASK_COMPLETE, |
| 152 | SAS_QUEUE_FULL); |
| 153 | } else { |
| 154 | /* There is a device and it's ready for I/O. */ |
| 155 | spin_lock_irqsave(&task->task_state_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 156 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 157 | if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { |
| 158 | /* The I/O was aborted. */ |
| 159 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Jeff Skirvin | f0846c6 | 2011-03-08 19:22:07 -0700 | [diff] [blame] | 160 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 161 | isci_task_refuse(ihost, task, |
| 162 | SAS_TASK_UNDELIVERED, |
| 163 | SAM_STAT_TASK_ABORTED); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 164 | } else { |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 165 | task->task_state_flags |= SAS_TASK_AT_INITIATOR; |
| 166 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 167 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 168 | /* build and send the request. */ |
| 169 | status = isci_request_execute(ihost, idev, task, tag); |
Jeff Skirvin | f0846c6 | 2011-03-08 19:22:07 -0700 | [diff] [blame] | 170 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 171 | if (status != SCI_SUCCESS) { |
| 172 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 173 | /* Did not really start this command. */ |
| 174 | task->task_state_flags &= ~SAS_TASK_AT_INITIATOR; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 175 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Jeff Skirvin | f0846c6 | 2011-03-08 19:22:07 -0700 | [diff] [blame] | 176 | |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 177 | if (test_bit(IDEV_GONE, &idev->flags)) { |
| 178 | /* Indicate that the device |
| 179 | * is gone. |
| 180 | */ |
| 181 | isci_task_refuse(ihost, task, |
| 182 | SAS_TASK_UNDELIVERED, |
| 183 | SAS_DEVICE_UNKNOWN); |
| 184 | } else { |
| 185 | /* Indicate QUEUE_FULL so that |
| 186 | * the scsi midlayer retries. |
| 187 | * If the request failed for |
| 188 | * remote device reasons, it |
| 189 | * gets returned as |
| 190 | * SAS_TASK_UNDELIVERED next |
| 191 | * time through. |
| 192 | */ |
| 193 | isci_task_refuse(ihost, task, |
| 194 | SAS_TASK_COMPLETE, |
| 195 | SAS_QUEUE_FULL); |
Jeff Skirvin | f0846c6 | 2011-03-08 19:22:07 -0700 | [diff] [blame] | 196 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
Dan Williams | 1077a57 | 2011-03-11 10:13:51 -0800 | [diff] [blame] | 199 | } |
Christoph Hellwig | 79855d1 | 2014-11-05 10:36:28 +0100 | [diff] [blame] | 200 | |
| 201 | if (status != SCI_SUCCESS && tag != SCI_CONTROLLER_INVALID_IO_TAG) { |
| 202 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 203 | /* command never hit the device, so just free |
| 204 | * the tci and skip the sequence increment |
| 205 | */ |
| 206 | isci_tci_free(ihost, ISCI_TAG_TCI(tag)); |
| 207 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 208 | } |
| 209 | |
| 210 | isci_put_device(idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 211 | return 0; |
| 212 | } |
| 213 | |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 214 | static struct isci_request *isci_task_request_build(struct isci_host *ihost, |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 215 | struct isci_remote_device *idev, |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 216 | u16 tag, struct isci_tmf *isci_tmf) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 217 | { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 218 | enum sci_status status = SCI_FAILURE; |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 219 | struct isci_request *ireq = NULL; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 220 | struct domain_device *dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 221 | |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 222 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 223 | "%s: isci_tmf = %p\n", __func__, isci_tmf); |
| 224 | |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 225 | dev = idev->domain_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 226 | |
| 227 | /* do common allocation and init of request object. */ |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 228 | ireq = isci_tmf_request_from_tag(ihost, isci_tmf, tag); |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 229 | if (!ireq) |
| 230 | return NULL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 231 | |
| 232 | /* let the core do it's construct. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 233 | status = sci_task_request_construct(ihost, idev, tag, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 234 | ireq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 235 | |
| 236 | if (status != SCI_SUCCESS) { |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 237 | dev_warn(&ihost->pdev->dev, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 238 | "%s: sci_task_request_construct failed - " |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 239 | "status = 0x%x\n", |
| 240 | __func__, |
| 241 | status); |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 242 | return NULL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 245 | /* XXX convert to get this from task->tproto like other drivers */ |
James Bottomley | aa9f832 | 2013-05-07 14:44:06 -0700 | [diff] [blame] | 246 | if (dev->dev_type == SAS_END_DEVICE) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 247 | isci_tmf->proto = SAS_PROTOCOL_SSP; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 248 | status = sci_task_request_construct_ssp(ireq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 249 | if (status != SCI_SUCCESS) |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 250 | return NULL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 253 | return ireq; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Dan Williams | 16ba770 | 2011-07-01 10:52:55 -0700 | [diff] [blame] | 256 | static int isci_task_execute_tmf(struct isci_host *ihost, |
| 257 | struct isci_remote_device *idev, |
| 258 | struct isci_tmf *tmf, unsigned long timeout_ms) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 259 | { |
| 260 | DECLARE_COMPLETION_ONSTACK(completion); |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 261 | enum sci_task_status status = SCI_TASK_FAILURE; |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 262 | struct isci_request *ireq; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 263 | int ret = TMF_RESP_FUNC_FAILED; |
| 264 | unsigned long flags; |
Edmund Nadolski | fd18388 | 2011-05-19 12:00:15 +0000 | [diff] [blame] | 265 | unsigned long timeleft; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 266 | u16 tag; |
| 267 | |
| 268 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 269 | tag = isci_alloc_tag(ihost); |
| 270 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 271 | |
| 272 | if (tag == SCI_CONTROLLER_INVALID_IO_TAG) |
| 273 | return ret; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 274 | |
| 275 | /* sanity check, return TMF_RESP_FUNC_FAILED |
| 276 | * if the device is not there and ready. |
| 277 | */ |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 278 | if (!idev || |
| 279 | (!test_bit(IDEV_IO_READY, &idev->flags) && |
| 280 | !test_bit(IDEV_IO_NCQERROR, &idev->flags))) { |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 281 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 282 | "%s: idev = %p not ready (%#lx)\n", |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 283 | __func__, |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 284 | idev, idev ? idev->flags : 0); |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 285 | goto err_tci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 286 | } else |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 287 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 288 | "%s: idev = %p\n", |
| 289 | __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 290 | |
| 291 | /* Assign the pointer to the TMF's completion kernel wait structure. */ |
| 292 | tmf->complete = &completion; |
Jeff Skirvin | b343dff | 2011-10-27 15:05:06 -0700 | [diff] [blame] | 293 | tmf->status = SCI_FAILURE_TIMEOUT; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 294 | |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 295 | ireq = isci_task_request_build(ihost, idev, tag, tmf); |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 296 | if (!ireq) |
| 297 | goto err_tci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 298 | |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 299 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 300 | |
| 301 | /* start the TMF io. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 302 | status = sci_controller_start_task(ihost, idev, ireq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 303 | |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 304 | if (status != SCI_TASK_SUCCESS) { |
Dan Williams | a8a0a13 | 2011-07-01 12:07:25 -0700 | [diff] [blame] | 305 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 306 | "%s: start_io failed - status = 0x%x, request = %p\n", |
| 307 | __func__, |
| 308 | status, |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 309 | ireq); |
| 310 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 311 | goto err_tci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 312 | } |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 313 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 314 | |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame] | 315 | /* The RNC must be unsuspended before the TMF can get a response. */ |
| 316 | isci_remote_device_resume_from_abort(ihost, idev); |
| 317 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 318 | /* Wait for the TMF to complete, or a timeout. */ |
Edmund Nadolski | fd18388 | 2011-05-19 12:00:15 +0000 | [diff] [blame] | 319 | timeleft = wait_for_completion_timeout(&completion, |
Dan Williams | 086a0da | 2011-06-21 16:23:03 -0700 | [diff] [blame] | 320 | msecs_to_jiffies(timeout_ms)); |
Edmund Nadolski | fd18388 | 2011-05-19 12:00:15 +0000 | [diff] [blame] | 321 | |
| 322 | if (timeleft == 0) { |
Jeff Skirvin | b343dff | 2011-10-27 15:05:06 -0700 | [diff] [blame] | 323 | /* The TMF did not complete - this could be because |
| 324 | * of an unplug. Terminate the TMF request now. |
| 325 | */ |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 326 | isci_remote_device_suspend_terminate(ihost, idev, ireq); |
Edmund Nadolski | fd18388 | 2011-05-19 12:00:15 +0000 | [diff] [blame] | 327 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 328 | |
Maciej Trela | 27234ab | 2012-01-04 01:33:05 -0800 | [diff] [blame] | 329 | isci_print_tmf(ihost, tmf); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 330 | |
| 331 | if (tmf->status == SCI_SUCCESS) |
| 332 | ret = TMF_RESP_FUNC_COMPLETE; |
| 333 | else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) { |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 334 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 335 | "%s: tmf.status == " |
| 336 | "SCI_FAILURE_IO_RESPONSE_VALID\n", |
| 337 | __func__); |
| 338 | ret = TMF_RESP_FUNC_COMPLETE; |
| 339 | } |
| 340 | /* Else - leave the default "failed" status alone. */ |
| 341 | |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 342 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 343 | "%s: completed request = %p\n", |
| 344 | __func__, |
Dan Williams | 0d0cf14 | 2011-06-13 00:51:30 -0700 | [diff] [blame] | 345 | ireq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 346 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 347 | return ret; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 348 | |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 349 | err_tci: |
| 350 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 351 | isci_tci_free(ihost, ISCI_TAG_TCI(tag)); |
| 352 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 353 | |
| 354 | return ret; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Dan Williams | 16ba770 | 2011-07-01 10:52:55 -0700 | [diff] [blame] | 357 | static void isci_task_build_tmf(struct isci_tmf *tmf, |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 358 | enum isci_tmf_function_codes code) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 359 | { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 360 | memset(tmf, 0, sizeof(*tmf)); |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 361 | tmf->tmf_code = code; |
Jeff Skirvin | c3f42fe | 2011-03-04 14:06:56 -0800 | [diff] [blame] | 362 | } |
Jeff Skirvin | 1fad9e9 | 2011-03-04 14:06:46 -0800 | [diff] [blame] | 363 | |
Dan Williams | 16ba770 | 2011-07-01 10:52:55 -0700 | [diff] [blame] | 364 | static void isci_task_build_abort_task_tmf(struct isci_tmf *tmf, |
| 365 | enum isci_tmf_function_codes code, |
Dan Williams | 16ba770 | 2011-07-01 10:52:55 -0700 | [diff] [blame] | 366 | struct isci_request *old_request) |
Jeff Skirvin | c3f42fe | 2011-03-04 14:06:56 -0800 | [diff] [blame] | 367 | { |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 368 | isci_task_build_tmf(tmf, code); |
Jeff Skirvin | c3f42fe | 2011-03-04 14:06:56 -0800 | [diff] [blame] | 369 | tmf->io_tag = old_request->io_tag; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 372 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 373 | * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain |
| 374 | * Template functions. |
| 375 | * @lun: This parameter specifies the lun to be reset. |
| 376 | * |
| 377 | * status, zero indicates success. |
| 378 | */ |
| 379 | static int isci_task_send_lu_reset_sas( |
| 380 | struct isci_host *isci_host, |
| 381 | struct isci_remote_device *isci_device, |
| 382 | u8 *lun) |
| 383 | { |
| 384 | struct isci_tmf tmf; |
| 385 | int ret = TMF_RESP_FUNC_FAILED; |
| 386 | |
| 387 | dev_dbg(&isci_host->pdev->dev, |
| 388 | "%s: isci_host = %p, isci_device = %p\n", |
| 389 | __func__, isci_host, isci_device); |
| 390 | /* Send the LUN reset to the target. By the time the call returns, |
| 391 | * the TMF has fully exected in the target (in which case the return |
| 392 | * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or |
| 393 | * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED"). |
| 394 | */ |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 395 | isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 396 | |
| 397 | #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */ |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 398 | 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] | 399 | |
| 400 | if (ret == TMF_RESP_FUNC_COMPLETE) |
| 401 | dev_dbg(&isci_host->pdev->dev, |
| 402 | "%s: %p: TMF_LU_RESET passed\n", |
| 403 | __func__, isci_device); |
| 404 | else |
| 405 | dev_dbg(&isci_host->pdev->dev, |
| 406 | "%s: %p: TMF_LU_RESET failed (%x)\n", |
| 407 | __func__, isci_device, ret); |
| 408 | |
| 409 | return ret; |
| 410 | } |
| 411 | |
Dan Williams | 43a5ab1 | 2011-12-08 23:20:44 -0800 | [diff] [blame] | 412 | int isci_task_lu_reset(struct domain_device *dev, u8 *lun) |
Dan Williams | 16ba770 | 2011-07-01 10:52:55 -0700 | [diff] [blame] | 413 | { |
Jeff Skirvin | 5b6bf22 | 2012-03-08 22:41:51 -0800 | [diff] [blame] | 414 | struct isci_host *ihost = dev_to_ihost(dev); |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 415 | struct isci_remote_device *idev; |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 416 | unsigned long flags; |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 417 | int ret = TMF_RESP_FUNC_COMPLETE; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 418 | |
Jeff Skirvin | 5b6bf22 | 2012-03-08 22:41:51 -0800 | [diff] [blame] | 419 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Jeff Skirvin | 6373250 | 2012-03-08 22:41:55 -0800 | [diff] [blame] | 420 | idev = isci_get_device(dev->lldd_dev); |
Jeff Skirvin | 5b6bf22 | 2012-03-08 22:41:51 -0800 | [diff] [blame] | 421 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 422 | |
Jeff Skirvin | 5b6bf22 | 2012-03-08 22:41:51 -0800 | [diff] [blame] | 423 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 424 | "%s: domain_device=%p, isci_host=%p; isci_device=%p\n", |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 425 | __func__, dev, ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 426 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 427 | if (!idev) { |
Jeff Skirvin | d80ecd5 | 2012-03-08 22:41:53 -0800 | [diff] [blame] | 428 | /* If the device is gone, escalate to I_T_Nexus_Reset. */ |
Jeff Skirvin | 5b6bf22 | 2012-03-08 22:41:51 -0800 | [diff] [blame] | 429 | dev_dbg(&ihost->pdev->dev, "%s: No dev\n", __func__); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 430 | |
Jeff Skirvin | d80ecd5 | 2012-03-08 22:41:53 -0800 | [diff] [blame] | 431 | ret = TMF_RESP_FUNC_FAILED; |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 432 | goto out; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Jeff Skirvin | 08c031e | 2012-03-08 22:42:00 -0800 | [diff] [blame] | 435 | /* Suspend the RNC, kill all TCs */ |
| 436 | if (isci_remote_device_suspend_terminate(ihost, idev, NULL) |
| 437 | != SCI_SUCCESS) { |
| 438 | /* The suspend/terminate only fails if isci_get_device fails */ |
| 439 | ret = TMF_RESP_FUNC_FAILED; |
| 440 | goto out; |
| 441 | } |
| 442 | /* All pending I/Os have been terminated and cleaned up. */ |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 443 | if (!test_bit(IDEV_GONE, &idev->flags)) { |
| 444 | if (dev_is_sata(dev)) |
| 445 | sas_ata_schedule_reset(dev); |
| 446 | else |
| 447 | /* Send the task management part of the reset. */ |
| 448 | ret = isci_task_send_lu_reset_sas(ihost, idev, lun); |
Jeff Skirvin | 5b6bf22 | 2012-03-08 22:41:51 -0800 | [diff] [blame] | 449 | } |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 450 | out: |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 451 | isci_put_device(idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | /* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */ |
| 457 | int isci_task_clear_nexus_port(struct asd_sas_port *port) |
| 458 | { |
| 459 | return TMF_RESP_FUNC_FAILED; |
| 460 | } |
| 461 | |
| 462 | |
| 463 | |
| 464 | int isci_task_clear_nexus_ha(struct sas_ha_struct *ha) |
| 465 | { |
| 466 | return TMF_RESP_FUNC_FAILED; |
| 467 | } |
| 468 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 469 | /* Task Management Functions. Must be called from process context. */ |
| 470 | |
| 471 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 472 | * isci_task_abort_task() - This function is one of the SAS Domain Template |
| 473 | * functions. This function is called by libsas to abort a specified task. |
| 474 | * @task: This parameter specifies the SAS task to abort. |
| 475 | * |
| 476 | * status, zero indicates success. |
| 477 | */ |
| 478 | int isci_task_abort_task(struct sas_task *task) |
| 479 | { |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 480 | struct isci_host *ihost = dev_to_ihost(task->dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 481 | DECLARE_COMPLETION_ONSTACK(aborted_io_completion); |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 482 | struct isci_request *old_request = NULL; |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 483 | struct isci_remote_device *idev = NULL; |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 484 | struct isci_tmf tmf; |
| 485 | int ret = TMF_RESP_FUNC_FAILED; |
| 486 | unsigned long flags; |
Jeff Skirvin | 96f15f2 | 2013-07-11 17:18:58 -0700 | [diff] [blame] | 487 | int target_done_already = 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 488 | |
| 489 | /* Get the isci_request reference from the task. Note that |
| 490 | * this check does not depend on the pending request list |
| 491 | * in the device, because tasks driving resets may land here |
| 492 | * after completion in the core. |
| 493 | */ |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 494 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 495 | spin_lock(&task->task_state_lock); |
| 496 | |
| 497 | old_request = task->lldd_task; |
| 498 | |
| 499 | /* If task is already done, the request isn't valid */ |
| 500 | if (!(task->task_state_flags & SAS_TASK_STATE_DONE) && |
| 501 | (task->task_state_flags & SAS_TASK_AT_INITIATOR) && |
Jeff Skirvin | 96f15f2 | 2013-07-11 17:18:58 -0700 | [diff] [blame] | 502 | old_request) { |
Jeff Skirvin | 6373250 | 2012-03-08 22:41:55 -0800 | [diff] [blame] | 503 | idev = isci_get_device(task->dev->lldd_dev); |
Jeff Skirvin | 96f15f2 | 2013-07-11 17:18:58 -0700 | [diff] [blame] | 504 | target_done_already = test_bit(IREQ_COMPLETE_IN_TARGET, |
| 505 | &old_request->flags); |
| 506 | } |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 507 | spin_unlock(&task->task_state_lock); |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 508 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 509 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 510 | dev_warn(&ihost->pdev->dev, |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 511 | "%s: dev = %p (%s%s), task = %p, old_request == %p\n", |
| 512 | __func__, idev, |
| 513 | (dev_is_sata(task->dev) ? "STP/SATA" |
| 514 | : ((dev_is_expander(task->dev)) |
| 515 | ? "SMP" |
| 516 | : "SSP")), |
| 517 | ((idev) ? ((test_bit(IDEV_GONE, &idev->flags)) |
| 518 | ? " IDEV_GONE" |
| 519 | : "") |
| 520 | : " <NULL>"), |
| 521 | task, old_request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 522 | |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 523 | /* Device reset conditions signalled in task_state_flags are the |
| 524 | * responsbility of libsas to observe at the start of the error |
| 525 | * handler thread. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 526 | */ |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 527 | if (!idev || !old_request) { |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 528 | /* The request has already completed and there |
| 529 | * is nothing to do here other than to set the task |
| 530 | * done bit, and indicate that the task abort function |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 531 | * was successful. |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 532 | */ |
| 533 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 534 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 535 | task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | |
| 536 | SAS_TASK_STATE_PENDING); |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 537 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 538 | |
| 539 | ret = TMF_RESP_FUNC_COMPLETE; |
| 540 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 541 | dev_warn(&ihost->pdev->dev, |
| 542 | "%s: abort task not needed for %p\n", |
| 543 | __func__, task); |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 544 | goto out; |
James Bottomley | a5ec7f86 | 2011-07-03 14:14:45 -0500 | [diff] [blame] | 545 | } |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 546 | /* Suspend the RNC, kill the TC */ |
| 547 | if (isci_remote_device_suspend_terminate(ihost, idev, old_request) |
| 548 | != SCI_SUCCESS) { |
| 549 | dev_warn(&ihost->pdev->dev, |
| 550 | "%s: isci_remote_device_reset_terminate(dev=%p, " |
| 551 | "req=%p, task=%p) failed\n", |
| 552 | __func__, idev, old_request, task); |
| 553 | ret = TMF_RESP_FUNC_FAILED; |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 554 | goto out; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 555 | } |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 556 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 557 | |
Dan Williams | 38d8879 | 2011-06-23 14:33:48 -0700 | [diff] [blame] | 558 | if (task->task_proto == SAS_PROTOCOL_SMP || |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 559 | sas_protocol_ata(task->task_proto) || |
Jeff Skirvin | 96f15f2 | 2013-07-11 17:18:58 -0700 | [diff] [blame] | 560 | target_done_already || |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 561 | test_bit(IDEV_GONE, &idev->flags)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 562 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 563 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Jeff Skirvin | a5fde22 | 2011-03-04 14:06:42 -0800 | [diff] [blame] | 564 | |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame] | 565 | /* No task to send, so explicitly resume the device here */ |
| 566 | isci_remote_device_resume_from_abort(ihost, idev); |
| 567 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 568 | dev_warn(&ihost->pdev->dev, |
| 569 | "%s: %s request" |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 570 | " or complete_in_target (%d), " |
| 571 | "or IDEV_GONE (%d), thus no TMF\n", |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 572 | __func__, |
| 573 | ((task->task_proto == SAS_PROTOCOL_SMP) |
| 574 | ? "SMP" |
| 575 | : (sas_protocol_ata(task->task_proto) |
| 576 | ? "SATA/STP" |
| 577 | : "<other>") |
| 578 | ), |
| 579 | test_bit(IREQ_COMPLETE_IN_TARGET, |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 580 | &old_request->flags), |
| 581 | test_bit(IDEV_GONE, &idev->flags)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 582 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 583 | spin_lock_irqsave(&task->task_state_lock, flags); |
| 584 | task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR | |
| 585 | SAS_TASK_STATE_PENDING); |
| 586 | task->task_state_flags |= SAS_TASK_STATE_DONE; |
| 587 | spin_unlock_irqrestore(&task->task_state_lock, flags); |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 588 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 589 | ret = TMF_RESP_FUNC_COMPLETE; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 590 | } else { |
Geert Uytterhoeven | 4e21051 | 2014-10-22 11:49:02 +0200 | [diff] [blame] | 591 | /* Fill in the tmf structure */ |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 592 | isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort, |
Jeff Skirvin | c3f42fe | 2011-03-04 14:06:56 -0800 | [diff] [blame] | 593 | old_request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 594 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 595 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 596 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 597 | /* Send the task management request. */ |
Jeff Skirvin | 98145cb | 2011-10-27 15:05:16 -0700 | [diff] [blame] | 598 | #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */ |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 599 | ret = isci_task_execute_tmf(ihost, idev, &tmf, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 600 | ISCI_ABORT_TASK_TIMEOUT_MS); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 601 | } |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 602 | out: |
Jeff Skirvin | 6373250 | 2012-03-08 22:41:55 -0800 | [diff] [blame] | 603 | dev_warn(&ihost->pdev->dev, |
| 604 | "%s: Done; dev = %p, task = %p , old_request == %p\n", |
| 605 | __func__, idev, task, old_request); |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 606 | isci_put_device(idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * isci_task_abort_task_set() - This function is one of the SAS Domain Template |
| 612 | * functions. This is one of the Task Management functoins called by libsas, |
| 613 | * to abort all task for the given lun. |
| 614 | * @d_device: This parameter specifies the domain device associated with this |
| 615 | * request. |
| 616 | * @lun: This parameter specifies the lun associated with this request. |
| 617 | * |
| 618 | * status, zero indicates success. |
| 619 | */ |
| 620 | int isci_task_abort_task_set( |
| 621 | struct domain_device *d_device, |
| 622 | u8 *lun) |
| 623 | { |
| 624 | return TMF_RESP_FUNC_FAILED; |
| 625 | } |
| 626 | |
| 627 | |
| 628 | /** |
| 629 | * isci_task_clear_aca() - This function is one of the SAS Domain Template |
| 630 | * functions. This is one of the Task Management functoins called by libsas. |
| 631 | * @d_device: This parameter specifies the domain device associated with this |
| 632 | * request. |
| 633 | * @lun: This parameter specifies the lun associated with this request. |
| 634 | * |
| 635 | * status, zero indicates success. |
| 636 | */ |
| 637 | int isci_task_clear_aca( |
| 638 | struct domain_device *d_device, |
| 639 | u8 *lun) |
| 640 | { |
| 641 | return TMF_RESP_FUNC_FAILED; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | |
| 646 | /** |
| 647 | * isci_task_clear_task_set() - This function is one of the SAS Domain Template |
| 648 | * functions. This is one of the Task Management functoins called by libsas. |
| 649 | * @d_device: This parameter specifies the domain device associated with this |
| 650 | * request. |
| 651 | * @lun: This parameter specifies the lun associated with this request. |
| 652 | * |
| 653 | * status, zero indicates success. |
| 654 | */ |
| 655 | int isci_task_clear_task_set( |
| 656 | struct domain_device *d_device, |
| 657 | u8 *lun) |
| 658 | { |
| 659 | return TMF_RESP_FUNC_FAILED; |
| 660 | } |
| 661 | |
| 662 | |
| 663 | /** |
| 664 | * isci_task_query_task() - This function is implemented to cause libsas to |
| 665 | * correctly escalate the failed abort to a LUN or target reset (this is |
| 666 | * because sas_scsi_find_task libsas function does not correctly interpret |
| 667 | * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is |
| 668 | * returned, libsas turns this into a LUN reset; when FUNC_FAILED is |
| 669 | * returned, libsas will turn this into a target reset |
| 670 | * @task: This parameter specifies the sas task being queried. |
| 671 | * @lun: This parameter specifies the lun associated with this request. |
| 672 | * |
| 673 | * status, zero indicates success. |
| 674 | */ |
| 675 | int isci_task_query_task( |
| 676 | struct sas_task *task) |
| 677 | { |
| 678 | /* See if there is a pending device reset for this device. */ |
| 679 | if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) |
| 680 | return TMF_RESP_FUNC_FAILED; |
| 681 | else |
| 682 | return TMF_RESP_FUNC_SUCC; |
| 683 | } |
| 684 | |
Dave Jiang | af5ae89 | 2011-05-04 17:53:24 -0700 | [diff] [blame] | 685 | /* |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 686 | * isci_task_request_complete() - This function is called by the sci core when |
| 687 | * an task request completes. |
Dave Jiang | af5ae89 | 2011-05-04 17:53:24 -0700 | [diff] [blame] | 688 | * @ihost: This parameter specifies the ISCI host object |
| 689 | * @ireq: This parameter is the completed isci_request object. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 690 | * @completion_status: This parameter specifies the completion status from the |
| 691 | * sci core. |
| 692 | * |
| 693 | * none. |
| 694 | */ |
Dave Jiang | af5ae89 | 2011-05-04 17:53:24 -0700 | [diff] [blame] | 695 | void |
| 696 | isci_task_request_complete(struct isci_host *ihost, |
| 697 | struct isci_request *ireq, |
| 698 | enum sci_task_status completion_status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 699 | { |
Dave Jiang | af5ae89 | 2011-05-04 17:53:24 -0700 | [diff] [blame] | 700 | struct isci_tmf *tmf = isci_request_access_tmf(ireq); |
Jeff Skirvin | b343dff | 2011-10-27 15:05:06 -0700 | [diff] [blame] | 701 | struct completion *tmf_complete = NULL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 702 | |
Dave Jiang | af5ae89 | 2011-05-04 17:53:24 -0700 | [diff] [blame] | 703 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 704 | "%s: request = %p, status=%d\n", |
Dave Jiang | af5ae89 | 2011-05-04 17:53:24 -0700 | [diff] [blame] | 705 | __func__, ireq, completion_status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 706 | |
Dan Williams | 38d8879 | 2011-06-23 14:33:48 -0700 | [diff] [blame] | 707 | set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 708 | |
Jeff Skirvin | b343dff | 2011-10-27 15:05:06 -0700 | [diff] [blame] | 709 | if (tmf) { |
| 710 | tmf->status = completion_status; |
| 711 | |
| 712 | if (tmf->proto == SAS_PROTOCOL_SSP) { |
| 713 | memcpy(&tmf->resp.resp_iu, |
| 714 | &ireq->ssp.rsp, |
| 715 | SSP_RESP_IU_MAX_SIZE); |
| 716 | } else if (tmf->proto == SAS_PROTOCOL_SATA) { |
| 717 | memcpy(&tmf->resp.d2h_fis, |
| 718 | &ireq->stp.rsp, |
| 719 | sizeof(struct dev_to_host_fis)); |
| 720 | } |
| 721 | /* PRINT_TMF( ((struct isci_tmf *)request->task)); */ |
| 722 | tmf_complete = tmf->complete; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 723 | } |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 724 | sci_controller_complete_io(ihost, ireq->target_device, ireq); |
Dan Williams | 67ea838 | 2011-05-08 11:47:15 -0700 | [diff] [blame] | 725 | /* set the 'terminated' flag handle to make sure it cannot be terminated |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 726 | * or completed again. |
| 727 | */ |
Dan Williams | 38d8879 | 2011-06-23 14:33:48 -0700 | [diff] [blame] | 728 | set_bit(IREQ_TERMINATED, &ireq->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 729 | |
Jeff Skirvin | 1db79b3 | 2012-03-08 22:42:05 -0800 | [diff] [blame] | 730 | if (test_and_clear_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags)) |
| 731 | wake_up_all(&ihost->eventq); |
| 732 | |
Jeff Skirvin | 621120c | 2012-03-08 22:42:03 -0800 | [diff] [blame] | 733 | if (!test_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags)) |
| 734 | isci_free_tag(ihost, ireq->io_tag); |
Jeff Skirvin | b343dff | 2011-10-27 15:05:06 -0700 | [diff] [blame] | 735 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 736 | /* The task management part completes last. */ |
Jeff Skirvin | b343dff | 2011-10-27 15:05:06 -0700 | [diff] [blame] | 737 | if (tmf_complete) |
| 738 | complete(tmf_complete); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 741 | static int isci_reset_device(struct isci_host *ihost, |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 742 | struct domain_device *dev, |
Jeff Skirvin | bc6f387 | 2011-07-01 13:03:44 -0700 | [diff] [blame] | 743 | struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 744 | { |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 745 | int rc = TMF_RESP_FUNC_COMPLETE, reset_stat = -1; |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 746 | struct sas_phy *phy = sas_get_local_phy(dev); |
| 747 | struct isci_port *iport = dev->port->lldd_port; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 748 | |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 749 | dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 750 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 751 | /* Suspend the RNC, terminate all outstanding TCs. */ |
| 752 | if (isci_remote_device_suspend_terminate(ihost, idev, NULL) |
| 753 | != SCI_SUCCESS) { |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 754 | rc = TMF_RESP_FUNC_FAILED; |
| 755 | goto out; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 756 | } |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 757 | /* Note that since the termination for outstanding requests succeeded, |
| 758 | * this function will return success. This is because the resets will |
| 759 | * only fail if the device has been removed (ie. hotplug), and the |
| 760 | * primary duty of this function is to cleanup tasks, so that is the |
| 761 | * relevant status. |
| 762 | */ |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 763 | if (!test_bit(IDEV_GONE, &idev->flags)) { |
| 764 | if (scsi_is_sas_phy_local(phy)) { |
| 765 | struct isci_phy *iphy = &ihost->phys[phy->number]; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 766 | |
Jeff Skirvin | 397497d | 2012-03-10 05:46:46 +0000 | [diff] [blame] | 767 | reset_stat = isci_port_perform_hard_reset(ihost, iport, |
| 768 | iphy); |
| 769 | } else |
| 770 | reset_stat = sas_phy_reset(phy, !dev_is_sata(dev)); |
| 771 | } |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 772 | /* Explicitly resume the RNC here, since there was no task sent. */ |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame] | 773 | isci_remote_device_resume_from_abort(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 774 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 775 | dev_dbg(&ihost->pdev->dev, "%s: idev %p complete, reset_stat=%d.\n", |
| 776 | __func__, idev, reset_stat); |
Dan Williams | f41a0c4 | 2011-12-21 21:33:17 -0800 | [diff] [blame] | 777 | out: |
| 778 | sas_put_local_phy(phy); |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 779 | return rc; |
| 780 | } |
| 781 | |
| 782 | int isci_task_I_T_nexus_reset(struct domain_device *dev) |
| 783 | { |
| 784 | struct isci_host *ihost = dev_to_ihost(dev); |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 785 | struct isci_remote_device *idev; |
| 786 | unsigned long flags; |
Jeff Skirvin | bc6f387 | 2011-07-01 13:03:44 -0700 | [diff] [blame] | 787 | int ret; |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 788 | |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 789 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 790 | idev = isci_get_device(dev->lldd_dev); |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 791 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 792 | |
Dan Williams | 5a99832 | 2011-12-12 20:32:09 -0800 | [diff] [blame] | 793 | if (!idev) { |
| 794 | /* XXX: need to cleanup any ireqs targeting this |
| 795 | * domain_device |
| 796 | */ |
Dan Williams | ddfadd7 | 2014-02-06 12:23:01 -0800 | [diff] [blame] | 797 | ret = -ENODEV; |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 798 | goto out; |
| 799 | } |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 800 | |
Dan Williams | 9277699 | 2011-11-30 11:57:34 -0800 | [diff] [blame] | 801 | ret = isci_reset_device(ihost, dev, idev); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 802 | out: |
| 803 | isci_put_device(idev); |
| 804 | return ret; |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 805 | } |