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.
57 #include "state_machine.h"
58 #include "remote_device.h"
59 #include "remote_node_context.h"
60 #include "scu_event_codes.h"
61 #include "scu_task_context.h"
66 * @sci_rnc: The RNC for which the is posted request is being made.
68 * This method will return true if the RNC is not in the initial state. In all
69 * other states the RNC is considered active and this will return true. The
70 * destroy request of the state machine drives the RNC back to the initial
71 * state. If the state machine changes then this routine will also have to be
72 * changed. bool true if the state machine is not in the initial state false if
73 * the state machine is in the initial state
78 * @sci_rnc: The state of the remote node context object to check.
80 * This method will return true if the remote node context is in a READY state
81 * otherwise it will return false bool true if the remote node context is in
82 * the ready state. false if the remote node context is not in the ready state.
84 bool scic_sds_remote_node_context_is_ready(
85 struct scic_sds_remote_node_context
*sci_rnc
)
87 u32 current_state
= sci_base_state_machine_get_state(&sci_rnc
->state_machine
);
89 if (current_state
== SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
) {
98 * @sci_dev: The remote device to use to construct the RNC buffer.
99 * @rnc: The buffer into which the remote device data will be copied.
101 * This method will construct the RNC buffer for this remote device object. none
103 static void scic_sds_remote_node_context_construct_buffer(
104 struct scic_sds_remote_node_context
*sci_rnc
)
106 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
107 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
108 int rni
= sci_rnc
->remote_node_index
;
109 union scu_remote_node_context
*rnc
;
110 struct scic_sds_controller
*scic
;
113 scic
= scic_sds_remote_device_get_controller(sci_dev
);
114 rnc
= scic_sds_controller_get_remote_node_context_buffer(scic
, rni
);
116 memset(rnc
, 0, sizeof(union scu_remote_node_context
)
117 * scic_sds_remote_device_node_count(sci_dev
));
119 rnc
->ssp
.remote_node_index
= rni
;
120 rnc
->ssp
.remote_node_port_width
= sci_dev
->device_port_width
;
121 rnc
->ssp
.logical_port_index
= sci_dev
->owning_port
->physical_port_index
;
123 /* sas address is __be64, context ram format is __le64 */
124 sas_addr
= cpu_to_le64(SAS_ADDR(dev
->sas_addr
));
125 rnc
->ssp
.remote_sas_address_hi
= upper_32_bits(sas_addr
);
126 rnc
->ssp
.remote_sas_address_lo
= lower_32_bits(sas_addr
);
128 rnc
->ssp
.nexus_loss_timer_enable
= true;
129 rnc
->ssp
.check_bit
= false;
130 rnc
->ssp
.is_valid
= false;
131 rnc
->ssp
.is_remote_node_context
= true;
132 rnc
->ssp
.function_number
= 0;
134 rnc
->ssp
.arbitration_wait_time
= 0;
136 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
137 rnc
->ssp
.connection_occupancy_timeout
=
138 scic
->user_parameters
.sds1
.stp_max_occupancy_timeout
;
139 rnc
->ssp
.connection_inactivity_timeout
=
140 scic
->user_parameters
.sds1
.stp_inactivity_timeout
;
142 rnc
->ssp
.connection_occupancy_timeout
=
143 scic
->user_parameters
.sds1
.ssp_max_occupancy_timeout
;
144 rnc
->ssp
.connection_inactivity_timeout
=
145 scic
->user_parameters
.sds1
.ssp_inactivity_timeout
;
148 rnc
->ssp
.initial_arbitration_wait_time
= 0;
150 /* Open Address Frame Parameters */
151 rnc
->ssp
.oaf_connection_rate
= sci_dev
->connection_rate
;
152 rnc
->ssp
.oaf_features
= 0;
153 rnc
->ssp
.oaf_source_zone_group
= 0;
154 rnc
->ssp
.oaf_more_compatibility_features
= 0;
161 * @callback_parameter:
163 * This method will setup the remote node context object so it will transition
164 * to its ready state. If the remote node context is already setup to
165 * transition to its final state then this function does nothing. none
167 static void scic_sds_remote_node_context_setup_to_resume(
168 struct scic_sds_remote_node_context
*sci_rnc
,
169 scics_sds_remote_node_context_callback callback
,
170 void *callback_parameter
)
172 if (sci_rnc
->destination_state
!= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
) {
173 sci_rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
;
174 sci_rnc
->user_callback
= callback
;
175 sci_rnc
->user_cookie
= callback_parameter
;
183 * @callback_parameter:
185 * This method will setup the remote node context object so it will transistion
186 * to its final state. none
188 static void scic_sds_remote_node_context_setup_to_destory(
189 struct scic_sds_remote_node_context
*sci_rnc
,
190 scics_sds_remote_node_context_callback callback
,
191 void *callback_parameter
)
193 sci_rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
;
194 sci_rnc
->user_callback
= callback
;
195 sci_rnc
->user_cookie
= callback_parameter
;
203 * This method will continue to resume a remote node context. This is used in
204 * the states where a resume is requested while a resume is in progress.
206 static enum sci_status
scic_sds_remote_node_context_continue_to_resume_handler(
207 struct scic_sds_remote_node_context
*sci_rnc
,
208 scics_sds_remote_node_context_callback callback
,
209 void *callback_parameter
)
211 if (sci_rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
) {
212 sci_rnc
->user_callback
= callback
;
213 sci_rnc
->user_cookie
= callback_parameter
;
218 return SCI_FAILURE_INVALID_STATE
;
221 /* --------------------------------------------------------------------------- */
223 static enum sci_status
scic_sds_remote_node_context_default_destruct_handler(
224 struct scic_sds_remote_node_context
*sci_rnc
,
225 scics_sds_remote_node_context_callback callback
,
226 void *callback_parameter
)
228 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
229 "%s: SCIC Remote Node Context 0x%p requested to stop while "
230 "in unexpected state %d\n",
233 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
236 * We have decided that the destruct request on the remote node context can not fail
237 * since it is either in the initial/destroyed state or is can be destroyed. */
241 static enum sci_status
scic_sds_remote_node_context_default_suspend_handler(
242 struct scic_sds_remote_node_context
*sci_rnc
,
244 scics_sds_remote_node_context_callback callback
,
245 void *callback_parameter
)
247 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
248 "%s: SCIC Remote Node Context 0x%p requested to suspend "
249 "while in wrong state %d\n",
252 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
254 return SCI_FAILURE_INVALID_STATE
;
257 static enum sci_status
scic_sds_remote_node_context_default_resume_handler(
258 struct scic_sds_remote_node_context
*sci_rnc
,
259 scics_sds_remote_node_context_callback callback
,
260 void *callback_parameter
)
262 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
263 "%s: SCIC Remote Node Context 0x%p requested to resume "
264 "while in wrong state %d\n",
267 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
269 return SCI_FAILURE_INVALID_STATE
;
272 static enum sci_status
scic_sds_remote_node_context_default_start_io_handler(
273 struct scic_sds_remote_node_context
*sci_rnc
,
274 struct scic_sds_request
*sci_req
)
276 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
277 "%s: SCIC Remote Node Context 0x%p requested to start io "
278 "0x%p while in wrong state %d\n",
282 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
284 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
;
287 static enum sci_status
scic_sds_remote_node_context_default_start_task_handler(
288 struct scic_sds_remote_node_context
*sci_rnc
,
289 struct scic_sds_request
*sci_req
)
291 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
292 "%s: SCIC Remote Node Context 0x%p requested to start "
293 "task 0x%p while in wrong state %d\n",
297 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
302 static enum sci_status
scic_sds_remote_node_context_default_event_handler(
303 struct scic_sds_remote_node_context
*sci_rnc
,
306 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
307 "%s: SCIC Remote Node Context 0x%p requested to process "
308 "event 0x%x while in wrong state %d\n",
312 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
314 return SCI_FAILURE_INVALID_STATE
;
319 * @sci_rnc: The rnc for which the task request is targeted.
320 * @sci_req: The request which is going to be started.
322 * This method determines if the task request can be started by the SCU
323 * hardware. When the RNC is in the ready state any task can be started.
324 * enum sci_status SCI_SUCCESS
326 static enum sci_status
scic_sds_remote_node_context_success_start_task_handler(
327 struct scic_sds_remote_node_context
*sci_rnc
,
328 struct scic_sds_request
*sci_req
)
337 * @callback_parameter:
339 * This method handles destruct calls from the various state handlers. The
340 * remote node context can be requested to destroy from any state. If there was
341 * a user callback it is always replaced with the request to destroy user
342 * callback. enum sci_status
344 static enum sci_status
scic_sds_remote_node_context_general_destruct_handler(
345 struct scic_sds_remote_node_context
*sci_rnc
,
346 scics_sds_remote_node_context_callback callback
,
347 void *callback_parameter
)
349 scic_sds_remote_node_context_setup_to_destory(
350 sci_rnc
, callback
, callback_parameter
353 sci_base_state_machine_change_state(
354 &sci_rnc
->state_machine
,
355 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
361 /* --------------------------------------------------------------------------- */
363 static enum sci_status
scic_sds_remote_node_context_initial_state_resume_handler(
364 struct scic_sds_remote_node_context
*sci_rnc
,
365 scics_sds_remote_node_context_callback callback
,
366 void *callback_parameter
)
368 if (sci_rnc
->remote_node_index
!= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
369 scic_sds_remote_node_context_setup_to_resume(
370 sci_rnc
, callback
, callback_parameter
373 scic_sds_remote_node_context_construct_buffer(sci_rnc
);
375 sci_base_state_machine_change_state(
376 &sci_rnc
->state_machine
,
377 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
383 return SCI_FAILURE_INVALID_STATE
;
386 /* --------------------------------------------------------------------------- */
388 static enum sci_status
scic_sds_remote_node_context_posting_state_event_handler(
389 struct scic_sds_remote_node_context
*sci_rnc
,
392 enum sci_status status
;
394 switch (scu_get_event_code(event_code
)) {
395 case SCU_EVENT_POST_RNC_COMPLETE
:
396 status
= SCI_SUCCESS
;
398 sci_base_state_machine_change_state(
399 &sci_rnc
->state_machine
,
400 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
405 status
= SCI_FAILURE
;
406 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
407 "%s: SCIC Remote Node Context 0x%p requested to "
408 "process unexpected event 0x%x while in posting "
419 /* --------------------------------------------------------------------------- */
421 static enum sci_status
scic_sds_remote_node_context_invalidating_state_destruct_handler(
422 struct scic_sds_remote_node_context
*sci_rnc
,
423 scics_sds_remote_node_context_callback callback
,
424 void *callback_parameter
)
426 scic_sds_remote_node_context_setup_to_destory(
427 sci_rnc
, callback
, callback_parameter
433 static enum sci_status
scic_sds_remote_node_context_invalidating_state_event_handler(
434 struct scic_sds_remote_node_context
*sci_rnc
,
437 enum sci_status status
;
439 if (scu_get_event_code(event_code
) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE
) {
440 status
= SCI_SUCCESS
;
442 if (sci_rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
) {
443 sci_base_state_machine_change_state(
444 &sci_rnc
->state_machine
,
445 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
448 sci_base_state_machine_change_state(
449 &sci_rnc
->state_machine
,
450 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
454 switch (scu_get_event_type(event_code
)) {
455 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
456 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
458 * We really dont care if the hardware is going to suspend
459 * the device since it's being invalidated anyway */
460 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
461 "%s: SCIC Remote Node Context 0x%p was "
462 "suspeneded by hardware while being "
466 status
= SCI_SUCCESS
;
470 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
471 "%s: SCIC Remote Node Context 0x%p "
472 "requested to process event 0x%x while "
477 sci_base_state_machine_get_state(
478 &sci_rnc
->state_machine
));
479 status
= SCI_FAILURE
;
487 /* --------------------------------------------------------------------------- */
490 static enum sci_status
scic_sds_remote_node_context_resuming_state_event_handler(
491 struct scic_sds_remote_node_context
*sci_rnc
,
494 enum sci_status status
;
496 if (scu_get_event_code(event_code
) == SCU_EVENT_POST_RCN_RELEASE
) {
497 status
= SCI_SUCCESS
;
499 sci_base_state_machine_change_state(
500 &sci_rnc
->state_machine
,
501 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
504 switch (scu_get_event_type(event_code
)) {
505 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
506 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
508 * We really dont care if the hardware is going to suspend
509 * the device since it's being resumed anyway */
510 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
511 "%s: SCIC Remote Node Context 0x%p was "
512 "suspeneded by hardware while being resumed.\n",
515 status
= SCI_SUCCESS
;
519 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
520 "%s: SCIC Remote Node Context 0x%p requested "
521 "to process event 0x%x while in state %d.\n",
525 sci_base_state_machine_get_state(
526 &sci_rnc
->state_machine
));
527 status
= SCI_FAILURE
;
535 /* --------------------------------------------------------------------------- */
539 * @sci_rnc: The remote node context object being suspended.
540 * @callback: The callback when the suspension is complete.
541 * @callback_parameter: The parameter that is to be passed into the callback.
543 * This method will handle the suspend requests from the ready state.
546 static enum sci_status
scic_sds_remote_node_context_ready_state_suspend_handler(
547 struct scic_sds_remote_node_context
*sci_rnc
,
549 scics_sds_remote_node_context_callback callback
,
550 void *callback_parameter
)
552 sci_rnc
->user_callback
= callback
;
553 sci_rnc
->user_cookie
= callback_parameter
;
554 sci_rnc
->suspension_code
= suspend_type
;
556 if (suspend_type
== SCI_SOFTWARE_SUSPENSION
) {
557 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc
),
558 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX
);
561 sci_base_state_machine_change_state(
562 &sci_rnc
->state_machine
,
563 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
571 * @sci_rnc: The rnc for which the io request is targeted.
572 * @sci_req: The request which is going to be started.
574 * This method determines if the io request can be started by the SCU hardware.
575 * When the RNC is in the ready state any io request can be started. enum sci_status
578 static enum sci_status
scic_sds_remote_node_context_ready_state_start_io_handler(
579 struct scic_sds_remote_node_context
*sci_rnc
,
580 struct scic_sds_request
*sci_req
)
586 static enum sci_status
scic_sds_remote_node_context_ready_state_event_handler(
587 struct scic_sds_remote_node_context
*sci_rnc
,
590 enum sci_status status
;
592 switch (scu_get_event_type(event_code
)) {
593 case SCU_EVENT_TL_RNC_SUSPEND_TX
:
594 sci_base_state_machine_change_state(
595 &sci_rnc
->state_machine
,
596 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
599 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
600 status
= SCI_SUCCESS
;
603 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX
:
604 sci_base_state_machine_change_state(
605 &sci_rnc
->state_machine
,
606 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
609 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
610 status
= SCI_SUCCESS
;
614 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
615 "%s: SCIC Remote Node Context 0x%p requested to "
616 "process event 0x%x while in state %d.\n",
620 sci_base_state_machine_get_state(
621 &sci_rnc
->state_machine
));
623 status
= SCI_FAILURE
;
630 /* --------------------------------------------------------------------------- */
632 static enum sci_status
scic_sds_remote_node_context_tx_suspended_state_resume_handler(
633 struct scic_sds_remote_node_context
*sci_rnc
,
634 scics_sds_remote_node_context_callback callback
,
635 void *callback_parameter
)
637 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
638 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
639 enum sci_status status
= SCI_SUCCESS
;
641 scic_sds_remote_node_context_setup_to_resume(sci_rnc
, callback
,
644 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
645 if (dev
->dev_type
== SAS_END_DEV
|| dev_is_expander(dev
))
646 sci_base_state_machine_change_state(&sci_rnc
->state_machine
,
647 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
);
648 else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
649 if (sci_dev
->is_direct_attached
) {
650 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
651 sci_base_state_machine_change_state(
652 &sci_rnc
->state_machine
,
653 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
);
655 sci_base_state_machine_change_state(
656 &sci_rnc
->state_machine
,
657 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
);
660 status
= SCI_FAILURE
;
667 * @sci_rnc: The remote node context which is to receive the task request.
668 * @sci_req: The task request to be transmitted to to the remote target
671 * This method will report a success or failure attempt to start a new task
672 * request to the hardware. Since all task requests are sent on the high
673 * priority queue they can be sent when the RCN is in a TX suspend state.
674 * enum sci_status SCI_SUCCESS
676 static enum sci_status
scic_sds_remote_node_context_suspended_start_task_handler(
677 struct scic_sds_remote_node_context
*sci_rnc
,
678 struct scic_sds_request
*sci_req
)
680 scic_sds_remote_node_context_resume(sci_rnc
, NULL
, NULL
);
685 /* --------------------------------------------------------------------------- */
687 static enum sci_status
scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
688 struct scic_sds_remote_node_context
*sci_rnc
,
689 scics_sds_remote_node_context_callback callback
,
690 void *callback_parameter
)
692 scic_sds_remote_node_context_setup_to_resume(
693 sci_rnc
, callback
, callback_parameter
696 sci_base_state_machine_change_state(
697 &sci_rnc
->state_machine
,
698 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
701 return SCI_FAILURE_INVALID_STATE
;
704 /* --------------------------------------------------------------------------- */
711 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_resume_handler(
712 struct scic_sds_remote_node_context
*sci_rnc
,
713 scics_sds_remote_node_context_callback callback
,
714 void *callback_parameter
)
716 scic_sds_remote_node_context_setup_to_resume(
717 sci_rnc
, callback
, callback_parameter
725 * @sci_rnc: The remote node context which is to receive the task request.
726 * @sci_req: The task request to be transmitted to to the remote target
729 * This method will report a success or failure attempt to start a new task
730 * request to the hardware. Since all task requests are sent on the high
731 * priority queue they can be sent when the RCN is in a TX suspend state.
732 * enum sci_status SCI_SUCCESS
734 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_start_task_handler(
735 struct scic_sds_remote_node_context
*sci_rnc
,
736 struct scic_sds_request
*sci_req
)
741 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_event_handler(
742 struct scic_sds_remote_node_context
*sci_rnc
,
745 enum sci_status status
;
747 switch (scu_get_event_type(event_code
)) {
748 case SCU_EVENT_TL_RNC_SUSPEND_TX
:
749 sci_base_state_machine_change_state(
750 &sci_rnc
->state_machine
,
751 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
754 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
755 status
= SCI_SUCCESS
;
758 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX
:
759 sci_base_state_machine_change_state(
760 &sci_rnc
->state_machine
,
761 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
764 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
765 status
= SCI_SUCCESS
;
769 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
770 "%s: SCIC Remote Node Context 0x%p requested to "
771 "process event 0x%x while in state %d.\n",
775 sci_base_state_machine_get_state(
776 &sci_rnc
->state_machine
));
778 status
= SCI_FAILURE
;
785 /* --------------------------------------------------------------------------- */
787 static struct scic_sds_remote_node_context_handlers
788 scic_sds_remote_node_context_state_handler_table
[] = {
789 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
] = {
790 .destruct_handler
= scic_sds_remote_node_context_default_destruct_handler
,
791 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
792 .resume_handler
= scic_sds_remote_node_context_initial_state_resume_handler
,
793 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
794 .start_task_handler
= scic_sds_remote_node_context_default_start_task_handler
,
795 .event_handler
= scic_sds_remote_node_context_default_event_handler
797 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
] = {
798 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
799 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
800 .resume_handler
= scic_sds_remote_node_context_continue_to_resume_handler
,
801 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
802 .start_task_handler
= scic_sds_remote_node_context_default_start_task_handler
,
803 .event_handler
= scic_sds_remote_node_context_posting_state_event_handler
805 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
] = {
806 .destruct_handler
= scic_sds_remote_node_context_invalidating_state_destruct_handler
,
807 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
808 .resume_handler
= scic_sds_remote_node_context_continue_to_resume_handler
,
809 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
810 .start_task_handler
= scic_sds_remote_node_context_default_start_task_handler
,
811 .event_handler
= scic_sds_remote_node_context_invalidating_state_event_handler
813 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
] = {
814 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
815 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
816 .resume_handler
= scic_sds_remote_node_context_continue_to_resume_handler
,
817 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
818 .start_task_handler
= scic_sds_remote_node_context_success_start_task_handler
,
819 .event_handler
= scic_sds_remote_node_context_resuming_state_event_handler
821 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
] = {
822 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
823 .suspend_handler
= scic_sds_remote_node_context_ready_state_suspend_handler
,
824 .resume_handler
= scic_sds_remote_node_context_default_resume_handler
,
825 .start_io_handler
= scic_sds_remote_node_context_ready_state_start_io_handler
,
826 .start_task_handler
= scic_sds_remote_node_context_success_start_task_handler
,
827 .event_handler
= scic_sds_remote_node_context_ready_state_event_handler
829 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
] = {
830 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
831 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
832 .resume_handler
= scic_sds_remote_node_context_tx_suspended_state_resume_handler
,
833 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
834 .start_task_handler
= scic_sds_remote_node_context_suspended_start_task_handler
,
835 .event_handler
= scic_sds_remote_node_context_default_event_handler
837 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
] = {
838 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
839 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
840 .resume_handler
= scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler
,
841 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
842 .start_task_handler
= scic_sds_remote_node_context_suspended_start_task_handler
,
843 .event_handler
= scic_sds_remote_node_context_default_event_handler
845 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
] = {
846 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
847 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
848 .resume_handler
= scic_sds_remote_node_context_await_suspension_state_resume_handler
,
849 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
850 .start_task_handler
= scic_sds_remote_node_context_await_suspension_state_start_task_handler
,
851 .event_handler
= scic_sds_remote_node_context_await_suspension_state_event_handler
856 * *****************************************************************************
857 * * REMOTE NODE CONTEXT PRIVATE METHODS
858 * ***************************************************************************** */
863 * This method just calls the user callback function and then resets the
866 static void scic_sds_remote_node_context_notify_user(
867 struct scic_sds_remote_node_context
*rnc
)
869 if (rnc
->user_callback
!= NULL
) {
870 (*rnc
->user_callback
)(rnc
->user_cookie
);
872 rnc
->user_callback
= NULL
;
873 rnc
->user_cookie
= NULL
;
880 * This method will continue the remote node context state machine by
881 * requesting to resume the remote node context state machine from its current
884 static void scic_sds_remote_node_context_continue_state_transitions(
885 struct scic_sds_remote_node_context
*rnc
)
887 if (rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
) {
888 rnc
->state_handlers
->resume_handler(
889 rnc
, rnc
->user_callback
, rnc
->user_cookie
896 * @sci_rnc: The remote node context object that is to be validated.
898 * This method will mark the rnc buffer as being valid and post the request to
901 static void scic_sds_remote_node_context_validate_context_buffer(
902 struct scic_sds_remote_node_context
*sci_rnc
)
904 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
905 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
906 union scu_remote_node_context
*rnc_buffer
;
908 rnc_buffer
= scic_sds_controller_get_remote_node_context_buffer(
909 scic_sds_remote_device_get_controller(sci_dev
),
910 sci_rnc
->remote_node_index
913 rnc_buffer
->ssp
.is_valid
= true;
915 if (!sci_dev
->is_direct_attached
&&
916 (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))) {
917 scic_sds_remote_device_post_request(sci_dev
,
918 SCU_CONTEXT_COMMAND_POST_RNC_96
);
920 scic_sds_remote_device_post_request(sci_dev
, SCU_CONTEXT_COMMAND_POST_RNC_32
);
922 if (sci_dev
->is_direct_attached
) {
923 scic_sds_port_setup_transports(sci_dev
->owning_port
,
924 sci_rnc
->remote_node_index
);
931 * @sci_rnc: The remote node context object that is to be invalidated.
933 * This method will update the RNC buffer and post the invalidate request. none
935 static void scic_sds_remote_node_context_invalidate_context_buffer(
936 struct scic_sds_remote_node_context
*sci_rnc
)
938 union scu_remote_node_context
*rnc_buffer
;
940 rnc_buffer
= scic_sds_controller_get_remote_node_context_buffer(
941 scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc
)),
942 sci_rnc
->remote_node_index
);
944 rnc_buffer
->ssp
.is_valid
= false;
946 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc
),
947 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
);
951 * *****************************************************************************
952 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
953 * ***************************************************************************** */
960 static void scic_sds_remote_node_context_initial_state_enter(void *object
)
962 struct scic_sds_remote_node_context
*rnc
= object
;
966 scic_sds_remote_node_context_state_handler_table
,
967 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
971 * Check to see if we have gotten back to the initial state because someone
972 * requested to destroy the remote node context object. */
974 rnc
->state_machine
.previous_state_id
975 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
977 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
979 scic_sds_remote_node_context_notify_user(rnc
);
988 static void scic_sds_remote_node_context_posting_state_enter(void *object
)
990 struct scic_sds_remote_node_context
*sci_rnc
= object
;
994 scic_sds_remote_node_context_state_handler_table
,
995 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
998 scic_sds_remote_node_context_validate_context_buffer(sci_rnc
);
1006 static void scic_sds_remote_node_context_invalidating_state_enter(void *object
)
1008 struct scic_sds_remote_node_context
*rnc
= object
;
1012 scic_sds_remote_node_context_state_handler_table
,
1013 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1016 scic_sds_remote_node_context_invalidate_context_buffer(rnc
);
1024 static void scic_sds_remote_node_context_resuming_state_enter(void *object
)
1026 struct scic_sds_remote_node_context
*rnc
= object
;
1027 struct scic_sds_remote_device
*sci_dev
;
1028 struct domain_device
*dev
;
1030 sci_dev
= rnc_to_dev(rnc
);
1031 dev
= sci_dev_to_domain(sci_dev
);
1035 scic_sds_remote_node_context_state_handler_table
,
1036 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1040 * For direct attached SATA devices we need to clear the TLCR
1041 * NCQ to TCi tag mapping on the phy and in cases where we
1042 * resume because of a target reset we also need to update
1043 * the STPTLDARNI register with the RNi of the device
1045 if ((dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) &&
1046 sci_dev
->is_direct_attached
)
1047 scic_sds_port_setup_transports(sci_dev
->owning_port
,
1048 rnc
->remote_node_index
);
1050 scic_sds_remote_device_post_request(sci_dev
, SCU_CONTEXT_COMMAND_POST_RNC_RESUME
);
1058 static void scic_sds_remote_node_context_ready_state_enter(void *object
)
1060 struct scic_sds_remote_node_context
*rnc
= object
;
1064 scic_sds_remote_node_context_state_handler_table
,
1065 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1068 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
1070 if (rnc
->user_callback
!= NULL
) {
1071 scic_sds_remote_node_context_notify_user(rnc
);
1080 static void scic_sds_remote_node_context_tx_suspended_state_enter(void *object
)
1082 struct scic_sds_remote_node_context
*rnc
= object
;
1086 scic_sds_remote_node_context_state_handler_table
,
1087 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1090 scic_sds_remote_node_context_continue_state_transitions(rnc
);
1098 static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
1101 struct scic_sds_remote_node_context
*rnc
= object
;
1105 scic_sds_remote_node_context_state_handler_table
,
1106 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1109 scic_sds_remote_node_context_continue_state_transitions(rnc
);
1117 static void scic_sds_remote_node_context_await_suspension_state_enter(
1120 struct scic_sds_remote_node_context
*rnc
= object
;
1124 scic_sds_remote_node_context_state_handler_table
,
1125 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1129 /* --------------------------------------------------------------------------- */
1131 static const struct sci_base_state scic_sds_remote_node_context_state_table
[] = {
1132 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
] = {
1133 .enter_state
= scic_sds_remote_node_context_initial_state_enter
,
1135 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
] = {
1136 .enter_state
= scic_sds_remote_node_context_posting_state_enter
,
1138 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
] = {
1139 .enter_state
= scic_sds_remote_node_context_invalidating_state_enter
,
1141 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
] = {
1142 .enter_state
= scic_sds_remote_node_context_resuming_state_enter
,
1144 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
] = {
1145 .enter_state
= scic_sds_remote_node_context_ready_state_enter
,
1147 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
] = {
1148 .enter_state
= scic_sds_remote_node_context_tx_suspended_state_enter
,
1150 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
] = {
1151 .enter_state
= scic_sds_remote_node_context_tx_rx_suspended_state_enter
,
1153 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
] = {
1154 .enter_state
= scic_sds_remote_node_context_await_suspension_state_enter
,
1158 void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context
*rnc
,
1159 u16 remote_node_index
)
1161 memset(rnc
, 0, sizeof(struct scic_sds_remote_node_context
));
1163 rnc
->remote_node_index
= remote_node_index
;
1164 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
1166 sci_base_state_machine_construct(
1167 &rnc
->state_machine
,
1169 scic_sds_remote_node_context_state_table
,
1170 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1173 sci_base_state_machine_start(&rnc
->state_machine
);