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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
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.
55 #include "intel_sas.h"
56 #include "intel_ata.h"
59 #include "remote_device.h"
61 #include "scic_controller.h"
62 #include "scic_io_request.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"
72 #include "scu_event_codes.h"
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
80 * status of the object as a isci_status enum.
82 void isci_remote_device_change_state(
83 struct isci_remote_device
*isci_device
,
84 enum isci_status status
)
88 spin_lock_irqsave(&isci_device
->state_lock
, flags
);
89 isci_device
->status
= status
;
90 spin_unlock_irqrestore(&isci_device
->state_lock
, flags
);
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
101 static void isci_remote_device_not_ready(struct isci_host
*ihost
,
102 struct isci_remote_device
*idev
, u32 reason
)
104 dev_dbg(&ihost
->pdev
->dev
,
105 "%s: isci_device = %p\n", __func__
, idev
);
107 if (reason
== SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED
)
108 isci_remote_device_change_state(idev
, isci_stopping
);
110 /* device ready is actually a "not ready for io" state. */
111 isci_remote_device_change_state(idev
, isci_ready
);
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
118 * @ihost: our valid isci_host
119 * @idev: remote device
122 static void isci_remote_device_ready(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
124 dev_dbg(&ihost
->pdev
->dev
,
125 "%s: idev = %p\n", __func__
, idev
);
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
);
132 /* 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
135 static void rnc_destruct_done(void *_dev
)
137 struct scic_sds_remote_device
*sci_dev
= _dev
;
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
);
144 static enum sci_status
scic_sds_remote_device_terminate_requests(struct scic_sds_remote_device
*sci_dev
)
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
;
150 for (i
= 0; i
< SCI_MAX_IO_REQUESTS
&& i
< request_count
; i
++) {
151 struct scic_sds_request
*sci_req
;
154 sci_req
= scic
->io_request_table
[i
];
155 if (!sci_req
|| sci_req
->target_device
!= sci_dev
)
157 s
= scic_controller_terminate_request(scic
, sci_dev
, sci_req
);
158 if (s
!= SCI_SUCCESS
)
165 enum sci_status
scic_remote_device_stop(struct scic_sds_remote_device
*sci_dev
,
168 struct sci_base_state_machine
*sm
= &sci_dev
->state_machine
;
169 enum scic_sds_remote_device_states state
= sm
->current_state_id
;
172 case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
:
173 case SCI_BASE_REMOTE_DEVICE_STATE_FAILED
:
174 case SCI_BASE_REMOTE_DEVICE_STATE_FINAL
:
176 dev_warn(scirdev_to_dev(sci_dev
), "%s: in wrong state: %d\n",
178 return SCI_FAILURE_INVALID_STATE
;
179 case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
:
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.
189 sci_base_state_machine_change_state(sm
, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
);
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
);
205 return scic_sds_remote_device_terminate_requests(sci_dev
);
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.
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
);
219 enum sci_status
scic_remote_device_reset(struct scic_sds_remote_device
*sci_dev
)
221 struct sci_base_state_machine
*sm
= &sci_dev
->state_machine
;
222 enum scic_sds_remote_device_states state
= sm
->current_state_id
;
225 case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
:
226 case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
:
227 case SCI_BASE_REMOTE_DEVICE_STATE_STARTING
:
228 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
:
229 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
:
230 case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
:
231 case SCI_BASE_REMOTE_DEVICE_STATE_FAILED
:
232 case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
:
233 case SCI_BASE_REMOTE_DEVICE_STATE_FINAL
:
235 dev_warn(scirdev_to_dev(sci_dev
), "%s: in wrong state: %d\n",
237 return SCI_FAILURE_INVALID_STATE
;
238 case SCI_BASE_REMOTE_DEVICE_STATE_READY
:
239 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
:
240 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
:
241 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
:
242 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
:
243 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET
:
244 sci_base_state_machine_change_state(sm
, SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
);
249 enum sci_status
scic_remote_device_reset_complete(struct scic_sds_remote_device
*sci_dev
)
251 struct sci_base_state_machine
*sm
= &sci_dev
->state_machine
;
252 enum scic_sds_remote_device_states state
= sm
->current_state_id
;
254 if (state
!= SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
) {
255 dev_warn(scirdev_to_dev(sci_dev
), "%s: in wrong state: %d\n",
257 return SCI_FAILURE_INVALID_STATE
;
260 sci_base_state_machine_change_state(sm
, SCI_BASE_REMOTE_DEVICE_STATE_READY
);
266 * @sci_dev: The remote device for which the suspend is being requested.
268 * This method invokes the remote device suspend state handler. enum sci_status
270 enum sci_status
scic_sds_remote_device_suspend(
271 struct scic_sds_remote_device
*sci_dev
,
274 return sci_dev
->state_handlers
->suspend_handler(sci_dev
, suspend_type
);
279 * @sci_dev: The remote device for which the event handling is being
281 * @frame_index: This is the frame index that is being processed.
283 * This method invokes the frame handler for the remote device state machine
286 enum sci_status
scic_sds_remote_device_frame_handler(
287 struct scic_sds_remote_device
*sci_dev
,
290 return sci_dev
->state_handlers
->frame_handler(sci_dev
, frame_index
);
295 * @sci_dev: The remote device for which the event handling is being
297 * @event_code: This is the event code that is to be processed.
299 * This method invokes the remote device event handler. enum sci_status
301 enum sci_status
scic_sds_remote_device_event_handler(
302 struct scic_sds_remote_device
*sci_dev
,
305 return sci_dev
->state_handlers
->event_handler(sci_dev
, event_code
);
310 * @controller: The controller that is starting the io request.
311 * @sci_dev: The remote device for which the start io handling is being
313 * @io_request: The io request that is being started.
315 * This method invokes the remote device start io handler. enum sci_status
317 enum sci_status
scic_sds_remote_device_start_io(
318 struct scic_sds_controller
*controller
,
319 struct scic_sds_remote_device
*sci_dev
,
320 struct scic_sds_request
*io_request
)
322 return sci_dev
->state_handlers
->start_io_handler(
323 sci_dev
, io_request
);
328 * @controller: The controller that is completing the io request.
329 * @sci_dev: The remote device for which the complete io handling is being
331 * @io_request: The io request that is being completed.
333 * This method invokes the remote device complete io handler. enum sci_status
335 enum sci_status
scic_sds_remote_device_complete_io(
336 struct scic_sds_controller
*controller
,
337 struct scic_sds_remote_device
*sci_dev
,
338 struct scic_sds_request
*io_request
)
340 return sci_dev
->state_handlers
->complete_io_handler(
341 sci_dev
, io_request
);
346 * @controller: The controller that is starting the task request.
347 * @sci_dev: The remote device for which the start task handling is being
349 * @io_request: The task request that is being started.
351 * This method invokes the remote device start task handler. enum sci_status
353 enum sci_status
scic_sds_remote_device_start_task(
354 struct scic_sds_controller
*controller
,
355 struct scic_sds_remote_device
*sci_dev
,
356 struct scic_sds_request
*io_request
)
358 return sci_dev
->state_handlers
->start_task_handler(
359 sci_dev
, io_request
);
367 * This method takes the request and bulids an appropriate SCU context for the
368 * request and then requests the controller to post the request. none
370 void scic_sds_remote_device_post_request(
371 struct scic_sds_remote_device
*sci_dev
,
376 context
= scic_sds_remote_device_build_command_context(sci_dev
, request
);
378 scic_sds_controller_post_request(
379 scic_sds_remote_device_get_controller(sci_dev
),
384 /* called once the remote node context has transisitioned to a
385 * ready state. This is the indication that the remote device object can also
386 * transition to ready.
388 static void remote_device_resume_done(void *_dev
)
390 struct scic_sds_remote_device
*sci_dev
= _dev
;
391 enum scic_sds_remote_device_states state
;
393 state
= sci_dev
->state_machine
.current_state_id
;
395 case SCI_BASE_REMOTE_DEVICE_STATE_READY
:
396 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
:
397 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
:
398 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
:
399 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
:
400 case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET
:
401 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
:
402 case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
:
405 /* go 'ready' if we are not already in a ready state */
406 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
407 SCI_BASE_REMOTE_DEVICE_STATE_READY
);
414 * @device: This parameter specifies the device for which the request is being
416 * @request: This parameter specifies the request being started.
417 * @status: This parameter specifies the current start operation status.
419 * This method will perform the STP request start processing common to IO
420 * requests and task requests of all types. none
422 static void scic_sds_remote_device_start_request(
423 struct scic_sds_remote_device
*sci_dev
,
424 struct scic_sds_request
*sci_req
,
425 enum sci_status status
)
427 /* We still have a fault in starting the io complete it on the port */
428 if (status
== SCI_SUCCESS
)
429 scic_sds_remote_device_increment_request_count(sci_dev
);
431 sci_dev
->owning_port
->state_handlers
->complete_io_handler(
432 sci_dev
->owning_port
, sci_dev
, sci_req
440 * @request: This parameter specifies the request being continued.
442 * This method will continue to post tc for a STP request. This method usually
443 * serves as a callback when RNC gets resumed during a task management
446 static void scic_sds_remote_device_continue_request(void *dev
)
448 struct scic_sds_remote_device
*sci_dev
= dev
;
450 /* we need to check if this request is still valid to continue. */
451 if (sci_dev
->working_request
)
452 scic_controller_continue_io(sci_dev
->working_request
);
455 static enum sci_status
456 default_device_handler(struct scic_sds_remote_device
*sci_dev
,
459 dev_warn(scirdev_to_dev(sci_dev
),
460 "%s: in wrong state: %d\n", func
,
461 sci_base_state_machine_get_state(&sci_dev
->state_machine
));
462 return SCI_FAILURE_INVALID_STATE
;
465 static enum sci_status
scic_sds_remote_device_default_suspend_handler(
466 struct scic_sds_remote_device
*sci_dev
, u32 suspend_type
)
468 return default_device_handler(sci_dev
, __func__
);
471 static enum sci_status
scic_sds_remote_device_default_resume_handler(
472 struct scic_sds_remote_device
*sci_dev
)
474 return default_device_handler(sci_dev
, __func__
);
479 * @device: The struct scic_sds_remote_device which is then cast into a
480 * struct scic_sds_remote_device.
481 * @event_code: The event code that the struct scic_sds_controller wants the device
484 * This method is the default event handler. It will call the RNC state
485 * machine handler for any RNC events otherwise it will log a warning and
486 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
488 static enum sci_status
scic_sds_remote_device_core_event_handler(
489 struct scic_sds_remote_device
*sci_dev
,
493 enum sci_status status
;
495 switch (scu_get_event_type(event_code
)) {
496 case SCU_EVENT_TYPE_RNC_OPS_MISC
:
497 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
498 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
499 status
= scic_sds_remote_node_context_event_handler(&sci_dev
->rnc
, event_code
);
501 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT
:
503 if (scu_get_event_code(event_code
) == SCU_EVENT_IT_NEXUS_TIMEOUT
) {
504 status
= SCI_SUCCESS
;
506 /* Suspend the associated RNC */
507 scic_sds_remote_node_context_suspend(&sci_dev
->rnc
,
508 SCI_SOFTWARE_SUSPENSION
,
511 dev_dbg(scirdev_to_dev(sci_dev
),
512 "%s: device: %p event code: %x: %s\n",
513 __func__
, sci_dev
, event_code
,
515 ? "I_T_Nexus_Timeout event"
516 : "I_T_Nexus_Timeout event in wrong state");
520 /* Else, fall through and treat as unhandled... */
523 dev_dbg(scirdev_to_dev(sci_dev
),
524 "%s: device: %p event code: %x: %s\n",
525 __func__
, sci_dev
, event_code
,
528 : "unexpected event in wrong state");
529 status
= SCI_FAILURE_INVALID_STATE
;
537 * @device: The struct scic_sds_remote_device which is then cast into a
538 * struct scic_sds_remote_device.
539 * @event_code: The event code that the struct scic_sds_controller wants the device
542 * This method is the default event handler. It will call the RNC state
543 * machine handler for any RNC events otherwise it will log a warning and
544 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
546 static enum sci_status
scic_sds_remote_device_default_event_handler(
547 struct scic_sds_remote_device
*sci_dev
,
550 return scic_sds_remote_device_core_event_handler(sci_dev
,
557 * @device: The struct scic_sds_remote_device which is then cast into a
558 * struct scic_sds_remote_device.
559 * @frame_index: The frame index for which the struct scic_sds_controller wants this
560 * device object to process.
562 * This method is the default unsolicited frame handler. It logs a warning,
563 * releases the frame and returns a failure. enum sci_status
564 * SCI_FAILURE_INVALID_STATE
566 static enum sci_status
scic_sds_remote_device_default_frame_handler(
567 struct scic_sds_remote_device
*sci_dev
,
570 dev_warn(scirdev_to_dev(sci_dev
),
571 "%s: SCIC Remote Device requested to handle frame %x "
572 "while in wrong state %d\n",
575 sci_base_state_machine_get_state(
576 &sci_dev
->state_machine
));
578 /* Return the frame back to the controller */
579 scic_sds_controller_release_frame(
580 scic_sds_remote_device_get_controller(sci_dev
), frame_index
583 return SCI_FAILURE_INVALID_STATE
;
586 static enum sci_status
scic_sds_remote_device_default_start_request_handler(
587 struct scic_sds_remote_device
*sci_dev
,
588 struct scic_sds_request
*request
)
590 return default_device_handler(sci_dev
, __func__
);
593 static enum sci_status
scic_sds_remote_device_default_complete_request_handler(
594 struct scic_sds_remote_device
*sci_dev
,
595 struct scic_sds_request
*request
)
597 return default_device_handler(sci_dev
, __func__
);
600 static enum sci_status
scic_sds_remote_device_default_continue_request_handler(
601 struct scic_sds_remote_device
*sci_dev
,
602 struct scic_sds_request
*request
)
604 return default_device_handler(sci_dev
, __func__
);
609 * @device: The struct scic_sds_remote_device which is then cast into a
610 * struct scic_sds_remote_device.
611 * @frame_index: The frame index for which the struct scic_sds_controller wants this
612 * device object to process.
614 * This method is a general ssp frame handler. In most cases the device object
615 * needs to route the unsolicited frame processing to the io request object.
616 * This method decodes the tag for the io request object and routes the
617 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
619 static enum sci_status
scic_sds_remote_device_general_frame_handler(
620 struct scic_sds_remote_device
*sci_dev
,
623 enum sci_status result
;
624 struct sci_ssp_frame_header
*frame_header
;
625 struct scic_sds_request
*io_request
;
627 result
= scic_sds_unsolicited_frame_control_get_header(
628 &(scic_sds_remote_device_get_controller(sci_dev
)->uf_control
),
630 (void **)&frame_header
633 if (SCI_SUCCESS
== result
) {
634 io_request
= scic_sds_controller_get_io_request_from_tag(
635 scic_sds_remote_device_get_controller(sci_dev
), frame_header
->tag
);
637 if ((io_request
== NULL
)
638 || (io_request
->target_device
!= sci_dev
)) {
640 * We could not map this tag to a valid IO request
641 * Just toss the frame and continue */
642 scic_sds_controller_release_frame(
643 scic_sds_remote_device_get_controller(sci_dev
), frame_index
646 /* The IO request is now in charge of releasing the frame */
647 result
= io_request
->state_handlers
->frame_handler(
648 io_request
, frame_index
);
657 * @[in]: sci_dev This is the device object that is receiving the event.
658 * @[in]: event_code The event code to process.
660 * This is a common method for handling events reported to the remote device
661 * from the controller object. enum sci_status
663 static enum sci_status
scic_sds_remote_device_general_event_handler(
664 struct scic_sds_remote_device
*sci_dev
,
667 return scic_sds_remote_device_core_event_handler(sci_dev
,
673 * This method will attempt to start a task request for this device object. The
674 * remote device object will issue the start request for the task and if
675 * successful it will start the request for the port object then increment its
676 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
677 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
678 * object could not get the resources to start.
680 static enum sci_status
scic_sds_remote_device_ready_state_start_task_handler(
681 struct scic_sds_remote_device
*sci_dev
,
682 struct scic_sds_request
*request
)
684 enum sci_status result
;
686 /* See if the port is in a state where we can start the IO request */
687 result
= scic_sds_port_start_io(
688 scic_sds_remote_device_get_port(sci_dev
), sci_dev
, request
);
690 if (result
== SCI_SUCCESS
) {
691 result
= scic_sds_remote_node_context_start_task(&sci_dev
->rnc
,
693 if (result
== SCI_SUCCESS
)
694 result
= scic_sds_request_start(request
);
696 scic_sds_remote_device_start_request(sci_dev
, request
, result
);
703 * This method will attempt to start an io request for this device object. The
704 * remote device object will issue the start request for the io and if
705 * successful it will start the request for the port object then increment its
706 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
707 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
708 * object could not get the resources to start.
710 static enum sci_status
scic_sds_remote_device_ready_state_start_io_handler(
711 struct scic_sds_remote_device
*sci_dev
,
712 struct scic_sds_request
*request
)
714 enum sci_status result
;
716 /* See if the port is in a state where we can start the IO request */
717 result
= scic_sds_port_start_io(
718 scic_sds_remote_device_get_port(sci_dev
), sci_dev
, request
);
720 if (result
== SCI_SUCCESS
) {
721 result
= scic_sds_remote_node_context_start_io(&sci_dev
->rnc
, request
);
722 if (result
== SCI_SUCCESS
)
723 result
= scic_sds_request_start(request
);
725 scic_sds_remote_device_start_request(sci_dev
, request
, result
);
732 * This method will complete the request for the remote device object. The
733 * method will call the completion handler for the request object and if
734 * successful it will complete the request on the port object then decrement
735 * its own started_request_count. enum sci_status
737 static enum sci_status
scic_sds_remote_device_ready_state_complete_request_handler(
738 struct scic_sds_remote_device
*sci_dev
,
739 struct scic_sds_request
*request
)
741 enum sci_status result
;
743 result
= scic_sds_request_complete(request
);
745 if (result
!= SCI_SUCCESS
)
748 /* See if the port is in a state
749 * where we can start the IO request */
750 result
= scic_sds_port_complete_io(
751 scic_sds_remote_device_get_port(sci_dev
),
754 if (result
== SCI_SUCCESS
)
755 scic_sds_remote_device_decrement_request_count(sci_dev
);
762 * @device: The device object for which the request is completing.
763 * @request: The task request that is being completed.
765 * This method completes requests for this struct scic_sds_remote_device while it is
766 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
767 * complete method for the request object and if that is successful the port
768 * object is called to complete the task request. Then the device object itself
769 * completes the task request. If struct scic_sds_remote_device started_request_count
770 * goes to 0 and the invalidate RNC request has completed the device object can
771 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
773 static enum sci_status
scic_sds_remote_device_stopping_state_complete_request_handler(
774 struct scic_sds_remote_device
*sci_dev
,
775 struct scic_sds_request
*request
)
777 enum sci_status status
= SCI_SUCCESS
;
779 status
= scic_sds_request_complete(request
);
781 if (status
!= SCI_SUCCESS
)
784 status
= scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev
),
786 if (status
!= SCI_SUCCESS
)
789 scic_sds_remote_device_decrement_request_count(sci_dev
);
791 if (scic_sds_remote_device_get_request_count(sci_dev
) == 0)
792 scic_sds_remote_node_context_destruct(&sci_dev
->rnc
,
793 rnc_destruct_done
, sci_dev
);
797 /* complete requests for this device while it is in the
798 * SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the complete
799 * method for the request object and if that is successful the port object is
800 * called to complete the task request. Then the device object itself completes
801 * the task request. enum sci_status
803 static enum sci_status
scic_sds_remote_device_resetting_state_complete_request_handler(
804 struct scic_sds_remote_device
*sci_dev
,
805 struct scic_sds_request
*request
)
807 enum sci_status status
= SCI_SUCCESS
;
809 status
= scic_sds_request_complete(request
);
811 if (status
== SCI_SUCCESS
) {
812 status
= scic_sds_port_complete_io(
813 scic_sds_remote_device_get_port(sci_dev
),
816 if (status
== SCI_SUCCESS
) {
817 scic_sds_remote_device_decrement_request_count(sci_dev
);
824 static enum sci_status
scic_sds_stp_remote_device_complete_request(struct scic_sds_remote_device
*sci_dev
,
825 struct scic_sds_request
*sci_req
)
827 enum sci_status status
;
829 status
= scic_sds_io_request_complete(sci_req
);
830 if (status
!= SCI_SUCCESS
)
833 status
= scic_sds_port_complete_io(sci_dev
->owning_port
, sci_dev
, sci_req
);
834 if (status
!= SCI_SUCCESS
)
837 scic_sds_remote_device_decrement_request_count(sci_dev
);
838 if (sci_req
->sci_status
== SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
) {
839 /* This request causes hardware error, device needs to be Lun Reset.
840 * So here we force the state machine to IDLE state so the rest IOs
841 * can reach RNC state handler, these IOs will be completed by RNC with
842 * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE".
844 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
845 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET
);
846 } else if (scic_sds_remote_device_get_request_count(sci_dev
) == 0)
847 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
848 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
852 if (status
!= SCI_SUCCESS
)
853 dev_err(scirdev_to_dev(sci_dev
),
854 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
855 "could not complete\n", __func__
, sci_dev
->owning_port
,
856 sci_dev
, sci_req
, status
);
861 /* scic_sds_stp_remote_device_ready_substate_start_request_handler - start stp
862 * @device: The target device a task management request towards to.
863 * @request: The task request.
865 * This is the READY NCQ substate handler to start task management request. In
866 * this routine, we suspend and resume the RNC. enum sci_status Always return
867 * SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS status to let
868 * controller_start_task_handler know that the controller can't post TC for
869 * task request yet, instead, when RNC gets resumed, a controller_continue_task
870 * callback will be called.
872 static enum sci_status
scic_sds_stp_remote_device_ready_substate_start_request_handler(
873 struct scic_sds_remote_device
*device
,
874 struct scic_sds_request
*request
)
876 enum sci_status status
;
878 /* Will the port allow the io request to start? */
879 status
= device
->owning_port
->state_handlers
->start_io_handler(
880 device
->owning_port
, device
, request
);
881 if (status
!= SCI_SUCCESS
)
884 status
= scic_sds_remote_node_context_start_task(&device
->rnc
, request
);
885 if (status
!= SCI_SUCCESS
)
888 status
= request
->state_handlers
->start_handler(request
);
889 if (status
!= SCI_SUCCESS
)
893 * Note: If the remote device state is not IDLE this will replace
894 * the request that probably resulted in the task management request.
896 device
->working_request
= request
;
897 sci_base_state_machine_change_state(&device
->state_machine
,
898 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
);
901 * The remote node context must cleanup the TCi to NCQ mapping table.
902 * The only way to do this correctly is to either write to the TLCR
903 * register or to invalidate and repost the RNC. In either case the
904 * remote node context state machine will take the correct action when
905 * the remote node context is suspended and later resumed.
907 scic_sds_remote_node_context_suspend(&device
->rnc
,
908 SCI_SOFTWARE_SUSPENSION
, NULL
, NULL
);
909 scic_sds_remote_node_context_resume(&device
->rnc
,
910 scic_sds_remote_device_continue_request
,
914 scic_sds_remote_device_start_request(device
, request
, status
);
916 * We need to let the controller start request handler know that it can't
917 * post TC yet. We will provide a callback function to post TC when RNC gets
920 return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
;
923 /* handle the start io operation for a sata device that is in the command idle
924 * state. - Evalute the type of IO request to be started - If its an NCQ
925 * request change to NCQ substate - If its any other command change to the CMD
928 * If this is a softreset we may want to have a different substate.
930 static enum sci_status
scic_sds_stp_remote_device_ready_idle_substate_start_io_handler(
931 struct scic_sds_remote_device
*sci_dev
,
932 struct scic_sds_request
*request
)
934 enum sci_status status
;
935 struct isci_request
*isci_request
= request
->ireq
;
936 enum scic_sds_remote_device_states new_state
;
938 /* Will the port allow the io request to start? */
939 status
= sci_dev
->owning_port
->state_handlers
->start_io_handler(
940 sci_dev
->owning_port
, sci_dev
, request
);
941 if (status
!= SCI_SUCCESS
)
944 status
= scic_sds_remote_node_context_start_io(&sci_dev
->rnc
, request
);
945 if (status
!= SCI_SUCCESS
)
948 status
= request
->state_handlers
->start_handler(request
);
949 if (status
!= SCI_SUCCESS
)
952 if (isci_sata_get_sat_protocol(isci_request
) == SAT_PROTOCOL_FPDMA
)
953 new_state
= SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
;
955 sci_dev
->working_request
= request
;
956 new_state
= SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
;
958 sci_base_state_machine_change_state(&sci_dev
->state_machine
, new_state
);
960 scic_sds_remote_device_start_request(sci_dev
, request
, status
);
965 static enum sci_status
scic_sds_stp_remote_device_ready_idle_substate_event_handler(
966 struct scic_sds_remote_device
*sci_dev
,
969 enum sci_status status
;
971 status
= scic_sds_remote_device_general_event_handler(sci_dev
, event_code
);
972 if (status
!= SCI_SUCCESS
)
975 /* We pick up suspension events to handle specifically to this state. We
976 * resume the RNC right away. enum sci_status
978 if (scu_get_event_type(event_code
) == SCU_EVENT_TYPE_RNC_SUSPEND_TX
||
979 scu_get_event_type(event_code
) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
)
980 status
= scic_sds_remote_node_context_resume(&sci_dev
->rnc
, NULL
, NULL
);
985 static enum sci_status
scic_sds_stp_remote_device_ready_ncq_substate_start_io_handler(
986 struct scic_sds_remote_device
*sci_dev
,
987 struct scic_sds_request
*request
)
989 enum sci_status status
;
990 struct isci_request
*isci_request
= request
->ireq
;
991 scic_sds_port_io_request_handler_t start_io
;
993 if (isci_sata_get_sat_protocol(isci_request
) == SAT_PROTOCOL_FPDMA
) {
994 start_io
= sci_dev
->owning_port
->state_handlers
->start_io_handler
;
995 status
= start_io(sci_dev
->owning_port
, sci_dev
, request
);
996 if (status
!= SCI_SUCCESS
)
999 status
= scic_sds_remote_node_context_start_io(&sci_dev
->rnc
, request
);
1000 if (status
== SCI_SUCCESS
)
1001 status
= request
->state_handlers
->start_handler(request
);
1003 scic_sds_remote_device_start_request(sci_dev
, request
, status
);
1005 status
= SCI_FAILURE_INVALID_STATE
;
1010 static enum sci_status
scic_sds_stp_remote_device_ready_ncq_substate_frame_handler(struct scic_sds_remote_device
*sci_dev
,
1013 enum sci_status status
;
1014 struct sata_fis_header
*frame_header
;
1015 struct scic_sds_controller
*scic
= sci_dev
->owning_port
->owning_controller
;
1017 status
= scic_sds_unsolicited_frame_control_get_header(&scic
->uf_control
,
1019 (void **)&frame_header
);
1020 if (status
!= SCI_SUCCESS
)
1023 if (frame_header
->fis_type
== SATA_FIS_TYPE_SETDEVBITS
&&
1024 (frame_header
->status
& ATA_STATUS_REG_ERROR_BIT
)) {
1025 sci_dev
->not_ready_reason
= SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED
;
1027 /* TODO Check sactive and complete associated IO if any. */
1029 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1030 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
);
1031 } else if (frame_header
->fis_type
== SATA_FIS_TYPE_REGD2H
&&
1032 (frame_header
->status
& ATA_STATUS_REG_ERROR_BIT
)) {
1034 * Some devices return D2H FIS when an NCQ error is detected.
1035 * Treat this like an SDB error FIS ready reason.
1037 sci_dev
->not_ready_reason
= SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED
;
1039 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1040 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
);
1042 status
= SCI_FAILURE
;
1044 scic_sds_controller_release_frame(scic
, frame_index
);
1049 static enum sci_status
scic_sds_stp_remote_device_ready_cmd_substate_start_io_handler(
1050 struct scic_sds_remote_device
*device
,
1051 struct scic_sds_request
*request
)
1053 /* device is already handling a command it can not accept new commands
1054 * until this one is complete.
1056 return SCI_FAILURE_INVALID_STATE
;
1059 static enum sci_status
scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler(
1060 struct scic_sds_remote_device
*sci_dev
,
1063 enum sci_status status
;
1065 status
= scic_sds_remote_node_context_suspend(&sci_dev
->rnc
,
1066 suspend_type
, NULL
, NULL
);
1071 static enum sci_status
scic_sds_stp_remote_device_ready_cmd_substate_frame_handler(
1072 struct scic_sds_remote_device
*sci_dev
,
1075 /* The device doe not process any UF received from the hardware while
1076 * in this state. All unsolicited frames are forwarded to the io
1079 return scic_sds_io_request_frame_handler(sci_dev
->working_request
,
1083 static enum sci_status
scic_sds_stp_remote_device_ready_await_reset_substate_start_io_handler(
1084 struct scic_sds_remote_device
*device
,
1085 struct scic_sds_request
*request
)
1087 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
;
1090 static enum sci_status
scic_sds_stp_remote_device_ready_await_reset_substate_complete_request_handler(
1091 struct scic_sds_remote_device
*device
,
1092 struct scic_sds_request
*request
)
1094 struct scic_sds_request
*sci_req
= request
;
1095 enum sci_status status
;
1097 status
= scic_sds_io_request_complete(sci_req
);
1098 if (status
!= SCI_SUCCESS
)
1101 status
= scic_sds_port_complete_io(device
->owning_port
, device
, sci_req
);
1102 if (status
!= SCI_SUCCESS
)
1105 scic_sds_remote_device_decrement_request_count(device
);
1107 if (status
!= SCI_SUCCESS
)
1108 dev_err(scirdev_to_dev(device
),
1109 "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x "
1110 "could not complete\n",
1111 __func__
, device
->owning_port
, device
, sci_req
, status
);
1116 static void scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev
)
1118 struct scic_sds_remote_device
*sci_dev
= _dev
;
1119 struct isci_remote_device
*idev
= sci_dev_to_idev(sci_dev
);
1120 struct scic_sds_controller
*scic
= sci_dev
->owning_port
->owning_controller
;
1122 /* For NCQ operation we do not issue a isci_remote_device_not_ready().
1123 * As a result, avoid sending the ready notification.
1125 if (sci_dev
->state_machine
.previous_state_id
!= SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
)
1126 isci_remote_device_ready(scic
->ihost
, idev
);
1129 static enum sci_status
scic_sds_smp_remote_device_ready_idle_substate_start_io_handler(
1130 struct scic_sds_remote_device
*sci_dev
,
1131 struct scic_sds_request
*sci_req
)
1133 enum sci_status status
;
1135 /* Will the port allow the io request to start? */
1136 status
= sci_dev
->owning_port
->state_handlers
->start_io_handler(
1137 sci_dev
->owning_port
, sci_dev
, sci_req
);
1138 if (status
!= SCI_SUCCESS
)
1141 status
= scic_sds_remote_node_context_start_io(&sci_dev
->rnc
, sci_req
);
1142 if (status
!= SCI_SUCCESS
)
1145 status
= scic_sds_request_start(sci_req
);
1146 if (status
!= SCI_SUCCESS
)
1149 sci_dev
->working_request
= sci_req
;
1150 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1151 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
);
1154 scic_sds_remote_device_start_request(sci_dev
, sci_req
, status
);
1159 static enum sci_status
scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler(
1160 struct scic_sds_remote_device
*device
,
1161 struct scic_sds_request
*request
)
1163 /* device is already handling a command it can not accept new commands
1164 * until this one is complete.
1166 return SCI_FAILURE_INVALID_STATE
;
1169 static enum sci_status
1170 scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler(struct scic_sds_remote_device
*sci_dev
,
1171 struct scic_sds_request
*sci_req
)
1173 enum sci_status status
;
1175 status
= scic_sds_io_request_complete(sci_req
);
1176 if (status
!= SCI_SUCCESS
)
1179 status
= scic_sds_port_complete_io(sci_dev
->owning_port
, sci_dev
, sci_req
);
1180 if (status
!= SCI_SUCCESS
) {
1181 dev_err(scirdev_to_dev(sci_dev
),
1182 "%s: SCIC SDS Remote Device 0x%p io request "
1183 "0x%p could not be completd on the port 0x%p "
1184 "failed with status %d.\n", __func__
, sci_dev
, sci_req
,
1185 sci_dev
->owning_port
, status
);
1189 scic_sds_remote_device_decrement_request_count(sci_dev
);
1190 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1191 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1196 static enum sci_status
scic_sds_smp_remote_device_ready_cmd_substate_frame_handler(
1197 struct scic_sds_remote_device
*sci_dev
,
1200 enum sci_status status
;
1202 /* The device does not process any UF received from the hardware while
1203 * in this state. All unsolicited frames are forwarded to the io request
1206 status
= scic_sds_io_request_frame_handler(
1207 sci_dev
->working_request
,
1214 static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table
[] = {
1215 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
] = {
1216 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1217 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1218 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1219 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1220 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1221 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1222 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1223 .event_handler
= scic_sds_remote_device_default_event_handler
,
1224 .frame_handler
= scic_sds_remote_device_default_frame_handler
1226 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
] = {
1227 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1228 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1229 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1230 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1231 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1232 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1233 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1234 .event_handler
= scic_sds_remote_device_default_event_handler
,
1235 .frame_handler
= scic_sds_remote_device_default_frame_handler
1237 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING
] = {
1238 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1239 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1240 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1241 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1242 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1243 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1244 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1245 .event_handler
= scic_sds_remote_device_general_event_handler
,
1246 .frame_handler
= scic_sds_remote_device_default_frame_handler
1248 [SCI_BASE_REMOTE_DEVICE_STATE_READY
] = {
1249 .start_io_handler
= scic_sds_remote_device_ready_state_start_io_handler
,
1250 .complete_io_handler
= scic_sds_remote_device_ready_state_complete_request_handler
,
1251 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1252 .start_task_handler
= scic_sds_remote_device_ready_state_start_task_handler
,
1253 .complete_task_handler
= scic_sds_remote_device_ready_state_complete_request_handler
,
1254 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1255 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1256 .event_handler
= scic_sds_remote_device_general_event_handler
,
1257 .frame_handler
= scic_sds_remote_device_general_frame_handler
,
1259 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
] = {
1260 .start_io_handler
= scic_sds_stp_remote_device_ready_idle_substate_start_io_handler
,
1261 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1262 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1263 .start_task_handler
= scic_sds_stp_remote_device_ready_substate_start_request_handler
,
1264 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1265 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1266 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1267 .event_handler
= scic_sds_stp_remote_device_ready_idle_substate_event_handler
,
1268 .frame_handler
= scic_sds_remote_device_default_frame_handler
1270 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
] = {
1271 .start_io_handler
= scic_sds_stp_remote_device_ready_cmd_substate_start_io_handler
,
1272 .complete_io_handler
= scic_sds_stp_remote_device_complete_request
,
1273 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1274 .start_task_handler
= scic_sds_stp_remote_device_ready_substate_start_request_handler
,
1275 .complete_task_handler
= scic_sds_stp_remote_device_complete_request
,
1276 .suspend_handler
= scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler
,
1277 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1278 .event_handler
= scic_sds_remote_device_general_event_handler
,
1279 .frame_handler
= scic_sds_stp_remote_device_ready_cmd_substate_frame_handler
1281 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
] = {
1282 .start_io_handler
= scic_sds_stp_remote_device_ready_ncq_substate_start_io_handler
,
1283 .complete_io_handler
= scic_sds_stp_remote_device_complete_request
,
1284 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1285 .start_task_handler
= scic_sds_stp_remote_device_ready_substate_start_request_handler
,
1286 .complete_task_handler
= scic_sds_stp_remote_device_complete_request
,
1287 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1288 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1289 .event_handler
= scic_sds_remote_device_general_event_handler
,
1290 .frame_handler
= scic_sds_stp_remote_device_ready_ncq_substate_frame_handler
1292 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
] = {
1293 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1294 .complete_io_handler
= scic_sds_stp_remote_device_complete_request
,
1295 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1296 .start_task_handler
= scic_sds_stp_remote_device_ready_substate_start_request_handler
,
1297 .complete_task_handler
= scic_sds_stp_remote_device_complete_request
,
1298 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1299 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1300 .event_handler
= scic_sds_remote_device_general_event_handler
,
1301 .frame_handler
= scic_sds_remote_device_general_frame_handler
1303 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET
] = {
1304 .start_io_handler
= scic_sds_stp_remote_device_ready_await_reset_substate_start_io_handler
,
1305 .complete_io_handler
= scic_sds_stp_remote_device_ready_await_reset_substate_complete_request_handler
,
1306 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1307 .start_task_handler
= scic_sds_stp_remote_device_ready_substate_start_request_handler
,
1308 .complete_task_handler
= scic_sds_stp_remote_device_complete_request
,
1309 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1310 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1311 .event_handler
= scic_sds_remote_device_general_event_handler
,
1312 .frame_handler
= scic_sds_remote_device_general_frame_handler
1314 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
] = {
1315 .start_io_handler
= scic_sds_smp_remote_device_ready_idle_substate_start_io_handler
,
1316 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1317 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1318 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1319 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1320 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1321 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1322 .event_handler
= scic_sds_remote_device_general_event_handler
,
1323 .frame_handler
= scic_sds_remote_device_default_frame_handler
1325 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
] = {
1326 .start_io_handler
= scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler
,
1327 .complete_io_handler
= scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler
,
1328 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1329 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1330 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1331 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1332 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1333 .event_handler
= scic_sds_remote_device_general_event_handler
,
1334 .frame_handler
= scic_sds_smp_remote_device_ready_cmd_substate_frame_handler
1336 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
] = {
1337 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1338 .complete_io_handler
= scic_sds_remote_device_stopping_state_complete_request_handler
,
1339 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1340 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1341 .complete_task_handler
= scic_sds_remote_device_stopping_state_complete_request_handler
,
1342 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1343 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1344 .event_handler
= scic_sds_remote_device_general_event_handler
,
1345 .frame_handler
= scic_sds_remote_device_general_frame_handler
1347 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED
] = {
1348 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1349 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1350 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1351 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1352 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1353 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1354 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1355 .event_handler
= scic_sds_remote_device_default_event_handler
,
1356 .frame_handler
= scic_sds_remote_device_general_frame_handler
1358 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
] = {
1359 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1360 .complete_io_handler
= scic_sds_remote_device_resetting_state_complete_request_handler
,
1361 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1362 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1363 .complete_task_handler
= scic_sds_remote_device_resetting_state_complete_request_handler
,
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_default_event_handler
,
1367 .frame_handler
= scic_sds_remote_device_general_frame_handler
1369 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL
] = {
1370 .start_io_handler
= scic_sds_remote_device_default_start_request_handler
,
1371 .complete_io_handler
= scic_sds_remote_device_default_complete_request_handler
,
1372 .continue_io_handler
= scic_sds_remote_device_default_continue_request_handler
,
1373 .start_task_handler
= scic_sds_remote_device_default_start_request_handler
,
1374 .complete_task_handler
= scic_sds_remote_device_default_complete_request_handler
,
1375 .suspend_handler
= scic_sds_remote_device_default_suspend_handler
,
1376 .resume_handler
= scic_sds_remote_device_default_resume_handler
,
1377 .event_handler
= scic_sds_remote_device_default_event_handler
,
1378 .frame_handler
= scic_sds_remote_device_default_frame_handler
1382 static void scic_sds_remote_device_initial_state_enter(void *object
)
1384 struct scic_sds_remote_device
*sci_dev
= object
;
1386 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1387 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
);
1389 /* Initial state is a transitional state to the stopped state */
1390 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1391 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
);
1395 * scic_remote_device_destruct() - free remote node context and destruct
1396 * @remote_device: This parameter specifies the remote device to be destructed.
1398 * Remote device objects are a limited resource. As such, they must be
1399 * protected. Thus calls to construct and destruct are mutually exclusive and
1400 * non-reentrant. The return value shall indicate if the device was
1401 * successfully destructed or if some failure occurred. enum sci_status This value
1402 * is returned if the device is successfully destructed.
1403 * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied
1404 * device isn't valid (e.g. it's already been destoryed, the handle isn't
1407 static enum sci_status
scic_remote_device_destruct(struct scic_sds_remote_device
*sci_dev
)
1409 struct sci_base_state_machine
*sm
= &sci_dev
->state_machine
;
1410 enum scic_sds_remote_device_states state
= sm
->current_state_id
;
1411 struct scic_sds_controller
*scic
;
1413 if (state
!= SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
) {
1414 dev_warn(scirdev_to_dev(sci_dev
), "%s: in wrong state: %d\n",
1416 return SCI_FAILURE_INVALID_STATE
;
1419 scic
= sci_dev
->owning_port
->owning_controller
;
1420 scic_sds_controller_free_remote_node_context(scic
, sci_dev
,
1421 sci_dev
->rnc
.remote_node_index
);
1422 sci_dev
->rnc
.remote_node_index
= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
;
1423 sci_base_state_machine_change_state(sm
, SCI_BASE_REMOTE_DEVICE_STATE_FINAL
);
1429 * isci_remote_device_deconstruct() - This function frees an isci_remote_device.
1430 * @ihost: This parameter specifies the isci host object.
1431 * @idev: This parameter specifies the remote device to be freed.
1434 static void isci_remote_device_deconstruct(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
1436 dev_dbg(&ihost
->pdev
->dev
,
1437 "%s: isci_device = %p\n", __func__
, idev
);
1439 /* There should not be any outstanding io's. All paths to
1440 * here should go through isci_remote_device_nuke_requests.
1441 * If we hit this condition, we will need a way to complete
1442 * io requests in process */
1443 while (!list_empty(&idev
->reqs_in_process
)) {
1445 dev_err(&ihost
->pdev
->dev
,
1446 "%s: ** request list not empty! **\n", __func__
);
1450 scic_remote_device_destruct(&idev
->sci
);
1451 idev
->domain_dev
->lldd_dev
= NULL
;
1452 idev
->domain_dev
= NULL
;
1453 idev
->isci_port
= NULL
;
1454 list_del_init(&idev
->node
);
1456 clear_bit(IDEV_START_PENDING
, &idev
->flags
);
1457 clear_bit(IDEV_STOP_PENDING
, &idev
->flags
);
1458 wake_up(&ihost
->eventq
);
1462 * isci_remote_device_stop_complete() - This function is called by the scic
1463 * when the remote device stop has completed. We mark the isci device as not
1464 * ready and remove the isci remote device.
1465 * @ihost: This parameter specifies the isci host object.
1466 * @idev: This parameter specifies the remote device.
1467 * @status: This parameter specifies status of the completion.
1470 static void isci_remote_device_stop_complete(struct isci_host
*ihost
,
1471 struct isci_remote_device
*idev
)
1473 dev_dbg(&ihost
->pdev
->dev
, "%s: complete idev = %p\n", __func__
, idev
);
1475 isci_remote_device_change_state(idev
, isci_stopped
);
1477 /* after stop, we can tear down resources. */
1478 isci_remote_device_deconstruct(ihost
, idev
);
1481 static void scic_sds_remote_device_stopped_state_enter(void *object
)
1483 struct scic_sds_remote_device
*sci_dev
= object
;
1484 struct scic_sds_controller
*scic
;
1485 struct isci_remote_device
*idev
;
1486 struct isci_host
*ihost
;
1489 scic
= scic_sds_remote_device_get_controller(sci_dev
);
1490 ihost
= scic
->ihost
;
1491 idev
= sci_dev_to_idev(sci_dev
);
1493 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1494 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
);
1496 /* If we are entering from the stopping state let the SCI User know that
1497 * the stop operation has completed.
1499 prev_state
= sci_dev
->state_machine
.previous_state_id
;
1500 if (prev_state
== SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
)
1501 isci_remote_device_stop_complete(ihost
, idev
);
1503 scic_sds_controller_remote_device_stopped(scic
, sci_dev
);
1506 static void scic_sds_remote_device_starting_state_enter(void *object
)
1508 struct scic_sds_remote_device
*sci_dev
= object
;
1509 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1510 struct isci_host
*ihost
= scic
->ihost
;
1511 struct isci_remote_device
*idev
= sci_dev_to_idev(sci_dev
);
1513 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1514 SCI_BASE_REMOTE_DEVICE_STATE_STARTING
);
1516 isci_remote_device_not_ready(ihost
, idev
,
1517 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED
);
1520 static void scic_sds_remote_device_ready_state_enter(void *object
)
1522 struct scic_sds_remote_device
*sci_dev
= object
;
1523 struct scic_sds_controller
*scic
= sci_dev
->owning_port
->owning_controller
;
1524 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1526 SET_STATE_HANDLER(sci_dev
,
1527 scic_sds_remote_device_state_handler_table
,
1528 SCI_BASE_REMOTE_DEVICE_STATE_READY
);
1530 scic
->remote_device_sequence
[sci_dev
->rnc
.remote_node_index
]++;
1532 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_SATA
)) {
1533 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1534 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1535 } else if (dev_is_expander(dev
)) {
1536 sci_base_state_machine_change_state(&sci_dev
->state_machine
,
1537 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1539 isci_remote_device_ready(scic
->ihost
, sci_dev_to_idev(sci_dev
));
1542 static void scic_sds_remote_device_ready_state_exit(void *object
)
1544 struct scic_sds_remote_device
*sci_dev
= object
;
1545 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1547 if (dev
->dev_type
== SAS_END_DEV
) {
1548 struct scic_sds_controller
*scic
= sci_dev
->owning_port
->owning_controller
;
1549 struct isci_remote_device
*idev
= sci_dev_to_idev(sci_dev
);
1551 isci_remote_device_not_ready(scic
->ihost
, idev
,
1552 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED
);
1556 static void scic_sds_remote_device_stopping_state_enter(void *object
)
1558 struct scic_sds_remote_device
*sci_dev
= object
;
1562 scic_sds_remote_device_state_handler_table
,
1563 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1567 static void scic_sds_remote_device_failed_state_enter(void *object
)
1569 struct scic_sds_remote_device
*sci_dev
= object
;
1573 scic_sds_remote_device_state_handler_table
,
1574 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1578 static void scic_sds_remote_device_resetting_state_enter(void *object
)
1580 struct scic_sds_remote_device
*sci_dev
= object
;
1584 scic_sds_remote_device_state_handler_table
,
1585 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1588 scic_sds_remote_node_context_suspend(
1589 &sci_dev
->rnc
, SCI_SOFTWARE_SUSPENSION
, NULL
, NULL
);
1592 static void scic_sds_remote_device_resetting_state_exit(void *object
)
1594 struct scic_sds_remote_device
*sci_dev
= object
;
1596 scic_sds_remote_node_context_resume(&sci_dev
->rnc
, NULL
, NULL
);
1599 static void scic_sds_remote_device_final_state_enter(void *object
)
1601 struct scic_sds_remote_device
*sci_dev
= object
;
1605 scic_sds_remote_device_state_handler_table
,
1606 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1610 static void scic_sds_stp_remote_device_ready_idle_substate_enter(void *object
)
1612 struct scic_sds_remote_device
*sci_dev
= object
;
1614 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1615 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1617 sci_dev
->working_request
= NULL
;
1618 if (scic_sds_remote_node_context_is_ready(&sci_dev
->rnc
)) {
1620 * Since the RNC is ready, it's alright to finish completion
1621 * processing (e.g. signal the remote device is ready). */
1622 scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(sci_dev
);
1624 scic_sds_remote_node_context_resume(&sci_dev
->rnc
,
1625 scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler
,
1630 static void scic_sds_stp_remote_device_ready_cmd_substate_enter(void *object
)
1632 struct scic_sds_remote_device
*sci_dev
= object
;
1633 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1635 BUG_ON(sci_dev
->working_request
== NULL
);
1637 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1638 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
);
1640 isci_remote_device_not_ready(scic
->ihost
, sci_dev_to_idev(sci_dev
),
1641 SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED
);
1644 static void scic_sds_stp_remote_device_ready_ncq_substate_enter(void *object
)
1646 struct scic_sds_remote_device
*sci_dev
= object
;
1648 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1649 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
);
1652 static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(void *object
)
1654 struct scic_sds_remote_device
*sci_dev
= object
;
1655 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1656 struct isci_remote_device
*idev
= sci_dev_to_idev(sci_dev
);
1658 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1659 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
);
1661 if (sci_dev
->not_ready_reason
== SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED
)
1662 isci_remote_device_not_ready(scic
->ihost
, idev
,
1663 sci_dev
->not_ready_reason
);
1666 static void scic_sds_stp_remote_device_ready_await_reset_substate_enter(void *object
)
1668 struct scic_sds_remote_device
*sci_dev
= object
;
1670 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1671 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET
);
1674 static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object
)
1676 struct scic_sds_remote_device
*sci_dev
= object
;
1677 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1679 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1680 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
);
1682 isci_remote_device_ready(scic
->ihost
, sci_dev_to_idev(sci_dev
));
1685 static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object
)
1687 struct scic_sds_remote_device
*sci_dev
= object
;
1688 struct scic_sds_controller
*scic
= scic_sds_remote_device_get_controller(sci_dev
);
1690 BUG_ON(sci_dev
->working_request
== NULL
);
1692 SET_STATE_HANDLER(sci_dev
, scic_sds_remote_device_state_handler_table
,
1693 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
);
1695 isci_remote_device_not_ready(scic
->ihost
, sci_dev_to_idev(sci_dev
),
1696 SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED
);
1699 static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object
)
1701 struct scic_sds_remote_device
*sci_dev
= object
;
1703 sci_dev
->working_request
= NULL
;
1706 static const struct sci_base_state scic_sds_remote_device_state_table
[] = {
1707 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
] = {
1708 .enter_state
= scic_sds_remote_device_initial_state_enter
,
1710 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
] = {
1711 .enter_state
= scic_sds_remote_device_stopped_state_enter
,
1713 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING
] = {
1714 .enter_state
= scic_sds_remote_device_starting_state_enter
,
1716 [SCI_BASE_REMOTE_DEVICE_STATE_READY
] = {
1717 .enter_state
= scic_sds_remote_device_ready_state_enter
,
1718 .exit_state
= scic_sds_remote_device_ready_state_exit
1720 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
] = {
1721 .enter_state
= scic_sds_stp_remote_device_ready_idle_substate_enter
,
1723 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD
] = {
1724 .enter_state
= scic_sds_stp_remote_device_ready_cmd_substate_enter
,
1726 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
] = {
1727 .enter_state
= scic_sds_stp_remote_device_ready_ncq_substate_enter
,
1729 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR
] = {
1730 .enter_state
= scic_sds_stp_remote_device_ready_ncq_error_substate_enter
,
1732 [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET
] = {
1733 .enter_state
= scic_sds_stp_remote_device_ready_await_reset_substate_enter
,
1735 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
] = {
1736 .enter_state
= scic_sds_smp_remote_device_ready_idle_substate_enter
,
1738 [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
] = {
1739 .enter_state
= scic_sds_smp_remote_device_ready_cmd_substate_enter
,
1740 .exit_state
= scic_sds_smp_remote_device_ready_cmd_substate_exit
,
1742 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
] = {
1743 .enter_state
= scic_sds_remote_device_stopping_state_enter
,
1745 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED
] = {
1746 .enter_state
= scic_sds_remote_device_failed_state_enter
,
1748 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
] = {
1749 .enter_state
= scic_sds_remote_device_resetting_state_enter
,
1750 .exit_state
= scic_sds_remote_device_resetting_state_exit
1752 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL
] = {
1753 .enter_state
= scic_sds_remote_device_final_state_enter
,
1758 * scic_remote_device_construct() - common construction
1759 * @sci_port: SAS/SATA port through which this device is accessed.
1760 * @sci_dev: remote device to construct
1762 * This routine just performs benign initialization and does not
1763 * allocate the remote_node_context which is left to
1764 * scic_remote_device_[de]a_construct(). scic_remote_device_destruct()
1765 * frees the remote_node_context(s) for the device.
1767 static void scic_remote_device_construct(struct scic_sds_port
*sci_port
,
1768 struct scic_sds_remote_device
*sci_dev
)
1770 sci_dev
->owning_port
= sci_port
;
1771 sci_dev
->started_request_count
= 0;
1773 sci_base_state_machine_construct(
1774 &sci_dev
->state_machine
,
1776 scic_sds_remote_device_state_table
,
1777 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1780 sci_base_state_machine_start(
1781 &sci_dev
->state_machine
1784 scic_sds_remote_node_context_construct(&sci_dev
->rnc
,
1785 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
);
1789 * scic_remote_device_da_construct() - construct direct attached device.
1791 * The information (e.g. IAF, Signature FIS, etc.) necessary to build
1792 * the device is known to the SCI Core since it is contained in the
1793 * scic_phy object. Remote node context(s) is/are a global resource
1794 * allocated by this routine, freed by scic_remote_device_destruct().
1797 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
1798 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
1799 * sata-only controller instance.
1800 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
1802 static enum sci_status
scic_remote_device_da_construct(struct scic_sds_port
*sci_port
,
1803 struct scic_sds_remote_device
*sci_dev
)
1805 enum sci_status status
;
1806 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1808 scic_remote_device_construct(sci_port
, sci_dev
);
1811 * This information is request to determine how many remote node context
1812 * entries will be needed to store the remote node.
1814 sci_dev
->is_direct_attached
= true;
1815 status
= scic_sds_controller_allocate_remote_node_context(sci_port
->owning_controller
,
1817 &sci_dev
->rnc
.remote_node_index
);
1819 if (status
!= SCI_SUCCESS
)
1822 if (dev
->dev_type
== SAS_END_DEV
|| dev
->dev_type
== SATA_DEV
||
1823 (dev
->tproto
& SAS_PROTOCOL_STP
) || dev_is_expander(dev
))
1826 return SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1828 sci_dev
->connection_rate
= scic_sds_port_get_max_allowed_speed(sci_port
);
1830 /* / @todo Should I assign the port width by reading all of the phys on the port? */
1831 sci_dev
->device_port_width
= 1;
1837 * scic_remote_device_ea_construct() - construct expander attached device
1839 * Remote node context(s) is/are a global resource allocated by this
1840 * routine, freed by scic_remote_device_destruct().
1843 * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed.
1844 * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to
1845 * sata-only controller instance.
1846 * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted.
1848 static enum sci_status
scic_remote_device_ea_construct(struct scic_sds_port
*sci_port
,
1849 struct scic_sds_remote_device
*sci_dev
)
1851 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1852 enum sci_status status
;
1854 scic_remote_device_construct(sci_port
, sci_dev
);
1856 status
= scic_sds_controller_allocate_remote_node_context(sci_port
->owning_controller
,
1858 &sci_dev
->rnc
.remote_node_index
);
1859 if (status
!= SCI_SUCCESS
)
1862 if (dev
->dev_type
== SAS_END_DEV
|| dev
->dev_type
== SATA_DEV
||
1863 (dev
->tproto
& SAS_PROTOCOL_STP
) || dev_is_expander(dev
))
1866 return SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1869 * For SAS-2 the physical link rate is actually a logical link
1870 * rate that incorporates multiplexing. The SCU doesn't
1871 * incorporate multiplexing and for the purposes of the
1872 * connection the logical link rate is that same as the
1873 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
1874 * one another, so this code works for both situations. */
1875 sci_dev
->connection_rate
= min_t(u16
, scic_sds_port_get_max_allowed_speed(sci_port
),
1878 /* / @todo Should I assign the port width by reading all of the phys on the port? */
1879 sci_dev
->device_port_width
= 1;
1885 * scic_remote_device_start() - This method will start the supplied remote
1886 * device. This method enables normal IO requests to flow through to the
1888 * @remote_device: This parameter specifies the device to be started.
1889 * @timeout: This parameter specifies the number of milliseconds in which the
1890 * start operation should complete.
1892 * An indication of whether the device was successfully started. SCI_SUCCESS
1893 * This value is returned if the device was successfully started.
1894 * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start
1895 * the device when there have been no phys added to it.
1897 static enum sci_status
scic_remote_device_start(struct scic_sds_remote_device
*sci_dev
,
1900 struct sci_base_state_machine
*sm
= &sci_dev
->state_machine
;
1901 enum scic_sds_remote_device_states state
= sm
->current_state_id
;
1902 enum sci_status status
;
1904 if (state
!= SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
) {
1905 dev_warn(scirdev_to_dev(sci_dev
), "%s: in wrong state: %d\n",
1907 return SCI_FAILURE_INVALID_STATE
;
1910 status
= scic_sds_remote_node_context_resume(&sci_dev
->rnc
,
1911 remote_device_resume_done
,
1913 if (status
!= SCI_SUCCESS
)
1916 sci_base_state_machine_change_state(sm
, SCI_BASE_REMOTE_DEVICE_STATE_STARTING
);
1921 static enum sci_status
isci_remote_device_construct(struct isci_port
*iport
,
1922 struct isci_remote_device
*idev
)
1924 struct scic_sds_port
*sci_port
= iport
->sci_port_handle
;
1925 struct isci_host
*ihost
= iport
->isci_host
;
1926 struct domain_device
*dev
= idev
->domain_dev
;
1927 enum sci_status status
;
1929 if (dev
->parent
&& dev_is_expander(dev
->parent
))
1930 status
= scic_remote_device_ea_construct(sci_port
, &idev
->sci
);
1932 status
= scic_remote_device_da_construct(sci_port
, &idev
->sci
);
1934 if (status
!= SCI_SUCCESS
) {
1935 dev_dbg(&ihost
->pdev
->dev
, "%s: construct failed: %d\n",
1941 /* start the device. */
1942 status
= scic_remote_device_start(&idev
->sci
, ISCI_REMOTE_DEVICE_START_TIMEOUT
);
1944 if (status
!= SCI_SUCCESS
)
1945 dev_warn(&ihost
->pdev
->dev
, "remote device start failed: %d\n",
1951 void isci_remote_device_nuke_requests(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
1953 DECLARE_COMPLETION_ONSTACK(aborted_task_completion
);
1955 dev_dbg(&ihost
->pdev
->dev
,
1956 "%s: idev = %p\n", __func__
, idev
);
1958 /* Cleanup all requests pending for this device. */
1959 isci_terminate_pending_requests(ihost
, idev
, terminating
);
1961 dev_dbg(&ihost
->pdev
->dev
,
1962 "%s: idev = %p, done\n", __func__
, idev
);
1966 * This function builds the isci_remote_device when a libsas dev_found message
1968 * @isci_host: This parameter specifies the isci host object.
1969 * @port: This parameter specifies the isci_port conected to this device.
1971 * pointer to new isci_remote_device.
1973 static struct isci_remote_device
*
1974 isci_remote_device_alloc(struct isci_host
*ihost
, struct isci_port
*iport
)
1976 struct isci_remote_device
*idev
;
1979 for (i
= 0; i
< SCI_MAX_REMOTE_DEVICES
; i
++) {
1980 idev
= &ihost
->devices
[i
];
1981 if (!test_and_set_bit(IDEV_ALLOCATED
, &idev
->flags
))
1985 if (i
>= SCI_MAX_REMOTE_DEVICES
) {
1986 dev_warn(&ihost
->pdev
->dev
, "%s: failed\n", __func__
);
1990 if (WARN_ONCE(!list_empty(&idev
->reqs_in_process
), "found requests in process\n"))
1993 if (WARN_ONCE(!list_empty(&idev
->node
), "found non-idle remote device\n"))
1996 isci_remote_device_change_state(idev
, isci_freed
);
2002 * isci_remote_device_stop() - This function is called internally to stop the
2004 * @isci_host: This parameter specifies the isci host object.
2005 * @isci_device: This parameter specifies the remote device.
2007 * The status of the scic request to stop.
2009 enum sci_status
isci_remote_device_stop(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
2011 enum sci_status status
;
2012 unsigned long flags
;
2014 dev_dbg(&ihost
->pdev
->dev
,
2015 "%s: isci_device = %p\n", __func__
, idev
);
2017 isci_remote_device_change_state(idev
, isci_stopping
);
2019 /* Kill all outstanding requests. */
2020 isci_remote_device_nuke_requests(ihost
, idev
);
2022 set_bit(IDEV_STOP_PENDING
, &idev
->flags
);
2024 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
2025 status
= scic_remote_device_stop(&idev
->sci
, 50);
2026 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);
2028 /* Wait for the stop complete callback. */
2029 if (status
== SCI_SUCCESS
) {
2030 wait_for_device_stop(ihost
, idev
);
2031 clear_bit(IDEV_ALLOCATED
, &idev
->flags
);
2034 dev_dbg(&ihost
->pdev
->dev
,
2035 "%s: idev = %p - after completion wait\n",
2042 * isci_remote_device_gone() - This function is called by libsas when a domain
2043 * device is removed.
2044 * @domain_device: This parameter specifies the libsas domain device.
2047 void isci_remote_device_gone(struct domain_device
*dev
)
2049 struct isci_host
*ihost
= dev_to_ihost(dev
);
2050 struct isci_remote_device
*idev
= dev
->lldd_dev
;
2052 dev_dbg(&ihost
->pdev
->dev
,
2053 "%s: domain_device = %p, isci_device = %p, isci_port = %p\n",
2054 __func__
, dev
, idev
, idev
->isci_port
);
2056 isci_remote_device_stop(ihost
, idev
);
2061 * isci_remote_device_found() - This function is called by libsas when a remote
2062 * device is discovered. A remote device object is created and started. the
2063 * function then sleeps until the sci core device started message is
2065 * @domain_device: This parameter specifies the libsas domain device.
2067 * status, zero indicates success.
2069 int isci_remote_device_found(struct domain_device
*domain_dev
)
2071 struct isci_host
*isci_host
= dev_to_ihost(domain_dev
);
2072 struct isci_port
*isci_port
;
2073 struct isci_phy
*isci_phy
;
2074 struct asd_sas_port
*sas_port
;
2075 struct asd_sas_phy
*sas_phy
;
2076 struct isci_remote_device
*isci_device
;
2077 enum sci_status status
;
2079 dev_dbg(&isci_host
->pdev
->dev
,
2080 "%s: domain_device = %p\n", __func__
, domain_dev
);
2082 wait_for_start(isci_host
);
2084 sas_port
= domain_dev
->port
;
2085 sas_phy
= list_first_entry(&sas_port
->phy_list
, struct asd_sas_phy
,
2087 isci_phy
= to_isci_phy(sas_phy
);
2088 isci_port
= isci_phy
->isci_port
;
2090 /* we are being called for a device on this port,
2091 * so it has to come up eventually
2093 wait_for_completion(&isci_port
->start_complete
);
2095 if ((isci_stopping
== isci_port_get_state(isci_port
)) ||
2096 (isci_stopped
== isci_port_get_state(isci_port
)))
2099 isci_device
= isci_remote_device_alloc(isci_host
, isci_port
);
2103 INIT_LIST_HEAD(&isci_device
->node
);
2104 domain_dev
->lldd_dev
= isci_device
;
2105 isci_device
->domain_dev
= domain_dev
;
2106 isci_device
->isci_port
= isci_port
;
2107 isci_remote_device_change_state(isci_device
, isci_starting
);
2110 spin_lock_irq(&isci_host
->scic_lock
);
2111 list_add_tail(&isci_device
->node
, &isci_port
->remote_dev_list
);
2113 set_bit(IDEV_START_PENDING
, &isci_device
->flags
);
2114 status
= isci_remote_device_construct(isci_port
, isci_device
);
2115 spin_unlock_irq(&isci_host
->scic_lock
);
2117 dev_dbg(&isci_host
->pdev
->dev
,
2118 "%s: isci_device = %p\n",
2119 __func__
, isci_device
);
2121 if (status
!= SCI_SUCCESS
) {
2123 spin_lock_irq(&isci_host
->scic_lock
);
2124 isci_remote_device_deconstruct(
2128 spin_unlock_irq(&isci_host
->scic_lock
);
2132 /* wait for the device ready callback. */
2133 wait_for_device_start(isci_host
, isci_device
);
2138 * isci_device_is_reset_pending() - This function will check if there is any
2139 * pending reset condition on the device.
2140 * @request: This parameter is the isci_device object.
2142 * true if there is a reset pending for the device.
2144 bool isci_device_is_reset_pending(
2145 struct isci_host
*isci_host
,
2146 struct isci_remote_device
*isci_device
)
2148 struct isci_request
*isci_request
;
2149 struct isci_request
*tmp_req
;
2150 bool reset_is_pending
= false;
2151 unsigned long flags
;
2153 dev_dbg(&isci_host
->pdev
->dev
,
2154 "%s: isci_device = %p\n", __func__
, isci_device
);
2156 spin_lock_irqsave(&isci_host
->scic_lock
, flags
);
2158 /* Check for reset on all pending requests. */
2159 list_for_each_entry_safe(isci_request
, tmp_req
,
2160 &isci_device
->reqs_in_process
, dev_node
) {
2161 dev_dbg(&isci_host
->pdev
->dev
,
2162 "%s: isci_device = %p request = %p\n",
2163 __func__
, isci_device
, isci_request
);
2165 if (isci_request
->ttype
== io_task
) {
2166 struct sas_task
*task
= isci_request_access_task(
2169 spin_lock(&task
->task_state_lock
);
2170 if (task
->task_state_flags
& SAS_TASK_NEED_DEV_RESET
)
2171 reset_is_pending
= true;
2172 spin_unlock(&task
->task_state_lock
);
2176 spin_unlock_irqrestore(&isci_host
->scic_lock
, flags
);
2178 dev_dbg(&isci_host
->pdev
->dev
,
2179 "%s: isci_device = %p reset_is_pending = %d\n",
2180 __func__
, isci_device
, reset_is_pending
);
2182 return reset_is_pending
;
2186 * isci_device_clear_reset_pending() - This function will clear if any pending
2187 * reset condition flags on the device.
2188 * @request: This parameter is the isci_device object.
2190 * true if there is a reset pending for the device.
2192 void isci_device_clear_reset_pending(struct isci_host
*ihost
, struct isci_remote_device
*idev
)
2194 struct isci_request
*isci_request
;
2195 struct isci_request
*tmp_req
;
2196 unsigned long flags
= 0;
2198 dev_dbg(&ihost
->pdev
->dev
, "%s: idev=%p, ihost=%p\n",
2199 __func__
, idev
, ihost
);
2201 spin_lock_irqsave(&ihost
->scic_lock
, flags
);
2203 /* Clear reset pending on all pending requests. */
2204 list_for_each_entry_safe(isci_request
, tmp_req
,
2205 &idev
->reqs_in_process
, dev_node
) {
2206 dev_dbg(&ihost
->pdev
->dev
, "%s: idev = %p request = %p\n",
2207 __func__
, idev
, isci_request
);
2209 if (isci_request
->ttype
== io_task
) {
2211 unsigned long flags2
;
2212 struct sas_task
*task
= isci_request_access_task(
2215 spin_lock_irqsave(&task
->task_state_lock
, flags2
);
2216 task
->task_state_flags
&= ~SAS_TASK_NEED_DEV_RESET
;
2217 spin_unlock_irqrestore(&task
->task_state_lock
, flags2
);
2220 spin_unlock_irqrestore(&ihost
->scic_lock
, flags
);