blob: 3a3f54677e5b196d02f8d28fc98352789ccebaf0 [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"
Dan Williams6f231dd2011-07-02 22:56:22 -070059#include "scic_task_request.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070060#include "scic_io_request.h"
Dan Williams88f3b622011-04-22 19:18:03 -070061#include "remote_device.h"
62#include "remote_node_context.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070063#include "isci.h"
64#include "request.h"
65#include "sata.h"
66#include "task.h"
Dave Jiangaf5ae892011-05-04 17:53:24 -070067#include "scic_sds_stp_request.h"
68
Dan Williams50e7f9b2011-03-09 21:27:46 -080069/**
Dan Williams1077a572011-03-11 10:13:51 -080070* isci_task_refuse() - complete the request to the upper layer driver in
71* the case where an I/O needs to be completed back in the submit path.
72* @ihost: host on which the the request was queued
73* @task: request to complete
74* @response: response code for the completed task.
75* @status: status code for the completed task.
Dan Williams50e7f9b2011-03-09 21:27:46 -080076*
Dan Williams50e7f9b2011-03-09 21:27:46 -080077*/
Dan Williams1077a572011-03-11 10:13:51 -080078static void isci_task_refuse(struct isci_host *ihost, struct sas_task *task,
79 enum service_response response,
80 enum exec_status status)
Dan Williams50e7f9b2011-03-09 21:27:46 -080081
Dan Williams1077a572011-03-11 10:13:51 -080082{
83 enum isci_completion_selection disposition;
84
85 disposition = isci_perform_normal_io_completion;
86 disposition = isci_task_set_completion_status(task, response, status,
87 disposition);
Dan Williams50e7f9b2011-03-09 21:27:46 -080088
89 /* Tasks aborted specifically by a call to the lldd_abort_task
Dan Williams1077a572011-03-11 10:13:51 -080090 * function should not be completed to the host in the regular path.
91 */
92 switch (disposition) {
Dan Williams50e7f9b2011-03-09 21:27:46 -080093 case isci_perform_normal_io_completion:
94 /* Normal notification (task_done) */
Dan Williams1077a572011-03-11 10:13:51 -080095 dev_dbg(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -070096 "%s: Normal - task = %p, response=%d, "
97 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -080098 __func__, task, response, status);
99
Dan Williams1077a572011-03-11 10:13:51 -0800100 task->lldd_task = NULL;
Dan Williams50e7f9b2011-03-09 21:27:46 -0800101
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700102 isci_execpath_callback(ihost, task, task->task_done);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800103 break;
104
105 case isci_perform_aborted_io_completion:
106 /* No notification because this request is already in the
107 * abort path.
108 */
Dan Williams1077a572011-03-11 10:13:51 -0800109 dev_warn(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700110 "%s: Aborted - task = %p, response=%d, "
111 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -0800112 __func__, task, response, status);
113 break;
114
115 case isci_perform_error_io_completion:
116 /* Use sas_task_abort */
Dan Williams1077a572011-03-11 10:13:51 -0800117 dev_warn(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700118 "%s: Error - task = %p, response=%d, "
119 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -0800120 __func__, task, response, status);
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700121
122 isci_execpath_callback(ihost, task, sas_task_abort);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800123 break;
124
125 default:
Dan Williams1077a572011-03-11 10:13:51 -0800126 dev_warn(&ihost->pdev->dev,
Dan Williams50e7f9b2011-03-09 21:27:46 -0800127 "%s: isci task notification default case!",
128 __func__);
129 sas_task_abort(task);
130 break;
131 }
132}
Dan Williams6f231dd2011-07-02 22:56:22 -0700133
Dan Williams1077a572011-03-11 10:13:51 -0800134#define for_each_sas_task(num, task) \
135 for (; num > 0; num--,\
136 task = list_entry(task->list.next, struct sas_task, list))
137
Dan Williams6f231dd2011-07-02 22:56:22 -0700138/**
139 * isci_task_execute_task() - This function is one of the SAS Domain Template
140 * functions. This function is called by libsas to send a task down to
141 * hardware.
142 * @task: This parameter specifies the SAS task to send.
143 * @num: This parameter specifies the number of tasks to queue.
144 * @gfp_flags: This parameter specifies the context of this call.
145 *
146 * status, zero indicates success.
147 */
148int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags)
149{
Dan Williams4393aa42011-03-31 13:10:44 -0700150 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700151 struct isci_request *request = NULL;
152 struct isci_remote_device *device;
153 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700154 int ret;
155 enum sci_status status;
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700156 enum isci_status device_status;
Dan Williams6f231dd2011-07-02 22:56:22 -0700157
Dan Williams1077a572011-03-11 10:13:51 -0800158 dev_dbg(&ihost->pdev->dev, "%s: num=%d\n", __func__, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700159
160 /* Check if we have room for more tasks */
Dan Williams1077a572011-03-11 10:13:51 -0800161 ret = isci_host_can_queue(ihost, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700162
163 if (ret) {
Dan Williams1077a572011-03-11 10:13:51 -0800164 dev_warn(&ihost->pdev->dev, "%s: queue full\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -0700165 return ret;
166 }
167
Dan Williams1077a572011-03-11 10:13:51 -0800168 for_each_sas_task(num, task) {
169 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700170 "task = %p, num = %d; dev = %p; cmd = %p\n",
171 task, num, task->dev, task->uldd_task);
172
Dan Williams4393aa42011-03-31 13:10:44 -0700173 device = task->dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700174
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700175 if (device)
176 device_status = device->status;
177 else
178 device_status = isci_freed;
179
180 /* From this point onward, any process that needs to guarantee
181 * that there is no kernel I/O being started will have to wait
182 * for the quiesce spinlock.
183 */
184
185 if (device_status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700186
187 /* Forces a retry from scsi mid layer. */
Dave Jiangd2d61432011-04-21 05:36:23 +0000188 dev_dbg(&ihost->pdev->dev,
189 "%s: task %p: isci_host->status = %d, "
190 "device = %p; device_status = 0x%x\n\n",
191 __func__,
192 task,
193 isci_host_get_state(ihost),
194 device,
195 device_status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700196
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700197 if (device_status == isci_ready) {
198 /* Indicate QUEUE_FULL so that the scsi midlayer
199 * retries.
200 */
Dan Williams1077a572011-03-11 10:13:51 -0800201 isci_task_refuse(ihost, task,
202 SAS_TASK_COMPLETE,
203 SAS_QUEUE_FULL);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700204 } else {
205 /* Else, the device is going down. */
Dan Williams1077a572011-03-11 10:13:51 -0800206 isci_task_refuse(ihost, task,
207 SAS_TASK_UNDELIVERED,
208 SAS_DEVICE_UNKNOWN);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700209 }
Dan Williams1077a572011-03-11 10:13:51 -0800210 isci_host_can_dequeue(ihost, 1);
Dan Williams6f231dd2011-07-02 22:56:22 -0700211 } else {
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700212 /* There is a device and it's ready for I/O. */
213 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700214
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700215 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
216
217 spin_unlock_irqrestore(&task->task_state_lock,
218 flags);
219
Dan Williams1077a572011-03-11 10:13:51 -0800220 isci_task_refuse(ihost, task,
221 SAS_TASK_UNDELIVERED,
222 SAM_STAT_TASK_ABORTED);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700223
224 /* The I/O was aborted. */
225
226 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700227 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
228 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700229
230 /* build and send the request. */
Dan Williams1077a572011-03-11 10:13:51 -0800231 status = isci_request_execute(ihost, task, &request,
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700232 gfp_flags);
233
234 if (status != SCI_SUCCESS) {
235
236 spin_lock_irqsave(&task->task_state_lock, flags);
237 /* Did not really start this command. */
238 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
239 spin_unlock_irqrestore(&task->task_state_lock, flags);
240
241 /* Indicate QUEUE_FULL so that the scsi
242 * midlayer retries. if the request
243 * failed for remote device reasons,
244 * it gets returned as
245 * SAS_TASK_UNDELIVERED next time
246 * through.
247 */
Dan Williams1077a572011-03-11 10:13:51 -0800248 isci_task_refuse(ihost, task,
249 SAS_TASK_COMPLETE,
250 SAS_QUEUE_FULL);
251 isci_host_can_dequeue(ihost, 1);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700252 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700253 }
254 }
Dan Williams1077a572011-03-11 10:13:51 -0800255 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700256 return 0;
257}
258
259
260
261/**
262 * isci_task_request_build() - This function builds the task request object.
263 * @isci_host: This parameter specifies the ISCI host object
264 * @request: This parameter points to the isci_request object allocated in the
265 * request construct function.
266 * @tmf: This parameter is the task management struct to be built
267 *
268 * SCI_SUCCESS on successfull completion, or specific failure code.
269 */
270static enum sci_status isci_task_request_build(
271 struct isci_host *isci_host,
272 struct isci_request **isci_request,
273 struct isci_tmf *isci_tmf)
274{
275 struct scic_sds_remote_device *sci_device;
276 enum sci_status status = SCI_FAILURE;
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700277 struct isci_request *request = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700278 struct isci_remote_device *isci_device;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700279 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700280
281 dev_dbg(&isci_host->pdev->dev,
282 "%s: isci_tmf = %p\n", __func__, isci_tmf);
283
284 isci_device = isci_tmf->device;
Dan Williams57f20f42011-04-21 18:14:45 -0700285 sci_device = &isci_device->sci;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700286 dev = isci_device->domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700287
288 /* do common allocation and init of request object. */
289 status = isci_request_alloc_tmf(
290 isci_host,
291 isci_tmf,
292 &request,
293 isci_device,
294 GFP_ATOMIC
295 );
296
297 if (status != SCI_SUCCESS)
298 goto out;
299
300 /* let the core do it's construct. */
301 status = scic_task_request_construct(
302 isci_host->core_controller,
303 sci_device,
304 SCI_CONTROLLER_INVALID_IO_TAG,
305 request,
306 request->sci_request_mem_ptr,
307 &request->sci_request_handle
308 );
309
310 if (status != SCI_SUCCESS) {
311 dev_warn(&isci_host->pdev->dev,
312 "%s: scic_task_request_construct failed - "
313 "status = 0x%x\n",
314 __func__,
315 status);
316 goto errout;
317 }
318
Maciej Patelczyk890cae92011-04-28 22:06:31 +0000319 request->sci_request_handle->ireq = request;
Dan Williams6f231dd2011-07-02 22:56:22 -0700320
Dan Williamsa1a113b2011-04-21 18:44:45 -0700321 /* XXX convert to get this from task->tproto like other drivers */
322 if (dev->dev_type == SAS_END_DEV) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700323 isci_tmf->proto = SAS_PROTOCOL_SSP;
324 status = scic_task_request_construct_ssp(
325 request->sci_request_handle
326 );
327 if (status != SCI_SUCCESS)
328 goto errout;
329 }
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;
333 status = isci_sata_management_task_request_build(request);
334
335 if (status != SCI_SUCCESS)
336 goto errout;
337 }
338
339 goto out;
340
341 errout:
342
343 /* release the dma memory if we fail. */
344 isci_request_free(isci_host, request);
345 request = NULL;
346
347 out:
348 *isci_request = request;
349 return status;
350}
351
352/**
353 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
354 * the timeout period for the TMF has expired.
355 *
356 *
357 */
358static void isci_tmf_timeout_cb(void *tmf_request_arg)
359{
360 struct isci_request *request = (struct isci_request *)tmf_request_arg;
361 struct isci_tmf *tmf = isci_request_access_tmf(request);
362 enum sci_status status;
363
Dan Williams6f231dd2011-07-02 22:56:22 -0700364 /* This task management request has timed-out. Terminate the request
365 * so that the request eventually completes to the requestor in the
366 * request completion callback path.
367 */
368 /* Note - the timer callback function itself has provided spinlock
369 * exclusion from the start and completion paths. No need to take
370 * the request->isci_host->scic_lock here.
371 */
372
373 if (tmf->timeout_timer != NULL) {
374 /* Call the users callback, if any. */
375 if (tmf->cb_state_func != NULL)
376 tmf->cb_state_func(isci_tmf_timed_out, tmf,
377 tmf->cb_data);
378
379 /* Terminate the TMF transmit request. */
380 status = scic_controller_terminate_request(
381 request->isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700382 &request->isci_device->sci,
Dan Williams6f231dd2011-07-02 22:56:22 -0700383 request->sci_request_handle
384 );
385
386 dev_dbg(&request->isci_host->pdev->dev,
387 "%s: tmf_request = %p; tmf = %p; status = %d\n",
388 __func__, request, tmf, status);
389 } else
390 dev_dbg(&request->isci_host->pdev->dev,
391 "%s: timer already canceled! "
392 "tmf_request = %p; tmf = %p\n",
393 __func__, request, tmf);
394
395 /* No need to unlock since the caller to this callback is doing it for
396 * us.
397 * request->isci_host->scic_lock
398 */
399}
400
401/**
402 * isci_task_execute_tmf() - This function builds and sends a task request,
403 * then waits for the completion.
404 * @isci_host: This parameter specifies the ISCI host object
405 * @tmf: This parameter is the pointer to the task management structure for
406 * this request.
407 * @timeout_ms: This parameter specifies the timeout period for the task
408 * management request.
409 *
410 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
411 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
412 */
413int isci_task_execute_tmf(
414 struct isci_host *isci_host,
415 struct isci_tmf *tmf,
416 unsigned long timeout_ms)
417{
418 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700419 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700420 struct scic_sds_remote_device *sci_device;
421 struct isci_remote_device *isci_device = tmf->device;
422 struct isci_request *request;
423 int ret = TMF_RESP_FUNC_FAILED;
424 unsigned long flags;
425
426 /* sanity check, return TMF_RESP_FUNC_FAILED
427 * if the device is not there and ready.
428 */
Dan Williams8acaec12011-03-07 14:47:35 -0800429 if (!isci_device || isci_device->status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700430 dev_dbg(&isci_host->pdev->dev,
431 "%s: isci_device = %p not ready (%d)\n",
432 __func__,
Dan Williams8acaec12011-03-07 14:47:35 -0800433 isci_device, isci_device->status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700434 return TMF_RESP_FUNC_FAILED;
435 } else
436 dev_dbg(&isci_host->pdev->dev,
437 "%s: isci_device = %p\n",
438 __func__, isci_device);
439
Dan Williams57f20f42011-04-21 18:14:45 -0700440 sci_device = &isci_device->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700441
442 /* Assign the pointer to the TMF's completion kernel wait structure. */
443 tmf->complete = &completion;
444
445 isci_task_request_build(
446 isci_host,
447 &request,
448 tmf
449 );
450
451 if (!request) {
452 dev_warn(&isci_host->pdev->dev,
453 "%s: isci_task_request_build failed\n",
454 __func__);
455 return TMF_RESP_FUNC_FAILED;
456 }
457
458 /* Allocate the TMF timeout timer. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700459 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800460 tmf->timeout_timer = isci_timer_create(isci_host, request, isci_tmf_timeout_cb);
Dan Williams6f231dd2011-07-02 22:56:22 -0700461
462 /* Start the timer. */
463 if (tmf->timeout_timer)
464 isci_timer_start(tmf->timeout_timer, timeout_ms);
465 else
466 dev_warn(&isci_host->pdev->dev,
467 "%s: isci_timer_create failed!!!!\n",
468 __func__);
469
470 /* start the TMF io. */
471 status = scic_controller_start_task(
472 isci_host->core_controller,
473 sci_device,
474 request->sci_request_handle,
475 SCI_CONTROLLER_INVALID_IO_TAG
476 );
477
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700478 if (status != SCI_TASK_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700479 dev_warn(&isci_host->pdev->dev,
480 "%s: start_io failed - status = 0x%x, request = %p\n",
481 __func__,
482 status,
483 request);
484 goto cleanup_request;
485 }
486
487 /* Call the users callback, if any. */
488 if (tmf->cb_state_func != NULL)
489 tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data);
490
491 /* Change the state of the TMF-bearing request to "started". */
492 isci_request_change_state(request, started);
493
494 /* add the request to the remote device request list. */
495 list_add(&request->dev_node, &isci_device->reqs_in_process);
496
497 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
498
499 /* Wait for the TMF to complete, or a timeout. */
500 wait_for_completion(&completion);
501
502 isci_print_tmf(tmf);
503
504 if (tmf->status == SCI_SUCCESS)
505 ret = TMF_RESP_FUNC_COMPLETE;
506 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
507 dev_dbg(&isci_host->pdev->dev,
508 "%s: tmf.status == "
509 "SCI_FAILURE_IO_RESPONSE_VALID\n",
510 __func__);
511 ret = TMF_RESP_FUNC_COMPLETE;
512 }
513 /* Else - leave the default "failed" status alone. */
514
515 dev_dbg(&isci_host->pdev->dev,
516 "%s: completed request = %p\n",
517 __func__,
518 request);
519
520 if (request->io_request_completion != NULL) {
521
522 /* The fact that this is non-NULL for a TMF request
523 * means there is a thread waiting for this TMF to
524 * finish.
525 */
526 complete(request->io_request_completion);
527 }
528
529 spin_lock_irqsave(&isci_host->scic_lock, flags);
530
531 cleanup_request:
532
533 /* Clean up the timer if needed. */
534 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -0800535 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -0700536 tmf->timeout_timer = NULL;
537 }
538
539 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
540
541 isci_request_free(isci_host, request);
542
543 return ret;
544}
545
546void isci_task_build_tmf(
547 struct isci_tmf *tmf,
548 struct isci_remote_device *isci_device,
549 enum isci_tmf_function_codes code,
550 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
551 struct isci_tmf *,
552 void *),
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800553 void *cb_data)
Dan Williams6f231dd2011-07-02 22:56:22 -0700554{
555 dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
556 "%s: isci_device = %p\n", __func__, isci_device);
557
558 memset(tmf, 0, sizeof(*tmf));
559
560 tmf->device = isci_device;
561 tmf->tmf_code = code;
562 tmf->timeout_timer = NULL;
563 tmf->cb_state_func = tmf_sent_cb;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800564 tmf->cb_data = cb_data;
565}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800566
Dan Williams35173d52011-03-26 16:43:01 -0700567static void isci_task_build_abort_task_tmf(
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800568 struct isci_tmf *tmf,
569 struct isci_remote_device *isci_device,
570 enum isci_tmf_function_codes code,
571 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
572 struct isci_tmf *,
573 void *),
574 struct isci_request *old_request)
575{
576 isci_task_build_tmf(tmf, isci_device, code, tmf_sent_cb,
577 (void *)old_request);
578 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700579}
580
581static struct isci_request *isci_task_get_request_from_task(
582 struct sas_task *task,
Dan Williams6f231dd2011-07-02 22:56:22 -0700583 struct isci_remote_device **isci_device)
584{
585
586 struct isci_request *request = NULL;
587 unsigned long flags;
588
589 spin_lock_irqsave(&task->task_state_lock, flags);
590
591 request = task->lldd_task;
592
593 /* If task is already done, the request isn't valid */
594 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
595 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
596 (request != NULL)) {
597
Dan Williams6f231dd2011-07-02 22:56:22 -0700598 if (isci_device != NULL)
599 *isci_device = request->isci_device;
600 }
601
602 spin_unlock_irqrestore(&task->task_state_lock, flags);
603
604 return request;
605}
606
607/**
608 * isci_task_validate_request_to_abort() - This function checks the given I/O
609 * against the "started" state. If the request is still "started", it's
610 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
611 * BEFORE CALLING THIS FUNCTION.
612 * @isci_request: This parameter specifies the request object to control.
613 * @isci_host: This parameter specifies the ISCI host object
614 * @isci_device: This is the device to which the request is pending.
615 * @aborted_io_completion: This is a completion structure that will be added to
616 * the request in case it is changed to aborting; this completion is
617 * triggered when the request is fully completed.
618 *
619 * Either "started" on successful change of the task status to "aborted", or
620 * "unallocated" if the task cannot be controlled.
621 */
622static enum isci_request_status isci_task_validate_request_to_abort(
623 struct isci_request *isci_request,
624 struct isci_host *isci_host,
625 struct isci_remote_device *isci_device,
626 struct completion *aborted_io_completion)
627{
628 enum isci_request_status old_state = unallocated;
629
630 /* Only abort the task if it's in the
631 * device's request_in_process list
632 */
633 if (isci_request && !list_empty(&isci_request->dev_node)) {
634 old_state = isci_request_change_started_to_aborted(
635 isci_request, aborted_io_completion);
636
Dan Williams6f231dd2011-07-02 22:56:22 -0700637 }
638
639 return old_state;
640}
641
642static void isci_request_cleanup_completed_loiterer(
643 struct isci_host *isci_host,
644 struct isci_remote_device *isci_device,
645 struct isci_request *isci_request)
646{
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800647 struct sas_task *task;
648 unsigned long flags;
649
650 task = (isci_request->ttype == io_task)
651 ? isci_request_access_task(isci_request)
652 : NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700653
654 dev_dbg(&isci_host->pdev->dev,
655 "%s: isci_device=%p, request=%p, task=%p\n",
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800656 __func__, isci_device, isci_request, task);
Dan Williams6f231dd2011-07-02 22:56:22 -0700657
658 spin_lock_irqsave(&isci_host->scic_lock, flags);
659 list_del_init(&isci_request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700660 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
661
Jeff Skirvina5fde222011-03-04 14:06:42 -0800662 if (task != NULL) {
663
664 spin_lock_irqsave(&task->task_state_lock, flags);
665 task->lldd_task = NULL;
666
667 isci_set_task_doneflags(task);
668
669 /* If this task is not in the abort path, call task_done. */
670 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
671
672 spin_unlock_irqrestore(&task->task_state_lock, flags);
673 task->task_done(task);
674 } else
675 spin_unlock_irqrestore(&task->task_state_lock, flags);
676 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700677 isci_request_free(isci_host, isci_request);
678}
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800679
680/**
681* @isci_termination_timed_out(): this function will deal with a request for
682* which the wait for termination has timed-out.
683*
684* @isci_host This SCU.
685* @isci_request The I/O request being terminated.
686*/
687static void
688isci_termination_timed_out(
689 struct isci_host * host,
690 struct isci_request * request
691 )
692{
693 unsigned long state_flags;
694
695 dev_warn(&host->pdev->dev,
696 "%s: host = %p; request = %p\n",
697 __func__, host, request);
698
699 /* At this point, the request to terminate
700 * has timed out. The best we can do is to
701 * have the request die a silent death
702 * if it ever completes.
703 */
704 spin_lock_irqsave(&request->state_lock, state_flags);
705
706 if (request->status == started) {
707
708 /* Set the request state to "dead",
709 * and clear the task pointer so that an actual
710 * completion event callback doesn't do
711 * anything.
712 */
713 request->status = dead;
714
715 /* Clear the timeout completion event pointer.*/
716 request->io_request_completion = NULL;
717
718 if (request->ttype == io_task) {
719
720 /* Break links with the sas_task. */
721 if (request->ttype_ptr.io_task_ptr != NULL) {
722
723 request->ttype_ptr.io_task_ptr->lldd_task = NULL;
724 request->ttype_ptr.io_task_ptr = NULL;
725 }
726 }
727 }
728 spin_unlock_irqrestore(&request->state_lock, state_flags);
729}
730
731
Dan Williams6f231dd2011-07-02 22:56:22 -0700732/**
733 * isci_terminate_request_core() - This function will terminate the given
734 * request, and wait for it to complete. This function must only be called
735 * from a thread that can wait. Note that the request is terminated and
736 * completed (back to the host, if started there).
737 * @isci_host: This SCU.
738 * @isci_device: The target.
739 * @isci_request: The I/O request to be terminated.
740 *
741 *
742 */
743static void isci_terminate_request_core(
744 struct isci_host *isci_host,
745 struct isci_remote_device *isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800746 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700747{
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800748 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700749 bool was_terminated = false;
750 bool needs_cleanup_handling = false;
751 enum isci_request_status request_status;
752 unsigned long flags;
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800753 unsigned long timeout_remaining;
754
Dan Williams6f231dd2011-07-02 22:56:22 -0700755
756 dev_dbg(&isci_host->pdev->dev,
757 "%s: device = %p; request = %p\n",
758 __func__, isci_device, isci_request);
759
Dan Williams6f231dd2011-07-02 22:56:22 -0700760 spin_lock_irqsave(&isci_host->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800761
762 /* Note that we are not going to control
763 * the target to abort the request.
764 */
765 isci_request->complete_in_target = true;
766
Dan Williams6f231dd2011-07-02 22:56:22 -0700767 /* Make sure the request wasn't just sitting around signalling
768 * device condition (if the request handle is NULL, then the
769 * request completed but needed additional handling here).
770 */
771 if (isci_request->sci_request_handle != NULL) {
772 was_terminated = true;
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800773 needs_cleanup_handling = true;
Dan Williams6f231dd2011-07-02 22:56:22 -0700774 status = scic_controller_terminate_request(
775 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700776 &isci_device->sci,
777 isci_request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -0700778 }
779 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
780
781 /*
782 * The only time the request to terminate will
783 * fail is when the io request is completed and
784 * being aborted.
785 */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800786 if (status != SCI_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700787 dev_err(&isci_host->pdev->dev,
788 "%s: scic_controller_terminate_request"
789 " returned = 0x%x\n",
790 __func__,
791 status);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800792 /* Clear the completion pointer from the request. */
793 isci_request->io_request_completion = NULL;
794
795 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700796 if (was_terminated) {
797 dev_dbg(&isci_host->pdev->dev,
798 "%s: before completion wait (%p)\n",
799 __func__,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800800 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700801
802 /* Wait here for the request to complete. */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800803 #define TERMINATION_TIMEOUT_MSEC 50
804 timeout_remaining
805 = wait_for_completion_timeout(
806 isci_request->io_request_completion,
807 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC));
Dan Williams6f231dd2011-07-02 22:56:22 -0700808
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800809 if (!timeout_remaining) {
810
811 isci_termination_timed_out(isci_host,
812 isci_request);
813
814 dev_err(&isci_host->pdev->dev,
815 "%s: *** Timeout waiting for "
816 "termination(%p/%p)\n",
817 __func__,
818 isci_request->io_request_completion,
819 isci_request);
820
821 } else
822 dev_dbg(&isci_host->pdev->dev,
823 "%s: after completion wait (%p)\n",
824 __func__,
825 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700826 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800827 /* Clear the completion pointer from the request. */
828 isci_request->io_request_completion = NULL;
829
830 /* Peek at the status of the request. This will tell
831 * us if there was special handling on the request such that it
832 * needs to be detached and freed here.
833 */
834 spin_lock_irqsave(&isci_request->state_lock, flags);
835 request_status = isci_request_get_state(isci_request);
836
837 if ((isci_request->ttype == io_task) /* TMFs are in their own thread */
838 && ((request_status == aborted)
839 || (request_status == aborting)
840 || (request_status == terminating)
841 || (request_status == completed)
842 || (request_status == dead)
843 )
844 ) {
845
846 /* The completion routine won't free a request in
847 * the aborted/aborting/etc. states, so we do
848 * it here.
849 */
850 needs_cleanup_handling = true;
851 }
852 spin_unlock_irqrestore(&isci_request->state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700853
854 if (needs_cleanup_handling)
855 isci_request_cleanup_completed_loiterer(
856 isci_host, isci_device, isci_request
857 );
858 }
859}
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800860
Dan Williams6f231dd2011-07-02 22:56:22 -0700861static void isci_terminate_request(
862 struct isci_host *isci_host,
863 struct isci_remote_device *isci_device,
864 struct isci_request *isci_request,
865 enum isci_request_status new_request_state)
866{
867 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -0700868 DECLARE_COMPLETION_ONSTACK(request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700869
870 /* Change state to "new_request_state" if it is currently "started" */
871 old_state = isci_request_change_started_to_newstate(
872 isci_request,
873 &request_completion,
874 new_request_state
875 );
876
Jeff Skirvinf219f012011-03-31 13:10:34 -0700877 if ((old_state == started) ||
878 (old_state == completed) ||
879 (old_state == aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700880
Jeff Skirvina5fde222011-03-04 14:06:42 -0800881 /* If the old_state is started:
882 * This request was not already being aborted. If it had been,
Dan Williams6f231dd2011-07-02 22:56:22 -0700883 * then the aborting I/O (ie. the TMF request) would not be in
884 * the aborting state, and thus would be terminated here. Note
885 * that since the TMF completion's call to the kernel function
886 * "complete()" does not happen until the pending I/O request
887 * terminate fully completes, we do not have to implement a
888 * special wait here for already aborting requests - the
889 * termination of the TMF request will force the request
890 * to finish it's already started terminate.
Jeff Skirvina5fde222011-03-04 14:06:42 -0800891 *
892 * If old_state == completed:
893 * This request completed from the SCU hardware perspective
894 * and now just needs cleaning up in terms of freeing the
895 * request and potentially calling up to libsas.
Jeff Skirvinf219f012011-03-31 13:10:34 -0700896 *
897 * If old_state == aborting:
898 * This request has already gone through a TMF timeout, but may
899 * not have been terminated; needs cleaning up at least.
Dan Williams6f231dd2011-07-02 22:56:22 -0700900 */
901 isci_terminate_request_core(isci_host, isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800902 isci_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800903 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700904}
905
906/**
907 * isci_terminate_pending_requests() - This function will change the all of the
908 * requests on the given device's state to "aborting", will terminate the
909 * requests, and wait for them to complete. This function must only be
910 * called from a thread that can wait. Note that the requests are all
911 * terminated and completed (back to the host, if started there).
912 * @isci_host: This parameter specifies SCU.
913 * @isci_device: This parameter specifies the target.
914 *
915 *
916 */
917void isci_terminate_pending_requests(
918 struct isci_host *isci_host,
919 struct isci_remote_device *isci_device,
920 enum isci_request_status new_request_state)
921{
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800922 struct isci_request *request;
923 struct isci_request *next_request;
924 unsigned long flags;
925 struct list_head aborted_request_list;
926
927 INIT_LIST_HEAD(&aborted_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700928
929 dev_dbg(&isci_host->pdev->dev,
930 "%s: isci_device = %p (new request state = %d)\n",
931 __func__, isci_device, new_request_state);
932
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800933 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700934
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800935 /* Move all of the pending requests off of the device list. */
936 list_splice_init(&isci_device->reqs_in_process,
937 &aborted_request_list);
938
939 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
940
941 /* Iterate through the now-local list. */
942 list_for_each_entry_safe(request, next_request,
943 &aborted_request_list, dev_node) {
944
945 dev_warn(&isci_host->pdev->dev,
946 "%s: isci_device=%p request=%p; task=%p\n",
947 __func__,
948 isci_device, request,
949 ((request->ttype == io_task)
950 ? isci_request_access_task(request)
951 : NULL));
952
953 /* Mark all still pending I/O with the selected next
954 * state, terminate and free it.
955 */
956 isci_terminate_request(isci_host, isci_device,
957 request, new_request_state
958 );
Dan Williams6f231dd2011-07-02 22:56:22 -0700959 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700960}
961
962/**
963 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
964 * Template functions.
965 * @lun: This parameter specifies the lun to be reset.
966 *
967 * status, zero indicates success.
968 */
969static int isci_task_send_lu_reset_sas(
970 struct isci_host *isci_host,
971 struct isci_remote_device *isci_device,
972 u8 *lun)
973{
974 struct isci_tmf tmf;
975 int ret = TMF_RESP_FUNC_FAILED;
976
977 dev_dbg(&isci_host->pdev->dev,
978 "%s: isci_host = %p, isci_device = %p\n",
979 __func__, isci_host, isci_device);
980 /* Send the LUN reset to the target. By the time the call returns,
981 * the TMF has fully exected in the target (in which case the return
982 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
983 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
984 */
985 isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_lun_reset, NULL,
986 NULL);
987
988 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
989 ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
990
991 if (ret == TMF_RESP_FUNC_COMPLETE)
992 dev_dbg(&isci_host->pdev->dev,
993 "%s: %p: TMF_LU_RESET passed\n",
994 __func__, isci_device);
995 else
996 dev_dbg(&isci_host->pdev->dev,
997 "%s: %p: TMF_LU_RESET failed (%x)\n",
998 __func__, isci_device, ret);
999
1000 return ret;
1001}
1002
1003/**
1004 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1005 * functions. This is one of the Task Management functoins called by libsas,
1006 * to reset the given lun. Note the assumption that while this call is
1007 * executing, no I/O will be sent by the host to the device.
1008 * @lun: This parameter specifies the lun to be reset.
1009 *
1010 * status, zero indicates success.
1011 */
Dan Williams4393aa42011-03-31 13:10:44 -07001012int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
Dan Williams6f231dd2011-07-02 22:56:22 -07001013{
Dan Williams4393aa42011-03-31 13:10:44 -07001014 struct isci_host *isci_host = dev_to_ihost(domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001015 struct isci_remote_device *isci_device = NULL;
1016 int ret;
1017 bool device_stopping = false;
1018
Dan Williams4393aa42011-03-31 13:10:44 -07001019 isci_device = domain_device->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001020
Dan Williams4393aa42011-03-31 13:10:44 -07001021 dev_dbg(&isci_host->pdev->dev,
1022 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07001023 __func__, domain_device, isci_host, isci_device);
1024
Dan Williamsd06b4872011-05-02 13:59:25 -07001025 if (isci_device != NULL) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001026 device_stopping = (isci_device->status == isci_stopping)
1027 || (isci_device->status == isci_stopped);
Dan Williamsd06b4872011-05-02 13:59:25 -07001028 set_bit(IDEV_EH, &isci_device->flags);
1029 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001030
1031 /* If there is a device reset pending on any request in the
1032 * device's list, fail this LUN reset request in order to
1033 * escalate to the device reset.
1034 */
Dan Williams4393aa42011-03-31 13:10:44 -07001035 if (!isci_device || device_stopping ||
1036 isci_device_is_reset_pending(isci_host, isci_device)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001037 dev_warn(&isci_host->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -07001038 "%s: No dev (%p), or "
Dan Williams6f231dd2011-07-02 22:56:22 -07001039 "RESET PENDING: domain_device=%p\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001040 __func__, isci_device, domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001041 return TMF_RESP_FUNC_FAILED;
1042 }
1043
Dan Williams6f231dd2011-07-02 22:56:22 -07001044 /* Send the task management part of the reset. */
1045 if (sas_protocol_ata(domain_device->tproto)) {
Dan Williams4393aa42011-03-31 13:10:44 -07001046 ret = isci_task_send_lu_reset_sata(isci_host, isci_device, lun);
Dan Williams6f231dd2011-07-02 22:56:22 -07001047 } else
1048 ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun);
1049
1050 /* If the LUN reset worked, all the I/O can now be terminated. */
1051 if (ret == TMF_RESP_FUNC_COMPLETE)
1052 /* Terminate all I/O now. */
1053 isci_terminate_pending_requests(isci_host,
1054 isci_device,
1055 terminating);
1056
Dan Williams6f231dd2011-07-02 22:56:22 -07001057 return ret;
1058}
1059
1060
1061/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1062int isci_task_clear_nexus_port(struct asd_sas_port *port)
1063{
1064 return TMF_RESP_FUNC_FAILED;
1065}
1066
1067
1068
1069int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
1070{
1071 return TMF_RESP_FUNC_FAILED;
1072}
1073
Dan Williams6f231dd2011-07-02 22:56:22 -07001074/* Task Management Functions. Must be called from process context. */
1075
1076/**
1077 * isci_abort_task_process_cb() - This is a helper function for the abort task
1078 * TMF command. It manages the request state with respect to the successful
1079 * transmission / completion of the abort task request.
1080 * @cb_state: This parameter specifies when this function was called - after
1081 * the TMF request has been started and after it has timed-out.
1082 * @tmf: This parameter specifies the TMF in progress.
1083 *
1084 *
1085 */
1086static void isci_abort_task_process_cb(
1087 enum isci_tmf_cb_state cb_state,
1088 struct isci_tmf *tmf,
1089 void *cb_data)
1090{
1091 struct isci_request *old_request;
1092
1093 old_request = (struct isci_request *)cb_data;
1094
1095 dev_dbg(&old_request->isci_host->pdev->dev,
1096 "%s: tmf=%p, old_request=%p\n",
1097 __func__, tmf, old_request);
1098
1099 switch (cb_state) {
1100
1101 case isci_tmf_started:
1102 /* The TMF has been started. Nothing to do here, since the
1103 * request state was already set to "aborted" by the abort
1104 * task function.
1105 */
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001106 if ((old_request->status != aborted)
1107 && (old_request->status != completed))
1108 dev_err(&old_request->isci_host->pdev->dev,
1109 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1110 __func__, old_request->status, tmf, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001111 break;
1112
1113 case isci_tmf_timed_out:
1114
1115 /* Set the task's state to "aborting", since the abort task
1116 * function thread set it to "aborted" (above) in anticipation
1117 * of the task management request working correctly. Since the
1118 * timeout has now fired, the TMF request failed. We set the
1119 * state such that the request completion will indicate the
1120 * device is no longer present.
1121 */
1122 isci_request_change_state(old_request, aborting);
1123 break;
1124
1125 default:
1126 dev_err(&old_request->isci_host->pdev->dev,
1127 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1128 __func__, cb_state, tmf, old_request);
1129 break;
1130 }
1131}
1132
1133/**
1134 * isci_task_abort_task() - This function is one of the SAS Domain Template
1135 * functions. This function is called by libsas to abort a specified task.
1136 * @task: This parameter specifies the SAS task to abort.
1137 *
1138 * status, zero indicates success.
1139 */
1140int isci_task_abort_task(struct sas_task *task)
1141{
Dan Williams4393aa42011-03-31 13:10:44 -07001142 struct isci_host *isci_host = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001143 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001144 struct isci_request *old_request = NULL;
1145 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -07001146 struct isci_remote_device *isci_device = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001147 struct isci_tmf tmf;
1148 int ret = TMF_RESP_FUNC_FAILED;
1149 unsigned long flags;
1150 bool any_dev_reset = false;
1151 bool device_stopping;
Dan Williams6f231dd2011-07-02 22:56:22 -07001152
1153 /* Get the isci_request reference from the task. Note that
1154 * this check does not depend on the pending request list
1155 * in the device, because tasks driving resets may land here
1156 * after completion in the core.
1157 */
Dan Williams4393aa42011-03-31 13:10:44 -07001158 old_request = isci_task_get_request_from_task(task, &isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001159
1160 dev_dbg(&isci_host->pdev->dev,
1161 "%s: task = %p\n", __func__, task);
1162
1163 /* Check if the device has been / is currently being removed.
1164 * If so, no task management will be done, and the I/O will
1165 * be terminated.
1166 */
1167 device_stopping = (isci_device->status == isci_stopping)
1168 || (isci_device->status == isci_stopped);
1169
Dan Williamsd06b4872011-05-02 13:59:25 -07001170 /* XXX need to fix device lookup lifetime (needs to be done
1171 * under scic_lock, among other things...), but for now assume
1172 * the device is available like the above code
1173 */
1174 set_bit(IDEV_EH, &isci_device->flags);
1175
Dan Williams6f231dd2011-07-02 22:56:22 -07001176 /* This version of the driver will fail abort requests for
1177 * SATA/STP. Failing the abort request this way will cause the
1178 * SCSI error handler thread to escalate to LUN reset
1179 */
1180 if (sas_protocol_ata(task->task_proto) && !device_stopping) {
1181 dev_warn(&isci_host->pdev->dev,
1182 " task %p is for a STP/SATA device;"
1183 " returning TMF_RESP_FUNC_FAILED\n"
1184 " to cause a LUN reset...\n", task);
1185 return TMF_RESP_FUNC_FAILED;
1186 }
1187
1188 dev_dbg(&isci_host->pdev->dev,
1189 "%s: old_request == %p\n", __func__, old_request);
1190
Jeff Skirvina5fde222011-03-04 14:06:42 -08001191 if (!device_stopping)
1192 any_dev_reset = isci_device_is_reset_pending(isci_host,isci_device);
1193
Dan Williams6f231dd2011-07-02 22:56:22 -07001194 spin_lock_irqsave(&task->task_state_lock, flags);
1195
1196 /* Don't do resets to stopping devices. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001197 if (device_stopping) {
1198
Dan Williams6f231dd2011-07-02 22:56:22 -07001199 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001200 any_dev_reset = false;
Dan Williams6f231dd2011-07-02 22:56:22 -07001201
Jeff Skirvina5fde222011-03-04 14:06:42 -08001202 } else /* See if there is a pending device reset for this device. */
Dan Williams6f231dd2011-07-02 22:56:22 -07001203 any_dev_reset = any_dev_reset
Jeff Skirvina5fde222011-03-04 14:06:42 -08001204 || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
Dan Williams6f231dd2011-07-02 22:56:22 -07001205
1206 /* If the extraction of the request reference from the task
1207 * failed, then the request has been completed (or if there is a
1208 * pending reset then this abort request function must be failed
1209 * in order to escalate to the target reset).
1210 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001211 if ((old_request == NULL) || any_dev_reset) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001212
1213 /* If the device reset task flag is set, fail the task
1214 * management request. Otherwise, the original request
1215 * has completed.
1216 */
1217 if (any_dev_reset) {
1218
1219 /* Turn off the task's DONE to make sure this
1220 * task is escalated to a target reset.
1221 */
1222 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1223
Jeff Skirvina5fde222011-03-04 14:06:42 -08001224 /* Make the reset happen as soon as possible. */
1225 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1226
1227 spin_unlock_irqrestore(&task->task_state_lock, flags);
1228
Dan Williams6f231dd2011-07-02 22:56:22 -07001229 /* Fail the task management request in order to
1230 * escalate to the target reset.
1231 */
1232 ret = TMF_RESP_FUNC_FAILED;
1233
1234 dev_dbg(&isci_host->pdev->dev,
1235 "%s: Failing task abort in order to "
1236 "escalate to target reset because\n"
1237 "SAS_TASK_NEED_DEV_RESET is set for "
1238 "task %p on dev %p\n",
1239 __func__, task, isci_device);
1240
Jeff Skirvina5fde222011-03-04 14:06:42 -08001241
Dan Williams6f231dd2011-07-02 22:56:22 -07001242 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -07001243 /* The request has already completed and there
1244 * is nothing to do here other than to set the task
1245 * done bit, and indicate that the task abort function
1246 * was sucessful.
1247 */
1248 isci_set_task_doneflags(task);
1249
Jeff Skirvina5fde222011-03-04 14:06:42 -08001250 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001251
Jeff Skirvina5fde222011-03-04 14:06:42 -08001252 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001253
Jeff Skirvina5fde222011-03-04 14:06:42 -08001254 dev_dbg(&isci_host->pdev->dev,
1255 "%s: abort task not needed for %p\n",
1256 __func__, task);
Dan Williams6f231dd2011-07-02 22:56:22 -07001257 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001258
1259 return ret;
1260 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001261 else
1262 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001263
1264 spin_lock_irqsave(&isci_host->scic_lock, flags);
1265
Jeff Skirvinf219f012011-03-31 13:10:34 -07001266 /* Check the request status and change to "aborted" if currently
Jeff Skirvina5fde222011-03-04 14:06:42 -08001267 * "starting"; if true then set the I/O kernel completion
Dan Williams6f231dd2011-07-02 22:56:22 -07001268 * struct that will be triggered when the request completes.
1269 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001270 old_state = isci_task_validate_request_to_abort(
1271 old_request, isci_host, isci_device,
1272 &aborted_io_completion);
Jeff Skirvinf219f012011-03-31 13:10:34 -07001273 if ((old_state != started) &&
1274 (old_state != completed) &&
1275 (old_state != aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001276
1277 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1278
Jeff Skirvina5fde222011-03-04 14:06:42 -08001279 /* The request was already being handled by someone else (because
1280 * they got to set the state away from started).
1281 */
1282 dev_dbg(&isci_host->pdev->dev,
1283 "%s: device = %p; old_request %p already being aborted\n",
1284 __func__,
1285 isci_device, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001286
1287 return TMF_RESP_FUNC_COMPLETE;
1288 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001289 if ((task->task_proto == SAS_PROTOCOL_SMP)
1290 || device_stopping
1291 || old_request->complete_in_target
1292 ) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001293
1294 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1295
Jeff Skirvina5fde222011-03-04 14:06:42 -08001296 dev_dbg(&isci_host->pdev->dev,
1297 "%s: SMP request (%d)"
1298 " or device is stopping (%d)"
1299 " or complete_in_target (%d), thus no TMF\n",
1300 __func__, (task->task_proto == SAS_PROTOCOL_SMP),
1301 device_stopping, old_request->complete_in_target);
1302
Dan Williams6f231dd2011-07-02 22:56:22 -07001303 /* Set the state on the task. */
1304 isci_task_all_done(task);
1305
1306 ret = TMF_RESP_FUNC_COMPLETE;
1307
1308 /* Stopping and SMP devices are not sent a TMF, and are not
Jeff Skirvina5fde222011-03-04 14:06:42 -08001309 * reset, but the outstanding I/O request is terminated below.
Dan Williams6f231dd2011-07-02 22:56:22 -07001310 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001311 } else {
1312 /* Fill in the tmf stucture */
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -08001313 isci_task_build_abort_task_tmf(&tmf, isci_device,
1314 isci_tmf_ssp_task_abort,
1315 isci_abort_task_process_cb,
1316 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001317
Dan Williams6f231dd2011-07-02 22:56:22 -07001318 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1319
1320 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1321 ret = isci_task_execute_tmf(isci_host, &tmf,
1322 ISCI_ABORT_TASK_TIMEOUT_MS);
1323
Jeff Skirvina5fde222011-03-04 14:06:42 -08001324 if (ret != TMF_RESP_FUNC_COMPLETE)
Dan Williams6f231dd2011-07-02 22:56:22 -07001325 dev_err(&isci_host->pdev->dev,
1326 "%s: isci_task_send_tmf failed\n",
1327 __func__);
1328 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001329 if (ret == TMF_RESP_FUNC_COMPLETE) {
1330 old_request->complete_in_target = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07001331
Jeff Skirvina5fde222011-03-04 14:06:42 -08001332 /* Clean up the request on our side, and wait for the aborted I/O to
1333 * complete.
1334 */
Jeff Skirvincbb65c62011-03-04 14:06:50 -08001335 isci_terminate_request_core(isci_host, isci_device, old_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001336 }
1337
1338 /* Make sure we do not leave a reference to aborted_io_completion */
1339 old_request->io_request_completion = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -07001340 return ret;
1341}
1342
1343/**
1344 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1345 * functions. This is one of the Task Management functoins called by libsas,
1346 * to abort all task for the given lun.
1347 * @d_device: This parameter specifies the domain device associated with this
1348 * request.
1349 * @lun: This parameter specifies the lun associated with this request.
1350 *
1351 * status, zero indicates success.
1352 */
1353int isci_task_abort_task_set(
1354 struct domain_device *d_device,
1355 u8 *lun)
1356{
1357 return TMF_RESP_FUNC_FAILED;
1358}
1359
1360
1361/**
1362 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1363 * functions. This is one of the Task Management functoins called by libsas.
1364 * @d_device: This parameter specifies the domain device associated with this
1365 * request.
1366 * @lun: This parameter specifies the lun associated with this request.
1367 *
1368 * status, zero indicates success.
1369 */
1370int isci_task_clear_aca(
1371 struct domain_device *d_device,
1372 u8 *lun)
1373{
1374 return TMF_RESP_FUNC_FAILED;
1375}
1376
1377
1378
1379/**
1380 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1381 * functions. This is one of the Task Management functoins called by libsas.
1382 * @d_device: This parameter specifies the domain device associated with this
1383 * request.
1384 * @lun: This parameter specifies the lun associated with this request.
1385 *
1386 * status, zero indicates success.
1387 */
1388int isci_task_clear_task_set(
1389 struct domain_device *d_device,
1390 u8 *lun)
1391{
1392 return TMF_RESP_FUNC_FAILED;
1393}
1394
1395
1396/**
1397 * isci_task_query_task() - This function is implemented to cause libsas to
1398 * correctly escalate the failed abort to a LUN or target reset (this is
1399 * because sas_scsi_find_task libsas function does not correctly interpret
1400 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1401 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1402 * returned, libsas will turn this into a target reset
1403 * @task: This parameter specifies the sas task being queried.
1404 * @lun: This parameter specifies the lun associated with this request.
1405 *
1406 * status, zero indicates success.
1407 */
1408int isci_task_query_task(
1409 struct sas_task *task)
1410{
1411 /* See if there is a pending device reset for this device. */
1412 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1413 return TMF_RESP_FUNC_FAILED;
1414 else
1415 return TMF_RESP_FUNC_SUCC;
1416}
1417
Dave Jiangaf5ae892011-05-04 17:53:24 -07001418/*
Dan Williams6f231dd2011-07-02 22:56:22 -07001419 * isci_task_request_complete() - This function is called by the sci core when
1420 * an task request completes.
Dave Jiangaf5ae892011-05-04 17:53:24 -07001421 * @ihost: This parameter specifies the ISCI host object
1422 * @ireq: This parameter is the completed isci_request object.
Dan Williams6f231dd2011-07-02 22:56:22 -07001423 * @completion_status: This parameter specifies the completion status from the
1424 * sci core.
1425 *
1426 * none.
1427 */
Dave Jiangaf5ae892011-05-04 17:53:24 -07001428void
1429isci_task_request_complete(struct isci_host *ihost,
1430 struct isci_request *ireq,
1431 enum sci_task_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -07001432{
Dave Jiangaf5ae892011-05-04 17:53:24 -07001433 struct isci_remote_device *idev = ireq->isci_device;
Dan Williams6f231dd2011-07-02 22:56:22 -07001434 enum isci_request_status old_state;
Dave Jiangaf5ae892011-05-04 17:53:24 -07001435 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
Dan Williams6f231dd2011-07-02 22:56:22 -07001436 struct completion *tmf_complete;
Dave Jiangaf5ae892011-05-04 17:53:24 -07001437 struct scic_sds_request *sci_req = ireq->sci_request_handle;
1438 struct scic_sds_stp_request *stp_req =
1439 container_of(sci_req, typeof(*stp_req), parent);
Dan Williams6f231dd2011-07-02 22:56:22 -07001440
Dave Jiangaf5ae892011-05-04 17:53:24 -07001441 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001442 "%s: request = %p, status=%d\n",
Dave Jiangaf5ae892011-05-04 17:53:24 -07001443 __func__, ireq, completion_status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001444
Dave Jiangaf5ae892011-05-04 17:53:24 -07001445 old_state = isci_request_change_state(ireq, completed);
Dan Williams6f231dd2011-07-02 22:56:22 -07001446
1447 tmf->status = completion_status;
Dave Jiangaf5ae892011-05-04 17:53:24 -07001448 ireq->complete_in_target = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07001449
Dave Jiangaf5ae892011-05-04 17:53:24 -07001450 if (tmf->proto == SAS_PROTOCOL_SSP) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001451 memcpy(&tmf->resp.resp_iu,
Dave Jiangaf5ae892011-05-04 17:53:24 -07001452 sci_req->response_buffer,
1453 SSP_RESP_IU_MAX_SIZE);
1454 } else if (tmf->proto == SAS_PROTOCOL_SATA) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001455 memcpy(&tmf->resp.d2h_fis,
Dave Jiangaf5ae892011-05-04 17:53:24 -07001456 &stp_req->d2h_reg_fis,
Dave Jiangf2f30082011-05-04 15:02:02 -07001457 sizeof(struct dev_to_host_fis));
Dan Williams6f231dd2011-07-02 22:56:22 -07001458 }
1459
1460 /* Manage the timer if it is still running. */
1461 if (tmf->timeout_timer) {
Dave Jiangaf5ae892011-05-04 17:53:24 -07001462 isci_del_timer(ihost, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -07001463 tmf->timeout_timer = NULL;
1464 }
1465
1466 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1467 tmf_complete = tmf->complete;
1468
Dave Jiangaf5ae892011-05-04 17:53:24 -07001469 scic_controller_complete_io(ihost->core_controller,
1470 &idev->sci,
1471 ireq->sci_request_handle);
1472
1473 /*
1474 * NULL the request handle to make sure it cannot be terminated
Dan Williams6f231dd2011-07-02 22:56:22 -07001475 * or completed again.
1476 */
Dave Jiangaf5ae892011-05-04 17:53:24 -07001477 ireq->sci_request_handle = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -07001478
Dave Jiangaf5ae892011-05-04 17:53:24 -07001479 isci_request_change_state(ireq, unallocated);
1480 list_del_init(&ireq->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -07001481
1482 /* The task management part completes last. */
1483 complete(tmf_complete);
1484}
1485
Dan Williamsd06b4872011-05-02 13:59:25 -07001486static int isci_reset_device(struct domain_device *dev, int hard_reset)
Dan Williams6f231dd2011-07-02 22:56:22 -07001487{
Dan Williamsd06b4872011-05-02 13:59:25 -07001488 struct isci_remote_device *idev = dev->lldd_dev;
1489 struct sas_phy *phy = sas_find_local_phy(dev);
1490 struct isci_host *ihost = dev_to_ihost(dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001491 enum sci_status status;
Dan Williamsd06b4872011-05-02 13:59:25 -07001492 unsigned long flags;
1493 int rc;
Dan Williams6f231dd2011-07-02 22:56:22 -07001494
Dan Williamsd06b4872011-05-02 13:59:25 -07001495 dev_dbg(&ihost->pdev->dev, "%s: idev %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001496
Dan Williamsd06b4872011-05-02 13:59:25 -07001497 if (!idev) {
1498 dev_warn(&ihost->pdev->dev,
1499 "%s: idev is GONE!\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07001500 __func__);
1501
1502 return TMF_RESP_FUNC_COMPLETE; /* Nothing to reset. */
1503 }
1504
Dan Williamsd06b4872011-05-02 13:59:25 -07001505 spin_lock_irqsave(&ihost->scic_lock, flags);
1506 status = scic_remote_device_reset(&idev->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07001507 if (status != SCI_SUCCESS) {
Dan Williamsd06b4872011-05-02 13:59:25 -07001508 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001509
Dan Williamsd06b4872011-05-02 13:59:25 -07001510 dev_warn(&ihost->pdev->dev,
1511 "%s: scic_remote_device_reset(%p) returned %d!\n",
1512 __func__, idev, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001513
1514 return TMF_RESP_FUNC_FAILED;
1515 }
Dan Williamsd06b4872011-05-02 13:59:25 -07001516 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001517
Dan Williams6f231dd2011-07-02 22:56:22 -07001518 /* Make sure all pending requests are able to be fully terminated. */
Dan Williamsd06b4872011-05-02 13:59:25 -07001519 isci_device_clear_reset_pending(ihost, idev);
1520
1521 rc = sas_phy_reset(phy, hard_reset);
1522 msleep(2000); /* just like mvsas */
Dan Williams6f231dd2011-07-02 22:56:22 -07001523
1524 /* Terminate in-progress I/O now. */
Dan Williamsd06b4872011-05-02 13:59:25 -07001525 isci_remote_device_nuke_requests(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001526
Dan Williamsd06b4872011-05-02 13:59:25 -07001527 spin_lock_irqsave(&ihost->scic_lock, flags);
1528 status = scic_remote_device_reset_complete(&idev->sci);
1529 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001530
1531 if (status != SCI_SUCCESS) {
Dan Williamsd06b4872011-05-02 13:59:25 -07001532 dev_warn(&ihost->pdev->dev,
1533 "%s: scic_remote_device_reset_complete(%p) "
1534 "returned %d!\n", __func__, idev, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07001535 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001536
Dan Williamsd06b4872011-05-02 13:59:25 -07001537 dev_dbg(&ihost->pdev->dev, "%s: idev %p complete.\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001538
Dan Williamsd06b4872011-05-02 13:59:25 -07001539 return rc;
1540}
1541
1542int isci_task_I_T_nexus_reset(struct domain_device *dev)
1543{
1544 struct isci_host *ihost = dev_to_ihost(dev);
1545 int ret = TMF_RESP_FUNC_FAILED, hard_reset = 1;
1546 struct isci_remote_device *idev;
1547 unsigned long flags;
1548
1549 /* XXX mvsas is not protecting against ->lldd_dev_gone(), are we
1550 * being too paranoid, or is mvsas busted?!
1551 */
1552 spin_lock_irqsave(&ihost->scic_lock, flags);
1553 idev = dev->lldd_dev;
1554 if (!idev || !test_bit(IDEV_EH, &idev->flags))
1555 ret = TMF_RESP_FUNC_COMPLETE;
1556 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1557
1558 if (ret == TMF_RESP_FUNC_COMPLETE)
1559 return ret;
1560
1561 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
1562 hard_reset = 0;
1563
1564 return isci_reset_device(dev, hard_reset);
1565}
1566
1567int isci_bus_reset_handler(struct scsi_cmnd *cmd)
1568{
1569 struct domain_device *dev = sdev_to_domain_dev(cmd->device);
1570 int hard_reset = 1;
1571
1572 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
1573 hard_reset = 0;
1574
1575 return isci_reset_device(dev, hard_reset);
Dan Williams6f231dd2011-07-02 22:56:22 -07001576}