blob: 4175f173868ecaaf45a7ac433da5837bf35d991b [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{
81 enum isci_completion_selection disposition;
82
83 disposition = isci_perform_normal_io_completion;
84 disposition = isci_task_set_completion_status(task, response, status,
85 disposition);
Dan Williams50e7f9b2011-03-09 21:27:46 -080086
87 /* Tasks aborted specifically by a call to the lldd_abort_task
Dan Williams1077a572011-03-11 10:13:51 -080088 * function should not be completed to the host in the regular path.
89 */
90 switch (disposition) {
James Bottomleya5ec7f862011-07-03 14:14:45 -050091 case isci_perform_normal_io_completion:
92 /* Normal notification (task_done) */
93 dev_dbg(&ihost->pdev->dev,
94 "%s: Normal - task = %p, response=%d, "
95 "status=%d\n",
96 __func__, task, response, status);
Dan Williams50e7f9b2011-03-09 21:27:46 -080097
James Bottomleya5ec7f862011-07-03 14:14:45 -050098 task->lldd_task = NULL;
Dan Williams50e7f9b2011-03-09 21:27:46 -080099
James Bottomleya5ec7f862011-07-03 14:14:45 -0500100 isci_execpath_callback(ihost, task, task->task_done);
101 break;
Dan Williams50e7f9b2011-03-09 21:27:46 -0800102
James Bottomleya5ec7f862011-07-03 14:14:45 -0500103 case isci_perform_aborted_io_completion:
104 /*
105 * No notification because this request is already in the
106 * abort path.
107 */
108 dev_dbg(&ihost->pdev->dev,
109 "%s: Aborted - task = %p, response=%d, "
110 "status=%d\n",
111 __func__, task, response, status);
112 break;
Dan Williams50e7f9b2011-03-09 21:27:46 -0800113
James Bottomleya5ec7f862011-07-03 14:14:45 -0500114 case isci_perform_error_io_completion:
115 /* Use sas_task_abort */
116 dev_dbg(&ihost->pdev->dev,
117 "%s: Error - task = %p, response=%d, "
118 "status=%d\n",
119 __func__, task, response, status);
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700120
James Bottomleya5ec7f862011-07-03 14:14:45 -0500121 isci_execpath_callback(ihost, task, sas_task_abort);
122 break;
Dan Williams50e7f9b2011-03-09 21:27:46 -0800123
James Bottomleya5ec7f862011-07-03 14:14:45 -0500124 default:
125 dev_dbg(&ihost->pdev->dev,
126 "%s: isci task notification default case!",
127 __func__);
128 sas_task_abort(task);
129 break;
Dan Williams50e7f9b2011-03-09 21:27:46 -0800130 }
131}
Dan Williams6f231dd2011-07-02 22:56:22 -0700132
Dan Williams1077a572011-03-11 10:13:51 -0800133#define for_each_sas_task(num, task) \
134 for (; num > 0; num--,\
135 task = list_entry(task->list.next, struct sas_task, list))
136
Jeff Skirvin9274f452011-06-23 17:09:02 -0700137
138static inline int isci_device_io_ready(struct isci_remote_device *idev,
139 struct sas_task *task)
140{
141 return idev ? test_bit(IDEV_IO_READY, &idev->flags) ||
142 (test_bit(IDEV_IO_NCQERROR, &idev->flags) &&
143 isci_task_is_ncq_recovery(task))
144 : 0;
145}
Dan Williams6f231dd2011-07-02 22:56:22 -0700146/**
147 * isci_task_execute_task() - This function is one of the SAS Domain Template
148 * functions. This function is called by libsas to send a task down to
149 * hardware.
150 * @task: This parameter specifies the SAS task to send.
151 * @num: This parameter specifies the number of tasks to queue.
152 * @gfp_flags: This parameter specifies the context of this call.
153 *
154 * status, zero indicates success.
155 */
156int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags)
157{
Dan Williams4393aa42011-03-31 13:10:44 -0700158 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams209fae12011-06-13 17:39:44 -0700159 struct isci_remote_device *idev;
Dan Williamsf2088262011-06-16 11:26:12 -0700160 unsigned long flags;
161 bool io_ready;
Dan Williams312e0c22011-06-28 13:47:09 -0700162 u16 tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700163
Dan Williams1077a572011-03-11 10:13:51 -0800164 dev_dbg(&ihost->pdev->dev, "%s: num=%d\n", __func__, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700165
Dan Williams1077a572011-03-11 10:13:51 -0800166 for_each_sas_task(num, task) {
Dan Williams312e0c22011-06-28 13:47:09 -0700167 enum sci_status status = SCI_FAILURE;
168
Dan Williams209fae12011-06-13 17:39:44 -0700169 spin_lock_irqsave(&ihost->scic_lock, flags);
170 idev = isci_lookup_device(task->dev);
Jeff Skirvin9274f452011-06-23 17:09:02 -0700171 io_ready = isci_device_io_ready(idev, task);
Dan Williams312e0c22011-06-28 13:47:09 -0700172 tag = isci_alloc_tag(ihost);
Dan Williams209fae12011-06-13 17:39:44 -0700173 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700174
Dan Williamsf2088262011-06-16 11:26:12 -0700175 dev_dbg(&ihost->pdev->dev,
176 "task: %p, num: %d dev: %p idev: %p:%#lx cmd = %p\n",
177 task, num, task->dev, idev, idev ? idev->flags : 0,
178 task->uldd_task);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700179
Dan Williamsf2088262011-06-16 11:26:12 -0700180 if (!idev) {
181 isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED,
182 SAS_DEVICE_UNKNOWN);
Dan Williams312e0c22011-06-28 13:47:09 -0700183 } else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) {
Dan Williamsf2088262011-06-16 11:26:12 -0700184 /* Indicate QUEUE_FULL so that the scsi midlayer
185 * retries.
186 */
187 isci_task_refuse(ihost, task, SAS_TASK_COMPLETE,
188 SAS_QUEUE_FULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700189 } else {
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700190 /* There is a device and it's ready for I/O. */
191 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700192
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700193 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
Dan Williamsf2088262011-06-16 11:26:12 -0700194 /* The I/O was aborted. */
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700195 spin_unlock_irqrestore(&task->task_state_lock,
196 flags);
197
Dan Williams1077a572011-03-11 10:13:51 -0800198 isci_task_refuse(ihost, task,
199 SAS_TASK_UNDELIVERED,
200 SAM_STAT_TASK_ABORTED);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700201 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700202 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
203 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700204
205 /* build and send the request. */
Dan Williamsdb056252011-06-17 14:18:39 -0700206 status = isci_request_execute(ihost, idev, task, tag);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700207
208 if (status != SCI_SUCCESS) {
209
210 spin_lock_irqsave(&task->task_state_lock, flags);
211 /* Did not really start this command. */
212 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
213 spin_unlock_irqrestore(&task->task_state_lock, flags);
214
Jeff Skirvinc2cb8a52011-10-27 15:04:56 -0700215 if (test_bit(IDEV_GONE, &idev->flags)) {
216
217 /* Indicate that the device
218 * is gone.
219 */
220 isci_task_refuse(ihost, task,
221 SAS_TASK_UNDELIVERED,
222 SAS_DEVICE_UNKNOWN);
223 } else {
224 /* Indicate QUEUE_FULL so that
225 * the scsi midlayer retries.
226 * If the request failed for
227 * remote device reasons, it
228 * gets returned as
229 * SAS_TASK_UNDELIVERED next
230 * time through.
231 */
232 isci_task_refuse(ihost, task,
233 SAS_TASK_COMPLETE,
234 SAS_QUEUE_FULL);
235 }
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700236 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700237 }
238 }
Dan Williams312e0c22011-06-28 13:47:09 -0700239 if (status != SCI_SUCCESS && tag != SCI_CONTROLLER_INVALID_IO_TAG) {
240 spin_lock_irqsave(&ihost->scic_lock, flags);
241 /* command never hit the device, so just free
242 * the tci and skip the sequence increment
243 */
244 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
245 spin_unlock_irqrestore(&ihost->scic_lock, flags);
246 }
Dan Williams209fae12011-06-13 17:39:44 -0700247 isci_put_device(idev);
Dan Williams1077a572011-03-11 10:13:51 -0800248 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700249 return 0;
250}
251
Dan Williams16ba7702011-07-01 10:52:55 -0700252static enum sci_status isci_sata_management_task_request_build(struct isci_request *ireq)
253{
254 struct isci_tmf *isci_tmf;
255 enum sci_status status;
256
257 if (tmf_task != ireq->ttype)
258 return SCI_FAILURE;
259
260 isci_tmf = isci_request_access_tmf(ireq);
261
262 switch (isci_tmf->tmf_code) {
263
264 case isci_tmf_sata_srst_high:
265 case isci_tmf_sata_srst_low: {
266 struct host_to_dev_fis *fis = &ireq->stp.cmd;
267
268 memset(fis, 0, sizeof(*fis));
269
270 fis->fis_type = 0x27;
271 fis->flags &= ~0x80;
272 fis->flags &= 0xF0;
273 if (isci_tmf->tmf_code == isci_tmf_sata_srst_high)
274 fis->control |= ATA_SRST;
275 else
276 fis->control &= ~ATA_SRST;
277 break;
278 }
279 /* other management commnd go here... */
280 default:
281 return SCI_FAILURE;
282 }
283
284 /* core builds the protocol specific request
285 * based on the h2d fis.
286 */
287 status = sci_task_request_construct_sata(ireq);
288
289 return status;
290}
291
Dan Williams0d0cf142011-06-13 00:51:30 -0700292static struct isci_request *isci_task_request_build(struct isci_host *ihost,
Dan Williams209fae12011-06-13 17:39:44 -0700293 struct isci_remote_device *idev,
Dan Williams312e0c22011-06-28 13:47:09 -0700294 u16 tag, struct isci_tmf *isci_tmf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700295{
Dan Williams6f231dd2011-07-02 22:56:22 -0700296 enum sci_status status = SCI_FAILURE;
Dan Williams0d0cf142011-06-13 00:51:30 -0700297 struct isci_request *ireq = NULL;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700298 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700299
Dan Williams0d0cf142011-06-13 00:51:30 -0700300 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700301 "%s: isci_tmf = %p\n", __func__, isci_tmf);
302
Dan Williams0d0cf142011-06-13 00:51:30 -0700303 dev = idev->domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700304
305 /* do common allocation and init of request object. */
Dan Williamsdb056252011-06-17 14:18:39 -0700306 ireq = isci_tmf_request_from_tag(ihost, isci_tmf, tag);
Dan Williams0d0cf142011-06-13 00:51:30 -0700307 if (!ireq)
308 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700309
310 /* let the core do it's construct. */
Dan Williams89a73012011-06-30 19:14:33 -0700311 status = sci_task_request_construct(ihost, idev, tag,
Dan Williams5076a1a2011-06-27 14:57:03 -0700312 ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700313
314 if (status != SCI_SUCCESS) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700315 dev_warn(&ihost->pdev->dev,
Dan Williams89a73012011-06-30 19:14:33 -0700316 "%s: sci_task_request_construct failed - "
Dan Williams6f231dd2011-07-02 22:56:22 -0700317 "status = 0x%x\n",
318 __func__,
319 status);
Dan Williamsdb056252011-06-17 14:18:39 -0700320 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700321 }
322
Dan Williamsa1a113b2011-04-21 18:44:45 -0700323 /* XXX convert to get this from task->tproto like other drivers */
324 if (dev->dev_type == SAS_END_DEV) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700325 isci_tmf->proto = SAS_PROTOCOL_SSP;
Dan Williams89a73012011-06-30 19:14:33 -0700326 status = sci_task_request_construct_ssp(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700327 if (status != SCI_SUCCESS)
Dan Williamsdb056252011-06-17 14:18:39 -0700328 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700329 }
330
Dan Williamsa1a113b2011-04-21 18:44:45 -0700331 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700332 isci_tmf->proto = SAS_PROTOCOL_SATA;
Dan Williams0d0cf142011-06-13 00:51:30 -0700333 status = isci_sata_management_task_request_build(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700334
335 if (status != SCI_SUCCESS)
Dan Williamsdb056252011-06-17 14:18:39 -0700336 return NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700337 }
Dan Williams0d0cf142011-06-13 00:51:30 -0700338 return ireq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700339}
340
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700341/**
342* isci_request_mark_zombie() - This function must be called with scic_lock held.
343*/
344static void isci_request_mark_zombie(struct isci_host *ihost, struct isci_request *ireq)
345{
346 struct completion *tmf_completion = NULL;
347 struct completion *req_completion;
348
349 /* Set the request state to "dead". */
350 ireq->status = dead;
351
352 req_completion = ireq->io_request_completion;
353 ireq->io_request_completion = NULL;
354
355 if (ireq->ttype == io_task) {
356
357 /* Break links with the sas_task - the callback is done
358 * elsewhere.
359 */
360 struct sas_task *task = isci_request_access_task(ireq);
361
362 if (task)
363 task->lldd_task = NULL;
364
365 ireq->ttype_ptr.io_task_ptr = NULL;
366 } else {
367 /* Break links with the TMF request. */
368 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
369
370 /* In the case where a task request is dying,
371 * the thread waiting on the complete will sit and
372 * timeout unless we wake it now. Since the TMF
373 * has a default error status, complete it here
374 * to wake the waiting thread.
375 */
376 if (tmf) {
377 tmf_completion = tmf->complete;
378 tmf->complete = NULL;
379 }
380 ireq->ttype_ptr.tmf_task_ptr = NULL;
381 dev_dbg(&ihost->pdev->dev, "%s: tmf_code %d, managed tag %#x\n",
382 __func__, tmf->tmf_code, tmf->io_tag);
383 }
384
385 dev_warn(&ihost->pdev->dev, "task context unrecoverable (tag: %#x)\n",
386 ireq->io_tag);
387
388 /* Don't force waiting threads to timeout. */
389 if (req_completion)
390 complete(req_completion);
391
392 if (tmf_completion != NULL)
393 complete(tmf_completion);
394}
395
Dan Williams16ba7702011-07-01 10:52:55 -0700396static int isci_task_execute_tmf(struct isci_host *ihost,
397 struct isci_remote_device *idev,
398 struct isci_tmf *tmf, unsigned long timeout_ms)
Dan Williams6f231dd2011-07-02 22:56:22 -0700399{
400 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700401 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams0d0cf142011-06-13 00:51:30 -0700402 struct isci_request *ireq;
Dan Williams6f231dd2011-07-02 22:56:22 -0700403 int ret = TMF_RESP_FUNC_FAILED;
404 unsigned long flags;
Edmund Nadolskifd183882011-05-19 12:00:15 +0000405 unsigned long timeleft;
Dan Williams312e0c22011-06-28 13:47:09 -0700406 u16 tag;
407
408 spin_lock_irqsave(&ihost->scic_lock, flags);
409 tag = isci_alloc_tag(ihost);
410 spin_unlock_irqrestore(&ihost->scic_lock, flags);
411
412 if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
413 return ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700414
415 /* sanity check, return TMF_RESP_FUNC_FAILED
416 * if the device is not there and ready.
417 */
Dan Williams78a6f062011-06-30 16:31:37 -0700418 if (!idev ||
419 (!test_bit(IDEV_IO_READY, &idev->flags) &&
420 !test_bit(IDEV_IO_NCQERROR, &idev->flags))) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700421 dev_dbg(&ihost->pdev->dev,
Dan Williams78a6f062011-06-30 16:31:37 -0700422 "%s: idev = %p not ready (%#lx)\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700423 __func__,
Dan Williams78a6f062011-06-30 16:31:37 -0700424 idev, idev ? idev->flags : 0);
Dan Williams312e0c22011-06-28 13:47:09 -0700425 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700426 } else
Dan Williams0d0cf142011-06-13 00:51:30 -0700427 dev_dbg(&ihost->pdev->dev,
Dan Williams78a6f062011-06-30 16:31:37 -0700428 "%s: idev = %p\n",
429 __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700430
431 /* Assign the pointer to the TMF's completion kernel wait structure. */
432 tmf->complete = &completion;
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700433 tmf->status = SCI_FAILURE_TIMEOUT;
Dan Williams6f231dd2011-07-02 22:56:22 -0700434
Dan Williams78a6f062011-06-30 16:31:37 -0700435 ireq = isci_task_request_build(ihost, idev, tag, tmf);
Dan Williams312e0c22011-06-28 13:47:09 -0700436 if (!ireq)
437 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700438
Dan Williams0d0cf142011-06-13 00:51:30 -0700439 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700440
441 /* start the TMF io. */
Dan Williams89a73012011-06-30 19:14:33 -0700442 status = sci_controller_start_task(ihost, idev, ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700443
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700444 if (status != SCI_TASK_SUCCESS) {
Dan Williamsa8a0a132011-07-01 12:07:25 -0700445 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700446 "%s: start_io failed - status = 0x%x, request = %p\n",
447 __func__,
448 status,
Dan Williams0d0cf142011-06-13 00:51:30 -0700449 ireq);
450 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williamsdb056252011-06-17 14:18:39 -0700451 goto err_tci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700452 }
453
Dan Williams6f231dd2011-07-02 22:56:22 -0700454 if (tmf->cb_state_func != NULL)
455 tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data);
456
Dan Williams0d0cf142011-06-13 00:51:30 -0700457 isci_request_change_state(ireq, started);
Dan Williams6f231dd2011-07-02 22:56:22 -0700458
459 /* add the request to the remote device request list. */
Dan Williams78a6f062011-06-30 16:31:37 -0700460 list_add(&ireq->dev_node, &idev->reqs_in_process);
Dan Williams6f231dd2011-07-02 22:56:22 -0700461
Dan Williams0d0cf142011-06-13 00:51:30 -0700462 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700463
464 /* Wait for the TMF to complete, or a timeout. */
Edmund Nadolskifd183882011-05-19 12:00:15 +0000465 timeleft = wait_for_completion_timeout(&completion,
Dan Williams086a0da2011-06-21 16:23:03 -0700466 msecs_to_jiffies(timeout_ms));
Edmund Nadolskifd183882011-05-19 12:00:15 +0000467
468 if (timeleft == 0) {
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700469 /* The TMF did not complete - this could be because
470 * of an unplug. Terminate the TMF request now.
471 */
Dan Williams0d0cf142011-06-13 00:51:30 -0700472 spin_lock_irqsave(&ihost->scic_lock, flags);
Edmund Nadolskifd183882011-05-19 12:00:15 +0000473
474 if (tmf->cb_state_func != NULL)
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700475 tmf->cb_state_func(isci_tmf_timed_out, tmf,
476 tmf->cb_data);
Edmund Nadolskifd183882011-05-19 12:00:15 +0000477
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700478 sci_controller_terminate_request(ihost, idev, ireq);
Edmund Nadolskifd183882011-05-19 12:00:15 +0000479
Dan Williams0d0cf142011-06-13 00:51:30 -0700480 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams086a0da2011-06-21 16:23:03 -0700481
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700482 timeleft = wait_for_completion_timeout(
483 &completion,
484 msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC));
485
486 if (!timeleft) {
487 /* Strange condition - the termination of the TMF
488 * request timed-out.
489 */
490 spin_lock_irqsave(&ihost->scic_lock, flags);
491
492 /* If the TMF status has not changed, kill it. */
493 if (tmf->status == SCI_FAILURE_TIMEOUT)
494 isci_request_mark_zombie(ihost, ireq);
495
496 spin_unlock_irqrestore(&ihost->scic_lock, flags);
497 }
Edmund Nadolskifd183882011-05-19 12:00:15 +0000498 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700499
500 isci_print_tmf(tmf);
501
502 if (tmf->status == SCI_SUCCESS)
503 ret = TMF_RESP_FUNC_COMPLETE;
504 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
Dan Williams0d0cf142011-06-13 00:51:30 -0700505 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700506 "%s: tmf.status == "
507 "SCI_FAILURE_IO_RESPONSE_VALID\n",
508 __func__);
509 ret = TMF_RESP_FUNC_COMPLETE;
510 }
511 /* Else - leave the default "failed" status alone. */
512
Dan Williams0d0cf142011-06-13 00:51:30 -0700513 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700514 "%s: completed request = %p\n",
515 __func__,
Dan Williams0d0cf142011-06-13 00:51:30 -0700516 ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700517
Dan Williams6f231dd2011-07-02 22:56:22 -0700518 return ret;
Dan Williams312e0c22011-06-28 13:47:09 -0700519
Dan Williams312e0c22011-06-28 13:47:09 -0700520 err_tci:
521 spin_lock_irqsave(&ihost->scic_lock, flags);
522 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
523 spin_unlock_irqrestore(&ihost->scic_lock, flags);
524
525 return ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700526}
527
Dan Williams16ba7702011-07-01 10:52:55 -0700528static void isci_task_build_tmf(struct isci_tmf *tmf,
529 enum isci_tmf_function_codes code,
530 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
531 struct isci_tmf *,
532 void *),
533 void *cb_data)
Dan Williams6f231dd2011-07-02 22:56:22 -0700534{
Dan Williams6f231dd2011-07-02 22:56:22 -0700535 memset(tmf, 0, sizeof(*tmf));
536
Dan Williams6f231dd2011-07-02 22:56:22 -0700537 tmf->tmf_code = code;
Dan Williams6f231dd2011-07-02 22:56:22 -0700538 tmf->cb_state_func = tmf_sent_cb;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800539 tmf->cb_data = cb_data;
540}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800541
Dan Williams16ba7702011-07-01 10:52:55 -0700542static void isci_task_build_abort_task_tmf(struct isci_tmf *tmf,
543 enum isci_tmf_function_codes code,
544 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
545 struct isci_tmf *,
546 void *),
547 struct isci_request *old_request)
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800548{
Dan Williams16ba7702011-07-01 10:52:55 -0700549 isci_task_build_tmf(tmf, code, tmf_sent_cb, old_request);
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800550 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700551}
552
Dan Williams6f231dd2011-07-02 22:56:22 -0700553/**
554 * isci_task_validate_request_to_abort() - This function checks the given I/O
555 * against the "started" state. If the request is still "started", it's
556 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
557 * BEFORE CALLING THIS FUNCTION.
558 * @isci_request: This parameter specifies the request object to control.
559 * @isci_host: This parameter specifies the ISCI host object
560 * @isci_device: This is the device to which the request is pending.
561 * @aborted_io_completion: This is a completion structure that will be added to
562 * the request in case it is changed to aborting; this completion is
563 * triggered when the request is fully completed.
564 *
565 * Either "started" on successful change of the task status to "aborted", or
566 * "unallocated" if the task cannot be controlled.
567 */
568static enum isci_request_status isci_task_validate_request_to_abort(
569 struct isci_request *isci_request,
570 struct isci_host *isci_host,
571 struct isci_remote_device *isci_device,
572 struct completion *aborted_io_completion)
573{
574 enum isci_request_status old_state = unallocated;
575
576 /* Only abort the task if it's in the
577 * device's request_in_process list
578 */
579 if (isci_request && !list_empty(&isci_request->dev_node)) {
580 old_state = isci_request_change_started_to_aborted(
581 isci_request, aborted_io_completion);
582
Dan Williams6f231dd2011-07-02 22:56:22 -0700583 }
584
585 return old_state;
586}
587
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700588/**
589* isci_request_cleanup_completed_loiterer() - This function will take care of
590* the final cleanup on any request which has been explicitly terminated.
591* @isci_host: This parameter specifies the ISCI host object
592* @isci_device: This is the device to which the request is pending.
593* @isci_request: This parameter specifies the terminated request object.
594* @task: This parameter is the libsas I/O request.
595*/
Dan Williams6f231dd2011-07-02 22:56:22 -0700596static void isci_request_cleanup_completed_loiterer(
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700597 struct isci_host *isci_host,
Dan Williams6f231dd2011-07-02 22:56:22 -0700598 struct isci_remote_device *isci_device,
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700599 struct isci_request *isci_request,
600 struct sas_task *task)
Dan Williams6f231dd2011-07-02 22:56:22 -0700601{
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700602 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700603
604 dev_dbg(&isci_host->pdev->dev,
605 "%s: isci_device=%p, request=%p, task=%p\n",
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800606 __func__, isci_device, isci_request, task);
Dan Williams6f231dd2011-07-02 22:56:22 -0700607
Jeff Skirvina5fde222011-03-04 14:06:42 -0800608 if (task != NULL) {
609
610 spin_lock_irqsave(&task->task_state_lock, flags);
611 task->lldd_task = NULL;
612
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700613 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
614
Jeff Skirvina5fde222011-03-04 14:06:42 -0800615 isci_set_task_doneflags(task);
616
617 /* If this task is not in the abort path, call task_done. */
618 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
619
620 spin_unlock_irqrestore(&task->task_state_lock, flags);
621 task->task_done(task);
622 } else
623 spin_unlock_irqrestore(&task->task_state_lock, flags);
624 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800625
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700626 if (isci_request != NULL) {
627 spin_lock_irqsave(&isci_host->scic_lock, flags);
Jeff Skirvind6891682011-10-27 15:05:01 -0700628 isci_free_tag(isci_host, isci_request->io_tag);
629 isci_request_change_state(isci_request, unallocated);
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700630 list_del_init(&isci_request->dev_node);
631 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800632 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800633}
634
Jeff Skirvind6891682011-10-27 15:05:01 -0700635static int isci_request_is_dealloc_managed(enum isci_request_status stat)
636{
637 switch (stat) {
638 case aborted:
639 case aborting:
640 case terminating:
641 case completed:
642 case dead:
643 return true;
644 default:
645 return false;
646 }
647}
648
Dan Williams6f231dd2011-07-02 22:56:22 -0700649/**
650 * isci_terminate_request_core() - This function will terminate the given
651 * request, and wait for it to complete. This function must only be called
652 * from a thread that can wait. Note that the request is terminated and
653 * completed (back to the host, if started there).
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700654 * @ihost: This SCU.
Dan Williams78a6f062011-06-30 16:31:37 -0700655 * @idev: The target.
Dan Williams6f231dd2011-07-02 22:56:22 -0700656 * @isci_request: The I/O request to be terminated.
657 *
Dan Williams6f231dd2011-07-02 22:56:22 -0700658 */
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700659static void isci_terminate_request_core(struct isci_host *ihost,
660 struct isci_remote_device *idev,
661 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700662{
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800663 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700664 bool was_terminated = false;
665 bool needs_cleanup_handling = false;
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700666 unsigned long flags;
667 unsigned long termination_completed = 1;
668 struct completion *io_request_completion;
669 struct sas_task *task;
Dan Williams6f231dd2011-07-02 22:56:22 -0700670
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700671 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700672 "%s: device = %p; request = %p\n",
Dan Williams78a6f062011-06-30 16:31:37 -0700673 __func__, idev, isci_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700674
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700675 spin_lock_irqsave(&ihost->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800676
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700677 io_request_completion = isci_request->io_request_completion;
678
679 task = (isci_request->ttype == io_task)
680 ? isci_request_access_task(isci_request)
681 : NULL;
682
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800683 /* Note that we are not going to control
Dan Williams38d88792011-06-23 14:33:48 -0700684 * the target to abort the request.
685 */
686 set_bit(IREQ_COMPLETE_IN_TARGET, &isci_request->flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800687
Dan Williams6f231dd2011-07-02 22:56:22 -0700688 /* Make sure the request wasn't just sitting around signalling
689 * device condition (if the request handle is NULL, then the
690 * request completed but needed additional handling here).
691 */
Dan Williams38d88792011-06-23 14:33:48 -0700692 if (!test_bit(IREQ_TERMINATED, &isci_request->flags)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700693 was_terminated = true;
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800694 needs_cleanup_handling = true;
Dan Williams89a73012011-06-30 19:14:33 -0700695 status = sci_controller_terminate_request(ihost,
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700696 idev,
697 isci_request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700698 }
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700699 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700700
701 /*
702 * The only time the request to terminate will
703 * fail is when the io request is completed and
704 * being aborted.
705 */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800706 if (status != SCI_SUCCESS) {
Dan Williamsa8a0a132011-07-01 12:07:25 -0700707 dev_dbg(&ihost->pdev->dev,
Dan Williams89a73012011-06-30 19:14:33 -0700708 "%s: sci_controller_terminate_request"
Dan Williams6f231dd2011-07-02 22:56:22 -0700709 " returned = 0x%x\n",
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700710 __func__, status);
711
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800712 isci_request->io_request_completion = NULL;
713
714 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700715 if (was_terminated) {
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700716 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700717 "%s: before completion wait (%p/%p)\n",
718 __func__, isci_request, io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700719
720 /* Wait here for the request to complete. */
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700721 termination_completed
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800722 = wait_for_completion_timeout(
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700723 io_request_completion,
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700724 msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC));
Dan Williams6f231dd2011-07-02 22:56:22 -0700725
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700726 if (!termination_completed) {
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800727
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700728 /* The request to terminate has timed out. */
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700729 spin_lock_irqsave(&ihost->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800730
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700731 /* Check for state changes. */
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700732 if (!test_bit(IREQ_TERMINATED,
733 &isci_request->flags)) {
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800734
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700735 /* The best we can do is to have the
736 * request die a silent death if it
737 * ever really completes.
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700738 */
Jeff Skirvinb343dff2011-10-27 15:05:06 -0700739 isci_request_mark_zombie(ihost,
740 isci_request);
741 needs_cleanup_handling = true;
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700742 } else
743 termination_completed = 1;
744
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700745 spin_unlock_irqrestore(&ihost->scic_lock,
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700746 flags);
747
748 if (!termination_completed) {
749
Dan Williamsa8a0a132011-07-01 12:07:25 -0700750 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700751 "%s: *** Timeout waiting for "
752 "termination(%p/%p)\n",
753 __func__, io_request_completion,
754 isci_request);
755
756 /* The request can no longer be referenced
757 * safely since it may go away if the
758 * termination every really does complete.
759 */
760 isci_request = NULL;
761 }
762 }
763 if (termination_completed)
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700764 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700765 "%s: after completion wait (%p/%p)\n",
766 __func__, isci_request, io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700767 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800768
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700769 if (termination_completed) {
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800770
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700771 isci_request->io_request_completion = NULL;
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800772
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700773 /* Peek at the status of the request. This will tell
774 * us if there was special handling on the request such that it
775 * needs to be detached and freed here.
776 */
777 spin_lock_irqsave(&isci_request->state_lock, flags);
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700778
Jeff Skirvind6891682011-10-27 15:05:01 -0700779 needs_cleanup_handling
780 = isci_request_is_dealloc_managed(
781 isci_request->status);
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700782
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700783 spin_unlock_irqrestore(&isci_request->state_lock, flags);
784
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800785 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700786 if (needs_cleanup_handling)
787 isci_request_cleanup_completed_loiterer(
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700788 ihost, idev, isci_request, task);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800789 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700790}
791
792/**
793 * isci_terminate_pending_requests() - This function will change the all of the
794 * requests on the given device's state to "aborting", will terminate the
795 * requests, and wait for them to complete. This function must only be
796 * called from a thread that can wait. Note that the requests are all
797 * terminated and completed (back to the host, if started there).
798 * @isci_host: This parameter specifies SCU.
Dan Williams78a6f062011-06-30 16:31:37 -0700799 * @idev: This parameter specifies the target.
Dan Williams6f231dd2011-07-02 22:56:22 -0700800 *
Dan Williams6f231dd2011-07-02 22:56:22 -0700801 */
Dan Williams980d3ae2011-06-20 15:11:22 -0700802void isci_terminate_pending_requests(struct isci_host *ihost,
803 struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -0700804{
Dan Williams980d3ae2011-06-20 15:11:22 -0700805 struct completion request_completion;
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700806 enum isci_request_status old_state;
Dan Williams980d3ae2011-06-20 15:11:22 -0700807 unsigned long flags;
808 LIST_HEAD(list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700809
Dan Williams980d3ae2011-06-20 15:11:22 -0700810 spin_lock_irqsave(&ihost->scic_lock, flags);
811 list_splice_init(&idev->reqs_in_process, &list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700812
Dan Williams980d3ae2011-06-20 15:11:22 -0700813 /* assumes that isci_terminate_request_core deletes from the list */
814 while (!list_empty(&list)) {
815 struct isci_request *ireq = list_entry(list.next, typeof(*ireq), dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700816
Dan Williams980d3ae2011-06-20 15:11:22 -0700817 /* Change state to "terminating" if it is currently
818 * "started".
819 */
820 old_state = isci_request_change_started_to_newstate(ireq,
821 &request_completion,
822 terminating);
823 switch (old_state) {
824 case started:
825 case completed:
826 case aborting:
827 break;
828 default:
829 /* termination in progress, or otherwise dispositioned.
830 * We know the request was on 'list' so should be safe
831 * to move it back to reqs_in_process
832 */
833 list_move(&ireq->dev_node, &idev->reqs_in_process);
834 ireq = NULL;
835 break;
836 }
837
838 if (!ireq)
839 continue;
840 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800841
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700842 init_completion(&request_completion);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800843
Dan Williams980d3ae2011-06-20 15:11:22 -0700844 dev_dbg(&ihost->pdev->dev,
845 "%s: idev=%p request=%p; task=%p old_state=%d\n",
846 __func__, idev, ireq,
847 ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL,
848 old_state);
Jeff Skirvin77c852f2011-06-20 14:09:16 -0700849
Dan Williams980d3ae2011-06-20 15:11:22 -0700850 /* If the old_state is started:
851 * This request was not already being aborted. If it had been,
852 * then the aborting I/O (ie. the TMF request) would not be in
853 * the aborting state, and thus would be terminated here. Note
854 * that since the TMF completion's call to the kernel function
855 * "complete()" does not happen until the pending I/O request
856 * terminate fully completes, we do not have to implement a
857 * special wait here for already aborting requests - the
858 * termination of the TMF request will force the request
859 * to finish it's already started terminate.
860 *
861 * If old_state == completed:
862 * This request completed from the SCU hardware perspective
863 * and now just needs cleaning up in terms of freeing the
864 * request and potentially calling up to libsas.
865 *
866 * If old_state == aborting:
867 * This request has already gone through a TMF timeout, but may
868 * not have been terminated; needs cleaning up at least.
869 */
870 isci_terminate_request_core(ihost, idev, ireq);
871 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700872 }
Dan Williams980d3ae2011-06-20 15:11:22 -0700873 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700874}
875
876/**
877 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
878 * Template functions.
879 * @lun: This parameter specifies the lun to be reset.
880 *
881 * status, zero indicates success.
882 */
883static int isci_task_send_lu_reset_sas(
884 struct isci_host *isci_host,
885 struct isci_remote_device *isci_device,
886 u8 *lun)
887{
888 struct isci_tmf tmf;
889 int ret = TMF_RESP_FUNC_FAILED;
890
891 dev_dbg(&isci_host->pdev->dev,
892 "%s: isci_host = %p, isci_device = %p\n",
893 __func__, isci_host, isci_device);
894 /* Send the LUN reset to the target. By the time the call returns,
895 * the TMF has fully exected in the target (in which case the return
896 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
897 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
898 */
Dan Williams209fae12011-06-13 17:39:44 -0700899 isci_task_build_tmf(&tmf, isci_tmf_ssp_lun_reset, NULL, NULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700900
901 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
Dan Williams209fae12011-06-13 17:39:44 -0700902 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
Dan Williams6f231dd2011-07-02 22:56:22 -0700903
904 if (ret == TMF_RESP_FUNC_COMPLETE)
905 dev_dbg(&isci_host->pdev->dev,
906 "%s: %p: TMF_LU_RESET passed\n",
907 __func__, isci_device);
908 else
909 dev_dbg(&isci_host->pdev->dev,
910 "%s: %p: TMF_LU_RESET failed (%x)\n",
911 __func__, isci_device, ret);
912
913 return ret;
914}
915
Dan Williams16ba7702011-07-01 10:52:55 -0700916static int isci_task_send_lu_reset_sata(struct isci_host *ihost,
917 struct isci_remote_device *idev, u8 *lun)
918{
919 int ret = TMF_RESP_FUNC_FAILED;
920 struct isci_tmf tmf;
921
922 /* Send the soft reset to the target */
923 #define ISCI_SRST_TIMEOUT_MS 25000 /* 25 second timeout. */
924 isci_task_build_tmf(&tmf, isci_tmf_sata_srst_high, NULL, NULL);
925
926 ret = isci_task_execute_tmf(ihost, idev, &tmf, ISCI_SRST_TIMEOUT_MS);
927
928 if (ret != TMF_RESP_FUNC_COMPLETE) {
Dan Williamsa8a0a132011-07-01 12:07:25 -0700929 dev_dbg(&ihost->pdev->dev,
Dan Williams16ba7702011-07-01 10:52:55 -0700930 "%s: Assert SRST failed (%p) = %x",
931 __func__, idev, ret);
932
933 /* Return the failure so that the LUN reset is escalated
934 * to a target reset.
935 */
936 }
937 return ret;
938}
939
Dan Williams6f231dd2011-07-02 22:56:22 -0700940/**
941 * isci_task_lu_reset() - This function is one of the SAS Domain Template
942 * functions. This is one of the Task Management functoins called by libsas,
943 * to reset the given lun. Note the assumption that while this call is
944 * executing, no I/O will be sent by the host to the device.
945 * @lun: This parameter specifies the lun to be reset.
946 *
947 * status, zero indicates success.
948 */
Dan Williams4393aa42011-03-31 13:10:44 -0700949int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
Dan Williams6f231dd2011-07-02 22:56:22 -0700950{
Dan Williams4393aa42011-03-31 13:10:44 -0700951 struct isci_host *isci_host = dev_to_ihost(domain_device);
Dan Williams209fae12011-06-13 17:39:44 -0700952 struct isci_remote_device *isci_device;
953 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700954 int ret;
Dan Williams6f231dd2011-07-02 22:56:22 -0700955
Dan Williams209fae12011-06-13 17:39:44 -0700956 spin_lock_irqsave(&isci_host->scic_lock, flags);
957 isci_device = isci_lookup_device(domain_device);
958 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700959
Dan Williams4393aa42011-03-31 13:10:44 -0700960 dev_dbg(&isci_host->pdev->dev,
961 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700962 __func__, domain_device, isci_host, isci_device);
963
Dan Williams209fae12011-06-13 17:39:44 -0700964 if (isci_device)
Dan Williamsd06b4872011-05-02 13:59:25 -0700965 set_bit(IDEV_EH, &isci_device->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700966
967 /* If there is a device reset pending on any request in the
968 * device's list, fail this LUN reset request in order to
969 * escalate to the device reset.
970 */
Dan Williams209fae12011-06-13 17:39:44 -0700971 if (!isci_device ||
Dan Williams4393aa42011-03-31 13:10:44 -0700972 isci_device_is_reset_pending(isci_host, isci_device)) {
Dan Williamsa8a0a132011-07-01 12:07:25 -0700973 dev_dbg(&isci_host->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -0700974 "%s: No dev (%p), or "
Dan Williams6f231dd2011-07-02 22:56:22 -0700975 "RESET PENDING: domain_device=%p\n",
Dan Williams4393aa42011-03-31 13:10:44 -0700976 __func__, isci_device, domain_device);
Dan Williams209fae12011-06-13 17:39:44 -0700977 ret = TMF_RESP_FUNC_FAILED;
978 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -0700979 }
980
Dan Williams6f231dd2011-07-02 22:56:22 -0700981 /* Send the task management part of the reset. */
982 if (sas_protocol_ata(domain_device->tproto)) {
Dan Williams4393aa42011-03-31 13:10:44 -0700983 ret = isci_task_send_lu_reset_sata(isci_host, isci_device, lun);
Dan Williams6f231dd2011-07-02 22:56:22 -0700984 } else
985 ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun);
986
987 /* If the LUN reset worked, all the I/O can now be terminated. */
988 if (ret == TMF_RESP_FUNC_COMPLETE)
989 /* Terminate all I/O now. */
990 isci_terminate_pending_requests(isci_host,
Dan Williams980d3ae2011-06-20 15:11:22 -0700991 isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -0700992
Dan Williams209fae12011-06-13 17:39:44 -0700993 out:
994 isci_put_device(isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -0700995 return ret;
996}
997
998
999/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1000int isci_task_clear_nexus_port(struct asd_sas_port *port)
1001{
1002 return TMF_RESP_FUNC_FAILED;
1003}
1004
1005
1006
1007int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
1008{
1009 return TMF_RESP_FUNC_FAILED;
1010}
1011
Dan Williams6f231dd2011-07-02 22:56:22 -07001012/* Task Management Functions. Must be called from process context. */
1013
1014/**
1015 * isci_abort_task_process_cb() - This is a helper function for the abort task
1016 * TMF command. It manages the request state with respect to the successful
1017 * transmission / completion of the abort task request.
1018 * @cb_state: This parameter specifies when this function was called - after
1019 * the TMF request has been started and after it has timed-out.
1020 * @tmf: This parameter specifies the TMF in progress.
1021 *
1022 *
1023 */
1024static void isci_abort_task_process_cb(
1025 enum isci_tmf_cb_state cb_state,
1026 struct isci_tmf *tmf,
1027 void *cb_data)
1028{
1029 struct isci_request *old_request;
1030
1031 old_request = (struct isci_request *)cb_data;
1032
1033 dev_dbg(&old_request->isci_host->pdev->dev,
1034 "%s: tmf=%p, old_request=%p\n",
1035 __func__, tmf, old_request);
1036
1037 switch (cb_state) {
1038
1039 case isci_tmf_started:
1040 /* The TMF has been started. Nothing to do here, since the
1041 * request state was already set to "aborted" by the abort
1042 * task function.
1043 */
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001044 if ((old_request->status != aborted)
1045 && (old_request->status != completed))
Dan Williamsa8a0a132011-07-01 12:07:25 -07001046 dev_dbg(&old_request->isci_host->pdev->dev,
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001047 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1048 __func__, old_request->status, tmf, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001049 break;
1050
1051 case isci_tmf_timed_out:
1052
1053 /* Set the task's state to "aborting", since the abort task
1054 * function thread set it to "aborted" (above) in anticipation
1055 * of the task management request working correctly. Since the
1056 * timeout has now fired, the TMF request failed. We set the
1057 * state such that the request completion will indicate the
1058 * device is no longer present.
1059 */
1060 isci_request_change_state(old_request, aborting);
1061 break;
1062
1063 default:
Dan Williamsa8a0a132011-07-01 12:07:25 -07001064 dev_dbg(&old_request->isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001065 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1066 __func__, cb_state, tmf, old_request);
1067 break;
1068 }
1069}
1070
1071/**
1072 * isci_task_abort_task() - This function is one of the SAS Domain Template
1073 * functions. This function is called by libsas to abort a specified task.
1074 * @task: This parameter specifies the SAS task to abort.
1075 *
1076 * status, zero indicates success.
1077 */
1078int isci_task_abort_task(struct sas_task *task)
1079{
Dan Williams4393aa42011-03-31 13:10:44 -07001080 struct isci_host *isci_host = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001081 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001082 struct isci_request *old_request = NULL;
1083 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -07001084 struct isci_remote_device *isci_device = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001085 struct isci_tmf tmf;
1086 int ret = TMF_RESP_FUNC_FAILED;
1087 unsigned long flags;
1088 bool any_dev_reset = false;
Dan Williams6f231dd2011-07-02 22:56:22 -07001089
1090 /* Get the isci_request reference from the task. Note that
1091 * this check does not depend on the pending request list
1092 * in the device, because tasks driving resets may land here
1093 * after completion in the core.
1094 */
Dan Williams209fae12011-06-13 17:39:44 -07001095 spin_lock_irqsave(&isci_host->scic_lock, flags);
1096 spin_lock(&task->task_state_lock);
1097
1098 old_request = task->lldd_task;
1099
1100 /* If task is already done, the request isn't valid */
1101 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
1102 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
1103 old_request)
1104 isci_device = isci_lookup_device(task->dev);
1105
1106 spin_unlock(&task->task_state_lock);
1107 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001108
1109 dev_dbg(&isci_host->pdev->dev,
1110 "%s: task = %p\n", __func__, task);
1111
Dan Williams209fae12011-06-13 17:39:44 -07001112 if (!isci_device || !old_request)
1113 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -07001114
Dan Williamsd06b4872011-05-02 13:59:25 -07001115 set_bit(IDEV_EH, &isci_device->flags);
1116
Dan Williams6f231dd2011-07-02 22:56:22 -07001117 /* This version of the driver will fail abort requests for
1118 * SATA/STP. Failing the abort request this way will cause the
1119 * SCSI error handler thread to escalate to LUN reset
1120 */
Dan Williams209fae12011-06-13 17:39:44 -07001121 if (sas_protocol_ata(task->task_proto)) {
Dan Williamsa8a0a132011-07-01 12:07:25 -07001122 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001123 " task %p is for a STP/SATA device;"
1124 " returning TMF_RESP_FUNC_FAILED\n"
1125 " to cause a LUN reset...\n", task);
Dan Williams209fae12011-06-13 17:39:44 -07001126 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -07001127 }
1128
1129 dev_dbg(&isci_host->pdev->dev,
1130 "%s: old_request == %p\n", __func__, old_request);
1131
James Bottomleya5ec7f862011-07-03 14:14:45 -05001132 any_dev_reset = isci_device_is_reset_pending(isci_host, isci_device);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001133
Dan Williams6f231dd2011-07-02 22:56:22 -07001134 spin_lock_irqsave(&task->task_state_lock, flags);
1135
Dan Williams209fae12011-06-13 17:39:44 -07001136 any_dev_reset = any_dev_reset || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
Dan Williams6f231dd2011-07-02 22:56:22 -07001137
1138 /* If the extraction of the request reference from the task
1139 * failed, then the request has been completed (or if there is a
1140 * pending reset then this abort request function must be failed
1141 * in order to escalate to the target reset).
1142 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001143 if ((old_request == NULL) || any_dev_reset) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001144
1145 /* If the device reset task flag is set, fail the task
1146 * management request. Otherwise, the original request
1147 * has completed.
1148 */
1149 if (any_dev_reset) {
1150
1151 /* Turn off the task's DONE to make sure this
1152 * task is escalated to a target reset.
1153 */
1154 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1155
Jeff Skirvina5fde222011-03-04 14:06:42 -08001156 /* Make the reset happen as soon as possible. */
1157 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1158
1159 spin_unlock_irqrestore(&task->task_state_lock, flags);
1160
Dan Williams6f231dd2011-07-02 22:56:22 -07001161 /* Fail the task management request in order to
1162 * escalate to the target reset.
1163 */
1164 ret = TMF_RESP_FUNC_FAILED;
1165
1166 dev_dbg(&isci_host->pdev->dev,
1167 "%s: Failing task abort in order to "
1168 "escalate to target reset because\n"
1169 "SAS_TASK_NEED_DEV_RESET is set for "
1170 "task %p on dev %p\n",
1171 __func__, task, isci_device);
1172
Jeff Skirvina5fde222011-03-04 14:06:42 -08001173
Dan Williams6f231dd2011-07-02 22:56:22 -07001174 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -07001175 /* The request has already completed and there
1176 * is nothing to do here other than to set the task
1177 * done bit, and indicate that the task abort function
1178 * was sucessful.
1179 */
1180 isci_set_task_doneflags(task);
1181
Jeff Skirvina5fde222011-03-04 14:06:42 -08001182 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001183
Jeff Skirvina5fde222011-03-04 14:06:42 -08001184 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001185
Jeff Skirvina5fde222011-03-04 14:06:42 -08001186 dev_dbg(&isci_host->pdev->dev,
1187 "%s: abort task not needed for %p\n",
1188 __func__, task);
Dan Williams6f231dd2011-07-02 22:56:22 -07001189 }
Dan Williams209fae12011-06-13 17:39:44 -07001190 goto out;
James Bottomleya5ec7f862011-07-03 14:14:45 -05001191 } else {
Jeff Skirvina5fde222011-03-04 14:06:42 -08001192 spin_unlock_irqrestore(&task->task_state_lock, flags);
James Bottomleya5ec7f862011-07-03 14:14:45 -05001193 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001194
1195 spin_lock_irqsave(&isci_host->scic_lock, flags);
1196
Jeff Skirvinf219f012011-03-31 13:10:34 -07001197 /* Check the request status and change to "aborted" if currently
Jeff Skirvina5fde222011-03-04 14:06:42 -08001198 * "starting"; if true then set the I/O kernel completion
Dan Williams6f231dd2011-07-02 22:56:22 -07001199 * struct that will be triggered when the request completes.
1200 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001201 old_state = isci_task_validate_request_to_abort(
1202 old_request, isci_host, isci_device,
1203 &aborted_io_completion);
Jeff Skirvinf219f012011-03-31 13:10:34 -07001204 if ((old_state != started) &&
1205 (old_state != completed) &&
1206 (old_state != aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001207
1208 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1209
Jeff Skirvina5fde222011-03-04 14:06:42 -08001210 /* The request was already being handled by someone else (because
1211 * they got to set the state away from started).
1212 */
1213 dev_dbg(&isci_host->pdev->dev,
1214 "%s: device = %p; old_request %p already being aborted\n",
1215 __func__,
1216 isci_device, old_request);
Dan Williams209fae12011-06-13 17:39:44 -07001217 ret = TMF_RESP_FUNC_COMPLETE;
1218 goto out;
Dan Williams6f231dd2011-07-02 22:56:22 -07001219 }
Dan Williams38d88792011-06-23 14:33:48 -07001220 if (task->task_proto == SAS_PROTOCOL_SMP ||
1221 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001222
1223 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1224
Jeff Skirvina5fde222011-03-04 14:06:42 -08001225 dev_dbg(&isci_host->pdev->dev,
1226 "%s: SMP request (%d)"
Jeff Skirvina5fde222011-03-04 14:06:42 -08001227 " or complete_in_target (%d), thus no TMF\n",
1228 __func__, (task->task_proto == SAS_PROTOCOL_SMP),
Dan Williams38d88792011-06-23 14:33:48 -07001229 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags));
Jeff Skirvina5fde222011-03-04 14:06:42 -08001230
Dan Williams6f231dd2011-07-02 22:56:22 -07001231 /* Set the state on the task. */
1232 isci_task_all_done(task);
1233
1234 ret = TMF_RESP_FUNC_COMPLETE;
1235
1236 /* Stopping and SMP devices are not sent a TMF, and are not
Jeff Skirvina5fde222011-03-04 14:06:42 -08001237 * reset, but the outstanding I/O request is terminated below.
Dan Williams6f231dd2011-07-02 22:56:22 -07001238 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001239 } else {
1240 /* Fill in the tmf stucture */
Dan Williams209fae12011-06-13 17:39:44 -07001241 isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort,
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -08001242 isci_abort_task_process_cb,
1243 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001244
Dan Williams6f231dd2011-07-02 22:56:22 -07001245 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1246
1247 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
Dan Williams209fae12011-06-13 17:39:44 -07001248 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf,
Dan Williams6f231dd2011-07-02 22:56:22 -07001249 ISCI_ABORT_TASK_TIMEOUT_MS);
1250
Jeff Skirvina5fde222011-03-04 14:06:42 -08001251 if (ret != TMF_RESP_FUNC_COMPLETE)
Dan Williamsa8a0a132011-07-01 12:07:25 -07001252 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001253 "%s: isci_task_send_tmf failed\n",
1254 __func__);
1255 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001256 if (ret == TMF_RESP_FUNC_COMPLETE) {
Dan Williams38d88792011-06-23 14:33:48 -07001257 set_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001258
Jeff Skirvin77c852f2011-06-20 14:09:16 -07001259 /* Clean up the request on our side, and wait for the aborted
1260 * I/O to complete.
1261 */
Jeff Skirvincbb65c62011-03-04 14:06:50 -08001262 isci_terminate_request_core(isci_host, isci_device, old_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001263 }
1264
1265 /* Make sure we do not leave a reference to aborted_io_completion */
1266 old_request->io_request_completion = NULL;
Dan Williams209fae12011-06-13 17:39:44 -07001267 out:
1268 isci_put_device(isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001269 return ret;
1270}
1271
1272/**
1273 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1274 * functions. This is one of the Task Management functoins called by libsas,
1275 * to abort all task for the given lun.
1276 * @d_device: This parameter specifies the domain device associated with this
1277 * request.
1278 * @lun: This parameter specifies the lun associated with this request.
1279 *
1280 * status, zero indicates success.
1281 */
1282int isci_task_abort_task_set(
1283 struct domain_device *d_device,
1284 u8 *lun)
1285{
1286 return TMF_RESP_FUNC_FAILED;
1287}
1288
1289
1290/**
1291 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1292 * functions. This is one of the Task Management functoins called by libsas.
1293 * @d_device: This parameter specifies the domain device associated with this
1294 * request.
1295 * @lun: This parameter specifies the lun associated with this request.
1296 *
1297 * status, zero indicates success.
1298 */
1299int isci_task_clear_aca(
1300 struct domain_device *d_device,
1301 u8 *lun)
1302{
1303 return TMF_RESP_FUNC_FAILED;
1304}
1305
1306
1307
1308/**
1309 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1310 * functions. This is one of the Task Management functoins called by libsas.
1311 * @d_device: This parameter specifies the domain device associated with this
1312 * request.
1313 * @lun: This parameter specifies the lun associated with this request.
1314 *
1315 * status, zero indicates success.
1316 */
1317int isci_task_clear_task_set(
1318 struct domain_device *d_device,
1319 u8 *lun)
1320{
1321 return TMF_RESP_FUNC_FAILED;
1322}
1323
1324
1325/**
1326 * isci_task_query_task() - This function is implemented to cause libsas to
1327 * correctly escalate the failed abort to a LUN or target reset (this is
1328 * because sas_scsi_find_task libsas function does not correctly interpret
1329 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1330 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1331 * returned, libsas will turn this into a target reset
1332 * @task: This parameter specifies the sas task being queried.
1333 * @lun: This parameter specifies the lun associated with this request.
1334 *
1335 * status, zero indicates success.
1336 */
1337int isci_task_query_task(
1338 struct sas_task *task)
1339{
1340 /* See if there is a pending device reset for this device. */
1341 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1342 return TMF_RESP_FUNC_FAILED;
1343 else
1344 return TMF_RESP_FUNC_SUCC;
1345}
1346
Dave Jiangaf5ae892011-05-04 17:53:24 -07001347/*
Dan Williams6f231dd2011-07-02 22:56:22 -07001348 * isci_task_request_complete() - This function is called by the sci core when
1349 * an task request completes.
Dave Jiangaf5ae892011-05-04 17:53:24 -07001350 * @ihost: This parameter specifies the ISCI host object
1351 * @ireq: This parameter is the completed isci_request object.
Dan Williams6f231dd2011-07-02 22:56:22 -07001352 * @completion_status: This parameter specifies the completion status from the
1353 * sci core.
1354 *
1355 * none.
1356 */
Dave Jiangaf5ae892011-05-04 17:53:24 -07001357void
1358isci_task_request_complete(struct isci_host *ihost,
1359 struct isci_request *ireq,
1360 enum sci_task_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -07001361{
Dave Jiangaf5ae892011-05-04 17:53:24 -07001362 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
Jeff Skirvinb343dff2011-10-27 15:05:06 -07001363 struct completion *tmf_complete = NULL;
1364 struct completion *request_complete = ireq->io_request_completion;
Dan Williams6f231dd2011-07-02 22:56:22 -07001365
Dave Jiangaf5ae892011-05-04 17:53:24 -07001366 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001367 "%s: request = %p, status=%d\n",
Dave Jiangaf5ae892011-05-04 17:53:24 -07001368 __func__, ireq, completion_status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001369
Dave Jiang8d2c65c2011-06-01 09:03:08 +00001370 isci_request_change_state(ireq, completed);
Dan Williams6f231dd2011-07-02 22:56:22 -07001371
Dan Williams38d88792011-06-23 14:33:48 -07001372 set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001373
Jeff Skirvinb343dff2011-10-27 15:05:06 -07001374 if (tmf) {
1375 tmf->status = completion_status;
1376
1377 if (tmf->proto == SAS_PROTOCOL_SSP) {
1378 memcpy(&tmf->resp.resp_iu,
1379 &ireq->ssp.rsp,
1380 SSP_RESP_IU_MAX_SIZE);
1381 } else if (tmf->proto == SAS_PROTOCOL_SATA) {
1382 memcpy(&tmf->resp.d2h_fis,
1383 &ireq->stp.rsp,
1384 sizeof(struct dev_to_host_fis));
1385 }
1386 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1387 tmf_complete = tmf->complete;
Dan Williams6f231dd2011-07-02 22:56:22 -07001388 }
Dan Williams89a73012011-06-30 19:14:33 -07001389 sci_controller_complete_io(ihost, ireq->target_device, ireq);
Dan Williams67ea8382011-05-08 11:47:15 -07001390 /* set the 'terminated' flag handle to make sure it cannot be terminated
Dan Williams6f231dd2011-07-02 22:56:22 -07001391 * or completed again.
1392 */
Dan Williams38d88792011-06-23 14:33:48 -07001393 set_bit(IREQ_TERMINATED, &ireq->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001394
Jeff Skirvind6891682011-10-27 15:05:01 -07001395 /* As soon as something is in the terminate path, deallocation is
1396 * managed there. Note that the final non-managed state of a task
1397 * request is "completed".
1398 */
1399 if ((ireq->status == completed) ||
1400 !isci_request_is_dealloc_managed(ireq->status)) {
1401 isci_request_change_state(ireq, unallocated);
1402 isci_free_tag(ihost, ireq->io_tag);
1403 list_del_init(&ireq->dev_node);
1404 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001405
Jeff Skirvinb343dff2011-10-27 15:05:06 -07001406 /* "request_complete" is set if the task was being terminated. */
1407 if (request_complete)
1408 complete(request_complete);
1409
Dan Williams6f231dd2011-07-02 22:56:22 -07001410 /* The task management part completes last. */
Jeff Skirvinb343dff2011-10-27 15:05:06 -07001411 if (tmf_complete)
1412 complete(tmf_complete);
Dan Williams6f231dd2011-07-02 22:56:22 -07001413}
1414
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001415static void isci_smp_task_timedout(unsigned long _task)
1416{
1417 struct sas_task *task = (void *) _task;
1418 unsigned long flags;
1419
1420 spin_lock_irqsave(&task->task_state_lock, flags);
1421 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
1422 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1423 spin_unlock_irqrestore(&task->task_state_lock, flags);
1424
1425 complete(&task->completion);
1426}
1427
1428static void isci_smp_task_done(struct sas_task *task)
1429{
1430 if (!del_timer(&task->timer))
1431 return;
1432 complete(&task->completion);
1433}
1434
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001435static int isci_smp_execute_task(struct isci_host *ihost,
1436 struct domain_device *dev, void *req,
1437 int req_size, void *resp, int resp_size)
1438{
1439 int res, retry;
1440 struct sas_task *task = NULL;
1441
1442 for (retry = 0; retry < 3; retry++) {
Dan Williams4fcf8122011-07-29 17:26:39 -07001443 task = sas_alloc_task(GFP_KERNEL);
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001444 if (!task)
1445 return -ENOMEM;
1446
1447 task->dev = dev;
1448 task->task_proto = dev->tproto;
1449 sg_init_one(&task->smp_task.smp_req, req, req_size);
1450 sg_init_one(&task->smp_task.smp_resp, resp, resp_size);
1451
1452 task->task_done = isci_smp_task_done;
1453
1454 task->timer.data = (unsigned long) task;
1455 task->timer.function = isci_smp_task_timedout;
1456 task->timer.expires = jiffies + 10*HZ;
1457 add_timer(&task->timer);
1458
1459 res = isci_task_execute_task(task, 1, GFP_KERNEL);
1460
1461 if (res) {
1462 del_timer(&task->timer);
Dan Williamsa8a0a132011-07-01 12:07:25 -07001463 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001464 "%s: executing SMP task failed:%d\n",
1465 __func__, res);
1466 goto ex_err;
1467 }
1468
1469 wait_for_completion(&task->completion);
1470 res = -ECOMM;
1471 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
Dan Williamsa8a0a132011-07-01 12:07:25 -07001472 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001473 "%s: smp task timed out or aborted\n",
1474 __func__);
1475 isci_task_abort_task(task);
1476 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
Dan Williamsa8a0a132011-07-01 12:07:25 -07001477 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001478 "%s: SMP task aborted and not done\n",
1479 __func__);
1480 goto ex_err;
1481 }
1482 }
1483 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1484 task->task_status.stat == SAM_STAT_GOOD) {
1485 res = 0;
1486 break;
1487 }
1488 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1489 task->task_status.stat == SAS_DATA_UNDERRUN) {
1490 /* no error, but return the number of bytes of
1491 * underrun */
1492 res = task->task_status.residual;
1493 break;
1494 }
1495 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1496 task->task_status.stat == SAS_DATA_OVERRUN) {
1497 res = -EMSGSIZE;
1498 break;
1499 } else {
Dan Williamsa8a0a132011-07-01 12:07:25 -07001500 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001501 "%s: task to dev %016llx response: 0x%x "
1502 "status 0x%x\n", __func__,
1503 SAS_ADDR(dev->sas_addr),
1504 task->task_status.resp,
1505 task->task_status.stat);
Dan Williams4fcf8122011-07-29 17:26:39 -07001506 sas_free_task(task);
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001507 task = NULL;
1508 }
1509 }
1510ex_err:
1511 BUG_ON(retry == 3 && task != NULL);
Dan Williams4fcf8122011-07-29 17:26:39 -07001512 sas_free_task(task);
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001513 return res;
1514}
1515
1516#define DISCOVER_REQ_SIZE 16
1517#define DISCOVER_RESP_SIZE 56
1518
1519int isci_smp_get_phy_attached_dev_type(struct isci_host *ihost,
1520 struct domain_device *dev,
1521 int phy_id, int *adt)
1522{
1523 struct smp_resp *disc_resp;
1524 u8 *disc_req;
1525 int res;
1526
1527 disc_resp = kzalloc(DISCOVER_RESP_SIZE, GFP_KERNEL);
1528 if (!disc_resp)
1529 return -ENOMEM;
1530
1531 disc_req = kzalloc(DISCOVER_REQ_SIZE, GFP_KERNEL);
1532 if (disc_req) {
1533 disc_req[0] = SMP_REQUEST;
1534 disc_req[1] = SMP_DISCOVER;
1535 disc_req[9] = phy_id;
1536 } else {
1537 kfree(disc_resp);
1538 return -ENOMEM;
1539 }
1540 res = isci_smp_execute_task(ihost, dev, disc_req, DISCOVER_REQ_SIZE,
1541 disc_resp, DISCOVER_RESP_SIZE);
1542 if (!res) {
1543 if (disc_resp->result != SMP_RESP_FUNC_ACC)
1544 res = disc_resp->result;
1545 else
1546 *adt = disc_resp->disc.attached_dev_type;
1547 }
1548 kfree(disc_req);
1549 kfree(disc_resp);
1550
1551 return res;
1552}
1553
1554static void isci_wait_for_smp_phy_reset(struct isci_remote_device *idev, int phy_num)
1555{
1556 struct domain_device *dev = idev->domain_dev;
1557 struct isci_port *iport = idev->isci_port;
1558 struct isci_host *ihost = iport->isci_host;
1559 int res, iteration = 0, attached_device_type;
1560 #define STP_WAIT_MSECS 25000
1561 unsigned long tmo = msecs_to_jiffies(STP_WAIT_MSECS);
1562 unsigned long deadline = jiffies + tmo;
1563 enum {
1564 SMP_PHYWAIT_PHYDOWN,
1565 SMP_PHYWAIT_PHYUP,
1566 SMP_PHYWAIT_DONE
1567 } phy_state = SMP_PHYWAIT_PHYDOWN;
1568
1569 /* While there is time, wait for the phy to go away and come back */
1570 while (time_is_after_jiffies(deadline) && phy_state != SMP_PHYWAIT_DONE) {
1571 int event = atomic_read(&iport->event);
1572
1573 ++iteration;
1574
1575 tmo = wait_event_timeout(ihost->eventq,
1576 event != atomic_read(&iport->event) ||
1577 !test_bit(IPORT_BCN_BLOCKED, &iport->flags),
1578 tmo);
1579 /* link down, stop polling */
1580 if (!test_bit(IPORT_BCN_BLOCKED, &iport->flags))
1581 break;
1582
1583 dev_dbg(&ihost->pdev->dev,
1584 "%s: iport %p, iteration %d,"
1585 " phase %d: time_remaining %lu, bcns = %d\n",
1586 __func__, iport, iteration, phy_state,
1587 tmo, test_bit(IPORT_BCN_PENDING, &iport->flags));
1588
1589 res = isci_smp_get_phy_attached_dev_type(ihost, dev, phy_num,
1590 &attached_device_type);
1591 tmo = deadline - jiffies;
1592
1593 if (res) {
Dan Williamsa8a0a132011-07-01 12:07:25 -07001594 dev_dbg(&ihost->pdev->dev,
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001595 "%s: iteration %d, phase %d:"
1596 " SMP error=%d, time_remaining=%lu\n",
1597 __func__, iteration, phy_state, res, tmo);
1598 break;
1599 }
1600 dev_dbg(&ihost->pdev->dev,
1601 "%s: iport %p, iteration %d,"
1602 " phase %d: time_remaining %lu, bcns = %d, "
1603 "attdevtype = %x\n",
1604 __func__, iport, iteration, phy_state,
1605 tmo, test_bit(IPORT_BCN_PENDING, &iport->flags),
1606 attached_device_type);
1607
1608 switch (phy_state) {
1609 case SMP_PHYWAIT_PHYDOWN:
1610 /* Has the device gone away? */
1611 if (!attached_device_type)
1612 phy_state = SMP_PHYWAIT_PHYUP;
1613
1614 break;
1615
1616 case SMP_PHYWAIT_PHYUP:
1617 /* Has the device come back? */
1618 if (attached_device_type)
1619 phy_state = SMP_PHYWAIT_DONE;
1620 break;
1621
1622 case SMP_PHYWAIT_DONE:
1623 break;
1624 }
1625
1626 }
1627 dev_dbg(&ihost->pdev->dev, "%s: done\n", __func__);
1628}
1629
Dan Williams209fae12011-06-13 17:39:44 -07001630static int isci_reset_device(struct isci_host *ihost,
Jeff Skirvinbc6f3872011-07-01 13:03:44 -07001631 struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07001632{
Dan Williams209fae12011-06-13 17:39:44 -07001633 struct sas_phy *phy = sas_find_local_phy(idev->domain_dev);
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001634 struct isci_port *iport = idev->isci_port;
Dan Williams6f231dd2011-07-02 22:56:22 -07001635 enum sci_status status;
Dan Williamsd06b4872011-05-02 13:59:25 -07001636 unsigned long flags;
1637 int rc;
Dan Williams6f231dd2011-07-02 22:56:22 -07001638
Dan Williamsd06b4872011-05-02 13:59:25 -07001639 dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001640
Dan Williamsd06b4872011-05-02 13:59:25 -07001641 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -07001642 status = sci_remote_device_reset(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001643 if (status != SCI_SUCCESS) {
Dan Williamsd06b4872011-05-02 13:59:25 -07001644 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001645
Dan Williamsa8a0a132011-07-01 12:07:25 -07001646 dev_dbg(&ihost->pdev->dev,
Dan Williams89a73012011-06-30 19:14:33 -07001647 "%s: sci_remote_device_reset(%p) returned %d!\n",
Dan Williamsd06b4872011-05-02 13:59:25 -07001648 __func__, idev, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001649
1650 return TMF_RESP_FUNC_FAILED;
1651 }
Dan Williamsd06b4872011-05-02 13:59:25 -07001652 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001653
Dan Williams6f231dd2011-07-02 22:56:22 -07001654 /* Make sure all pending requests are able to be fully terminated. */
Dan Williamsd06b4872011-05-02 13:59:25 -07001655 isci_device_clear_reset_pending(ihost, idev);
1656
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001657 /* If this is a device on an expander, disable BCN processing. */
1658 if (!scsi_is_sas_phy_local(phy))
1659 set_bit(IPORT_BCN_BLOCKED, &iport->flags);
1660
Jeff Skirvinbc6f3872011-07-01 13:03:44 -07001661 rc = sas_phy_reset(phy, true);
Dan Williams6f231dd2011-07-02 22:56:22 -07001662
1663 /* Terminate in-progress I/O now. */
Dan Williamsd06b4872011-05-02 13:59:25 -07001664 isci_remote_device_nuke_requests(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001665
Jeff Skirvinff717ab2011-06-20 14:08:51 -07001666 /* Since all pending TCs have been cleaned, resume the RNC. */
Dan Williamsd06b4872011-05-02 13:59:25 -07001667 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams89a73012011-06-30 19:14:33 -07001668 status = sci_remote_device_reset_complete(idev);
Dan Williamsd06b4872011-05-02 13:59:25 -07001669 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001670
Jeff Skirvin61aaff42011-06-21 12:16:33 -07001671 /* If this is a device on an expander, bring the phy back up. */
1672 if (!scsi_is_sas_phy_local(phy)) {
1673 /* A phy reset will cause the device to go away then reappear.
1674 * Since libsas will take action on incoming BCNs (eg. remove
1675 * a device going through an SMP phy-control driven reset),
1676 * we need to wait until the phy comes back up before letting
1677 * discovery proceed in libsas.
1678 */
1679 isci_wait_for_smp_phy_reset(idev, phy->number);
1680
1681 spin_lock_irqsave(&ihost->scic_lock, flags);
1682 isci_port_bcn_enable(ihost, idev->isci_port);
1683 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1684 }
Jeff Skirvinff717ab2011-06-20 14:08:51 -07001685
Dan Williams6f231dd2011-07-02 22:56:22 -07001686 if (status != SCI_SUCCESS) {
Dan Williamsa8a0a132011-07-01 12:07:25 -07001687 dev_dbg(&ihost->pdev->dev,
Dan Williams89a73012011-06-30 19:14:33 -07001688 "%s: sci_remote_device_reset_complete(%p) "
Dan Williamsd06b4872011-05-02 13:59:25 -07001689 "returned %d!\n", __func__, idev, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001690 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001691
Dan Williamsd06b4872011-05-02 13:59:25 -07001692 dev_dbg(&ihost->pdev->dev, "%s: idev %p complete.\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001693
Dan Williamsd06b4872011-05-02 13:59:25 -07001694 return rc;
1695}
1696
1697int isci_task_I_T_nexus_reset(struct domain_device *dev)
1698{
1699 struct isci_host *ihost = dev_to_ihost(dev);
Dan Williamsd06b4872011-05-02 13:59:25 -07001700 struct isci_remote_device *idev;
1701 unsigned long flags;
Jeff Skirvinbc6f3872011-07-01 13:03:44 -07001702 int ret;
Dan Williamsd06b4872011-05-02 13:59:25 -07001703
Dan Williamsd06b4872011-05-02 13:59:25 -07001704 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams209fae12011-06-13 17:39:44 -07001705 idev = isci_lookup_device(dev);
Dan Williamsd06b4872011-05-02 13:59:25 -07001706 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1707
Dan Williams209fae12011-06-13 17:39:44 -07001708 if (!idev || !test_bit(IDEV_EH, &idev->flags)) {
1709 ret = TMF_RESP_FUNC_COMPLETE;
1710 goto out;
1711 }
Dan Williamsd06b4872011-05-02 13:59:25 -07001712
Jeff Skirvinbc6f3872011-07-01 13:03:44 -07001713 ret = isci_reset_device(ihost, idev);
Dan Williams209fae12011-06-13 17:39:44 -07001714 out:
1715 isci_put_device(idev);
1716 return ret;
Dan Williamsd06b4872011-05-02 13:59:25 -07001717}
1718
1719int isci_bus_reset_handler(struct scsi_cmnd *cmd)
1720{
1721 struct domain_device *dev = sdev_to_domain_dev(cmd->device);
Dan Williams209fae12011-06-13 17:39:44 -07001722 struct isci_host *ihost = dev_to_ihost(dev);
1723 struct isci_remote_device *idev;
Dan Williams209fae12011-06-13 17:39:44 -07001724 unsigned long flags;
Jeff Skirvinbc6f3872011-07-01 13:03:44 -07001725 int ret;
Dan Williamsd06b4872011-05-02 13:59:25 -07001726
Dan Williams209fae12011-06-13 17:39:44 -07001727 spin_lock_irqsave(&ihost->scic_lock, flags);
1728 idev = isci_lookup_device(dev);
1729 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1730
1731 if (!idev) {
1732 ret = TMF_RESP_FUNC_COMPLETE;
1733 goto out;
1734 }
1735
Jeff Skirvinbc6f3872011-07-01 13:03:44 -07001736 ret = isci_reset_device(ihost, idev);
Dan Williams209fae12011-06-13 17:39:44 -07001737 out:
1738 isci_put_device(idev);
1739 return ret;
Dan Williams6f231dd2011-07-02 22:56:22 -07001740}