blob: c0ed1b28f3e56b45b42d765ca716c778d14e980c [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>
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "scic_task_request.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070059#include "scic_io_request.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"
64#include "sata.h"
65#include "task.h"
66
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) {
Dan Williams50e7f9b2011-03-09 21:27:46 -080091 case isci_perform_normal_io_completion:
92 /* Normal notification (task_done) */
Dan Williams1077a572011-03-11 10:13:51 -080093 dev_dbg(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -070094 "%s: Normal - task = %p, response=%d, "
95 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -080096 __func__, task, response, status);
97
Dan Williams1077a572011-03-11 10:13:51 -080098 task->lldd_task = NULL;
Dan Williams50e7f9b2011-03-09 21:27:46 -080099
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700100 isci_execpath_callback(ihost, task, task->task_done);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800101 break;
102
103 case isci_perform_aborted_io_completion:
104 /* No notification because this request is already in the
105 * abort path.
106 */
Dan Williams1077a572011-03-11 10:13:51 -0800107 dev_warn(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700108 "%s: Aborted - task = %p, response=%d, "
109 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -0800110 __func__, task, response, status);
111 break;
112
113 case isci_perform_error_io_completion:
114 /* Use sas_task_abort */
Dan Williams1077a572011-03-11 10:13:51 -0800115 dev_warn(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700116 "%s: Error - task = %p, response=%d, "
117 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -0800118 __func__, task, response, status);
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700119
120 isci_execpath_callback(ihost, task, sas_task_abort);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800121 break;
122
123 default:
Dan Williams1077a572011-03-11 10:13:51 -0800124 dev_warn(&ihost->pdev->dev,
Dan Williams50e7f9b2011-03-09 21:27:46 -0800125 "%s: isci task notification default case!",
126 __func__);
127 sas_task_abort(task);
128 break;
129 }
130}
Dan Williams6f231dd2011-07-02 22:56:22 -0700131
Dan Williams1077a572011-03-11 10:13:51 -0800132#define for_each_sas_task(num, task) \
133 for (; num > 0; num--,\
134 task = list_entry(task->list.next, struct sas_task, list))
135
Dan Williams6f231dd2011-07-02 22:56:22 -0700136/**
137 * isci_task_execute_task() - This function is one of the SAS Domain Template
138 * functions. This function is called by libsas to send a task down to
139 * hardware.
140 * @task: This parameter specifies the SAS task to send.
141 * @num: This parameter specifies the number of tasks to queue.
142 * @gfp_flags: This parameter specifies the context of this call.
143 *
144 * status, zero indicates success.
145 */
146int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags)
147{
Dan Williams4393aa42011-03-31 13:10:44 -0700148 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700149 struct isci_request *request = NULL;
150 struct isci_remote_device *device;
151 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700152 int ret;
153 enum sci_status status;
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700154 enum isci_status device_status;
Dan Williams6f231dd2011-07-02 22:56:22 -0700155
Dan Williams1077a572011-03-11 10:13:51 -0800156 dev_dbg(&ihost->pdev->dev, "%s: num=%d\n", __func__, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700157
158 /* Check if we have room for more tasks */
Dan Williams1077a572011-03-11 10:13:51 -0800159 ret = isci_host_can_queue(ihost, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700160
161 if (ret) {
Dan Williams1077a572011-03-11 10:13:51 -0800162 dev_warn(&ihost->pdev->dev, "%s: queue full\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -0700163 return ret;
164 }
165
Dan Williams1077a572011-03-11 10:13:51 -0800166 for_each_sas_task(num, task) {
167 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700168 "task = %p, num = %d; dev = %p; cmd = %p\n",
169 task, num, task->dev, task->uldd_task);
170
Dan Williams4393aa42011-03-31 13:10:44 -0700171 device = task->dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700172
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700173 if (device)
174 device_status = device->status;
175 else
176 device_status = isci_freed;
177
178 /* From this point onward, any process that needs to guarantee
179 * that there is no kernel I/O being started will have to wait
180 * for the quiesce spinlock.
181 */
182
183 if (device_status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700184
185 /* Forces a retry from scsi mid layer. */
Dave Jiangd2d61432011-04-21 05:36:23 +0000186 dev_dbg(&ihost->pdev->dev,
187 "%s: task %p: isci_host->status = %d, "
188 "device = %p; device_status = 0x%x\n\n",
189 __func__,
190 task,
191 isci_host_get_state(ihost),
192 device,
193 device_status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700194
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700195 if (device_status == isci_ready) {
196 /* Indicate QUEUE_FULL so that the scsi midlayer
197 * retries.
198 */
Dan Williams1077a572011-03-11 10:13:51 -0800199 isci_task_refuse(ihost, task,
200 SAS_TASK_COMPLETE,
201 SAS_QUEUE_FULL);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700202 } else {
203 /* Else, the device is going down. */
Dan Williams1077a572011-03-11 10:13:51 -0800204 isci_task_refuse(ihost, task,
205 SAS_TASK_UNDELIVERED,
206 SAS_DEVICE_UNKNOWN);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700207 }
Dan Williams1077a572011-03-11 10:13:51 -0800208 isci_host_can_dequeue(ihost, 1);
Dan Williams6f231dd2011-07-02 22:56:22 -0700209 } else {
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700210 /* There is a device and it's ready for I/O. */
211 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700212
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700213 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
214
215 spin_unlock_irqrestore(&task->task_state_lock,
216 flags);
217
Dan Williams1077a572011-03-11 10:13:51 -0800218 isci_task_refuse(ihost, task,
219 SAS_TASK_UNDELIVERED,
220 SAM_STAT_TASK_ABORTED);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700221
222 /* The I/O was aborted. */
223
224 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700225 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
226 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700227
228 /* build and send the request. */
Dan Williams1077a572011-03-11 10:13:51 -0800229 status = isci_request_execute(ihost, task, &request,
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700230 gfp_flags);
231
232 if (status != SCI_SUCCESS) {
233
234 spin_lock_irqsave(&task->task_state_lock, flags);
235 /* Did not really start this command. */
236 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
237 spin_unlock_irqrestore(&task->task_state_lock, flags);
238
239 /* Indicate QUEUE_FULL so that the scsi
240 * midlayer retries. if the request
241 * failed for remote device reasons,
242 * it gets returned as
243 * SAS_TASK_UNDELIVERED next time
244 * through.
245 */
Dan Williams1077a572011-03-11 10:13:51 -0800246 isci_task_refuse(ihost, task,
247 SAS_TASK_COMPLETE,
248 SAS_QUEUE_FULL);
249 isci_host_can_dequeue(ihost, 1);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700250 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700251 }
252 }
Dan Williams1077a572011-03-11 10:13:51 -0800253 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700254 return 0;
255}
256
257
258
259/**
260 * isci_task_request_build() - This function builds the task request object.
261 * @isci_host: This parameter specifies the ISCI host object
262 * @request: This parameter points to the isci_request object allocated in the
263 * request construct function.
264 * @tmf: This parameter is the task management struct to be built
265 *
266 * SCI_SUCCESS on successfull completion, or specific failure code.
267 */
268static enum sci_status isci_task_request_build(
269 struct isci_host *isci_host,
270 struct isci_request **isci_request,
271 struct isci_tmf *isci_tmf)
272{
273 struct scic_sds_remote_device *sci_device;
274 enum sci_status status = SCI_FAILURE;
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700275 struct isci_request *request = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700276 struct isci_remote_device *isci_device;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700277 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700278
279 dev_dbg(&isci_host->pdev->dev,
280 "%s: isci_tmf = %p\n", __func__, isci_tmf);
281
282 isci_device = isci_tmf->device;
Dan Williams57f20f42011-04-21 18:14:45 -0700283 sci_device = &isci_device->sci;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700284 dev = isci_device->domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700285
286 /* do common allocation and init of request object. */
287 status = isci_request_alloc_tmf(
288 isci_host,
289 isci_tmf,
290 &request,
291 isci_device,
292 GFP_ATOMIC
293 );
294
295 if (status != SCI_SUCCESS)
296 goto out;
297
298 /* let the core do it's construct. */
299 status = scic_task_request_construct(
300 isci_host->core_controller,
301 sci_device,
302 SCI_CONTROLLER_INVALID_IO_TAG,
303 request,
304 request->sci_request_mem_ptr,
305 &request->sci_request_handle
306 );
307
308 if (status != SCI_SUCCESS) {
309 dev_warn(&isci_host->pdev->dev,
310 "%s: scic_task_request_construct failed - "
311 "status = 0x%x\n",
312 __func__,
313 status);
314 goto errout;
315 }
316
317 sci_object_set_association(
318 request->sci_request_handle,
319 request
320 );
321
Dan Williamsa1a113b2011-04-21 18:44:45 -0700322 /* XXX convert to get this from task->tproto like other drivers */
323 if (dev->dev_type == SAS_END_DEV) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700324 isci_tmf->proto = SAS_PROTOCOL_SSP;
325 status = scic_task_request_construct_ssp(
326 request->sci_request_handle
327 );
328 if (status != SCI_SUCCESS)
329 goto errout;
330 }
331
Dan Williamsa1a113b2011-04-21 18:44:45 -0700332 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700333 isci_tmf->proto = SAS_PROTOCOL_SATA;
334 status = isci_sata_management_task_request_build(request);
335
336 if (status != SCI_SUCCESS)
337 goto errout;
338 }
339
340 goto out;
341
342 errout:
343
344 /* release the dma memory if we fail. */
345 isci_request_free(isci_host, request);
346 request = NULL;
347
348 out:
349 *isci_request = request;
350 return status;
351}
352
353/**
354 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
355 * the timeout period for the TMF has expired.
356 *
357 *
358 */
359static void isci_tmf_timeout_cb(void *tmf_request_arg)
360{
361 struct isci_request *request = (struct isci_request *)tmf_request_arg;
362 struct isci_tmf *tmf = isci_request_access_tmf(request);
363 enum sci_status status;
364
Dan Williams6f231dd2011-07-02 22:56:22 -0700365 /* This task management request has timed-out. Terminate the request
366 * so that the request eventually completes to the requestor in the
367 * request completion callback path.
368 */
369 /* Note - the timer callback function itself has provided spinlock
370 * exclusion from the start and completion paths. No need to take
371 * the request->isci_host->scic_lock here.
372 */
373
374 if (tmf->timeout_timer != NULL) {
375 /* Call the users callback, if any. */
376 if (tmf->cb_state_func != NULL)
377 tmf->cb_state_func(isci_tmf_timed_out, tmf,
378 tmf->cb_data);
379
380 /* Terminate the TMF transmit request. */
381 status = scic_controller_terminate_request(
382 request->isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700383 &request->isci_device->sci,
Dan Williams6f231dd2011-07-02 22:56:22 -0700384 request->sci_request_handle
385 );
386
387 dev_dbg(&request->isci_host->pdev->dev,
388 "%s: tmf_request = %p; tmf = %p; status = %d\n",
389 __func__, request, tmf, status);
390 } else
391 dev_dbg(&request->isci_host->pdev->dev,
392 "%s: timer already canceled! "
393 "tmf_request = %p; tmf = %p\n",
394 __func__, request, tmf);
395
396 /* No need to unlock since the caller to this callback is doing it for
397 * us.
398 * request->isci_host->scic_lock
399 */
400}
401
402/**
403 * isci_task_execute_tmf() - This function builds and sends a task request,
404 * then waits for the completion.
405 * @isci_host: This parameter specifies the ISCI host object
406 * @tmf: This parameter is the pointer to the task management structure for
407 * this request.
408 * @timeout_ms: This parameter specifies the timeout period for the task
409 * management request.
410 *
411 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
412 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
413 */
414int isci_task_execute_tmf(
415 struct isci_host *isci_host,
416 struct isci_tmf *tmf,
417 unsigned long timeout_ms)
418{
419 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700420 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700421 struct scic_sds_remote_device *sci_device;
422 struct isci_remote_device *isci_device = tmf->device;
423 struct isci_request *request;
424 int ret = TMF_RESP_FUNC_FAILED;
425 unsigned long flags;
426
427 /* sanity check, return TMF_RESP_FUNC_FAILED
428 * if the device is not there and ready.
429 */
Dan Williams8acaec12011-03-07 14:47:35 -0800430 if (!isci_device || isci_device->status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700431 dev_dbg(&isci_host->pdev->dev,
432 "%s: isci_device = %p not ready (%d)\n",
433 __func__,
Dan Williams8acaec12011-03-07 14:47:35 -0800434 isci_device, isci_device->status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700435 return TMF_RESP_FUNC_FAILED;
436 } else
437 dev_dbg(&isci_host->pdev->dev,
438 "%s: isci_device = %p\n",
439 __func__, isci_device);
440
Dan Williams57f20f42011-04-21 18:14:45 -0700441 sci_device = &isci_device->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700442
443 /* Assign the pointer to the TMF's completion kernel wait structure. */
444 tmf->complete = &completion;
445
446 isci_task_request_build(
447 isci_host,
448 &request,
449 tmf
450 );
451
452 if (!request) {
453 dev_warn(&isci_host->pdev->dev,
454 "%s: isci_task_request_build failed\n",
455 __func__);
456 return TMF_RESP_FUNC_FAILED;
457 }
458
459 /* Allocate the TMF timeout timer. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700460 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800461 tmf->timeout_timer = isci_timer_create(isci_host, request, isci_tmf_timeout_cb);
Dan Williams6f231dd2011-07-02 22:56:22 -0700462
463 /* Start the timer. */
464 if (tmf->timeout_timer)
465 isci_timer_start(tmf->timeout_timer, timeout_ms);
466 else
467 dev_warn(&isci_host->pdev->dev,
468 "%s: isci_timer_create failed!!!!\n",
469 __func__);
470
471 /* start the TMF io. */
472 status = scic_controller_start_task(
473 isci_host->core_controller,
474 sci_device,
475 request->sci_request_handle,
476 SCI_CONTROLLER_INVALID_IO_TAG
477 );
478
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700479 if (status != SCI_TASK_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700480 dev_warn(&isci_host->pdev->dev,
481 "%s: start_io failed - status = 0x%x, request = %p\n",
482 __func__,
483 status,
484 request);
485 goto cleanup_request;
486 }
487
488 /* Call the users callback, if any. */
489 if (tmf->cb_state_func != NULL)
490 tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data);
491
492 /* Change the state of the TMF-bearing request to "started". */
493 isci_request_change_state(request, started);
494
495 /* add the request to the remote device request list. */
496 list_add(&request->dev_node, &isci_device->reqs_in_process);
497
498 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
499
500 /* Wait for the TMF to complete, or a timeout. */
501 wait_for_completion(&completion);
502
503 isci_print_tmf(tmf);
504
505 if (tmf->status == SCI_SUCCESS)
506 ret = TMF_RESP_FUNC_COMPLETE;
507 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
508 dev_dbg(&isci_host->pdev->dev,
509 "%s: tmf.status == "
510 "SCI_FAILURE_IO_RESPONSE_VALID\n",
511 __func__);
512 ret = TMF_RESP_FUNC_COMPLETE;
513 }
514 /* Else - leave the default "failed" status alone. */
515
516 dev_dbg(&isci_host->pdev->dev,
517 "%s: completed request = %p\n",
518 __func__,
519 request);
520
521 if (request->io_request_completion != NULL) {
522
523 /* The fact that this is non-NULL for a TMF request
524 * means there is a thread waiting for this TMF to
525 * finish.
526 */
527 complete(request->io_request_completion);
528 }
529
530 spin_lock_irqsave(&isci_host->scic_lock, flags);
531
532 cleanup_request:
533
534 /* Clean up the timer if needed. */
535 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -0800536 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -0700537 tmf->timeout_timer = NULL;
538 }
539
540 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
541
542 isci_request_free(isci_host, request);
543
544 return ret;
545}
546
547void isci_task_build_tmf(
548 struct isci_tmf *tmf,
549 struct isci_remote_device *isci_device,
550 enum isci_tmf_function_codes code,
551 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
552 struct isci_tmf *,
553 void *),
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800554 void *cb_data)
Dan Williams6f231dd2011-07-02 22:56:22 -0700555{
556 dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
557 "%s: isci_device = %p\n", __func__, isci_device);
558
559 memset(tmf, 0, sizeof(*tmf));
560
561 tmf->device = isci_device;
562 tmf->tmf_code = code;
563 tmf->timeout_timer = NULL;
564 tmf->cb_state_func = tmf_sent_cb;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800565 tmf->cb_data = cb_data;
566}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800567
Dan Williams35173d52011-03-26 16:43:01 -0700568static void isci_task_build_abort_task_tmf(
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800569 struct isci_tmf *tmf,
570 struct isci_remote_device *isci_device,
571 enum isci_tmf_function_codes code,
572 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
573 struct isci_tmf *,
574 void *),
575 struct isci_request *old_request)
576{
577 isci_task_build_tmf(tmf, isci_device, code, tmf_sent_cb,
578 (void *)old_request);
579 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700580}
581
582static struct isci_request *isci_task_get_request_from_task(
583 struct sas_task *task,
Dan Williams6f231dd2011-07-02 22:56:22 -0700584 struct isci_remote_device **isci_device)
585{
586
587 struct isci_request *request = NULL;
588 unsigned long flags;
589
590 spin_lock_irqsave(&task->task_state_lock, flags);
591
592 request = task->lldd_task;
593
594 /* If task is already done, the request isn't valid */
595 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
596 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
597 (request != NULL)) {
598
Dan Williams6f231dd2011-07-02 22:56:22 -0700599 if (isci_device != NULL)
600 *isci_device = request->isci_device;
601 }
602
603 spin_unlock_irqrestore(&task->task_state_lock, flags);
604
605 return request;
606}
607
608/**
609 * isci_task_validate_request_to_abort() - This function checks the given I/O
610 * against the "started" state. If the request is still "started", it's
611 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
612 * BEFORE CALLING THIS FUNCTION.
613 * @isci_request: This parameter specifies the request object to control.
614 * @isci_host: This parameter specifies the ISCI host object
615 * @isci_device: This is the device to which the request is pending.
616 * @aborted_io_completion: This is a completion structure that will be added to
617 * the request in case it is changed to aborting; this completion is
618 * triggered when the request is fully completed.
619 *
620 * Either "started" on successful change of the task status to "aborted", or
621 * "unallocated" if the task cannot be controlled.
622 */
623static enum isci_request_status isci_task_validate_request_to_abort(
624 struct isci_request *isci_request,
625 struct isci_host *isci_host,
626 struct isci_remote_device *isci_device,
627 struct completion *aborted_io_completion)
628{
629 enum isci_request_status old_state = unallocated;
630
631 /* Only abort the task if it's in the
632 * device's request_in_process list
633 */
634 if (isci_request && !list_empty(&isci_request->dev_node)) {
635 old_state = isci_request_change_started_to_aborted(
636 isci_request, aborted_io_completion);
637
Dan Williams6f231dd2011-07-02 22:56:22 -0700638 }
639
640 return old_state;
641}
642
643static void isci_request_cleanup_completed_loiterer(
644 struct isci_host *isci_host,
645 struct isci_remote_device *isci_device,
646 struct isci_request *isci_request)
647{
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800648 struct sas_task *task;
649 unsigned long flags;
650
651 task = (isci_request->ttype == io_task)
652 ? isci_request_access_task(isci_request)
653 : NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700654
655 dev_dbg(&isci_host->pdev->dev,
656 "%s: isci_device=%p, request=%p, task=%p\n",
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800657 __func__, isci_device, isci_request, task);
Dan Williams6f231dd2011-07-02 22:56:22 -0700658
659 spin_lock_irqsave(&isci_host->scic_lock, flags);
660 list_del_init(&isci_request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700661 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
662
Jeff Skirvina5fde222011-03-04 14:06:42 -0800663 if (task != NULL) {
664
665 spin_lock_irqsave(&task->task_state_lock, flags);
666 task->lldd_task = NULL;
667
668 isci_set_task_doneflags(task);
669
670 /* If this task is not in the abort path, call task_done. */
671 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
672
673 spin_unlock_irqrestore(&task->task_state_lock, flags);
674 task->task_done(task);
675 } else
676 spin_unlock_irqrestore(&task->task_state_lock, flags);
677 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700678 isci_request_free(isci_host, isci_request);
679}
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800680
681/**
682* @isci_termination_timed_out(): this function will deal with a request for
683* which the wait for termination has timed-out.
684*
685* @isci_host This SCU.
686* @isci_request The I/O request being terminated.
687*/
688static void
689isci_termination_timed_out(
690 struct isci_host * host,
691 struct isci_request * request
692 )
693{
694 unsigned long state_flags;
695
696 dev_warn(&host->pdev->dev,
697 "%s: host = %p; request = %p\n",
698 __func__, host, request);
699
700 /* At this point, the request to terminate
701 * has timed out. The best we can do is to
702 * have the request die a silent death
703 * if it ever completes.
704 */
705 spin_lock_irqsave(&request->state_lock, state_flags);
706
707 if (request->status == started) {
708
709 /* Set the request state to "dead",
710 * and clear the task pointer so that an actual
711 * completion event callback doesn't do
712 * anything.
713 */
714 request->status = dead;
715
716 /* Clear the timeout completion event pointer.*/
717 request->io_request_completion = NULL;
718
719 if (request->ttype == io_task) {
720
721 /* Break links with the sas_task. */
722 if (request->ttype_ptr.io_task_ptr != NULL) {
723
724 request->ttype_ptr.io_task_ptr->lldd_task = NULL;
725 request->ttype_ptr.io_task_ptr = NULL;
726 }
727 }
728 }
729 spin_unlock_irqrestore(&request->state_lock, state_flags);
730}
731
732
Dan Williams6f231dd2011-07-02 22:56:22 -0700733/**
734 * isci_terminate_request_core() - This function will terminate the given
735 * request, and wait for it to complete. This function must only be called
736 * from a thread that can wait. Note that the request is terminated and
737 * completed (back to the host, if started there).
738 * @isci_host: This SCU.
739 * @isci_device: The target.
740 * @isci_request: The I/O request to be terminated.
741 *
742 *
743 */
744static void isci_terminate_request_core(
745 struct isci_host *isci_host,
746 struct isci_remote_device *isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800747 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700748{
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800749 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700750 bool was_terminated = false;
751 bool needs_cleanup_handling = false;
752 enum isci_request_status request_status;
753 unsigned long flags;
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800754 unsigned long timeout_remaining;
755
Dan Williams6f231dd2011-07-02 22:56:22 -0700756
757 dev_dbg(&isci_host->pdev->dev,
758 "%s: device = %p; request = %p\n",
759 __func__, isci_device, isci_request);
760
Dan Williams6f231dd2011-07-02 22:56:22 -0700761 spin_lock_irqsave(&isci_host->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800762
763 /* Note that we are not going to control
764 * the target to abort the request.
765 */
766 isci_request->complete_in_target = true;
767
Dan Williams6f231dd2011-07-02 22:56:22 -0700768 /* Make sure the request wasn't just sitting around signalling
769 * device condition (if the request handle is NULL, then the
770 * request completed but needed additional handling here).
771 */
772 if (isci_request->sci_request_handle != NULL) {
773 was_terminated = true;
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800774 needs_cleanup_handling = true;
Dan Williams6f231dd2011-07-02 22:56:22 -0700775 status = scic_controller_terminate_request(
776 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700777 &isci_device->sci,
778 isci_request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -0700779 }
780 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
781
782 /*
783 * The only time the request to terminate will
784 * fail is when the io request is completed and
785 * being aborted.
786 */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800787 if (status != SCI_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700788 dev_err(&isci_host->pdev->dev,
789 "%s: scic_controller_terminate_request"
790 " returned = 0x%x\n",
791 __func__,
792 status);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800793 /* Clear the completion pointer from the request. */
794 isci_request->io_request_completion = NULL;
795
796 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700797 if (was_terminated) {
798 dev_dbg(&isci_host->pdev->dev,
799 "%s: before completion wait (%p)\n",
800 __func__,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800801 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700802
803 /* Wait here for the request to complete. */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800804 #define TERMINATION_TIMEOUT_MSEC 50
805 timeout_remaining
806 = wait_for_completion_timeout(
807 isci_request->io_request_completion,
808 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC));
Dan Williams6f231dd2011-07-02 22:56:22 -0700809
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800810 if (!timeout_remaining) {
811
812 isci_termination_timed_out(isci_host,
813 isci_request);
814
815 dev_err(&isci_host->pdev->dev,
816 "%s: *** Timeout waiting for "
817 "termination(%p/%p)\n",
818 __func__,
819 isci_request->io_request_completion,
820 isci_request);
821
822 } else
823 dev_dbg(&isci_host->pdev->dev,
824 "%s: after completion wait (%p)\n",
825 __func__,
826 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700827 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800828 /* Clear the completion pointer from the request. */
829 isci_request->io_request_completion = NULL;
830
831 /* Peek at the status of the request. This will tell
832 * us if there was special handling on the request such that it
833 * needs to be detached and freed here.
834 */
835 spin_lock_irqsave(&isci_request->state_lock, flags);
836 request_status = isci_request_get_state(isci_request);
837
838 if ((isci_request->ttype == io_task) /* TMFs are in their own thread */
839 && ((request_status == aborted)
840 || (request_status == aborting)
841 || (request_status == terminating)
842 || (request_status == completed)
843 || (request_status == dead)
844 )
845 ) {
846
847 /* The completion routine won't free a request in
848 * the aborted/aborting/etc. states, so we do
849 * it here.
850 */
851 needs_cleanup_handling = true;
852 }
853 spin_unlock_irqrestore(&isci_request->state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700854
855 if (needs_cleanup_handling)
856 isci_request_cleanup_completed_loiterer(
857 isci_host, isci_device, isci_request
858 );
859 }
860}
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800861
Dan Williams6f231dd2011-07-02 22:56:22 -0700862static void isci_terminate_request(
863 struct isci_host *isci_host,
864 struct isci_remote_device *isci_device,
865 struct isci_request *isci_request,
866 enum isci_request_status new_request_state)
867{
868 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -0700869 DECLARE_COMPLETION_ONSTACK(request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700870
871 /* Change state to "new_request_state" if it is currently "started" */
872 old_state = isci_request_change_started_to_newstate(
873 isci_request,
874 &request_completion,
875 new_request_state
876 );
877
Jeff Skirvinf219f012011-03-31 13:10:34 -0700878 if ((old_state == started) ||
879 (old_state == completed) ||
880 (old_state == aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700881
Jeff Skirvina5fde222011-03-04 14:06:42 -0800882 /* If the old_state is started:
883 * This request was not already being aborted. If it had been,
Dan Williams6f231dd2011-07-02 22:56:22 -0700884 * then the aborting I/O (ie. the TMF request) would not be in
885 * the aborting state, and thus would be terminated here. Note
886 * that since the TMF completion's call to the kernel function
887 * "complete()" does not happen until the pending I/O request
888 * terminate fully completes, we do not have to implement a
889 * special wait here for already aborting requests - the
890 * termination of the TMF request will force the request
891 * to finish it's already started terminate.
Jeff Skirvina5fde222011-03-04 14:06:42 -0800892 *
893 * If old_state == completed:
894 * This request completed from the SCU hardware perspective
895 * and now just needs cleaning up in terms of freeing the
896 * request and potentially calling up to libsas.
Jeff Skirvinf219f012011-03-31 13:10:34 -0700897 *
898 * If old_state == aborting:
899 * This request has already gone through a TMF timeout, but may
900 * not have been terminated; needs cleaning up at least.
Dan Williams6f231dd2011-07-02 22:56:22 -0700901 */
902 isci_terminate_request_core(isci_host, isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800903 isci_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800904 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700905}
906
907/**
908 * isci_terminate_pending_requests() - This function will change the all of the
909 * requests on the given device's state to "aborting", will terminate the
910 * requests, and wait for them to complete. This function must only be
911 * called from a thread that can wait. Note that the requests are all
912 * terminated and completed (back to the host, if started there).
913 * @isci_host: This parameter specifies SCU.
914 * @isci_device: This parameter specifies the target.
915 *
916 *
917 */
918void isci_terminate_pending_requests(
919 struct isci_host *isci_host,
920 struct isci_remote_device *isci_device,
921 enum isci_request_status new_request_state)
922{
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800923 struct isci_request *request;
924 struct isci_request *next_request;
925 unsigned long flags;
926 struct list_head aborted_request_list;
927
928 INIT_LIST_HEAD(&aborted_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700929
930 dev_dbg(&isci_host->pdev->dev,
931 "%s: isci_device = %p (new request state = %d)\n",
932 __func__, isci_device, new_request_state);
933
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800934 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700935
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800936 /* Move all of the pending requests off of the device list. */
937 list_splice_init(&isci_device->reqs_in_process,
938 &aborted_request_list);
939
940 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
941
942 /* Iterate through the now-local list. */
943 list_for_each_entry_safe(request, next_request,
944 &aborted_request_list, dev_node) {
945
946 dev_warn(&isci_host->pdev->dev,
947 "%s: isci_device=%p request=%p; task=%p\n",
948 __func__,
949 isci_device, request,
950 ((request->ttype == io_task)
951 ? isci_request_access_task(request)
952 : NULL));
953
954 /* Mark all still pending I/O with the selected next
955 * state, terminate and free it.
956 */
957 isci_terminate_request(isci_host, isci_device,
958 request, new_request_state
959 );
Dan Williams6f231dd2011-07-02 22:56:22 -0700960 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700961}
962
963/**
964 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
965 * Template functions.
966 * @lun: This parameter specifies the lun to be reset.
967 *
968 * status, zero indicates success.
969 */
970static int isci_task_send_lu_reset_sas(
971 struct isci_host *isci_host,
972 struct isci_remote_device *isci_device,
973 u8 *lun)
974{
975 struct isci_tmf tmf;
976 int ret = TMF_RESP_FUNC_FAILED;
977
978 dev_dbg(&isci_host->pdev->dev,
979 "%s: isci_host = %p, isci_device = %p\n",
980 __func__, isci_host, isci_device);
981 /* Send the LUN reset to the target. By the time the call returns,
982 * the TMF has fully exected in the target (in which case the return
983 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
984 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
985 */
986 isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_lun_reset, NULL,
987 NULL);
988
989 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
990 ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
991
992 if (ret == TMF_RESP_FUNC_COMPLETE)
993 dev_dbg(&isci_host->pdev->dev,
994 "%s: %p: TMF_LU_RESET passed\n",
995 __func__, isci_device);
996 else
997 dev_dbg(&isci_host->pdev->dev,
998 "%s: %p: TMF_LU_RESET failed (%x)\n",
999 __func__, isci_device, ret);
1000
1001 return ret;
1002}
1003
1004/**
1005 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1006 * functions. This is one of the Task Management functoins called by libsas,
1007 * to reset the given lun. Note the assumption that while this call is
1008 * executing, no I/O will be sent by the host to the device.
1009 * @lun: This parameter specifies the lun to be reset.
1010 *
1011 * status, zero indicates success.
1012 */
Dan Williams4393aa42011-03-31 13:10:44 -07001013int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
Dan Williams6f231dd2011-07-02 22:56:22 -07001014{
Dan Williams4393aa42011-03-31 13:10:44 -07001015 struct isci_host *isci_host = dev_to_ihost(domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001016 struct isci_remote_device *isci_device = NULL;
1017 int ret;
1018 bool device_stopping = false;
1019
Dan Williams4393aa42011-03-31 13:10:44 -07001020 isci_device = domain_device->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001021
Dan Williams4393aa42011-03-31 13:10:44 -07001022 dev_dbg(&isci_host->pdev->dev,
1023 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07001024 __func__, domain_device, isci_host, isci_device);
1025
1026 if (isci_device != NULL)
1027 device_stopping = (isci_device->status == isci_stopping)
1028 || (isci_device->status == isci_stopped);
1029
1030 /* If there is a device reset pending on any request in the
1031 * device's list, fail this LUN reset request in order to
1032 * escalate to the device reset.
1033 */
Dan Williams4393aa42011-03-31 13:10:44 -07001034 if (!isci_device || device_stopping ||
1035 isci_device_is_reset_pending(isci_host, isci_device)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001036 dev_warn(&isci_host->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -07001037 "%s: No dev (%p), or "
Dan Williams6f231dd2011-07-02 22:56:22 -07001038 "RESET PENDING: domain_device=%p\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001039 __func__, isci_device, domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001040 return TMF_RESP_FUNC_FAILED;
1041 }
1042
Dan Williams6f231dd2011-07-02 22:56:22 -07001043 /* Send the task management part of the reset. */
1044 if (sas_protocol_ata(domain_device->tproto)) {
Dan Williams4393aa42011-03-31 13:10:44 -07001045 ret = isci_task_send_lu_reset_sata(isci_host, isci_device, lun);
Dan Williams6f231dd2011-07-02 22:56:22 -07001046 } else
1047 ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun);
1048
1049 /* If the LUN reset worked, all the I/O can now be terminated. */
1050 if (ret == TMF_RESP_FUNC_COMPLETE)
1051 /* Terminate all I/O now. */
1052 isci_terminate_pending_requests(isci_host,
1053 isci_device,
1054 terminating);
1055
Dan Williams6f231dd2011-07-02 22:56:22 -07001056 return ret;
1057}
1058
1059
1060/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1061int isci_task_clear_nexus_port(struct asd_sas_port *port)
1062{
1063 return TMF_RESP_FUNC_FAILED;
1064}
1065
1066
1067
1068int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
1069{
1070 return TMF_RESP_FUNC_FAILED;
1071}
1072
1073int isci_task_I_T_nexus_reset(struct domain_device *dev)
1074{
1075 return TMF_RESP_FUNC_FAILED;
1076}
1077
1078
1079/* Task Management Functions. Must be called from process context. */
1080
1081/**
1082 * isci_abort_task_process_cb() - This is a helper function for the abort task
1083 * TMF command. It manages the request state with respect to the successful
1084 * transmission / completion of the abort task request.
1085 * @cb_state: This parameter specifies when this function was called - after
1086 * the TMF request has been started and after it has timed-out.
1087 * @tmf: This parameter specifies the TMF in progress.
1088 *
1089 *
1090 */
1091static void isci_abort_task_process_cb(
1092 enum isci_tmf_cb_state cb_state,
1093 struct isci_tmf *tmf,
1094 void *cb_data)
1095{
1096 struct isci_request *old_request;
1097
1098 old_request = (struct isci_request *)cb_data;
1099
1100 dev_dbg(&old_request->isci_host->pdev->dev,
1101 "%s: tmf=%p, old_request=%p\n",
1102 __func__, tmf, old_request);
1103
1104 switch (cb_state) {
1105
1106 case isci_tmf_started:
1107 /* The TMF has been started. Nothing to do here, since the
1108 * request state was already set to "aborted" by the abort
1109 * task function.
1110 */
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001111 if ((old_request->status != aborted)
1112 && (old_request->status != completed))
1113 dev_err(&old_request->isci_host->pdev->dev,
1114 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1115 __func__, old_request->status, tmf, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001116 break;
1117
1118 case isci_tmf_timed_out:
1119
1120 /* Set the task's state to "aborting", since the abort task
1121 * function thread set it to "aborted" (above) in anticipation
1122 * of the task management request working correctly. Since the
1123 * timeout has now fired, the TMF request failed. We set the
1124 * state such that the request completion will indicate the
1125 * device is no longer present.
1126 */
1127 isci_request_change_state(old_request, aborting);
1128 break;
1129
1130 default:
1131 dev_err(&old_request->isci_host->pdev->dev,
1132 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1133 __func__, cb_state, tmf, old_request);
1134 break;
1135 }
1136}
1137
1138/**
1139 * isci_task_abort_task() - This function is one of the SAS Domain Template
1140 * functions. This function is called by libsas to abort a specified task.
1141 * @task: This parameter specifies the SAS task to abort.
1142 *
1143 * status, zero indicates success.
1144 */
1145int isci_task_abort_task(struct sas_task *task)
1146{
Dan Williams4393aa42011-03-31 13:10:44 -07001147 struct isci_host *isci_host = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001148 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001149 struct isci_request *old_request = NULL;
1150 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -07001151 struct isci_remote_device *isci_device = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001152 struct isci_tmf tmf;
1153 int ret = TMF_RESP_FUNC_FAILED;
1154 unsigned long flags;
1155 bool any_dev_reset = false;
1156 bool device_stopping;
Dan Williams6f231dd2011-07-02 22:56:22 -07001157
1158 /* Get the isci_request reference from the task. Note that
1159 * this check does not depend on the pending request list
1160 * in the device, because tasks driving resets may land here
1161 * after completion in the core.
1162 */
Dan Williams4393aa42011-03-31 13:10:44 -07001163 old_request = isci_task_get_request_from_task(task, &isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001164
1165 dev_dbg(&isci_host->pdev->dev,
1166 "%s: task = %p\n", __func__, task);
1167
1168 /* Check if the device has been / is currently being removed.
1169 * If so, no task management will be done, and the I/O will
1170 * be terminated.
1171 */
1172 device_stopping = (isci_device->status == isci_stopping)
1173 || (isci_device->status == isci_stopped);
1174
Dan Williams6f231dd2011-07-02 22:56:22 -07001175 /* This version of the driver will fail abort requests for
1176 * SATA/STP. Failing the abort request this way will cause the
1177 * SCSI error handler thread to escalate to LUN reset
1178 */
1179 if (sas_protocol_ata(task->task_proto) && !device_stopping) {
1180 dev_warn(&isci_host->pdev->dev,
1181 " task %p is for a STP/SATA device;"
1182 " returning TMF_RESP_FUNC_FAILED\n"
1183 " to cause a LUN reset...\n", task);
1184 return TMF_RESP_FUNC_FAILED;
1185 }
1186
1187 dev_dbg(&isci_host->pdev->dev,
1188 "%s: old_request == %p\n", __func__, old_request);
1189
Jeff Skirvina5fde222011-03-04 14:06:42 -08001190 if (!device_stopping)
1191 any_dev_reset = isci_device_is_reset_pending(isci_host,isci_device);
1192
Dan Williams6f231dd2011-07-02 22:56:22 -07001193 spin_lock_irqsave(&task->task_state_lock, flags);
1194
1195 /* Don't do resets to stopping devices. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001196 if (device_stopping) {
1197
Dan Williams6f231dd2011-07-02 22:56:22 -07001198 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001199 any_dev_reset = false;
Dan Williams6f231dd2011-07-02 22:56:22 -07001200
Jeff Skirvina5fde222011-03-04 14:06:42 -08001201 } else /* See if there is a pending device reset for this device. */
Dan Williams6f231dd2011-07-02 22:56:22 -07001202 any_dev_reset = any_dev_reset
Jeff Skirvina5fde222011-03-04 14:06:42 -08001203 || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
Dan Williams6f231dd2011-07-02 22:56:22 -07001204
1205 /* If the extraction of the request reference from the task
1206 * failed, then the request has been completed (or if there is a
1207 * pending reset then this abort request function must be failed
1208 * in order to escalate to the target reset).
1209 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001210 if ((old_request == NULL) || any_dev_reset) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001211
1212 /* If the device reset task flag is set, fail the task
1213 * management request. Otherwise, the original request
1214 * has completed.
1215 */
1216 if (any_dev_reset) {
1217
1218 /* Turn off the task's DONE to make sure this
1219 * task is escalated to a target reset.
1220 */
1221 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1222
Jeff Skirvina5fde222011-03-04 14:06:42 -08001223 /* Make the reset happen as soon as possible. */
1224 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1225
1226 spin_unlock_irqrestore(&task->task_state_lock, flags);
1227
Dan Williams6f231dd2011-07-02 22:56:22 -07001228 /* Fail the task management request in order to
1229 * escalate to the target reset.
1230 */
1231 ret = TMF_RESP_FUNC_FAILED;
1232
1233 dev_dbg(&isci_host->pdev->dev,
1234 "%s: Failing task abort in order to "
1235 "escalate to target reset because\n"
1236 "SAS_TASK_NEED_DEV_RESET is set for "
1237 "task %p on dev %p\n",
1238 __func__, task, isci_device);
1239
Jeff Skirvina5fde222011-03-04 14:06:42 -08001240
Dan Williams6f231dd2011-07-02 22:56:22 -07001241 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -07001242 /* The request has already completed and there
1243 * is nothing to do here other than to set the task
1244 * done bit, and indicate that the task abort function
1245 * was sucessful.
1246 */
1247 isci_set_task_doneflags(task);
1248
Jeff Skirvina5fde222011-03-04 14:06:42 -08001249 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001250
Jeff Skirvina5fde222011-03-04 14:06:42 -08001251 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001252
Jeff Skirvina5fde222011-03-04 14:06:42 -08001253 dev_dbg(&isci_host->pdev->dev,
1254 "%s: abort task not needed for %p\n",
1255 __func__, task);
Dan Williams6f231dd2011-07-02 22:56:22 -07001256 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001257
1258 return ret;
1259 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001260 else
1261 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001262
1263 spin_lock_irqsave(&isci_host->scic_lock, flags);
1264
Jeff Skirvinf219f012011-03-31 13:10:34 -07001265 /* Check the request status and change to "aborted" if currently
Jeff Skirvina5fde222011-03-04 14:06:42 -08001266 * "starting"; if true then set the I/O kernel completion
Dan Williams6f231dd2011-07-02 22:56:22 -07001267 * struct that will be triggered when the request completes.
1268 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001269 old_state = isci_task_validate_request_to_abort(
1270 old_request, isci_host, isci_device,
1271 &aborted_io_completion);
Jeff Skirvinf219f012011-03-31 13:10:34 -07001272 if ((old_state != started) &&
1273 (old_state != completed) &&
1274 (old_state != aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001275
1276 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1277
Jeff Skirvina5fde222011-03-04 14:06:42 -08001278 /* The request was already being handled by someone else (because
1279 * they got to set the state away from started).
1280 */
1281 dev_dbg(&isci_host->pdev->dev,
1282 "%s: device = %p; old_request %p already being aborted\n",
1283 __func__,
1284 isci_device, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001285
1286 return TMF_RESP_FUNC_COMPLETE;
1287 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001288 if ((task->task_proto == SAS_PROTOCOL_SMP)
1289 || device_stopping
1290 || old_request->complete_in_target
1291 ) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001292
1293 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1294
Jeff Skirvina5fde222011-03-04 14:06:42 -08001295 dev_dbg(&isci_host->pdev->dev,
1296 "%s: SMP request (%d)"
1297 " or device is stopping (%d)"
1298 " or complete_in_target (%d), thus no TMF\n",
1299 __func__, (task->task_proto == SAS_PROTOCOL_SMP),
1300 device_stopping, old_request->complete_in_target);
1301
Dan Williams6f231dd2011-07-02 22:56:22 -07001302 /* Set the state on the task. */
1303 isci_task_all_done(task);
1304
1305 ret = TMF_RESP_FUNC_COMPLETE;
1306
1307 /* Stopping and SMP devices are not sent a TMF, and are not
Jeff Skirvina5fde222011-03-04 14:06:42 -08001308 * reset, but the outstanding I/O request is terminated below.
Dan Williams6f231dd2011-07-02 22:56:22 -07001309 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001310 } else {
1311 /* Fill in the tmf stucture */
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -08001312 isci_task_build_abort_task_tmf(&tmf, isci_device,
1313 isci_tmf_ssp_task_abort,
1314 isci_abort_task_process_cb,
1315 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001316
Dan Williams6f231dd2011-07-02 22:56:22 -07001317 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1318
1319 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1320 ret = isci_task_execute_tmf(isci_host, &tmf,
1321 ISCI_ABORT_TASK_TIMEOUT_MS);
1322
Jeff Skirvina5fde222011-03-04 14:06:42 -08001323 if (ret != TMF_RESP_FUNC_COMPLETE)
Dan Williams6f231dd2011-07-02 22:56:22 -07001324 dev_err(&isci_host->pdev->dev,
1325 "%s: isci_task_send_tmf failed\n",
1326 __func__);
1327 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001328 if (ret == TMF_RESP_FUNC_COMPLETE) {
1329 old_request->complete_in_target = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07001330
Jeff Skirvina5fde222011-03-04 14:06:42 -08001331 /* Clean up the request on our side, and wait for the aborted I/O to
1332 * complete.
1333 */
Jeff Skirvincbb65c62011-03-04 14:06:50 -08001334 isci_terminate_request_core(isci_host, isci_device, old_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001335 }
1336
1337 /* Make sure we do not leave a reference to aborted_io_completion */
1338 old_request->io_request_completion = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -07001339 return ret;
1340}
1341
1342/**
1343 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1344 * functions. This is one of the Task Management functoins called by libsas,
1345 * to abort all task for the given lun.
1346 * @d_device: This parameter specifies the domain device associated with this
1347 * request.
1348 * @lun: This parameter specifies the lun associated with this request.
1349 *
1350 * status, zero indicates success.
1351 */
1352int isci_task_abort_task_set(
1353 struct domain_device *d_device,
1354 u8 *lun)
1355{
1356 return TMF_RESP_FUNC_FAILED;
1357}
1358
1359
1360/**
1361 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1362 * functions. This is one of the Task Management functoins called by libsas.
1363 * @d_device: This parameter specifies the domain device associated with this
1364 * request.
1365 * @lun: This parameter specifies the lun associated with this request.
1366 *
1367 * status, zero indicates success.
1368 */
1369int isci_task_clear_aca(
1370 struct domain_device *d_device,
1371 u8 *lun)
1372{
1373 return TMF_RESP_FUNC_FAILED;
1374}
1375
1376
1377
1378/**
1379 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1380 * functions. This is one of the Task Management functoins called by libsas.
1381 * @d_device: This parameter specifies the domain device associated with this
1382 * request.
1383 * @lun: This parameter specifies the lun associated with this request.
1384 *
1385 * status, zero indicates success.
1386 */
1387int isci_task_clear_task_set(
1388 struct domain_device *d_device,
1389 u8 *lun)
1390{
1391 return TMF_RESP_FUNC_FAILED;
1392}
1393
1394
1395/**
1396 * isci_task_query_task() - This function is implemented to cause libsas to
1397 * correctly escalate the failed abort to a LUN or target reset (this is
1398 * because sas_scsi_find_task libsas function does not correctly interpret
1399 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1400 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1401 * returned, libsas will turn this into a target reset
1402 * @task: This parameter specifies the sas task being queried.
1403 * @lun: This parameter specifies the lun associated with this request.
1404 *
1405 * status, zero indicates success.
1406 */
1407int isci_task_query_task(
1408 struct sas_task *task)
1409{
1410 /* See if there is a pending device reset for this device. */
1411 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1412 return TMF_RESP_FUNC_FAILED;
1413 else
1414 return TMF_RESP_FUNC_SUCC;
1415}
1416
1417/**
1418 * isci_task_request_complete() - This function is called by the sci core when
1419 * an task request completes.
1420 * @isci_host: This parameter specifies the ISCI host object
1421 * @request: This parameter is the completed isci_request object.
1422 * @completion_status: This parameter specifies the completion status from the
1423 * sci core.
1424 *
1425 * none.
1426 */
1427void isci_task_request_complete(
1428 struct isci_host *isci_host,
1429 struct isci_request *request,
1430 enum sci_task_status completion_status)
1431{
1432 struct isci_remote_device *isci_device = request->isci_device;
1433 enum isci_request_status old_state;
1434 struct isci_tmf *tmf = isci_request_access_tmf(request);
1435 struct completion *tmf_complete;
1436
1437 dev_dbg(&isci_host->pdev->dev,
1438 "%s: request = %p, status=%d\n",
1439 __func__, request, completion_status);
1440
1441 old_state = isci_request_change_state(request, completed);
1442
1443 tmf->status = completion_status;
1444 request->complete_in_target = true;
1445
1446 if (SAS_PROTOCOL_SSP == tmf->proto) {
1447
1448 memcpy(&tmf->resp.resp_iu,
1449 scic_io_request_get_response_iu_address(
1450 request->sci_request_handle
1451 ),
1452 sizeof(struct sci_ssp_response_iu));
1453
1454 } else if (SAS_PROTOCOL_SATA == tmf->proto) {
1455
1456 memcpy(&tmf->resp.d2h_fis,
1457 scic_stp_io_request_get_d2h_reg_address(
1458 request->sci_request_handle
1459 ),
1460 sizeof(struct sata_fis_reg_d2h)
1461 );
1462 }
1463
1464 /* Manage the timer if it is still running. */
1465 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -08001466 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -07001467 tmf->timeout_timer = NULL;
1468 }
1469
1470 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1471 tmf_complete = tmf->complete;
1472
Christoph Hellwigc6295822011-04-02 08:15:20 -04001473 scic_controller_complete_io(
Dan Williams6f231dd2011-07-02 22:56:22 -07001474 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -07001475 &isci_device->sci,
1476 request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -07001477 /* NULL the request handle to make sure it cannot be terminated
1478 * or completed again.
1479 */
1480 request->sci_request_handle = NULL;
1481
1482 isci_request_change_state(request, unallocated);
1483 list_del_init(&request->dev_node);
1484
1485 /* The task management part completes last. */
1486 complete(tmf_complete);
1487}
1488
1489
1490/**
1491 * isci_task_ssp_request_get_lun() - This function is called by the sci core to
1492 * retrieve the lun for a given task request.
1493 * @request: This parameter is the isci_request object.
1494 *
1495 * lun for specified task request.
1496 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001497
1498/**
1499 * isci_task_ssp_request_get_function() - This function is called by the sci
1500 * core to retrieve the function for a given task request.
1501 * @request: This parameter is the isci_request object.
1502 *
1503 * function code for specified task request.
1504 */
1505u8 isci_task_ssp_request_get_function(struct isci_request *request)
1506{
1507 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1508
1509 dev_dbg(&request->isci_host->pdev->dev,
1510 "%s: func = %d\n", __func__, isci_tmf->tmf_code);
1511
1512 return isci_tmf->tmf_code;
1513}
1514
1515/**
1516 * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by
1517 * the sci core to retrieve the io tag for a given task request.
1518 * @request: This parameter is the isci_request object.
1519 *
1520 * io tag for specified task request.
1521 */
1522u16 isci_task_ssp_request_get_io_tag_to_manage(struct isci_request *request)
1523{
1524 u16 io_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1525
1526 if (tmf_task == request->ttype) {
1527 struct isci_tmf *tmf = isci_request_access_tmf(request);
1528 io_tag = tmf->io_tag;
1529 }
1530
1531 dev_dbg(&request->isci_host->pdev->dev,
1532 "%s: request = %p, io_tag = %d\n",
1533 __func__, request, io_tag);
1534
1535 return io_tag;
1536}
1537
1538/**
1539 * isci_task_ssp_request_get_response_data_address() - This function is called
1540 * by the sci core to retrieve the response data address for a given task
1541 * request.
1542 * @request: This parameter is the isci_request object.
1543 *
1544 * response data address for specified task request.
1545 */
1546void *isci_task_ssp_request_get_response_data_address(
1547 struct isci_request *request)
1548{
1549 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1550
1551 return &isci_tmf->resp.resp_iu;
1552}
1553
1554/**
1555 * isci_task_ssp_request_get_response_data_length() - This function is called
1556 * by the sci core to retrieve the response data length for a given task
1557 * request.
1558 * @request: This parameter is the isci_request object.
1559 *
1560 * response data length for specified task request.
1561 */
1562u32 isci_task_ssp_request_get_response_data_length(
1563 struct isci_request *request)
1564{
1565 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1566
1567 return sizeof(isci_tmf->resp.resp_iu);
1568}
1569
1570/**
1571 * isci_bus_reset_handler() - This function performs a target reset of the
1572 * device referenced by "cmd'. This function is exported through the
1573 * "struct scsi_host_template" structure such that it is called when an I/O
1574 * recovery process has escalated to a target reset. Note that this function
1575 * is called from the scsi error handler event thread, so may block on calls.
1576 * @scsi_cmd: This parameter specifies the target to be reset.
1577 *
1578 * SUCCESS if the reset process was successful, else FAILED.
1579 */
1580int isci_bus_reset_handler(struct scsi_cmnd *cmd)
1581{
Dan Williams4393aa42011-03-31 13:10:44 -07001582 struct domain_device *dev = cmd_to_domain_dev(cmd);
1583 struct isci_host *isci_host = dev_to_ihost(dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001584 unsigned long flags = 0;
Dan Williams6f231dd2011-07-02 22:56:22 -07001585 enum sci_status status;
1586 int base_status;
Dan Williams4393aa42011-03-31 13:10:44 -07001587 struct isci_remote_device *isci_dev = dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001588
Dan Williams4393aa42011-03-31 13:10:44 -07001589 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001590 "%s: cmd %p, isci_dev %p\n",
1591 __func__, cmd, isci_dev);
1592
1593 if (!isci_dev) {
Dan Williams4393aa42011-03-31 13:10:44 -07001594 dev_warn(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001595 "%s: isci_dev is GONE!\n",
1596 __func__);
1597
1598 return TMF_RESP_FUNC_COMPLETE; /* Nothing to reset. */
1599 }
1600
Dan Williams4393aa42011-03-31 13:10:44 -07001601 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07001602 status = scic_remote_device_reset(&isci_dev->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07001603 if (status != SCI_SUCCESS) {
Dan Williams4393aa42011-03-31 13:10:44 -07001604 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001605
1606 scmd_printk(KERN_WARNING, cmd,
1607 "%s: scic_remote_device_reset(%p) returned %d!\n",
1608 __func__, isci_dev, status);
1609
1610 return TMF_RESP_FUNC_FAILED;
1611 }
Dan Williams4393aa42011-03-31 13:10:44 -07001612 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001613
Dan Williams6f231dd2011-07-02 22:56:22 -07001614 /* Make sure all pending requests are able to be fully terminated. */
Dan Williams4393aa42011-03-31 13:10:44 -07001615 isci_device_clear_reset_pending(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001616
1617 /* Terminate in-progress I/O now. */
Dan Williams4393aa42011-03-31 13:10:44 -07001618 isci_remote_device_nuke_requests(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001619
1620 /* Call into the libsas default handler (which calls sas_phy_reset). */
1621 base_status = sas_eh_bus_reset_handler(cmd);
1622
1623 if (base_status != SUCCESS) {
1624
1625 /* There can be cases where the resets to individual devices
1626 * behind an expander will fail because of an unplug of the
1627 * expander itself.
1628 */
1629 scmd_printk(KERN_WARNING, cmd,
1630 "%s: sas_eh_bus_reset_handler(%p) returned %d!\n",
1631 __func__, cmd, base_status);
1632 }
1633
1634 /* WHAT TO DO HERE IF sas_phy_reset FAILS? */
Dan Williams4393aa42011-03-31 13:10:44 -07001635 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07001636 status = scic_remote_device_reset_complete(&isci_dev->sci);
Dan Williams4393aa42011-03-31 13:10:44 -07001637 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001638
1639 if (status != SCI_SUCCESS) {
1640 scmd_printk(KERN_WARNING, cmd,
1641 "%s: scic_remote_device_reset_complete(%p) "
1642 "returned %d!\n",
1643 __func__, isci_dev, status);
1644 }
1645 /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */
1646
Dan Williams4393aa42011-03-31 13:10:44 -07001647 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001648 "%s: cmd %p, isci_dev %p complete.\n",
1649 __func__, cmd, isci_dev);
1650
Dan Williams6f231dd2011-07-02 22:56:22 -07001651 return TMF_RESP_FUNC_COMPLETE;
1652}