blob: c79968db871cc7a687fef1804817eed1747e2153 [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"
59#include "scic_remote_device.h"
60#include "scic_io_request.h"
61#include "scic_sds_remote_device.h"
62#include "scic_sds_remote_node_context.h"
63#include "isci.h"
64#include "request.h"
65#include "sata.h"
66#include "task.h"
67
Dan Williams50e7f9b2011-03-09 21:27:46 -080068/**
Dan Williams1077a572011-03-11 10:13:51 -080069* isci_task_refuse() - complete the request to the upper layer driver in
70* the case where an I/O needs to be completed back in the submit path.
71* @ihost: host on which the the request was queued
72* @task: request to complete
73* @response: response code for the completed task.
74* @status: status code for the completed task.
Dan Williams50e7f9b2011-03-09 21:27:46 -080075*
Dan Williams50e7f9b2011-03-09 21:27:46 -080076*/
Dan Williams1077a572011-03-11 10:13:51 -080077static void isci_task_refuse(struct isci_host *ihost, struct sas_task *task,
78 enum service_response response,
79 enum exec_status status)
Dan Williams50e7f9b2011-03-09 21:27:46 -080080
Dan Williams1077a572011-03-11 10:13:51 -080081{
82 enum isci_completion_selection disposition;
83
84 disposition = isci_perform_normal_io_completion;
85 disposition = isci_task_set_completion_status(task, response, status,
86 disposition);
Dan Williams50e7f9b2011-03-09 21:27:46 -080087
88 /* Tasks aborted specifically by a call to the lldd_abort_task
Dan Williams1077a572011-03-11 10:13:51 -080089 * function should not be completed to the host in the regular path.
90 */
91 switch (disposition) {
Dan Williams50e7f9b2011-03-09 21:27:46 -080092 case isci_perform_normal_io_completion:
93 /* Normal notification (task_done) */
Dan Williams1077a572011-03-11 10:13:51 -080094 dev_dbg(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -070095 "%s: Normal - task = %p, response=%d, "
96 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -080097 __func__, task, response, status);
98
Dan Williams1077a572011-03-11 10:13:51 -080099 task->lldd_task = NULL;
Dan Williams50e7f9b2011-03-09 21:27:46 -0800100
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700101 isci_execpath_callback(ihost, task, task->task_done);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800102 break;
103
104 case isci_perform_aborted_io_completion:
105 /* No notification because this request is already in the
106 * abort path.
107 */
Dan Williams1077a572011-03-11 10:13:51 -0800108 dev_warn(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700109 "%s: Aborted - task = %p, response=%d, "
110 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -0800111 __func__, task, response, status);
112 break;
113
114 case isci_perform_error_io_completion:
115 /* Use sas_task_abort */
Dan Williams1077a572011-03-11 10:13:51 -0800116 dev_warn(&ihost->pdev->dev,
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700117 "%s: Error - task = %p, response=%d, "
118 "status=%d\n",
Dan Williams50e7f9b2011-03-09 21:27:46 -0800119 __func__, task, response, status);
Jeff Skirvined8a72d2011-03-31 13:10:40 -0700120
121 isci_execpath_callback(ihost, task, sas_task_abort);
Dan Williams50e7f9b2011-03-09 21:27:46 -0800122 break;
123
124 default:
Dan Williams1077a572011-03-11 10:13:51 -0800125 dev_warn(&ihost->pdev->dev,
Dan Williams50e7f9b2011-03-09 21:27:46 -0800126 "%s: isci task notification default case!",
127 __func__);
128 sas_task_abort(task);
129 break;
130 }
131}
Dan Williams6f231dd2011-07-02 22:56:22 -0700132
Dan Williams1077a572011-03-11 10:13:51 -0800133#define for_each_sas_task(num, task) \
134 for (; num > 0; num--,\
135 task = list_entry(task->list.next, struct sas_task, list))
136
Dan Williams6f231dd2011-07-02 22:56:22 -0700137/**
138 * isci_task_execute_task() - This function is one of the SAS Domain Template
139 * functions. This function is called by libsas to send a task down to
140 * hardware.
141 * @task: This parameter specifies the SAS task to send.
142 * @num: This parameter specifies the number of tasks to queue.
143 * @gfp_flags: This parameter specifies the context of this call.
144 *
145 * status, zero indicates success.
146 */
147int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags)
148{
Dan Williams4393aa42011-03-31 13:10:44 -0700149 struct isci_host *ihost = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700150 struct isci_request *request = NULL;
151 struct isci_remote_device *device;
152 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700153 int ret;
154 enum sci_status status;
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700155 enum isci_status device_status;
Dan Williams6f231dd2011-07-02 22:56:22 -0700156
Dan Williams1077a572011-03-11 10:13:51 -0800157 dev_dbg(&ihost->pdev->dev, "%s: num=%d\n", __func__, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700158
159 /* Check if we have room for more tasks */
Dan Williams1077a572011-03-11 10:13:51 -0800160 ret = isci_host_can_queue(ihost, num);
Dan Williams6f231dd2011-07-02 22:56:22 -0700161
162 if (ret) {
Dan Williams1077a572011-03-11 10:13:51 -0800163 dev_warn(&ihost->pdev->dev, "%s: queue full\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -0700164 return ret;
165 }
166
Dan Williams1077a572011-03-11 10:13:51 -0800167 for_each_sas_task(num, task) {
168 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700169 "task = %p, num = %d; dev = %p; cmd = %p\n",
170 task, num, task->dev, task->uldd_task);
171
Dan Williams4393aa42011-03-31 13:10:44 -0700172 device = task->dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -0700173
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700174 if (device)
175 device_status = device->status;
176 else
177 device_status = isci_freed;
178
179 /* From this point onward, any process that needs to guarantee
180 * that there is no kernel I/O being started will have to wait
181 * for the quiesce spinlock.
182 */
183
184 if (device_status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700185
186 /* Forces a retry from scsi mid layer. */
Dan Williams1077a572011-03-11 10:13:51 -0800187 dev_warn(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700188 "%s: task %p: isci_host->status = %d, "
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700189 "device = %p; device_status = 0x%x\n\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700190 __func__,
191 task,
Dan Williams1077a572011-03-11 10:13:51 -0800192 isci_host_get_state(ihost),
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700193 device, device_status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700194
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700195 if (device_status == isci_ready) {
196 /* Indicate QUEUE_FULL so that the scsi midlayer
197 * retries.
198 */
Dan Williams1077a572011-03-11 10:13:51 -0800199 isci_task_refuse(ihost, task,
200 SAS_TASK_COMPLETE,
201 SAS_QUEUE_FULL);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700202 } else {
203 /* Else, the device is going down. */
Dan Williams1077a572011-03-11 10:13:51 -0800204 isci_task_refuse(ihost, task,
205 SAS_TASK_UNDELIVERED,
206 SAS_DEVICE_UNKNOWN);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700207 }
Dan Williams1077a572011-03-11 10:13:51 -0800208 isci_host_can_dequeue(ihost, 1);
Dan Williams6f231dd2011-07-02 22:56:22 -0700209 } else {
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700210 /* There is a device and it's ready for I/O. */
211 spin_lock_irqsave(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700212
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700213 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
214
215 spin_unlock_irqrestore(&task->task_state_lock,
216 flags);
217
Dan Williams1077a572011-03-11 10:13:51 -0800218 isci_task_refuse(ihost, task,
219 SAS_TASK_UNDELIVERED,
220 SAM_STAT_TASK_ABORTED);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700221
222 /* The I/O was aborted. */
223
224 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700225 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
226 spin_unlock_irqrestore(&task->task_state_lock, flags);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700227
228 /* build and send the request. */
Dan Williams1077a572011-03-11 10:13:51 -0800229 status = isci_request_execute(ihost, task, &request,
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700230 gfp_flags);
231
232 if (status != SCI_SUCCESS) {
233
234 spin_lock_irqsave(&task->task_state_lock, flags);
235 /* Did not really start this command. */
236 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
237 spin_unlock_irqrestore(&task->task_state_lock, flags);
238
239 /* Indicate QUEUE_FULL so that the scsi
240 * midlayer retries. if the request
241 * failed for remote device reasons,
242 * it gets returned as
243 * SAS_TASK_UNDELIVERED next time
244 * through.
245 */
Dan Williams1077a572011-03-11 10:13:51 -0800246 isci_task_refuse(ihost, task,
247 SAS_TASK_COMPLETE,
248 SAS_QUEUE_FULL);
249 isci_host_can_dequeue(ihost, 1);
Jeff Skirvinf0846c62011-03-08 19:22:07 -0700250 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700251 }
252 }
Dan Williams1077a572011-03-11 10:13:51 -0800253 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700254 return 0;
255}
256
257
258
259/**
260 * isci_task_request_build() - This function builds the task request object.
261 * @isci_host: This parameter specifies the ISCI host object
262 * @request: This parameter points to the isci_request object allocated in the
263 * request construct function.
264 * @tmf: This parameter is the task management struct to be built
265 *
266 * SCI_SUCCESS on successfull completion, or specific failure code.
267 */
268static enum sci_status isci_task_request_build(
269 struct isci_host *isci_host,
270 struct isci_request **isci_request,
271 struct isci_tmf *isci_tmf)
272{
273 struct scic_sds_remote_device *sci_device;
274 enum sci_status status = SCI_FAILURE;
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700275 struct isci_request *request = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700276 struct isci_remote_device *isci_device;
277/* struct sci_sas_identify_address_frame_protocols dev_protocols; */
278 struct smp_discover_response_protocols dev_protocols;
279
280
281 dev_dbg(&isci_host->pdev->dev,
282 "%s: isci_tmf = %p\n", __func__, isci_tmf);
283
284 isci_device = isci_tmf->device;
Dan Williams3a97eec2011-03-04 11:51:43 -0800285 sci_device = to_sci_dev(isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -0700286
287 /* do common allocation and init of request object. */
288 status = isci_request_alloc_tmf(
289 isci_host,
290 isci_tmf,
291 &request,
292 isci_device,
293 GFP_ATOMIC
294 );
295
296 if (status != SCI_SUCCESS)
297 goto out;
298
299 /* let the core do it's construct. */
300 status = scic_task_request_construct(
301 isci_host->core_controller,
302 sci_device,
303 SCI_CONTROLLER_INVALID_IO_TAG,
304 request,
305 request->sci_request_mem_ptr,
306 &request->sci_request_handle
307 );
308
309 if (status != SCI_SUCCESS) {
310 dev_warn(&isci_host->pdev->dev,
311 "%s: scic_task_request_construct failed - "
312 "status = 0x%x\n",
313 __func__,
314 status);
315 goto errout;
316 }
317
318 sci_object_set_association(
319 request->sci_request_handle,
320 request
321 );
322
323 scic_remote_device_get_protocols(
324 sci_device,
325 &dev_protocols
326 );
327
328 /* let the core do it's protocol
329 * specific construction.
330 */
331 if (dev_protocols.u.bits.attached_ssp_target) {
332
333 isci_tmf->proto = SAS_PROTOCOL_SSP;
334 status = scic_task_request_construct_ssp(
335 request->sci_request_handle
336 );
337 if (status != SCI_SUCCESS)
338 goto errout;
339 }
340
341 if (dev_protocols.u.bits.attached_stp_target) {
342
343 isci_tmf->proto = SAS_PROTOCOL_SATA;
344 status = isci_sata_management_task_request_build(request);
345
346 if (status != SCI_SUCCESS)
347 goto errout;
348 }
349
350 goto out;
351
352 errout:
353
354 /* release the dma memory if we fail. */
355 isci_request_free(isci_host, request);
356 request = NULL;
357
358 out:
359 *isci_request = request;
360 return status;
361}
362
363/**
364 * isci_tmf_timeout_cb() - This function is called as a kernel callback when
365 * the timeout period for the TMF has expired.
366 *
367 *
368 */
369static void isci_tmf_timeout_cb(void *tmf_request_arg)
370{
371 struct isci_request *request = (struct isci_request *)tmf_request_arg;
372 struct isci_tmf *tmf = isci_request_access_tmf(request);
373 enum sci_status status;
374
Dan Williams6f231dd2011-07-02 22:56:22 -0700375 /* This task management request has timed-out. Terminate the request
376 * so that the request eventually completes to the requestor in the
377 * request completion callback path.
378 */
379 /* Note - the timer callback function itself has provided spinlock
380 * exclusion from the start and completion paths. No need to take
381 * the request->isci_host->scic_lock here.
382 */
383
384 if (tmf->timeout_timer != NULL) {
385 /* Call the users callback, if any. */
386 if (tmf->cb_state_func != NULL)
387 tmf->cb_state_func(isci_tmf_timed_out, tmf,
388 tmf->cb_data);
389
390 /* Terminate the TMF transmit request. */
391 status = scic_controller_terminate_request(
392 request->isci_host->core_controller,
Dan Williams3a97eec2011-03-04 11:51:43 -0800393 to_sci_dev(request->isci_device),
Dan Williams6f231dd2011-07-02 22:56:22 -0700394 request->sci_request_handle
395 );
396
397 dev_dbg(&request->isci_host->pdev->dev,
398 "%s: tmf_request = %p; tmf = %p; status = %d\n",
399 __func__, request, tmf, status);
400 } else
401 dev_dbg(&request->isci_host->pdev->dev,
402 "%s: timer already canceled! "
403 "tmf_request = %p; tmf = %p\n",
404 __func__, request, tmf);
405
406 /* No need to unlock since the caller to this callback is doing it for
407 * us.
408 * request->isci_host->scic_lock
409 */
410}
411
412/**
413 * isci_task_execute_tmf() - This function builds and sends a task request,
414 * then waits for the completion.
415 * @isci_host: This parameter specifies the ISCI host object
416 * @tmf: This parameter is the pointer to the task management structure for
417 * this request.
418 * @timeout_ms: This parameter specifies the timeout period for the task
419 * management request.
420 *
421 * TMF_RESP_FUNC_COMPLETE on successful completion of the TMF (this includes
422 * error conditions reported in the IU status), or TMF_RESP_FUNC_FAILED.
423 */
424int isci_task_execute_tmf(
425 struct isci_host *isci_host,
426 struct isci_tmf *tmf,
427 unsigned long timeout_ms)
428{
429 DECLARE_COMPLETION_ONSTACK(completion);
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700430 enum sci_task_status status = SCI_TASK_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700431 struct scic_sds_remote_device *sci_device;
432 struct isci_remote_device *isci_device = tmf->device;
433 struct isci_request *request;
434 int ret = TMF_RESP_FUNC_FAILED;
435 unsigned long flags;
436
437 /* sanity check, return TMF_RESP_FUNC_FAILED
438 * if the device is not there and ready.
439 */
Dan Williams8acaec12011-03-07 14:47:35 -0800440 if (!isci_device || isci_device->status != isci_ready_for_io) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700441 dev_dbg(&isci_host->pdev->dev,
442 "%s: isci_device = %p not ready (%d)\n",
443 __func__,
Dan Williams8acaec12011-03-07 14:47:35 -0800444 isci_device, isci_device->status);
Dan Williams6f231dd2011-07-02 22:56:22 -0700445 return TMF_RESP_FUNC_FAILED;
446 } else
447 dev_dbg(&isci_host->pdev->dev,
448 "%s: isci_device = %p\n",
449 __func__, isci_device);
450
Dan Williams3a97eec2011-03-04 11:51:43 -0800451 sci_device = to_sci_dev(isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -0700452
453 /* Assign the pointer to the TMF's completion kernel wait structure. */
454 tmf->complete = &completion;
455
456 isci_task_request_build(
457 isci_host,
458 &request,
459 tmf
460 );
461
462 if (!request) {
463 dev_warn(&isci_host->pdev->dev,
464 "%s: isci_task_request_build failed\n",
465 __func__);
466 return TMF_RESP_FUNC_FAILED;
467 }
468
469 /* Allocate the TMF timeout timer. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700470 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800471 tmf->timeout_timer = isci_timer_create(isci_host, request, isci_tmf_timeout_cb);
Dan Williams6f231dd2011-07-02 22:56:22 -0700472
473 /* Start the timer. */
474 if (tmf->timeout_timer)
475 isci_timer_start(tmf->timeout_timer, timeout_ms);
476 else
477 dev_warn(&isci_host->pdev->dev,
478 "%s: isci_timer_create failed!!!!\n",
479 __func__);
480
481 /* start the TMF io. */
482 status = scic_controller_start_task(
483 isci_host->core_controller,
484 sci_device,
485 request->sci_request_handle,
486 SCI_CONTROLLER_INVALID_IO_TAG
487 );
488
Bartosz Barcinski467e8552011-04-12 17:28:41 -0700489 if (status != SCI_TASK_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700490 dev_warn(&isci_host->pdev->dev,
491 "%s: start_io failed - status = 0x%x, request = %p\n",
492 __func__,
493 status,
494 request);
495 goto cleanup_request;
496 }
497
498 /* Call the users callback, if any. */
499 if (tmf->cb_state_func != NULL)
500 tmf->cb_state_func(isci_tmf_started, tmf, tmf->cb_data);
501
502 /* Change the state of the TMF-bearing request to "started". */
503 isci_request_change_state(request, started);
504
505 /* add the request to the remote device request list. */
506 list_add(&request->dev_node, &isci_device->reqs_in_process);
507
508 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
509
510 /* Wait for the TMF to complete, or a timeout. */
511 wait_for_completion(&completion);
512
513 isci_print_tmf(tmf);
514
515 if (tmf->status == SCI_SUCCESS)
516 ret = TMF_RESP_FUNC_COMPLETE;
517 else if (tmf->status == SCI_FAILURE_IO_RESPONSE_VALID) {
518 dev_dbg(&isci_host->pdev->dev,
519 "%s: tmf.status == "
520 "SCI_FAILURE_IO_RESPONSE_VALID\n",
521 __func__);
522 ret = TMF_RESP_FUNC_COMPLETE;
523 }
524 /* Else - leave the default "failed" status alone. */
525
526 dev_dbg(&isci_host->pdev->dev,
527 "%s: completed request = %p\n",
528 __func__,
529 request);
530
531 if (request->io_request_completion != NULL) {
532
533 /* The fact that this is non-NULL for a TMF request
534 * means there is a thread waiting for this TMF to
535 * finish.
536 */
537 complete(request->io_request_completion);
538 }
539
540 spin_lock_irqsave(&isci_host->scic_lock, flags);
541
542 cleanup_request:
543
544 /* Clean up the timer if needed. */
545 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -0800546 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -0700547 tmf->timeout_timer = NULL;
548 }
549
550 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
551
552 isci_request_free(isci_host, request);
553
554 return ret;
555}
556
557void isci_task_build_tmf(
558 struct isci_tmf *tmf,
559 struct isci_remote_device *isci_device,
560 enum isci_tmf_function_codes code,
561 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
562 struct isci_tmf *,
563 void *),
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800564 void *cb_data)
Dan Williams6f231dd2011-07-02 22:56:22 -0700565{
566 dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
567 "%s: isci_device = %p\n", __func__, isci_device);
568
569 memset(tmf, 0, sizeof(*tmf));
570
571 tmf->device = isci_device;
572 tmf->tmf_code = code;
573 tmf->timeout_timer = NULL;
574 tmf->cb_state_func = tmf_sent_cb;
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800575 tmf->cb_data = cb_data;
576}
Jeff Skirvin1fad9e92011-03-04 14:06:46 -0800577
Dan Williams35173d52011-03-26 16:43:01 -0700578static void isci_task_build_abort_task_tmf(
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -0800579 struct isci_tmf *tmf,
580 struct isci_remote_device *isci_device,
581 enum isci_tmf_function_codes code,
582 void (*tmf_sent_cb)(enum isci_tmf_cb_state,
583 struct isci_tmf *,
584 void *),
585 struct isci_request *old_request)
586{
587 isci_task_build_tmf(tmf, isci_device, code, tmf_sent_cb,
588 (void *)old_request);
589 tmf->io_tag = old_request->io_tag;
Dan Williams6f231dd2011-07-02 22:56:22 -0700590}
591
592static struct isci_request *isci_task_get_request_from_task(
593 struct sas_task *task,
Dan Williams6f231dd2011-07-02 22:56:22 -0700594 struct isci_remote_device **isci_device)
595{
596
597 struct isci_request *request = NULL;
598 unsigned long flags;
599
600 spin_lock_irqsave(&task->task_state_lock, flags);
601
602 request = task->lldd_task;
603
604 /* If task is already done, the request isn't valid */
605 if (!(task->task_state_flags & SAS_TASK_STATE_DONE) &&
606 (task->task_state_flags & SAS_TASK_AT_INITIATOR) &&
607 (request != NULL)) {
608
Dan Williams6f231dd2011-07-02 22:56:22 -0700609 if (isci_device != NULL)
610 *isci_device = request->isci_device;
611 }
612
613 spin_unlock_irqrestore(&task->task_state_lock, flags);
614
615 return request;
616}
617
618/**
619 * isci_task_validate_request_to_abort() - This function checks the given I/O
620 * against the "started" state. If the request is still "started", it's
621 * state is changed to aborted. NOTE: isci_host->scic_lock MUST BE HELD
622 * BEFORE CALLING THIS FUNCTION.
623 * @isci_request: This parameter specifies the request object to control.
624 * @isci_host: This parameter specifies the ISCI host object
625 * @isci_device: This is the device to which the request is pending.
626 * @aborted_io_completion: This is a completion structure that will be added to
627 * the request in case it is changed to aborting; this completion is
628 * triggered when the request is fully completed.
629 *
630 * Either "started" on successful change of the task status to "aborted", or
631 * "unallocated" if the task cannot be controlled.
632 */
633static enum isci_request_status isci_task_validate_request_to_abort(
634 struct isci_request *isci_request,
635 struct isci_host *isci_host,
636 struct isci_remote_device *isci_device,
637 struct completion *aborted_io_completion)
638{
639 enum isci_request_status old_state = unallocated;
640
641 /* Only abort the task if it's in the
642 * device's request_in_process list
643 */
644 if (isci_request && !list_empty(&isci_request->dev_node)) {
645 old_state = isci_request_change_started_to_aborted(
646 isci_request, aborted_io_completion);
647
Dan Williams6f231dd2011-07-02 22:56:22 -0700648 }
649
650 return old_state;
651}
652
653static void isci_request_cleanup_completed_loiterer(
654 struct isci_host *isci_host,
655 struct isci_remote_device *isci_device,
656 struct isci_request *isci_request)
657{
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800658 struct sas_task *task;
659 unsigned long flags;
660
661 task = (isci_request->ttype == io_task)
662 ? isci_request_access_task(isci_request)
663 : NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700664
665 dev_dbg(&isci_host->pdev->dev,
666 "%s: isci_device=%p, request=%p, task=%p\n",
Jeff Skirvin18d3d722011-03-04 14:06:38 -0800667 __func__, isci_device, isci_request, task);
Dan Williams6f231dd2011-07-02 22:56:22 -0700668
669 spin_lock_irqsave(&isci_host->scic_lock, flags);
670 list_del_init(&isci_request->dev_node);
Dan Williams6f231dd2011-07-02 22:56:22 -0700671 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
672
Jeff Skirvina5fde222011-03-04 14:06:42 -0800673 if (task != NULL) {
674
675 spin_lock_irqsave(&task->task_state_lock, flags);
676 task->lldd_task = NULL;
677
678 isci_set_task_doneflags(task);
679
680 /* If this task is not in the abort path, call task_done. */
681 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
682
683 spin_unlock_irqrestore(&task->task_state_lock, flags);
684 task->task_done(task);
685 } else
686 spin_unlock_irqrestore(&task->task_state_lock, flags);
687 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700688 isci_request_free(isci_host, isci_request);
689}
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800690
691/**
692* @isci_termination_timed_out(): this function will deal with a request for
693* which the wait for termination has timed-out.
694*
695* @isci_host This SCU.
696* @isci_request The I/O request being terminated.
697*/
698static void
699isci_termination_timed_out(
700 struct isci_host * host,
701 struct isci_request * request
702 )
703{
704 unsigned long state_flags;
705
706 dev_warn(&host->pdev->dev,
707 "%s: host = %p; request = %p\n",
708 __func__, host, request);
709
710 /* At this point, the request to terminate
711 * has timed out. The best we can do is to
712 * have the request die a silent death
713 * if it ever completes.
714 */
715 spin_lock_irqsave(&request->state_lock, state_flags);
716
717 if (request->status == started) {
718
719 /* Set the request state to "dead",
720 * and clear the task pointer so that an actual
721 * completion event callback doesn't do
722 * anything.
723 */
724 request->status = dead;
725
726 /* Clear the timeout completion event pointer.*/
727 request->io_request_completion = NULL;
728
729 if (request->ttype == io_task) {
730
731 /* Break links with the sas_task. */
732 if (request->ttype_ptr.io_task_ptr != NULL) {
733
734 request->ttype_ptr.io_task_ptr->lldd_task = NULL;
735 request->ttype_ptr.io_task_ptr = NULL;
736 }
737 }
738 }
739 spin_unlock_irqrestore(&request->state_lock, state_flags);
740}
741
742
Dan Williams6f231dd2011-07-02 22:56:22 -0700743/**
744 * isci_terminate_request_core() - This function will terminate the given
745 * request, and wait for it to complete. This function must only be called
746 * from a thread that can wait. Note that the request is terminated and
747 * completed (back to the host, if started there).
748 * @isci_host: This SCU.
749 * @isci_device: The target.
750 * @isci_request: The I/O request to be terminated.
751 *
752 *
753 */
754static void isci_terminate_request_core(
755 struct isci_host *isci_host,
756 struct isci_remote_device *isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800757 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700758{
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800759 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700760 bool was_terminated = false;
761 bool needs_cleanup_handling = false;
762 enum isci_request_status request_status;
763 unsigned long flags;
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800764 unsigned long timeout_remaining;
765
Dan Williams6f231dd2011-07-02 22:56:22 -0700766
767 dev_dbg(&isci_host->pdev->dev,
768 "%s: device = %p; request = %p\n",
769 __func__, isci_device, isci_request);
770
Dan Williams6f231dd2011-07-02 22:56:22 -0700771 spin_lock_irqsave(&isci_host->scic_lock, flags);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800772
773 /* Note that we are not going to control
774 * the target to abort the request.
775 */
776 isci_request->complete_in_target = true;
777
Dan Williams6f231dd2011-07-02 22:56:22 -0700778 /* Make sure the request wasn't just sitting around signalling
779 * device condition (if the request handle is NULL, then the
780 * request completed but needed additional handling here).
781 */
782 if (isci_request->sci_request_handle != NULL) {
783 was_terminated = true;
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800784 needs_cleanup_handling = true;
Dan Williams6f231dd2011-07-02 22:56:22 -0700785 status = scic_controller_terminate_request(
786 isci_host->core_controller,
Dan Williams3a97eec2011-03-04 11:51:43 -0800787 to_sci_dev(isci_device),
Dan Williams6f231dd2011-07-02 22:56:22 -0700788 isci_request->sci_request_handle
789 );
790 }
791 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
792
793 /*
794 * The only time the request to terminate will
795 * fail is when the io request is completed and
796 * being aborted.
797 */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800798 if (status != SCI_SUCCESS) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700799 dev_err(&isci_host->pdev->dev,
800 "%s: scic_controller_terminate_request"
801 " returned = 0x%x\n",
802 __func__,
803 status);
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800804 /* Clear the completion pointer from the request. */
805 isci_request->io_request_completion = NULL;
806
807 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -0700808 if (was_terminated) {
809 dev_dbg(&isci_host->pdev->dev,
810 "%s: before completion wait (%p)\n",
811 __func__,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800812 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700813
814 /* Wait here for the request to complete. */
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800815 #define TERMINATION_TIMEOUT_MSEC 50
816 timeout_remaining
817 = wait_for_completion_timeout(
818 isci_request->io_request_completion,
819 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC));
Dan Williams6f231dd2011-07-02 22:56:22 -0700820
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800821 if (!timeout_remaining) {
822
823 isci_termination_timed_out(isci_host,
824 isci_request);
825
826 dev_err(&isci_host->pdev->dev,
827 "%s: *** Timeout waiting for "
828 "termination(%p/%p)\n",
829 __func__,
830 isci_request->io_request_completion,
831 isci_request);
832
833 } else
834 dev_dbg(&isci_host->pdev->dev,
835 "%s: after completion wait (%p)\n",
836 __func__,
837 isci_request->io_request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700838 }
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800839 /* Clear the completion pointer from the request. */
840 isci_request->io_request_completion = NULL;
841
842 /* Peek at the status of the request. This will tell
843 * us if there was special handling on the request such that it
844 * needs to be detached and freed here.
845 */
846 spin_lock_irqsave(&isci_request->state_lock, flags);
847 request_status = isci_request_get_state(isci_request);
848
849 if ((isci_request->ttype == io_task) /* TMFs are in their own thread */
850 && ((request_status == aborted)
851 || (request_status == aborting)
852 || (request_status == terminating)
853 || (request_status == completed)
854 || (request_status == dead)
855 )
856 ) {
857
858 /* The completion routine won't free a request in
859 * the aborted/aborting/etc. states, so we do
860 * it here.
861 */
862 needs_cleanup_handling = true;
863 }
864 spin_unlock_irqrestore(&isci_request->state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700865
866 if (needs_cleanup_handling)
867 isci_request_cleanup_completed_loiterer(
868 isci_host, isci_device, isci_request
869 );
870 }
871}
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800872
Dan Williams6f231dd2011-07-02 22:56:22 -0700873static void isci_terminate_request(
874 struct isci_host *isci_host,
875 struct isci_remote_device *isci_device,
876 struct isci_request *isci_request,
877 enum isci_request_status new_request_state)
878{
879 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -0700880 DECLARE_COMPLETION_ONSTACK(request_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -0700881
882 /* Change state to "new_request_state" if it is currently "started" */
883 old_state = isci_request_change_started_to_newstate(
884 isci_request,
885 &request_completion,
886 new_request_state
887 );
888
Jeff Skirvinf219f012011-03-31 13:10:34 -0700889 if ((old_state == started) ||
890 (old_state == completed) ||
891 (old_state == aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700892
Jeff Skirvina5fde222011-03-04 14:06:42 -0800893 /* If the old_state is started:
894 * This request was not already being aborted. If it had been,
Dan Williams6f231dd2011-07-02 22:56:22 -0700895 * then the aborting I/O (ie. the TMF request) would not be in
896 * the aborting state, and thus would be terminated here. Note
897 * that since the TMF completion's call to the kernel function
898 * "complete()" does not happen until the pending I/O request
899 * terminate fully completes, we do not have to implement a
900 * special wait here for already aborting requests - the
901 * termination of the TMF request will force the request
902 * to finish it's already started terminate.
Jeff Skirvina5fde222011-03-04 14:06:42 -0800903 *
904 * If old_state == completed:
905 * This request completed from the SCU hardware perspective
906 * and now just needs cleaning up in terms of freeing the
907 * request and potentially calling up to libsas.
Jeff Skirvinf219f012011-03-31 13:10:34 -0700908 *
909 * If old_state == aborting:
910 * This request has already gone through a TMF timeout, but may
911 * not have been terminated; needs cleaning up at least.
Dan Williams6f231dd2011-07-02 22:56:22 -0700912 */
913 isci_terminate_request_core(isci_host, isci_device,
Jeff Skirvincbb65c62011-03-04 14:06:50 -0800914 isci_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -0800915 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700916}
917
918/**
919 * isci_terminate_pending_requests() - This function will change the all of the
920 * requests on the given device's state to "aborting", will terminate the
921 * requests, and wait for them to complete. This function must only be
922 * called from a thread that can wait. Note that the requests are all
923 * terminated and completed (back to the host, if started there).
924 * @isci_host: This parameter specifies SCU.
925 * @isci_device: This parameter specifies the target.
926 *
927 *
928 */
929void isci_terminate_pending_requests(
930 struct isci_host *isci_host,
931 struct isci_remote_device *isci_device,
932 enum isci_request_status new_request_state)
933{
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800934 struct isci_request *request;
935 struct isci_request *next_request;
936 unsigned long flags;
937 struct list_head aborted_request_list;
938
939 INIT_LIST_HEAD(&aborted_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700940
941 dev_dbg(&isci_host->pdev->dev,
942 "%s: isci_device = %p (new request state = %d)\n",
943 __func__, isci_device, new_request_state);
944
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800945 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -0700946
Jeff Skirvin4dc043c2011-03-04 14:06:52 -0800947 /* Move all of the pending requests off of the device list. */
948 list_splice_init(&isci_device->reqs_in_process,
949 &aborted_request_list);
950
951 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
952
953 /* Iterate through the now-local list. */
954 list_for_each_entry_safe(request, next_request,
955 &aborted_request_list, dev_node) {
956
957 dev_warn(&isci_host->pdev->dev,
958 "%s: isci_device=%p request=%p; task=%p\n",
959 __func__,
960 isci_device, request,
961 ((request->ttype == io_task)
962 ? isci_request_access_task(request)
963 : NULL));
964
965 /* Mark all still pending I/O with the selected next
966 * state, terminate and free it.
967 */
968 isci_terminate_request(isci_host, isci_device,
969 request, new_request_state
970 );
Dan Williams6f231dd2011-07-02 22:56:22 -0700971 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700972}
973
974/**
975 * isci_task_send_lu_reset_sas() - This function is called by of the SAS Domain
976 * Template functions.
977 * @lun: This parameter specifies the lun to be reset.
978 *
979 * status, zero indicates success.
980 */
981static int isci_task_send_lu_reset_sas(
982 struct isci_host *isci_host,
983 struct isci_remote_device *isci_device,
984 u8 *lun)
985{
986 struct isci_tmf tmf;
987 int ret = TMF_RESP_FUNC_FAILED;
988
989 dev_dbg(&isci_host->pdev->dev,
990 "%s: isci_host = %p, isci_device = %p\n",
991 __func__, isci_host, isci_device);
992 /* Send the LUN reset to the target. By the time the call returns,
993 * the TMF has fully exected in the target (in which case the return
994 * value is "TMF_RESP_FUNC_COMPLETE", or the request timed-out (or
995 * was otherwise unable to be executed ("TMF_RESP_FUNC_FAILED").
996 */
997 isci_task_build_tmf(&tmf, isci_device, isci_tmf_ssp_lun_reset, NULL,
998 NULL);
999
1000 #define ISCI_LU_RESET_TIMEOUT_MS 2000 /* 2 second timeout. */
1001 ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_LU_RESET_TIMEOUT_MS);
1002
1003 if (ret == TMF_RESP_FUNC_COMPLETE)
1004 dev_dbg(&isci_host->pdev->dev,
1005 "%s: %p: TMF_LU_RESET passed\n",
1006 __func__, isci_device);
1007 else
1008 dev_dbg(&isci_host->pdev->dev,
1009 "%s: %p: TMF_LU_RESET failed (%x)\n",
1010 __func__, isci_device, ret);
1011
1012 return ret;
1013}
1014
1015/**
1016 * isci_task_lu_reset() - This function is one of the SAS Domain Template
1017 * functions. This is one of the Task Management functoins called by libsas,
1018 * to reset the given lun. Note the assumption that while this call is
1019 * executing, no I/O will be sent by the host to the device.
1020 * @lun: This parameter specifies the lun to be reset.
1021 *
1022 * status, zero indicates success.
1023 */
Dan Williams4393aa42011-03-31 13:10:44 -07001024int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
Dan Williams6f231dd2011-07-02 22:56:22 -07001025{
Dan Williams4393aa42011-03-31 13:10:44 -07001026 struct isci_host *isci_host = dev_to_ihost(domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001027 struct isci_remote_device *isci_device = NULL;
1028 int ret;
1029 bool device_stopping = false;
1030
Dan Williams4393aa42011-03-31 13:10:44 -07001031 isci_device = domain_device->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001032
Dan Williams4393aa42011-03-31 13:10:44 -07001033 dev_dbg(&isci_host->pdev->dev,
1034 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
Dan Williams6f231dd2011-07-02 22:56:22 -07001035 __func__, domain_device, isci_host, isci_device);
1036
1037 if (isci_device != NULL)
1038 device_stopping = (isci_device->status == isci_stopping)
1039 || (isci_device->status == isci_stopped);
1040
1041 /* If there is a device reset pending on any request in the
1042 * device's list, fail this LUN reset request in order to
1043 * escalate to the device reset.
1044 */
Dan Williams4393aa42011-03-31 13:10:44 -07001045 if (!isci_device || device_stopping ||
1046 isci_device_is_reset_pending(isci_host, isci_device)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001047 dev_warn(&isci_host->pdev->dev,
Dan Williams4393aa42011-03-31 13:10:44 -07001048 "%s: No dev (%p), or "
Dan Williams6f231dd2011-07-02 22:56:22 -07001049 "RESET PENDING: domain_device=%p\n",
Dan Williams4393aa42011-03-31 13:10:44 -07001050 __func__, isci_device, domain_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001051 return TMF_RESP_FUNC_FAILED;
1052 }
1053
Dan Williams6f231dd2011-07-02 22:56:22 -07001054 /* Send the task management part of the reset. */
1055 if (sas_protocol_ata(domain_device->tproto)) {
Dan Williams4393aa42011-03-31 13:10:44 -07001056 ret = isci_task_send_lu_reset_sata(isci_host, isci_device, lun);
Dan Williams6f231dd2011-07-02 22:56:22 -07001057 } else
1058 ret = isci_task_send_lu_reset_sas(isci_host, isci_device, lun);
1059
1060 /* If the LUN reset worked, all the I/O can now be terminated. */
1061 if (ret == TMF_RESP_FUNC_COMPLETE)
1062 /* Terminate all I/O now. */
1063 isci_terminate_pending_requests(isci_host,
1064 isci_device,
1065 terminating);
1066
Dan Williams6f231dd2011-07-02 22:56:22 -07001067 return ret;
1068}
1069
1070
1071/* int (*lldd_clear_nexus_port)(struct asd_sas_port *); */
1072int isci_task_clear_nexus_port(struct asd_sas_port *port)
1073{
1074 return TMF_RESP_FUNC_FAILED;
1075}
1076
1077
1078
1079int isci_task_clear_nexus_ha(struct sas_ha_struct *ha)
1080{
1081 return TMF_RESP_FUNC_FAILED;
1082}
1083
1084int isci_task_I_T_nexus_reset(struct domain_device *dev)
1085{
1086 return TMF_RESP_FUNC_FAILED;
1087}
1088
1089
1090/* Task Management Functions. Must be called from process context. */
1091
1092/**
1093 * isci_abort_task_process_cb() - This is a helper function for the abort task
1094 * TMF command. It manages the request state with respect to the successful
1095 * transmission / completion of the abort task request.
1096 * @cb_state: This parameter specifies when this function was called - after
1097 * the TMF request has been started and after it has timed-out.
1098 * @tmf: This parameter specifies the TMF in progress.
1099 *
1100 *
1101 */
1102static void isci_abort_task_process_cb(
1103 enum isci_tmf_cb_state cb_state,
1104 struct isci_tmf *tmf,
1105 void *cb_data)
1106{
1107 struct isci_request *old_request;
1108
1109 old_request = (struct isci_request *)cb_data;
1110
1111 dev_dbg(&old_request->isci_host->pdev->dev,
1112 "%s: tmf=%p, old_request=%p\n",
1113 __func__, tmf, old_request);
1114
1115 switch (cb_state) {
1116
1117 case isci_tmf_started:
1118 /* The TMF has been started. Nothing to do here, since the
1119 * request state was already set to "aborted" by the abort
1120 * task function.
1121 */
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07001122 if ((old_request->status != aborted)
1123 && (old_request->status != completed))
1124 dev_err(&old_request->isci_host->pdev->dev,
1125 "%s: Bad request status (%d): tmf=%p, old_request=%p\n",
1126 __func__, old_request->status, tmf, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001127 break;
1128
1129 case isci_tmf_timed_out:
1130
1131 /* Set the task's state to "aborting", since the abort task
1132 * function thread set it to "aborted" (above) in anticipation
1133 * of the task management request working correctly. Since the
1134 * timeout has now fired, the TMF request failed. We set the
1135 * state such that the request completion will indicate the
1136 * device is no longer present.
1137 */
1138 isci_request_change_state(old_request, aborting);
1139 break;
1140
1141 default:
1142 dev_err(&old_request->isci_host->pdev->dev,
1143 "%s: Bad cb_state (%d): tmf=%p, old_request=%p\n",
1144 __func__, cb_state, tmf, old_request);
1145 break;
1146 }
1147}
1148
1149/**
1150 * isci_task_abort_task() - This function is one of the SAS Domain Template
1151 * functions. This function is called by libsas to abort a specified task.
1152 * @task: This parameter specifies the SAS task to abort.
1153 *
1154 * status, zero indicates success.
1155 */
1156int isci_task_abort_task(struct sas_task *task)
1157{
Dan Williams4393aa42011-03-31 13:10:44 -07001158 struct isci_host *isci_host = dev_to_ihost(task->dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001159 DECLARE_COMPLETION_ONSTACK(aborted_io_completion);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001160 struct isci_request *old_request = NULL;
1161 enum isci_request_status old_state;
Dan Williams6f231dd2011-07-02 22:56:22 -07001162 struct isci_remote_device *isci_device = NULL;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001163 struct isci_tmf tmf;
1164 int ret = TMF_RESP_FUNC_FAILED;
1165 unsigned long flags;
1166 bool any_dev_reset = false;
1167 bool device_stopping;
Dan Williams6f231dd2011-07-02 22:56:22 -07001168
1169 /* Get the isci_request reference from the task. Note that
1170 * this check does not depend on the pending request list
1171 * in the device, because tasks driving resets may land here
1172 * after completion in the core.
1173 */
Dan Williams4393aa42011-03-31 13:10:44 -07001174 old_request = isci_task_get_request_from_task(task, &isci_device);
Dan Williams6f231dd2011-07-02 22:56:22 -07001175
1176 dev_dbg(&isci_host->pdev->dev,
1177 "%s: task = %p\n", __func__, task);
1178
1179 /* Check if the device has been / is currently being removed.
1180 * If so, no task management will be done, and the I/O will
1181 * be terminated.
1182 */
1183 device_stopping = (isci_device->status == isci_stopping)
1184 || (isci_device->status == isci_stopped);
1185
Dan Williams6f231dd2011-07-02 22:56:22 -07001186 /* This version of the driver will fail abort requests for
1187 * SATA/STP. Failing the abort request this way will cause the
1188 * SCSI error handler thread to escalate to LUN reset
1189 */
1190 if (sas_protocol_ata(task->task_proto) && !device_stopping) {
1191 dev_warn(&isci_host->pdev->dev,
1192 " task %p is for a STP/SATA device;"
1193 " returning TMF_RESP_FUNC_FAILED\n"
1194 " to cause a LUN reset...\n", task);
1195 return TMF_RESP_FUNC_FAILED;
1196 }
1197
1198 dev_dbg(&isci_host->pdev->dev,
1199 "%s: old_request == %p\n", __func__, old_request);
1200
Jeff Skirvina5fde222011-03-04 14:06:42 -08001201 if (!device_stopping)
1202 any_dev_reset = isci_device_is_reset_pending(isci_host,isci_device);
1203
Dan Williams6f231dd2011-07-02 22:56:22 -07001204 spin_lock_irqsave(&task->task_state_lock, flags);
1205
1206 /* Don't do resets to stopping devices. */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001207 if (device_stopping) {
1208
Dan Williams6f231dd2011-07-02 22:56:22 -07001209 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
Jeff Skirvina5fde222011-03-04 14:06:42 -08001210 any_dev_reset = false;
Dan Williams6f231dd2011-07-02 22:56:22 -07001211
Jeff Skirvina5fde222011-03-04 14:06:42 -08001212 } else /* See if there is a pending device reset for this device. */
Dan Williams6f231dd2011-07-02 22:56:22 -07001213 any_dev_reset = any_dev_reset
Jeff Skirvina5fde222011-03-04 14:06:42 -08001214 || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
Dan Williams6f231dd2011-07-02 22:56:22 -07001215
1216 /* If the extraction of the request reference from the task
1217 * failed, then the request has been completed (or if there is a
1218 * pending reset then this abort request function must be failed
1219 * in order to escalate to the target reset).
1220 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001221 if ((old_request == NULL) || any_dev_reset) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001222
1223 /* If the device reset task flag is set, fail the task
1224 * management request. Otherwise, the original request
1225 * has completed.
1226 */
1227 if (any_dev_reset) {
1228
1229 /* Turn off the task's DONE to make sure this
1230 * task is escalated to a target reset.
1231 */
1232 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1233
Jeff Skirvina5fde222011-03-04 14:06:42 -08001234 /* Make the reset happen as soon as possible. */
1235 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1236
1237 spin_unlock_irqrestore(&task->task_state_lock, flags);
1238
Dan Williams6f231dd2011-07-02 22:56:22 -07001239 /* Fail the task management request in order to
1240 * escalate to the target reset.
1241 */
1242 ret = TMF_RESP_FUNC_FAILED;
1243
1244 dev_dbg(&isci_host->pdev->dev,
1245 "%s: Failing task abort in order to "
1246 "escalate to target reset because\n"
1247 "SAS_TASK_NEED_DEV_RESET is set for "
1248 "task %p on dev %p\n",
1249 __func__, task, isci_device);
1250
Jeff Skirvina5fde222011-03-04 14:06:42 -08001251
Dan Williams6f231dd2011-07-02 22:56:22 -07001252 } else {
Dan Williams6f231dd2011-07-02 22:56:22 -07001253 /* The request has already completed and there
1254 * is nothing to do here other than to set the task
1255 * done bit, and indicate that the task abort function
1256 * was sucessful.
1257 */
1258 isci_set_task_doneflags(task);
1259
Jeff Skirvina5fde222011-03-04 14:06:42 -08001260 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001261
Jeff Skirvina5fde222011-03-04 14:06:42 -08001262 ret = TMF_RESP_FUNC_COMPLETE;
Dan Williams6f231dd2011-07-02 22:56:22 -07001263
Jeff Skirvina5fde222011-03-04 14:06:42 -08001264 dev_dbg(&isci_host->pdev->dev,
1265 "%s: abort task not needed for %p\n",
1266 __func__, task);
Dan Williams6f231dd2011-07-02 22:56:22 -07001267 }
Dan Williams6f231dd2011-07-02 22:56:22 -07001268
1269 return ret;
1270 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001271 else
1272 spin_unlock_irqrestore(&task->task_state_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001273
1274 spin_lock_irqsave(&isci_host->scic_lock, flags);
1275
Jeff Skirvinf219f012011-03-31 13:10:34 -07001276 /* Check the request status and change to "aborted" if currently
Jeff Skirvina5fde222011-03-04 14:06:42 -08001277 * "starting"; if true then set the I/O kernel completion
Dan Williams6f231dd2011-07-02 22:56:22 -07001278 * struct that will be triggered when the request completes.
1279 */
Jeff Skirvina5fde222011-03-04 14:06:42 -08001280 old_state = isci_task_validate_request_to_abort(
1281 old_request, isci_host, isci_device,
1282 &aborted_io_completion);
Jeff Skirvinf219f012011-03-31 13:10:34 -07001283 if ((old_state != started) &&
1284 (old_state != completed) &&
1285 (old_state != aborting)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001286
1287 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1288
Jeff Skirvina5fde222011-03-04 14:06:42 -08001289 /* The request was already being handled by someone else (because
1290 * they got to set the state away from started).
1291 */
1292 dev_dbg(&isci_host->pdev->dev,
1293 "%s: device = %p; old_request %p already being aborted\n",
1294 __func__,
1295 isci_device, old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001296
1297 return TMF_RESP_FUNC_COMPLETE;
1298 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001299 if ((task->task_proto == SAS_PROTOCOL_SMP)
1300 || device_stopping
1301 || old_request->complete_in_target
1302 ) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001303
1304 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1305
Jeff Skirvina5fde222011-03-04 14:06:42 -08001306 dev_dbg(&isci_host->pdev->dev,
1307 "%s: SMP request (%d)"
1308 " or device is stopping (%d)"
1309 " or complete_in_target (%d), thus no TMF\n",
1310 __func__, (task->task_proto == SAS_PROTOCOL_SMP),
1311 device_stopping, old_request->complete_in_target);
1312
Dan Williams6f231dd2011-07-02 22:56:22 -07001313 /* Set the state on the task. */
1314 isci_task_all_done(task);
1315
1316 ret = TMF_RESP_FUNC_COMPLETE;
1317
1318 /* Stopping and SMP devices are not sent a TMF, and are not
Jeff Skirvina5fde222011-03-04 14:06:42 -08001319 * reset, but the outstanding I/O request is terminated below.
Dan Williams6f231dd2011-07-02 22:56:22 -07001320 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001321 } else {
1322 /* Fill in the tmf stucture */
Jeff Skirvinc3f42fe2011-03-04 14:06:56 -08001323 isci_task_build_abort_task_tmf(&tmf, isci_device,
1324 isci_tmf_ssp_task_abort,
1325 isci_abort_task_process_cb,
1326 old_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07001327
Dan Williams6f231dd2011-07-02 22:56:22 -07001328 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1329
1330 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */
1331 ret = isci_task_execute_tmf(isci_host, &tmf,
1332 ISCI_ABORT_TASK_TIMEOUT_MS);
1333
Jeff Skirvina5fde222011-03-04 14:06:42 -08001334 if (ret != TMF_RESP_FUNC_COMPLETE)
Dan Williams6f231dd2011-07-02 22:56:22 -07001335 dev_err(&isci_host->pdev->dev,
1336 "%s: isci_task_send_tmf failed\n",
1337 __func__);
1338 }
Jeff Skirvina5fde222011-03-04 14:06:42 -08001339 if (ret == TMF_RESP_FUNC_COMPLETE) {
1340 old_request->complete_in_target = true;
Dan Williams6f231dd2011-07-02 22:56:22 -07001341
Jeff Skirvina5fde222011-03-04 14:06:42 -08001342 /* Clean up the request on our side, and wait for the aborted I/O to
1343 * complete.
1344 */
Jeff Skirvincbb65c62011-03-04 14:06:50 -08001345 isci_terminate_request_core(isci_host, isci_device, old_request);
Jeff Skirvina5fde222011-03-04 14:06:42 -08001346 }
1347
1348 /* Make sure we do not leave a reference to aborted_io_completion */
1349 old_request->io_request_completion = NULL;
Dan Williams6f231dd2011-07-02 22:56:22 -07001350 return ret;
1351}
1352
1353/**
1354 * isci_task_abort_task_set() - This function is one of the SAS Domain Template
1355 * functions. This is one of the Task Management functoins called by libsas,
1356 * to abort all task for the given lun.
1357 * @d_device: This parameter specifies the domain device associated with this
1358 * request.
1359 * @lun: This parameter specifies the lun associated with this request.
1360 *
1361 * status, zero indicates success.
1362 */
1363int isci_task_abort_task_set(
1364 struct domain_device *d_device,
1365 u8 *lun)
1366{
1367 return TMF_RESP_FUNC_FAILED;
1368}
1369
1370
1371/**
1372 * isci_task_clear_aca() - This function is one of the SAS Domain Template
1373 * functions. This is one of the Task Management functoins called by libsas.
1374 * @d_device: This parameter specifies the domain device associated with this
1375 * request.
1376 * @lun: This parameter specifies the lun associated with this request.
1377 *
1378 * status, zero indicates success.
1379 */
1380int isci_task_clear_aca(
1381 struct domain_device *d_device,
1382 u8 *lun)
1383{
1384 return TMF_RESP_FUNC_FAILED;
1385}
1386
1387
1388
1389/**
1390 * isci_task_clear_task_set() - This function is one of the SAS Domain Template
1391 * functions. This is one of the Task Management functoins called by libsas.
1392 * @d_device: This parameter specifies the domain device associated with this
1393 * request.
1394 * @lun: This parameter specifies the lun associated with this request.
1395 *
1396 * status, zero indicates success.
1397 */
1398int isci_task_clear_task_set(
1399 struct domain_device *d_device,
1400 u8 *lun)
1401{
1402 return TMF_RESP_FUNC_FAILED;
1403}
1404
1405
1406/**
1407 * isci_task_query_task() - This function is implemented to cause libsas to
1408 * correctly escalate the failed abort to a LUN or target reset (this is
1409 * because sas_scsi_find_task libsas function does not correctly interpret
1410 * all return codes from the abort task call). When TMF_RESP_FUNC_SUCC is
1411 * returned, libsas turns this into a LUN reset; when FUNC_FAILED is
1412 * returned, libsas will turn this into a target reset
1413 * @task: This parameter specifies the sas task being queried.
1414 * @lun: This parameter specifies the lun associated with this request.
1415 *
1416 * status, zero indicates success.
1417 */
1418int isci_task_query_task(
1419 struct sas_task *task)
1420{
1421 /* See if there is a pending device reset for this device. */
1422 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1423 return TMF_RESP_FUNC_FAILED;
1424 else
1425 return TMF_RESP_FUNC_SUCC;
1426}
1427
1428/**
1429 * isci_task_request_complete() - This function is called by the sci core when
1430 * an task request completes.
1431 * @isci_host: This parameter specifies the ISCI host object
1432 * @request: This parameter is the completed isci_request object.
1433 * @completion_status: This parameter specifies the completion status from the
1434 * sci core.
1435 *
1436 * none.
1437 */
1438void isci_task_request_complete(
1439 struct isci_host *isci_host,
1440 struct isci_request *request,
1441 enum sci_task_status completion_status)
1442{
1443 struct isci_remote_device *isci_device = request->isci_device;
1444 enum isci_request_status old_state;
1445 struct isci_tmf *tmf = isci_request_access_tmf(request);
1446 struct completion *tmf_complete;
1447
1448 dev_dbg(&isci_host->pdev->dev,
1449 "%s: request = %p, status=%d\n",
1450 __func__, request, completion_status);
1451
1452 old_state = isci_request_change_state(request, completed);
1453
1454 tmf->status = completion_status;
1455 request->complete_in_target = true;
1456
1457 if (SAS_PROTOCOL_SSP == tmf->proto) {
1458
1459 memcpy(&tmf->resp.resp_iu,
1460 scic_io_request_get_response_iu_address(
1461 request->sci_request_handle
1462 ),
1463 sizeof(struct sci_ssp_response_iu));
1464
1465 } else if (SAS_PROTOCOL_SATA == tmf->proto) {
1466
1467 memcpy(&tmf->resp.d2h_fis,
1468 scic_stp_io_request_get_d2h_reg_address(
1469 request->sci_request_handle
1470 ),
1471 sizeof(struct sata_fis_reg_d2h)
1472 );
1473 }
1474
1475 /* Manage the timer if it is still running. */
1476 if (tmf->timeout_timer) {
Dan Williams7c40a802011-03-02 11:49:26 -08001477 isci_del_timer(isci_host, tmf->timeout_timer);
Dan Williams6f231dd2011-07-02 22:56:22 -07001478 tmf->timeout_timer = NULL;
1479 }
1480
1481 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1482 tmf_complete = tmf->complete;
1483
Christoph Hellwigc6295822011-04-02 08:15:20 -04001484 scic_controller_complete_io(
Dan Williams6f231dd2011-07-02 22:56:22 -07001485 isci_host->core_controller,
Dan Williams3a97eec2011-03-04 11:51:43 -08001486 to_sci_dev(isci_device),
Dan Williams6f231dd2011-07-02 22:56:22 -07001487 request->sci_request_handle
1488 );
1489 /* NULL the request handle to make sure it cannot be terminated
1490 * or completed again.
1491 */
1492 request->sci_request_handle = NULL;
1493
1494 isci_request_change_state(request, unallocated);
1495 list_del_init(&request->dev_node);
1496
1497 /* The task management part completes last. */
1498 complete(tmf_complete);
1499}
1500
1501
1502/**
1503 * isci_task_ssp_request_get_lun() - This function is called by the sci core to
1504 * retrieve the lun for a given task request.
1505 * @request: This parameter is the isci_request object.
1506 *
1507 * lun for specified task request.
1508 */
Dan Williams6f231dd2011-07-02 22:56:22 -07001509
1510/**
1511 * isci_task_ssp_request_get_function() - This function is called by the sci
1512 * core to retrieve the function for a given task request.
1513 * @request: This parameter is the isci_request object.
1514 *
1515 * function code for specified task request.
1516 */
1517u8 isci_task_ssp_request_get_function(struct isci_request *request)
1518{
1519 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1520
1521 dev_dbg(&request->isci_host->pdev->dev,
1522 "%s: func = %d\n", __func__, isci_tmf->tmf_code);
1523
1524 return isci_tmf->tmf_code;
1525}
1526
1527/**
1528 * isci_task_ssp_request_get_io_tag_to_manage() - This function is called by
1529 * the sci core to retrieve the io tag for a given task request.
1530 * @request: This parameter is the isci_request object.
1531 *
1532 * io tag for specified task request.
1533 */
1534u16 isci_task_ssp_request_get_io_tag_to_manage(struct isci_request *request)
1535{
1536 u16 io_tag = SCI_CONTROLLER_INVALID_IO_TAG;
1537
1538 if (tmf_task == request->ttype) {
1539 struct isci_tmf *tmf = isci_request_access_tmf(request);
1540 io_tag = tmf->io_tag;
1541 }
1542
1543 dev_dbg(&request->isci_host->pdev->dev,
1544 "%s: request = %p, io_tag = %d\n",
1545 __func__, request, io_tag);
1546
1547 return io_tag;
1548}
1549
1550/**
1551 * isci_task_ssp_request_get_response_data_address() - This function is called
1552 * by the sci core to retrieve the response data address for a given task
1553 * request.
1554 * @request: This parameter is the isci_request object.
1555 *
1556 * response data address for specified task request.
1557 */
1558void *isci_task_ssp_request_get_response_data_address(
1559 struct isci_request *request)
1560{
1561 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1562
1563 return &isci_tmf->resp.resp_iu;
1564}
1565
1566/**
1567 * isci_task_ssp_request_get_response_data_length() - This function is called
1568 * by the sci core to retrieve the response data length for a given task
1569 * request.
1570 * @request: This parameter is the isci_request object.
1571 *
1572 * response data length for specified task request.
1573 */
1574u32 isci_task_ssp_request_get_response_data_length(
1575 struct isci_request *request)
1576{
1577 struct isci_tmf *isci_tmf = isci_request_access_tmf(request);
1578
1579 return sizeof(isci_tmf->resp.resp_iu);
1580}
1581
1582/**
1583 * isci_bus_reset_handler() - This function performs a target reset of the
1584 * device referenced by "cmd'. This function is exported through the
1585 * "struct scsi_host_template" structure such that it is called when an I/O
1586 * recovery process has escalated to a target reset. Note that this function
1587 * is called from the scsi error handler event thread, so may block on calls.
1588 * @scsi_cmd: This parameter specifies the target to be reset.
1589 *
1590 * SUCCESS if the reset process was successful, else FAILED.
1591 */
1592int isci_bus_reset_handler(struct scsi_cmnd *cmd)
1593{
Dan Williams4393aa42011-03-31 13:10:44 -07001594 struct domain_device *dev = cmd_to_domain_dev(cmd);
1595 struct isci_host *isci_host = dev_to_ihost(dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001596 unsigned long flags = 0;
Dan Williams6f231dd2011-07-02 22:56:22 -07001597 enum sci_status status;
1598 int base_status;
Dan Williams4393aa42011-03-31 13:10:44 -07001599 struct isci_remote_device *isci_dev = dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001600
Dan Williams4393aa42011-03-31 13:10:44 -07001601 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001602 "%s: cmd %p, isci_dev %p\n",
1603 __func__, cmd, isci_dev);
1604
1605 if (!isci_dev) {
Dan Williams4393aa42011-03-31 13:10:44 -07001606 dev_warn(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001607 "%s: isci_dev is GONE!\n",
1608 __func__);
1609
1610 return TMF_RESP_FUNC_COMPLETE; /* Nothing to reset. */
1611 }
1612
Dan Williams4393aa42011-03-31 13:10:44 -07001613 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams3a97eec2011-03-04 11:51:43 -08001614 status = scic_remote_device_reset(to_sci_dev(isci_dev));
Dan Williams6f231dd2011-07-02 22:56:22 -07001615 if (status != SCI_SUCCESS) {
Dan Williams4393aa42011-03-31 13:10:44 -07001616 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001617
1618 scmd_printk(KERN_WARNING, cmd,
1619 "%s: scic_remote_device_reset(%p) returned %d!\n",
1620 __func__, isci_dev, status);
1621
1622 return TMF_RESP_FUNC_FAILED;
1623 }
Dan Williams4393aa42011-03-31 13:10:44 -07001624 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001625
Dan Williams6f231dd2011-07-02 22:56:22 -07001626 /* Make sure all pending requests are able to be fully terminated. */
Dan Williams4393aa42011-03-31 13:10:44 -07001627 isci_device_clear_reset_pending(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001628
1629 /* Terminate in-progress I/O now. */
Dan Williams4393aa42011-03-31 13:10:44 -07001630 isci_remote_device_nuke_requests(isci_host, isci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001631
1632 /* Call into the libsas default handler (which calls sas_phy_reset). */
1633 base_status = sas_eh_bus_reset_handler(cmd);
1634
1635 if (base_status != SUCCESS) {
1636
1637 /* There can be cases where the resets to individual devices
1638 * behind an expander will fail because of an unplug of the
1639 * expander itself.
1640 */
1641 scmd_printk(KERN_WARNING, cmd,
1642 "%s: sas_eh_bus_reset_handler(%p) returned %d!\n",
1643 __func__, cmd, base_status);
1644 }
1645
1646 /* WHAT TO DO HERE IF sas_phy_reset FAILS? */
Dan Williams4393aa42011-03-31 13:10:44 -07001647 spin_lock_irqsave(&isci_host->scic_lock, flags);
Dan Williams3a97eec2011-03-04 11:51:43 -08001648 status = scic_remote_device_reset_complete(to_sci_dev(isci_dev));
Dan Williams4393aa42011-03-31 13:10:44 -07001649 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07001650
1651 if (status != SCI_SUCCESS) {
1652 scmd_printk(KERN_WARNING, cmd,
1653 "%s: scic_remote_device_reset_complete(%p) "
1654 "returned %d!\n",
1655 __func__, isci_dev, status);
1656 }
1657 /* WHAT TO DO HERE IF scic_remote_device_reset_complete FAILS? */
1658
Dan Williams4393aa42011-03-31 13:10:44 -07001659 dev_dbg(&isci_host->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001660 "%s: cmd %p, isci_dev %p complete.\n",
1661 __func__, cmd, isci_dev);
1662
Dan Williams6f231dd2011-07-02 22:56:22 -07001663 return TMF_RESP_FUNC_COMPLETE;
1664}