blob: e011d668949d6d194033a1e66495641abff615a6 [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. */
Dan Williams1077a572011-03-11 10:13:51 -0800186 dev_warn(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700187 "%s: task %p: isci_host->status = %d, "
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700188 "device = %p; device_status = 0x%x\n\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700189 __func__,
190 task,
Dan Williams1077a572011-03-11 10:13:51 -0800191 isci_host_get_state(ihost),
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700192 device, device_status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700193
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700194 if (device_status == isci_ready) {
195 /* Indicate QUEUE_FULL so that the scsi midlayer
196 * retries.
197 */
Dan Williams1077a572011-03-11 10:13:51 -0800198 isci_task_refuse(ihost, task,
199 SAS_TASK_COMPLETE,
200 SAS_QUEUE_FULL);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700201 } else {
202 /* Else, the device is going down. */
Dan Williams1077a572011-03-11 10:13:51 -0800203 isci_task_refuse(ihost, task,
204 SAS_TASK_UNDELIVERED,
205 SAS_DEVICE_UNKNOWN);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700206 }
Dan Williams1077a572011-03-11 10:13:51 -0800207 isci_host_can_dequeue(ihost, 1);
Dan Williams6f231dd2011-07-02 22:56:22 -0700208 } else {
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700209 /* There is a device and it's ready for I/O. */
210 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700211
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700212 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
213
214 spin_unlock_irqrestore(&task->task_state_lock,
215 flags);
216
Dan Williams1077a572011-03-11 10:13:51 -0800217 isci_task_refuse(ihost, task,
218 SAS_TASK_UNDELIVERED,
219 SAM_STAT_TASK_ABORTED);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700220
221 /* The I/O was aborted. */
222
223 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700224 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
225 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700226
227 /* build and send the request. */
Dan Williams1077a572011-03-11 10:13:51 -0800228 status = isci_request_execute(ihost, task, &request,
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700229 gfp_flags);
230
231 if (status != SCI_SUCCESS) {
232
233 spin_lock_irqsave(&task->task_state_lock, flags);
234 /* Did not really start this command. */
235 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
236 spin_unlock_irqrestore(&task->task_state_lock, flags);
237
238 /* Indicate QUEUE_FULL so that the scsi
239 * midlayer retries. if the request
240 * failed for remote device reasons,
241 * it gets returned as
242 * SAS_TASK_UNDELIVERED next time
243 * through.
244 */
Dan Williams1077a572011-03-11 10:13:51 -0800245 isci_task_refuse(ihost, task,
246 SAS_TASK_COMPLETE,
247 SAS_QUEUE_FULL);
248 isci_host_can_dequeue(ihost, 1);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700249 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700250 }
251 }
Dan Williams1077a572011-03-11 10:13:51 -0800252 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700253 return 0;
254}
255
256
257
258/**
259 * isci_task_request_build() - This function builds the task request object.
260 * @isci_host: This parameter specifies the ISCI host object
261 * @request: This parameter points to the isci_request object allocated in the
262 * request construct function.
263 * @tmf: This parameter is the task management struct to be built
264 *
265 * SCI_SUCCESS on successfull completion, or specific failure code.
266 */
267static enum sci_status isci_task_request_build(
268 struct isci_host *isci_host,
269 struct isci_request **isci_request,
270 struct isci_tmf *isci_tmf)
271{
272 struct scic_sds_remote_device *sci_device;
273 enum sci_status status = SCI_FAILURE;
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700274 struct isci_request *request = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700275 struct isci_remote_device *isci_device;
276/* struct sci_sas_identify_address_frame_protocols dev_protocols; */
277 struct smp_discover_response_protocols dev_protocols;
278
279
280 dev_dbg(&isci_host->pdev->dev,
281 "%s: isci_tmf = %p\n", __func__, isci_tmf);
282
283 isci_device = isci_tmf->device;
Dan Williams57f20f42011-04-21 18:14:45 -0700284 sci_device = &isci_device->sci;
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
322 scic_remote_device_get_protocols(
323 sci_device,
324 &dev_protocols
325 );
326
327 /* let the core do it's protocol
328 * specific construction.
329 */
330 if (dev_protocols.u.bits.attached_ssp_target) {
331
332 isci_tmf->proto = SAS_PROTOCOL_SSP;
333 status = scic_task_request_construct_ssp(
334 request->sci_request_handle
335 );
336 if (status != SCI_SUCCESS)
337 goto errout;
338 }
339
340 if (dev_protocols.u.bits.attached_stp_target) {
341
342 isci_tmf->proto = SAS_PROTOCOL_SATA;
343 status = isci_sata_management_task_request_build(request);
344
345 if (status != SCI_SUCCESS)
346 goto errout;
347 }
348
349 goto out;
350
351 errout:
352
353 /* release the dma memory if we fail. */
354 isci_request_free(isci_host, request);
355 request = NULL;
356
357 out:
358 *isci_request = request;
359 return status;
360}
361
362/**
363 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
364 * the timeout period for the TMF has expired.
365 *
366 *
367 */
368static void isci_tmf_timeout_cb(void *tmf_request_arg)
369{
370 struct isci_request *request = (struct isci_request *)tmf_request_arg;
371 struct isci_tmf *tmf = isci_request_access_tmf(request);
372 enum sci_status status;
373
Dan Williams6f231dd2011-07-02 22:56:22 -0700374 /* This task management request has timed-out. Terminate the request
375 * so that the request eventually completes to the requestor in the
376 * request completion callback path.
377 */
378 /* Note - the timer callback function itself has provided spinlock
379 * exclusion from the start and completion paths. No need to take
380 * the request->isci_host->scic_lock here.
381 */
382
383 if (tmf->timeout_timer != NULL) {
384 /* Call the users callback, if any. */
385 if (tmf->cb_state_func != NULL)
386 tmf->cb_state_func(isci_tmf_timed_out, tmf,
387 tmf->cb_data);
388
389 /* Terminate the TMF transmit request. */
390 status = scic_controller_terminate_request(
391 request->isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700392 &request->isci_device->sci,
Dan Williams6f231dd2011-07-02 22:56:22 -0700393 request->sci_request_handle
394 );
395
396 dev_dbg(&request->isci_host->pdev->dev,
397 "%s: tmf_request = %p; tmf = %p; status = %d\n",
398 __func__, request, tmf, status);
399 } else
400 dev_dbg(&request->isci_host->pdev->dev,
401 "%s: timer already canceled! "
402 "tmf_request = %p; tmf = %p\n",
403 __func__, request, tmf);
404
405 /* No need to unlock since the caller to this callback is doing it for
406 * us.
407 * request->isci_host->scic_lock
408 */
409}
410
411/**
412 * isci_task_execute_tmf() - This function builds and sends a task request,
413 * then waits for the completion.
414 * @isci_host: This parameter specifies the ISCI host object
415 * @tmf: This parameter is the pointer to the task management structure for
416 * this request.
417 * @timeout_ms: This parameter specifies the timeout period for the task
418 * management request.
419 *
420 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
421 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
422 */
423int isci_task_execute_tmf(
424 struct isci_host *isci_host,
425 struct isci_tmf *tmf,
426 unsigned long timeout_ms)
427{
428 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700429 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700430 struct scic_sds_remote_device *sci_device;
431 struct isci_remote_device *isci_device = tmf->device;
432 struct isci_request *request;
433 int ret = TMF_RESP_FUNC_FAILED;
434 unsigned long flags;
435
436 /* sanity check, return TMF_RESP_FUNC_FAILED
437 * if the device is not there and ready.
438 */
Dan Williams8acaec12011-03-07 14:47:35 -0800439 if (!isci_device || isci_device->status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700440 dev_dbg(&isci_host->pdev->dev,
441 "%s: isci_device = %p not ready (%d)\n",
442 __func__,
Dan Williams8acaec12011-03-07 14:47:35 -0800443 isci_device, isci_device->status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700444 return TMF_RESP_FUNC_FAILED;
445 } else
446 dev_dbg(&isci_host->pdev->dev,
447 "%s: isci_device = %p\n",
448 __func__, isci_device);
449
Dan Williams57f20f42011-04-21 18:14:45 -0700450 sci_device = &isci_device->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700451
452 /* Assign the pointer to the TMF's completion kernel wait structure. */
453 tmf->complete = &completion;
454
455 isci_task_request_build(
456 isci_host,
457 &request,
458 tmf
459 );
460
461 if (!request) {
462 dev_warn(&isci_host->pdev->dev,
463 "%s: isci_task_request_build failed\n",
464 __func__);
465 return TMF_RESP_FUNC_FAILED;
466 }
467
468 /* Allocate the TMF timeout timer. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700469 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800470 tmf->timeout_timer = isci_timer_create(isci_host, request, isci_tmf_timeout_cb);
Dan Williams6f231dd2011-07-02 22:56:22 -0700471
472 /* Start the timer. */
473 if (tmf->timeout_timer)
474 isci_timer_start(tmf->timeout_timer, timeout_ms);
475 else
476 dev_warn(&isci_host->pdev->dev,
477 "%s: isci_timer_create failed!!!!\n",
478 __func__);
479
480 /* start the TMF io. */
481 status = scic_controller_start_task(
482 isci_host->core_controller,
483 sci_device,
484 request->sci_request_handle,
485 SCI_CONTROLLER_INVALID_IO_TAG
486 );
487
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700488 if (status != SCI_TASK_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700489 dev_warn(&isci_host->pdev->dev,
490 "%s: start_io failed - status = 0x%x, request = %p\n",
491 __func__,
492 status,
493 request);
494 goto cleanup_request;
495 }
496
497 /* Call the users callback, if any. */
498 if (tmf->cb_state_func != NULL)
499 tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data);
500
501 /* Change the state of the TMF-bearing request to "started". */
502 isci_request_change_state(request, started);
503
504 /* add the request to the remote device request list. */
505 list_add(&request->dev_node, &isci_device->reqs_in_process);
506
507 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
508
509 /* Wait for the TMF to complete, or a timeout. */
510 wait_for_completion(&completion);
511
512 isci_print_tmf(tmf);
513
514 if (tmf->status == SCI_SUCCESS)
515 ret = TMF_RESP_FUNC_COMPLETE;
516 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
517 dev_dbg(&isci_host->pdev->dev,
518 "%s: tmf.status == "
519 "SCI_FAILURE_IO_RESPONSE_VALID\n",
520 __func__);
521 ret = TMF_RESP_FUNC_COMPLETE;
522 }
523 /* Else - leave the default "failed" status alone. */
524
525 dev_dbg(&isci_host->pdev->dev,
526 "%s: completed request = %p\n",
527 __func__,
528 request);
529
530 if (request->io_request_completion != NULL) {
531
532 /* The fact that this is non-NULL for a TMF request
533 * means there is a thread waiting for this TMF to
534 * finish.
535 */
536 complete(request->io_request_completion);
537 }
538
539 spin_lock_irqsave(&isci_host->scic_lock, flags);
540
541 cleanup_request:
542
543 /* Clean up the timer if needed. */
544 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -0800545 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -0700546 tmf->timeout_timer = NULL;
547 }
548
549 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
550
551 isci_request_free(isci_host, request);
552
553 return ret;
554}
555
556void isci_task_build_tmf(
557 struct isci_tmf *tmf,
558 struct isci_remote_device *isci_device,
559 enum isci_tmf_function_codes code,
560 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
561 struct isci_tmf *,
562 void *),
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800563 void *cb_data)
Dan Williams6f231dd2011-07-02 22:56:22 -0700564{
565 dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
566 "%s: isci_device = %p\n", __func__, isci_device);
567
568 memset(tmf, 0, sizeof(*tmf));
569
570 tmf->device = isci_device;
571 tmf->tmf_code = code;
572 tmf->timeout_timer = NULL;
573 tmf->cb_state_func = tmf_sent_cb;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800574 tmf->cb_data = cb_data;
575}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800576
Dan Williams35173d52011-03-26 16:43:01 -0700577static void isci_task_build_abort_task_tmf(
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800578 struct isci_tmf *tmf,
579 struct isci_remote_device *isci_device,
580 enum isci_tmf_function_codes code,
581 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
582 struct isci_tmf *,
583 void *),
584 struct isci_request *old_request)
585{
586 isci_task_build_tmf(tmf, isci_device, code, tmf_sent_cb,
587 (void *)old_request);
588 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700589}
590
591static struct isci_request *isci_task_get_request_from_task(
592 struct sas_task *task,
Dan Williams6f231dd2011-07-02 22:56:22 -0700593 struct isci_remote_device **isci_device)
594{
595
596 struct isci_request *request = NULL;
597 unsigned long flags;
598
599 spin_lock_irqsave(&task->task_state_lock, flags);
600
601 request = task->lldd_task;
602
603 /* If task is already done, the request isn't valid */
604 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
605 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
606 (request != NULL)) {
607
Dan Williams6f231dd2011-07-02 22:56:22 -0700608 if (isci_device != NULL)
609 *isci_device = request->isci_device;
610 }
611
612 spin_unlock_irqrestore(&task->task_state_lock, flags);
613
614 return request;
615}
616
617/**
618 * isci_task_validate_request_to_abort() - This function checks the given I/O
619 * against the "started" state. If the request is still "started", it's
620 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
621 * BEFORE CALLING THIS FUNCTION.
622 * @isci_request: This parameter specifies the request object to control.
623 * @isci_host: This parameter specifies the ISCI host object
624 * @isci_device: This is the device to which the request is pending.
625 * @aborted_io_completion: This is a completion structure that will be added to
626 * the request in case it is changed to aborting; this completion is
627 * triggered when the request is fully completed.
628 *
629 * Either "started" on successful change of the task status to "aborted", or
630 * "unallocated" if the task cannot be controlled.
631 */
632static enum isci_request_status isci_task_validate_request_to_abort(
633 struct isci_request *isci_request,
634 struct isci_host *isci_host,
635 struct isci_remote_device *isci_device,
636 struct completion *aborted_io_completion)
637{
638 enum isci_request_status old_state = unallocated;
639
640 /* Only abort the task if it's in the
641 * device's request_in_process list
642 */
643 if (isci_request && !list_empty(&isci_request->dev_node)) {
644 old_state = isci_request_change_started_to_aborted(
645 isci_request, aborted_io_completion);
646
Dan Williams6f231dd2011-07-02 22:56:22 -0700647 }
648
649 return old_state;
650}
651
652static void isci_request_cleanup_completed_loiterer(
653 struct isci_host *isci_host,
654 struct isci_remote_device *isci_device,
655 struct isci_request *isci_request)
656{
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800657 struct sas_task *task;
658 unsigned long flags;
659
660 task = (isci_request->ttype == io_task)
661 ? isci_request_access_task(isci_request)
662 : NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700663
664 dev_dbg(&isci_host->pdev->dev,
665 "%s: isci_device=%p, request=%p, task=%p\n",
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800666 __func__, isci_device, isci_request, task);
Dan Williams6f231dd2011-07-02 22:56:22 -0700667
668 spin_lock_irqsave(&isci_host->scic_lock, flags);
669 list_del_init(&isci_request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700670 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
671
Jeff Skirvina5fde222011-03-04 14:06:42 -0800672 if (task != NULL) {
673
674 spin_lock_irqsave(&task->task_state_lock, flags);
675 task->lldd_task = NULL;
676
677 isci_set_task_doneflags(task);
678
679 /* If this task is not in the abort path, call task_done. */
680 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
681
682 spin_unlock_irqrestore(&task->task_state_lock, flags);
683 task->task_done(task);
684 } else
685 spin_unlock_irqrestore(&task->task_state_lock, flags);
686 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700687 isci_request_free(isci_host, isci_request);
688}
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800689
690/**
691* @isci_termination_timed_out(): this function will deal with a request for
692* which the wait for termination has timed-out.
693*
694* @isci_host This SCU.
695* @isci_request The I/O request being terminated.
696*/
697static void
698isci_termination_timed_out(
699 struct isci_host * host,
700 struct isci_request * request
701 )
702{
703 unsigned long state_flags;
704
705 dev_warn(&host->pdev->dev,
706 "%s: host = %p; request = %p\n",
707 __func__, host, request);
708
709 /* At this point, the request to terminate
710 * has timed out. The best we can do is to
711 * have the request die a silent death
712 * if it ever completes.
713 */
714 spin_lock_irqsave(&request->state_lock, state_flags);
715
716 if (request->status == started) {
717
718 /* Set the request state to "dead",
719 * and clear the task pointer so that an actual
720 * completion event callback doesn't do
721 * anything.
722 */
723 request->status = dead;
724
725 /* Clear the timeout completion event pointer.*/
726 request->io_request_completion = NULL;
727
728 if (request->ttype == io_task) {
729
730 /* Break links with the sas_task. */
731 if (request->ttype_ptr.io_task_ptr != NULL) {
732
733 request->ttype_ptr.io_task_ptr->lldd_task = NULL;
734 request->ttype_ptr.io_task_ptr = NULL;
735 }
736 }
737 }
738 spin_unlock_irqrestore(&request->state_lock, state_flags);
739}
740
741
Dan Williams6f231dd2011-07-02 22:56:22 -0700742/**
743 * isci_terminate_request_core() - This function will terminate the given
744 * request, and wait for it to complete. This function must only be called
745 * from a thread that can wait. Note that the request is terminated and
746 * completed (back to the host, if started there).
747 * @isci_host: This SCU.
748 * @isci_device: The target.
749 * @isci_request: The I/O request to be terminated.
750 *
751 *
752 */
753static void isci_terminate_request_core(
754 struct isci_host *isci_host,
755 struct isci_remote_device *isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800756 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700757{
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800758 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700759 bool was_terminated = false;
760 bool needs_cleanup_handling = false;
761 enum isci_request_status request_status;
762 unsigned long flags;
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800763 unsigned long timeout_remaining;
764
Dan Williams6f231dd2011-07-02 22:56:22 -0700765
766 dev_dbg(&isci_host->pdev->dev,
767 "%s: device = %p; request = %p\n",
768 __func__, isci_device, isci_request);
769
Dan Williams6f231dd2011-07-02 22:56:22 -0700770 spin_lock_irqsave(&isci_host->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800771
772 /* Note that we are not going to control
773 * the target to abort the request.
774 */
775 isci_request->complete_in_target = true;
776
Dan Williams6f231dd2011-07-02 22:56:22 -0700777 /* Make sure the request wasn't just sitting around signalling
778 * device condition (if the request handle is NULL, then the
779 * request completed but needed additional handling here).
780 */
781 if (isci_request->sci_request_handle != NULL) {
782 was_terminated = true;
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800783 needs_cleanup_handling = true;
Dan Williams6f231dd2011-07-02 22:56:22 -0700784 status = scic_controller_terminate_request(
785 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700786 &isci_device->sci,
787 isci_request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -0700788 }
789 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
790
791 /*
792 * The only time the request to terminate will
793 * fail is when the io request is completed and
794 * being aborted.
795 */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800796 if (status != SCI_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700797 dev_err(&isci_host->pdev->dev,
798 "%s: scic_controller_terminate_request"
799 " returned = 0x%x\n",
800 __func__,
801 status);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800802 /* Clear the completion pointer from the request. */
803 isci_request->io_request_completion = NULL;
804
805 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700806 if (was_terminated) {
807 dev_dbg(&isci_host->pdev->dev,
808 "%s: before completion wait (%p)\n",
809 __func__,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800810 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700811
812 /* Wait here for the request to complete. */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800813 #define TERMINATION_TIMEOUT_MSEC 50
814 timeout_remaining
815 = wait_for_completion_timeout(
816 isci_request->io_request_completion,
817 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC));
Dan Williams6f231dd2011-07-02 22:56:22 -0700818
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800819 if (!timeout_remaining) {
820
821 isci_termination_timed_out(isci_host,
822 isci_request);
823
824 dev_err(&isci_host->pdev->dev,
825 "%s: *** Timeout waiting for "
826 "termination(%p/%p)\n",
827 __func__,
828 isci_request->io_request_completion,
829 isci_request);
830
831 } else
832 dev_dbg(&isci_host->pdev->dev,
833 "%s: after completion wait (%p)\n",
834 __func__,
835 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700836 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800837 /* Clear the completion pointer from the request. */
838 isci_request->io_request_completion = NULL;
839
840 /* Peek at the status of the request. This will tell
841 * us if there was special handling on the request such that it
842 * needs to be detached and freed here.
843 */
844 spin_lock_irqsave(&isci_request->state_lock, flags);
845 request_status = isci_request_get_state(isci_request);
846
847 if ((isci_request->ttype == io_task) /* TMFs are in their own thread */
848 && ((request_status == aborted)
849 || (request_status == aborting)
850 || (request_status == terminating)
851 || (request_status == completed)
852 || (request_status == dead)
853 )
854 ) {
855
856 /* The completion routine won't free a request in
857 * the aborted/aborting/etc. states, so we do
858 * it here.
859 */
860 needs_cleanup_handling = true;
861 }
862 spin_unlock_irqrestore(&isci_request->state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700863
864 if (needs_cleanup_handling)
865 isci_request_cleanup_completed_loiterer(
866 isci_host, isci_device, isci_request
867 );
868 }
869}
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800870
Dan Williams6f231dd2011-07-02 22:56:22 -0700871static void isci_terminate_request(
872 struct isci_host *isci_host,
873 struct isci_remote_device *isci_device,
874 struct isci_request *isci_request,
875 enum isci_request_status new_request_state)
876{
877 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -0700878 DECLARE_COMPLETION_ONSTACK(request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700879
880 /* Change state to "new_request_state" if it is currently "started" */
881 old_state = isci_request_change_started_to_newstate(
882 isci_request,
883 &request_completion,
884 new_request_state
885 );
886
Jeff Skirvinf219f012011-03-31 13:10:34 -0700887 if ((old_state == started) ||
888 (old_state == completed) ||
889 (old_state == aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700890
Jeff Skirvina5fde222011-03-04 14:06:42 -0800891 /* If the old_state is started:
892 * This request was not already being aborted. If it had been,
Dan Williams6f231dd2011-07-02 22:56:22 -0700893 * then the aborting I/O (ie. the TMF request) would not be in
894 * the aborting state, and thus would be terminated here. Note
895 * that since the TMF completion's call to the kernel function
896 * "complete()" does not happen until the pending I/O request
897 * terminate fully completes, we do not have to implement a
898 * special wait here for already aborting requests - the
899 * termination of the TMF request will force the request
900 * to finish it's already started terminate.
Jeff Skirvina5fde222011-03-04 14:06:42 -0800901 *
902 * If old_state == completed:
903 * This request completed from the SCU hardware perspective
904 * and now just needs cleaning up in terms of freeing the
905 * request and potentially calling up to libsas.
Jeff Skirvinf219f012011-03-31 13:10:34 -0700906 *
907 * If old_state == aborting:
908 * This request has already gone through a TMF timeout, but may
909 * not have been terminated; needs cleaning up at least.
Dan Williams6f231dd2011-07-02 22:56:22 -0700910 */
911 isci_terminate_request_core(isci_host, isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800912 isci_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800913 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700914}
915
916/**
917 * isci_terminate_pending_requests() - This function will change the all of the
918 * requests on the given device's state to "aborting", will terminate the
919 * requests, and wait for them to complete. This function must only be
920 * called from a thread that can wait. Note that the requests are all
921 * terminated and completed (back to the host, if started there).
922 * @isci_host: This parameter specifies SCU.
923 * @isci_device: This parameter specifies the target.
924 *
925 *
926 */
927void isci_terminate_pending_requests(
928 struct isci_host *isci_host,
929 struct isci_remote_device *isci_device,
930 enum isci_request_status new_request_state)
931{
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800932 struct isci_request *request;
933 struct isci_request *next_request;
934 unsigned long flags;
935 struct list_head aborted_request_list;
936
937 INIT_LIST_HEAD(&aborted_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700938
939 dev_dbg(&isci_host->pdev->dev,
940 "%s: isci_device = %p (new request state = %d)\n",
941 __func__, isci_device, new_request_state);
942
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800943 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700944
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800945 /* Move all of the pending requests off of the device list. */
946 list_splice_init(&isci_device->reqs_in_process,
947 &aborted_request_list);
948
949 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
950
951 /* Iterate through the now-local list. */
952 list_for_each_entry_safe(request, next_request,
953 &aborted_request_list, dev_node) {
954
955 dev_warn(&isci_host->pdev->dev,
956 "%s: isci_device=%p request=%p; task=%p\n",
957 __func__,
958 isci_device, request,
959 ((request->ttype == io_task)
960 ? isci_request_access_task(request)
961 : NULL));
962
963 /* Mark all still pending I/O with the selected next
964 * state, terminate and free it.
965 */
966 isci_terminate_request(isci_host, isci_device,
967 request, new_request_state
968 );
Dan Williams6f231dd2011-07-02 22:56:22 -0700969 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700970}
971
972/**
973 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
974 * Template functions.
975 * @lun: This parameter specifies the lun to be reset.
976 *
977 * status, zero indicates success.
978 */
979static int isci_task_send_lu_reset_sas(
980 struct isci_host *isci_host,
981 struct isci_remote_device *isci_device,
982 u8 *lun)
983{
984 struct isci_tmf tmf;
985 int ret = TMF_RESP_FUNC_FAILED;
986
987 dev_dbg(&isci_host->pdev->dev,
988 "%s: isci_host = %p, isci_device = %p\n",
989 __func__, isci_host, isci_device);
990 /* Send the LUN reset to the target. By the time the call returns,
991 * the TMF has fully exected in the target (in which case the return
992 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
993 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
994 */
995 isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_lun_reset, NULL,
996 NULL);
997
998 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
999 ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
1000
1001 if (ret == TMF_RESP_FUNC_COMPLETE)
1002 dev_dbg(&isci_host->pdev->dev,
1003 "%s: %p: TMF_LU_RESET passed\n",
1004 __func__, isci_device);
1005 else
1006 dev_dbg(&isci_host->pdev->dev,
1007 "%s: %p: TMF_LU_RESET failed (%x)\n",
1008 __func__, isci_device, ret);
1009
1010 return ret;
1011}
1012
1013/**
1014 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1015 * functions. This is one of the Task Management functoins called by libsas,
1016 * to reset the given lun. Note the assumption that while this call is
1017 * executing, no I/O will be sent by the host to the device.
1018 * @lun: This parameter specifies the lun to be reset.
1019 *
1020 * status, zero indicates success.
1021 */
Dan Williams4393aa42011-03-31 13:10:44 -07001022int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
Dan Williams6f231dd2011-07-02 22:56:22 -07001023{
Dan Williams4393aa42011-03-31 13:10:44 -07001024 struct isci_host *isci_host = dev_to_ihost(domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001025 struct isci_remote_device *isci_device = NULL;
1026 int ret;
1027 bool device_stopping = false;
1028
Dan Williams4393aa42011-03-31 13:10:44 -07001029 isci_device = domain_device->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001030
Dan Williams4393aa42011-03-31 13:10:44 -07001031 dev_dbg(&isci_host->pdev->dev,
1032 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07001033 __func__, domain_device, isci_host, isci_device);
1034
1035 if (isci_device != NULL)
1036 device_stopping = (isci_device->status == isci_stopping)
1037 || (isci_device->status == isci_stopped);
1038
1039 /* If there is a device reset pending on any request in the
1040 * device's list, fail this LUN reset request in order to
1041 * escalate to the device reset.
1042 */
Dan Williams4393aa42011-03-31 13:10:44 -07001043 if (!isci_device || device_stopping ||
1044 isci_device_is_reset_pending(isci_host, isci_device)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001045 dev_warn(&isci_host->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -07001046 "%s: No dev (%p), or "
Dan Williams6f231dd2011-07-02 22:56:22 -07001047 "RESET PENDING: domain_device=%p\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001048 __func__, isci_device, domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001049 return TMF_RESP_FUNC_FAILED;
1050 }
1051
Dan Williams6f231dd2011-07-02 22:56:22 -07001052 /* Send the task management part of the reset. */
1053 if (sas_protocol_ata(domain_device->tproto)) {
Dan Williams4393aa42011-03-31 13:10:44 -07001054 ret = isci_task_send_lu_reset_sata(isci_host, isci_device, lun);
Dan Williams6f231dd2011-07-02 22:56:22 -07001055 } else
1056 ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun);
1057
1058 /* If the LUN reset worked, all the I/O can now be terminated. */
1059 if (ret == TMF_RESP_FUNC_COMPLETE)
1060 /* Terminate all I/O now. */
1061 isci_terminate_pending_requests(isci_host,
1062 isci_device,
1063 terminating);
1064
Dan Williams6f231dd2011-07-02 22:56:22 -07001065 return ret;
1066}
1067
1068
1069/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1070int isci_task_clear_nexus_port(struct asd_sas_port *port)
1071{
1072 return TMF_RESP_FUNC_FAILED;
1073}
1074
1075
1076
1077int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
1078{
1079 return TMF_RESP_FUNC_FAILED;
1080}
1081
1082int isci_task_I_T_nexus_reset(struct domain_device *dev)
1083{
1084 return TMF_RESP_FUNC_FAILED;
1085}
1086
1087
1088/* Task Management Functions. Must be called from process context. */
1089
1090/**
1091 * isci_abort_task_process_cb() - This is a helper function for the abort task
1092 * TMF command. It manages the request state with respect to the successful
1093 * transmission / completion of the abort task request.
1094 * @cb_state: This parameter specifies when this function was called - after
1095 * the TMF request has been started and after it has timed-out.
1096 * @tmf: This parameter specifies the TMF in progress.
1097 *
1098 *
1099 */
1100static void isci_abort_task_process_cb(
1101 enum isci_tmf_cb_state cb_state,
1102 struct isci_tmf *tmf,
1103 void *cb_data)
1104{
1105 struct isci_request *old_request;
1106
1107 old_request = (struct isci_request *)cb_data;
1108
1109 dev_dbg(&old_request->isci_host->pdev->dev,
1110 "%s: tmf=%p, old_request=%p\n",
1111 __func__, tmf, old_request);
1112
1113 switch (cb_state) {
1114
1115 case isci_tmf_started:
1116 /* The TMF has been started. Nothing to do here, since the
1117 * request state was already set to "aborted" by the abort
1118 * task function.
1119 */
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001120 if ((old_request->status != aborted)
1121 && (old_request->status != completed))
1122 dev_err(&old_request->isci_host->pdev->dev,
1123 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1124 __func__, old_request->status, tmf, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001125 break;
1126
1127 case isci_tmf_timed_out:
1128
1129 /* Set the task's state to "aborting", since the abort task
1130 * function thread set it to "aborted" (above) in anticipation
1131 * of the task management request working correctly. Since the
1132 * timeout has now fired, the TMF request failed. We set the
1133 * state such that the request completion will indicate the
1134 * device is no longer present.
1135 */
1136 isci_request_change_state(old_request, aborting);
1137 break;
1138
1139 default:
1140 dev_err(&old_request->isci_host->pdev->dev,
1141 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1142 __func__, cb_state, tmf, old_request);
1143 break;
1144 }
1145}
1146
1147/**
1148 * isci_task_abort_task() - This function is one of the SAS Domain Template
1149 * functions. This function is called by libsas to abort a specified task.
1150 * @task: This parameter specifies the SAS task to abort.
1151 *
1152 * status, zero indicates success.
1153 */
1154int isci_task_abort_task(struct sas_task *task)
1155{
Dan Williams4393aa42011-03-31 13:10:44 -07001156 struct isci_host *isci_host = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001157 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001158 struct isci_request *old_request = NULL;
1159 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -07001160 struct isci_remote_device *isci_device = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001161 struct isci_tmf tmf;
1162 int ret = TMF_RESP_FUNC_FAILED;
1163 unsigned long flags;
1164 bool any_dev_reset = false;
1165 bool device_stopping;
Dan Williams6f231dd2011-07-02 22:56:22 -07001166
1167 /* Get the isci_request reference from the task. Note that
1168 * this check does not depend on the pending request list
1169 * in the device, because tasks driving resets may land here
1170 * after completion in the core.
1171 */
Dan Williams4393aa42011-03-31 13:10:44 -07001172 old_request = isci_task_get_request_from_task(task, &isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001173
1174 dev_dbg(&isci_host->pdev->dev,
1175 "%s: task = %p\n", __func__, task);
1176
1177 /* Check if the device has been / is currently being removed.
1178 * If so, no task management will be done, and the I/O will
1179 * be terminated.
1180 */
1181 device_stopping = (isci_device->status == isci_stopping)
1182 || (isci_device->status == isci_stopped);
1183
Dan Williams6f231dd2011-07-02 22:56:22 -07001184 /* This version of the driver will fail abort requests for
1185 * SATA/STP. Failing the abort request this way will cause the
1186 * SCSI error handler thread to escalate to LUN reset
1187 */
1188 if (sas_protocol_ata(task->task_proto) && !device_stopping) {
1189 dev_warn(&isci_host->pdev->dev,
1190 " task %p is for a STP/SATA device;"
1191 " returning TMF_RESP_FUNC_FAILED\n"
1192 " to cause a LUN reset...\n", task);
1193 return TMF_RESP_FUNC_FAILED;
1194 }
1195
1196 dev_dbg(&isci_host->pdev->dev,
1197 "%s: old_request == %p\n", __func__, old_request);
1198
Jeff Skirvina5fde222011-03-04 14:06:42 -08001199 if (!device_stopping)
1200 any_dev_reset = isci_device_is_reset_pending(isci_host,isci_device);
1201
Dan Williams6f231dd2011-07-02 22:56:22 -07001202 spin_lock_irqsave(&task->task_state_lock, flags);
1203
1204 /* Don't do resets to stopping devices. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001205 if (device_stopping) {
1206
Dan Williams6f231dd2011-07-02 22:56:22 -07001207 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001208 any_dev_reset = false;
Dan Williams6f231dd2011-07-02 22:56:22 -07001209
Jeff Skirvina5fde222011-03-04 14:06:42 -08001210 } else /* See if there is a pending device reset for this device. */
Dan Williams6f231dd2011-07-02 22:56:22 -07001211 any_dev_reset = any_dev_reset
Jeff Skirvina5fde222011-03-04 14:06:42 -08001212 || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
Dan Williams6f231dd2011-07-02 22:56:22 -07001213
1214 /* If the extraction of the request reference from the task
1215 * failed, then the request has been completed (or if there is a
1216 * pending reset then this abort request function must be failed
1217 * in order to escalate to the target reset).
1218 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001219 if ((old_request == NULL) || any_dev_reset) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001220
1221 /* If the device reset task flag is set, fail the task
1222 * management request. Otherwise, the original request
1223 * has completed.
1224 */
1225 if (any_dev_reset) {
1226
1227 /* Turn off the task's DONE to make sure this
1228 * task is escalated to a target reset.
1229 */
1230 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1231
Jeff Skirvina5fde222011-03-04 14:06:42 -08001232 /* Make the reset happen as soon as possible. */
1233 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1234
1235 spin_unlock_irqrestore(&task->task_state_lock, flags);
1236
Dan Williams6f231dd2011-07-02 22:56:22 -07001237 /* Fail the task management request in order to
1238 * escalate to the target reset.
1239 */
1240 ret = TMF_RESP_FUNC_FAILED;
1241
1242 dev_dbg(&isci_host->pdev->dev,
1243 "%s: Failing task abort in order to "
1244 "escalate to target reset because\n"
1245 "SAS_TASK_NEED_DEV_RESET is set for "
1246 "task %p on dev %p\n",
1247 __func__, task, isci_device);
1248
Jeff Skirvina5fde222011-03-04 14:06:42 -08001249
Dan Williams6f231dd2011-07-02 22:56:22 -07001250 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -07001251 /* The request has already completed and there
1252 * is nothing to do here other than to set the task
1253 * done bit, and indicate that the task abort function
1254 * was sucessful.
1255 */
1256 isci_set_task_doneflags(task);
1257
Jeff Skirvina5fde222011-03-04 14:06:42 -08001258 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001259
Jeff Skirvina5fde222011-03-04 14:06:42 -08001260 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001261
Jeff Skirvina5fde222011-03-04 14:06:42 -08001262 dev_dbg(&isci_host->pdev->dev,
1263 "%s: abort task not needed for %p\n",
1264 __func__, task);
Dan Williams6f231dd2011-07-02 22:56:22 -07001265 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001266
1267 return ret;
1268 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001269 else
1270 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001271
1272 spin_lock_irqsave(&isci_host->scic_lock, flags);
1273
Jeff Skirvinf219f012011-03-31 13:10:34 -07001274 /* Check the request status and change to "aborted" if currently
Jeff Skirvina5fde222011-03-04 14:06:42 -08001275 * "starting"; if true then set the I/O kernel completion
Dan Williams6f231dd2011-07-02 22:56:22 -07001276 * struct that will be triggered when the request completes.
1277 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001278 old_state = isci_task_validate_request_to_abort(
1279 old_request, isci_host, isci_device,
1280 &aborted_io_completion);
Jeff Skirvinf219f012011-03-31 13:10:34 -07001281 if ((old_state != started) &&
1282 (old_state != completed) &&
1283 (old_state != aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001284
1285 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1286
Jeff Skirvina5fde222011-03-04 14:06:42 -08001287 /* The request was already being handled by someone else (because
1288 * they got to set the state away from started).
1289 */
1290 dev_dbg(&isci_host->pdev->dev,
1291 "%s: device = %p; old_request %p already being aborted\n",
1292 __func__,
1293 isci_device, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001294
1295 return TMF_RESP_FUNC_COMPLETE;
1296 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001297 if ((task->task_proto == SAS_PROTOCOL_SMP)
1298 || device_stopping
1299 || old_request->complete_in_target
1300 ) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001301
1302 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1303
Jeff Skirvina5fde222011-03-04 14:06:42 -08001304 dev_dbg(&isci_host->pdev->dev,
1305 "%s: SMP request (%d)"
1306 " or device is stopping (%d)"
1307 " or complete_in_target (%d), thus no TMF\n",
1308 __func__, (task->task_proto == SAS_PROTOCOL_SMP),
1309 device_stopping, old_request->complete_in_target);
1310
Dan Williams6f231dd2011-07-02 22:56:22 -07001311 /* Set the state on the task. */
1312 isci_task_all_done(task);
1313
1314 ret = TMF_RESP_FUNC_COMPLETE;
1315
1316 /* Stopping and SMP devices are not sent a TMF, and are not
Jeff Skirvina5fde222011-03-04 14:06:42 -08001317 * reset, but the outstanding I/O request is terminated below.
Dan Williams6f231dd2011-07-02 22:56:22 -07001318 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001319 } else {
1320 /* Fill in the tmf stucture */
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -08001321 isci_task_build_abort_task_tmf(&tmf, isci_device,
1322 isci_tmf_ssp_task_abort,
1323 isci_abort_task_process_cb,
1324 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001325
Dan Williams6f231dd2011-07-02 22:56:22 -07001326 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1327
1328 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1329 ret = isci_task_execute_tmf(isci_host, &tmf,
1330 ISCI_ABORT_TASK_TIMEOUT_MS);
1331
Jeff Skirvina5fde222011-03-04 14:06:42 -08001332 if (ret != TMF_RESP_FUNC_COMPLETE)
Dan Williams6f231dd2011-07-02 22:56:22 -07001333 dev_err(&isci_host->pdev->dev,
1334 "%s: isci_task_send_tmf failed\n",
1335 __func__);
1336 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001337 if (ret == TMF_RESP_FUNC_COMPLETE) {
1338 old_request->complete_in_target = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07001339
Jeff Skirvina5fde222011-03-04 14:06:42 -08001340 /* Clean up the request on our side, and wait for the aborted I/O to
1341 * complete.
1342 */
Jeff Skirvincbb65c62011-03-04 14:06:50 -08001343 isci_terminate_request_core(isci_host, isci_device, old_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001344 }
1345
1346 /* Make sure we do not leave a reference to aborted_io_completion */
1347 old_request->io_request_completion = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -07001348 return ret;
1349}
1350
1351/**
1352 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1353 * functions. This is one of the Task Management functoins called by libsas,
1354 * to abort all task for the given lun.
1355 * @d_device: This parameter specifies the domain device associated with this
1356 * request.
1357 * @lun: This parameter specifies the lun associated with this request.
1358 *
1359 * status, zero indicates success.
1360 */
1361int isci_task_abort_task_set(
1362 struct domain_device *d_device,
1363 u8 *lun)
1364{
1365 return TMF_RESP_FUNC_FAILED;
1366}
1367
1368
1369/**
1370 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1371 * functions. This is one of the Task Management functoins called by libsas.
1372 * @d_device: This parameter specifies the domain device associated with this
1373 * request.
1374 * @lun: This parameter specifies the lun associated with this request.
1375 *
1376 * status, zero indicates success.
1377 */
1378int isci_task_clear_aca(
1379 struct domain_device *d_device,
1380 u8 *lun)
1381{
1382 return TMF_RESP_FUNC_FAILED;
1383}
1384
1385
1386
1387/**
1388 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1389 * functions. This is one of the Task Management functoins called by libsas.
1390 * @d_device: This parameter specifies the domain device associated with this
1391 * request.
1392 * @lun: This parameter specifies the lun associated with this request.
1393 *
1394 * status, zero indicates success.
1395 */
1396int isci_task_clear_task_set(
1397 struct domain_device *d_device,
1398 u8 *lun)
1399{
1400 return TMF_RESP_FUNC_FAILED;
1401}
1402
1403
1404/**
1405 * isci_task_query_task() - This function is implemented to cause libsas to
1406 * correctly escalate the failed abort to a LUN or target reset (this is
1407 * because sas_scsi_find_task libsas function does not correctly interpret
1408 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1409 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1410 * returned, libsas will turn this into a target reset
1411 * @task: This parameter specifies the sas task being queried.
1412 * @lun: This parameter specifies the lun associated with this request.
1413 *
1414 * status, zero indicates success.
1415 */
1416int isci_task_query_task(
1417 struct sas_task *task)
1418{
1419 /* See if there is a pending device reset for this device. */
1420 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1421 return TMF_RESP_FUNC_FAILED;
1422 else
1423 return TMF_RESP_FUNC_SUCC;
1424}
1425
1426/**
1427 * isci_task_request_complete() - This function is called by the sci core when
1428 * an task request completes.
1429 * @isci_host: This parameter specifies the ISCI host object
1430 * @request: This parameter is the completed isci_request object.
1431 * @completion_status: This parameter specifies the completion status from the
1432 * sci core.
1433 *
1434 * none.
1435 */
1436void isci_task_request_complete(
1437 struct isci_host *isci_host,
1438 struct isci_request *request,
1439 enum sci_task_status completion_status)
1440{
1441 struct isci_remote_device *isci_device = request->isci_device;
1442 enum isci_request_status old_state;
1443 struct isci_tmf *tmf = isci_request_access_tmf(request);
1444 struct completion *tmf_complete;
1445
1446 dev_dbg(&isci_host->pdev->dev,
1447 "%s: request = %p, status=%d\n",
1448 __func__, request, completion_status);
1449
1450 old_state = isci_request_change_state(request, completed);
1451
1452 tmf->status = completion_status;
1453 request->complete_in_target = true;
1454
1455 if (SAS_PROTOCOL_SSP == tmf->proto) {
1456
1457 memcpy(&tmf->resp.resp_iu,
1458 scic_io_request_get_response_iu_address(
1459 request->sci_request_handle
1460 ),
1461 sizeof(struct sci_ssp_response_iu));
1462
1463 } else if (SAS_PROTOCOL_SATA == tmf->proto) {
1464
1465 memcpy(&tmf->resp.d2h_fis,
1466 scic_stp_io_request_get_d2h_reg_address(
1467 request->sci_request_handle
1468 ),
1469 sizeof(struct sata_fis_reg_d2h)
1470 );
1471 }
1472
1473 /* Manage the timer if it is still running. */
1474 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -08001475 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -07001476 tmf->timeout_timer = NULL;
1477 }
1478
1479 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1480 tmf_complete = tmf->complete;
1481
Christoph Hellwigc6295822011-04-02 08:15:20 -04001482 scic_controller_complete_io(
Dan Williams6f231dd2011-07-02 22:56:22 -07001483 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -07001484 &isci_device->sci,
1485 request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -07001486 /* NULL the request handle to make sure it cannot be terminated
1487 * or completed again.
1488 */
1489 request->sci_request_handle = NULL;
1490
1491 isci_request_change_state(request, unallocated);
1492 list_del_init(&request->dev_node);
1493
1494 /* The task management part completes last. */
1495 complete(tmf_complete);
1496}
1497
1498
1499/**
1500 * isci_task_ssp_request_get_lun() - This function is called by the sci core to
1501 * retrieve the lun for a given task request.
1502 * @request: This parameter is the isci_request object.
1503 *
1504 * lun for specified task request.
1505 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001506
1507/**
1508 * isci_task_ssp_request_get_function() - This function is called by the sci
1509 * core to retrieve the function for a given task request.
1510 * @request: This parameter is the isci_request object.
1511 *
1512 * function code for specified task request.
1513 */
1514u8 isci_task_ssp_request_get_function(struct isci_request *request)
1515{
1516 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1517
1518 dev_dbg(&request->isci_host->pdev->dev,
1519 "%s: func = %d\n", __func__, isci_tmf->tmf_code);
1520
1521 return isci_tmf->tmf_code;
1522}
1523
1524/**
1525 * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by
1526 * the sci core to retrieve the io tag for a given task request.
1527 * @request: This parameter is the isci_request object.
1528 *
1529 * io tag for specified task request.
1530 */
1531u16 isci_task_ssp_request_get_io_tag_to_manage(struct isci_request *request)
1532{
1533 u16 io_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1534
1535 if (tmf_task == request->ttype) {
1536 struct isci_tmf *tmf = isci_request_access_tmf(request);
1537 io_tag = tmf->io_tag;
1538 }
1539
1540 dev_dbg(&request->isci_host->pdev->dev,
1541 "%s: request = %p, io_tag = %d\n",
1542 __func__, request, io_tag);
1543
1544 return io_tag;
1545}
1546
1547/**
1548 * isci_task_ssp_request_get_response_data_address() - This function is called
1549 * by the sci core to retrieve the response data address for a given task
1550 * request.
1551 * @request: This parameter is the isci_request object.
1552 *
1553 * response data address for specified task request.
1554 */
1555void *isci_task_ssp_request_get_response_data_address(
1556 struct isci_request *request)
1557{
1558 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1559
1560 return &isci_tmf->resp.resp_iu;
1561}
1562
1563/**
1564 * isci_task_ssp_request_get_response_data_length() - This function is called
1565 * by the sci core to retrieve the response data length for a given task
1566 * request.
1567 * @request: This parameter is the isci_request object.
1568 *
1569 * response data length for specified task request.
1570 */
1571u32 isci_task_ssp_request_get_response_data_length(
1572 struct isci_request *request)
1573{
1574 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1575
1576 return sizeof(isci_tmf->resp.resp_iu);
1577}
1578
1579/**
1580 * isci_bus_reset_handler() - This function performs a target reset of the
1581 * device referenced by "cmd'. This function is exported through the
1582 * "struct scsi_host_template" structure such that it is called when an I/O
1583 * recovery process has escalated to a target reset. Note that this function
1584 * is called from the scsi error handler event thread, so may block on calls.
1585 * @scsi_cmd: This parameter specifies the target to be reset.
1586 *
1587 * SUCCESS if the reset process was successful, else FAILED.
1588 */
1589int isci_bus_reset_handler(struct scsi_cmnd *cmd)
1590{
Dan Williams4393aa42011-03-31 13:10:44 -07001591 struct domain_device *dev = cmd_to_domain_dev(cmd);
1592 struct isci_host *isci_host = dev_to_ihost(dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001593 unsigned long flags = 0;
Dan Williams6f231dd2011-07-02 22:56:22 -07001594 enum sci_status status;
1595 int base_status;
Dan Williams4393aa42011-03-31 13:10:44 -07001596 struct isci_remote_device *isci_dev = dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001597
Dan Williams4393aa42011-03-31 13:10:44 -07001598 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001599 "%s: cmd %p, isci_dev %p\n",
1600 __func__, cmd, isci_dev);
1601
1602 if (!isci_dev) {
Dan Williams4393aa42011-03-31 13:10:44 -07001603 dev_warn(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001604 "%s: isci_dev is GONE!\n",
1605 __func__);
1606
1607 return TMF_RESP_FUNC_COMPLETE; /* Nothing to reset. */
1608 }
1609
Dan Williams4393aa42011-03-31 13:10:44 -07001610 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07001611 status = scic_remote_device_reset(&isci_dev->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07001612 if (status != SCI_SUCCESS) {
Dan Williams4393aa42011-03-31 13:10:44 -07001613 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001614
1615 scmd_printk(KERN_WARNING, cmd,
1616 "%s: scic_remote_device_reset(%p) returned %d!\n",
1617 __func__, isci_dev, status);
1618
1619 return TMF_RESP_FUNC_FAILED;
1620 }
Dan Williams4393aa42011-03-31 13:10:44 -07001621 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001622
Dan Williams6f231dd2011-07-02 22:56:22 -07001623 /* Make sure all pending requests are able to be fully terminated. */
Dan Williams4393aa42011-03-31 13:10:44 -07001624 isci_device_clear_reset_pending(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001625
1626 /* Terminate in-progress I/O now. */
Dan Williams4393aa42011-03-31 13:10:44 -07001627 isci_remote_device_nuke_requests(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001628
1629 /* Call into the libsas default handler (which calls sas_phy_reset). */
1630 base_status = sas_eh_bus_reset_handler(cmd);
1631
1632 if (base_status != SUCCESS) {
1633
1634 /* There can be cases where the resets to individual devices
1635 * behind an expander will fail because of an unplug of the
1636 * expander itself.
1637 */
1638 scmd_printk(KERN_WARNING, cmd,
1639 "%s: sas_eh_bus_reset_handler(%p) returned %d!\n",
1640 __func__, cmd, base_status);
1641 }
1642
1643 /* WHAT TO DO HERE IF sas_phy_reset FAILS? */
Dan Williams4393aa42011-03-31 13:10:44 -07001644 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07001645 status = scic_remote_device_reset_complete(&isci_dev->sci);
Dan Williams4393aa42011-03-31 13:10:44 -07001646 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001647
1648 if (status != SCI_SUCCESS) {
1649 scmd_printk(KERN_WARNING, cmd,
1650 "%s: scic_remote_device_reset_complete(%p) "
1651 "returned %d!\n",
1652 __func__, isci_dev, status);
1653 }
1654 /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */
1655
Dan Williams4393aa42011-03-31 13:10:44 -07001656 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001657 "%s: cmd %p, isci_dev %p complete.\n",
1658 __func__, cmd, isci_dev);
1659
Dan Williams6f231dd2011-07-02 22:56:22 -07001660 return TMF_RESP_FUNC_COMPLETE;
1661}