blob: c6f1ffd713a89ca83b7a879673cb88d2f63770ac [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;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700276 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700277
278 dev_dbg(&isci_host->pdev->dev,
279 "%s: isci_tmf = %p\n", __func__, isci_tmf);
280
281 isci_device = isci_tmf->device;
Dan Williams57f20f42011-04-21 18:14:45 -0700282 sci_device = &isci_device->sci;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700283 dev = isci_device->domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700284
285 /* do common allocation and init of request object. */
286 status = isci_request_alloc_tmf(
287 isci_host,
288 isci_tmf,
289 &request,
290 isci_device,
291 GFP_ATOMIC
292 );
293
294 if (status != SCI_SUCCESS)
295 goto out;
296
297 /* let the core do it's construct. */
298 status = scic_task_request_construct(
299 isci_host->core_controller,
300 sci_device,
301 SCI_CONTROLLER_INVALID_IO_TAG,
302 request,
303 request->sci_request_mem_ptr,
304 &request->sci_request_handle
305 );
306
307 if (status != SCI_SUCCESS) {
308 dev_warn(&isci_host->pdev->dev,
309 "%s: scic_task_request_construct failed - "
310 "status = 0x%x\n",
311 __func__,
312 status);
313 goto errout;
314 }
315
316 sci_object_set_association(
317 request->sci_request_handle,
318 request
319 );
320
Dan Williamsa1a113b2011-04-21 18:44:45 -0700321 /* XXX convert to get this from task->tproto like other drivers */
322 if (dev->dev_type == SAS_END_DEV) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700323 isci_tmf->proto = SAS_PROTOCOL_SSP;
324 status = scic_task_request_construct_ssp(
325 request->sci_request_handle
326 );
327 if (status != SCI_SUCCESS)
328 goto errout;
329 }
330
Dan Williamsa1a113b2011-04-21 18:44:45 -0700331 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700332 isci_tmf->proto = SAS_PROTOCOL_SATA;
333 status = isci_sata_management_task_request_build(request);
334
335 if (status != SCI_SUCCESS)
336 goto errout;
337 }
338
339 goto out;
340
341 errout:
342
343 /* release the dma memory if we fail. */
344 isci_request_free(isci_host, request);
345 request = NULL;
346
347 out:
348 *isci_request = request;
349 return status;
350}
351
352/**
353 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
354 * the timeout period for the TMF has expired.
355 *
356 *
357 */
358static void isci_tmf_timeout_cb(void *tmf_request_arg)
359{
360 struct isci_request *request = (struct isci_request *)tmf_request_arg;
361 struct isci_tmf *tmf = isci_request_access_tmf(request);
362 enum sci_status status;
363
Dan Williams6f231dd2011-07-02 22:56:22 -0700364 /* This task management request has timed-out. Terminate the request
365 * so that the request eventually completes to the requestor in the
366 * request completion callback path.
367 */
368 /* Note - the timer callback function itself has provided spinlock
369 * exclusion from the start and completion paths. No need to take
370 * the request->isci_host->scic_lock here.
371 */
372
373 if (tmf->timeout_timer != NULL) {
374 /* Call the users callback, if any. */
375 if (tmf->cb_state_func != NULL)
376 tmf->cb_state_func(isci_tmf_timed_out, tmf,
377 tmf->cb_data);
378
379 /* Terminate the TMF transmit request. */
380 status = scic_controller_terminate_request(
381 request->isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700382 &request->isci_device->sci,
Dan Williams6f231dd2011-07-02 22:56:22 -0700383 request->sci_request_handle
384 );
385
386 dev_dbg(&request->isci_host->pdev->dev,
387 "%s: tmf_request = %p; tmf = %p; status = %d\n",
388 __func__, request, tmf, status);
389 } else
390 dev_dbg(&request->isci_host->pdev->dev,
391 "%s: timer already canceled! "
392 "tmf_request = %p; tmf = %p\n",
393 __func__, request, tmf);
394
395 /* No need to unlock since the caller to this callback is doing it for
396 * us.
397 * request->isci_host->scic_lock
398 */
399}
400
401/**
402 * isci_task_execute_tmf() - This function builds and sends a task request,
403 * then waits for the completion.
404 * @isci_host: This parameter specifies the ISCI host object
405 * @tmf: This parameter is the pointer to the task management structure for
406 * this request.
407 * @timeout_ms: This parameter specifies the timeout period for the task
408 * management request.
409 *
410 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
411 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
412 */
413int isci_task_execute_tmf(
414 struct isci_host *isci_host,
415 struct isci_tmf *tmf,
416 unsigned long timeout_ms)
417{
418 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700419 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700420 struct scic_sds_remote_device *sci_device;
421 struct isci_remote_device *isci_device = tmf->device;
422 struct isci_request *request;
423 int ret = TMF_RESP_FUNC_FAILED;
424 unsigned long flags;
425
426 /* sanity check, return TMF_RESP_FUNC_FAILED
427 * if the device is not there and ready.
428 */
Dan Williams8acaec12011-03-07 14:47:35 -0800429 if (!isci_device || isci_device->status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700430 dev_dbg(&isci_host->pdev->dev,
431 "%s: isci_device = %p not ready (%d)\n",
432 __func__,
Dan Williams8acaec12011-03-07 14:47:35 -0800433 isci_device, isci_device->status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700434 return TMF_RESP_FUNC_FAILED;
435 } else
436 dev_dbg(&isci_host->pdev->dev,
437 "%s: isci_device = %p\n",
438 __func__, isci_device);
439
Dan Williams57f20f42011-04-21 18:14:45 -0700440 sci_device = &isci_device->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700441
442 /* Assign the pointer to the TMF's completion kernel wait structure. */
443 tmf->complete = &completion;
444
445 isci_task_request_build(
446 isci_host,
447 &request,
448 tmf
449 );
450
451 if (!request) {
452 dev_warn(&isci_host->pdev->dev,
453 "%s: isci_task_request_build failed\n",
454 __func__);
455 return TMF_RESP_FUNC_FAILED;
456 }
457
458 /* Allocate the TMF timeout timer. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700459 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800460 tmf->timeout_timer = isci_timer_create(isci_host, request, isci_tmf_timeout_cb);
Dan Williams6f231dd2011-07-02 22:56:22 -0700461
462 /* Start the timer. */
463 if (tmf->timeout_timer)
464 isci_timer_start(tmf->timeout_timer, timeout_ms);
465 else
466 dev_warn(&isci_host->pdev->dev,
467 "%s: isci_timer_create failed!!!!\n",
468 __func__);
469
470 /* start the TMF io. */
471 status = scic_controller_start_task(
472 isci_host->core_controller,
473 sci_device,
474 request->sci_request_handle,
475 SCI_CONTROLLER_INVALID_IO_TAG
476 );
477
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700478 if (status != SCI_TASK_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700479 dev_warn(&isci_host->pdev->dev,
480 "%s: start_io failed - status = 0x%x, request = %p\n",
481 __func__,
482 status,
483 request);
484 goto cleanup_request;
485 }
486
487 /* Call the users callback, if any. */
488 if (tmf->cb_state_func != NULL)
489 tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data);
490
491 /* Change the state of the TMF-bearing request to "started". */
492 isci_request_change_state(request, started);
493
494 /* add the request to the remote device request list. */
495 list_add(&request->dev_node, &isci_device->reqs_in_process);
496
497 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
498
499 /* Wait for the TMF to complete, or a timeout. */
500 wait_for_completion(&completion);
501
502 isci_print_tmf(tmf);
503
504 if (tmf->status == SCI_SUCCESS)
505 ret = TMF_RESP_FUNC_COMPLETE;
506 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
507 dev_dbg(&isci_host->pdev->dev,
508 "%s: tmf.status == "
509 "SCI_FAILURE_IO_RESPONSE_VALID\n",
510 __func__);
511 ret = TMF_RESP_FUNC_COMPLETE;
512 }
513 /* Else - leave the default "failed" status alone. */
514
515 dev_dbg(&isci_host->pdev->dev,
516 "%s: completed request = %p\n",
517 __func__,
518 request);
519
520 if (request->io_request_completion != NULL) {
521
522 /* The fact that this is non-NULL for a TMF request
523 * means there is a thread waiting for this TMF to
524 * finish.
525 */
526 complete(request->io_request_completion);
527 }
528
529 spin_lock_irqsave(&isci_host->scic_lock, flags);
530
531 cleanup_request:
532
533 /* Clean up the timer if needed. */
534 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -0800535 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -0700536 tmf->timeout_timer = NULL;
537 }
538
539 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
540
541 isci_request_free(isci_host, request);
542
543 return ret;
544}
545
546void isci_task_build_tmf(
547 struct isci_tmf *tmf,
548 struct isci_remote_device *isci_device,
549 enum isci_tmf_function_codes code,
550 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
551 struct isci_tmf *,
552 void *),
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800553 void *cb_data)
Dan Williams6f231dd2011-07-02 22:56:22 -0700554{
555 dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
556 "%s: isci_device = %p\n", __func__, isci_device);
557
558 memset(tmf, 0, sizeof(*tmf));
559
560 tmf->device = isci_device;
561 tmf->tmf_code = code;
562 tmf->timeout_timer = NULL;
563 tmf->cb_state_func = tmf_sent_cb;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800564 tmf->cb_data = cb_data;
565}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800566
Dan Williams35173d52011-03-26 16:43:01 -0700567static void isci_task_build_abort_task_tmf(
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800568 struct isci_tmf *tmf,
569 struct isci_remote_device *isci_device,
570 enum isci_tmf_function_codes code,
571 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
572 struct isci_tmf *,
573 void *),
574 struct isci_request *old_request)
575{
576 isci_task_build_tmf(tmf, isci_device, code, tmf_sent_cb,
577 (void *)old_request);
578 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700579}
580
581static struct isci_request *isci_task_get_request_from_task(
582 struct sas_task *task,
Dan Williams6f231dd2011-07-02 22:56:22 -0700583 struct isci_remote_device **isci_device)
584{
585
586 struct isci_request *request = NULL;
587 unsigned long flags;
588
589 spin_lock_irqsave(&task->task_state_lock, flags);
590
591 request = task->lldd_task;
592
593 /* If task is already done, the request isn't valid */
594 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
595 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
596 (request != NULL)) {
597
Dan Williams6f231dd2011-07-02 22:56:22 -0700598 if (isci_device != NULL)
599 *isci_device = request->isci_device;
600 }
601
602 spin_unlock_irqrestore(&task->task_state_lock, flags);
603
604 return request;
605}
606
607/**
608 * isci_task_validate_request_to_abort() - This function checks the given I/O
609 * against the "started" state. If the request is still "started", it's
610 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
611 * BEFORE CALLING THIS FUNCTION.
612 * @isci_request: This parameter specifies the request object to control.
613 * @isci_host: This parameter specifies the ISCI host object
614 * @isci_device: This is the device to which the request is pending.
615 * @aborted_io_completion: This is a completion structure that will be added to
616 * the request in case it is changed to aborting; this completion is
617 * triggered when the request is fully completed.
618 *
619 * Either "started" on successful change of the task status to "aborted", or
620 * "unallocated" if the task cannot be controlled.
621 */
622static enum isci_request_status isci_task_validate_request_to_abort(
623 struct isci_request *isci_request,
624 struct isci_host *isci_host,
625 struct isci_remote_device *isci_device,
626 struct completion *aborted_io_completion)
627{
628 enum isci_request_status old_state = unallocated;
629
630 /* Only abort the task if it's in the
631 * device's request_in_process list
632 */
633 if (isci_request && !list_empty(&isci_request->dev_node)) {
634 old_state = isci_request_change_started_to_aborted(
635 isci_request, aborted_io_completion);
636
Dan Williams6f231dd2011-07-02 22:56:22 -0700637 }
638
639 return old_state;
640}
641
642static void isci_request_cleanup_completed_loiterer(
643 struct isci_host *isci_host,
644 struct isci_remote_device *isci_device,
645 struct isci_request *isci_request)
646{
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800647 struct sas_task *task;
648 unsigned long flags;
649
650 task = (isci_request->ttype == io_task)
651 ? isci_request_access_task(isci_request)
652 : NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700653
654 dev_dbg(&isci_host->pdev->dev,
655 "%s: isci_device=%p, request=%p, task=%p\n",
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800656 __func__, isci_device, isci_request, task);
Dan Williams6f231dd2011-07-02 22:56:22 -0700657
658 spin_lock_irqsave(&isci_host->scic_lock, flags);
659 list_del_init(&isci_request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700660 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
661
Jeff Skirvina5fde222011-03-04 14:06:42 -0800662 if (task != NULL) {
663
664 spin_lock_irqsave(&task->task_state_lock, flags);
665 task->lldd_task = NULL;
666
667 isci_set_task_doneflags(task);
668
669 /* If this task is not in the abort path, call task_done. */
670 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
671
672 spin_unlock_irqrestore(&task->task_state_lock, flags);
673 task->task_done(task);
674 } else
675 spin_unlock_irqrestore(&task->task_state_lock, flags);
676 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700677 isci_request_free(isci_host, isci_request);
678}
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800679
680/**
681* @isci_termination_timed_out(): this function will deal with a request for
682* which the wait for termination has timed-out.
683*
684* @isci_host This SCU.
685* @isci_request The I/O request being terminated.
686*/
687static void
688isci_termination_timed_out(
689 struct isci_host * host,
690 struct isci_request * request
691 )
692{
693 unsigned long state_flags;
694
695 dev_warn(&host->pdev->dev,
696 "%s: host = %p; request = %p\n",
697 __func__, host, request);
698
699 /* At this point, the request to terminate
700 * has timed out. The best we can do is to
701 * have the request die a silent death
702 * if it ever completes.
703 */
704 spin_lock_irqsave(&request->state_lock, state_flags);
705
706 if (request->status == started) {
707
708 /* Set the request state to "dead",
709 * and clear the task pointer so that an actual
710 * completion event callback doesn't do
711 * anything.
712 */
713 request->status = dead;
714
715 /* Clear the timeout completion event pointer.*/
716 request->io_request_completion = NULL;
717
718 if (request->ttype == io_task) {
719
720 /* Break links with the sas_task. */
721 if (request->ttype_ptr.io_task_ptr != NULL) {
722
723 request->ttype_ptr.io_task_ptr->lldd_task = NULL;
724 request->ttype_ptr.io_task_ptr = NULL;
725 }
726 }
727 }
728 spin_unlock_irqrestore(&request->state_lock, state_flags);
729}
730
731
Dan Williams6f231dd2011-07-02 22:56:22 -0700732/**
733 * isci_terminate_request_core() - This function will terminate the given
734 * request, and wait for it to complete. This function must only be called
735 * from a thread that can wait. Note that the request is terminated and
736 * completed (back to the host, if started there).
737 * @isci_host: This SCU.
738 * @isci_device: The target.
739 * @isci_request: The I/O request to be terminated.
740 *
741 *
742 */
743static void isci_terminate_request_core(
744 struct isci_host *isci_host,
745 struct isci_remote_device *isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800746 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700747{
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800748 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700749 bool was_terminated = false;
750 bool needs_cleanup_handling = false;
751 enum isci_request_status request_status;
752 unsigned long flags;
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800753 unsigned long timeout_remaining;
754
Dan Williams6f231dd2011-07-02 22:56:22 -0700755
756 dev_dbg(&isci_host->pdev->dev,
757 "%s: device = %p; request = %p\n",
758 __func__, isci_device, isci_request);
759
Dan Williams6f231dd2011-07-02 22:56:22 -0700760 spin_lock_irqsave(&isci_host->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800761
762 /* Note that we are not going to control
763 * the target to abort the request.
764 */
765 isci_request->complete_in_target = true;
766
Dan Williams6f231dd2011-07-02 22:56:22 -0700767 /* Make sure the request wasn't just sitting around signalling
768 * device condition (if the request handle is NULL, then the
769 * request completed but needed additional handling here).
770 */
771 if (isci_request->sci_request_handle != NULL) {
772 was_terminated = true;
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800773 needs_cleanup_handling = true;
Dan Williams6f231dd2011-07-02 22:56:22 -0700774 status = scic_controller_terminate_request(
775 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -0700776 &isci_device->sci,
777 isci_request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -0700778 }
779 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
780
781 /*
782 * The only time the request to terminate will
783 * fail is when the io request is completed and
784 * being aborted.
785 */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800786 if (status != SCI_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700787 dev_err(&isci_host->pdev->dev,
788 "%s: scic_controller_terminate_request"
789 " returned = 0x%x\n",
790 __func__,
791 status);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800792 /* Clear the completion pointer from the request. */
793 isci_request->io_request_completion = NULL;
794
795 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700796 if (was_terminated) {
797 dev_dbg(&isci_host->pdev->dev,
798 "%s: before completion wait (%p)\n",
799 __func__,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800800 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700801
802 /* Wait here for the request to complete. */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800803 #define TERMINATION_TIMEOUT_MSEC 50
804 timeout_remaining
805 = wait_for_completion_timeout(
806 isci_request->io_request_completion,
807 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC));
Dan Williams6f231dd2011-07-02 22:56:22 -0700808
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800809 if (!timeout_remaining) {
810
811 isci_termination_timed_out(isci_host,
812 isci_request);
813
814 dev_err(&isci_host->pdev->dev,
815 "%s: *** Timeout waiting for "
816 "termination(%p/%p)\n",
817 __func__,
818 isci_request->io_request_completion,
819 isci_request);
820
821 } else
822 dev_dbg(&isci_host->pdev->dev,
823 "%s: after completion wait (%p)\n",
824 __func__,
825 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700826 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800827 /* Clear the completion pointer from the request. */
828 isci_request->io_request_completion = NULL;
829
830 /* Peek at the status of the request. This will tell
831 * us if there was special handling on the request such that it
832 * needs to be detached and freed here.
833 */
834 spin_lock_irqsave(&isci_request->state_lock, flags);
835 request_status = isci_request_get_state(isci_request);
836
837 if ((isci_request->ttype == io_task) /* TMFs are in their own thread */
838 && ((request_status == aborted)
839 || (request_status == aborting)
840 || (request_status == terminating)
841 || (request_status == completed)
842 || (request_status == dead)
843 )
844 ) {
845
846 /* The completion routine won't free a request in
847 * the aborted/aborting/etc. states, so we do
848 * it here.
849 */
850 needs_cleanup_handling = true;
851 }
852 spin_unlock_irqrestore(&isci_request->state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700853
854 if (needs_cleanup_handling)
855 isci_request_cleanup_completed_loiterer(
856 isci_host, isci_device, isci_request
857 );
858 }
859}
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800860
Dan Williams6f231dd2011-07-02 22:56:22 -0700861static void isci_terminate_request(
862 struct isci_host *isci_host,
863 struct isci_remote_device *isci_device,
864 struct isci_request *isci_request,
865 enum isci_request_status new_request_state)
866{
867 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -0700868 DECLARE_COMPLETION_ONSTACK(request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700869
870 /* Change state to "new_request_state" if it is currently "started" */
871 old_state = isci_request_change_started_to_newstate(
872 isci_request,
873 &request_completion,
874 new_request_state
875 );
876
Jeff Skirvinf219f012011-03-31 13:10:34 -0700877 if ((old_state == started) ||
878 (old_state == completed) ||
879 (old_state == aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700880
Jeff Skirvina5fde222011-03-04 14:06:42 -0800881 /* If the old_state is started:
882 * This request was not already being aborted. If it had been,
Dan Williams6f231dd2011-07-02 22:56:22 -0700883 * then the aborting I/O (ie. the TMF request) would not be in
884 * the aborting state, and thus would be terminated here. Note
885 * that since the TMF completion's call to the kernel function
886 * "complete()" does not happen until the pending I/O request
887 * terminate fully completes, we do not have to implement a
888 * special wait here for already aborting requests - the
889 * termination of the TMF request will force the request
890 * to finish it's already started terminate.
Jeff Skirvina5fde222011-03-04 14:06:42 -0800891 *
892 * If old_state == completed:
893 * This request completed from the SCU hardware perspective
894 * and now just needs cleaning up in terms of freeing the
895 * request and potentially calling up to libsas.
Jeff Skirvinf219f012011-03-31 13:10:34 -0700896 *
897 * If old_state == aborting:
898 * This request has already gone through a TMF timeout, but may
899 * not have been terminated; needs cleaning up at least.
Dan Williams6f231dd2011-07-02 22:56:22 -0700900 */
901 isci_terminate_request_core(isci_host, isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800902 isci_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800903 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700904}
905
906/**
907 * isci_terminate_pending_requests() - This function will change the all of the
908 * requests on the given device's state to "aborting", will terminate the
909 * requests, and wait for them to complete. This function must only be
910 * called from a thread that can wait. Note that the requests are all
911 * terminated and completed (back to the host, if started there).
912 * @isci_host: This parameter specifies SCU.
913 * @isci_device: This parameter specifies the target.
914 *
915 *
916 */
917void isci_terminate_pending_requests(
918 struct isci_host *isci_host,
919 struct isci_remote_device *isci_device,
920 enum isci_request_status new_request_state)
921{
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800922 struct isci_request *request;
923 struct isci_request *next_request;
924 unsigned long flags;
925 struct list_head aborted_request_list;
926
927 INIT_LIST_HEAD(&aborted_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700928
929 dev_dbg(&isci_host->pdev->dev,
930 "%s: isci_device = %p (new request state = %d)\n",
931 __func__, isci_device, new_request_state);
932
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800933 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700934
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800935 /* Move all of the pending requests off of the device list. */
936 list_splice_init(&isci_device->reqs_in_process,
937 &aborted_request_list);
938
939 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
940
941 /* Iterate through the now-local list. */
942 list_for_each_entry_safe(request, next_request,
943 &aborted_request_list, dev_node) {
944
945 dev_warn(&isci_host->pdev->dev,
946 "%s: isci_device=%p request=%p; task=%p\n",
947 __func__,
948 isci_device, request,
949 ((request->ttype == io_task)
950 ? isci_request_access_task(request)
951 : NULL));
952
953 /* Mark all still pending I/O with the selected next
954 * state, terminate and free it.
955 */
956 isci_terminate_request(isci_host, isci_device,
957 request, new_request_state
958 );
Dan Williams6f231dd2011-07-02 22:56:22 -0700959 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700960}
961
962/**
963 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
964 * Template functions.
965 * @lun: This parameter specifies the lun to be reset.
966 *
967 * status, zero indicates success.
968 */
969static int isci_task_send_lu_reset_sas(
970 struct isci_host *isci_host,
971 struct isci_remote_device *isci_device,
972 u8 *lun)
973{
974 struct isci_tmf tmf;
975 int ret = TMF_RESP_FUNC_FAILED;
976
977 dev_dbg(&isci_host->pdev->dev,
978 "%s: isci_host = %p, isci_device = %p\n",
979 __func__, isci_host, isci_device);
980 /* Send the LUN reset to the target. By the time the call returns,
981 * the TMF has fully exected in the target (in which case the return
982 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
983 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
984 */
985 isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_lun_reset, NULL,
986 NULL);
987
988 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
989 ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
990
991 if (ret == TMF_RESP_FUNC_COMPLETE)
992 dev_dbg(&isci_host->pdev->dev,
993 "%s: %p: TMF_LU_RESET passed\n",
994 __func__, isci_device);
995 else
996 dev_dbg(&isci_host->pdev->dev,
997 "%s: %p: TMF_LU_RESET failed (%x)\n",
998 __func__, isci_device, ret);
999
1000 return ret;
1001}
1002
1003/**
1004 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1005 * functions. This is one of the Task Management functoins called by libsas,
1006 * to reset the given lun. Note the assumption that while this call is
1007 * executing, no I/O will be sent by the host to the device.
1008 * @lun: This parameter specifies the lun to be reset.
1009 *
1010 * status, zero indicates success.
1011 */
Dan Williams4393aa42011-03-31 13:10:44 -07001012int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
Dan Williams6f231dd2011-07-02 22:56:22 -07001013{
Dan Williams4393aa42011-03-31 13:10:44 -07001014 struct isci_host *isci_host = dev_to_ihost(domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001015 struct isci_remote_device *isci_device = NULL;
1016 int ret;
1017 bool device_stopping = false;
1018
Dan Williams4393aa42011-03-31 13:10:44 -07001019 isci_device = domain_device->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001020
Dan Williams4393aa42011-03-31 13:10:44 -07001021 dev_dbg(&isci_host->pdev->dev,
1022 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07001023 __func__, domain_device, isci_host, isci_device);
1024
1025 if (isci_device != NULL)
1026 device_stopping = (isci_device->status == isci_stopping)
1027 || (isci_device->status == isci_stopped);
1028
1029 /* If there is a device reset pending on any request in the
1030 * device's list, fail this LUN reset request in order to
1031 * escalate to the device reset.
1032 */
Dan Williams4393aa42011-03-31 13:10:44 -07001033 if (!isci_device || device_stopping ||
1034 isci_device_is_reset_pending(isci_host, isci_device)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001035 dev_warn(&isci_host->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -07001036 "%s: No dev (%p), or "
Dan Williams6f231dd2011-07-02 22:56:22 -07001037 "RESET PENDING: domain_device=%p\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001038 __func__, isci_device, domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001039 return TMF_RESP_FUNC_FAILED;
1040 }
1041
Dan Williams6f231dd2011-07-02 22:56:22 -07001042 /* Send the task management part of the reset. */
1043 if (sas_protocol_ata(domain_device->tproto)) {
Dan Williams4393aa42011-03-31 13:10:44 -07001044 ret = isci_task_send_lu_reset_sata(isci_host, isci_device, lun);
Dan Williams6f231dd2011-07-02 22:56:22 -07001045 } else
1046 ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun);
1047
1048 /* If the LUN reset worked, all the I/O can now be terminated. */
1049 if (ret == TMF_RESP_FUNC_COMPLETE)
1050 /* Terminate all I/O now. */
1051 isci_terminate_pending_requests(isci_host,
1052 isci_device,
1053 terminating);
1054
Dan Williams6f231dd2011-07-02 22:56:22 -07001055 return ret;
1056}
1057
1058
1059/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1060int isci_task_clear_nexus_port(struct asd_sas_port *port)
1061{
1062 return TMF_RESP_FUNC_FAILED;
1063}
1064
1065
1066
1067int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
1068{
1069 return TMF_RESP_FUNC_FAILED;
1070}
1071
1072int isci_task_I_T_nexus_reset(struct domain_device *dev)
1073{
1074 return TMF_RESP_FUNC_FAILED;
1075}
1076
1077
1078/* Task Management Functions. Must be called from process context. */
1079
1080/**
1081 * isci_abort_task_process_cb() - This is a helper function for the abort task
1082 * TMF command. It manages the request state with respect to the successful
1083 * transmission / completion of the abort task request.
1084 * @cb_state: This parameter specifies when this function was called - after
1085 * the TMF request has been started and after it has timed-out.
1086 * @tmf: This parameter specifies the TMF in progress.
1087 *
1088 *
1089 */
1090static void isci_abort_task_process_cb(
1091 enum isci_tmf_cb_state cb_state,
1092 struct isci_tmf *tmf,
1093 void *cb_data)
1094{
1095 struct isci_request *old_request;
1096
1097 old_request = (struct isci_request *)cb_data;
1098
1099 dev_dbg(&old_request->isci_host->pdev->dev,
1100 "%s: tmf=%p, old_request=%p\n",
1101 __func__, tmf, old_request);
1102
1103 switch (cb_state) {
1104
1105 case isci_tmf_started:
1106 /* The TMF has been started. Nothing to do here, since the
1107 * request state was already set to "aborted" by the abort
1108 * task function.
1109 */
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001110 if ((old_request->status != aborted)
1111 && (old_request->status != completed))
1112 dev_err(&old_request->isci_host->pdev->dev,
1113 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1114 __func__, old_request->status, tmf, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001115 break;
1116
1117 case isci_tmf_timed_out:
1118
1119 /* Set the task's state to "aborting", since the abort task
1120 * function thread set it to "aborted" (above) in anticipation
1121 * of the task management request working correctly. Since the
1122 * timeout has now fired, the TMF request failed. We set the
1123 * state such that the request completion will indicate the
1124 * device is no longer present.
1125 */
1126 isci_request_change_state(old_request, aborting);
1127 break;
1128
1129 default:
1130 dev_err(&old_request->isci_host->pdev->dev,
1131 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1132 __func__, cb_state, tmf, old_request);
1133 break;
1134 }
1135}
1136
1137/**
1138 * isci_task_abort_task() - This function is one of the SAS Domain Template
1139 * functions. This function is called by libsas to abort a specified task.
1140 * @task: This parameter specifies the SAS task to abort.
1141 *
1142 * status, zero indicates success.
1143 */
1144int isci_task_abort_task(struct sas_task *task)
1145{
Dan Williams4393aa42011-03-31 13:10:44 -07001146 struct isci_host *isci_host = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001147 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001148 struct isci_request *old_request = NULL;
1149 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -07001150 struct isci_remote_device *isci_device = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001151 struct isci_tmf tmf;
1152 int ret = TMF_RESP_FUNC_FAILED;
1153 unsigned long flags;
1154 bool any_dev_reset = false;
1155 bool device_stopping;
Dan Williams6f231dd2011-07-02 22:56:22 -07001156
1157 /* Get the isci_request reference from the task. Note that
1158 * this check does not depend on the pending request list
1159 * in the device, because tasks driving resets may land here
1160 * after completion in the core.
1161 */
Dan Williams4393aa42011-03-31 13:10:44 -07001162 old_request = isci_task_get_request_from_task(task, &isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001163
1164 dev_dbg(&isci_host->pdev->dev,
1165 "%s: task = %p\n", __func__, task);
1166
1167 /* Check if the device has been / is currently being removed.
1168 * If so, no task management will be done, and the I/O will
1169 * be terminated.
1170 */
1171 device_stopping = (isci_device->status == isci_stopping)
1172 || (isci_device->status == isci_stopped);
1173
Dan Williams6f231dd2011-07-02 22:56:22 -07001174 /* This version of the driver will fail abort requests for
1175 * SATA/STP. Failing the abort request this way will cause the
1176 * SCSI error handler thread to escalate to LUN reset
1177 */
1178 if (sas_protocol_ata(task->task_proto) && !device_stopping) {
1179 dev_warn(&isci_host->pdev->dev,
1180 " task %p is for a STP/SATA device;"
1181 " returning TMF_RESP_FUNC_FAILED\n"
1182 " to cause a LUN reset...\n", task);
1183 return TMF_RESP_FUNC_FAILED;
1184 }
1185
1186 dev_dbg(&isci_host->pdev->dev,
1187 "%s: old_request == %p\n", __func__, old_request);
1188
Jeff Skirvina5fde222011-03-04 14:06:42 -08001189 if (!device_stopping)
1190 any_dev_reset = isci_device_is_reset_pending(isci_host,isci_device);
1191
Dan Williams6f231dd2011-07-02 22:56:22 -07001192 spin_lock_irqsave(&task->task_state_lock, flags);
1193
1194 /* Don't do resets to stopping devices. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001195 if (device_stopping) {
1196
Dan Williams6f231dd2011-07-02 22:56:22 -07001197 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001198 any_dev_reset = false;
Dan Williams6f231dd2011-07-02 22:56:22 -07001199
Jeff Skirvina5fde222011-03-04 14:06:42 -08001200 } else /* See if there is a pending device reset for this device. */
Dan Williams6f231dd2011-07-02 22:56:22 -07001201 any_dev_reset = any_dev_reset
Jeff Skirvina5fde222011-03-04 14:06:42 -08001202 || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
Dan Williams6f231dd2011-07-02 22:56:22 -07001203
1204 /* If the extraction of the request reference from the task
1205 * failed, then the request has been completed (or if there is a
1206 * pending reset then this abort request function must be failed
1207 * in order to escalate to the target reset).
1208 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001209 if ((old_request == NULL) || any_dev_reset) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001210
1211 /* If the device reset task flag is set, fail the task
1212 * management request. Otherwise, the original request
1213 * has completed.
1214 */
1215 if (any_dev_reset) {
1216
1217 /* Turn off the task's DONE to make sure this
1218 * task is escalated to a target reset.
1219 */
1220 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1221
Jeff Skirvina5fde222011-03-04 14:06:42 -08001222 /* Make the reset happen as soon as possible. */
1223 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1224
1225 spin_unlock_irqrestore(&task->task_state_lock, flags);
1226
Dan Williams6f231dd2011-07-02 22:56:22 -07001227 /* Fail the task management request in order to
1228 * escalate to the target reset.
1229 */
1230 ret = TMF_RESP_FUNC_FAILED;
1231
1232 dev_dbg(&isci_host->pdev->dev,
1233 "%s: Failing task abort in order to "
1234 "escalate to target reset because\n"
1235 "SAS_TASK_NEED_DEV_RESET is set for "
1236 "task %p on dev %p\n",
1237 __func__, task, isci_device);
1238
Jeff Skirvina5fde222011-03-04 14:06:42 -08001239
Dan Williams6f231dd2011-07-02 22:56:22 -07001240 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -07001241 /* The request has already completed and there
1242 * is nothing to do here other than to set the task
1243 * done bit, and indicate that the task abort function
1244 * was sucessful.
1245 */
1246 isci_set_task_doneflags(task);
1247
Jeff Skirvina5fde222011-03-04 14:06:42 -08001248 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001249
Jeff Skirvina5fde222011-03-04 14:06:42 -08001250 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001251
Jeff Skirvina5fde222011-03-04 14:06:42 -08001252 dev_dbg(&isci_host->pdev->dev,
1253 "%s: abort task not needed for %p\n",
1254 __func__, task);
Dan Williams6f231dd2011-07-02 22:56:22 -07001255 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001256
1257 return ret;
1258 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001259 else
1260 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001261
1262 spin_lock_irqsave(&isci_host->scic_lock, flags);
1263
Jeff Skirvinf219f012011-03-31 13:10:34 -07001264 /* Check the request status and change to "aborted" if currently
Jeff Skirvina5fde222011-03-04 14:06:42 -08001265 * "starting"; if true then set the I/O kernel completion
Dan Williams6f231dd2011-07-02 22:56:22 -07001266 * struct that will be triggered when the request completes.
1267 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001268 old_state = isci_task_validate_request_to_abort(
1269 old_request, isci_host, isci_device,
1270 &aborted_io_completion);
Jeff Skirvinf219f012011-03-31 13:10:34 -07001271 if ((old_state != started) &&
1272 (old_state != completed) &&
1273 (old_state != aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001274
1275 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1276
Jeff Skirvina5fde222011-03-04 14:06:42 -08001277 /* The request was already being handled by someone else (because
1278 * they got to set the state away from started).
1279 */
1280 dev_dbg(&isci_host->pdev->dev,
1281 "%s: device = %p; old_request %p already being aborted\n",
1282 __func__,
1283 isci_device, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001284
1285 return TMF_RESP_FUNC_COMPLETE;
1286 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001287 if ((task->task_proto == SAS_PROTOCOL_SMP)
1288 || device_stopping
1289 || old_request->complete_in_target
1290 ) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001291
1292 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1293
Jeff Skirvina5fde222011-03-04 14:06:42 -08001294 dev_dbg(&isci_host->pdev->dev,
1295 "%s: SMP request (%d)"
1296 " or device is stopping (%d)"
1297 " or complete_in_target (%d), thus no TMF\n",
1298 __func__, (task->task_proto == SAS_PROTOCOL_SMP),
1299 device_stopping, old_request->complete_in_target);
1300
Dan Williams6f231dd2011-07-02 22:56:22 -07001301 /* Set the state on the task. */
1302 isci_task_all_done(task);
1303
1304 ret = TMF_RESP_FUNC_COMPLETE;
1305
1306 /* Stopping and SMP devices are not sent a TMF, and are not
Jeff Skirvina5fde222011-03-04 14:06:42 -08001307 * reset, but the outstanding I/O request is terminated below.
Dan Williams6f231dd2011-07-02 22:56:22 -07001308 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001309 } else {
1310 /* Fill in the tmf stucture */
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -08001311 isci_task_build_abort_task_tmf(&tmf, isci_device,
1312 isci_tmf_ssp_task_abort,
1313 isci_abort_task_process_cb,
1314 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001315
Dan Williams6f231dd2011-07-02 22:56:22 -07001316 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1317
1318 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1319 ret = isci_task_execute_tmf(isci_host, &tmf,
1320 ISCI_ABORT_TASK_TIMEOUT_MS);
1321
Jeff Skirvina5fde222011-03-04 14:06:42 -08001322 if (ret != TMF_RESP_FUNC_COMPLETE)
Dan Williams6f231dd2011-07-02 22:56:22 -07001323 dev_err(&isci_host->pdev->dev,
1324 "%s: isci_task_send_tmf failed\n",
1325 __func__);
1326 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001327 if (ret == TMF_RESP_FUNC_COMPLETE) {
1328 old_request->complete_in_target = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07001329
Jeff Skirvina5fde222011-03-04 14:06:42 -08001330 /* Clean up the request on our side, and wait for the aborted I/O to
1331 * complete.
1332 */
Jeff Skirvincbb65c62011-03-04 14:06:50 -08001333 isci_terminate_request_core(isci_host, isci_device, old_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001334 }
1335
1336 /* Make sure we do not leave a reference to aborted_io_completion */
1337 old_request->io_request_completion = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -07001338 return ret;
1339}
1340
1341/**
1342 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1343 * functions. This is one of the Task Management functoins called by libsas,
1344 * to abort all task for the given lun.
1345 * @d_device: This parameter specifies the domain device associated with this
1346 * request.
1347 * @lun: This parameter specifies the lun associated with this request.
1348 *
1349 * status, zero indicates success.
1350 */
1351int isci_task_abort_task_set(
1352 struct domain_device *d_device,
1353 u8 *lun)
1354{
1355 return TMF_RESP_FUNC_FAILED;
1356}
1357
1358
1359/**
1360 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1361 * functions. This is one of the Task Management functoins called by libsas.
1362 * @d_device: This parameter specifies the domain device associated with this
1363 * request.
1364 * @lun: This parameter specifies the lun associated with this request.
1365 *
1366 * status, zero indicates success.
1367 */
1368int isci_task_clear_aca(
1369 struct domain_device *d_device,
1370 u8 *lun)
1371{
1372 return TMF_RESP_FUNC_FAILED;
1373}
1374
1375
1376
1377/**
1378 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1379 * functions. This is one of the Task Management functoins called by libsas.
1380 * @d_device: This parameter specifies the domain device associated with this
1381 * request.
1382 * @lun: This parameter specifies the lun associated with this request.
1383 *
1384 * status, zero indicates success.
1385 */
1386int isci_task_clear_task_set(
1387 struct domain_device *d_device,
1388 u8 *lun)
1389{
1390 return TMF_RESP_FUNC_FAILED;
1391}
1392
1393
1394/**
1395 * isci_task_query_task() - This function is implemented to cause libsas to
1396 * correctly escalate the failed abort to a LUN or target reset (this is
1397 * because sas_scsi_find_task libsas function does not correctly interpret
1398 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1399 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1400 * returned, libsas will turn this into a target reset
1401 * @task: This parameter specifies the sas task being queried.
1402 * @lun: This parameter specifies the lun associated with this request.
1403 *
1404 * status, zero indicates success.
1405 */
1406int isci_task_query_task(
1407 struct sas_task *task)
1408{
1409 /* See if there is a pending device reset for this device. */
1410 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1411 return TMF_RESP_FUNC_FAILED;
1412 else
1413 return TMF_RESP_FUNC_SUCC;
1414}
1415
1416/**
1417 * isci_task_request_complete() - This function is called by the sci core when
1418 * an task request completes.
1419 * @isci_host: This parameter specifies the ISCI host object
1420 * @request: This parameter is the completed isci_request object.
1421 * @completion_status: This parameter specifies the completion status from the
1422 * sci core.
1423 *
1424 * none.
1425 */
1426void isci_task_request_complete(
1427 struct isci_host *isci_host,
1428 struct isci_request *request,
1429 enum sci_task_status completion_status)
1430{
1431 struct isci_remote_device *isci_device = request->isci_device;
1432 enum isci_request_status old_state;
1433 struct isci_tmf *tmf = isci_request_access_tmf(request);
1434 struct completion *tmf_complete;
1435
1436 dev_dbg(&isci_host->pdev->dev,
1437 "%s: request = %p, status=%d\n",
1438 __func__, request, completion_status);
1439
1440 old_state = isci_request_change_state(request, completed);
1441
1442 tmf->status = completion_status;
1443 request->complete_in_target = true;
1444
1445 if (SAS_PROTOCOL_SSP == tmf->proto) {
1446
1447 memcpy(&tmf->resp.resp_iu,
1448 scic_io_request_get_response_iu_address(
1449 request->sci_request_handle
1450 ),
1451 sizeof(struct sci_ssp_response_iu));
1452
1453 } else if (SAS_PROTOCOL_SATA == tmf->proto) {
1454
1455 memcpy(&tmf->resp.d2h_fis,
1456 scic_stp_io_request_get_d2h_reg_address(
1457 request->sci_request_handle
1458 ),
1459 sizeof(struct sata_fis_reg_d2h)
1460 );
1461 }
1462
1463 /* Manage the timer if it is still running. */
1464 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -08001465 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -07001466 tmf->timeout_timer = NULL;
1467 }
1468
1469 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1470 tmf_complete = tmf->complete;
1471
Christoph Hellwigc6295822011-04-02 08:15:20 -04001472 scic_controller_complete_io(
Dan Williams6f231dd2011-07-02 22:56:22 -07001473 isci_host->core_controller,
Dan Williams57f20f42011-04-21 18:14:45 -07001474 &isci_device->sci,
1475 request->sci_request_handle);
Dan Williams6f231dd2011-07-02 22:56:22 -07001476 /* NULL the request handle to make sure it cannot be terminated
1477 * or completed again.
1478 */
1479 request->sci_request_handle = NULL;
1480
1481 isci_request_change_state(request, unallocated);
1482 list_del_init(&request->dev_node);
1483
1484 /* The task management part completes last. */
1485 complete(tmf_complete);
1486}
1487
1488
1489/**
1490 * isci_task_ssp_request_get_lun() - This function is called by the sci core to
1491 * retrieve the lun for a given task request.
1492 * @request: This parameter is the isci_request object.
1493 *
1494 * lun for specified task request.
1495 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001496
1497/**
1498 * isci_task_ssp_request_get_function() - This function is called by the sci
1499 * core to retrieve the function for a given task request.
1500 * @request: This parameter is the isci_request object.
1501 *
1502 * function code for specified task request.
1503 */
1504u8 isci_task_ssp_request_get_function(struct isci_request *request)
1505{
1506 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1507
1508 dev_dbg(&request->isci_host->pdev->dev,
1509 "%s: func = %d\n", __func__, isci_tmf->tmf_code);
1510
1511 return isci_tmf->tmf_code;
1512}
1513
1514/**
1515 * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by
1516 * the sci core to retrieve the io tag for a given task request.
1517 * @request: This parameter is the isci_request object.
1518 *
1519 * io tag for specified task request.
1520 */
1521u16 isci_task_ssp_request_get_io_tag_to_manage(struct isci_request *request)
1522{
1523 u16 io_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1524
1525 if (tmf_task == request->ttype) {
1526 struct isci_tmf *tmf = isci_request_access_tmf(request);
1527 io_tag = tmf->io_tag;
1528 }
1529
1530 dev_dbg(&request->isci_host->pdev->dev,
1531 "%s: request = %p, io_tag = %d\n",
1532 __func__, request, io_tag);
1533
1534 return io_tag;
1535}
1536
1537/**
1538 * isci_task_ssp_request_get_response_data_address() - This function is called
1539 * by the sci core to retrieve the response data address for a given task
1540 * request.
1541 * @request: This parameter is the isci_request object.
1542 *
1543 * response data address for specified task request.
1544 */
1545void *isci_task_ssp_request_get_response_data_address(
1546 struct isci_request *request)
1547{
1548 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1549
1550 return &isci_tmf->resp.resp_iu;
1551}
1552
1553/**
1554 * isci_task_ssp_request_get_response_data_length() - This function is called
1555 * by the sci core to retrieve the response data length for a given task
1556 * request.
1557 * @request: This parameter is the isci_request object.
1558 *
1559 * response data length for specified task request.
1560 */
1561u32 isci_task_ssp_request_get_response_data_length(
1562 struct isci_request *request)
1563{
1564 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1565
1566 return sizeof(isci_tmf->resp.resp_iu);
1567}
1568
1569/**
1570 * isci_bus_reset_handler() - This function performs a target reset of the
1571 * device referenced by "cmd'. This function is exported through the
1572 * "struct scsi_host_template" structure such that it is called when an I/O
1573 * recovery process has escalated to a target reset. Note that this function
1574 * is called from the scsi error handler event thread, so may block on calls.
1575 * @scsi_cmd: This parameter specifies the target to be reset.
1576 *
1577 * SUCCESS if the reset process was successful, else FAILED.
1578 */
1579int isci_bus_reset_handler(struct scsi_cmnd *cmd)
1580{
Dan Williams4393aa42011-03-31 13:10:44 -07001581 struct domain_device *dev = cmd_to_domain_dev(cmd);
1582 struct isci_host *isci_host = dev_to_ihost(dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001583 unsigned long flags = 0;
Dan Williams6f231dd2011-07-02 22:56:22 -07001584 enum sci_status status;
1585 int base_status;
Dan Williams4393aa42011-03-31 13:10:44 -07001586 struct isci_remote_device *isci_dev = dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001587
Dan Williams4393aa42011-03-31 13:10:44 -07001588 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001589 "%s: cmd %p, isci_dev %p\n",
1590 __func__, cmd, isci_dev);
1591
1592 if (!isci_dev) {
Dan Williams4393aa42011-03-31 13:10:44 -07001593 dev_warn(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001594 "%s: isci_dev is GONE!\n",
1595 __func__);
1596
1597 return TMF_RESP_FUNC_COMPLETE; /* Nothing to reset. */
1598 }
1599
Dan Williams4393aa42011-03-31 13:10:44 -07001600 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07001601 status = scic_remote_device_reset(&isci_dev->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07001602 if (status != SCI_SUCCESS) {
Dan Williams4393aa42011-03-31 13:10:44 -07001603 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001604
1605 scmd_printk(KERN_WARNING, cmd,
1606 "%s: scic_remote_device_reset(%p) returned %d!\n",
1607 __func__, isci_dev, status);
1608
1609 return TMF_RESP_FUNC_FAILED;
1610 }
Dan Williams4393aa42011-03-31 13:10:44 -07001611 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001612
Dan Williams6f231dd2011-07-02 22:56:22 -07001613 /* Make sure all pending requests are able to be fully terminated. */
Dan Williams4393aa42011-03-31 13:10:44 -07001614 isci_device_clear_reset_pending(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001615
1616 /* Terminate in-progress I/O now. */
Dan Williams4393aa42011-03-31 13:10:44 -07001617 isci_remote_device_nuke_requests(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001618
1619 /* Call into the libsas default handler (which calls sas_phy_reset). */
1620 base_status = sas_eh_bus_reset_handler(cmd);
1621
1622 if (base_status != SUCCESS) {
1623
1624 /* There can be cases where the resets to individual devices
1625 * behind an expander will fail because of an unplug of the
1626 * expander itself.
1627 */
1628 scmd_printk(KERN_WARNING, cmd,
1629 "%s: sas_eh_bus_reset_handler(%p) returned %d!\n",
1630 __func__, cmd, base_status);
1631 }
1632
1633 /* WHAT TO DO HERE IF sas_phy_reset FAILS? */
Dan Williams4393aa42011-03-31 13:10:44 -07001634 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07001635 status = scic_remote_device_reset_complete(&isci_dev->sci);
Dan Williams4393aa42011-03-31 13:10:44 -07001636 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001637
1638 if (status != SCI_SUCCESS) {
1639 scmd_printk(KERN_WARNING, cmd,
1640 "%s: scic_remote_device_reset_complete(%p) "
1641 "returned %d!\n",
1642 __func__, isci_dev, status);
1643 }
1644 /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */
1645
Dan Williams4393aa42011-03-31 13:10:44 -07001646 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001647 "%s: cmd %p, isci_dev %p complete.\n",
1648 __func__, cmd, isci_dev);
1649
Dan Williams6f231dd2011-07-02 22:56:22 -07001650 return TMF_RESP_FUNC_COMPLETE;
1651}