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