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 "scic_sds_port.h"
59 #include "remote_device.h"
60 #include "remote_node_context.h"
62 #include "scu_event_codes.h"
63 #include "scu_task_context.h"
68 * @sci_rnc: The RNC for which the is posted request is being made.
70 * This method will return true if the RNC is not in the initial state. In all
71 * other states the RNC is considered active and this will return true. The
72 * destroy request of the state machine drives the RNC back to the initial
73 * state. If the state machine changes then this routine will also have to be
74 * changed. bool true if the state machine is not in the initial state false if
75 * the state machine is in the initial state
80 * @sci_rnc: The state of the remote node context object to check.
82 * This method will return true if the remote node context is in a READY state
83 * otherwise it will return false bool true if the remote node context is in
84 * the ready state. false if the remote node context is not in the ready state.
86 bool scic_sds_remote_node_context_is_ready(
87 struct scic_sds_remote_node_context
*sci_rnc
)
89 u32 current_state
= sci_base_state_machine_get_state(&sci_rnc
->state_machine
);
91 if (current_state
== SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
) {
100 * @sci_dev: The remote device to use to construct the RNC buffer.
101 * @rnc: The buffer into which the remote device data will be copied.
103 * This method will construct the RNC buffer for this remote device object. none
105 static void scic_sds_remote_node_context_construct_buffer(
106 struct scic_sds_remote_node_context
*sci_rnc
)
108 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
109 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
110 int rni
= sci_rnc
->remote_node_index
;
111 union scu_remote_node_context
*rnc
;
112 struct scic_sds_controller
*scic
;
115 scic
= scic_sds_remote_device_get_controller(sci_dev
);
116 rnc
= scic_sds_controller_get_remote_node_context_buffer(scic
, rni
);
118 memset(rnc
, 0, sizeof(union scu_remote_node_context
)
119 * scic_sds_remote_device_node_count(sci_dev
));
121 rnc
->ssp
.remote_node_index
= rni
;
122 rnc
->ssp
.remote_node_port_width
= sci_dev
->device_port_width
;
123 rnc
->ssp
.logical_port_index
= sci_dev
->owning_port
->physical_port_index
;
125 /* sas address is __be64, context ram format is __le64 */
126 sas_addr
= cpu_to_le64(SAS_ADDR(dev
->sas_addr
));
127 rnc
->ssp
.remote_sas_address_hi
= upper_32_bits(sas_addr
);
128 rnc
->ssp
.remote_sas_address_lo
= lower_32_bits(sas_addr
);
130 rnc
->ssp
.nexus_loss_timer_enable
= true;
131 rnc
->ssp
.check_bit
= false;
132 rnc
->ssp
.is_valid
= false;
133 rnc
->ssp
.is_remote_node_context
= true;
134 rnc
->ssp
.function_number
= 0;
136 rnc
->ssp
.arbitration_wait_time
= 0;
138 if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
139 rnc
->ssp
.connection_occupancy_timeout
=
140 scic
->user_parameters
.sds1
.stp_max_occupancy_timeout
;
141 rnc
->ssp
.connection_inactivity_timeout
=
142 scic
->user_parameters
.sds1
.stp_inactivity_timeout
;
144 rnc
->ssp
.connection_occupancy_timeout
=
145 scic
->user_parameters
.sds1
.ssp_max_occupancy_timeout
;
146 rnc
->ssp
.connection_inactivity_timeout
=
147 scic
->user_parameters
.sds1
.ssp_inactivity_timeout
;
150 rnc
->ssp
.initial_arbitration_wait_time
= 0;
152 /* Open Address Frame Parameters */
153 rnc
->ssp
.oaf_connection_rate
= sci_dev
->connection_rate
;
154 rnc
->ssp
.oaf_features
= 0;
155 rnc
->ssp
.oaf_source_zone_group
= 0;
156 rnc
->ssp
.oaf_more_compatibility_features
= 0;
163 * @callback_parameter:
165 * This method will setup the remote node context object so it will transition
166 * to its ready state. If the remote node context is already setup to
167 * transition to its final state then this function does nothing. none
169 static void scic_sds_remote_node_context_setup_to_resume(
170 struct scic_sds_remote_node_context
*sci_rnc
,
171 scics_sds_remote_node_context_callback callback
,
172 void *callback_parameter
)
174 if (sci_rnc
->destination_state
!= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
) {
175 sci_rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
;
176 sci_rnc
->user_callback
= callback
;
177 sci_rnc
->user_cookie
= callback_parameter
;
185 * @callback_parameter:
187 * This method will setup the remote node context object so it will transistion
188 * to its final state. none
190 static void scic_sds_remote_node_context_setup_to_destory(
191 struct scic_sds_remote_node_context
*sci_rnc
,
192 scics_sds_remote_node_context_callback callback
,
193 void *callback_parameter
)
195 sci_rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
;
196 sci_rnc
->user_callback
= callback
;
197 sci_rnc
->user_cookie
= callback_parameter
;
205 * This method will continue to resume a remote node context. This is used in
206 * the states where a resume is requested while a resume is in progress.
208 static enum sci_status
scic_sds_remote_node_context_continue_to_resume_handler(
209 struct scic_sds_remote_node_context
*sci_rnc
,
210 scics_sds_remote_node_context_callback callback
,
211 void *callback_parameter
)
213 if (sci_rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
) {
214 sci_rnc
->user_callback
= callback
;
215 sci_rnc
->user_cookie
= callback_parameter
;
220 return SCI_FAILURE_INVALID_STATE
;
223 /* --------------------------------------------------------------------------- */
225 static enum sci_status
scic_sds_remote_node_context_default_destruct_handler(
226 struct scic_sds_remote_node_context
*sci_rnc
,
227 scics_sds_remote_node_context_callback callback
,
228 void *callback_parameter
)
230 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
231 "%s: SCIC Remote Node Context 0x%p requested to stop while "
232 "in unexpected state %d\n",
235 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
238 * We have decided that the destruct request on the remote node context can not fail
239 * since it is either in the initial/destroyed state or is can be destroyed. */
243 static enum sci_status
scic_sds_remote_node_context_default_suspend_handler(
244 struct scic_sds_remote_node_context
*sci_rnc
,
246 scics_sds_remote_node_context_callback callback
,
247 void *callback_parameter
)
249 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
250 "%s: SCIC Remote Node Context 0x%p requested to suspend "
251 "while in wrong state %d\n",
254 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
256 return SCI_FAILURE_INVALID_STATE
;
259 static enum sci_status
scic_sds_remote_node_context_default_resume_handler(
260 struct scic_sds_remote_node_context
*sci_rnc
,
261 scics_sds_remote_node_context_callback callback
,
262 void *callback_parameter
)
264 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
265 "%s: SCIC Remote Node Context 0x%p requested to resume "
266 "while in wrong state %d\n",
269 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
271 return SCI_FAILURE_INVALID_STATE
;
274 static enum sci_status
scic_sds_remote_node_context_default_start_io_handler(
275 struct scic_sds_remote_node_context
*sci_rnc
,
276 struct scic_sds_request
*sci_req
)
278 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
279 "%s: SCIC Remote Node Context 0x%p requested to start io "
280 "0x%p while in wrong state %d\n",
284 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
286 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
;
289 static enum sci_status
scic_sds_remote_node_context_default_start_task_handler(
290 struct scic_sds_remote_node_context
*sci_rnc
,
291 struct scic_sds_request
*sci_req
)
293 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
294 "%s: SCIC Remote Node Context 0x%p requested to start "
295 "task 0x%p while in wrong state %d\n",
299 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
304 static enum sci_status
scic_sds_remote_node_context_default_event_handler(
305 struct scic_sds_remote_node_context
*sci_rnc
,
308 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
309 "%s: SCIC Remote Node Context 0x%p requested to process "
310 "event 0x%x while in wrong state %d\n",
314 sci_base_state_machine_get_state(&sci_rnc
->state_machine
));
316 return SCI_FAILURE_INVALID_STATE
;
321 * @sci_rnc: The rnc for which the task request is targeted.
322 * @sci_req: The request which is going to be started.
324 * This method determines if the task request can be started by the SCU
325 * hardware. When the RNC is in the ready state any task can be started.
326 * enum sci_status SCI_SUCCESS
328 static enum sci_status
scic_sds_remote_node_context_success_start_task_handler(
329 struct scic_sds_remote_node_context
*sci_rnc
,
330 struct scic_sds_request
*sci_req
)
339 * @callback_parameter:
341 * This method handles destruct calls from the various state handlers. The
342 * remote node context can be requested to destroy from any state. If there was
343 * a user callback it is always replaced with the request to destroy user
344 * callback. enum sci_status
346 static enum sci_status
scic_sds_remote_node_context_general_destruct_handler(
347 struct scic_sds_remote_node_context
*sci_rnc
,
348 scics_sds_remote_node_context_callback callback
,
349 void *callback_parameter
)
351 scic_sds_remote_node_context_setup_to_destory(
352 sci_rnc
, callback
, callback_parameter
355 sci_base_state_machine_change_state(
356 &sci_rnc
->state_machine
,
357 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
363 /* --------------------------------------------------------------------------- */
365 static enum sci_status
scic_sds_remote_node_context_initial_state_resume_handler(
366 struct scic_sds_remote_node_context
*sci_rnc
,
367 scics_sds_remote_node_context_callback callback
,
368 void *callback_parameter
)
370 if (sci_rnc
->remote_node_index
!= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
371 scic_sds_remote_node_context_setup_to_resume(
372 sci_rnc
, callback
, callback_parameter
375 scic_sds_remote_node_context_construct_buffer(sci_rnc
);
377 sci_base_state_machine_change_state(
378 &sci_rnc
->state_machine
,
379 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
385 return SCI_FAILURE_INVALID_STATE
;
388 /* --------------------------------------------------------------------------- */
390 static enum sci_status
scic_sds_remote_node_context_posting_state_event_handler(
391 struct scic_sds_remote_node_context
*sci_rnc
,
394 enum sci_status status
;
396 switch (scu_get_event_code(event_code
)) {
397 case SCU_EVENT_POST_RNC_COMPLETE
:
398 status
= SCI_SUCCESS
;
400 sci_base_state_machine_change_state(
401 &sci_rnc
->state_machine
,
402 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
407 status
= SCI_FAILURE
;
408 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
409 "%s: SCIC Remote Node Context 0x%p requested to "
410 "process unexpected event 0x%x while in posting "
421 /* --------------------------------------------------------------------------- */
423 static enum sci_status
scic_sds_remote_node_context_invalidating_state_destruct_handler(
424 struct scic_sds_remote_node_context
*sci_rnc
,
425 scics_sds_remote_node_context_callback callback
,
426 void *callback_parameter
)
428 scic_sds_remote_node_context_setup_to_destory(
429 sci_rnc
, callback
, callback_parameter
435 static enum sci_status
scic_sds_remote_node_context_invalidating_state_event_handler(
436 struct scic_sds_remote_node_context
*sci_rnc
,
439 enum sci_status status
;
441 if (scu_get_event_code(event_code
) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE
) {
442 status
= SCI_SUCCESS
;
444 if (sci_rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL
) {
445 sci_base_state_machine_change_state(
446 &sci_rnc
->state_machine
,
447 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
450 sci_base_state_machine_change_state(
451 &sci_rnc
->state_machine
,
452 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
456 switch (scu_get_event_type(event_code
)) {
457 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
458 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
460 * We really dont care if the hardware is going to suspend
461 * the device since it's being invalidated anyway */
462 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
463 "%s: SCIC Remote Node Context 0x%p was "
464 "suspeneded by hardware while being "
468 status
= SCI_SUCCESS
;
472 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
473 "%s: SCIC Remote Node Context 0x%p "
474 "requested to process event 0x%x while "
479 sci_base_state_machine_get_state(
480 &sci_rnc
->state_machine
));
481 status
= SCI_FAILURE
;
489 /* --------------------------------------------------------------------------- */
492 static enum sci_status
scic_sds_remote_node_context_resuming_state_event_handler(
493 struct scic_sds_remote_node_context
*sci_rnc
,
496 enum sci_status status
;
498 if (scu_get_event_code(event_code
) == SCU_EVENT_POST_RCN_RELEASE
) {
499 status
= SCI_SUCCESS
;
501 sci_base_state_machine_change_state(
502 &sci_rnc
->state_machine
,
503 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
506 switch (scu_get_event_type(event_code
)) {
507 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
508 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
510 * We really dont care if the hardware is going to suspend
511 * the device since it's being resumed anyway */
512 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
513 "%s: SCIC Remote Node Context 0x%p was "
514 "suspeneded by hardware while being resumed.\n",
517 status
= SCI_SUCCESS
;
521 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
522 "%s: SCIC Remote Node Context 0x%p requested "
523 "to process event 0x%x while in state %d.\n",
527 sci_base_state_machine_get_state(
528 &sci_rnc
->state_machine
));
529 status
= SCI_FAILURE
;
537 /* --------------------------------------------------------------------------- */
541 * @sci_rnc: The remote node context object being suspended.
542 * @callback: The callback when the suspension is complete.
543 * @callback_parameter: The parameter that is to be passed into the callback.
545 * This method will handle the suspend requests from the ready state.
548 static enum sci_status
scic_sds_remote_node_context_ready_state_suspend_handler(
549 struct scic_sds_remote_node_context
*sci_rnc
,
551 scics_sds_remote_node_context_callback callback
,
552 void *callback_parameter
)
554 sci_rnc
->user_callback
= callback
;
555 sci_rnc
->user_cookie
= callback_parameter
;
556 sci_rnc
->suspension_code
= suspend_type
;
558 if (suspend_type
== SCI_SOFTWARE_SUSPENSION
) {
559 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc
),
560 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX
);
563 sci_base_state_machine_change_state(
564 &sci_rnc
->state_machine
,
565 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
573 * @sci_rnc: The rnc for which the io request is targeted.
574 * @sci_req: The request which is going to be started.
576 * This method determines if the io request can be started by the SCU hardware.
577 * When the RNC is in the ready state any io request can be started. enum sci_status
580 static enum sci_status
scic_sds_remote_node_context_ready_state_start_io_handler(
581 struct scic_sds_remote_node_context
*sci_rnc
,
582 struct scic_sds_request
*sci_req
)
588 static enum sci_status
scic_sds_remote_node_context_ready_state_event_handler(
589 struct scic_sds_remote_node_context
*sci_rnc
,
592 enum sci_status status
;
594 switch (scu_get_event_type(event_code
)) {
595 case SCU_EVENT_TL_RNC_SUSPEND_TX
:
596 sci_base_state_machine_change_state(
597 &sci_rnc
->state_machine
,
598 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
601 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
602 status
= SCI_SUCCESS
;
605 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX
:
606 sci_base_state_machine_change_state(
607 &sci_rnc
->state_machine
,
608 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
611 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
612 status
= SCI_SUCCESS
;
616 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
617 "%s: SCIC Remote Node Context 0x%p requested to "
618 "process event 0x%x while in state %d.\n",
622 sci_base_state_machine_get_state(
623 &sci_rnc
->state_machine
));
625 status
= SCI_FAILURE
;
632 /* --------------------------------------------------------------------------- */
634 static enum sci_status
scic_sds_remote_node_context_tx_suspended_state_resume_handler(
635 struct scic_sds_remote_node_context
*sci_rnc
,
636 scics_sds_remote_node_context_callback callback
,
637 void *callback_parameter
)
639 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
640 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
641 enum sci_status status
= SCI_SUCCESS
;
643 scic_sds_remote_node_context_setup_to_resume(sci_rnc
, callback
,
646 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
647 if (dev
->dev_type
== SAS_END_DEV
|| dev_is_expander(dev
))
648 sci_base_state_machine_change_state(&sci_rnc
->state_machine
,
649 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
);
650 else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
651 if (sci_dev
->is_direct_attached
) {
652 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
653 sci_base_state_machine_change_state(
654 &sci_rnc
->state_machine
,
655 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
);
657 sci_base_state_machine_change_state(
658 &sci_rnc
->state_machine
,
659 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
);
662 status
= SCI_FAILURE
;
669 * @sci_rnc: The remote node context which is to receive the task request.
670 * @sci_req: The task request to be transmitted to to the remote target
673 * This method will report a success or failure attempt to start a new task
674 * request to the hardware. Since all task requests are sent on the high
675 * priority queue they can be sent when the RCN is in a TX suspend state.
676 * enum sci_status SCI_SUCCESS
678 static enum sci_status
scic_sds_remote_node_context_suspended_start_task_handler(
679 struct scic_sds_remote_node_context
*sci_rnc
,
680 struct scic_sds_request
*sci_req
)
682 scic_sds_remote_node_context_resume(sci_rnc
, NULL
, NULL
);
687 /* --------------------------------------------------------------------------- */
689 static enum sci_status
scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
690 struct scic_sds_remote_node_context
*sci_rnc
,
691 scics_sds_remote_node_context_callback callback
,
692 void *callback_parameter
)
694 scic_sds_remote_node_context_setup_to_resume(
695 sci_rnc
, callback
, callback_parameter
698 sci_base_state_machine_change_state(
699 &sci_rnc
->state_machine
,
700 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
703 return SCI_FAILURE_INVALID_STATE
;
706 /* --------------------------------------------------------------------------- */
713 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_resume_handler(
714 struct scic_sds_remote_node_context
*sci_rnc
,
715 scics_sds_remote_node_context_callback callback
,
716 void *callback_parameter
)
718 scic_sds_remote_node_context_setup_to_resume(
719 sci_rnc
, callback
, callback_parameter
727 * @sci_rnc: The remote node context which is to receive the task request.
728 * @sci_req: The task request to be transmitted to to the remote target
731 * This method will report a success or failure attempt to start a new task
732 * request to the hardware. Since all task requests are sent on the high
733 * priority queue they can be sent when the RCN is in a TX suspend state.
734 * enum sci_status SCI_SUCCESS
736 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_start_task_handler(
737 struct scic_sds_remote_node_context
*sci_rnc
,
738 struct scic_sds_request
*sci_req
)
743 static enum sci_status
scic_sds_remote_node_context_await_suspension_state_event_handler(
744 struct scic_sds_remote_node_context
*sci_rnc
,
747 enum sci_status status
;
749 switch (scu_get_event_type(event_code
)) {
750 case SCU_EVENT_TL_RNC_SUSPEND_TX
:
751 sci_base_state_machine_change_state(
752 &sci_rnc
->state_machine
,
753 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
756 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
757 status
= SCI_SUCCESS
;
760 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX
:
761 sci_base_state_machine_change_state(
762 &sci_rnc
->state_machine
,
763 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
766 sci_rnc
->suspension_code
= scu_get_event_specifier(event_code
);
767 status
= SCI_SUCCESS
;
771 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc
)),
772 "%s: SCIC Remote Node Context 0x%p requested to "
773 "process event 0x%x while in state %d.\n",
777 sci_base_state_machine_get_state(
778 &sci_rnc
->state_machine
));
780 status
= SCI_FAILURE
;
787 /* --------------------------------------------------------------------------- */
789 static struct scic_sds_remote_node_context_handlers
790 scic_sds_remote_node_context_state_handler_table
[] = {
791 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
] = {
792 .destruct_handler
= scic_sds_remote_node_context_default_destruct_handler
,
793 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
794 .resume_handler
= scic_sds_remote_node_context_initial_state_resume_handler
,
795 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
796 .start_task_handler
= scic_sds_remote_node_context_default_start_task_handler
,
797 .event_handler
= scic_sds_remote_node_context_default_event_handler
799 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
] = {
800 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
801 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
802 .resume_handler
= scic_sds_remote_node_context_continue_to_resume_handler
,
803 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
804 .start_task_handler
= scic_sds_remote_node_context_default_start_task_handler
,
805 .event_handler
= scic_sds_remote_node_context_posting_state_event_handler
807 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
] = {
808 .destruct_handler
= scic_sds_remote_node_context_invalidating_state_destruct_handler
,
809 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
810 .resume_handler
= scic_sds_remote_node_context_continue_to_resume_handler
,
811 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
812 .start_task_handler
= scic_sds_remote_node_context_default_start_task_handler
,
813 .event_handler
= scic_sds_remote_node_context_invalidating_state_event_handler
815 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
] = {
816 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
817 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
818 .resume_handler
= scic_sds_remote_node_context_continue_to_resume_handler
,
819 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
820 .start_task_handler
= scic_sds_remote_node_context_success_start_task_handler
,
821 .event_handler
= scic_sds_remote_node_context_resuming_state_event_handler
823 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
] = {
824 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
825 .suspend_handler
= scic_sds_remote_node_context_ready_state_suspend_handler
,
826 .resume_handler
= scic_sds_remote_node_context_default_resume_handler
,
827 .start_io_handler
= scic_sds_remote_node_context_ready_state_start_io_handler
,
828 .start_task_handler
= scic_sds_remote_node_context_success_start_task_handler
,
829 .event_handler
= scic_sds_remote_node_context_ready_state_event_handler
831 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
] = {
832 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
833 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
834 .resume_handler
= scic_sds_remote_node_context_tx_suspended_state_resume_handler
,
835 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
836 .start_task_handler
= scic_sds_remote_node_context_suspended_start_task_handler
,
837 .event_handler
= scic_sds_remote_node_context_default_event_handler
839 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
] = {
840 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
841 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
842 .resume_handler
= scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler
,
843 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
844 .start_task_handler
= scic_sds_remote_node_context_suspended_start_task_handler
,
845 .event_handler
= scic_sds_remote_node_context_default_event_handler
847 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
] = {
848 .destruct_handler
= scic_sds_remote_node_context_general_destruct_handler
,
849 .suspend_handler
= scic_sds_remote_node_context_default_suspend_handler
,
850 .resume_handler
= scic_sds_remote_node_context_await_suspension_state_resume_handler
,
851 .start_io_handler
= scic_sds_remote_node_context_default_start_io_handler
,
852 .start_task_handler
= scic_sds_remote_node_context_await_suspension_state_start_task_handler
,
853 .event_handler
= scic_sds_remote_node_context_await_suspension_state_event_handler
858 * *****************************************************************************
859 * * REMOTE NODE CONTEXT PRIVATE METHODS
860 * ***************************************************************************** */
865 * This method just calls the user callback function and then resets the
868 static void scic_sds_remote_node_context_notify_user(
869 struct scic_sds_remote_node_context
*rnc
)
871 if (rnc
->user_callback
!= NULL
) {
872 (*rnc
->user_callback
)(rnc
->user_cookie
);
874 rnc
->user_callback
= NULL
;
875 rnc
->user_cookie
= NULL
;
882 * This method will continue the remote node context state machine by
883 * requesting to resume the remote node context state machine from its current
886 static void scic_sds_remote_node_context_continue_state_transitions(
887 struct scic_sds_remote_node_context
*rnc
)
889 if (rnc
->destination_state
== SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY
) {
890 rnc
->state_handlers
->resume_handler(
891 rnc
, rnc
->user_callback
, rnc
->user_cookie
898 * @sci_rnc: The remote node context object that is to be validated.
900 * This method will mark the rnc buffer as being valid and post the request to
903 static void scic_sds_remote_node_context_validate_context_buffer(
904 struct scic_sds_remote_node_context
*sci_rnc
)
906 struct scic_sds_remote_device
*sci_dev
= rnc_to_dev(sci_rnc
);
907 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
908 union scu_remote_node_context
*rnc_buffer
;
910 rnc_buffer
= scic_sds_controller_get_remote_node_context_buffer(
911 scic_sds_remote_device_get_controller(sci_dev
),
912 sci_rnc
->remote_node_index
915 rnc_buffer
->ssp
.is_valid
= true;
917 if (!sci_dev
->is_direct_attached
&&
918 (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))) {
919 scic_sds_remote_device_post_request(sci_dev
,
920 SCU_CONTEXT_COMMAND_POST_RNC_96
);
922 scic_sds_remote_device_post_request(sci_dev
, SCU_CONTEXT_COMMAND_POST_RNC_32
);
924 if (sci_dev
->is_direct_attached
) {
925 scic_sds_port_setup_transports(sci_dev
->owning_port
,
926 sci_rnc
->remote_node_index
);
933 * @sci_rnc: The remote node context object that is to be invalidated.
935 * This method will update the RNC buffer and post the invalidate request. none
937 static void scic_sds_remote_node_context_invalidate_context_buffer(
938 struct scic_sds_remote_node_context
*sci_rnc
)
940 union scu_remote_node_context
*rnc_buffer
;
942 rnc_buffer
= scic_sds_controller_get_remote_node_context_buffer(
943 scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc
)),
944 sci_rnc
->remote_node_index
);
946 rnc_buffer
->ssp
.is_valid
= false;
948 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc
),
949 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
);
953 * *****************************************************************************
954 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
955 * ***************************************************************************** */
962 static void scic_sds_remote_node_context_initial_state_enter(void *object
)
964 struct scic_sds_remote_node_context
*rnc
= object
;
968 scic_sds_remote_node_context_state_handler_table
,
969 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
973 * Check to see if we have gotten back to the initial state because someone
974 * requested to destroy the remote node context object. */
976 rnc
->state_machine
.previous_state_id
977 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
979 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
981 scic_sds_remote_node_context_notify_user(rnc
);
990 static void scic_sds_remote_node_context_posting_state_enter(void *object
)
992 struct scic_sds_remote_node_context
*sci_rnc
= object
;
996 scic_sds_remote_node_context_state_handler_table
,
997 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
1000 scic_sds_remote_node_context_validate_context_buffer(sci_rnc
);
1008 static void scic_sds_remote_node_context_invalidating_state_enter(void *object
)
1010 struct scic_sds_remote_node_context
*rnc
= object
;
1014 scic_sds_remote_node_context_state_handler_table
,
1015 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1018 scic_sds_remote_node_context_invalidate_context_buffer(rnc
);
1026 static void scic_sds_remote_node_context_resuming_state_enter(void *object
)
1028 struct scic_sds_remote_node_context
*rnc
= object
;
1029 struct scic_sds_remote_device
*sci_dev
;
1030 struct domain_device
*dev
;
1032 sci_dev
= rnc_to_dev(rnc
);
1033 dev
= sci_dev_to_domain(sci_dev
);
1037 scic_sds_remote_node_context_state_handler_table
,
1038 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1042 * For direct attached SATA devices we need to clear the TLCR
1043 * NCQ to TCi tag mapping on the phy and in cases where we
1044 * resume because of a target reset we also need to update
1045 * the STPTLDARNI register with the RNi of the device
1047 if ((dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) &&
1048 sci_dev
->is_direct_attached
)
1049 scic_sds_port_setup_transports(sci_dev
->owning_port
,
1050 rnc
->remote_node_index
);
1052 scic_sds_remote_device_post_request(sci_dev
, SCU_CONTEXT_COMMAND_POST_RNC_RESUME
);
1060 static void scic_sds_remote_node_context_ready_state_enter(void *object
)
1062 struct scic_sds_remote_node_context
*rnc
= object
;
1066 scic_sds_remote_node_context_state_handler_table
,
1067 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1070 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
1072 if (rnc
->user_callback
!= NULL
) {
1073 scic_sds_remote_node_context_notify_user(rnc
);
1082 static void scic_sds_remote_node_context_tx_suspended_state_enter(void *object
)
1084 struct scic_sds_remote_node_context
*rnc
= object
;
1088 scic_sds_remote_node_context_state_handler_table
,
1089 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1092 scic_sds_remote_node_context_continue_state_transitions(rnc
);
1100 static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
1103 struct scic_sds_remote_node_context
*rnc
= object
;
1107 scic_sds_remote_node_context_state_handler_table
,
1108 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1111 scic_sds_remote_node_context_continue_state_transitions(rnc
);
1119 static void scic_sds_remote_node_context_await_suspension_state_enter(
1122 struct scic_sds_remote_node_context
*rnc
= object
;
1126 scic_sds_remote_node_context_state_handler_table
,
1127 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1131 /* --------------------------------------------------------------------------- */
1133 static const struct sci_base_state scic_sds_remote_node_context_state_table
[] = {
1134 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
] = {
1135 .enter_state
= scic_sds_remote_node_context_initial_state_enter
,
1137 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
] = {
1138 .enter_state
= scic_sds_remote_node_context_posting_state_enter
,
1140 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
] = {
1141 .enter_state
= scic_sds_remote_node_context_invalidating_state_enter
,
1143 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
] = {
1144 .enter_state
= scic_sds_remote_node_context_resuming_state_enter
,
1146 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
] = {
1147 .enter_state
= scic_sds_remote_node_context_ready_state_enter
,
1149 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
] = {
1150 .enter_state
= scic_sds_remote_node_context_tx_suspended_state_enter
,
1152 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
] = {
1153 .enter_state
= scic_sds_remote_node_context_tx_rx_suspended_state_enter
,
1155 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
] = {
1156 .enter_state
= scic_sds_remote_node_context_await_suspension_state_enter
,
1160 void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context
*rnc
,
1161 u16 remote_node_index
)
1163 memset(rnc
, 0, sizeof(struct scic_sds_remote_node_context
));
1165 rnc
->remote_node_index
= remote_node_index
;
1166 rnc
->destination_state
= SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED
;
1168 sci_base_state_machine_construct(
1169 &rnc
->state_machine
,
1171 scic_sds_remote_node_context_state_table
,
1172 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1175 sci_base_state_machine_start(&rnc
->state_machine
);