blob: 29ce8815e799de2930087f75ca10f64013d9e524 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 Williams50e7f9b2011-03-09 21:27:46 -080057#include <linux/irqflags.h>
Dave Jiangaf5ae892011-05-04 17:53:24 -070058#include "sas.h"
Jeff Skirvin61aaff42011-06-21 12:16:33 -070059#include <scsi/libsas.h>
Dan Williams88f3b622011-04-22 19:18:03 -070060#include "remote_device.h"
61#include "remote_node_context.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070062#include "isci.h"
63#include "request.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070064#include "task.h"
Dan Williams312e0c22011-06-28 13:47:09 -070065#include "host.h"
Dave Jiangaf5ae892011-05-04 17:53:24 -070066
Dan Williams50e7f9b2011-03-09 21:27:46 -080067/**
Dan Williams1077a572011-03-11 10:13:51 -080068* 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 Williams50e7f9b2011-03-09 21:27:46 -080074*
Dan Williams50e7f9b2011-03-09 21:27:46 -080075*/
Dan Williams1077a572011-03-11 10:13:51 -080076static void isci_task_refuse(struct isci_host *ihost, struct sas_task *task,
77 enum service_response response,
78 enum exec_status status)
Dan Williams50e7f9b2011-03-09 21:27:46 -080079
Dan Williams1077a572011-03-11 10:13:51 -080080{
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080081 unsigned long flags;
Dan Williams1077a572011-03-11 10:13:51 -080082
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080083 /* Normal notification (task_done) */
84 dev_dbg(&ihost->pdev->dev, "%s: task = %p, response=%d, status=%d\n",
85 __func__, task, response, status);
Dan Williams50e7f9b2011-03-09 21:27:46 -080086
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080087 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams50e7f9b2011-03-09 21:27:46 -080088
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080089 task->task_status.resp = response;
90 task->task_status.stat = status;
Dan Williams50e7f9b2011-03-09 21:27:46 -080091
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080092 /* 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 Williams50e7f9b2011-03-09 21:27:46 -080098
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080099 task->task_done(task);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800100}
Dan Williams6f231dd2011-07-02 22:56:22 -0700101
Dan Williams1077a572011-03-11 10:13:51 -0800102#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 Skirvin9274f452011-06-23 17:09:02 -0700106
107static 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 Williams6f231dd2011-07-02 22:56:22 -0700115/**
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 */
125int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags)
126{
Dan Williams4393aa42011-03-31 13:10:44 -0700127 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams209fae12011-06-13 17:39:44 -0700128 struct isci_remote_device *idev;
Dan Williamsf2088262011-06-16 11:26:12 -0700129 unsigned long flags;
130 bool io_ready;
Dan Williams312e0c22011-06-28 13:47:09 -0700131 u16 tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700132
Dan Williams1077a572011-03-11 10:13:51 -0800133 dev_dbg(&ihost->pdev->dev, "%s: num=%d\n", __func__, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700134
Dan Williams1077a572011-03-11 10:13:51 -0800135 for_each_sas_task(num, task) {
Dan Williams312e0c22011-06-28 13:47:09 -0700136 enum sci_status status = SCI_FAILURE;
137
Dan Williams209fae12011-06-13 17:39:44 -0700138 spin_lock_irqsave(&ihost->scic_lock, flags);
139 idev = isci_lookup_device(task->dev);
Jeff Skirvin9274f452011-06-23 17:09:02 -0700140 io_ready = isci_device_io_ready(idev, task);
Dan Williams312e0c22011-06-28 13:47:09 -0700141 tag = isci_alloc_tag(ihost);
Dan Williams209fae12011-06-13 17:39:44 -0700142 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700143
Dan Williamsf2088262011-06-16 11:26:12 -0700144 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 Skirvinf0846c62011-03-08 19:22:07 -0700148
Dan Williamsf2088262011-06-16 11:26:12 -0700149 if (!idev) {
150 isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED,
151 SAS_DEVICE_UNKNOWN);
Dan Williams312e0c22011-06-28 13:47:09 -0700152 } else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) {
Dan Williamsf2088262011-06-16 11:26:12 -0700153 /* 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 Williams6f231dd2011-07-02 22:56:22 -0700158 } else {
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700159 /* There is a device and it's ready for I/O. */
160 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700161
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700162 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
Dan Williamsf2088262011-06-16 11:26:12 -0700163 /* The I/O was aborted. */
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700164 spin_unlock_irqrestore(&task->task_state_lock,
165 flags);
166
Dan Williams1077a572011-03-11 10:13:51 -0800167 isci_task_refuse(ihost, task,
168 SAS_TASK_UNDELIVERED,
169 SAM_STAT_TASK_ABORTED);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700170 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700171 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
172 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700173
174 /* build and send the request. */
Dan Williamsdb056252011-06-17 14:18:39 -0700175 status = isci_request_execute(ihost, idev, task, tag);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700176
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 Skirvinc2cb8a52011-10-27 15:04:56 -0700184 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 Skirvinf0846c62011-03-08 19:22:07 -0700205 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700206 }
207 }
Dan Williams312e0c22011-06-28 13:47:09 -0700208 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 Williams209fae12011-06-13 17:39:44 -0700216 isci_put_device(idev);
Dan Williams1077a572011-03-11 10:13:51 -0800217 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700218 return 0;
219}
220
Dan Williams0d0cf142011-06-13 00:51:30 -0700221static struct isci_request *isci_task_request_build(struct isci_host *ihost,
Dan Williams209fae12011-06-13 17:39:44 -0700222 struct isci_remote_device *idev,
Dan Williams312e0c22011-06-28 13:47:09 -0700223 u16 tag, struct isci_tmf *isci_tmf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700224{
Dan Williams6f231dd2011-07-02 22:56:22 -0700225 enum sci_status status = SCI_FAILURE;
Dan Williams0d0cf142011-06-13 00:51:30 -0700226 struct isci_request *ireq = NULL;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700227 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700228
Dan Williams0d0cf142011-06-13 00:51:30 -0700229 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700230 "%s: isci_tmf = %p\n", __func__, isci_tmf);
231
Dan Williams0d0cf142011-06-13 00:51:30 -0700232 dev = idev->domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700233
234 /* do common allocation and init of request object. */
Dan Williamsdb056252011-06-17 14:18:39 -0700235 ireq = isci_tmf_request_from_tag(ihost, isci_tmf, tag);
Dan Williams0d0cf142011-06-13 00:51:30 -0700236 if (!ireq)
237 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700238
239 /* let the core do it's construct. */
Dan Williams89a73012011-06-30 19:14:33 -0700240 status = sci_task_request_construct(ihost, idev, tag,
Dan Williams5076a1a2011-06-27 14:57:03 -0700241 ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700242
243 if (status != SCI_SUCCESS) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700244 dev_warn(&ihost->pdev->dev,
Dan Williams89a73012011-06-30 19:14:33 -0700245 "%s: sci_task_request_construct failed - "
Dan Williams6f231dd2011-07-02 22:56:22 -0700246 "status = 0x%x\n",
247 __func__,
248 status);
Dan Williamsdb056252011-06-17 14:18:39 -0700249 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700250 }
251
Dan Williamsa1a113b2011-04-21 18:44:45 -0700252 /* XXX convert to get this from task->tproto like other drivers */
253 if (dev->dev_type == SAS_END_DEV) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700254 isci_tmf->proto = SAS_PROTOCOL_SSP;
Dan Williams89a73012011-06-30 19:14:33 -0700255 status = sci_task_request_construct_ssp(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700256 if (status != SCI_SUCCESS)
Dan Williamsdb056252011-06-17 14:18:39 -0700257 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700258 }
259
Dan Williams0d0cf142011-06-13 00:51:30 -0700260 return ireq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700261}
262
Dan Williams16ba7702011-07-01 10:52:55 -0700263static 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 Williams6f231dd2011-07-02 22:56:22 -0700266{
267 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700268 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams0d0cf142011-06-13 00:51:30 -0700269 struct isci_request *ireq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700270 int ret = TMF_RESP_FUNC_FAILED;
271 unsigned long flags;
Edmund Nadolskifd183882011-05-19 12:00:15 +0000272 unsigned long timeleft;
Dan Williams312e0c22011-06-28 13:47:09 -0700273 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 Williams6f231dd2011-07-02 22:56:22 -0700281
282 /* sanity check, return TMF_RESP_FUNC_FAILED
283 * if the device is not there and ready.
284 */
Dan Williams78a6f062011-06-30 16:31:37 -0700285 if (!idev ||
286 (!test_bit(IDEV_IO_READY, &idev->flags) &&
287 !test_bit(IDEV_IO_NCQERROR, &idev->flags))) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700288 dev_dbg(&ihost->pdev->dev,
Dan Williams78a6f062011-06-30 16:31:37 -0700289 "%s: idev = %p not ready (%#lx)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700290 __func__,
Dan Williams78a6f062011-06-30 16:31:37 -0700291 idev, idev ? idev->flags : 0);
Dan Williams312e0c22011-06-28 13:47:09 -0700292 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700293 } else
Dan Williams0d0cf142011-06-13 00:51:30 -0700294 dev_dbg(&ihost->pdev->dev,
Dan Williams78a6f062011-06-30 16:31:37 -0700295 "%s: idev = %p\n",
296 __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700297
298 /* Assign the pointer to the TMF's completion kernel wait structure. */
299 tmf->complete = &completion;
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700300 tmf->status = SCI_FAILURE_TIMEOUT;
Dan Williams6f231dd2011-07-02 22:56:22 -0700301
Dan Williams78a6f062011-06-30 16:31:37 -0700302 ireq = isci_task_request_build(ihost, idev, tag, tmf);
Dan Williams312e0c22011-06-28 13:47:09 -0700303 if (!ireq)
304 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700305
Dan Williams0d0cf142011-06-13 00:51:30 -0700306 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700307
308 /* start the TMF io. */
Dan Williams89a73012011-06-30 19:14:33 -0700309 status = sci_controller_start_task(ihost, idev, ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700310
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700311 if (status != SCI_TASK_SUCCESS) {
Dan Williamsa8a0a132011-07-01 12:07:25 -0700312 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700313 "%s: start_io failed - status = 0x%x, request = %p\n",
314 __func__,
315 status,
Dan Williams0d0cf142011-06-13 00:51:30 -0700316 ireq);
317 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsdb056252011-06-17 14:18:39 -0700318 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700319 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700320 /* add the request to the remote device request list. */
Dan Williams78a6f062011-06-30 16:31:37 -0700321 list_add(&ireq->dev_node, &idev->reqs_in_process);
Dan Williams6f231dd2011-07-02 22:56:22 -0700322
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800323 /* The RNC must be unsuspended before the TMF can get a response. */
324 sci_remote_device_resume(idev, NULL, NULL);
325
Dan Williams0d0cf142011-06-13 00:51:30 -0700326 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700327
328 /* Wait for the TMF to complete, or a timeout. */
Edmund Nadolskifd183882011-05-19 12:00:15 +0000329 timeleft = wait_for_completion_timeout(&completion,
Dan Williams086a0da2011-06-21 16:23:03 -0700330 msecs_to_jiffies(timeout_ms));
Edmund Nadolskifd183882011-05-19 12:00:15 +0000331
332 if (timeleft == 0) {
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700333 /* The TMF did not complete - this could be because
334 * of an unplug. Terminate the TMF request now.
335 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800336 isci_remote_device_suspend_terminate(ihost, idev, ireq);
Edmund Nadolskifd183882011-05-19 12:00:15 +0000337 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700338
Maciej Trela27234ab2012-01-04 01:33:05 -0800339 isci_print_tmf(ihost, tmf);
Dan Williams6f231dd2011-07-02 22:56:22 -0700340
341 if (tmf->status == SCI_SUCCESS)
342 ret = TMF_RESP_FUNC_COMPLETE;
343 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700344 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700345 "%s: tmf.status == "
346 "SCI_FAILURE_IO_RESPONSE_VALID\n",
347 __func__);
348 ret = TMF_RESP_FUNC_COMPLETE;
349 }
350 /* Else - leave the default "failed" status alone. */
351
Dan Williams0d0cf142011-06-13 00:51:30 -0700352 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700353 "%s: completed request = %p\n",
354 __func__,
Dan Williams0d0cf142011-06-13 00:51:30 -0700355 ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700356
Dan Williams6f231dd2011-07-02 22:56:22 -0700357 return ret;
Dan Williams312e0c22011-06-28 13:47:09 -0700358
Dan Williams312e0c22011-06-28 13:47:09 -0700359 err_tci:
360 spin_lock_irqsave(&ihost->scic_lock, flags);
361 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
362 spin_unlock_irqrestore(&ihost->scic_lock, flags);
363
364 return ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700365}
366
Dan Williams16ba7702011-07-01 10:52:55 -0700367static void isci_task_build_tmf(struct isci_tmf *tmf,
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800368 enum isci_tmf_function_codes code)
Dan Williams6f231dd2011-07-02 22:56:22 -0700369{
Dan Williams6f231dd2011-07-02 22:56:22 -0700370 memset(tmf, 0, sizeof(*tmf));
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800371 tmf->tmf_code = code;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800372}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800373
Dan Williams16ba7702011-07-01 10:52:55 -0700374static void isci_task_build_abort_task_tmf(struct isci_tmf *tmf,
375 enum isci_tmf_function_codes code,
Dan Williams16ba7702011-07-01 10:52:55 -0700376 struct isci_request *old_request)
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800377{
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800378 isci_task_build_tmf(tmf, code);
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800379 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700380}
381
Dan Williams6f231dd2011-07-02 22:56:22 -0700382/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700383 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
384 * Template functions.
385 * @lun: This parameter specifies the lun to be reset.
386 *
387 * status, zero indicates success.
388 */
389static int isci_task_send_lu_reset_sas(
390 struct isci_host *isci_host,
391 struct isci_remote_device *isci_device,
392 u8 *lun)
393{
394 struct isci_tmf tmf;
395 int ret = TMF_RESP_FUNC_FAILED;
396
397 dev_dbg(&isci_host->pdev->dev,
398 "%s: isci_host = %p, isci_device = %p\n",
399 __func__, isci_host, isci_device);
400 /* Send the LUN reset to the target. By the time the call returns,
401 * the TMF has fully exected in the target (in which case the return
402 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
403 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
404 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800405 isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset);
Dan Williams6f231dd2011-07-02 22:56:22 -0700406
407 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
Dan Williams209fae12011-06-13 17:39:44 -0700408 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
Dan Williams6f231dd2011-07-02 22:56:22 -0700409
410 if (ret == TMF_RESP_FUNC_COMPLETE)
411 dev_dbg(&isci_host->pdev->dev,
412 "%s: %p: TMF_LU_RESET passed\n",
413 __func__, isci_device);
414 else
415 dev_dbg(&isci_host->pdev->dev,
416 "%s: %p: TMF_LU_RESET failed (%x)\n",
417 __func__, isci_device, ret);
418
419 return ret;
420}
421
Dan Williams43a5ab12011-12-08 23:20:44 -0800422int isci_task_lu_reset(struct domain_device *dev, u8 *lun)
Dan Williams16ba7702011-07-01 10:52:55 -0700423{
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800424 struct isci_host *ihost = dev_to_ihost(dev);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800425 struct isci_remote_device *idev;
Dan Williams209fae12011-06-13 17:39:44 -0700426 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700427 int ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700428
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800429 spin_lock_irqsave(&ihost->scic_lock, flags);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800430 idev = isci_lookup_device(dev);
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800431 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700432
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800433 dev_dbg(&ihost->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -0700434 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800435 __func__, dev, ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700436
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800437 if (!idev) {
Jeff Skirvind80ecd52012-03-08 22:41:53 -0800438 /* If the device is gone, escalate to I_T_Nexus_Reset. */
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800439 dev_dbg(&ihost->pdev->dev, "%s: No dev\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -0700440
Jeff Skirvind80ecd52012-03-08 22:41:53 -0800441 ret = TMF_RESP_FUNC_FAILED;
Dan Williams209fae12011-06-13 17:39:44 -0700442 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -0700443 }
444
Dan Williams43a5ab12011-12-08 23:20:44 -0800445 if (dev_is_sata(dev)) {
446 sas_ata_schedule_reset(dev);
447 ret = TMF_RESP_FUNC_COMPLETE;
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800448 } else {
449 /* Suspend the RNC, kill all TCs */
450 if (isci_remote_device_suspend_terminate(ihost, idev, NULL)
451 != SCI_SUCCESS) {
452 ret = TMF_RESP_FUNC_FAILED;
453 goto out;
454 }
455 /* Send the task management part of the reset. */
456 ret = isci_task_send_lu_reset_sas(ihost, idev, lun);
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800457 }
Dan Williams209fae12011-06-13 17:39:44 -0700458 out:
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800459 isci_put_device(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700460 return ret;
461}
462
463
464/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
465int isci_task_clear_nexus_port(struct asd_sas_port *port)
466{
467 return TMF_RESP_FUNC_FAILED;
468}
469
470
471
472int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
473{
474 return TMF_RESP_FUNC_FAILED;
475}
476
Dan Williams6f231dd2011-07-02 22:56:22 -0700477/* Task Management Functions. Must be called from process context. */
478
479/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700480 * isci_task_abort_task() - This function is one of the SAS Domain Template
481 * functions. This function is called by libsas to abort a specified task.
482 * @task: This parameter specifies the SAS task to abort.
483 *
484 * status, zero indicates success.
485 */
486int isci_task_abort_task(struct sas_task *task)
487{
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800488 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700489 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800490 struct isci_request *old_request = NULL;
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800491 struct isci_remote_device *idev = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -0800492 struct isci_tmf tmf;
493 int ret = TMF_RESP_FUNC_FAILED;
494 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700495
496 /* Get the isci_request reference from the task. Note that
497 * this check does not depend on the pending request list
498 * in the device, because tasks driving resets may land here
499 * after completion in the core.
500 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800501 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams209fae12011-06-13 17:39:44 -0700502 spin_lock(&task->task_state_lock);
503
504 old_request = task->lldd_task;
505
506 /* If task is already done, the request isn't valid */
507 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
508 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
509 old_request)
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800510 idev = isci_lookup_device(task->dev);
Dan Williams209fae12011-06-13 17:39:44 -0700511
512 spin_unlock(&task->task_state_lock);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800513 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700514
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800515 dev_warn(&ihost->pdev->dev,
516 "%s: dev = %p, task = %p, old_request == %p\n",
517 __func__, idev, task, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700518
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700519 /* Device reset conditions signalled in task_state_flags are the
520 * responsbility of libsas to observe at the start of the error
521 * handler thread.
Dan Williams6f231dd2011-07-02 22:56:22 -0700522 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800523 if (!idev || !old_request) {
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700524 /* The request has already completed and there
525 * is nothing to do here other than to set the task
526 * done bit, and indicate that the task abort function
527 * was sucessful.
528 */
529 spin_lock_irqsave(&task->task_state_lock, flags);
530 task->task_state_flags |= SAS_TASK_STATE_DONE;
531 task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
532 SAS_TASK_STATE_PENDING);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800533 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700534
535 ret = TMF_RESP_FUNC_COMPLETE;
536
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800537 dev_warn(&ihost->pdev->dev,
538 "%s: abort task not needed for %p\n",
539 __func__, task);
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700540 goto out;
James Bottomleya5ec7f862011-07-03 14:14:45 -0500541 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800542 /* Suspend the RNC, kill the TC */
543 if (isci_remote_device_suspend_terminate(ihost, idev, old_request)
544 != SCI_SUCCESS) {
545 dev_warn(&ihost->pdev->dev,
546 "%s: isci_remote_device_reset_terminate(dev=%p, "
547 "req=%p, task=%p) failed\n",
548 __func__, idev, old_request, task);
549 ret = TMF_RESP_FUNC_FAILED;
Dan Williams209fae12011-06-13 17:39:44 -0700550 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -0700551 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800552 spin_lock_irqsave(&ihost->scic_lock, flags);
553
Dan Williams38d88792011-06-23 14:33:48 -0700554 if (task->task_proto == SAS_PROTOCOL_SMP ||
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700555 sas_protocol_ata(task->task_proto) ||
Dan Williams38d88792011-06-23 14:33:48 -0700556 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700557
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800558 /* No task to send, so explicitly resume the device here */
559 sci_remote_device_resume(idev, NULL, NULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700560
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800561 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800562
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800563 dev_warn(&ihost->pdev->dev,
564 "%s: %s request"
565 " or complete_in_target (%d), thus no TMF\n",
566 __func__,
567 ((task->task_proto == SAS_PROTOCOL_SMP)
568 ? "SMP"
569 : (sas_protocol_ata(task->task_proto)
570 ? "SATA/STP"
571 : "<other>")
572 ),
573 test_bit(IREQ_COMPLETE_IN_TARGET,
574 &old_request->flags));
Dan Williams6f231dd2011-07-02 22:56:22 -0700575
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800576 spin_lock_irqsave(&task->task_state_lock, flags);
577 task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
578 SAS_TASK_STATE_PENDING);
579 task->task_state_flags |= SAS_TASK_STATE_DONE;
580 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700581
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800582 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700583 } else {
584 /* Fill in the tmf stucture */
Dan Williams209fae12011-06-13 17:39:44 -0700585 isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort,
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800586 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700587
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800588 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700589
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800590 /* Send the task management request. */
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700591 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800592 ret = isci_task_execute_tmf(ihost, idev, &tmf,
Dan Williams6f231dd2011-07-02 22:56:22 -0700593 ISCI_ABORT_TASK_TIMEOUT_MS);
Dan Williams6f231dd2011-07-02 22:56:22 -0700594 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800595out:
596 isci_put_device(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700597 return ret;
598}
599
600/**
601 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
602 * functions. This is one of the Task Management functoins called by libsas,
603 * to abort all task for the given lun.
604 * @d_device: This parameter specifies the domain device associated with this
605 * request.
606 * @lun: This parameter specifies the lun associated with this request.
607 *
608 * status, zero indicates success.
609 */
610int isci_task_abort_task_set(
611 struct domain_device *d_device,
612 u8 *lun)
613{
614 return TMF_RESP_FUNC_FAILED;
615}
616
617
618/**
619 * isci_task_clear_aca() - This function is one of the SAS Domain Template
620 * functions. This is one of the Task Management functoins called by libsas.
621 * @d_device: This parameter specifies the domain device associated with this
622 * request.
623 * @lun: This parameter specifies the lun associated with this request.
624 *
625 * status, zero indicates success.
626 */
627int isci_task_clear_aca(
628 struct domain_device *d_device,
629 u8 *lun)
630{
631 return TMF_RESP_FUNC_FAILED;
632}
633
634
635
636/**
637 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
638 * functions. This is one of the Task Management functoins called by libsas.
639 * @d_device: This parameter specifies the domain device associated with this
640 * request.
641 * @lun: This parameter specifies the lun associated with this request.
642 *
643 * status, zero indicates success.
644 */
645int isci_task_clear_task_set(
646 struct domain_device *d_device,
647 u8 *lun)
648{
649 return TMF_RESP_FUNC_FAILED;
650}
651
652
653/**
654 * isci_task_query_task() - This function is implemented to cause libsas to
655 * correctly escalate the failed abort to a LUN or target reset (this is
656 * because sas_scsi_find_task libsas function does not correctly interpret
657 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
658 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
659 * returned, libsas will turn this into a target reset
660 * @task: This parameter specifies the sas task being queried.
661 * @lun: This parameter specifies the lun associated with this request.
662 *
663 * status, zero indicates success.
664 */
665int isci_task_query_task(
666 struct sas_task *task)
667{
668 /* See if there is a pending device reset for this device. */
669 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
670 return TMF_RESP_FUNC_FAILED;
671 else
672 return TMF_RESP_FUNC_SUCC;
673}
674
Dave Jiangaf5ae892011-05-04 17:53:24 -0700675/*
Dan Williams6f231dd2011-07-02 22:56:22 -0700676 * isci_task_request_complete() - This function is called by the sci core when
677 * an task request completes.
Dave Jiangaf5ae892011-05-04 17:53:24 -0700678 * @ihost: This parameter specifies the ISCI host object
679 * @ireq: This parameter is the completed isci_request object.
Dan Williams6f231dd2011-07-02 22:56:22 -0700680 * @completion_status: This parameter specifies the completion status from the
681 * sci core.
682 *
683 * none.
684 */
Dave Jiangaf5ae892011-05-04 17:53:24 -0700685void
686isci_task_request_complete(struct isci_host *ihost,
687 struct isci_request *ireq,
688 enum sci_task_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700689{
Dave Jiangaf5ae892011-05-04 17:53:24 -0700690 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700691 struct completion *tmf_complete = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700692
Dave Jiangaf5ae892011-05-04 17:53:24 -0700693 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700694 "%s: request = %p, status=%d\n",
Dave Jiangaf5ae892011-05-04 17:53:24 -0700695 __func__, ireq, completion_status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700696
Dan Williams38d88792011-06-23 14:33:48 -0700697 set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700698
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700699 if (tmf) {
700 tmf->status = completion_status;
701
702 if (tmf->proto == SAS_PROTOCOL_SSP) {
703 memcpy(&tmf->resp.resp_iu,
704 &ireq->ssp.rsp,
705 SSP_RESP_IU_MAX_SIZE);
706 } else if (tmf->proto == SAS_PROTOCOL_SATA) {
707 memcpy(&tmf->resp.d2h_fis,
708 &ireq->stp.rsp,
709 sizeof(struct dev_to_host_fis));
710 }
711 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
712 tmf_complete = tmf->complete;
Dan Williams6f231dd2011-07-02 22:56:22 -0700713 }
Dan Williams89a73012011-06-30 19:14:33 -0700714 sci_controller_complete_io(ihost, ireq->target_device, ireq);
Dan Williams67ea8382011-05-08 11:47:15 -0700715 /* set the 'terminated' flag handle to make sure it cannot be terminated
Dan Williams6f231dd2011-07-02 22:56:22 -0700716 * or completed again.
717 */
Dan Williams38d88792011-06-23 14:33:48 -0700718 set_bit(IREQ_TERMINATED, &ireq->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700719
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800720 isci_free_tag(ihost, ireq->io_tag);
721 list_del_init(&ireq->dev_node);
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700722
Dan Williams6f231dd2011-07-02 22:56:22 -0700723 /* The task management part completes last. */
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700724 if (tmf_complete)
725 complete(tmf_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -0700726}
727
Dan Williams209fae12011-06-13 17:39:44 -0700728static int isci_reset_device(struct isci_host *ihost,
Dan Williams92776992011-11-30 11:57:34 -0800729 struct domain_device *dev,
Jeff Skirvinbc6f3872011-07-01 13:03:44 -0700730 struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -0700731{
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800732 int rc = TMF_RESP_FUNC_COMPLETE, reset_stat;
Dan Williams92776992011-11-30 11:57:34 -0800733 struct sas_phy *phy = sas_get_local_phy(dev);
734 struct isci_port *iport = dev->port->lldd_port;
Dan Williams6f231dd2011-07-02 22:56:22 -0700735
Dan Williamsd06b4872011-05-02 13:59:25 -0700736 dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700737
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800738 /* Suspend the RNC, terminate all outstanding TCs. */
739 if (isci_remote_device_suspend_terminate(ihost, idev, NULL)
740 != SCI_SUCCESS) {
Dan Williamsf41a0c42011-12-21 21:33:17 -0800741 rc = TMF_RESP_FUNC_FAILED;
742 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -0700743 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800744 /* Note that since the termination for outstanding requests succeeded,
745 * this function will return success. This is because the resets will
746 * only fail if the device has been removed (ie. hotplug), and the
747 * primary duty of this function is to cleanup tasks, so that is the
748 * relevant status.
749 */
Dan Williams6f231dd2011-07-02 22:56:22 -0700750
Dan Williams92776992011-11-30 11:57:34 -0800751 if (scsi_is_sas_phy_local(phy)) {
752 struct isci_phy *iphy = &ihost->phys[phy->number];
753
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800754 reset_stat = isci_port_perform_hard_reset(ihost, iport, iphy);
Dan Williams92776992011-11-30 11:57:34 -0800755 } else
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800756 reset_stat = sas_phy_reset(phy, !dev_is_sata(dev));
Dan Williams6f231dd2011-07-02 22:56:22 -0700757
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800758 /* Explicitly resume the RNC here, since there was no task sent. */
759 isci_remote_device_resume(ihost, idev, NULL, NULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700760
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800761 dev_dbg(&ihost->pdev->dev, "%s: idev %p complete, reset_stat=%d.\n",
762 __func__, idev, reset_stat);
Dan Williamsf41a0c42011-12-21 21:33:17 -0800763 out:
764 sas_put_local_phy(phy);
Dan Williamsd06b4872011-05-02 13:59:25 -0700765 return rc;
766}
767
768int isci_task_I_T_nexus_reset(struct domain_device *dev)
769{
770 struct isci_host *ihost = dev_to_ihost(dev);
Dan Williamsd06b4872011-05-02 13:59:25 -0700771 struct isci_remote_device *idev;
772 unsigned long flags;
Jeff Skirvinbc6f3872011-07-01 13:03:44 -0700773 int ret;
Dan Williamsd06b4872011-05-02 13:59:25 -0700774
Dan Williamsd06b4872011-05-02 13:59:25 -0700775 spin_lock_irqsave(&ihost->scic_lock, flags);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800776 idev = isci_get_device(dev->lldd_dev);
Dan Williamsd06b4872011-05-02 13:59:25 -0700777 spin_unlock_irqrestore(&ihost->scic_lock, flags);
778
Dan Williams5a998322011-12-12 20:32:09 -0800779 if (!idev) {
780 /* XXX: need to cleanup any ireqs targeting this
781 * domain_device
782 */
Dan Williams209fae12011-06-13 17:39:44 -0700783 ret = TMF_RESP_FUNC_COMPLETE;
784 goto out;
785 }
Dan Williamsd06b4872011-05-02 13:59:25 -0700786
Dan Williams92776992011-11-30 11:57:34 -0800787 ret = isci_reset_device(ihost, dev, idev);
Dan Williams209fae12011-06-13 17:39:44 -0700788 out:
789 isci_put_device(idev);
790 return ret;
Dan Williamsd06b4872011-05-02 13:59:25 -0700791}