blob: c514b20293b2a74fb767bff43a17af4066822337 [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;
John Garry26fc0ea2022-02-10 18:43:24 +080094 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080095 task->lldd_task = NULL;
96 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams50e7f9b2011-03-09 21:27:46 -080097
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -080098 task->task_done(task);
Dan Williams50e7f9b2011-03-09 21:27:46 -080099}
Dan Williams6f231dd2011-07-02 22:56:22 -0700100
Dan Williams1077a572011-03-11 10:13:51 -0800101#define for_each_sas_task(num, task) \
102 for (; num > 0; num--,\
103 task = list_entry(task->list.next, struct sas_task, list))
104
Jeff Skirvin9274f452011-06-23 17:09:02 -0700105
106static inline int isci_device_io_ready(struct isci_remote_device *idev,
107 struct sas_task *task)
108{
109 return idev ? test_bit(IDEV_IO_READY, &idev->flags) ||
110 (test_bit(IDEV_IO_NCQERROR, &idev->flags) &&
111 isci_task_is_ncq_recovery(task))
112 : 0;
113}
Dan Williams6f231dd2011-07-02 22:56:22 -0700114/**
115 * isci_task_execute_task() - This function is one of the SAS Domain Template
116 * functions. This function is called by libsas to send a task down to
117 * hardware.
118 * @task: This parameter specifies the SAS task to send.
Dan Williams6f231dd2011-07-02 22:56:22 -0700119 * @gfp_flags: This parameter specifies the context of this call.
120 *
121 * status, zero indicates success.
122 */
Christoph Hellwig79855d12014-11-05 10:36:28 +0100123int isci_task_execute_task(struct sas_task *task, gfp_t gfp_flags)
Dan Williams6f231dd2011-07-02 22:56:22 -0700124{
Dan Williams4393aa42011-03-31 13:10:44 -0700125 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams209fae12011-06-13 17:39:44 -0700126 struct isci_remote_device *idev;
Dan Williamsf2088262011-06-16 11:26:12 -0700127 unsigned long flags;
Christoph Hellwig79855d12014-11-05 10:36:28 +0100128 enum sci_status status = SCI_FAILURE;
Dan Williamsf2088262011-06-16 11:26:12 -0700129 bool io_ready;
Dan Williams312e0c22011-06-28 13:47:09 -0700130 u16 tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700131
Christoph Hellwig79855d12014-11-05 10:36:28 +0100132 spin_lock_irqsave(&ihost->scic_lock, flags);
133 idev = isci_lookup_device(task->dev);
134 io_ready = isci_device_io_ready(idev, task);
135 tag = isci_alloc_tag(ihost);
136 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700137
Christoph Hellwig79855d12014-11-05 10:36:28 +0100138 dev_dbg(&ihost->pdev->dev,
139 "task: %p, dev: %p idev: %p:%#lx cmd = %p\n",
140 task, task->dev, idev, idev ? idev->flags : 0,
141 task->uldd_task);
Dan Williams312e0c22011-06-28 13:47:09 -0700142
Christoph Hellwig79855d12014-11-05 10:36:28 +0100143 if (!idev) {
144 isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED,
145 SAS_DEVICE_UNKNOWN);
146 } else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) {
147 /* Indicate QUEUE_FULL so that the scsi midlayer
148 * retries.
149 */
150 isci_task_refuse(ihost, task, SAS_TASK_COMPLETE,
151 SAS_QUEUE_FULL);
152 } else {
153 /* There is a device and it's ready for I/O. */
154 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700155
Christoph Hellwig79855d12014-11-05 10:36:28 +0100156 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
157 /* The I/O was aborted. */
158 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700159
Christoph Hellwig79855d12014-11-05 10:36:28 +0100160 isci_task_refuse(ihost, task,
161 SAS_TASK_UNDELIVERED,
Bart Van Assched377f412021-05-23 19:54:55 -0700162 SAS_SAM_STAT_TASK_ABORTED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700163 } else {
John Garryc39d5aa2022-02-10 18:43:23 +0800164 struct isci_request *ireq;
165
John Garryc39d5aa2022-02-10 18:43:23 +0800166 /* do common allocation and init of request object. */
167 ireq = isci_io_request_from_tag(ihost, task, tag);
Christoph Hellwig79855d12014-11-05 10:36:28 +0100168 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700169
Christoph Hellwig79855d12014-11-05 10:36:28 +0100170 /* build and send the request. */
John Garryc39d5aa2022-02-10 18:43:23 +0800171 /* do common allocation and init of request object. */
172 status = isci_request_execute(ihost, idev, task, ireq);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700173
Christoph Hellwig79855d12014-11-05 10:36:28 +0100174 if (status != SCI_SUCCESS) {
Christoph Hellwig79855d12014-11-05 10:36:28 +0100175 if (test_bit(IDEV_GONE, &idev->flags)) {
176 /* Indicate that the device
177 * is gone.
178 */
179 isci_task_refuse(ihost, task,
180 SAS_TASK_UNDELIVERED,
181 SAS_DEVICE_UNKNOWN);
182 } else {
183 /* Indicate QUEUE_FULL so that
184 * the scsi midlayer retries.
185 * If the request failed for
186 * remote device reasons, it
187 * gets returned as
188 * SAS_TASK_UNDELIVERED next
189 * time through.
190 */
191 isci_task_refuse(ihost, task,
192 SAS_TASK_COMPLETE,
193 SAS_QUEUE_FULL);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700194 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700195 }
196 }
Dan Williams1077a572011-03-11 10:13:51 -0800197 }
Christoph Hellwig79855d12014-11-05 10:36:28 +0100198
199 if (status != SCI_SUCCESS && tag != SCI_CONTROLLER_INVALID_IO_TAG) {
200 spin_lock_irqsave(&ihost->scic_lock, flags);
201 /* command never hit the device, so just free
202 * the tci and skip the sequence increment
203 */
204 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
205 spin_unlock_irqrestore(&ihost->scic_lock, flags);
206 }
207
208 isci_put_device(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700209 return 0;
210}
211
Dan Williams0d0cf142011-06-13 00:51:30 -0700212static struct isci_request *isci_task_request_build(struct isci_host *ihost,
Dan Williams209fae12011-06-13 17:39:44 -0700213 struct isci_remote_device *idev,
Dan Williams312e0c22011-06-28 13:47:09 -0700214 u16 tag, struct isci_tmf *isci_tmf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700215{
Dan Williams6f231dd2011-07-02 22:56:22 -0700216 enum sci_status status = SCI_FAILURE;
Dan Williams0d0cf142011-06-13 00:51:30 -0700217 struct isci_request *ireq = NULL;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700218 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700219
Dan Williams0d0cf142011-06-13 00:51:30 -0700220 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700221 "%s: isci_tmf = %p\n", __func__, isci_tmf);
222
Dan Williams0d0cf142011-06-13 00:51:30 -0700223 dev = idev->domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700224
225 /* do common allocation and init of request object. */
Dan Williamsdb056252011-06-17 14:18:39 -0700226 ireq = isci_tmf_request_from_tag(ihost, isci_tmf, tag);
Dan Williams0d0cf142011-06-13 00:51:30 -0700227 if (!ireq)
228 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700229
230 /* let the core do it's construct. */
Dan Williams89a73012011-06-30 19:14:33 -0700231 status = sci_task_request_construct(ihost, idev, tag,
Dan Williams5076a1a2011-06-27 14:57:03 -0700232 ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700233
234 if (status != SCI_SUCCESS) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700235 dev_warn(&ihost->pdev->dev,
Dan Williams89a73012011-06-30 19:14:33 -0700236 "%s: sci_task_request_construct failed - "
Dan Williams6f231dd2011-07-02 22:56:22 -0700237 "status = 0x%x\n",
238 __func__,
239 status);
Dan Williamsdb056252011-06-17 14:18:39 -0700240 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700241 }
242
Dan Williamsa1a113b2011-04-21 18:44:45 -0700243 /* XXX convert to get this from task->tproto like other drivers */
James Bottomleyaa9f8322013-05-07 14:44:06 -0700244 if (dev->dev_type == SAS_END_DEVICE) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700245 isci_tmf->proto = SAS_PROTOCOL_SSP;
Dan Williams89a73012011-06-30 19:14:33 -0700246 status = sci_task_request_construct_ssp(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700247 if (status != SCI_SUCCESS)
Dan Williamsdb056252011-06-17 14:18:39 -0700248 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700249 }
250
Dan Williams0d0cf142011-06-13 00:51:30 -0700251 return ireq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700252}
253
Dan Williams16ba7702011-07-01 10:52:55 -0700254static int isci_task_execute_tmf(struct isci_host *ihost,
255 struct isci_remote_device *idev,
256 struct isci_tmf *tmf, unsigned long timeout_ms)
Dan Williams6f231dd2011-07-02 22:56:22 -0700257{
258 DECLARE_COMPLETION_ONSTACK(completion);
Nathan Chancellor362b5da2018-09-26 17:12:00 -0700259 enum sci_status status = SCI_FAILURE;
Dan Williams0d0cf142011-06-13 00:51:30 -0700260 struct isci_request *ireq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700261 int ret = TMF_RESP_FUNC_FAILED;
262 unsigned long flags;
Edmund Nadolskifd183882011-05-19 12:00:15 +0000263 unsigned long timeleft;
Dan Williams312e0c22011-06-28 13:47:09 -0700264 u16 tag;
265
266 spin_lock_irqsave(&ihost->scic_lock, flags);
267 tag = isci_alloc_tag(ihost);
268 spin_unlock_irqrestore(&ihost->scic_lock, flags);
269
270 if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
271 return ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700272
273 /* sanity check, return TMF_RESP_FUNC_FAILED
274 * if the device is not there and ready.
275 */
Dan Williams78a6f062011-06-30 16:31:37 -0700276 if (!idev ||
277 (!test_bit(IDEV_IO_READY, &idev->flags) &&
278 !test_bit(IDEV_IO_NCQERROR, &idev->flags))) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700279 dev_dbg(&ihost->pdev->dev,
Dan Williams78a6f062011-06-30 16:31:37 -0700280 "%s: idev = %p not ready (%#lx)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700281 __func__,
Dan Williams78a6f062011-06-30 16:31:37 -0700282 idev, idev ? idev->flags : 0);
Dan Williams312e0c22011-06-28 13:47:09 -0700283 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700284 } else
Dan Williams0d0cf142011-06-13 00:51:30 -0700285 dev_dbg(&ihost->pdev->dev,
Dan Williams78a6f062011-06-30 16:31:37 -0700286 "%s: idev = %p\n",
287 __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700288
289 /* Assign the pointer to the TMF's completion kernel wait structure. */
290 tmf->complete = &completion;
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700291 tmf->status = SCI_FAILURE_TIMEOUT;
Dan Williams6f231dd2011-07-02 22:56:22 -0700292
Dan Williams78a6f062011-06-30 16:31:37 -0700293 ireq = isci_task_request_build(ihost, idev, tag, tmf);
Dan Williams312e0c22011-06-28 13:47:09 -0700294 if (!ireq)
295 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700296
Dan Williams0d0cf142011-06-13 00:51:30 -0700297 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700298
299 /* start the TMF io. */
Dan Williams89a73012011-06-30 19:14:33 -0700300 status = sci_controller_start_task(ihost, idev, ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700301
Nathan Chancellor362b5da2018-09-26 17:12:00 -0700302 if (status != SCI_SUCCESS) {
Dan Williamsa8a0a132011-07-01 12:07:25 -0700303 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700304 "%s: start_io failed - status = 0x%x, request = %p\n",
305 __func__,
306 status,
Dan Williams0d0cf142011-06-13 00:51:30 -0700307 ireq);
308 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsdb056252011-06-17 14:18:39 -0700309 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700310 }
Dan Williams0d0cf142011-06-13 00:51:30 -0700311 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700312
Jeff Skirvin31a38ef2012-03-08 22:42:01 -0800313 /* The RNC must be unsuspended before the TMF can get a response. */
314 isci_remote_device_resume_from_abort(ihost, idev);
315
Dan Williams6f231dd2011-07-02 22:56:22 -0700316 /* Wait for the TMF to complete, or a timeout. */
Edmund Nadolskifd183882011-05-19 12:00:15 +0000317 timeleft = wait_for_completion_timeout(&completion,
Dan Williams086a0da2011-06-21 16:23:03 -0700318 msecs_to_jiffies(timeout_ms));
Edmund Nadolskifd183882011-05-19 12:00:15 +0000319
320 if (timeleft == 0) {
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700321 /* The TMF did not complete - this could be because
322 * of an unplug. Terminate the TMF request now.
323 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800324 isci_remote_device_suspend_terminate(ihost, idev, ireq);
Edmund Nadolskifd183882011-05-19 12:00:15 +0000325 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700326
Maciej Trela27234ab2012-01-04 01:33:05 -0800327 isci_print_tmf(ihost, tmf);
Dan Williams6f231dd2011-07-02 22:56:22 -0700328
329 if (tmf->status == SCI_SUCCESS)
330 ret = TMF_RESP_FUNC_COMPLETE;
331 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700332 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700333 "%s: tmf.status == "
334 "SCI_FAILURE_IO_RESPONSE_VALID\n",
335 __func__);
336 ret = TMF_RESP_FUNC_COMPLETE;
337 }
338 /* Else - leave the default "failed" status alone. */
339
Dan Williams0d0cf142011-06-13 00:51:30 -0700340 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700341 "%s: completed request = %p\n",
342 __func__,
Dan Williams0d0cf142011-06-13 00:51:30 -0700343 ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700344
Dan Williams6f231dd2011-07-02 22:56:22 -0700345 return ret;
Dan Williams312e0c22011-06-28 13:47:09 -0700346
Dan Williams312e0c22011-06-28 13:47:09 -0700347 err_tci:
348 spin_lock_irqsave(&ihost->scic_lock, flags);
349 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
350 spin_unlock_irqrestore(&ihost->scic_lock, flags);
351
352 return ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700353}
354
Dan Williams16ba7702011-07-01 10:52:55 -0700355static void isci_task_build_tmf(struct isci_tmf *tmf,
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800356 enum isci_tmf_function_codes code)
Dan Williams6f231dd2011-07-02 22:56:22 -0700357{
Dan Williams6f231dd2011-07-02 22:56:22 -0700358 memset(tmf, 0, sizeof(*tmf));
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800359 tmf->tmf_code = code;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800360}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800361
Dan Williams16ba7702011-07-01 10:52:55 -0700362static void isci_task_build_abort_task_tmf(struct isci_tmf *tmf,
363 enum isci_tmf_function_codes code,
Dan Williams16ba7702011-07-01 10:52:55 -0700364 struct isci_request *old_request)
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800365{
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800366 isci_task_build_tmf(tmf, code);
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800367 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700368}
369
Lee Jones0afdee02021-03-17 09:12:16 +0000370/*
Dan Williams6f231dd2011-07-02 22:56:22 -0700371 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
372 * Template functions.
373 * @lun: This parameter specifies the lun to be reset.
374 *
375 * status, zero indicates success.
376 */
377static int isci_task_send_lu_reset_sas(
378 struct isci_host *isci_host,
379 struct isci_remote_device *isci_device,
380 u8 *lun)
381{
382 struct isci_tmf tmf;
383 int ret = TMF_RESP_FUNC_FAILED;
384
385 dev_dbg(&isci_host->pdev->dev,
386 "%s: isci_host = %p, isci_device = %p\n",
387 __func__, isci_host, isci_device);
388 /* Send the LUN reset to the target. By the time the call returns,
389 * the TMF has fully exected in the target (in which case the return
390 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
391 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
392 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800393 isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset);
Dan Williams6f231dd2011-07-02 22:56:22 -0700394
395 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
Dan Williams209fae12011-06-13 17:39:44 -0700396 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
Dan Williams6f231dd2011-07-02 22:56:22 -0700397
398 if (ret == TMF_RESP_FUNC_COMPLETE)
399 dev_dbg(&isci_host->pdev->dev,
400 "%s: %p: TMF_LU_RESET passed\n",
401 __func__, isci_device);
402 else
403 dev_dbg(&isci_host->pdev->dev,
404 "%s: %p: TMF_LU_RESET failed (%x)\n",
405 __func__, isci_device, ret);
406
407 return ret;
408}
409
Dan Williams43a5ab152011-12-08 23:20:44 -0800410int isci_task_lu_reset(struct domain_device *dev, u8 *lun)
Dan Williams16ba7702011-07-01 10:52:55 -0700411{
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800412 struct isci_host *ihost = dev_to_ihost(dev);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800413 struct isci_remote_device *idev;
Dan Williams209fae12011-06-13 17:39:44 -0700414 unsigned long flags;
Jeff Skirvin397497d2012-03-10 05:46:46 +0000415 int ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700416
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800417 spin_lock_irqsave(&ihost->scic_lock, flags);
Jeff Skirvin63732502012-03-08 22:41:55 -0800418 idev = isci_get_device(dev->lldd_dev);
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800419 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700420
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800421 dev_dbg(&ihost->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -0700422 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800423 __func__, dev, ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700424
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800425 if (!idev) {
Jeff Skirvind80ecd52012-03-08 22:41:53 -0800426 /* If the device is gone, escalate to I_T_Nexus_Reset. */
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800427 dev_dbg(&ihost->pdev->dev, "%s: No dev\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -0700428
Jeff Skirvind80ecd52012-03-08 22:41:53 -0800429 ret = TMF_RESP_FUNC_FAILED;
Dan Williams209fae12011-06-13 17:39:44 -0700430 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -0700431 }
432
Jeff Skirvin08c031e2012-03-08 22:42:00 -0800433 /* Suspend the RNC, kill all TCs */
434 if (isci_remote_device_suspend_terminate(ihost, idev, NULL)
435 != SCI_SUCCESS) {
436 /* The suspend/terminate only fails if isci_get_device fails */
437 ret = TMF_RESP_FUNC_FAILED;
438 goto out;
439 }
440 /* All pending I/Os have been terminated and cleaned up. */
Jeff Skirvin397497d2012-03-10 05:46:46 +0000441 if (!test_bit(IDEV_GONE, &idev->flags)) {
442 if (dev_is_sata(dev))
443 sas_ata_schedule_reset(dev);
444 else
445 /* Send the task management part of the reset. */
446 ret = isci_task_send_lu_reset_sas(ihost, idev, lun);
Jeff Skirvin5b6bf222012-03-08 22:41:51 -0800447 }
Dan Williams209fae12011-06-13 17:39:44 -0700448 out:
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800449 isci_put_device(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700450 return ret;
451}
452
453
454/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
455int isci_task_clear_nexus_port(struct asd_sas_port *port)
456{
457 return TMF_RESP_FUNC_FAILED;
458}
459
460
461
462int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
463{
464 return TMF_RESP_FUNC_FAILED;
465}
466
Dan Williams6f231dd2011-07-02 22:56:22 -0700467/* Task Management Functions. Must be called from process context. */
468
469/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700470 * isci_task_abort_task() - This function is one of the SAS Domain Template
471 * functions. This function is called by libsas to abort a specified task.
472 * @task: This parameter specifies the SAS task to abort.
473 *
474 * status, zero indicates success.
475 */
476int isci_task_abort_task(struct sas_task *task)
477{
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800478 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700479 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800480 struct isci_request *old_request = NULL;
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800481 struct isci_remote_device *idev = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -0800482 struct isci_tmf tmf;
483 int ret = TMF_RESP_FUNC_FAILED;
484 unsigned long flags;
Jeff Skirvin96f15f22013-07-11 17:18:58 -0700485 int target_done_already = 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700486
487 /* Get the isci_request reference from the task. Note that
488 * this check does not depend on the pending request list
489 * in the device, because tasks driving resets may land here
490 * after completion in the core.
491 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800492 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams209fae12011-06-13 17:39:44 -0700493 spin_lock(&task->task_state_lock);
494
495 old_request = task->lldd_task;
496
497 /* If task is already done, the request isn't valid */
498 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
Jeff Skirvin96f15f22013-07-11 17:18:58 -0700499 old_request) {
Jeff Skirvin63732502012-03-08 22:41:55 -0800500 idev = isci_get_device(task->dev->lldd_dev);
Jeff Skirvin96f15f22013-07-11 17:18:58 -0700501 target_done_already = test_bit(IREQ_COMPLETE_IN_TARGET,
502 &old_request->flags);
503 }
Dan Williams209fae12011-06-13 17:39:44 -0700504 spin_unlock(&task->task_state_lock);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800505 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700506
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800507 dev_warn(&ihost->pdev->dev,
Jeff Skirvin397497d2012-03-10 05:46:46 +0000508 "%s: dev = %p (%s%s), task = %p, old_request == %p\n",
509 __func__, idev,
510 (dev_is_sata(task->dev) ? "STP/SATA"
John Garry924a3542019-06-10 20:41:41 +0800511 : ((dev_is_expander(task->dev->dev_type))
Jeff Skirvin397497d2012-03-10 05:46:46 +0000512 ? "SMP"
513 : "SSP")),
514 ((idev) ? ((test_bit(IDEV_GONE, &idev->flags))
515 ? " IDEV_GONE"
516 : "")
517 : " <NULL>"),
518 task, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700519
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700520 /* Device reset conditions signalled in task_state_flags are the
521 * responsbility of libsas to observe at the start of the error
522 * handler thread.
Dan Williams6f231dd2011-07-02 22:56:22 -0700523 */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800524 if (!idev || !old_request) {
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700525 /* The request has already completed and there
526 * is nothing to do here other than to set the task
527 * done bit, and indicate that the task abort function
Anatol Pomozov4907cb72012-09-01 10:31:09 -0700528 * was successful.
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700529 */
530 spin_lock_irqsave(&task->task_state_lock, flags);
531 task->task_state_flags |= SAS_TASK_STATE_DONE;
John Garry26fc0ea2022-02-10 18:43:24 +0800532 task->task_state_flags &= ~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) ||
Jeff Skirvin96f15f22013-07-11 17:18:58 -0700556 target_done_already ||
Jeff Skirvin397497d2012-03-10 05:46:46 +0000557 test_bit(IDEV_GONE, &idev->flags)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700558
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800559 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800560
Jeff Skirvin31a38ef2012-03-08 22:42:01 -0800561 /* No task to send, so explicitly resume the device here */
562 isci_remote_device_resume_from_abort(ihost, idev);
563
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800564 dev_warn(&ihost->pdev->dev,
565 "%s: %s request"
Jeff Skirvin397497d2012-03-10 05:46:46 +0000566 " or complete_in_target (%d), "
567 "or IDEV_GONE (%d), thus no TMF\n",
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800568 __func__,
569 ((task->task_proto == SAS_PROTOCOL_SMP)
570 ? "SMP"
571 : (sas_protocol_ata(task->task_proto)
572 ? "SATA/STP"
573 : "<other>")
574 ),
575 test_bit(IREQ_COMPLETE_IN_TARGET,
Jeff Skirvin397497d2012-03-10 05:46:46 +0000576 &old_request->flags),
577 test_bit(IDEV_GONE, &idev->flags));
Dan Williams6f231dd2011-07-02 22:56:22 -0700578
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800579 spin_lock_irqsave(&task->task_state_lock, flags);
John Garry26fc0ea2022-02-10 18:43:24 +0800580 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800581 task->task_state_flags |= SAS_TASK_STATE_DONE;
582 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700583
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800584 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700585 } else {
Geert Uytterhoeven4e210512014-10-22 11:49:02 +0200586 /* Fill in the tmf structure */
Dan Williams209fae12011-06-13 17:39:44 -0700587 isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort,
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800588 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700589
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800590 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700591
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800592 /* Send the task management request. */
Jeff Skirvin98145cb2011-10-27 15:05:16 -0700593 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800594 ret = isci_task_execute_tmf(ihost, idev, &tmf,
Dan Williams6f231dd2011-07-02 22:56:22 -0700595 ISCI_ABORT_TASK_TIMEOUT_MS);
Dan Williams6f231dd2011-07-02 22:56:22 -0700596 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800597out:
Jeff Skirvin63732502012-03-08 22:41:55 -0800598 dev_warn(&ihost->pdev->dev,
599 "%s: Done; dev = %p, task = %p , old_request == %p\n",
600 __func__, idev, task, old_request);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800601 isci_put_device(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700602 return ret;
603}
604
605/**
606 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
607 * functions. This is one of the Task Management functoins called by libsas,
608 * to abort all task for the given lun.
609 * @d_device: This parameter specifies the domain device associated with this
610 * request.
611 * @lun: This parameter specifies the lun associated with this request.
612 *
613 * status, zero indicates success.
614 */
615int isci_task_abort_task_set(
616 struct domain_device *d_device,
617 u8 *lun)
618{
619 return TMF_RESP_FUNC_FAILED;
620}
621
622
623/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700624 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
625 * functions. This is one of the Task Management functoins called by libsas.
626 * @d_device: This parameter specifies the domain device associated with this
627 * request.
628 * @lun: This parameter specifies the lun associated with this request.
629 *
630 * status, zero indicates success.
631 */
632int isci_task_clear_task_set(
633 struct domain_device *d_device,
634 u8 *lun)
635{
636 return TMF_RESP_FUNC_FAILED;
637}
638
639
640/**
641 * isci_task_query_task() - This function is implemented to cause libsas to
642 * correctly escalate the failed abort to a LUN or target reset (this is
643 * because sas_scsi_find_task libsas function does not correctly interpret
644 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
645 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
646 * returned, libsas will turn this into a target reset
647 * @task: This parameter specifies the sas task being queried.
Dan Williams6f231dd2011-07-02 22:56:22 -0700648 *
649 * status, zero indicates success.
650 */
651int isci_task_query_task(
652 struct sas_task *task)
653{
654 /* See if there is a pending device reset for this device. */
655 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
656 return TMF_RESP_FUNC_FAILED;
657 else
658 return TMF_RESP_FUNC_SUCC;
659}
660
Dave Jiangaf5ae892011-05-04 17:53:24 -0700661/*
Dan Williams6f231dd2011-07-02 22:56:22 -0700662 * isci_task_request_complete() - This function is called by the sci core when
663 * an task request completes.
Dave Jiangaf5ae892011-05-04 17:53:24 -0700664 * @ihost: This parameter specifies the ISCI host object
665 * @ireq: This parameter is the completed isci_request object.
Dan Williams6f231dd2011-07-02 22:56:22 -0700666 * @completion_status: This parameter specifies the completion status from the
667 * sci core.
668 *
669 * none.
670 */
Dave Jiangaf5ae892011-05-04 17:53:24 -0700671void
672isci_task_request_complete(struct isci_host *ihost,
673 struct isci_request *ireq,
674 enum sci_task_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700675{
Dave Jiangaf5ae892011-05-04 17:53:24 -0700676 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700677 struct completion *tmf_complete = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700678
Dave Jiangaf5ae892011-05-04 17:53:24 -0700679 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700680 "%s: request = %p, status=%d\n",
Dave Jiangaf5ae892011-05-04 17:53:24 -0700681 __func__, ireq, completion_status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700682
Dan Williams38d88792011-06-23 14:33:48 -0700683 set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700684
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700685 if (tmf) {
686 tmf->status = completion_status;
687
688 if (tmf->proto == SAS_PROTOCOL_SSP) {
Kees Cook5250db62021-05-28 11:13:37 -0700689 memcpy(tmf->resp.rsp_buf,
690 ireq->ssp.rsp_buf,
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700691 SSP_RESP_IU_MAX_SIZE);
692 } else if (tmf->proto == SAS_PROTOCOL_SATA) {
693 memcpy(&tmf->resp.d2h_fis,
694 &ireq->stp.rsp,
695 sizeof(struct dev_to_host_fis));
696 }
697 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
698 tmf_complete = tmf->complete;
Dan Williams6f231dd2011-07-02 22:56:22 -0700699 }
Dan Williams89a73012011-06-30 19:14:33 -0700700 sci_controller_complete_io(ihost, ireq->target_device, ireq);
Dan Williams67ea8382011-05-08 11:47:15 -0700701 /* set the 'terminated' flag handle to make sure it cannot be terminated
Dan Williams6f231dd2011-07-02 22:56:22 -0700702 * or completed again.
703 */
Dan Williams38d88792011-06-23 14:33:48 -0700704 set_bit(IREQ_TERMINATED, &ireq->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700705
Jeff Skirvin1db79b32012-03-08 22:42:05 -0800706 if (test_and_clear_bit(IREQ_ABORT_PATH_ACTIVE, &ireq->flags))
707 wake_up_all(&ihost->eventq);
708
Jeff Skirvin621120c2012-03-08 22:42:03 -0800709 if (!test_bit(IREQ_NO_AUTO_FREE_TAG, &ireq->flags))
710 isci_free_tag(ihost, ireq->io_tag);
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700711
Dan Williams6f231dd2011-07-02 22:56:22 -0700712 /* The task management part completes last. */
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700713 if (tmf_complete)
714 complete(tmf_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -0700715}
716
Dan Williams209fae12011-06-13 17:39:44 -0700717static int isci_reset_device(struct isci_host *ihost,
Dan Williams92776992011-11-30 11:57:34 -0800718 struct domain_device *dev,
Jeff Skirvinbc6f3872011-07-01 13:03:44 -0700719 struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -0700720{
Jeff Skirvin397497d2012-03-10 05:46:46 +0000721 int rc = TMF_RESP_FUNC_COMPLETE, reset_stat = -1;
Dan Williams92776992011-11-30 11:57:34 -0800722 struct sas_phy *phy = sas_get_local_phy(dev);
723 struct isci_port *iport = dev->port->lldd_port;
Dan Williams6f231dd2011-07-02 22:56:22 -0700724
Dan Williamsd06b4872011-05-02 13:59:25 -0700725 dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700726
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800727 /* Suspend the RNC, terminate all outstanding TCs. */
728 if (isci_remote_device_suspend_terminate(ihost, idev, NULL)
729 != SCI_SUCCESS) {
Dan Williamsf41a0c42011-12-21 21:33:17 -0800730 rc = TMF_RESP_FUNC_FAILED;
731 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -0700732 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800733 /* Note that since the termination for outstanding requests succeeded,
734 * this function will return success. This is because the resets will
735 * only fail if the device has been removed (ie. hotplug), and the
736 * primary duty of this function is to cleanup tasks, so that is the
737 * relevant status.
738 */
Jeff Skirvin397497d2012-03-10 05:46:46 +0000739 if (!test_bit(IDEV_GONE, &idev->flags)) {
740 if (scsi_is_sas_phy_local(phy)) {
741 struct isci_phy *iphy = &ihost->phys[phy->number];
Dan Williams6f231dd2011-07-02 22:56:22 -0700742
Jeff Skirvin397497d2012-03-10 05:46:46 +0000743 reset_stat = isci_port_perform_hard_reset(ihost, iport,
744 iphy);
745 } else
746 reset_stat = sas_phy_reset(phy, !dev_is_sata(dev));
747 }
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800748 /* Explicitly resume the RNC here, since there was no task sent. */
Jeff Skirvin31a38ef2012-03-08 22:42:01 -0800749 isci_remote_device_resume_from_abort(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700750
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800751 dev_dbg(&ihost->pdev->dev, "%s: idev %p complete, reset_stat=%d.\n",
752 __func__, idev, reset_stat);
Dan Williamsf41a0c42011-12-21 21:33:17 -0800753 out:
754 sas_put_local_phy(phy);
Dan Williamsd06b4872011-05-02 13:59:25 -0700755 return rc;
756}
757
758int isci_task_I_T_nexus_reset(struct domain_device *dev)
759{
760 struct isci_host *ihost = dev_to_ihost(dev);
Dan Williamsd06b4872011-05-02 13:59:25 -0700761 struct isci_remote_device *idev;
762 unsigned long flags;
Jeff Skirvinbc6f3872011-07-01 13:03:44 -0700763 int ret;
Dan Williamsd06b4872011-05-02 13:59:25 -0700764
Dan Williamsd06b4872011-05-02 13:59:25 -0700765 spin_lock_irqsave(&ihost->scic_lock, flags);
Jeff Skirvin14aaa9f2012-03-08 22:41:54 -0800766 idev = isci_get_device(dev->lldd_dev);
Dan Williamsd06b4872011-05-02 13:59:25 -0700767 spin_unlock_irqrestore(&ihost->scic_lock, flags);
768
Dan Williams5a998322011-12-12 20:32:09 -0800769 if (!idev) {
770 /* XXX: need to cleanup any ireqs targeting this
771 * domain_device
772 */
Dan Williamsddfadd72014-02-06 12:23:01 -0800773 ret = -ENODEV;
Dan Williams209fae12011-06-13 17:39:44 -0700774 goto out;
775 }
Dan Williamsd06b4872011-05-02 13:59:25 -0700776
Dan Williams92776992011-11-30 11:57:34 -0800777 ret = isci_reset_device(ihost, dev, idev);
Dan Williams209fae12011-06-13 17:39:44 -0700778 out:
779 isci_put_device(idev);
780 return ret;
Dan Williamsd06b4872011-05-02 13:59:25 -0700781}