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.
56 #include "sci_base_state_machine.h"
57 #include "scic_sds_controller.h"
58 #include "scic_sds_port.h"
59 #include "remote_device.h"
60 #include "remote_node_context.h"
61 #include "sci_environment.h"
63 #include "scu_event_codes.h"
64 #include "scu_task_context.h"
69 * @sci_rnc: The RNC for which the is posted request is being made.
71 * This method will return true if the RNC is not in the initial state. In all
72 * other states the RNC is considered active and this will return true. The
73 * destroy request of the state machine drives the RNC back to the initial
74 * state. If the state machine changes then this routine will also have to be
75 * changed. bool true if the state machine is not in the initial state false if
76 * the state machine is in the initial state
81 * @sci_rnc: The state of the remote node context object to check.
83 * This method will return true if the remote node context is in a READY state
84 * otherwise it will return false bool true if the remote node context is in
85 * the ready state. false if the remote node context is not in the ready state.
87 bool scic_sds_remote_node_context_is_ready(
88 struct scic_sds_remote_node_context
*sci_rnc
)
90 u32 current_state
= sci_base_state_machine_get_state(&sci_rnc
->state_machine
);
92 if (current_state
== SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
) {
101 * @sci_dev: The remote device to use to construct the RNC buffer.
102 * @rnc: The buffer into which the remote device data will be copied.
104 * This method will construct the RNC buffer for this remote device object. none
106 static void scic_sds_remote_node_context_construct_buffer(
107 struct scic_sds_remote_node_context
*sci_rnc
)
109 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
110 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
111 union scu_remote_node_context
*rnc
;
112 struct scic_sds_controller
*scic
;
115 scic
= scic_sds_remote_device_get_controller(sci_dev
);
117 rnc
= scic_sds_controller_get_remote_node_context_buffer(
118 scic
, sci_rnc
->remote_node_index
);
120 memset(rnc
, 0, sizeof(union scu_remote_node_context
)
121 * scic_sds_remote_device_node_count(sci_dev
));
123 rnc
->ssp
.remote_node_index
= sci_rnc
->remote_node_index
;
124 rnc
->ssp
.remote_node_port_width
= sci_dev
->device_port_width
;
125 rnc
->ssp
.logical_port_index
=
126 scic_sds_remote_device_get_port_index(sci_dev
);
128 /* sas address is __be64, context ram format is __le64 */
129 sas_addr
= cpu_to_le64(SAS_ADDR(dev
->sas_addr
));
130 rnc
->ssp
.remote_sas_address_hi
= upper_32_bits(sas_addr
);
131 rnc
->ssp
.remote_sas_address_lo
= lower_32_bits(sas_addr
);
133 rnc
->ssp
.nexus_loss_timer_enable
= true;
134 rnc
->ssp
.check_bit
= false;
135 rnc
->ssp
.is_valid
= false;
136 rnc
->ssp
.is_remote_node_context
= true;
137 rnc
->ssp
.function_number
= 0;
139 rnc
->ssp
.arbitration_wait_time
= 0;
141 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
142 rnc
->ssp
.connection_occupancy_timeout
=
143 scic
->user_parameters
.sds1
.stp_max_occupancy_timeout
;
144 rnc
->ssp
.connection_inactivity_timeout
=
145 scic
->user_parameters
.sds1
.stp_inactivity_timeout
;
147 rnc
->ssp
.connection_occupancy_timeout
=
148 scic
->user_parameters
.sds1
.ssp_max_occupancy_timeout
;
149 rnc
->ssp
.connection_inactivity_timeout
=
150 scic
->user_parameters
.sds1
.ssp_inactivity_timeout
;
153 rnc
->ssp
.initial_arbitration_wait_time
= 0;
155 /* Open Address Frame Parameters */
156 rnc
->ssp
.oaf_connection_rate
= sci_dev
->connection_rate
;
157 rnc
->ssp
.oaf_features
= 0;
158 rnc
->ssp
.oaf_source_zone_group
= 0;
159 rnc
->ssp
.oaf_more_compatibility_features
= 0;
166 * @callback_parameter:
168 * This method will setup the remote node context object so it will transition
169 * to its ready state. If the remote node context is already setup to
170 * transition to its final state then this function does nothing. none
172 static void scic_sds_remote_node_context_setup_to_resume(
173 struct scic_sds_remote_node_context
*sci_rnc
,
174 scics_sds_remote_node_context_callback callback
,
175 void *callback_parameter
)
177 if (sci_rnc
->destination_state
!= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
) {
178 sci_rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
;
179 sci_rnc
->user_callback
= callback
;
180 sci_rnc
->user_cookie
= callback_parameter
;
188 * @callback_parameter:
190 * This method will setup the remote node context object so it will transistion
191 * to its final state. none
193 static void scic_sds_remote_node_context_setup_to_destory(
194 struct scic_sds_remote_node_context
*sci_rnc
,
195 scics_sds_remote_node_context_callback callback
,
196 void *callback_parameter
)
198 sci_rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
;
199 sci_rnc
->user_callback
= callback
;
200 sci_rnc
->user_cookie
= callback_parameter
;
208 * This method will continue to resume a remote node context. This is used in
209 * the states where a resume is requested while a resume is in progress.
211 static enum sci_status
scic_sds_remote_node_context_continue_to_resume_handler(
212 struct scic_sds_remote_node_context
*sci_rnc
,
213 scics_sds_remote_node_context_callback callback
,
214 void *callback_parameter
)
216 if (sci_rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
) {
217 sci_rnc
->user_callback
= callback
;
218 sci_rnc
->user_cookie
= callback_parameter
;
223 return SCI_FAILURE_INVALID_STATE
;
226 /* --------------------------------------------------------------------------- */
228 static enum sci_status
scic_sds_remote_node_context_default_destruct_handler(
229 struct scic_sds_remote_node_context
*sci_rnc
,
230 scics_sds_remote_node_context_callback callback
,
231 void *callback_parameter
)
233 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
234 "%s: SCIC Remote Node Context 0x%p requested to stop while "
235 "in unexpected state %d\n",
238 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
241 * We have decided that the destruct request on the remote node context can not fail
242 * since it is either in the initial/destroyed state or is can be destroyed. */
246 static enum sci_status
scic_sds_remote_node_context_default_suspend_handler(
247 struct scic_sds_remote_node_context
*sci_rnc
,
249 scics_sds_remote_node_context_callback callback
,
250 void *callback_parameter
)
252 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
253 "%s: SCIC Remote Node Context 0x%p requested to suspend "
254 "while in wrong state %d\n",
257 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
259 return SCI_FAILURE_INVALID_STATE
;
262 static enum sci_status
scic_sds_remote_node_context_default_resume_handler(
263 struct scic_sds_remote_node_context
*sci_rnc
,
264 scics_sds_remote_node_context_callback callback
,
265 void *callback_parameter
)
267 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
268 "%s: SCIC Remote Node Context 0x%p requested to resume "
269 "while in wrong state %d\n",
272 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
274 return SCI_FAILURE_INVALID_STATE
;
277 static enum sci_status
scic_sds_remote_node_context_default_start_io_handler(
278 struct scic_sds_remote_node_context
*sci_rnc
,
279 struct scic_sds_request
*sci_req
)
281 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
282 "%s: SCIC Remote Node Context 0x%p requested to start io "
283 "0x%p while in wrong state %d\n",
287 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
289 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
;
292 static enum sci_status
scic_sds_remote_node_context_default_start_task_handler(
293 struct scic_sds_remote_node_context
*sci_rnc
,
294 struct scic_sds_request
*sci_req
)
296 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
297 "%s: SCIC Remote Node Context 0x%p requested to start "
298 "task 0x%p while in wrong state %d\n",
302 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
307 static enum sci_status
scic_sds_remote_node_context_default_event_handler(
308 struct scic_sds_remote_node_context
*sci_rnc
,
311 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
312 "%s: SCIC Remote Node Context 0x%p requested to process "
313 "event 0x%x while in wrong state %d\n",
317 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
319 return SCI_FAILURE_INVALID_STATE
;
324 * @sci_rnc: The rnc for which the task request is targeted.
325 * @sci_req: The request which is going to be started.
327 * This method determines if the task request can be started by the SCU
328 * hardware. When the RNC is in the ready state any task can be started.
329 * enum sci_status SCI_SUCCESS
331 static enum sci_status
scic_sds_remote_node_context_success_start_task_handler(
332 struct scic_sds_remote_node_context
*sci_rnc
,
333 struct scic_sds_request
*sci_req
)
342 * @callback_parameter:
344 * This method handles destruct calls from the various state handlers. The
345 * remote node context can be requested to destroy from any state. If there was
346 * a user callback it is always replaced with the request to destroy user
347 * callback. enum sci_status
349 static enum sci_status
scic_sds_remote_node_context_general_destruct_handler(
350 struct scic_sds_remote_node_context
*sci_rnc
,
351 scics_sds_remote_node_context_callback callback
,
352 void *callback_parameter
)
354 scic_sds_remote_node_context_setup_to_destory(
355 sci_rnc
, callback
, callback_parameter
358 sci_base_state_machine_change_state(
359 &sci_rnc
->state_machine
,
360 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
366 /* --------------------------------------------------------------------------- */
368 static enum sci_status
scic_sds_remote_node_context_initial_state_resume_handler(
369 struct scic_sds_remote_node_context
*sci_rnc
,
370 scics_sds_remote_node_context_callback callback
,
371 void *callback_parameter
)
373 if (sci_rnc
->remote_node_index
!= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
374 scic_sds_remote_node_context_setup_to_resume(
375 sci_rnc
, callback
, callback_parameter
378 scic_sds_remote_node_context_construct_buffer(sci_rnc
);
380 sci_base_state_machine_change_state(
381 &sci_rnc
->state_machine
,
382 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
388 return SCI_FAILURE_INVALID_STATE
;
391 /* --------------------------------------------------------------------------- */
393 static enum sci_status
scic_sds_remote_node_context_posting_state_event_handler(
394 struct scic_sds_remote_node_context
*sci_rnc
,
397 enum sci_status status
;
399 switch (scu_get_event_code(event_code
)) {
400 case SCU_EVENT_POST_RNC_COMPLETE
:
401 status
= SCI_SUCCESS
;
403 sci_base_state_machine_change_state(
404 &sci_rnc
->state_machine
,
405 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
410 status
= SCI_FAILURE
;
411 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
412 "%s: SCIC Remote Node Context 0x%p requested to "
413 "process unexpected event 0x%x while in posting "
424 /* --------------------------------------------------------------------------- */
426 static enum sci_status
scic_sds_remote_node_context_invalidating_state_destruct_handler(
427 struct scic_sds_remote_node_context
*sci_rnc
,
428 scics_sds_remote_node_context_callback callback
,
429 void *callback_parameter
)
431 scic_sds_remote_node_context_setup_to_destory(
432 sci_rnc
, callback
, callback_parameter
438 static enum sci_status
scic_sds_remote_node_context_invalidating_state_event_handler(
439 struct scic_sds_remote_node_context
*sci_rnc
,
442 enum sci_status status
;
444 if (scu_get_event_code(event_code
) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE
) {
445 status
= SCI_SUCCESS
;
447 if (sci_rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
) {
448 sci_base_state_machine_change_state(
449 &sci_rnc
->state_machine
,
450 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
453 sci_base_state_machine_change_state(
454 &sci_rnc
->state_machine
,
455 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
459 switch (scu_get_event_type(event_code
)) {
460 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
461 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
463 * We really dont care if the hardware is going to suspend
464 * the device since it's being invalidated anyway */
465 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
466 "%s: SCIC Remote Node Context 0x%p was "
467 "suspeneded by hardware while being "
471 status
= SCI_SUCCESS
;
475 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
476 "%s: SCIC Remote Node Context 0x%p "
477 "requested to process event 0x%x while "
482 sci_base_state_machine_get_state(
483 &sci_rnc
->state_machine
));
484 status
= SCI_FAILURE
;
492 /* --------------------------------------------------------------------------- */
495 static enum sci_status
scic_sds_remote_node_context_resuming_state_event_handler(
496 struct scic_sds_remote_node_context
*sci_rnc
,
499 enum sci_status status
;
501 if (scu_get_event_code(event_code
) == SCU_EVENT_POST_RCN_RELEASE
) {
502 status
= SCI_SUCCESS
;
504 sci_base_state_machine_change_state(
505 &sci_rnc
->state_machine
,
506 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
509 switch (scu_get_event_type(event_code
)) {
510 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
511 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
513 * We really dont care if the hardware is going to suspend
514 * the device since it's being resumed anyway */
515 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
516 "%s: SCIC Remote Node Context 0x%p was "
517 "suspeneded by hardware while being resumed.\n",
520 status
= SCI_SUCCESS
;
524 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
525 "%s: SCIC Remote Node Context 0x%p requested "
526 "to process event 0x%x while in state %d.\n",
530 sci_base_state_machine_get_state(
531 &sci_rnc
->state_machine
));
532 status
= SCI_FAILURE
;
540 /* --------------------------------------------------------------------------- */
544 * @sci_rnc: The remote node context object being suspended.
545 * @callback: The callback when the suspension is complete.
546 * @callback_parameter: The parameter that is to be passed into the callback.
548 * This method will handle the suspend requests from the ready state.
551 static enum sci_status
scic_sds_remote_node_context_ready_state_suspend_handler(
552 struct scic_sds_remote_node_context
*sci_rnc
,
554 scics_sds_remote_node_context_callback callback
,
555 void *callback_parameter
)
557 sci_rnc
->user_callback
= callback
;
558 sci_rnc
->user_cookie
= callback_parameter
;
559 sci_rnc
->suspension_code
= suspend_type
;
561 if (suspend_type
== SCI_SOFTWARE_SUSPENSION
) {
562 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc
),
563 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX
);
566 sci_base_state_machine_change_state(
567 &sci_rnc
->state_machine
,
568 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
576 * @sci_rnc: The rnc for which the io request is targeted.
577 * @sci_req: The request which is going to be started.
579 * This method determines if the io request can be started by the SCU hardware.
580 * When the RNC is in the ready state any io request can be started. enum sci_status
583 static enum sci_status
scic_sds_remote_node_context_ready_state_start_io_handler(
584 struct scic_sds_remote_node_context
*sci_rnc
,
585 struct scic_sds_request
*sci_req
)
591 static enum sci_status
scic_sds_remote_node_context_ready_state_event_handler(
592 struct scic_sds_remote_node_context
*sci_rnc
,
595 enum sci_status status
;
597 switch (scu_get_event_type(event_code
)) {
598 case SCU_EVENT_TL_RNC_SUSPEND_TX
:
599 sci_base_state_machine_change_state(
600 &sci_rnc
->state_machine
,
601 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
604 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
605 status
= SCI_SUCCESS
;
608 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX
:
609 sci_base_state_machine_change_state(
610 &sci_rnc
->state_machine
,
611 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
614 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
615 status
= SCI_SUCCESS
;
619 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
620 "%s: SCIC Remote Node Context 0x%p requested to "
621 "process event 0x%x while in state %d.\n",
625 sci_base_state_machine_get_state(
626 &sci_rnc
->state_machine
));
628 status
= SCI_FAILURE
;
635 /* --------------------------------------------------------------------------- */
637 static enum sci_status
scic_sds_remote_node_context_tx_suspended_state_resume_handler(
638 struct scic_sds_remote_node_context
*sci_rnc
,
639 scics_sds_remote_node_context_callback callback
,
640 void *callback_parameter
)
642 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
643 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
644 enum sci_status status
= SCI_SUCCESS
;
646 scic_sds_remote_node_context_setup_to_resume(sci_rnc
, callback
,
649 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
650 if (dev
->dev_type
== SAS_END_DEV
|| dev_is_expander(dev
))
651 sci_base_state_machine_change_state(&sci_rnc
->state_machine
,
652 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
);
653 else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
654 if (sci_dev
->is_direct_attached
) {
655 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
656 sci_base_state_machine_change_state(
657 &sci_rnc
->state_machine
,
658 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
);
660 sci_base_state_machine_change_state(
661 &sci_rnc
->state_machine
,
662 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
);
665 status
= SCI_FAILURE
;
672 * @sci_rnc: The remote node context which is to receive the task request.
673 * @sci_req: The task request to be transmitted to to the remote target
676 * This method will report a success or failure attempt to start a new task
677 * request to the hardware. Since all task requests are sent on the high
678 * priority queue they can be sent when the RCN is in a TX suspend state.
679 * enum sci_status SCI_SUCCESS
681 static enum sci_status
scic_sds_remote_node_context_suspended_start_task_handler(
682 struct scic_sds_remote_node_context
*sci_rnc
,
683 struct scic_sds_request
*sci_req
)
685 scic_sds_remote_node_context_resume(sci_rnc
, NULL
, NULL
);
690 /* --------------------------------------------------------------------------- */
692 static enum sci_status
scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
693 struct scic_sds_remote_node_context
*sci_rnc
,
694 scics_sds_remote_node_context_callback callback
,
695 void *callback_parameter
)
697 scic_sds_remote_node_context_setup_to_resume(
698 sci_rnc
, callback
, callback_parameter
701 sci_base_state_machine_change_state(
702 &sci_rnc
->state_machine
,
703 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
706 return SCI_FAILURE_INVALID_STATE
;
709 /* --------------------------------------------------------------------------- */
716 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_resume_handler(
717 struct scic_sds_remote_node_context
*sci_rnc
,
718 scics_sds_remote_node_context_callback callback
,
719 void *callback_parameter
)
721 scic_sds_remote_node_context_setup_to_resume(
722 sci_rnc
, callback
, callback_parameter
730 * @sci_rnc: The remote node context which is to receive the task request.
731 * @sci_req: The task request to be transmitted to to the remote target
734 * This method will report a success or failure attempt to start a new task
735 * request to the hardware. Since all task requests are sent on the high
736 * priority queue they can be sent when the RCN is in a TX suspend state.
737 * enum sci_status SCI_SUCCESS
739 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_start_task_handler(
740 struct scic_sds_remote_node_context
*sci_rnc
,
741 struct scic_sds_request
*sci_req
)
746 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_event_handler(
747 struct scic_sds_remote_node_context
*sci_rnc
,
750 enum sci_status status
;
752 switch (scu_get_event_type(event_code
)) {
753 case SCU_EVENT_TL_RNC_SUSPEND_TX
:
754 sci_base_state_machine_change_state(
755 &sci_rnc
->state_machine
,
756 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
759 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
760 status
= SCI_SUCCESS
;
763 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX
:
764 sci_base_state_machine_change_state(
765 &sci_rnc
->state_machine
,
766 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
769 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
770 status
= SCI_SUCCESS
;
774 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
775 "%s: SCIC Remote Node Context 0x%p requested to "
776 "process event 0x%x while in state %d.\n",
780 sci_base_state_machine_get_state(
781 &sci_rnc
->state_machine
));
783 status
= SCI_FAILURE
;
790 /* --------------------------------------------------------------------------- */
792 static struct scic_sds_remote_node_context_handlers
793 scic_sds_remote_node_context_state_handler_table
[
794 SCIC_SDS_REMOTE_NODE_CONTEXT_MAX_STATES
] =
796 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE */
798 scic_sds_remote_node_context_default_destruct_handler
,
799 scic_sds_remote_node_context_default_suspend_handler
,
800 scic_sds_remote_node_context_initial_state_resume_handler
,
801 scic_sds_remote_node_context_default_start_io_handler
,
802 scic_sds_remote_node_context_default_start_task_handler
,
803 scic_sds_remote_node_context_default_event_handler
805 /* SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE */
807 scic_sds_remote_node_context_general_destruct_handler
,
808 scic_sds_remote_node_context_default_suspend_handler
,
809 scic_sds_remote_node_context_continue_to_resume_handler
,
810 scic_sds_remote_node_context_default_start_io_handler
,
811 scic_sds_remote_node_context_default_start_task_handler
,
812 scic_sds_remote_node_context_posting_state_event_handler
814 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE */
816 scic_sds_remote_node_context_invalidating_state_destruct_handler
,
817 scic_sds_remote_node_context_default_suspend_handler
,
818 scic_sds_remote_node_context_continue_to_resume_handler
,
819 scic_sds_remote_node_context_default_start_io_handler
,
820 scic_sds_remote_node_context_default_start_task_handler
,
821 scic_sds_remote_node_context_invalidating_state_event_handler
823 /* SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE */
825 scic_sds_remote_node_context_general_destruct_handler
,
826 scic_sds_remote_node_context_default_suspend_handler
,
827 scic_sds_remote_node_context_continue_to_resume_handler
,
828 scic_sds_remote_node_context_default_start_io_handler
,
829 scic_sds_remote_node_context_success_start_task_handler
,
830 scic_sds_remote_node_context_resuming_state_event_handler
832 /* SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE */
834 scic_sds_remote_node_context_general_destruct_handler
,
835 scic_sds_remote_node_context_ready_state_suspend_handler
,
836 scic_sds_remote_node_context_default_resume_handler
,
837 scic_sds_remote_node_context_ready_state_start_io_handler
,
838 scic_sds_remote_node_context_success_start_task_handler
,
839 scic_sds_remote_node_context_ready_state_event_handler
841 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE */
843 scic_sds_remote_node_context_general_destruct_handler
,
844 scic_sds_remote_node_context_default_suspend_handler
,
845 scic_sds_remote_node_context_tx_suspended_state_resume_handler
,
846 scic_sds_remote_node_context_default_start_io_handler
,
847 scic_sds_remote_node_context_suspended_start_task_handler
,
848 scic_sds_remote_node_context_default_event_handler
850 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE */
852 scic_sds_remote_node_context_general_destruct_handler
,
853 scic_sds_remote_node_context_default_suspend_handler
,
854 scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler
,
855 scic_sds_remote_node_context_default_start_io_handler
,
856 scic_sds_remote_node_context_suspended_start_task_handler
,
857 scic_sds_remote_node_context_default_event_handler
859 /* SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE */
861 scic_sds_remote_node_context_general_destruct_handler
,
862 scic_sds_remote_node_context_default_suspend_handler
,
863 scic_sds_remote_node_context_await_suspension_state_resume_handler
,
864 scic_sds_remote_node_context_default_start_io_handler
,
865 scic_sds_remote_node_context_await_suspension_state_start_task_handler
,
866 scic_sds_remote_node_context_await_suspension_state_event_handler
871 * *****************************************************************************
872 * * REMOTE NODE CONTEXT PRIVATE METHODS
873 * ***************************************************************************** */
878 * This method just calls the user callback function and then resets the
881 static void scic_sds_remote_node_context_notify_user(
882 struct scic_sds_remote_node_context
*rnc
)
884 if (rnc
->user_callback
!= NULL
) {
885 (*rnc
->user_callback
)(rnc
->user_cookie
);
887 rnc
->user_callback
= NULL
;
888 rnc
->user_cookie
= NULL
;
895 * This method will continue the remote node context state machine by
896 * requesting to resume the remote node context state machine from its current
899 static void scic_sds_remote_node_context_continue_state_transitions(
900 struct scic_sds_remote_node_context
*rnc
)
902 if (rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
) {
903 rnc
->state_handlers
->resume_handler(
904 rnc
, rnc
->user_callback
, rnc
->user_cookie
911 * @sci_rnc: The remote node context object that is to be validated.
913 * This method will mark the rnc buffer as being valid and post the request to
916 static void scic_sds_remote_node_context_validate_context_buffer(
917 struct scic_sds_remote_node_context
*sci_rnc
)
919 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
920 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
921 union scu_remote_node_context
*rnc_buffer
;
923 rnc_buffer
= scic_sds_controller_get_remote_node_context_buffer(
924 scic_sds_remote_device_get_controller(sci_dev
),
925 sci_rnc
->remote_node_index
928 rnc_buffer
->ssp
.is_valid
= true;
930 if (!sci_dev
->is_direct_attached
&&
931 (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))) {
932 scic_sds_remote_device_post_request(sci_dev
,
933 SCU_CONTEXT_COMMAND_POST_RNC_96
);
935 scic_sds_remote_device_post_request(sci_dev
, SCU_CONTEXT_COMMAND_POST_RNC_32
);
937 if (sci_dev
->is_direct_attached
) {
938 scic_sds_port_setup_transports(sci_dev
->owning_port
,
939 sci_rnc
->remote_node_index
);
946 * @sci_rnc: The remote node context object that is to be invalidated.
948 * This method will update the RNC buffer and post the invalidate request. none
950 static void scic_sds_remote_node_context_invalidate_context_buffer(
951 struct scic_sds_remote_node_context
*sci_rnc
)
953 union scu_remote_node_context
*rnc_buffer
;
955 rnc_buffer
= scic_sds_controller_get_remote_node_context_buffer(
956 scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc
)),
957 sci_rnc
->remote_node_index
);
959 rnc_buffer
->ssp
.is_valid
= false;
961 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc
),
962 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
);
966 * *****************************************************************************
967 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
968 * ***************************************************************************** */
975 static void scic_sds_remote_node_context_initial_state_enter(
976 struct sci_base_object
*object
)
978 struct scic_sds_remote_node_context
*rnc
;
980 rnc
= (struct scic_sds_remote_node_context
*)object
;
984 scic_sds_remote_node_context_state_handler_table
,
985 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
989 * Check to see if we have gotten back to the initial state because someone
990 * requested to destroy the remote node context object. */
992 rnc
->state_machine
.previous_state_id
993 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
995 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
997 scic_sds_remote_node_context_notify_user(rnc
);
1006 static void scic_sds_remote_node_context_posting_state_enter(
1007 struct sci_base_object
*object
)
1009 struct scic_sds_remote_node_context
*sci_rnc
;
1011 sci_rnc
= (struct scic_sds_remote_node_context
*)object
;
1015 scic_sds_remote_node_context_state_handler_table
,
1016 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
1019 scic_sds_remote_node_context_validate_context_buffer(sci_rnc
);
1027 static void scic_sds_remote_node_context_invalidating_state_enter(
1028 struct sci_base_object
*object
)
1030 struct scic_sds_remote_node_context
*rnc
;
1032 rnc
= (struct scic_sds_remote_node_context
*)object
;
1036 scic_sds_remote_node_context_state_handler_table
,
1037 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1040 scic_sds_remote_node_context_invalidate_context_buffer(rnc
);
1048 static void scic_sds_remote_node_context_resuming_state_enter(
1049 struct sci_base_object
*object
)
1051 struct scic_sds_remote_node_context
*rnc
;
1052 struct scic_sds_remote_device
*sci_dev
;
1053 struct domain_device
*dev
;
1055 rnc
= (struct scic_sds_remote_node_context
*)object
;
1056 sci_dev
= rnc_to_dev(rnc
);
1057 dev
= sci_dev_to_domain(sci_dev
);
1061 scic_sds_remote_node_context_state_handler_table
,
1062 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1066 * For direct attached SATA devices we need to clear the TLCR
1067 * NCQ to TCi tag mapping on the phy and in cases where we
1068 * resume because of a target reset we also need to update
1069 * the STPTLDARNI register with the RNi of the device
1071 if ((dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) &&
1072 sci_dev
->is_direct_attached
)
1073 scic_sds_port_setup_transports(sci_dev
->owning_port
,
1074 rnc
->remote_node_index
);
1076 scic_sds_remote_device_post_request(sci_dev
, SCU_CONTEXT_COMMAND_POST_RNC_RESUME
);
1084 static void scic_sds_remote_node_context_ready_state_enter(
1085 struct sci_base_object
*object
)
1087 struct scic_sds_remote_node_context
*rnc
;
1089 rnc
= (struct scic_sds_remote_node_context
*)object
;
1093 scic_sds_remote_node_context_state_handler_table
,
1094 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1097 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
1099 if (rnc
->user_callback
!= NULL
) {
1100 scic_sds_remote_node_context_notify_user(rnc
);
1109 static void scic_sds_remote_node_context_tx_suspended_state_enter(
1110 struct sci_base_object
*object
)
1112 struct scic_sds_remote_node_context
*rnc
;
1114 rnc
= (struct scic_sds_remote_node_context
*)object
;
1118 scic_sds_remote_node_context_state_handler_table
,
1119 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1122 scic_sds_remote_node_context_continue_state_transitions(rnc
);
1130 static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
1131 struct sci_base_object
*object
)
1133 struct scic_sds_remote_node_context
*rnc
;
1135 rnc
= (struct scic_sds_remote_node_context
*)object
;
1139 scic_sds_remote_node_context_state_handler_table
,
1140 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1143 scic_sds_remote_node_context_continue_state_transitions(rnc
);
1151 static void scic_sds_remote_node_context_await_suspension_state_enter(
1152 struct sci_base_object
*object
)
1154 struct scic_sds_remote_node_context
*rnc
;
1156 rnc
= (struct scic_sds_remote_node_context
*)object
;
1160 scic_sds_remote_node_context_state_handler_table
,
1161 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1165 /* --------------------------------------------------------------------------- */
1167 static const struct sci_base_state scic_sds_remote_node_context_state_table
[] = {
1168 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
] = {
1169 .enter_state
= scic_sds_remote_node_context_initial_state_enter
,
1171 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
] = {
1172 .enter_state
= scic_sds_remote_node_context_posting_state_enter
,
1174 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
] = {
1175 .enter_state
= scic_sds_remote_node_context_invalidating_state_enter
,
1177 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
] = {
1178 .enter_state
= scic_sds_remote_node_context_resuming_state_enter
,
1180 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
] = {
1181 .enter_state
= scic_sds_remote_node_context_ready_state_enter
,
1183 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
] = {
1184 .enter_state
= scic_sds_remote_node_context_tx_suspended_state_enter
,
1186 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
] = {
1187 .enter_state
= scic_sds_remote_node_context_tx_rx_suspended_state_enter
,
1189 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
] = {
1190 .enter_state
= scic_sds_remote_node_context_await_suspension_state_enter
,
1194 void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context
*rnc
,
1195 u16 remote_node_index
)
1197 memset(rnc
, 0, sizeof(struct scic_sds_remote_node_context
));
1199 rnc
->remote_node_index
= remote_node_index
;
1200 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
1202 sci_base_state_machine_construct(
1203 &rnc
->state_machine
,
1205 scic_sds_remote_node_context_state_table
,
1206 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1209 sci_base_state_machine_start(&rnc
->state_machine
);