blob: bc51ecf76b14cb4a6a46aafe76b7fb198ba8dfa1 [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);
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700111 int rni = sci_rnc->remote_node_index;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700112 union scu_remote_node_context *rnc;
Dave Jiange2023b82011-04-21 05:34:49 +0000113 struct scic_sds_controller *scic;
Dan Williamsa3d568f02011-04-26 09:41:52 -0700114 __le64 sas_addr;
Dan Williams6f231dd2011-07-02 22:56:22 -0700115
Dan Williams96143952011-04-19 18:35:58 -0700116 scic = scic_sds_remote_device_get_controller(sci_dev);
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700117 rnc = scic_sds_controller_get_remote_node_context_buffer(scic, rni);
Dan Williams6f231dd2011-07-02 22:56:22 -0700118
Dan Williams96143952011-04-19 18:35:58 -0700119 memset(rnc, 0, sizeof(union scu_remote_node_context)
120 * scic_sds_remote_device_node_count(sci_dev));
Dan Williams6f231dd2011-07-02 22:56:22 -0700121
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700122 rnc->ssp.remote_node_index = rni;
Dan Williams96143952011-04-19 18:35:58 -0700123 rnc->ssp.remote_node_port_width = sci_dev->device_port_width;
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700124 rnc->ssp.logical_port_index = sci_dev->owning_port->physical_port_index;
Dan Williams6f231dd2011-07-02 22:56:22 -0700125
Dan Williamsa3d568f02011-04-26 09:41:52 -0700126 /* sas address is __be64, context ram format is __le64 */
127 sas_addr = cpu_to_le64(SAS_ADDR(dev->sas_addr));
128 rnc->ssp.remote_sas_address_hi = upper_32_bits(sas_addr);
129 rnc->ssp.remote_sas_address_lo = lower_32_bits(sas_addr);
Dan Williams6f231dd2011-07-02 22:56:22 -0700130
131 rnc->ssp.nexus_loss_timer_enable = true;
132 rnc->ssp.check_bit = false;
133 rnc->ssp.is_valid = false;
134 rnc->ssp.is_remote_node_context = true;
135 rnc->ssp.function_number = 0;
136
137 rnc->ssp.arbitration_wait_time = 0;
138
Dan Williamsa1a113b2011-04-21 18:44:45 -0700139 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700140 rnc->ssp.connection_occupancy_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000141 scic->user_parameters.sds1.stp_max_occupancy_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700142 rnc->ssp.connection_inactivity_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000143 scic->user_parameters.sds1.stp_inactivity_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700144 } else {
145 rnc->ssp.connection_occupancy_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000146 scic->user_parameters.sds1.ssp_max_occupancy_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700147 rnc->ssp.connection_inactivity_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000148 scic->user_parameters.sds1.ssp_inactivity_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700149 }
150
151 rnc->ssp.initial_arbitration_wait_time = 0;
152
153 /* Open Address Frame Parameters */
Dan Williams96143952011-04-19 18:35:58 -0700154 rnc->ssp.oaf_connection_rate = sci_dev->connection_rate;
Dan Williams6f231dd2011-07-02 22:56:22 -0700155 rnc->ssp.oaf_features = 0;
156 rnc->ssp.oaf_source_zone_group = 0;
157 rnc->ssp.oaf_more_compatibility_features = 0;
158}
159
160/**
161 *
Dave Jiange2023b82011-04-21 05:34:49 +0000162 * @sci_rnc:
163 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700164 * @callback_parameter:
165 *
166 * This method will setup the remote node context object so it will transition
167 * to its ready state. If the remote node context is already setup to
168 * transition to its final state then this function does nothing. none
169 */
170static void scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000171 struct scic_sds_remote_node_context *sci_rnc,
172 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700173 void *callback_parameter)
174{
Dave Jiange2023b82011-04-21 05:34:49 +0000175 if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
176 sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY;
177 sci_rnc->user_callback = callback;
178 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700179 }
180}
181
182/**
183 *
Dave Jiange2023b82011-04-21 05:34:49 +0000184 * @sci_rnc:
185 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700186 * @callback_parameter:
187 *
188 * This method will setup the remote node context object so it will transistion
189 * to its final state. none
190 */
191static void scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000192 struct scic_sds_remote_node_context *sci_rnc,
193 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700194 void *callback_parameter)
195{
Dave Jiange2023b82011-04-21 05:34:49 +0000196 sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL;
197 sci_rnc->user_callback = callback;
198 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700199}
200
201/**
202 *
Dave Jiange2023b82011-04-21 05:34:49 +0000203 * @sci_rnc:
204 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700205 *
206 * This method will continue to resume a remote node context. This is used in
207 * the states where a resume is requested while a resume is in progress.
208 */
209static enum sci_status scic_sds_remote_node_context_continue_to_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000210 struct scic_sds_remote_node_context *sci_rnc,
211 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700212 void *callback_parameter)
213{
Dave Jiange2023b82011-04-21 05:34:49 +0000214 if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) {
215 sci_rnc->user_callback = callback;
216 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700217
218 return SCI_SUCCESS;
219 }
220
221 return SCI_FAILURE_INVALID_STATE;
222}
223
224/* --------------------------------------------------------------------------- */
225
226static enum sci_status scic_sds_remote_node_context_default_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000227 struct scic_sds_remote_node_context *sci_rnc,
228 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700229 void *callback_parameter)
230{
Dan Williams96143952011-04-19 18:35:58 -0700231 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700232 "%s: SCIC Remote Node Context 0x%p requested to stop while "
233 "in unexpected state %d\n",
234 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000235 sci_rnc,
236 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700237
238 /*
239 * We have decided that the destruct request on the remote node context can not fail
240 * since it is either in the initial/destroyed state or is can be destroyed. */
241 return SCI_SUCCESS;
242}
243
244static enum sci_status scic_sds_remote_node_context_default_suspend_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000245 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700246 u32 suspend_type,
Dave Jiange2023b82011-04-21 05:34:49 +0000247 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700248 void *callback_parameter)
249{
Dan Williams96143952011-04-19 18:35:58 -0700250 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700251 "%s: SCIC Remote Node Context 0x%p requested to suspend "
252 "while in wrong state %d\n",
253 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000254 sci_rnc,
255 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700256
257 return SCI_FAILURE_INVALID_STATE;
258}
259
260static enum sci_status scic_sds_remote_node_context_default_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000261 struct scic_sds_remote_node_context *sci_rnc,
262 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700263 void *callback_parameter)
264{
Dan Williams96143952011-04-19 18:35:58 -0700265 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700266 "%s: SCIC Remote Node Context 0x%p requested to resume "
267 "while in wrong state %d\n",
268 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000269 sci_rnc,
270 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700271
272 return SCI_FAILURE_INVALID_STATE;
273}
274
275static enum sci_status scic_sds_remote_node_context_default_start_io_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000276 struct scic_sds_remote_node_context *sci_rnc,
277 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700278{
Dan Williams96143952011-04-19 18:35:58 -0700279 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700280 "%s: SCIC Remote Node Context 0x%p requested to start io "
281 "0x%p while in wrong state %d\n",
282 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000283 sci_rnc,
284 sci_req,
285 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700286
287 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
288}
289
290static enum sci_status scic_sds_remote_node_context_default_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000291 struct scic_sds_remote_node_context *sci_rnc,
292 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700293{
Dan Williams96143952011-04-19 18:35:58 -0700294 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700295 "%s: SCIC Remote Node Context 0x%p requested to start "
296 "task 0x%p while in wrong state %d\n",
297 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000298 sci_rnc,
299 sci_req,
300 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700301
302 return SCI_FAILURE;
303}
304
305static enum sci_status scic_sds_remote_node_context_default_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000306 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700307 u32 event_code)
308{
Dan Williams96143952011-04-19 18:35:58 -0700309 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700310 "%s: SCIC Remote Node Context 0x%p requested to process "
311 "event 0x%x while in wrong state %d\n",
312 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000313 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700314 event_code,
Dave Jiange2023b82011-04-21 05:34:49 +0000315 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700316
317 return SCI_FAILURE_INVALID_STATE;
318}
319
320/**
321 *
Dave Jiange2023b82011-04-21 05:34:49 +0000322 * @sci_rnc: The rnc for which the task request is targeted.
323 * @sci_req: The request which is going to be started.
Dan Williams6f231dd2011-07-02 22:56:22 -0700324 *
325 * This method determines if the task request can be started by the SCU
326 * hardware. When the RNC is in the ready state any task can be started.
327 * enum sci_status SCI_SUCCESS
328 */
329static enum sci_status scic_sds_remote_node_context_success_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000330 struct scic_sds_remote_node_context *sci_rnc,
331 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700332{
333 return SCI_SUCCESS;
334}
335
336/**
337 *
Dave Jiange2023b82011-04-21 05:34:49 +0000338 * @sci_rnc:
339 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700340 * @callback_parameter:
341 *
342 * This method handles destruct calls from the various state handlers. The
343 * remote node context can be requested to destroy from any state. If there was
344 * a user callback it is always replaced with the request to destroy user
345 * callback. enum sci_status
346 */
347static enum sci_status scic_sds_remote_node_context_general_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000348 struct scic_sds_remote_node_context *sci_rnc,
349 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700350 void *callback_parameter)
351{
352 scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000353 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700354 );
355
356 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000357 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700358 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
359 );
360
361 return SCI_SUCCESS;
362}
363
364/* --------------------------------------------------------------------------- */
365
366static enum sci_status scic_sds_remote_node_context_initial_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000367 struct scic_sds_remote_node_context *sci_rnc,
368 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700369 void *callback_parameter)
370{
Dave Jiange2023b82011-04-21 05:34:49 +0000371 if (sci_rnc->remote_node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700372 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000373 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700374 );
375
Dave Jiange2023b82011-04-21 05:34:49 +0000376 scic_sds_remote_node_context_construct_buffer(sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700377
378 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000379 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700380 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
381 );
382
383 return SCI_SUCCESS;
384 }
385
386 return SCI_FAILURE_INVALID_STATE;
387}
388
389/* --------------------------------------------------------------------------- */
390
391static enum sci_status scic_sds_remote_node_context_posting_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000392 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700393 u32 event_code)
394{
395 enum sci_status status;
396
397 switch (scu_get_event_code(event_code)) {
398 case SCU_EVENT_POST_RNC_COMPLETE:
399 status = SCI_SUCCESS;
400
401 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000402 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700403 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
404 );
405 break;
406
407 default:
408 status = SCI_FAILURE;
Dan Williams96143952011-04-19 18:35:58 -0700409 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700410 "%s: SCIC Remote Node Context 0x%p requested to "
411 "process unexpected event 0x%x while in posting "
412 "state\n",
413 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000414 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700415 event_code);
416 break;
417 }
418
419 return status;
420}
421
422/* --------------------------------------------------------------------------- */
423
424static enum sci_status scic_sds_remote_node_context_invalidating_state_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000425 struct scic_sds_remote_node_context *sci_rnc,
426 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700427 void *callback_parameter)
428{
429 scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000430 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700431 );
432
433 return SCI_SUCCESS;
434}
435
436static enum sci_status scic_sds_remote_node_context_invalidating_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000437 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700438 u32 event_code)
439{
440 enum sci_status status;
441
442 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
443 status = SCI_SUCCESS;
444
Dave Jiange2023b82011-04-21 05:34:49 +0000445 if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700446 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000447 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700448 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
449 );
450 } else {
451 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000452 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700453 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
454 );
455 }
456 } else {
457 switch (scu_get_event_type(event_code)) {
458 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
459 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
460 /*
461 * We really dont care if the hardware is going to suspend
462 * the device since it's being invalidated anyway */
Dan Williams96143952011-04-19 18:35:58 -0700463 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700464 "%s: SCIC Remote Node Context 0x%p was "
465 "suspeneded by hardware while being "
466 "invalidated.\n",
467 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000468 sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700469 status = SCI_SUCCESS;
470 break;
471
472 default:
Dan Williams96143952011-04-19 18:35:58 -0700473 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700474 "%s: SCIC Remote Node Context 0x%p "
475 "requested to process event 0x%x while "
476 "in state %d.\n",
477 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000478 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700479 event_code,
480 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000481 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700482 status = SCI_FAILURE;
483 break;
484 }
485 }
486
487 return status;
488}
489
490/* --------------------------------------------------------------------------- */
491
492
493static enum sci_status scic_sds_remote_node_context_resuming_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000494 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700495 u32 event_code)
496{
497 enum sci_status status;
498
499 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
500 status = SCI_SUCCESS;
501
502 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000503 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700504 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
505 );
506 } else {
507 switch (scu_get_event_type(event_code)) {
508 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
509 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
510 /*
511 * We really dont care if the hardware is going to suspend
512 * the device since it's being resumed anyway */
Dan Williams96143952011-04-19 18:35:58 -0700513 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700514 "%s: SCIC Remote Node Context 0x%p was "
515 "suspeneded by hardware while being resumed.\n",
516 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000517 sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700518 status = SCI_SUCCESS;
519 break;
520
521 default:
Dan Williams96143952011-04-19 18:35:58 -0700522 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700523 "%s: SCIC Remote Node Context 0x%p requested "
524 "to process event 0x%x while in state %d.\n",
525 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000526 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700527 event_code,
528 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000529 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700530 status = SCI_FAILURE;
531 break;
532 }
533 }
534
535 return status;
536}
537
538/* --------------------------------------------------------------------------- */
539
540/**
541 *
Dave Jiange2023b82011-04-21 05:34:49 +0000542 * @sci_rnc: The remote node context object being suspended.
543 * @callback: The callback when the suspension is complete.
Dan Williams6f231dd2011-07-02 22:56:22 -0700544 * @callback_parameter: The parameter that is to be passed into the callback.
545 *
546 * This method will handle the suspend requests from the ready state.
547 * SCI_SUCCESS
548 */
549static enum sci_status scic_sds_remote_node_context_ready_state_suspend_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000550 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700551 u32 suspend_type,
Dave Jiange2023b82011-04-21 05:34:49 +0000552 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700553 void *callback_parameter)
554{
Dave Jiange2023b82011-04-21 05:34:49 +0000555 sci_rnc->user_callback = callback;
556 sci_rnc->user_cookie = callback_parameter;
557 sci_rnc->suspension_code = suspend_type;
Dan Williams6f231dd2011-07-02 22:56:22 -0700558
559 if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
Dan Williams96143952011-04-19 18:35:58 -0700560 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc),
561 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX);
Dan Williams6f231dd2011-07-02 22:56:22 -0700562 }
563
564 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000565 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700566 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
567 );
568
569 return SCI_SUCCESS;
570}
571
572/**
573 *
Dave Jiange2023b82011-04-21 05:34:49 +0000574 * @sci_rnc: The rnc for which the io request is targeted.
575 * @sci_req: The request which is going to be started.
Dan Williams6f231dd2011-07-02 22:56:22 -0700576 *
577 * This method determines if the io request can be started by the SCU hardware.
578 * When the RNC is in the ready state any io request can be started. enum sci_status
579 * SCI_SUCCESS
580 */
581static enum sci_status scic_sds_remote_node_context_ready_state_start_io_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000582 struct scic_sds_remote_node_context *sci_rnc,
583 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700584{
585 return SCI_SUCCESS;
586}
587
588
589static enum sci_status scic_sds_remote_node_context_ready_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000590 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700591 u32 event_code)
592{
593 enum sci_status status;
594
595 switch (scu_get_event_type(event_code)) {
596 case SCU_EVENT_TL_RNC_SUSPEND_TX:
597 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000598 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700599 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
600 );
601
Dave Jiange2023b82011-04-21 05:34:49 +0000602 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700603 status = SCI_SUCCESS;
604 break;
605
606 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
607 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000608 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700609 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
610 );
611
Dave Jiange2023b82011-04-21 05:34:49 +0000612 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700613 status = SCI_SUCCESS;
614 break;
615
616 default:
Dan Williams96143952011-04-19 18:35:58 -0700617 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700618 "%s: SCIC Remote Node Context 0x%p requested to "
619 "process event 0x%x while in state %d.\n",
620 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000621 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700622 event_code,
623 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000624 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700625
626 status = SCI_FAILURE;
627 break;
628 }
629
630 return status;
631}
632
633/* --------------------------------------------------------------------------- */
634
635static enum sci_status scic_sds_remote_node_context_tx_suspended_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000636 struct scic_sds_remote_node_context *sci_rnc,
637 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700638 void *callback_parameter)
639{
Dan Williamsa1a113b2011-04-21 18:44:45 -0700640 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
641 struct domain_device *dev = sci_dev_to_domain(sci_dev);
642 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700643
Dan Williamsa1a113b2011-04-21 18:44:45 -0700644 scic_sds_remote_node_context_setup_to_resume(sci_rnc, callback,
645 callback_parameter);
Dan Williams6f231dd2011-07-02 22:56:22 -0700646
647 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
Dan Williamsa1a113b2011-04-21 18:44:45 -0700648 if (dev->dev_type == SAS_END_DEV || dev_is_expander(dev))
649 sci_base_state_machine_change_state(&sci_rnc->state_machine,
650 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE);
651 else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
652 if (sci_dev->is_direct_attached) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700653 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700654 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000655 &sci_rnc->state_machine,
Dan Williamsa1a113b2011-04-21 18:44:45 -0700656 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700657 } else {
658 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000659 &sci_rnc->state_machine,
Dan Williamsa1a113b2011-04-21 18:44:45 -0700660 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700661 }
Dan Williamsa1a113b2011-04-21 18:44:45 -0700662 } else
Dan Williams6f231dd2011-07-02 22:56:22 -0700663 status = SCI_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700664
665 return status;
666}
667
668/**
669 *
Dave Jiange2023b82011-04-21 05:34:49 +0000670 * @sci_rnc: The remote node context which is to receive the task request.
671 * @sci_req: The task request to be transmitted to to the remote target
Dan Williams6f231dd2011-07-02 22:56:22 -0700672 * device.
673 *
674 * This method will report a success or failure attempt to start a new task
675 * request to the hardware. Since all task requests are sent on the high
676 * priority queue they can be sent when the RCN is in a TX suspend state.
677 * enum sci_status SCI_SUCCESS
678 */
679static enum sci_status scic_sds_remote_node_context_suspended_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000680 struct scic_sds_remote_node_context *sci_rnc,
681 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700682{
Dave Jiange2023b82011-04-21 05:34:49 +0000683 scic_sds_remote_node_context_resume(sci_rnc, NULL, NULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700684
685 return SCI_SUCCESS;
686}
687
688/* --------------------------------------------------------------------------- */
689
690static enum sci_status scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000691 struct scic_sds_remote_node_context *sci_rnc,
692 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700693 void *callback_parameter)
694{
695 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000696 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700697 );
698
699 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000700 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700701 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
702 );
703
704 return SCI_FAILURE_INVALID_STATE;
705}
706
707/* --------------------------------------------------------------------------- */
708
709/**
710 *
711 *
712 *
713 */
714static enum sci_status scic_sds_remote_node_context_await_suspension_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000715 struct scic_sds_remote_node_context *sci_rnc,
716 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700717 void *callback_parameter)
718{
719 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000720 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700721 );
722
723 return SCI_SUCCESS;
724}
725
726/**
727 *
Dave Jiange2023b82011-04-21 05:34:49 +0000728 * @sci_rnc: The remote node context which is to receive the task request.
729 * @sci_req: The task request to be transmitted to to the remote target
Dan Williams6f231dd2011-07-02 22:56:22 -0700730 * device.
731 *
732 * This method will report a success or failure attempt to start a new task
733 * request to the hardware. Since all task requests are sent on the high
734 * priority queue they can be sent when the RCN is in a TX suspend state.
735 * enum sci_status SCI_SUCCESS
736 */
737static enum sci_status scic_sds_remote_node_context_await_suspension_state_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000738 struct scic_sds_remote_node_context *sci_rnc,
739 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700740{
741 return SCI_SUCCESS;
742}
743
744static enum sci_status scic_sds_remote_node_context_await_suspension_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000745 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700746 u32 event_code)
747{
748 enum sci_status status;
749
750 switch (scu_get_event_type(event_code)) {
751 case SCU_EVENT_TL_RNC_SUSPEND_TX:
752 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000753 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700754 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
755 );
756
Dave Jiange2023b82011-04-21 05:34:49 +0000757 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700758 status = SCI_SUCCESS;
759 break;
760
761 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
762 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000763 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700764 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
765 );
766
Dave Jiange2023b82011-04-21 05:34:49 +0000767 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700768 status = SCI_SUCCESS;
769 break;
770
771 default:
Dan Williams96143952011-04-19 18:35:58 -0700772 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700773 "%s: SCIC Remote Node Context 0x%p requested to "
774 "process event 0x%x while in state %d.\n",
775 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000776 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700777 event_code,
778 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000779 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700780
781 status = SCI_FAILURE;
782 break;
783 }
784
785 return status;
786}
787
788/* --------------------------------------------------------------------------- */
789
Dan Williams35173d52011-03-26 16:43:01 -0700790static struct scic_sds_remote_node_context_handlers
Dan Williams6f231dd2011-07-02 22:56:22 -0700791scic_sds_remote_node_context_state_handler_table[
792 SCIC_SDS_REMOTE_NODE_CONTEXT_MAX_STATES] =
793{
794 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE */
795 {
796 scic_sds_remote_node_context_default_destruct_handler,
797 scic_sds_remote_node_context_default_suspend_handler,
798 scic_sds_remote_node_context_initial_state_resume_handler,
799 scic_sds_remote_node_context_default_start_io_handler,
800 scic_sds_remote_node_context_default_start_task_handler,
801 scic_sds_remote_node_context_default_event_handler
802 },
803 /* SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE */
804 {
805 scic_sds_remote_node_context_general_destruct_handler,
806 scic_sds_remote_node_context_default_suspend_handler,
807 scic_sds_remote_node_context_continue_to_resume_handler,
808 scic_sds_remote_node_context_default_start_io_handler,
809 scic_sds_remote_node_context_default_start_task_handler,
810 scic_sds_remote_node_context_posting_state_event_handler
811 },
812 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE */
813 {
814 scic_sds_remote_node_context_invalidating_state_destruct_handler,
815 scic_sds_remote_node_context_default_suspend_handler,
816 scic_sds_remote_node_context_continue_to_resume_handler,
817 scic_sds_remote_node_context_default_start_io_handler,
818 scic_sds_remote_node_context_default_start_task_handler,
819 scic_sds_remote_node_context_invalidating_state_event_handler
820 },
821 /* SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE */
822 {
823 scic_sds_remote_node_context_general_destruct_handler,
824 scic_sds_remote_node_context_default_suspend_handler,
825 scic_sds_remote_node_context_continue_to_resume_handler,
826 scic_sds_remote_node_context_default_start_io_handler,
827 scic_sds_remote_node_context_success_start_task_handler,
828 scic_sds_remote_node_context_resuming_state_event_handler
829 },
830 /* SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE */
831 {
832 scic_sds_remote_node_context_general_destruct_handler,
833 scic_sds_remote_node_context_ready_state_suspend_handler,
834 scic_sds_remote_node_context_default_resume_handler,
835 scic_sds_remote_node_context_ready_state_start_io_handler,
836 scic_sds_remote_node_context_success_start_task_handler,
837 scic_sds_remote_node_context_ready_state_event_handler
838 },
839 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE */
840 {
841 scic_sds_remote_node_context_general_destruct_handler,
842 scic_sds_remote_node_context_default_suspend_handler,
843 scic_sds_remote_node_context_tx_suspended_state_resume_handler,
844 scic_sds_remote_node_context_default_start_io_handler,
845 scic_sds_remote_node_context_suspended_start_task_handler,
846 scic_sds_remote_node_context_default_event_handler
847 },
848 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE */
849 {
850 scic_sds_remote_node_context_general_destruct_handler,
851 scic_sds_remote_node_context_default_suspend_handler,
852 scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler,
853 scic_sds_remote_node_context_default_start_io_handler,
854 scic_sds_remote_node_context_suspended_start_task_handler,
855 scic_sds_remote_node_context_default_event_handler
856 },
857 /* SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE */
858 {
859 scic_sds_remote_node_context_general_destruct_handler,
860 scic_sds_remote_node_context_default_suspend_handler,
861 scic_sds_remote_node_context_await_suspension_state_resume_handler,
862 scic_sds_remote_node_context_default_start_io_handler,
863 scic_sds_remote_node_context_await_suspension_state_start_task_handler,
864 scic_sds_remote_node_context_await_suspension_state_event_handler
865 }
866};
867
868/*
869 * *****************************************************************************
870 * * REMOTE NODE CONTEXT PRIVATE METHODS
871 * ***************************************************************************** */
872
873/**
874 *
875 *
876 * This method just calls the user callback function and then resets the
877 * callback.
878 */
879static void scic_sds_remote_node_context_notify_user(
880 struct scic_sds_remote_node_context *rnc)
881{
882 if (rnc->user_callback != NULL) {
883 (*rnc->user_callback)(rnc->user_cookie);
884
885 rnc->user_callback = NULL;
886 rnc->user_cookie = NULL;
887 }
888}
889
890/**
891 *
892 *
893 * This method will continue the remote node context state machine by
894 * requesting to resume the remote node context state machine from its current
895 * state.
896 */
897static void scic_sds_remote_node_context_continue_state_transitions(
898 struct scic_sds_remote_node_context *rnc)
899{
900 if (rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) {
901 rnc->state_handlers->resume_handler(
902 rnc, rnc->user_callback, rnc->user_cookie
903 );
904 }
905}
906
907/**
908 *
Dave Jiange2023b82011-04-21 05:34:49 +0000909 * @sci_rnc: The remote node context object that is to be validated.
Dan Williams6f231dd2011-07-02 22:56:22 -0700910 *
911 * This method will mark the rnc buffer as being valid and post the request to
912 * the hardware. none
913 */
914static void scic_sds_remote_node_context_validate_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000915 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700916{
Dan Williams96143952011-04-19 18:35:58 -0700917 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -0700918 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700919 union scu_remote_node_context *rnc_buffer;
920
921 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
Dan Williams96143952011-04-19 18:35:58 -0700922 scic_sds_remote_device_get_controller(sci_dev),
Dave Jiange2023b82011-04-21 05:34:49 +0000923 sci_rnc->remote_node_index
Dan Williams6f231dd2011-07-02 22:56:22 -0700924 );
925
926 rnc_buffer->ssp.is_valid = true;
927
Dan Williams96143952011-04-19 18:35:58 -0700928 if (!sci_dev->is_direct_attached &&
Dan Williamsa1a113b2011-04-21 18:44:45 -0700929 (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) {
Dan Williams96143952011-04-19 18:35:58 -0700930 scic_sds_remote_device_post_request(sci_dev,
931 SCU_CONTEXT_COMMAND_POST_RNC_96);
Dan Williams6f231dd2011-07-02 22:56:22 -0700932 } else {
Dan Williams96143952011-04-19 18:35:58 -0700933 scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_32);
Dan Williams6f231dd2011-07-02 22:56:22 -0700934
Dan Williams96143952011-04-19 18:35:58 -0700935 if (sci_dev->is_direct_attached) {
936 scic_sds_port_setup_transports(sci_dev->owning_port,
937 sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700938 }
939 }
940}
941
942/**
943 *
Dave Jiange2023b82011-04-21 05:34:49 +0000944 * @sci_rnc: The remote node context object that is to be invalidated.
Dan Williams6f231dd2011-07-02 22:56:22 -0700945 *
946 * This method will update the RNC buffer and post the invalidate request. none
947 */
948static void scic_sds_remote_node_context_invalidate_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000949 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700950{
951 union scu_remote_node_context *rnc_buffer;
952
953 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
Dan Williams96143952011-04-19 18:35:58 -0700954 scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc)),
955 sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700956
957 rnc_buffer->ssp.is_valid = false;
958
Dan Williams96143952011-04-19 18:35:58 -0700959 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc),
960 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700961}
962
963/*
964 * *****************************************************************************
965 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
966 * ***************************************************************************** */
967
968/**
969 *
970 *
971 *
972 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000973static void scic_sds_remote_node_context_initial_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700974{
975 struct scic_sds_remote_node_context *rnc;
976
977 rnc = (struct scic_sds_remote_node_context *)object;
978
979 SET_STATE_HANDLER(
980 rnc,
981 scic_sds_remote_node_context_state_handler_table,
982 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
983 );
984
985 /*
986 * Check to see if we have gotten back to the initial state because someone
987 * requested to destroy the remote node context object. */
988 if (
989 rnc->state_machine.previous_state_id
990 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
991 ) {
992 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
993
994 scic_sds_remote_node_context_notify_user(rnc);
995 }
996}
997
998/**
999 *
1000 *
1001 *
1002 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001003static void scic_sds_remote_node_context_posting_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001004{
Dave Jiange2023b82011-04-21 05:34:49 +00001005 struct scic_sds_remote_node_context *sci_rnc;
Dan Williams6f231dd2011-07-02 22:56:22 -07001006
Dave Jiange2023b82011-04-21 05:34:49 +00001007 sci_rnc = (struct scic_sds_remote_node_context *)object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001008
1009 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +00001010 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -07001011 scic_sds_remote_node_context_state_handler_table,
1012 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
1013 );
1014
Dave Jiange2023b82011-04-21 05:34:49 +00001015 scic_sds_remote_node_context_validate_context_buffer(sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -07001016}
1017
1018/**
1019 *
1020 *
1021 *
1022 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001023static void scic_sds_remote_node_context_invalidating_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001024{
1025 struct scic_sds_remote_node_context *rnc;
1026
1027 rnc = (struct scic_sds_remote_node_context *)object;
1028
1029 SET_STATE_HANDLER(
1030 rnc,
1031 scic_sds_remote_node_context_state_handler_table,
1032 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1033 );
1034
1035 scic_sds_remote_node_context_invalidate_context_buffer(rnc);
1036}
1037
1038/**
1039 *
1040 *
1041 *
1042 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001043static void scic_sds_remote_node_context_resuming_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001044{
1045 struct scic_sds_remote_node_context *rnc;
Dan Williams96143952011-04-19 18:35:58 -07001046 struct scic_sds_remote_device *sci_dev;
Dan Williamsa1a113b2011-04-21 18:44:45 -07001047 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001048
1049 rnc = (struct scic_sds_remote_node_context *)object;
Dan Williams96143952011-04-19 18:35:58 -07001050 sci_dev = rnc_to_dev(rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -07001051 dev = sci_dev_to_domain(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001052
1053 SET_STATE_HANDLER(
1054 rnc,
1055 scic_sds_remote_node_context_state_handler_table,
1056 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1057 );
1058
Henryk Dembkowski24621462011-02-23 00:08:52 -08001059 /*
1060 * For direct attached SATA devices we need to clear the TLCR
1061 * NCQ to TCi tag mapping on the phy and in cases where we
1062 * resume because of a target reset we also need to update
1063 * the STPTLDARNI register with the RNi of the device
1064 */
Dan Williamsa1a113b2011-04-21 18:44:45 -07001065 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
1066 sci_dev->is_direct_attached)
Dan Williams96143952011-04-19 18:35:58 -07001067 scic_sds_port_setup_transports(sci_dev->owning_port,
1068 rnc->remote_node_index);
Henryk Dembkowski24621462011-02-23 00:08:52 -08001069
Dan Williams96143952011-04-19 18:35:58 -07001070 scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
Dan Williams6f231dd2011-07-02 22:56:22 -07001071}
1072
1073/**
1074 *
1075 *
1076 *
1077 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001078static void scic_sds_remote_node_context_ready_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001079{
1080 struct scic_sds_remote_node_context *rnc;
1081
1082 rnc = (struct scic_sds_remote_node_context *)object;
1083
1084 SET_STATE_HANDLER(
1085 rnc,
1086 scic_sds_remote_node_context_state_handler_table,
1087 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1088 );
1089
1090 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1091
1092 if (rnc->user_callback != NULL) {
1093 scic_sds_remote_node_context_notify_user(rnc);
1094 }
1095}
1096
1097/**
1098 *
1099 *
1100 *
1101 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001102static void scic_sds_remote_node_context_tx_suspended_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001103{
1104 struct scic_sds_remote_node_context *rnc;
1105
1106 rnc = (struct scic_sds_remote_node_context *)object;
1107
1108 SET_STATE_HANDLER(
1109 rnc,
1110 scic_sds_remote_node_context_state_handler_table,
1111 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1112 );
1113
1114 scic_sds_remote_node_context_continue_state_transitions(rnc);
1115}
1116
1117/**
1118 *
1119 *
1120 *
1121 */
1122static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001123 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001124{
1125 struct scic_sds_remote_node_context *rnc;
1126
1127 rnc = (struct scic_sds_remote_node_context *)object;
1128
1129 SET_STATE_HANDLER(
1130 rnc,
1131 scic_sds_remote_node_context_state_handler_table,
1132 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1133 );
1134
1135 scic_sds_remote_node_context_continue_state_transitions(rnc);
1136}
1137
1138/**
1139 *
1140 *
1141 *
1142 */
1143static void scic_sds_remote_node_context_await_suspension_state_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001144 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001145{
1146 struct scic_sds_remote_node_context *rnc;
1147
1148 rnc = (struct scic_sds_remote_node_context *)object;
1149
1150 SET_STATE_HANDLER(
1151 rnc,
1152 scic_sds_remote_node_context_state_handler_table,
1153 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1154 );
1155}
1156
1157/* --------------------------------------------------------------------------- */
1158
Dan Williams35173d52011-03-26 16:43:01 -07001159static const struct sci_base_state scic_sds_remote_node_context_state_table[] = {
Dan Williams6f231dd2011-07-02 22:56:22 -07001160 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE] = {
1161 .enter_state = scic_sds_remote_node_context_initial_state_enter,
1162 },
1163 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE] = {
1164 .enter_state = scic_sds_remote_node_context_posting_state_enter,
1165 },
1166 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE] = {
1167 .enter_state = scic_sds_remote_node_context_invalidating_state_enter,
1168 },
1169 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE] = {
1170 .enter_state = scic_sds_remote_node_context_resuming_state_enter,
1171 },
1172 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE] = {
1173 .enter_state = scic_sds_remote_node_context_ready_state_enter,
1174 },
1175 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE] = {
1176 .enter_state = scic_sds_remote_node_context_tx_suspended_state_enter,
1177 },
1178 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE] = {
1179 .enter_state = scic_sds_remote_node_context_tx_rx_suspended_state_enter,
1180 },
1181 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE] = {
1182 .enter_state = scic_sds_remote_node_context_await_suspension_state_enter,
1183 },
1184};
1185
Dan Williams96143952011-04-19 18:35:58 -07001186void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context *rnc,
1187 u16 remote_node_index)
Dan Williams35173d52011-03-26 16:43:01 -07001188{
1189 memset(rnc, 0, sizeof(struct scic_sds_remote_node_context));
1190
1191 rnc->remote_node_index = remote_node_index;
Dan Williams35173d52011-03-26 16:43:01 -07001192 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1193
1194 sci_base_state_machine_construct(
1195 &rnc->state_machine,
1196 &rnc->parent,
1197 scic_sds_remote_node_context_state_table,
1198 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1199 );
1200
1201 sci_base_state_machine_start(&rnc->state_machine);
1202}