blob: d779939a6175798d414d07e4846f23d79d26c9ad [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 */
Dan Williams88f3b622011-04-22 19:18:03 -070055#include "intel_sas.h"
Dan Williamsab2e8f72011-04-27 16:32:45 -070056#include "intel_ata.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070057#include "isci.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "port.h"
59#include "remote_device.h"
60#include "request.h"
Dan Williams88f3b622011-04-22 19:18:03 -070061#include "scic_controller.h"
62#include "scic_io_request.h"
63#include "scic_phy.h"
64#include "scic_port.h"
65#include "scic_sds_controller.h"
66#include "scic_sds_phy.h"
67#include "scic_sds_port.h"
68#include "remote_node_context.h"
69#include "scic_sds_request.h"
70#include "sci_environment.h"
71#include "sci_util.h"
72#include "scu_event_codes.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070073#include "task.h"
74
Dan Williamsab2e8f72011-04-27 16:32:45 -070075/**
76 * isci_remote_device_change_state() - This function gets the status of the
77 * remote_device object.
78 * @isci_device: This parameter points to the isci_remote_device object
79 *
80 * status of the object as a isci_status enum.
81 */
82void isci_remote_device_change_state(
83 struct isci_remote_device *isci_device,
84 enum isci_status status)
85{
86 unsigned long flags;
87
88 spin_lock_irqsave(&isci_device->state_lock, flags);
89 isci_device->status = status;
90 spin_unlock_irqrestore(&isci_device->state_lock, flags);
91}
92
93/**
94 * isci_remote_device_not_ready() - This function is called by the scic when
95 * the remote device is not ready. We mark the isci device as ready (not
96 * "ready_for_io") and signal the waiting proccess.
97 * @isci_host: This parameter specifies the isci host object.
98 * @isci_device: This parameter specifies the remote device
99 *
100 */
101static void isci_remote_device_not_ready(struct isci_host *ihost,
102 struct isci_remote_device *idev, u32 reason)
103{
104 dev_dbg(&ihost->pdev->dev,
105 "%s: isci_device = %p\n", __func__, idev);
106
107 if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED)
108 isci_remote_device_change_state(idev, isci_stopping);
109 else
110 /* device ready is actually a "not ready for io" state. */
111 isci_remote_device_change_state(idev, isci_ready);
112}
113
114/**
115 * isci_remote_device_ready() - This function is called by the scic when the
116 * remote device is ready. We mark the isci device as ready and signal the
117 * waiting proccess.
118 * @ihost: our valid isci_host
119 * @idev: remote device
120 *
121 */
122static void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev)
123{
124 dev_dbg(&ihost->pdev->dev,
125 "%s: idev = %p\n", __func__, idev);
126
127 isci_remote_device_change_state(idev, isci_ready_for_io);
128 if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags))
129 wake_up(&ihost->eventq);
130}
131
Dan Williamsec575662011-05-01 14:19:25 -0700132/* called once the remote node context is ready to be freed.
133 * The remote device can now report that its stop operation is complete. none
134 */
135static void rnc_destruct_done(void *_dev)
Dan Williams88f3b622011-04-22 19:18:03 -0700136{
Dan Williamsec575662011-05-01 14:19:25 -0700137 struct scic_sds_remote_device *sci_dev = _dev;
138
139 BUG_ON(sci_dev->started_request_count != 0);
140 sci_base_state_machine_change_state(&sci_dev->state_machine,
141 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
142}
143
144static enum sci_status scic_sds_remote_device_terminate_requests(struct scic_sds_remote_device *sci_dev)
145{
146 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
147 u32 i, request_count = sci_dev->started_request_count;
148 enum sci_status status = SCI_SUCCESS;
149
150 for (i = 0; i < SCI_MAX_IO_REQUESTS && i < request_count; i++) {
151 struct scic_sds_request *sci_req;
152 enum sci_status s;
153
154 sci_req = scic->io_request_table[i];
155 if (!sci_req || sci_req->target_device != sci_dev)
156 continue;
157 s = scic_controller_terminate_request(scic, sci_dev, sci_req);
158 if (s != SCI_SUCCESS)
159 status = s;
160 }
161
162 return status;
163}
164
165enum sci_status scic_remote_device_stop(struct scic_sds_remote_device *sci_dev,
166 u32 timeout)
167{
168 struct sci_base_state_machine *sm = &sci_dev->state_machine;
169 enum scic_sds_remote_device_states state = sm->current_state_id;
170
171 switch (state) {
172 case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL:
173 case SCI_BASE_REMOTE_DEVICE_STATE_FAILED:
174 case SCI_BASE_REMOTE_DEVICE_STATE_FINAL:
175 default:
176 dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
177 __func__, state);
178 return SCI_FAILURE_INVALID_STATE;
179 case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED:
180 return SCI_SUCCESS;
181 case SCI_BASE_REMOTE_DEVICE_STATE_STARTING:
182 /* device not started so there had better be no requests */
183 BUG_ON(sci_dev->started_request_count != 0);
184 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
185 rnc_destruct_done, sci_dev);
186 /* Transition to the stopping state and wait for the
187 * remote node to complete being posted and invalidated.
188 */
189 sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
190 return SCI_SUCCESS;
191 case SCI_BASE_REMOTE_DEVICE_STATE_READY:
192 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
193 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
194 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
195 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
196 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
197 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
198 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
199 sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
200 if (sci_dev->started_request_count == 0) {
201 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
202 rnc_destruct_done, sci_dev);
203 return SCI_SUCCESS;
204 } else
205 return scic_sds_remote_device_terminate_requests(sci_dev);
206 break;
207 case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING:
208 /* All requests should have been terminated, but if there is an
209 * attempt to stop a device already in the stopping state, then
210 * try again to terminate.
211 */
212 return scic_sds_remote_device_terminate_requests(sci_dev);
213 case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING:
214 sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
215 return SCI_SUCCESS;
216 }
Dan Williams88f3b622011-04-22 19:18:03 -0700217}
Dan Williams6f231dd2011-07-02 22:56:22 -0700218
219
Dan Williams88f3b622011-04-22 19:18:03 -0700220enum sci_status scic_remote_device_reset(
221 struct scic_sds_remote_device *sci_dev)
222{
223 return sci_dev->state_handlers->reset_handler(sci_dev);
224}
225
226
227enum sci_status scic_remote_device_reset_complete(
228 struct scic_sds_remote_device *sci_dev)
229{
230 return sci_dev->state_handlers->reset_complete_handler(sci_dev);
231}
232
Dan Williams88f3b622011-04-22 19:18:03 -0700233#define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
234#define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
235
Dan Williams88f3b622011-04-22 19:18:03 -0700236/**
237 *
238 * @sci_dev: The remote device for which the suspend is being requested.
239 *
240 * This method invokes the remote device suspend state handler. enum sci_status
241 */
242enum sci_status scic_sds_remote_device_suspend(
243 struct scic_sds_remote_device *sci_dev,
244 u32 suspend_type)
245{
246 return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type);
247}
248
249/**
250 *
251 * @sci_dev: The remote device for which the event handling is being
252 * requested.
253 * @frame_index: This is the frame index that is being processed.
254 *
255 * This method invokes the frame handler for the remote device state machine
256 * enum sci_status
257 */
258enum sci_status scic_sds_remote_device_frame_handler(
259 struct scic_sds_remote_device *sci_dev,
260 u32 frame_index)
261{
262 return sci_dev->state_handlers->frame_handler(sci_dev, frame_index);
263}
264
265/**
266 *
267 * @sci_dev: The remote device for which the event handling is being
268 * requested.
269 * @event_code: This is the event code that is to be processed.
270 *
271 * This method invokes the remote device event handler. enum sci_status
272 */
273enum sci_status scic_sds_remote_device_event_handler(
274 struct scic_sds_remote_device *sci_dev,
275 u32 event_code)
276{
277 return sci_dev->state_handlers->event_handler(sci_dev, event_code);
278}
279
280/**
281 *
282 * @controller: The controller that is starting the io request.
283 * @sci_dev: The remote device for which the start io handling is being
284 * requested.
285 * @io_request: The io request that is being started.
286 *
287 * This method invokes the remote device start io handler. enum sci_status
288 */
289enum sci_status scic_sds_remote_device_start_io(
290 struct scic_sds_controller *controller,
291 struct scic_sds_remote_device *sci_dev,
292 struct scic_sds_request *io_request)
293{
294 return sci_dev->state_handlers->start_io_handler(
295 sci_dev, io_request);
296}
297
298/**
299 *
300 * @controller: The controller that is completing the io request.
301 * @sci_dev: The remote device for which the complete io handling is being
302 * requested.
303 * @io_request: The io request that is being completed.
304 *
305 * This method invokes the remote device complete io handler. enum sci_status
306 */
307enum sci_status scic_sds_remote_device_complete_io(
308 struct scic_sds_controller *controller,
309 struct scic_sds_remote_device *sci_dev,
310 struct scic_sds_request *io_request)
311{
312 return sci_dev->state_handlers->complete_io_handler(
313 sci_dev, io_request);
314}
315
316/**
317 *
318 * @controller: The controller that is starting the task request.
319 * @sci_dev: The remote device for which the start task handling is being
320 * requested.
321 * @io_request: The task request that is being started.
322 *
323 * This method invokes the remote device start task handler. enum sci_status
324 */
325enum sci_status scic_sds_remote_device_start_task(
326 struct scic_sds_controller *controller,
327 struct scic_sds_remote_device *sci_dev,
328 struct scic_sds_request *io_request)
329{
330 return sci_dev->state_handlers->start_task_handler(
331 sci_dev, io_request);
332}
333
334/**
335 *
Dan Williams88f3b622011-04-22 19:18:03 -0700336 * @sci_dev:
337 * @request:
338 *
339 * This method takes the request and bulids an appropriate SCU context for the
340 * request and then requests the controller to post the request. none
341 */
342void scic_sds_remote_device_post_request(
343 struct scic_sds_remote_device *sci_dev,
344 u32 request)
345{
346 u32 context;
347
348 context = scic_sds_remote_device_build_command_context(sci_dev, request);
349
350 scic_sds_controller_post_request(
351 scic_sds_remote_device_get_controller(sci_dev),
352 context
353 );
354}
355
Dan Williamsab2e8f72011-04-27 16:32:45 -0700356/* called once the remote node context has transisitioned to a
Dan Williams88f3b622011-04-22 19:18:03 -0700357 * ready state. This is the indication that the remote device object can also
Dan Williamsab2e8f72011-04-27 16:32:45 -0700358 * transition to ready.
Dan Williams88f3b622011-04-22 19:18:03 -0700359 */
Dan Williamseb229672011-05-01 14:05:57 -0700360static void remote_device_resume_done(void *_dev)
Dan Williams88f3b622011-04-22 19:18:03 -0700361{
Dan Williamsab2e8f72011-04-27 16:32:45 -0700362 struct scic_sds_remote_device *sci_dev = _dev;
363 enum scic_sds_remote_device_states state;
Dan Williams88f3b622011-04-22 19:18:03 -0700364
Dan Williamsab2e8f72011-04-27 16:32:45 -0700365 state = sci_dev->state_machine.current_state_id;
366 switch (state) {
367 case SCI_BASE_REMOTE_DEVICE_STATE_READY:
368 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
369 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
370 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ:
371 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR:
372 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET:
373 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE:
374 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD:
375 break;
376 default:
377 /* go 'ready' if we are not already in a ready state */
378 sci_base_state_machine_change_state(&sci_dev->state_machine,
379 SCI_BASE_REMOTE_DEVICE_STATE_READY);
380 break;
Dan Williams88f3b622011-04-22 19:18:03 -0700381 }
382}
383
384/**
385 *
386 * @device: This parameter specifies the device for which the request is being
387 * started.
388 * @request: This parameter specifies the request being started.
389 * @status: This parameter specifies the current start operation status.
390 *
391 * This method will perform the STP request start processing common to IO
392 * requests and task requests of all types. none
393 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700394static void scic_sds_remote_device_start_request(
Dan Williams88f3b622011-04-22 19:18:03 -0700395 struct scic_sds_remote_device *sci_dev,
396 struct scic_sds_request *sci_req,
397 enum sci_status status)
398{
399 /* We still have a fault in starting the io complete it on the port */
400 if (status == SCI_SUCCESS)
401 scic_sds_remote_device_increment_request_count(sci_dev);
402 else{
403 sci_dev->owning_port->state_handlers->complete_io_handler(
404 sci_dev->owning_port, sci_dev, sci_req
405 );
406 }
407}
408
409
410/**
411 *
412 * @request: This parameter specifies the request being continued.
413 *
414 * This method will continue to post tc for a STP request. This method usually
415 * serves as a callback when RNC gets resumed during a task management
416 * sequence. none
417 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700418static void scic_sds_remote_device_continue_request(void *dev)
Dan Williams88f3b622011-04-22 19:18:03 -0700419{
420 struct scic_sds_remote_device *sci_dev = dev;
421
422 /* we need to check if this request is still valid to continue. */
423 if (sci_dev->working_request)
424 scic_controller_continue_io(sci_dev->working_request);
425}
426
Dan Williams88f3b622011-04-22 19:18:03 -0700427static enum sci_status
428default_device_handler(struct scic_sds_remote_device *sci_dev,
429 const char *func)
430{
431 dev_warn(scirdev_to_dev(sci_dev),
432 "%s: in wrong state: %d\n", func,
433 sci_base_state_machine_get_state(&sci_dev->state_machine));
434 return SCI_FAILURE_INVALID_STATE;
435}
436
Dan Williamsab2e8f72011-04-27 16:32:45 -0700437static enum sci_status scic_sds_remote_device_default_fail_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700438 struct scic_sds_remote_device *sci_dev)
439{
440 return default_device_handler(sci_dev, __func__);
441}
442
Dan Williamsab2e8f72011-04-27 16:32:45 -0700443static enum sci_status scic_sds_remote_device_default_destruct_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700444 struct scic_sds_remote_device *sci_dev)
445{
446 return default_device_handler(sci_dev, __func__);
447}
448
Dan Williamsab2e8f72011-04-27 16:32:45 -0700449static enum sci_status scic_sds_remote_device_default_reset_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700450 struct scic_sds_remote_device *sci_dev)
451{
452 return default_device_handler(sci_dev, __func__);
453}
454
Dan Williamsab2e8f72011-04-27 16:32:45 -0700455static enum sci_status scic_sds_remote_device_default_reset_complete_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700456 struct scic_sds_remote_device *sci_dev)
457{
458 return default_device_handler(sci_dev, __func__);
459}
460
Dan Williamsab2e8f72011-04-27 16:32:45 -0700461static enum sci_status scic_sds_remote_device_default_suspend_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700462 struct scic_sds_remote_device *sci_dev, u32 suspend_type)
463{
464 return default_device_handler(sci_dev, __func__);
465}
466
Dan Williamsab2e8f72011-04-27 16:32:45 -0700467static enum sci_status scic_sds_remote_device_default_resume_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700468 struct scic_sds_remote_device *sci_dev)
469{
470 return default_device_handler(sci_dev, __func__);
471}
472
473/**
474 *
475 * @device: The struct scic_sds_remote_device which is then cast into a
476 * struct scic_sds_remote_device.
477 * @event_code: The event code that the struct scic_sds_controller wants the device
478 * object to process.
479 *
480 * This method is the default event handler. It will call the RNC state
481 * machine handler for any RNC events otherwise it will log a warning and
482 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
483 */
484static enum sci_status scic_sds_remote_device_core_event_handler(
485 struct scic_sds_remote_device *sci_dev,
486 u32 event_code,
487 bool is_ready_state)
488{
489 enum sci_status status;
490
491 switch (scu_get_event_type(event_code)) {
492 case SCU_EVENT_TYPE_RNC_OPS_MISC:
493 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
494 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
495 status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code);
496 break;
497 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
498
499 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
500 status = SCI_SUCCESS;
501
502 /* Suspend the associated RNC */
503 scic_sds_remote_node_context_suspend(&sci_dev->rnc,
504 SCI_SOFTWARE_SUSPENSION,
505 NULL, NULL);
506
507 dev_dbg(scirdev_to_dev(sci_dev),
508 "%s: device: %p event code: %x: %s\n",
509 __func__, sci_dev, event_code,
510 (is_ready_state)
511 ? "I_T_Nexus_Timeout event"
512 : "I_T_Nexus_Timeout event in wrong state");
513
514 break;
515 }
516 /* Else, fall through and treat as unhandled... */
517
518 default:
519 dev_dbg(scirdev_to_dev(sci_dev),
520 "%s: device: %p event code: %x: %s\n",
521 __func__, sci_dev, event_code,
522 (is_ready_state)
523 ? "unexpected event"
524 : "unexpected event in wrong state");
525 status = SCI_FAILURE_INVALID_STATE;
526 break;
527 }
528
529 return status;
530}
531/**
532 *
533 * @device: The struct scic_sds_remote_device which is then cast into a
534 * struct scic_sds_remote_device.
535 * @event_code: The event code that the struct scic_sds_controller wants the device
536 * object to process.
537 *
538 * This method is the default event handler. It will call the RNC state
539 * machine handler for any RNC events otherwise it will log a warning and
540 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
541 */
542static enum sci_status scic_sds_remote_device_default_event_handler(
543 struct scic_sds_remote_device *sci_dev,
544 u32 event_code)
545{
546 return scic_sds_remote_device_core_event_handler(sci_dev,
547 event_code,
548 false);
549}
550
551/**
552 *
553 * @device: The struct scic_sds_remote_device which is then cast into a
554 * struct scic_sds_remote_device.
555 * @frame_index: The frame index for which the struct scic_sds_controller wants this
556 * device object to process.
557 *
558 * This method is the default unsolicited frame handler. It logs a warning,
559 * releases the frame and returns a failure. enum sci_status
560 * SCI_FAILURE_INVALID_STATE
561 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700562static enum sci_status scic_sds_remote_device_default_frame_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700563 struct scic_sds_remote_device *sci_dev,
564 u32 frame_index)
565{
566 dev_warn(scirdev_to_dev(sci_dev),
567 "%s: SCIC Remote Device requested to handle frame %x "
568 "while in wrong state %d\n",
569 __func__,
570 frame_index,
571 sci_base_state_machine_get_state(
572 &sci_dev->state_machine));
573
574 /* Return the frame back to the controller */
575 scic_sds_controller_release_frame(
576 scic_sds_remote_device_get_controller(sci_dev), frame_index
577 );
578
579 return SCI_FAILURE_INVALID_STATE;
580}
581
Dan Williamsab2e8f72011-04-27 16:32:45 -0700582static enum sci_status scic_sds_remote_device_default_start_request_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700583 struct scic_sds_remote_device *sci_dev,
584 struct scic_sds_request *request)
585{
586 return default_device_handler(sci_dev, __func__);
587}
588
Dan Williamsab2e8f72011-04-27 16:32:45 -0700589static enum sci_status scic_sds_remote_device_default_complete_request_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700590 struct scic_sds_remote_device *sci_dev,
591 struct scic_sds_request *request)
592{
593 return default_device_handler(sci_dev, __func__);
594}
595
Dan Williamsab2e8f72011-04-27 16:32:45 -0700596static enum sci_status scic_sds_remote_device_default_continue_request_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700597 struct scic_sds_remote_device *sci_dev,
598 struct scic_sds_request *request)
599{
600 return default_device_handler(sci_dev, __func__);
601}
602
603/**
604 *
605 * @device: The struct scic_sds_remote_device which is then cast into a
606 * struct scic_sds_remote_device.
607 * @frame_index: The frame index for which the struct scic_sds_controller wants this
608 * device object to process.
609 *
610 * This method is a general ssp frame handler. In most cases the device object
611 * needs to route the unsolicited frame processing to the io request object.
612 * This method decodes the tag for the io request object and routes the
613 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
614 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700615static enum sci_status scic_sds_remote_device_general_frame_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700616 struct scic_sds_remote_device *sci_dev,
617 u32 frame_index)
618{
619 enum sci_status result;
620 struct sci_ssp_frame_header *frame_header;
621 struct scic_sds_request *io_request;
622
623 result = scic_sds_unsolicited_frame_control_get_header(
624 &(scic_sds_remote_device_get_controller(sci_dev)->uf_control),
625 frame_index,
626 (void **)&frame_header
627 );
628
629 if (SCI_SUCCESS == result) {
630 io_request = scic_sds_controller_get_io_request_from_tag(
631 scic_sds_remote_device_get_controller(sci_dev), frame_header->tag);
632
633 if ((io_request == NULL)
634 || (io_request->target_device != sci_dev)) {
635 /*
636 * We could not map this tag to a valid IO request
637 * Just toss the frame and continue */
638 scic_sds_controller_release_frame(
639 scic_sds_remote_device_get_controller(sci_dev), frame_index
640 );
641 } else {
642 /* The IO request is now in charge of releasing the frame */
643 result = io_request->state_handlers->frame_handler(
644 io_request, frame_index);
645 }
646 }
647
648 return result;
649}
650
651/**
652 *
653 * @[in]: sci_dev This is the device object that is receiving the event.
654 * @[in]: event_code The event code to process.
655 *
656 * This is a common method for handling events reported to the remote device
657 * from the controller object. enum sci_status
658 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700659static enum sci_status scic_sds_remote_device_general_event_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700660 struct scic_sds_remote_device *sci_dev,
661 u32 event_code)
662{
663 return scic_sds_remote_device_core_event_handler(sci_dev,
664 event_code,
665 true);
666}
667
Dan Williams88f3b622011-04-22 19:18:03 -0700668/**
669 *
670 * @sci_dev: The struct scic_sds_remote_device which is cast into a
671 * struct scic_sds_remote_device.
672 *
673 * This method will destruct a struct scic_sds_remote_device that is in a stopped
674 * state. This is the only state from which a destruct request will succeed.
675 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
676 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
677 * enum sci_status SCI_SUCCESS
678 */
679static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
680 struct scic_sds_remote_device *sci_dev)
681{
682 struct scic_sds_controller *scic;
683
684 scic = scic_sds_remote_device_get_controller(sci_dev);
685 scic_sds_controller_free_remote_node_context(scic, sci_dev,
686 sci_dev->rnc.remote_node_index);
687 sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
688
689 sci_base_state_machine_change_state(&sci_dev->state_machine,
690 SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
691
692 return SCI_SUCCESS;
693}
694
Dan Williams88f3b622011-04-22 19:18:03 -0700695/**
696 *
697 * @device: The struct scic_sds_remote_device object which is cast to a
698 * struct scic_sds_remote_device object.
699 *
700 * This is the ready state device reset handler enum sci_status
701 */
Dan Williamsab2e8f72011-04-27 16:32:45 -0700702static enum sci_status scic_sds_remote_device_ready_state_reset_handler(
Dan Williams88f3b622011-04-22 19:18:03 -0700703 struct scic_sds_remote_device *sci_dev)
704{
705 /* Request the parent state machine to transition to the stopping state */
706 sci_base_state_machine_change_state(&sci_dev->state_machine,
707 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
708
709 return SCI_SUCCESS;
710}
711
712/*
713 * This method will attempt to start a task request for this device object. The
714 * remote device object will issue the start request for the task and if
715 * successful it will start the request for the port object then increment its
716 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
717 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
718 * object could not get the resources to start.
719 */
720static enum sci_status scic_sds_remote_device_ready_state_start_task_handler(
721 struct scic_sds_remote_device *sci_dev,
722 struct scic_sds_request *request)
723{
724 enum sci_status result;
725
726 /* See if the port is in a state where we can start the IO request */
727 result = scic_sds_port_start_io(
728 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
729
730 if (result == SCI_SUCCESS) {
731 result = scic_sds_remote_node_context_start_task(&sci_dev->rnc,
732 request);
733 if (result == SCI_SUCCESS)
734 result = scic_sds_request_start(request);
735
736 scic_sds_remote_device_start_request(sci_dev, request, result);
737 }
738
739 return result;
740}
741
742/*
743 * This method will attempt to start an io request for this device object. The
744 * remote device object will issue the start request for the io and if
745 * successful it will start the request for the port object then increment its
746 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
747 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
748 * object could not get the resources to start.
749 */
750static enum sci_status scic_sds_remote_device_ready_state_start_io_handler(
751 struct scic_sds_remote_device *sci_dev,
752 struct scic_sds_request *request)
753{
754 enum sci_status result;
755
756 /* See if the port is in a state where we can start the IO request */
757 result = scic_sds_port_start_io(
758 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
759
760 if (result == SCI_SUCCESS) {
761 result = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
762 if (result == SCI_SUCCESS)
763 result = scic_sds_request_start(request);
764
765 scic_sds_remote_device_start_request(sci_dev, request, result);
766 }
767
768 return result;
769}
770
771/*
772 * This method will complete the request for the remote device object. The
773 * method will call the completion handler for the request object and if
774 * successful it will complete the request on the port object then decrement
775 * its own started_request_count. enum sci_status
776 */
777static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler(
778 struct scic_sds_remote_device *sci_dev,
779 struct scic_sds_request *request)
780{
781 enum sci_status result;
782
783 result = scic_sds_request_complete(request);
784
785 if (result != SCI_SUCCESS)
786 return result;
787
788 /* See if the port is in a state
789 * where we can start the IO request */
790 result = scic_sds_port_complete_io(
791 scic_sds_remote_device_get_port(sci_dev),
792 sci_dev, request);
793
794 if (result == SCI_SUCCESS)
795 scic_sds_remote_device_decrement_request_count(sci_dev);
796
797 return result;
798}
799
Dan Williams88f3b622011-04-22 19:18:03 -0700800/**
801 *
802 * @device: The device object for which the request is completing.
803 * @request: The task request that is being completed.
804 *
805 * This method completes requests for this struct scic_sds_remote_device while it is
806 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
807 * complete method for the request object and if that is successful the port
808 * object is called to complete the task request. Then the device object itself
809 * completes the task request. If struct scic_sds_remote_device started_request_count
810 * goes to 0 and the invalidate RNC request has completed the device object can
811 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
812 */
813static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler(
814 struct scic_sds_remote_device *sci_dev,
815 struct scic_sds_request *request)
816{
817 enum sci_status status = SCI_SUCCESS;
818
819 status = scic_sds_request_complete(request);
820
821 if (status != SCI_SUCCESS)
822 return status;
823
824 status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev),
825 sci_dev, request);
826 if (status != SCI_SUCCESS)
827 return status;
828
829 scic_sds_remote_device_decrement_request_count(sci_dev);
830
831 if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
832 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
Dan Williamsec575662011-05-01 14:19:25 -0700833 rnc_destruct_done, sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -0700834 return SCI_SUCCESS;
835}
836
Dan Williams88f3b622011-04-22 19:18:03 -0700837static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler(
838 struct scic_sds_remote_device *sci_dev)
839{
Dan Williamsab2e8f72011-04-27 16:32:45 -0700840 sci_base_state_machine_change_state(&sci_dev->state_machine,
841 SCI_BASE_REMOTE_DEVICE_STATE_READY);
Dan Williams88f3b622011-04-22 19:18:03 -0700842
843 return SCI_SUCCESS;
844}
845
Dan Williamsab2e8f72011-04-27 16:32:45 -0700846/* complete requests for this device while it is in the
847 * SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the complete
848 * method for the request object and if that is successful the port object is
849 * called to complete the task request. Then the device object itself completes
850 * the task request. enum sci_status
Dan Williams88f3b622011-04-22 19:18:03 -0700851 */
852static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler(
853 struct scic_sds_remote_device *sci_dev,
854 struct scic_sds_request *request)
855{
856 enum sci_status status = SCI_SUCCESS;
857
858 status = scic_sds_request_complete(request);
859
860 if (status == SCI_SUCCESS) {
861 status = scic_sds_port_complete_io(
862 scic_sds_remote_device_get_port(sci_dev),
863 sci_dev, request);
864
865 if (status == SCI_SUCCESS) {
866 scic_sds_remote_device_decrement_request_count(sci_dev);
867 }
868 }
869
870 return status;
871}
872
Dan Williamsab2e8f72011-04-27 16:32:45 -0700873static enum sci_status scic_sds_stp_remote_device_complete_request(struct scic_sds_remote_device *sci_dev,
874 struct scic_sds_request *sci_req)
875{
876 enum sci_status status;
877
878 status = scic_sds_io_request_complete(sci_req);
879 if (status != SCI_SUCCESS)
880 goto out;
881
882 status = scic_sds_port_complete_io(sci_dev->owning_port, sci_dev, sci_req);
883 if (status != SCI_SUCCESS)
884 goto out;
885
886 scic_sds_remote_device_decrement_request_count(sci_dev);
887 if (sci_req->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
888 /* This request causes hardware error, device needs to be Lun Reset.
889 * So here we force the state machine to IDLE state so the rest IOs
890 * can reach RNC state handler, these IOs will be completed by RNC with
891 * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE".
892 */
893 sci_base_state_machine_change_state(&sci_dev->state_machine,
894 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET);
895 } else if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
896 sci_base_state_machine_change_state(&sci_dev->state_machine,
897 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
898
899
900 out:
901 if (status != SCI_SUCCESS)
902 dev_err(scirdev_to_dev(sci_dev),
903 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
904 "could not complete\n", __func__, sci_dev->owning_port,
905 sci_dev, sci_req, status);
906
907 return status;
908}
909
910/* scic_sds_stp_remote_device_ready_substate_start_request_handler - start stp
911 * @device: The target device a task management request towards to.
912 * @request: The task request.
913 *
914 * This is the READY NCQ substate handler to start task management request. In
915 * this routine, we suspend and resume the RNC. enum sci_status Always return
916 * SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS status to let
917 * controller_start_task_handler know that the controller can't post TC for
918 * task request yet, instead, when RNC gets resumed, a controller_continue_task
919 * callback will be called.
920 */
921static enum sci_status scic_sds_stp_remote_device_ready_substate_start_request_handler(
922 struct scic_sds_remote_device *device,
923 struct scic_sds_request *request)
924{
925 enum sci_status status;
926
927 /* Will the port allow the io request to start? */
928 status = device->owning_port->state_handlers->start_io_handler(
929 device->owning_port, device, request);
930 if (status != SCI_SUCCESS)
931 return status;
932
933 status = scic_sds_remote_node_context_start_task(&device->rnc, request);
934 if (status != SCI_SUCCESS)
935 goto out;
936
937 status = request->state_handlers->start_handler(request);
938 if (status != SCI_SUCCESS)
939 goto out;
940
941 /*
942 * Note: If the remote device state is not IDLE this will replace
943 * the request that probably resulted in the task management request.
944 */
945 device->working_request = request;
946 sci_base_state_machine_change_state(&device->state_machine,
947 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
948
949 /*
950 * The remote node context must cleanup the TCi to NCQ mapping table.
951 * The only way to do this correctly is to either write to the TLCR
952 * register or to invalidate and repost the RNC. In either case the
953 * remote node context state machine will take the correct action when
954 * the remote node context is suspended and later resumed.
955 */
956 scic_sds_remote_node_context_suspend(&device->rnc,
957 SCI_SOFTWARE_SUSPENSION, NULL, NULL);
958 scic_sds_remote_node_context_resume(&device->rnc,
959 scic_sds_remote_device_continue_request,
960 device);
961
962out:
963 scic_sds_remote_device_start_request(device, request, status);
964 /*
965 * We need to let the controller start request handler know that it can't
966 * post TC yet. We will provide a callback function to post TC when RNC gets
967 * resumed.
968 */
969 return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS;
970}
971
972/* handle the start io operation for a sata device that is in the command idle
973 * state. - Evalute the type of IO request to be started - If its an NCQ
974 * request change to NCQ substate - If its any other command change to the CMD
975 * substate
976 *
977 * If this is a softreset we may want to have a different substate.
978 */
979static enum sci_status scic_sds_stp_remote_device_ready_idle_substate_start_io_handler(
980 struct scic_sds_remote_device *sci_dev,
981 struct scic_sds_request *request)
982{
983 enum sci_status status;
984 struct isci_request *isci_request = request->ireq;
985 enum scic_sds_remote_device_states new_state;
986
987 /* Will the port allow the io request to start? */
988 status = sci_dev->owning_port->state_handlers->start_io_handler(
989 sci_dev->owning_port, sci_dev, request);
990 if (status != SCI_SUCCESS)
991 return status;
992
993 status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
994 if (status != SCI_SUCCESS)
995 goto out;
996
997 status = request->state_handlers->start_handler(request);
998 if (status != SCI_SUCCESS)
999 goto out;
1000
1001 if (isci_sata_get_sat_protocol(isci_request) == SAT_PROTOCOL_FPDMA)
1002 new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ;
1003 else {
1004 sci_dev->working_request = request;
1005 new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD;
1006 }
1007 sci_base_state_machine_change_state(&sci_dev->state_machine, new_state);
1008out:
1009 scic_sds_remote_device_start_request(sci_dev, request, status);
1010 return status;
1011}
1012
1013
1014static enum sci_status scic_sds_stp_remote_device_ready_idle_substate_event_handler(
1015 struct scic_sds_remote_device *sci_dev,
1016 u32 event_code)
1017{
1018 enum sci_status status;
1019
1020 status = scic_sds_remote_device_general_event_handler(sci_dev, event_code);
1021 if (status != SCI_SUCCESS)
1022 return status;
1023
1024 /* We pick up suspension events to handle specifically to this state. We
1025 * resume the RNC right away. enum sci_status
1026 */
1027 if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX ||
1028 scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX)
1029 status = scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
1030
1031 return status;
1032}
1033
1034static enum sci_status scic_sds_stp_remote_device_ready_ncq_substate_start_io_handler(
1035 struct scic_sds_remote_device *sci_dev,
1036 struct scic_sds_request *request)
1037{
1038 enum sci_status status;
1039 struct isci_request *isci_request = request->ireq;
1040 scic_sds_port_io_request_handler_t start_io;
1041
1042 if (isci_sata_get_sat_protocol(isci_request) == SAT_PROTOCOL_FPDMA) {
1043 start_io = sci_dev->owning_port->state_handlers->start_io_handler;
1044 status = start_io(sci_dev->owning_port, sci_dev, request);
1045 if (status != SCI_SUCCESS)
1046 return status;
1047
1048 status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
Dan Williamsf619fff2011-05-01 10:13:04 -07001049 if (status == SCI_SUCCESS)
1050 status = request->state_handlers->start_handler(request);
Dan Williamsab2e8f72011-04-27 16:32:45 -07001051
1052 scic_sds_remote_device_start_request(sci_dev, request, status);
1053 } else
1054 status = SCI_FAILURE_INVALID_STATE;
1055
1056 return status;
1057}
1058
1059static enum sci_status scic_sds_stp_remote_device_ready_ncq_substate_frame_handler(struct scic_sds_remote_device *sci_dev,
1060 u32 frame_index)
1061{
1062 enum sci_status status;
1063 struct sata_fis_header *frame_header;
1064 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
1065
1066 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1067 frame_index,
1068 (void **)&frame_header);
1069 if (status != SCI_SUCCESS)
1070 return status;
1071
1072 if (frame_header->fis_type == SATA_FIS_TYPE_SETDEVBITS &&
1073 (frame_header->status & ATA_STATUS_REG_ERROR_BIT)) {
1074 sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
1075
1076 /* TODO Check sactive and complete associated IO if any. */
1077
1078 sci_base_state_machine_change_state(&sci_dev->state_machine,
1079 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
1080 } else if (frame_header->fis_type == SATA_FIS_TYPE_REGD2H &&
1081 (frame_header->status & ATA_STATUS_REG_ERROR_BIT)) {
1082 /*
1083 * Some devices return D2H FIS when an NCQ error is detected.
1084 * Treat this like an SDB error FIS ready reason.
1085 */
1086 sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED;
1087
1088 sci_base_state_machine_change_state(&sci_dev->state_machine,
1089 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
1090 } else
1091 status = SCI_FAILURE;
1092
1093 scic_sds_controller_release_frame(scic, frame_index);
1094
1095 return status;
1096}
1097
1098static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_start_io_handler(
1099 struct scic_sds_remote_device *device,
1100 struct scic_sds_request *request)
1101{
1102 /* device is already handling a command it can not accept new commands
1103 * until this one is complete.
1104 */
1105 return SCI_FAILURE_INVALID_STATE;
1106}
1107
1108static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler(
1109 struct scic_sds_remote_device *sci_dev,
1110 u32 suspend_type)
1111{
1112 enum sci_status status;
1113
1114 status = scic_sds_remote_node_context_suspend(&sci_dev->rnc,
1115 suspend_type, NULL, NULL);
1116
1117 return status;
1118}
1119
1120static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_frame_handler(
1121 struct scic_sds_remote_device *sci_dev,
1122 u32 frame_index)
1123{
1124 /* The device doe not process any UF received from the hardware while
1125 * in this state. All unsolicited frames are forwarded to the io
1126 * request object.
1127 */
1128 return scic_sds_io_request_frame_handler(sci_dev->working_request,
1129 frame_index);
1130}
1131
1132static enum sci_status scic_sds_stp_remote_device_ready_await_reset_substate_start_io_handler(
1133 struct scic_sds_remote_device *device,
1134 struct scic_sds_request *request)
1135{
1136 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
1137}
1138
1139static enum sci_status scic_sds_stp_remote_device_ready_await_reset_substate_complete_request_handler(
1140 struct scic_sds_remote_device *device,
1141 struct scic_sds_request *request)
1142{
1143 struct scic_sds_request *sci_req = request;
1144 enum sci_status status;
1145
1146 status = scic_sds_io_request_complete(sci_req);
1147 if (status != SCI_SUCCESS)
1148 goto out;
1149
1150 status = scic_sds_port_complete_io(device->owning_port, device, sci_req);
1151 if (status != SCI_SUCCESS)
1152 goto out;
1153
1154 scic_sds_remote_device_decrement_request_count(device);
1155 out:
1156 if (status != SCI_SUCCESS)
1157 dev_err(scirdev_to_dev(device),
1158 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
1159 "could not complete\n",
1160 __func__, device->owning_port, device, sci_req, status);
1161
1162 return status;
1163}
1164
1165static void scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev)
1166{
1167 struct scic_sds_remote_device *sci_dev = _dev;
1168 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
1169 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
1170
1171 /* For NCQ operation we do not issue a isci_remote_device_not_ready().
1172 * As a result, avoid sending the ready notification.
1173 */
1174 if (sci_dev->state_machine.previous_state_id != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ)
1175 isci_remote_device_ready(scic->ihost, idev);
1176}
1177
1178static enum sci_status scic_sds_smp_remote_device_ready_idle_substate_start_io_handler(
1179 struct scic_sds_remote_device *sci_dev,
1180 struct scic_sds_request *sci_req)
1181{
1182 enum sci_status status;
1183
1184 /* Will the port allow the io request to start? */
1185 status = sci_dev->owning_port->state_handlers->start_io_handler(
1186 sci_dev->owning_port, sci_dev, sci_req);
1187 if (status != SCI_SUCCESS)
1188 return status;
1189
1190 status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req);
1191 if (status != SCI_SUCCESS)
Dan Williamsf619fff2011-05-01 10:13:04 -07001192 goto out;
Dan Williamsab2e8f72011-04-27 16:32:45 -07001193
1194 status = scic_sds_request_start(sci_req);
1195 if (status != SCI_SUCCESS)
Dan Williamsf619fff2011-05-01 10:13:04 -07001196 goto out;
Dan Williamsab2e8f72011-04-27 16:32:45 -07001197
1198 sci_dev->working_request = sci_req;
1199 sci_base_state_machine_change_state(&sci_dev->state_machine,
1200 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1201
Dan Williamsf619fff2011-05-01 10:13:04 -07001202 out:
Dan Williamsab2e8f72011-04-27 16:32:45 -07001203 scic_sds_remote_device_start_request(sci_dev, sci_req, status);
1204
1205 return status;
1206}
1207
1208static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler(
1209 struct scic_sds_remote_device *device,
1210 struct scic_sds_request *request)
1211{
1212 /* device is already handling a command it can not accept new commands
1213 * until this one is complete.
1214 */
1215 return SCI_FAILURE_INVALID_STATE;
1216}
1217
1218static enum sci_status
1219scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler(struct scic_sds_remote_device *sci_dev,
1220 struct scic_sds_request *sci_req)
1221{
1222 enum sci_status status;
1223
1224 status = scic_sds_io_request_complete(sci_req);
1225 if (status != SCI_SUCCESS)
1226 return status;
1227
1228 status = scic_sds_port_complete_io(sci_dev->owning_port, sci_dev, sci_req);
1229 if (status != SCI_SUCCESS) {
1230 dev_err(scirdev_to_dev(sci_dev),
1231 "%s: SCIC SDS Remote Device 0x%p io request "
1232 "0x%p could not be completd on the port 0x%p "
1233 "failed with status %d.\n", __func__, sci_dev, sci_req,
1234 sci_dev->owning_port, status);
1235 return status;
1236 }
1237
1238 scic_sds_remote_device_decrement_request_count(sci_dev);
1239 sci_base_state_machine_change_state(&sci_dev->state_machine,
1240 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1241
1242 return status;
1243}
1244
1245static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_frame_handler(
1246 struct scic_sds_remote_device *sci_dev,
1247 u32 frame_index)
1248{
1249 enum sci_status status;
1250
1251 /* The device does not process any UF received from the hardware while
1252 * in this state. All unsolicited frames are forwarded to the io request
1253 * object.
1254 */
1255 status = scic_sds_io_request_frame_handler(
1256 sci_dev->working_request,
1257 frame_index
1258 );
1259
1260 return status;
1261}
1262
Dan Williams88f3b622011-04-22 19:18:03 -07001263static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = {
1264 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001265 .fail_handler = scic_sds_remote_device_default_fail_handler,
1266 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1267 .reset_handler = scic_sds_remote_device_default_reset_handler,
1268 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1269 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1270 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1271 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1272 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1273 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1274 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1275 .resume_handler = scic_sds_remote_device_default_resume_handler,
1276 .event_handler = scic_sds_remote_device_default_event_handler,
1277 .frame_handler = scic_sds_remote_device_default_frame_handler
1278 },
1279 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001280 .fail_handler = scic_sds_remote_device_default_fail_handler,
1281 .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler,
1282 .reset_handler = scic_sds_remote_device_default_reset_handler,
1283 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1284 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1285 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1286 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1287 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1288 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1289 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1290 .resume_handler = scic_sds_remote_device_default_resume_handler,
1291 .event_handler = scic_sds_remote_device_default_event_handler,
1292 .frame_handler = scic_sds_remote_device_default_frame_handler
1293 },
1294 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001295 .fail_handler = scic_sds_remote_device_default_fail_handler,
1296 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1297 .reset_handler = scic_sds_remote_device_default_reset_handler,
1298 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1299 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1300 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1301 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1302 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1303 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1304 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1305 .resume_handler = scic_sds_remote_device_default_resume_handler,
1306 .event_handler = scic_sds_remote_device_general_event_handler,
1307 .frame_handler = scic_sds_remote_device_default_frame_handler
1308 },
1309 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001310 .fail_handler = scic_sds_remote_device_default_fail_handler,
1311 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1312 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1313 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1314 .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler,
1315 .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1316 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1317 .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler,
1318 .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1319 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1320 .resume_handler = scic_sds_remote_device_default_resume_handler,
1321 .event_handler = scic_sds_remote_device_general_event_handler,
1322 .frame_handler = scic_sds_remote_device_general_frame_handler,
1323 },
Dan Williamsab2e8f72011-04-27 16:32:45 -07001324 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001325 .fail_handler = scic_sds_remote_device_default_fail_handler,
1326 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1327 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1328 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1329 .start_io_handler = scic_sds_stp_remote_device_ready_idle_substate_start_io_handler,
1330 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1331 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1332 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1333 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1334 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1335 .resume_handler = scic_sds_remote_device_default_resume_handler,
1336 .event_handler = scic_sds_stp_remote_device_ready_idle_substate_event_handler,
1337 .frame_handler = scic_sds_remote_device_default_frame_handler
1338 },
1339 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001340 .fail_handler = scic_sds_remote_device_default_fail_handler,
1341 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1342 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1343 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1344 .start_io_handler = scic_sds_stp_remote_device_ready_cmd_substate_start_io_handler,
1345 .complete_io_handler = scic_sds_stp_remote_device_complete_request,
1346 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1347 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1348 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1349 .suspend_handler = scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler,
1350 .resume_handler = scic_sds_remote_device_default_resume_handler,
1351 .event_handler = scic_sds_remote_device_general_event_handler,
1352 .frame_handler = scic_sds_stp_remote_device_ready_cmd_substate_frame_handler
1353 },
1354 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001355 .fail_handler = scic_sds_remote_device_default_fail_handler,
1356 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1357 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1358 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1359 .start_io_handler = scic_sds_stp_remote_device_ready_ncq_substate_start_io_handler,
1360 .complete_io_handler = scic_sds_stp_remote_device_complete_request,
1361 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1362 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1363 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1364 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1365 .resume_handler = scic_sds_remote_device_default_resume_handler,
1366 .event_handler = scic_sds_remote_device_general_event_handler,
1367 .frame_handler = scic_sds_stp_remote_device_ready_ncq_substate_frame_handler
1368 },
1369 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001370 .fail_handler = scic_sds_remote_device_default_fail_handler,
1371 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1372 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1373 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1374 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1375 .complete_io_handler = scic_sds_stp_remote_device_complete_request,
1376 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1377 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1378 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1379 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1380 .resume_handler = scic_sds_remote_device_default_resume_handler,
1381 .event_handler = scic_sds_remote_device_general_event_handler,
1382 .frame_handler = scic_sds_remote_device_general_frame_handler
1383 },
1384 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001385 .fail_handler = scic_sds_remote_device_default_fail_handler,
1386 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1387 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1388 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1389 .start_io_handler = scic_sds_stp_remote_device_ready_await_reset_substate_start_io_handler,
1390 .complete_io_handler = scic_sds_stp_remote_device_ready_await_reset_substate_complete_request_handler,
1391 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1392 .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler,
1393 .complete_task_handler = scic_sds_stp_remote_device_complete_request,
1394 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1395 .resume_handler = scic_sds_remote_device_default_resume_handler,
1396 .event_handler = scic_sds_remote_device_general_event_handler,
1397 .frame_handler = scic_sds_remote_device_general_frame_handler
1398 },
1399 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001400 .fail_handler = scic_sds_remote_device_default_fail_handler,
1401 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1402 .reset_handler = scic_sds_remote_device_default_reset_handler,
1403 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1404 .start_io_handler = scic_sds_smp_remote_device_ready_idle_substate_start_io_handler,
1405 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1406 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1407 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1408 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1409 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1410 .resume_handler = scic_sds_remote_device_default_resume_handler,
1411 .event_handler = scic_sds_remote_device_general_event_handler,
1412 .frame_handler = scic_sds_remote_device_default_frame_handler
1413 },
1414 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
Dan Williamsab2e8f72011-04-27 16:32:45 -07001415 .fail_handler = scic_sds_remote_device_default_fail_handler,
1416 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1417 .reset_handler = scic_sds_remote_device_default_reset_handler,
1418 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1419 .start_io_handler = scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler,
1420 .complete_io_handler = scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler,
1421 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1422 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1423 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1424 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1425 .resume_handler = scic_sds_remote_device_default_resume_handler,
1426 .event_handler = scic_sds_remote_device_general_event_handler,
1427 .frame_handler = scic_sds_smp_remote_device_ready_cmd_substate_frame_handler
1428 },
Dan Williams88f3b622011-04-22 19:18:03 -07001429 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001430 .fail_handler = scic_sds_remote_device_default_fail_handler,
1431 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1432 .reset_handler = scic_sds_remote_device_default_reset_handler,
1433 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1434 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1435 .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1436 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1437 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1438 .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1439 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1440 .resume_handler = scic_sds_remote_device_default_resume_handler,
1441 .event_handler = scic_sds_remote_device_general_event_handler,
1442 .frame_handler = scic_sds_remote_device_general_frame_handler
1443 },
1444 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001445 .fail_handler = scic_sds_remote_device_default_fail_handler,
1446 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1447 .reset_handler = scic_sds_remote_device_default_reset_handler,
1448 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1449 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1450 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1451 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1452 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1453 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1454 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1455 .resume_handler = scic_sds_remote_device_default_resume_handler,
1456 .event_handler = scic_sds_remote_device_default_event_handler,
1457 .frame_handler = scic_sds_remote_device_general_frame_handler
1458 },
1459 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001460 .fail_handler = scic_sds_remote_device_default_fail_handler,
1461 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1462 .reset_handler = scic_sds_remote_device_default_reset_handler,
1463 .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler,
1464 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1465 .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1466 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1467 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1468 .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1469 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1470 .resume_handler = scic_sds_remote_device_default_resume_handler,
1471 .event_handler = scic_sds_remote_device_default_event_handler,
1472 .frame_handler = scic_sds_remote_device_general_frame_handler
1473 },
1474 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
Dan Williams88f3b622011-04-22 19:18:03 -07001475 .fail_handler = scic_sds_remote_device_default_fail_handler,
1476 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1477 .reset_handler = scic_sds_remote_device_default_reset_handler,
1478 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1479 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1480 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1481 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1482 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1483 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1484 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1485 .resume_handler = scic_sds_remote_device_default_resume_handler,
1486 .event_handler = scic_sds_remote_device_default_event_handler,
1487 .frame_handler = scic_sds_remote_device_default_frame_handler
1488 }
1489};
1490
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001491static void scic_sds_remote_device_initial_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001492{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001493 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001494
Dan Williams88f3b622011-04-22 19:18:03 -07001495 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1496 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL);
1497
1498 /* Initial state is a transitional state to the stopped state */
1499 sci_base_state_machine_change_state(&sci_dev->state_machine,
1500 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1501}
1502
1503/**
Dan Williams88f3b622011-04-22 19:18:03 -07001504 * scic_remote_device_destruct() - free remote node context and destruct
1505 * @remote_device: This parameter specifies the remote device to be destructed.
1506 *
1507 * Remote device objects are a limited resource. As such, they must be
1508 * protected. Thus calls to construct and destruct are mutually exclusive and
1509 * non-reentrant. The return value shall indicate if the device was
1510 * successfully destructed or if some failure occurred. enum sci_status This value
1511 * is returned if the device is successfully destructed.
1512 * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied
1513 * device isn't valid (e.g. it's already been destoryed, the handle isn't
1514 * valid, etc.).
1515 */
1516static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev)
1517{
1518 return sci_dev->state_handlers->destruct_handler(sci_dev);
1519}
1520
Dan Williams6f231dd2011-07-02 22:56:22 -07001521/**
1522 * isci_remote_device_deconstruct() - This function frees an isci_remote_device.
Dan Williamsd9c37392011-03-03 17:59:32 -08001523 * @ihost: This parameter specifies the isci host object.
1524 * @idev: This parameter specifies the remote device to be freed.
Dan Williams6f231dd2011-07-02 22:56:22 -07001525 *
1526 */
Dan Williamsd9c37392011-03-03 17:59:32 -08001527static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07001528{
Dan Williamsd9c37392011-03-03 17:59:32 -08001529 dev_dbg(&ihost->pdev->dev,
1530 "%s: isci_device = %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001531
1532 /* There should not be any outstanding io's. All paths to
1533 * here should go through isci_remote_device_nuke_requests.
1534 * If we hit this condition, we will need a way to complete
1535 * io requests in process */
Dan Williamsd9c37392011-03-03 17:59:32 -08001536 while (!list_empty(&idev->reqs_in_process)) {
Dan Williams6f231dd2011-07-02 22:56:22 -07001537
Dan Williamsd9c37392011-03-03 17:59:32 -08001538 dev_err(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07001539 "%s: ** request list not empty! **\n", __func__);
1540 BUG();
1541 }
1542
Dan Williams57f20f42011-04-21 18:14:45 -07001543 scic_remote_device_destruct(&idev->sci);
Dan Williamsd9c37392011-03-03 17:59:32 -08001544 idev->domain_dev->lldd_dev = NULL;
1545 idev->domain_dev = NULL;
1546 idev->isci_port = NULL;
1547 list_del_init(&idev->node);
Dan Williams6ad31fe2011-03-04 12:10:29 -08001548
Dan Williamsd9c37392011-03-03 17:59:32 -08001549 clear_bit(IDEV_START_PENDING, &idev->flags);
1550 clear_bit(IDEV_STOP_PENDING, &idev->flags);
1551 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -07001552}
1553
Dan Williams88f3b622011-04-22 19:18:03 -07001554/**
1555 * isci_remote_device_stop_complete() - This function is called by the scic
1556 * when the remote device stop has completed. We mark the isci device as not
1557 * ready and remove the isci remote device.
1558 * @ihost: This parameter specifies the isci host object.
1559 * @idev: This parameter specifies the remote device.
1560 * @status: This parameter specifies status of the completion.
1561 *
1562 */
1563static void isci_remote_device_stop_complete(struct isci_host *ihost,
1564 struct isci_remote_device *idev)
1565{
1566 dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev);
1567
1568 isci_remote_device_change_state(idev, isci_stopped);
1569
1570 /* after stop, we can tear down resources. */
1571 isci_remote_device_deconstruct(ihost, idev);
1572}
1573
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001574static void scic_sds_remote_device_stopped_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001575{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001576 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001577 struct scic_sds_controller *scic;
1578 struct isci_remote_device *idev;
1579 struct isci_host *ihost;
1580 u32 prev_state;
1581
Dan Williams88f3b622011-04-22 19:18:03 -07001582 scic = scic_sds_remote_device_get_controller(sci_dev);
Maciej Patelczykd3757c32011-04-28 22:06:06 +00001583 ihost = scic->ihost;
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001584 idev = sci_dev_to_idev(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001585
1586 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1587 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1588
1589 /* If we are entering from the stopping state let the SCI User know that
1590 * the stop operation has completed.
1591 */
1592 prev_state = sci_dev->state_machine.previous_state_id;
1593 if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
1594 isci_remote_device_stop_complete(ihost, idev);
1595
1596 scic_sds_controller_remote_device_stopped(scic, sci_dev);
1597}
1598
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001599static void scic_sds_remote_device_starting_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001600{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001601 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001602 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
Maciej Patelczykd3757c32011-04-28 22:06:06 +00001603 struct isci_host *ihost = scic->ihost;
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001604 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001605
1606 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1607 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
1608
1609 isci_remote_device_not_ready(ihost, idev,
1610 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
1611}
1612
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001613static void scic_sds_remote_device_ready_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001614{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001615 struct scic_sds_remote_device *sci_dev = object;
Dan Williamsab2e8f72011-04-27 16:32:45 -07001616 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
1617 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001618
1619 SET_STATE_HANDLER(sci_dev,
1620 scic_sds_remote_device_state_handler_table,
1621 SCI_BASE_REMOTE_DEVICE_STATE_READY);
1622
1623 scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++;
1624
Dan Williamsab2e8f72011-04-27 16:32:45 -07001625 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_SATA)) {
1626 sci_base_state_machine_change_state(&sci_dev->state_machine,
1627 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1628 } else if (dev_is_expander(dev)) {
1629 sci_base_state_machine_change_state(&sci_dev->state_machine,
1630 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1631 } else
1632 isci_remote_device_ready(scic->ihost, sci_dev_to_idev(sci_dev));
Dan Williams88f3b622011-04-22 19:18:03 -07001633}
1634
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001635static void scic_sds_remote_device_ready_state_exit(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001636{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001637 struct scic_sds_remote_device *sci_dev = object;
Dan Williamsab2e8f72011-04-27 16:32:45 -07001638 struct domain_device *dev = sci_dev_to_domain(sci_dev);
1639
1640 if (dev->dev_type == SAS_END_DEV) {
1641 struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller;
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001642 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001643
Dan Williamsab2e8f72011-04-27 16:32:45 -07001644 isci_remote_device_not_ready(scic->ihost, idev,
Dan Williams88f3b622011-04-22 19:18:03 -07001645 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
1646 }
1647}
1648
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001649static void scic_sds_remote_device_stopping_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001650{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001651 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001652
1653 SET_STATE_HANDLER(
1654 sci_dev,
1655 scic_sds_remote_device_state_handler_table,
1656 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1657 );
1658}
1659
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001660static void scic_sds_remote_device_failed_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001661{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001662 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001663
1664 SET_STATE_HANDLER(
1665 sci_dev,
1666 scic_sds_remote_device_state_handler_table,
1667 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1668 );
1669}
1670
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001671static void scic_sds_remote_device_resetting_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001672{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001673 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001674
1675 SET_STATE_HANDLER(
1676 sci_dev,
1677 scic_sds_remote_device_state_handler_table,
1678 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1679 );
1680
1681 scic_sds_remote_node_context_suspend(
1682 &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
1683}
1684
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001685static void scic_sds_remote_device_resetting_state_exit(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001686{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001687 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001688
1689 scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
1690}
1691
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001692static void scic_sds_remote_device_final_state_enter(void *object)
Dan Williams88f3b622011-04-22 19:18:03 -07001693{
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001694 struct scic_sds_remote_device *sci_dev = object;
Dan Williams88f3b622011-04-22 19:18:03 -07001695
1696 SET_STATE_HANDLER(
1697 sci_dev,
1698 scic_sds_remote_device_state_handler_table,
1699 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1700 );
1701}
1702
Dan Williamsab2e8f72011-04-27 16:32:45 -07001703static void scic_sds_stp_remote_device_ready_idle_substate_enter(void *object)
1704{
1705 struct scic_sds_remote_device *sci_dev = object;
1706
1707 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1708 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1709
1710 sci_dev->working_request = NULL;
1711 if (scic_sds_remote_node_context_is_ready(&sci_dev->rnc)) {
1712 /*
1713 * Since the RNC is ready, it's alright to finish completion
1714 * processing (e.g. signal the remote device is ready). */
1715 scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(sci_dev);
1716 } else {
1717 scic_sds_remote_node_context_resume(&sci_dev->rnc,
1718 scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler,
1719 sci_dev);
1720 }
1721}
1722
1723static void scic_sds_stp_remote_device_ready_cmd_substate_enter(void *object)
1724{
1725 struct scic_sds_remote_device *sci_dev = object;
1726 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1727
1728 BUG_ON(sci_dev->working_request == NULL);
1729
1730 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1731 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1732
1733 isci_remote_device_not_ready(scic->ihost, sci_dev_to_idev(sci_dev),
1734 SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED);
1735}
1736
1737static void scic_sds_stp_remote_device_ready_ncq_substate_enter(void *object)
1738{
1739 struct scic_sds_remote_device *sci_dev = object;
1740
1741 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1742 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ);
1743}
1744
1745static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(void *object)
1746{
1747 struct scic_sds_remote_device *sci_dev = object;
1748 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1749 struct isci_remote_device *idev = sci_dev_to_idev(sci_dev);
1750
1751 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1752 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
1753
1754 if (sci_dev->not_ready_reason == SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED)
1755 isci_remote_device_not_ready(scic->ihost, idev,
1756 sci_dev->not_ready_reason);
1757}
1758
1759static void scic_sds_stp_remote_device_ready_await_reset_substate_enter(void *object)
1760{
1761 struct scic_sds_remote_device *sci_dev = object;
1762
1763 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1764 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET);
1765}
1766
1767static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object)
1768{
1769 struct scic_sds_remote_device *sci_dev = object;
1770 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1771
1772 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1773 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
1774
1775 isci_remote_device_ready(scic->ihost, sci_dev_to_idev(sci_dev));
1776}
1777
1778static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object)
1779{
1780 struct scic_sds_remote_device *sci_dev = object;
1781 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1782
1783 BUG_ON(sci_dev->working_request == NULL);
1784
1785 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1786 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
1787
1788 isci_remote_device_not_ready(scic->ihost, sci_dev_to_idev(sci_dev),
1789 SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
1790}
1791
1792static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object)
1793{
1794 struct scic_sds_remote_device *sci_dev = object;
1795
1796 sci_dev->working_request = NULL;
1797}
Dan Williams88f3b622011-04-22 19:18:03 -07001798
1799static const struct sci_base_state scic_sds_remote_device_state_table[] = {
1800 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1801 .enter_state = scic_sds_remote_device_initial_state_enter,
1802 },
1803 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1804 .enter_state = scic_sds_remote_device_stopped_state_enter,
1805 },
1806 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1807 .enter_state = scic_sds_remote_device_starting_state_enter,
1808 },
1809 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1810 .enter_state = scic_sds_remote_device_ready_state_enter,
1811 .exit_state = scic_sds_remote_device_ready_state_exit
1812 },
Dan Williamsab2e8f72011-04-27 16:32:45 -07001813 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
1814 .enter_state = scic_sds_stp_remote_device_ready_idle_substate_enter,
1815 },
1816 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
1817 .enter_state = scic_sds_stp_remote_device_ready_cmd_substate_enter,
1818 },
1819 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = {
1820 .enter_state = scic_sds_stp_remote_device_ready_ncq_substate_enter,
1821 },
1822 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = {
1823 .enter_state = scic_sds_stp_remote_device_ready_ncq_error_substate_enter,
1824 },
1825 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = {
1826 .enter_state = scic_sds_stp_remote_device_ready_await_reset_substate_enter,
1827 },
1828 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = {
1829 .enter_state = scic_sds_smp_remote_device_ready_idle_substate_enter,
1830 },
1831 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = {
1832 .enter_state = scic_sds_smp_remote_device_ready_cmd_substate_enter,
1833 .exit_state = scic_sds_smp_remote_device_ready_cmd_substate_exit,
1834 },
Dan Williams88f3b622011-04-22 19:18:03 -07001835 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1836 .enter_state = scic_sds_remote_device_stopping_state_enter,
1837 },
1838 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1839 .enter_state = scic_sds_remote_device_failed_state_enter,
1840 },
1841 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1842 .enter_state = scic_sds_remote_device_resetting_state_enter,
1843 .exit_state = scic_sds_remote_device_resetting_state_exit
1844 },
1845 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1846 .enter_state = scic_sds_remote_device_final_state_enter,
1847 },
1848};
1849
1850/**
Dan Williamsb87ee302011-04-25 11:48:29 -07001851 * scic_remote_device_construct() - common construction
Dan Williams88f3b622011-04-22 19:18:03 -07001852 * @sci_port: SAS/SATA port through which this device is accessed.
1853 * @sci_dev: remote device to construct
1854 *
Dan Williamsb87ee302011-04-25 11:48:29 -07001855 * This routine just performs benign initialization and does not
1856 * allocate the remote_node_context which is left to
1857 * scic_remote_device_[de]a_construct(). scic_remote_device_destruct()
1858 * frees the remote_node_context(s) for the device.
Dan Williams88f3b622011-04-22 19:18:03 -07001859 */
1860static void scic_remote_device_construct(struct scic_sds_port *sci_port,
1861 struct scic_sds_remote_device *sci_dev)
1862{
1863 sci_dev->owning_port = sci_port;
1864 sci_dev->started_request_count = 0;
Dan Williams88f3b622011-04-22 19:18:03 -07001865
1866 sci_base_state_machine_construct(
1867 &sci_dev->state_machine,
Maciej Patelczyk5d937e92011-04-28 22:06:21 +00001868 sci_dev,
Dan Williams88f3b622011-04-22 19:18:03 -07001869 scic_sds_remote_device_state_table,
1870 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1871 );
1872
1873 sci_base_state_machine_start(
1874 &sci_dev->state_machine
1875 );
1876
1877 scic_sds_remote_node_context_construct(&sci_dev->rnc,
1878 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
Dan Williams88f3b622011-04-22 19:18:03 -07001879}
1880
1881/**
Dan Williamsb87ee302011-04-25 11:48:29 -07001882 * scic_remote_device_da_construct() - construct direct attached device.
Dan Williams88f3b622011-04-22 19:18:03 -07001883 *
Dan Williamsb87ee302011-04-25 11:48:29 -07001884 * The information (e.g. IAF, Signature FIS, etc.) necessary to build
1885 * the device is known to the SCI Core since it is contained in the
1886 * scic_phy object. Remote node context(s) is/are a global resource
1887 * allocated by this routine, freed by scic_remote_device_destruct().
1888 *
1889 * Returns:
1890 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
1891 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
1892 * sata-only controller instance.
1893 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
Dan Williams88f3b622011-04-22 19:18:03 -07001894 */
Dan Williamsb87ee302011-04-25 11:48:29 -07001895static enum sci_status scic_remote_device_da_construct(struct scic_sds_port *sci_port,
1896 struct scic_sds_remote_device *sci_dev)
Dan Williams88f3b622011-04-22 19:18:03 -07001897{
1898 enum sci_status status;
Dan Williamsa1a113b2011-04-21 18:44:45 -07001899 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001900
Dan Williamsb87ee302011-04-25 11:48:29 -07001901 scic_remote_device_construct(sci_port, sci_dev);
1902
Dan Williams88f3b622011-04-22 19:18:03 -07001903 /*
1904 * This information is request to determine how many remote node context
1905 * entries will be needed to store the remote node.
1906 */
Dan Williams88f3b622011-04-22 19:18:03 -07001907 sci_dev->is_direct_attached = true;
Dan Williamsa1a113b2011-04-21 18:44:45 -07001908 status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller,
1909 sci_dev,
Dan Williamsab2e8f72011-04-27 16:32:45 -07001910 &sci_dev->rnc.remote_node_index);
Dan Williams88f3b622011-04-22 19:18:03 -07001911
Dan Williamsa1a113b2011-04-21 18:44:45 -07001912 if (status != SCI_SUCCESS)
1913 return status;
Dan Williams88f3b622011-04-22 19:18:03 -07001914
Dan Williamsab2e8f72011-04-27 16:32:45 -07001915 if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV ||
1916 (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev))
1917 /* pass */;
1918 else
Dan Williamsa1a113b2011-04-21 18:44:45 -07001919 return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williams88f3b622011-04-22 19:18:03 -07001920
Dan Williamsa1a113b2011-04-21 18:44:45 -07001921 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(sci_port);
Dan Williams88f3b622011-04-22 19:18:03 -07001922
Dan Williamsa1a113b2011-04-21 18:44:45 -07001923 /* / @todo Should I assign the port width by reading all of the phys on the port? */
1924 sci_dev->device_port_width = 1;
Dan Williams88f3b622011-04-22 19:18:03 -07001925
Dan Williamsa1a113b2011-04-21 18:44:45 -07001926 return SCI_SUCCESS;
Dan Williams88f3b622011-04-22 19:18:03 -07001927}
1928
Dan Williams88f3b622011-04-22 19:18:03 -07001929/**
Dan Williamsb87ee302011-04-25 11:48:29 -07001930 * scic_remote_device_ea_construct() - construct expander attached device
Dan Williams88f3b622011-04-22 19:18:03 -07001931 *
Dan Williamsb87ee302011-04-25 11:48:29 -07001932 * Remote node context(s) is/are a global resource allocated by this
1933 * routine, freed by scic_remote_device_destruct().
1934 *
1935 * Returns:
1936 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
1937 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
1938 * sata-only controller instance.
1939 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
Dan Williams88f3b622011-04-22 19:18:03 -07001940 */
Dan Williamsb87ee302011-04-25 11:48:29 -07001941static enum sci_status scic_remote_device_ea_construct(struct scic_sds_port *sci_port,
Dan Williams00d680e2011-04-25 14:29:29 -07001942 struct scic_sds_remote_device *sci_dev)
Dan Williams88f3b622011-04-22 19:18:03 -07001943{
Dan Williamsa1a113b2011-04-21 18:44:45 -07001944 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001945 enum sci_status status;
Dan Williams88f3b622011-04-22 19:18:03 -07001946
Dan Williamsb87ee302011-04-25 11:48:29 -07001947 scic_remote_device_construct(sci_port, sci_dev);
Dan Williams88f3b622011-04-22 19:18:03 -07001948
Dan Williamsab2e8f72011-04-27 16:32:45 -07001949 status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller,
1950 sci_dev,
1951 &sci_dev->rnc.remote_node_index);
Dan Williamsa1a113b2011-04-21 18:44:45 -07001952 if (status != SCI_SUCCESS)
1953 return status;
Dan Williams88f3b622011-04-22 19:18:03 -07001954
Dan Williamsab2e8f72011-04-27 16:32:45 -07001955 if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV ||
1956 (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev))
1957 /* pass */;
1958 else
1959 return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
Dan Williams88f3b622011-04-22 19:18:03 -07001960
Dan Williamsa1a113b2011-04-21 18:44:45 -07001961 /*
1962 * For SAS-2 the physical link rate is actually a logical link
1963 * rate that incorporates multiplexing. The SCU doesn't
1964 * incorporate multiplexing and for the purposes of the
1965 * connection the logical link rate is that same as the
1966 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
1967 * one another, so this code works for both situations. */
1968 sci_dev->connection_rate = min_t(u16, scic_sds_port_get_max_allowed_speed(sci_port),
Dan Williams00d680e2011-04-25 14:29:29 -07001969 dev->linkrate);
Dan Williams88f3b622011-04-22 19:18:03 -07001970
Dan Williamsa1a113b2011-04-21 18:44:45 -07001971 /* / @todo Should I assign the port width by reading all of the phys on the port? */
1972 sci_dev->device_port_width = 1;
Dan Williams88f3b622011-04-22 19:18:03 -07001973
Dan Williamsab2e8f72011-04-27 16:32:45 -07001974 return SCI_SUCCESS;
Dan Williams88f3b622011-04-22 19:18:03 -07001975}
1976
1977/**
1978 * scic_remote_device_start() - This method will start the supplied remote
1979 * device. This method enables normal IO requests to flow through to the
1980 * remote device.
1981 * @remote_device: This parameter specifies the device to be started.
1982 * @timeout: This parameter specifies the number of milliseconds in which the
1983 * start operation should complete.
1984 *
1985 * An indication of whether the device was successfully started. SCI_SUCCESS
1986 * This value is returned if the device was successfully started.
1987 * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start
1988 * the device when there have been no phys added to it.
1989 */
1990static enum sci_status scic_remote_device_start(struct scic_sds_remote_device *sci_dev,
Dan Williamseb229672011-05-01 14:05:57 -07001991 u32 timeout)
Dan Williams88f3b622011-04-22 19:18:03 -07001992{
Dan Williamseb229672011-05-01 14:05:57 -07001993 struct sci_base_state_machine *sm = &sci_dev->state_machine;
1994 enum scic_sds_remote_device_states state = sm->current_state_id;
1995 enum sci_status status;
1996
1997 if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) {
1998 dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n",
1999 __func__, state);
2000 return SCI_FAILURE_INVALID_STATE;
2001 }
2002
2003 status = scic_sds_remote_node_context_resume(&sci_dev->rnc,
2004 remote_device_resume_done,
2005 sci_dev);
2006 if (status != SCI_SUCCESS)
2007 return status;
2008
2009 sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
2010
2011 return SCI_SUCCESS;
Dan Williams88f3b622011-04-22 19:18:03 -07002012}
Dan Williams6f231dd2011-07-02 22:56:22 -07002013
Dan Williams00d680e2011-04-25 14:29:29 -07002014static enum sci_status isci_remote_device_construct(struct isci_port *iport,
2015 struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002016{
Dan Williams00d680e2011-04-25 14:29:29 -07002017 struct scic_sds_port *sci_port = iport->sci_port_handle;
2018 struct isci_host *ihost = iport->isci_host;
2019 struct domain_device *dev = idev->domain_dev;
2020 enum sci_status status;
Dan Williams6f231dd2011-07-02 22:56:22 -07002021
Dan Williams00d680e2011-04-25 14:29:29 -07002022 if (dev->parent && dev_is_expander(dev->parent))
2023 status = scic_remote_device_ea_construct(sci_port, &idev->sci);
2024 else
2025 status = scic_remote_device_da_construct(sci_port, &idev->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -07002026
2027 if (status != SCI_SUCCESS) {
Dan Williams00d680e2011-04-25 14:29:29 -07002028 dev_dbg(&ihost->pdev->dev, "%s: construct failed: %d\n",
2029 __func__, status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002030
2031 return status;
2032 }
2033
Dan Williams6f231dd2011-07-02 22:56:22 -07002034 /* start the device. */
Dan Williams00d680e2011-04-25 14:29:29 -07002035 status = scic_remote_device_start(&idev->sci, ISCI_REMOTE_DEVICE_START_TIMEOUT);
Dan Williams6f231dd2011-07-02 22:56:22 -07002036
Dan Williams00d680e2011-04-25 14:29:29 -07002037 if (status != SCI_SUCCESS)
2038 dev_warn(&ihost->pdev->dev, "remote device start failed: %d\n",
2039 status);
Dan Williams6f231dd2011-07-02 22:56:22 -07002040
2041 return status;
2042}
2043
Dan Williams4393aa42011-03-31 13:10:44 -07002044void isci_remote_device_nuke_requests(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002045{
2046 DECLARE_COMPLETION_ONSTACK(aborted_task_completion);
Dan Williams6f231dd2011-07-02 22:56:22 -07002047
Dan Williams4393aa42011-03-31 13:10:44 -07002048 dev_dbg(&ihost->pdev->dev,
2049 "%s: idev = %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002050
2051 /* Cleanup all requests pending for this device. */
Dan Williams4393aa42011-03-31 13:10:44 -07002052 isci_terminate_pending_requests(ihost, idev, terminating);
Dan Williams6f231dd2011-07-02 22:56:22 -07002053
Dan Williams4393aa42011-03-31 13:10:44 -07002054 dev_dbg(&ihost->pdev->dev,
2055 "%s: idev = %p, done\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002056}
2057
Dan Williams6f231dd2011-07-02 22:56:22 -07002058/**
2059 * This function builds the isci_remote_device when a libsas dev_found message
2060 * is received.
2061 * @isci_host: This parameter specifies the isci host object.
2062 * @port: This parameter specifies the isci_port conected to this device.
2063 *
2064 * pointer to new isci_remote_device.
2065 */
2066static struct isci_remote_device *
Dan Williamsd9c37392011-03-03 17:59:32 -08002067isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport)
Dan Williams6f231dd2011-07-02 22:56:22 -07002068{
Dan Williamsd9c37392011-03-03 17:59:32 -08002069 struct isci_remote_device *idev;
2070 int i;
Dan Williams6f231dd2011-07-02 22:56:22 -07002071
Dan Williamsd9c37392011-03-03 17:59:32 -08002072 for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
Dan Williams57f20f42011-04-21 18:14:45 -07002073 idev = &ihost->devices[i];
Dan Williamsd9c37392011-03-03 17:59:32 -08002074 if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags))
2075 break;
2076 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002077
Dan Williamsd9c37392011-03-03 17:59:32 -08002078 if (i >= SCI_MAX_REMOTE_DEVICES) {
2079 dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -07002080 return NULL;
2081 }
2082
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -07002083 if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n"))
2084 return NULL;
2085
2086 if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n"))
2087 return NULL;
2088
Dan Williamsd9c37392011-03-03 17:59:32 -08002089 isci_remote_device_change_state(idev, isci_freed);
Dan Williams6f231dd2011-07-02 22:56:22 -07002090
Dan Williamsd9c37392011-03-03 17:59:32 -08002091 return idev;
Dan Williams6f231dd2011-07-02 22:56:22 -07002092}
Dan Williams6f231dd2011-07-02 22:56:22 -07002093
2094/**
Dan Williams6f231dd2011-07-02 22:56:22 -07002095 * isci_remote_device_stop() - This function is called internally to stop the
2096 * remote device.
2097 * @isci_host: This parameter specifies the isci host object.
2098 * @isci_device: This parameter specifies the remote device.
2099 *
2100 * The status of the scic request to stop.
2101 */
Dan Williams6ad31fe2011-03-04 12:10:29 -08002102enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002103{
2104 enum sci_status status;
2105 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -07002106
Dan Williams6ad31fe2011-03-04 12:10:29 -08002107 dev_dbg(&ihost->pdev->dev,
2108 "%s: isci_device = %p\n", __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002109
Dan Williams6ad31fe2011-03-04 12:10:29 -08002110 isci_remote_device_change_state(idev, isci_stopping);
Jeff Skirvin6e2802a2011-03-08 20:32:16 -07002111
2112 /* Kill all outstanding requests. */
Dan Williams4393aa42011-03-31 13:10:44 -07002113 isci_remote_device_nuke_requests(ihost, idev);
Jeff Skirvin6e2802a2011-03-08 20:32:16 -07002114
Dan Williams6ad31fe2011-03-04 12:10:29 -08002115 set_bit(IDEV_STOP_PENDING, &idev->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002116
Dan Williams6ad31fe2011-03-04 12:10:29 -08002117 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams57f20f42011-04-21 18:14:45 -07002118 status = scic_remote_device_stop(&idev->sci, 50);
Dan Williams6ad31fe2011-03-04 12:10:29 -08002119 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002120
2121 /* Wait for the stop complete callback. */
Dan Williamsd9c37392011-03-03 17:59:32 -08002122 if (status == SCI_SUCCESS) {
Dan Williams6ad31fe2011-03-04 12:10:29 -08002123 wait_for_device_stop(ihost, idev);
Dan Williamsd9c37392011-03-03 17:59:32 -08002124 clear_bit(IDEV_ALLOCATED, &idev->flags);
2125 }
Dan Williams6f231dd2011-07-02 22:56:22 -07002126
Dan Williams6ad31fe2011-03-04 12:10:29 -08002127 dev_dbg(&ihost->pdev->dev,
2128 "%s: idev = %p - after completion wait\n",
2129 __func__, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002130
Dan Williams6f231dd2011-07-02 22:56:22 -07002131 return status;
2132}
2133
2134/**
2135 * isci_remote_device_gone() - This function is called by libsas when a domain
2136 * device is removed.
2137 * @domain_device: This parameter specifies the libsas domain device.
2138 *
2139 */
Dan Williams6ad31fe2011-03-04 12:10:29 -08002140void isci_remote_device_gone(struct domain_device *dev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002141{
Dan Williams4393aa42011-03-31 13:10:44 -07002142 struct isci_host *ihost = dev_to_ihost(dev);
Dan Williams6ad31fe2011-03-04 12:10:29 -08002143 struct isci_remote_device *idev = dev->lldd_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07002144
Dan Williams6ad31fe2011-03-04 12:10:29 -08002145 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -07002146 "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
Dan Williams6ad31fe2011-03-04 12:10:29 -08002147 __func__, dev, idev, idev->isci_port);
Dan Williams6f231dd2011-07-02 22:56:22 -07002148
Dan Williams6ad31fe2011-03-04 12:10:29 -08002149 isci_remote_device_stop(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002150}
2151
2152
2153/**
2154 * isci_remote_device_found() - This function is called by libsas when a remote
2155 * device is discovered. A remote device object is created and started. the
2156 * function then sleeps until the sci core device started message is
2157 * received.
2158 * @domain_device: This parameter specifies the libsas domain device.
2159 *
2160 * status, zero indicates success.
2161 */
2162int isci_remote_device_found(struct domain_device *domain_dev)
2163{
Dan Williams4393aa42011-03-31 13:10:44 -07002164 struct isci_host *isci_host = dev_to_ihost(domain_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07002165 struct isci_port *isci_port;
2166 struct isci_phy *isci_phy;
2167 struct asd_sas_port *sas_port;
2168 struct asd_sas_phy *sas_phy;
2169 struct isci_remote_device *isci_device;
2170 enum sci_status status;
Dan Williams6f231dd2011-07-02 22:56:22 -07002171
Dan Williams6f231dd2011-07-02 22:56:22 -07002172 dev_dbg(&isci_host->pdev->dev,
2173 "%s: domain_device = %p\n", __func__, domain_dev);
2174
Dan Williams0cf89d12011-02-18 09:25:07 -08002175 wait_for_start(isci_host);
2176
Dan Williams6f231dd2011-07-02 22:56:22 -07002177 sas_port = domain_dev->port;
2178 sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy,
2179 port_phy_el);
2180 isci_phy = to_isci_phy(sas_phy);
2181 isci_port = isci_phy->isci_port;
2182
2183 /* we are being called for a device on this port,
2184 * so it has to come up eventually
2185 */
2186 wait_for_completion(&isci_port->start_complete);
2187
2188 if ((isci_stopping == isci_port_get_state(isci_port)) ||
2189 (isci_stopped == isci_port_get_state(isci_port)))
2190 return -ENODEV;
2191
2192 isci_device = isci_remote_device_alloc(isci_host, isci_port);
Dan Williamsd9c37392011-03-03 17:59:32 -08002193 if (!isci_device)
2194 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -07002195
2196 INIT_LIST_HEAD(&isci_device->node);
2197 domain_dev->lldd_dev = isci_device;
2198 isci_device->domain_dev = domain_dev;
2199 isci_device->isci_port = isci_port;
2200 isci_remote_device_change_state(isci_device, isci_starting);
2201
2202
Dan Williams1a380452011-03-03 18:01:43 -08002203 spin_lock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002204 list_add_tail(&isci_device->node, &isci_port->remote_dev_list);
2205
Dan Williams6ad31fe2011-03-04 12:10:29 -08002206 set_bit(IDEV_START_PENDING, &isci_device->flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002207 status = isci_remote_device_construct(isci_port, isci_device);
Dan Williams1a380452011-03-03 18:01:43 -08002208 spin_unlock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002209
Dan Williams6f231dd2011-07-02 22:56:22 -07002210 dev_dbg(&isci_host->pdev->dev,
2211 "%s: isci_device = %p\n",
2212 __func__, isci_device);
2213
2214 if (status != SCI_SUCCESS) {
2215
Dan Williams1a380452011-03-03 18:01:43 -08002216 spin_lock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002217 isci_remote_device_deconstruct(
2218 isci_host,
2219 isci_device
2220 );
Dan Williams1a380452011-03-03 18:01:43 -08002221 spin_unlock_irq(&isci_host->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002222 return -ENODEV;
2223 }
2224
Dan Williams6ad31fe2011-03-04 12:10:29 -08002225 /* wait for the device ready callback. */
2226 wait_for_device_start(isci_host, isci_device);
2227
Dan Williams6f231dd2011-07-02 22:56:22 -07002228 return 0;
2229}
2230/**
2231 * isci_device_is_reset_pending() - This function will check if there is any
2232 * pending reset condition on the device.
2233 * @request: This parameter is the isci_device object.
2234 *
2235 * true if there is a reset pending for the device.
2236 */
2237bool isci_device_is_reset_pending(
2238 struct isci_host *isci_host,
2239 struct isci_remote_device *isci_device)
2240{
2241 struct isci_request *isci_request;
2242 struct isci_request *tmp_req;
2243 bool reset_is_pending = false;
2244 unsigned long flags;
2245
2246 dev_dbg(&isci_host->pdev->dev,
2247 "%s: isci_device = %p\n", __func__, isci_device);
2248
2249 spin_lock_irqsave(&isci_host->scic_lock, flags);
2250
2251 /* Check for reset on all pending requests. */
2252 list_for_each_entry_safe(isci_request, tmp_req,
2253 &isci_device->reqs_in_process, dev_node) {
2254 dev_dbg(&isci_host->pdev->dev,
2255 "%s: isci_device = %p request = %p\n",
2256 __func__, isci_device, isci_request);
2257
2258 if (isci_request->ttype == io_task) {
Dan Williams6f231dd2011-07-02 22:56:22 -07002259 struct sas_task *task = isci_request_access_task(
2260 isci_request);
2261
Bartosz Barcinski467e8552011-04-12 17:28:41 -07002262 spin_lock(&task->task_state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002263 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
2264 reset_is_pending = true;
Bartosz Barcinski467e8552011-04-12 17:28:41 -07002265 spin_unlock(&task->task_state_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -07002266 }
2267 }
2268
2269 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
2270
2271 dev_dbg(&isci_host->pdev->dev,
2272 "%s: isci_device = %p reset_is_pending = %d\n",
2273 __func__, isci_device, reset_is_pending);
2274
2275 return reset_is_pending;
2276}
2277
2278/**
2279 * isci_device_clear_reset_pending() - This function will clear if any pending
2280 * reset condition flags on the device.
2281 * @request: This parameter is the isci_device object.
2282 *
2283 * true if there is a reset pending for the device.
2284 */
Dan Williams4393aa42011-03-31 13:10:44 -07002285void isci_device_clear_reset_pending(struct isci_host *ihost, struct isci_remote_device *idev)
Dan Williams6f231dd2011-07-02 22:56:22 -07002286{
2287 struct isci_request *isci_request;
2288 struct isci_request *tmp_req;
Dan Williams6f231dd2011-07-02 22:56:22 -07002289 unsigned long flags = 0;
2290
Dan Williams4393aa42011-03-31 13:10:44 -07002291 dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n",
2292 __func__, idev, ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -07002293
Dan Williams4393aa42011-03-31 13:10:44 -07002294 spin_lock_irqsave(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002295
2296 /* Clear reset pending on all pending requests. */
2297 list_for_each_entry_safe(isci_request, tmp_req,
Dan Williams4393aa42011-03-31 13:10:44 -07002298 &idev->reqs_in_process, dev_node) {
2299 dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n",
2300 __func__, idev, isci_request);
Dan Williams6f231dd2011-07-02 22:56:22 -07002301
2302 if (isci_request->ttype == io_task) {
2303
2304 unsigned long flags2;
2305 struct sas_task *task = isci_request_access_task(
2306 isci_request);
2307
2308 spin_lock_irqsave(&task->task_state_lock, flags2);
2309 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
2310 spin_unlock_irqrestore(&task->task_state_lock, flags2);
2311 }
2312 }
Dan Williams4393aa42011-03-31 13:10:44 -07002313 spin_unlock_irqrestore(&ihost->scic_lock, flags);
Dan Williams6f231dd2011-07-02 22:56:22 -07002314}