blob: e83657d554b773906a5c298c0b2bdb2480b2cb09 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55
56#include "sci_base_state_machine.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070057#include "scic_sds_controller.h"
58#include "scic_sds_port.h"
Dan Williams88f3b622011-04-22 19:18:03 -070059#include "remote_device.h"
60#include "remote_node_context.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070061#include "sci_environment.h"
62#include "sci_util.h"
63#include "scu_event_codes.h"
64#include "scu_task_context.h"
65
Dan Williams6f231dd2011-07-02 22:56:22 -070066
67/**
68 *
Dave Jiange2023b82011-04-21 05:34:49 +000069 * @sci_rnc: The RNC for which the is posted request is being made.
Dan Williams6f231dd2011-07-02 22:56:22 -070070 *
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
77 */
78
79/**
80 *
Dave Jiange2023b82011-04-21 05:34:49 +000081 * @sci_rnc: The state of the remote node context object to check.
Dan Williams6f231dd2011-07-02 22:56:22 -070082 *
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.
86 */
87bool scic_sds_remote_node_context_is_ready(
Dave Jiange2023b82011-04-21 05:34:49 +000088 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -070089{
Dave Jiange2023b82011-04-21 05:34:49 +000090 u32 current_state = sci_base_state_machine_get_state(&sci_rnc->state_machine);
Dan Williams6f231dd2011-07-02 22:56:22 -070091
92 if (current_state == SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE) {
93 return true;
94 }
95
96 return false;
97}
98
99/**
100 *
Dave Jiange2023b82011-04-21 05:34:49 +0000101 * @sci_dev: The remote device to use to construct the RNC buffer.
Dan Williams6f231dd2011-07-02 22:56:22 -0700102 * @rnc: The buffer into which the remote device data will be copied.
103 *
104 * This method will construct the RNC buffer for this remote device object. none
105 */
Dan Williams35173d52011-03-26 16:43:01 -0700106static void scic_sds_remote_node_context_construct_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000107 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700108{
Dan Williams96143952011-04-19 18:35:58 -0700109 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -0700110 struct domain_device *dev = sci_dev_to_domain(sci_dev);
111 union scu_remote_node_context *rnc;
Dave Jiange2023b82011-04-21 05:34:49 +0000112 struct scic_sds_controller *scic;
Dan Williamsa3d568f02011-04-26 09:41:52 -0700113 __le64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -0700114
Dan Williams96143952011-04-19 18:35:58 -0700115 scic = scic_sds_remote_device_get_controller(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700116
117 rnc = scic_sds_controller_get_remote_node_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000118 scic, sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700119
Dan Williams96143952011-04-19 18:35:58 -0700120 memset(rnc, 0, sizeof(union scu_remote_node_context)
121 * scic_sds_remote_device_node_count(sci_dev));
Dan Williams6f231dd2011-07-02 22:56:22 -0700122
Dave Jiange2023b82011-04-21 05:34:49 +0000123 rnc->ssp.remote_node_index = sci_rnc->remote_node_index;
Dan Williams96143952011-04-19 18:35:58 -0700124 rnc->ssp.remote_node_port_width = sci_dev->device_port_width;
Dan Williams6f231dd2011-07-02 22:56:22 -0700125 rnc->ssp.logical_port_index =
Dan Williams96143952011-04-19 18:35:58 -0700126 scic_sds_remote_device_get_port_index(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700127
Dan Williamsa3d568f02011-04-26 09:41:52 -0700128 /* 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);
Dan Williams6f231dd2011-07-02 22:56:22 -0700132
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;
138
139 rnc->ssp.arbitration_wait_time = 0;
140
Dan Williamsa1a113b2011-04-21 18:44:45 -0700141 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700142 rnc->ssp.connection_occupancy_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000143 scic->user_parameters.sds1.stp_max_occupancy_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700144 rnc->ssp.connection_inactivity_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000145 scic->user_parameters.sds1.stp_inactivity_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700146 } else {
147 rnc->ssp.connection_occupancy_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000148 scic->user_parameters.sds1.ssp_max_occupancy_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700149 rnc->ssp.connection_inactivity_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000150 scic->user_parameters.sds1.ssp_inactivity_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700151 }
152
153 rnc->ssp.initial_arbitration_wait_time = 0;
154
155 /* Open Address Frame Parameters */
Dan Williams96143952011-04-19 18:35:58 -0700156 rnc->ssp.oaf_connection_rate = sci_dev->connection_rate;
Dan Williams6f231dd2011-07-02 22:56:22 -0700157 rnc->ssp.oaf_features = 0;
158 rnc->ssp.oaf_source_zone_group = 0;
159 rnc->ssp.oaf_more_compatibility_features = 0;
160}
161
162/**
163 *
Dave Jiange2023b82011-04-21 05:34:49 +0000164 * @sci_rnc:
165 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700166 * @callback_parameter:
167 *
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
171 */
172static void scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000173 struct scic_sds_remote_node_context *sci_rnc,
174 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700175 void *callback_parameter)
176{
Dave Jiange2023b82011-04-21 05:34:49 +0000177 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;
Dan Williams6f231dd2011-07-02 22:56:22 -0700181 }
182}
183
184/**
185 *
Dave Jiange2023b82011-04-21 05:34:49 +0000186 * @sci_rnc:
187 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700188 * @callback_parameter:
189 *
190 * This method will setup the remote node context object so it will transistion
191 * to its final state. none
192 */
193static void scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000194 struct scic_sds_remote_node_context *sci_rnc,
195 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700196 void *callback_parameter)
197{
Dave Jiange2023b82011-04-21 05:34:49 +0000198 sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL;
199 sci_rnc->user_callback = callback;
200 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700201}
202
203/**
204 *
Dave Jiange2023b82011-04-21 05:34:49 +0000205 * @sci_rnc:
206 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700207 *
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.
210 */
211static enum sci_status scic_sds_remote_node_context_continue_to_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000212 struct scic_sds_remote_node_context *sci_rnc,
213 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700214 void *callback_parameter)
215{
Dave Jiange2023b82011-04-21 05:34:49 +0000216 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;
Dan Williams6f231dd2011-07-02 22:56:22 -0700219
220 return SCI_SUCCESS;
221 }
222
223 return SCI_FAILURE_INVALID_STATE;
224}
225
226/* --------------------------------------------------------------------------- */
227
228static enum sci_status scic_sds_remote_node_context_default_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000229 struct scic_sds_remote_node_context *sci_rnc,
230 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700231 void *callback_parameter)
232{
Dan Williams96143952011-04-19 18:35:58 -0700233 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700234 "%s: SCIC Remote Node Context 0x%p requested to stop while "
235 "in unexpected state %d\n",
236 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000237 sci_rnc,
238 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700239
240 /*
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. */
243 return SCI_SUCCESS;
244}
245
246static enum sci_status scic_sds_remote_node_context_default_suspend_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000247 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700248 u32 suspend_type,
Dave Jiange2023b82011-04-21 05:34:49 +0000249 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700250 void *callback_parameter)
251{
Dan Williams96143952011-04-19 18:35:58 -0700252 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700253 "%s: SCIC Remote Node Context 0x%p requested to suspend "
254 "while in wrong state %d\n",
255 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000256 sci_rnc,
257 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700258
259 return SCI_FAILURE_INVALID_STATE;
260}
261
262static enum sci_status scic_sds_remote_node_context_default_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000263 struct scic_sds_remote_node_context *sci_rnc,
264 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700265 void *callback_parameter)
266{
Dan Williams96143952011-04-19 18:35:58 -0700267 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700268 "%s: SCIC Remote Node Context 0x%p requested to resume "
269 "while in wrong state %d\n",
270 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000271 sci_rnc,
272 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700273
274 return SCI_FAILURE_INVALID_STATE;
275}
276
277static enum sci_status scic_sds_remote_node_context_default_start_io_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000278 struct scic_sds_remote_node_context *sci_rnc,
279 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700280{
Dan Williams96143952011-04-19 18:35:58 -0700281 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700282 "%s: SCIC Remote Node Context 0x%p requested to start io "
283 "0x%p while in wrong state %d\n",
284 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000285 sci_rnc,
286 sci_req,
287 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700288
289 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
290}
291
292static enum sci_status scic_sds_remote_node_context_default_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000293 struct scic_sds_remote_node_context *sci_rnc,
294 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700295{
Dan Williams96143952011-04-19 18:35:58 -0700296 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700297 "%s: SCIC Remote Node Context 0x%p requested to start "
298 "task 0x%p while in wrong state %d\n",
299 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000300 sci_rnc,
301 sci_req,
302 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700303
304 return SCI_FAILURE;
305}
306
307static enum sci_status scic_sds_remote_node_context_default_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000308 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700309 u32 event_code)
310{
Dan Williams96143952011-04-19 18:35:58 -0700311 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700312 "%s: SCIC Remote Node Context 0x%p requested to process "
313 "event 0x%x while in wrong state %d\n",
314 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000315 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700316 event_code,
Dave Jiange2023b82011-04-21 05:34:49 +0000317 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700318
319 return SCI_FAILURE_INVALID_STATE;
320}
321
322/**
323 *
Dave Jiange2023b82011-04-21 05:34:49 +0000324 * @sci_rnc: The rnc for which the task request is targeted.
325 * @sci_req: The request which is going to be started.
Dan Williams6f231dd2011-07-02 22:56:22 -0700326 *
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
330 */
331static enum sci_status scic_sds_remote_node_context_success_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000332 struct scic_sds_remote_node_context *sci_rnc,
333 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700334{
335 return SCI_SUCCESS;
336}
337
338/**
339 *
Dave Jiange2023b82011-04-21 05:34:49 +0000340 * @sci_rnc:
341 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700342 * @callback_parameter:
343 *
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
348 */
349static enum sci_status scic_sds_remote_node_context_general_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000350 struct scic_sds_remote_node_context *sci_rnc,
351 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700352 void *callback_parameter)
353{
354 scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000355 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700356 );
357
358 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000359 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700360 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
361 );
362
363 return SCI_SUCCESS;
364}
365
366/* --------------------------------------------------------------------------- */
367
368static enum sci_status scic_sds_remote_node_context_initial_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000369 struct scic_sds_remote_node_context *sci_rnc,
370 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700371 void *callback_parameter)
372{
Dave Jiange2023b82011-04-21 05:34:49 +0000373 if (sci_rnc->remote_node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700374 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000375 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700376 );
377
Dave Jiange2023b82011-04-21 05:34:49 +0000378 scic_sds_remote_node_context_construct_buffer(sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700379
380 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000381 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700382 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
383 );
384
385 return SCI_SUCCESS;
386 }
387
388 return SCI_FAILURE_INVALID_STATE;
389}
390
391/* --------------------------------------------------------------------------- */
392
393static enum sci_status scic_sds_remote_node_context_posting_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000394 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700395 u32 event_code)
396{
397 enum sci_status status;
398
399 switch (scu_get_event_code(event_code)) {
400 case SCU_EVENT_POST_RNC_COMPLETE:
401 status = SCI_SUCCESS;
402
403 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000404 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700405 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
406 );
407 break;
408
409 default:
410 status = SCI_FAILURE;
Dan Williams96143952011-04-19 18:35:58 -0700411 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700412 "%s: SCIC Remote Node Context 0x%p requested to "
413 "process unexpected event 0x%x while in posting "
414 "state\n",
415 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000416 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700417 event_code);
418 break;
419 }
420
421 return status;
422}
423
424/* --------------------------------------------------------------------------- */
425
426static enum sci_status scic_sds_remote_node_context_invalidating_state_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000427 struct scic_sds_remote_node_context *sci_rnc,
428 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700429 void *callback_parameter)
430{
431 scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000432 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700433 );
434
435 return SCI_SUCCESS;
436}
437
438static enum sci_status scic_sds_remote_node_context_invalidating_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000439 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700440 u32 event_code)
441{
442 enum sci_status status;
443
444 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
445 status = SCI_SUCCESS;
446
Dave Jiange2023b82011-04-21 05:34:49 +0000447 if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700448 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000449 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700450 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
451 );
452 } else {
453 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000454 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700455 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
456 );
457 }
458 } else {
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:
462 /*
463 * We really dont care if the hardware is going to suspend
464 * the device since it's being invalidated anyway */
Dan Williams96143952011-04-19 18:35:58 -0700465 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700466 "%s: SCIC Remote Node Context 0x%p was "
467 "suspeneded by hardware while being "
468 "invalidated.\n",
469 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000470 sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700471 status = SCI_SUCCESS;
472 break;
473
474 default:
Dan Williams96143952011-04-19 18:35:58 -0700475 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700476 "%s: SCIC Remote Node Context 0x%p "
477 "requested to process event 0x%x while "
478 "in state %d.\n",
479 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000480 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700481 event_code,
482 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000483 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700484 status = SCI_FAILURE;
485 break;
486 }
487 }
488
489 return status;
490}
491
492/* --------------------------------------------------------------------------- */
493
494
495static enum sci_status scic_sds_remote_node_context_resuming_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000496 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700497 u32 event_code)
498{
499 enum sci_status status;
500
501 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
502 status = SCI_SUCCESS;
503
504 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000505 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700506 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
507 );
508 } else {
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:
512 /*
513 * We really dont care if the hardware is going to suspend
514 * the device since it's being resumed anyway */
Dan Williams96143952011-04-19 18:35:58 -0700515 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700516 "%s: SCIC Remote Node Context 0x%p was "
517 "suspeneded by hardware while being resumed.\n",
518 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000519 sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700520 status = SCI_SUCCESS;
521 break;
522
523 default:
Dan Williams96143952011-04-19 18:35:58 -0700524 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700525 "%s: SCIC Remote Node Context 0x%p requested "
526 "to process event 0x%x while in state %d.\n",
527 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000528 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700529 event_code,
530 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000531 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700532 status = SCI_FAILURE;
533 break;
534 }
535 }
536
537 return status;
538}
539
540/* --------------------------------------------------------------------------- */
541
542/**
543 *
Dave Jiange2023b82011-04-21 05:34:49 +0000544 * @sci_rnc: The remote node context object being suspended.
545 * @callback: The callback when the suspension is complete.
Dan Williams6f231dd2011-07-02 22:56:22 -0700546 * @callback_parameter: The parameter that is to be passed into the callback.
547 *
548 * This method will handle the suspend requests from the ready state.
549 * SCI_SUCCESS
550 */
551static enum sci_status scic_sds_remote_node_context_ready_state_suspend_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000552 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700553 u32 suspend_type,
Dave Jiange2023b82011-04-21 05:34:49 +0000554 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700555 void *callback_parameter)
556{
Dave Jiange2023b82011-04-21 05:34:49 +0000557 sci_rnc->user_callback = callback;
558 sci_rnc->user_cookie = callback_parameter;
559 sci_rnc->suspension_code = suspend_type;
Dan Williams6f231dd2011-07-02 22:56:22 -0700560
561 if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
Dan Williams96143952011-04-19 18:35:58 -0700562 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc),
563 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX);
Dan Williams6f231dd2011-07-02 22:56:22 -0700564 }
565
566 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000567 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700568 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
569 );
570
571 return SCI_SUCCESS;
572}
573
574/**
575 *
Dave Jiange2023b82011-04-21 05:34:49 +0000576 * @sci_rnc: The rnc for which the io request is targeted.
577 * @sci_req: The request which is going to be started.
Dan Williams6f231dd2011-07-02 22:56:22 -0700578 *
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
581 * SCI_SUCCESS
582 */
583static enum sci_status scic_sds_remote_node_context_ready_state_start_io_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000584 struct scic_sds_remote_node_context *sci_rnc,
585 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700586{
587 return SCI_SUCCESS;
588}
589
590
591static enum sci_status scic_sds_remote_node_context_ready_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000592 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700593 u32 event_code)
594{
595 enum sci_status status;
596
597 switch (scu_get_event_type(event_code)) {
598 case SCU_EVENT_TL_RNC_SUSPEND_TX:
599 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000600 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700601 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
602 );
603
Dave Jiange2023b82011-04-21 05:34:49 +0000604 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700605 status = SCI_SUCCESS;
606 break;
607
608 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
609 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000610 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700611 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
612 );
613
Dave Jiange2023b82011-04-21 05:34:49 +0000614 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700615 status = SCI_SUCCESS;
616 break;
617
618 default:
Dan Williams96143952011-04-19 18:35:58 -0700619 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700620 "%s: SCIC Remote Node Context 0x%p requested to "
621 "process event 0x%x while in state %d.\n",
622 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000623 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700624 event_code,
625 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000626 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700627
628 status = SCI_FAILURE;
629 break;
630 }
631
632 return status;
633}
634
635/* --------------------------------------------------------------------------- */
636
637static enum sci_status scic_sds_remote_node_context_tx_suspended_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000638 struct scic_sds_remote_node_context *sci_rnc,
639 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700640 void *callback_parameter)
641{
Dan Williamsa1a113b2011-04-21 18:44:45 -0700642 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;
Dan Williams6f231dd2011-07-02 22:56:22 -0700645
Dan Williamsa1a113b2011-04-21 18:44:45 -0700646 scic_sds_remote_node_context_setup_to_resume(sci_rnc, callback,
647 callback_parameter);
Dan Williams6f231dd2011-07-02 22:56:22 -0700648
649 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
Dan Williamsa1a113b2011-04-21 18:44:45 -0700650 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) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700655 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700656 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000657 &sci_rnc->state_machine,
Dan Williamsa1a113b2011-04-21 18:44:45 -0700658 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700659 } else {
660 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000661 &sci_rnc->state_machine,
Dan Williamsa1a113b2011-04-21 18:44:45 -0700662 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700663 }
Dan Williamsa1a113b2011-04-21 18:44:45 -0700664 } else
Dan Williams6f231dd2011-07-02 22:56:22 -0700665 status = SCI_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700666
667 return status;
668}
669
670/**
671 *
Dave Jiange2023b82011-04-21 05:34:49 +0000672 * @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
Dan Williams6f231dd2011-07-02 22:56:22 -0700674 * device.
675 *
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
680 */
681static enum sci_status scic_sds_remote_node_context_suspended_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000682 struct scic_sds_remote_node_context *sci_rnc,
683 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700684{
Dave Jiange2023b82011-04-21 05:34:49 +0000685 scic_sds_remote_node_context_resume(sci_rnc, NULL, NULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700686
687 return SCI_SUCCESS;
688}
689
690/* --------------------------------------------------------------------------- */
691
692static enum sci_status scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000693 struct scic_sds_remote_node_context *sci_rnc,
694 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700695 void *callback_parameter)
696{
697 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000698 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700699 );
700
701 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000702 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700703 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
704 );
705
706 return SCI_FAILURE_INVALID_STATE;
707}
708
709/* --------------------------------------------------------------------------- */
710
711/**
712 *
713 *
714 *
715 */
716static enum sci_status scic_sds_remote_node_context_await_suspension_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000717 struct scic_sds_remote_node_context *sci_rnc,
718 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700719 void *callback_parameter)
720{
721 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000722 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700723 );
724
725 return SCI_SUCCESS;
726}
727
728/**
729 *
Dave Jiange2023b82011-04-21 05:34:49 +0000730 * @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
Dan Williams6f231dd2011-07-02 22:56:22 -0700732 * device.
733 *
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
738 */
739static enum sci_status scic_sds_remote_node_context_await_suspension_state_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000740 struct scic_sds_remote_node_context *sci_rnc,
741 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700742{
743 return SCI_SUCCESS;
744}
745
746static enum sci_status scic_sds_remote_node_context_await_suspension_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000747 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700748 u32 event_code)
749{
750 enum sci_status status;
751
752 switch (scu_get_event_type(event_code)) {
753 case SCU_EVENT_TL_RNC_SUSPEND_TX:
754 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000755 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700756 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
757 );
758
Dave Jiange2023b82011-04-21 05:34:49 +0000759 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700760 status = SCI_SUCCESS;
761 break;
762
763 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
764 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000765 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700766 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
767 );
768
Dave Jiange2023b82011-04-21 05:34:49 +0000769 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700770 status = SCI_SUCCESS;
771 break;
772
773 default:
Dan Williams96143952011-04-19 18:35:58 -0700774 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700775 "%s: SCIC Remote Node Context 0x%p requested to "
776 "process event 0x%x while in state %d.\n",
777 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000778 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700779 event_code,
780 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000781 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700782
783 status = SCI_FAILURE;
784 break;
785 }
786
787 return status;
788}
789
790/* --------------------------------------------------------------------------- */
791
Dan Williams35173d52011-03-26 16:43:01 -0700792static struct scic_sds_remote_node_context_handlers
Dan Williams6f231dd2011-07-02 22:56:22 -0700793scic_sds_remote_node_context_state_handler_table[
794 SCIC_SDS_REMOTE_NODE_CONTEXT_MAX_STATES] =
795{
796 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE */
797 {
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
804 },
805 /* SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE */
806 {
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
813 },
814 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE */
815 {
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
822 },
823 /* SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE */
824 {
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
831 },
832 /* SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE */
833 {
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
840 },
841 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE */
842 {
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
849 },
850 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE */
851 {
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
858 },
859 /* SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE */
860 {
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
867 }
868};
869
870/*
871 * *****************************************************************************
872 * * REMOTE NODE CONTEXT PRIVATE METHODS
873 * ***************************************************************************** */
874
875/**
876 *
877 *
878 * This method just calls the user callback function and then resets the
879 * callback.
880 */
881static void scic_sds_remote_node_context_notify_user(
882 struct scic_sds_remote_node_context *rnc)
883{
884 if (rnc->user_callback != NULL) {
885 (*rnc->user_callback)(rnc->user_cookie);
886
887 rnc->user_callback = NULL;
888 rnc->user_cookie = NULL;
889 }
890}
891
892/**
893 *
894 *
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
897 * state.
898 */
899static void scic_sds_remote_node_context_continue_state_transitions(
900 struct scic_sds_remote_node_context *rnc)
901{
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
905 );
906 }
907}
908
909/**
910 *
Dave Jiange2023b82011-04-21 05:34:49 +0000911 * @sci_rnc: The remote node context object that is to be validated.
Dan Williams6f231dd2011-07-02 22:56:22 -0700912 *
913 * This method will mark the rnc buffer as being valid and post the request to
914 * the hardware. none
915 */
916static void scic_sds_remote_node_context_validate_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000917 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700918{
Dan Williams96143952011-04-19 18:35:58 -0700919 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -0700920 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700921 union scu_remote_node_context *rnc_buffer;
922
923 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
Dan Williams96143952011-04-19 18:35:58 -0700924 scic_sds_remote_device_get_controller(sci_dev),
Dave Jiange2023b82011-04-21 05:34:49 +0000925 sci_rnc->remote_node_index
Dan Williams6f231dd2011-07-02 22:56:22 -0700926 );
927
928 rnc_buffer->ssp.is_valid = true;
929
Dan Williams96143952011-04-19 18:35:58 -0700930 if (!sci_dev->is_direct_attached &&
Dan Williamsa1a113b2011-04-21 18:44:45 -0700931 (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) {
Dan Williams96143952011-04-19 18:35:58 -0700932 scic_sds_remote_device_post_request(sci_dev,
933 SCU_CONTEXT_COMMAND_POST_RNC_96);
Dan Williams6f231dd2011-07-02 22:56:22 -0700934 } else {
Dan Williams96143952011-04-19 18:35:58 -0700935 scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_32);
Dan Williams6f231dd2011-07-02 22:56:22 -0700936
Dan Williams96143952011-04-19 18:35:58 -0700937 if (sci_dev->is_direct_attached) {
938 scic_sds_port_setup_transports(sci_dev->owning_port,
939 sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700940 }
941 }
942}
943
944/**
945 *
Dave Jiange2023b82011-04-21 05:34:49 +0000946 * @sci_rnc: The remote node context object that is to be invalidated.
Dan Williams6f231dd2011-07-02 22:56:22 -0700947 *
948 * This method will update the RNC buffer and post the invalidate request. none
949 */
950static void scic_sds_remote_node_context_invalidate_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000951 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700952{
953 union scu_remote_node_context *rnc_buffer;
954
955 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
Dan Williams96143952011-04-19 18:35:58 -0700956 scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc)),
957 sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700958
959 rnc_buffer->ssp.is_valid = false;
960
Dan Williams96143952011-04-19 18:35:58 -0700961 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc),
962 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700963}
964
965/*
966 * *****************************************************************************
967 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
968 * ***************************************************************************** */
969
970/**
971 *
972 *
973 *
974 */
975static void scic_sds_remote_node_context_initial_state_enter(
976 struct sci_base_object *object)
977{
978 struct scic_sds_remote_node_context *rnc;
979
980 rnc = (struct scic_sds_remote_node_context *)object;
981
982 SET_STATE_HANDLER(
983 rnc,
984 scic_sds_remote_node_context_state_handler_table,
985 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
986 );
987
988 /*
989 * Check to see if we have gotten back to the initial state because someone
990 * requested to destroy the remote node context object. */
991 if (
992 rnc->state_machine.previous_state_id
993 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
994 ) {
995 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
996
997 scic_sds_remote_node_context_notify_user(rnc);
998 }
999}
1000
1001/**
1002 *
1003 *
1004 *
1005 */
1006static void scic_sds_remote_node_context_posting_state_enter(
1007 struct sci_base_object *object)
1008{
Dave Jiange2023b82011-04-21 05:34:49 +00001009 struct scic_sds_remote_node_context *sci_rnc;
Dan Williams6f231dd2011-07-02 22:56:22 -07001010
Dave Jiange2023b82011-04-21 05:34:49 +00001011 sci_rnc = (struct scic_sds_remote_node_context *)object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001012
1013 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +00001014 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -07001015 scic_sds_remote_node_context_state_handler_table,
1016 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
1017 );
1018
Dave Jiange2023b82011-04-21 05:34:49 +00001019 scic_sds_remote_node_context_validate_context_buffer(sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -07001020}
1021
1022/**
1023 *
1024 *
1025 *
1026 */
1027static void scic_sds_remote_node_context_invalidating_state_enter(
1028 struct sci_base_object *object)
1029{
1030 struct scic_sds_remote_node_context *rnc;
1031
1032 rnc = (struct scic_sds_remote_node_context *)object;
1033
1034 SET_STATE_HANDLER(
1035 rnc,
1036 scic_sds_remote_node_context_state_handler_table,
1037 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1038 );
1039
1040 scic_sds_remote_node_context_invalidate_context_buffer(rnc);
1041}
1042
1043/**
1044 *
1045 *
1046 *
1047 */
1048static void scic_sds_remote_node_context_resuming_state_enter(
1049 struct sci_base_object *object)
1050{
1051 struct scic_sds_remote_node_context *rnc;
Dan Williams96143952011-04-19 18:35:58 -07001052 struct scic_sds_remote_device *sci_dev;
Dan Williamsa1a113b2011-04-21 18:44:45 -07001053 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001054
1055 rnc = (struct scic_sds_remote_node_context *)object;
Dan Williams96143952011-04-19 18:35:58 -07001056 sci_dev = rnc_to_dev(rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -07001057 dev = sci_dev_to_domain(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001058
1059 SET_STATE_HANDLER(
1060 rnc,
1061 scic_sds_remote_node_context_state_handler_table,
1062 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1063 );
1064
Henryk Dembkowski24621462011-02-23 00:08:52 -08001065 /*
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
1070 */
Dan Williamsa1a113b2011-04-21 18:44:45 -07001071 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
1072 sci_dev->is_direct_attached)
Dan Williams96143952011-04-19 18:35:58 -07001073 scic_sds_port_setup_transports(sci_dev->owning_port,
1074 rnc->remote_node_index);
Henryk Dembkowski24621462011-02-23 00:08:52 -08001075
Dan Williams96143952011-04-19 18:35:58 -07001076 scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
Dan Williams6f231dd2011-07-02 22:56:22 -07001077}
1078
1079/**
1080 *
1081 *
1082 *
1083 */
1084static void scic_sds_remote_node_context_ready_state_enter(
1085 struct sci_base_object *object)
1086{
1087 struct scic_sds_remote_node_context *rnc;
1088
1089 rnc = (struct scic_sds_remote_node_context *)object;
1090
1091 SET_STATE_HANDLER(
1092 rnc,
1093 scic_sds_remote_node_context_state_handler_table,
1094 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1095 );
1096
1097 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1098
1099 if (rnc->user_callback != NULL) {
1100 scic_sds_remote_node_context_notify_user(rnc);
1101 }
1102}
1103
1104/**
1105 *
1106 *
1107 *
1108 */
1109static void scic_sds_remote_node_context_tx_suspended_state_enter(
1110 struct sci_base_object *object)
1111{
1112 struct scic_sds_remote_node_context *rnc;
1113
1114 rnc = (struct scic_sds_remote_node_context *)object;
1115
1116 SET_STATE_HANDLER(
1117 rnc,
1118 scic_sds_remote_node_context_state_handler_table,
1119 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1120 );
1121
1122 scic_sds_remote_node_context_continue_state_transitions(rnc);
1123}
1124
1125/**
1126 *
1127 *
1128 *
1129 */
1130static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
1131 struct sci_base_object *object)
1132{
1133 struct scic_sds_remote_node_context *rnc;
1134
1135 rnc = (struct scic_sds_remote_node_context *)object;
1136
1137 SET_STATE_HANDLER(
1138 rnc,
1139 scic_sds_remote_node_context_state_handler_table,
1140 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1141 );
1142
1143 scic_sds_remote_node_context_continue_state_transitions(rnc);
1144}
1145
1146/**
1147 *
1148 *
1149 *
1150 */
1151static void scic_sds_remote_node_context_await_suspension_state_enter(
1152 struct sci_base_object *object)
1153{
1154 struct scic_sds_remote_node_context *rnc;
1155
1156 rnc = (struct scic_sds_remote_node_context *)object;
1157
1158 SET_STATE_HANDLER(
1159 rnc,
1160 scic_sds_remote_node_context_state_handler_table,
1161 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1162 );
1163}
1164
1165/* --------------------------------------------------------------------------- */
1166
Dan Williams35173d52011-03-26 16:43:01 -07001167static const struct sci_base_state scic_sds_remote_node_context_state_table[] = {
Dan Williams6f231dd2011-07-02 22:56:22 -07001168 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE] = {
1169 .enter_state = scic_sds_remote_node_context_initial_state_enter,
1170 },
1171 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE] = {
1172 .enter_state = scic_sds_remote_node_context_posting_state_enter,
1173 },
1174 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE] = {
1175 .enter_state = scic_sds_remote_node_context_invalidating_state_enter,
1176 },
1177 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE] = {
1178 .enter_state = scic_sds_remote_node_context_resuming_state_enter,
1179 },
1180 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE] = {
1181 .enter_state = scic_sds_remote_node_context_ready_state_enter,
1182 },
1183 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE] = {
1184 .enter_state = scic_sds_remote_node_context_tx_suspended_state_enter,
1185 },
1186 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE] = {
1187 .enter_state = scic_sds_remote_node_context_tx_rx_suspended_state_enter,
1188 },
1189 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE] = {
1190 .enter_state = scic_sds_remote_node_context_await_suspension_state_enter,
1191 },
1192};
1193
Dan Williams96143952011-04-19 18:35:58 -07001194void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context *rnc,
1195 u16 remote_node_index)
Dan Williams35173d52011-03-26 16:43:01 -07001196{
1197 memset(rnc, 0, sizeof(struct scic_sds_remote_node_context));
1198
1199 rnc->remote_node_index = remote_node_index;
Dan Williams35173d52011-03-26 16:43:01 -07001200 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1201
1202 sci_base_state_machine_construct(
1203 &rnc->state_machine,
1204 &rnc->parent,
1205 scic_sds_remote_node_context_state_table,
1206 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1207 );
1208
1209 sci_base_state_machine_start(&rnc->state_machine);
1210}