blob: 5891f3d501772449e927016d1df175a0d87ffed6 [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
Dan Williamscc9203b2011-05-08 17:34:44 -070056#include "host.h"
Dan Williams3bff9d52011-05-08 22:15:10 -070057#include "state_machine.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070058#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_util.h"
62#include "scu_event_codes.h"
63#include "scu_task_context.h"
64
Dan Williams6f231dd2011-07-02 22:56:22 -070065
66/**
67 *
Dave Jiange2023b82011-04-21 05:34:49 +000068 * @sci_rnc: The RNC for which the is posted request is being made.
Dan Williams6f231dd2011-07-02 22:56:22 -070069 *
70 * This method will return true if the RNC is not in the initial state. In all
71 * other states the RNC is considered active and this will return true. The
72 * destroy request of the state machine drives the RNC back to the initial
73 * state. If the state machine changes then this routine will also have to be
74 * changed. bool true if the state machine is not in the initial state false if
75 * the state machine is in the initial state
76 */
77
78/**
79 *
Dave Jiange2023b82011-04-21 05:34:49 +000080 * @sci_rnc: The state of the remote node context object to check.
Dan Williams6f231dd2011-07-02 22:56:22 -070081 *
82 * This method will return true if the remote node context is in a READY state
83 * otherwise it will return false bool true if the remote node context is in
84 * the ready state. false if the remote node context is not in the ready state.
85 */
86bool scic_sds_remote_node_context_is_ready(
Dave Jiange2023b82011-04-21 05:34:49 +000087 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -070088{
Dave Jiange2023b82011-04-21 05:34:49 +000089 u32 current_state = sci_base_state_machine_get_state(&sci_rnc->state_machine);
Dan Williams6f231dd2011-07-02 22:56:22 -070090
91 if (current_state == SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE) {
92 return true;
93 }
94
95 return false;
96}
97
98/**
99 *
Dave Jiange2023b82011-04-21 05:34:49 +0000100 * @sci_dev: The remote device to use to construct the RNC buffer.
Dan Williams6f231dd2011-07-02 22:56:22 -0700101 * @rnc: The buffer into which the remote device data will be copied.
102 *
103 * This method will construct the RNC buffer for this remote device object. none
104 */
Dan Williams35173d52011-03-26 16:43:01 -0700105static void scic_sds_remote_node_context_construct_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000106 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700107{
Dan Williams96143952011-04-19 18:35:58 -0700108 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -0700109 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700110 int rni = sci_rnc->remote_node_index;
Dan Williamsa1a113b2011-04-21 18:44:45 -0700111 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 Williams1f4fa1f2011-04-26 11:44:06 -0700116 rnc = scic_sds_controller_get_remote_node_context_buffer(scic, rni);
Dan Williams6f231dd2011-07-02 22:56:22 -0700117
Dan Williams96143952011-04-19 18:35:58 -0700118 memset(rnc, 0, sizeof(union scu_remote_node_context)
119 * scic_sds_remote_device_node_count(sci_dev));
Dan Williams6f231dd2011-07-02 22:56:22 -0700120
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700121 rnc->ssp.remote_node_index = rni;
Dan Williams96143952011-04-19 18:35:58 -0700122 rnc->ssp.remote_node_port_width = sci_dev->device_port_width;
Dan Williams1f4fa1f2011-04-26 11:44:06 -0700123 rnc->ssp.logical_port_index = sci_dev->owning_port->physical_port_index;
Dan Williams6f231dd2011-07-02 22:56:22 -0700124
Dan Williamsa3d568f02011-04-26 09:41:52 -0700125 /* sas address is __be64, context ram format is __le64 */
126 sas_addr = cpu_to_le64(SAS_ADDR(dev->sas_addr));
127 rnc->ssp.remote_sas_address_hi = upper_32_bits(sas_addr);
128 rnc->ssp.remote_sas_address_lo = lower_32_bits(sas_addr);
Dan Williams6f231dd2011-07-02 22:56:22 -0700129
130 rnc->ssp.nexus_loss_timer_enable = true;
131 rnc->ssp.check_bit = false;
132 rnc->ssp.is_valid = false;
133 rnc->ssp.is_remote_node_context = true;
134 rnc->ssp.function_number = 0;
135
136 rnc->ssp.arbitration_wait_time = 0;
137
Dan Williamsa1a113b2011-04-21 18:44:45 -0700138 if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700139 rnc->ssp.connection_occupancy_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000140 scic->user_parameters.sds1.stp_max_occupancy_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700141 rnc->ssp.connection_inactivity_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000142 scic->user_parameters.sds1.stp_inactivity_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700143 } else {
144 rnc->ssp.connection_occupancy_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000145 scic->user_parameters.sds1.ssp_max_occupancy_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700146 rnc->ssp.connection_inactivity_timeout =
Dave Jiange2023b82011-04-21 05:34:49 +0000147 scic->user_parameters.sds1.ssp_inactivity_timeout;
Dan Williams6f231dd2011-07-02 22:56:22 -0700148 }
149
150 rnc->ssp.initial_arbitration_wait_time = 0;
151
152 /* Open Address Frame Parameters */
Dan Williams96143952011-04-19 18:35:58 -0700153 rnc->ssp.oaf_connection_rate = sci_dev->connection_rate;
Dan Williams6f231dd2011-07-02 22:56:22 -0700154 rnc->ssp.oaf_features = 0;
155 rnc->ssp.oaf_source_zone_group = 0;
156 rnc->ssp.oaf_more_compatibility_features = 0;
157}
158
159/**
160 *
Dave Jiange2023b82011-04-21 05:34:49 +0000161 * @sci_rnc:
162 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700163 * @callback_parameter:
164 *
165 * This method will setup the remote node context object so it will transition
166 * to its ready state. If the remote node context is already setup to
167 * transition to its final state then this function does nothing. none
168 */
169static void scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000170 struct scic_sds_remote_node_context *sci_rnc,
171 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700172 void *callback_parameter)
173{
Dave Jiange2023b82011-04-21 05:34:49 +0000174 if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
175 sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY;
176 sci_rnc->user_callback = callback;
177 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700178 }
179}
180
181/**
182 *
Dave Jiange2023b82011-04-21 05:34:49 +0000183 * @sci_rnc:
184 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700185 * @callback_parameter:
186 *
187 * This method will setup the remote node context object so it will transistion
188 * to its final state. none
189 */
190static void scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000191 struct scic_sds_remote_node_context *sci_rnc,
192 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700193 void *callback_parameter)
194{
Dave Jiange2023b82011-04-21 05:34:49 +0000195 sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL;
196 sci_rnc->user_callback = callback;
197 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700198}
199
200/**
201 *
Dave Jiange2023b82011-04-21 05:34:49 +0000202 * @sci_rnc:
203 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700204 *
205 * This method will continue to resume a remote node context. This is used in
206 * the states where a resume is requested while a resume is in progress.
207 */
208static enum sci_status scic_sds_remote_node_context_continue_to_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000209 struct scic_sds_remote_node_context *sci_rnc,
210 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700211 void *callback_parameter)
212{
Dave Jiange2023b82011-04-21 05:34:49 +0000213 if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) {
214 sci_rnc->user_callback = callback;
215 sci_rnc->user_cookie = callback_parameter;
Dan Williams6f231dd2011-07-02 22:56:22 -0700216
217 return SCI_SUCCESS;
218 }
219
220 return SCI_FAILURE_INVALID_STATE;
221}
222
223/* --------------------------------------------------------------------------- */
224
225static enum sci_status scic_sds_remote_node_context_default_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000226 struct scic_sds_remote_node_context *sci_rnc,
227 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700228 void *callback_parameter)
229{
Dan Williams96143952011-04-19 18:35:58 -0700230 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700231 "%s: SCIC Remote Node Context 0x%p requested to stop while "
232 "in unexpected state %d\n",
233 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000234 sci_rnc,
235 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700236
237 /*
238 * We have decided that the destruct request on the remote node context can not fail
239 * since it is either in the initial/destroyed state or is can be destroyed. */
240 return SCI_SUCCESS;
241}
242
243static enum sci_status scic_sds_remote_node_context_default_suspend_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000244 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700245 u32 suspend_type,
Dave Jiange2023b82011-04-21 05:34:49 +0000246 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700247 void *callback_parameter)
248{
Dan Williams96143952011-04-19 18:35:58 -0700249 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700250 "%s: SCIC Remote Node Context 0x%p requested to suspend "
251 "while in wrong state %d\n",
252 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000253 sci_rnc,
254 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700255
256 return SCI_FAILURE_INVALID_STATE;
257}
258
259static enum sci_status scic_sds_remote_node_context_default_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000260 struct scic_sds_remote_node_context *sci_rnc,
261 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700262 void *callback_parameter)
263{
Dan Williams96143952011-04-19 18:35:58 -0700264 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700265 "%s: SCIC Remote Node Context 0x%p requested to resume "
266 "while in wrong state %d\n",
267 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000268 sci_rnc,
269 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700270
271 return SCI_FAILURE_INVALID_STATE;
272}
273
274static enum sci_status scic_sds_remote_node_context_default_start_io_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000275 struct scic_sds_remote_node_context *sci_rnc,
276 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700277{
Dan Williams96143952011-04-19 18:35:58 -0700278 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700279 "%s: SCIC Remote Node Context 0x%p requested to start io "
280 "0x%p while in wrong state %d\n",
281 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000282 sci_rnc,
283 sci_req,
284 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700285
286 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
287}
288
289static enum sci_status scic_sds_remote_node_context_default_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000290 struct scic_sds_remote_node_context *sci_rnc,
291 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700292{
Dan Williams96143952011-04-19 18:35:58 -0700293 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700294 "%s: SCIC Remote Node Context 0x%p requested to start "
295 "task 0x%p while in wrong state %d\n",
296 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000297 sci_rnc,
298 sci_req,
299 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700300
301 return SCI_FAILURE;
302}
303
304static enum sci_status scic_sds_remote_node_context_default_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000305 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700306 u32 event_code)
307{
Dan Williams96143952011-04-19 18:35:58 -0700308 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700309 "%s: SCIC Remote Node Context 0x%p requested to process "
310 "event 0x%x while in wrong state %d\n",
311 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000312 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700313 event_code,
Dave Jiange2023b82011-04-21 05:34:49 +0000314 sci_base_state_machine_get_state(&sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700315
316 return SCI_FAILURE_INVALID_STATE;
317}
318
319/**
320 *
Dave Jiange2023b82011-04-21 05:34:49 +0000321 * @sci_rnc: The rnc for which the task request is targeted.
322 * @sci_req: The request which is going to be started.
Dan Williams6f231dd2011-07-02 22:56:22 -0700323 *
324 * This method determines if the task request can be started by the SCU
325 * hardware. When the RNC is in the ready state any task can be started.
326 * enum sci_status SCI_SUCCESS
327 */
328static enum sci_status scic_sds_remote_node_context_success_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000329 struct scic_sds_remote_node_context *sci_rnc,
330 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700331{
332 return SCI_SUCCESS;
333}
334
335/**
336 *
Dave Jiange2023b82011-04-21 05:34:49 +0000337 * @sci_rnc:
338 * @callback:
Dan Williams6f231dd2011-07-02 22:56:22 -0700339 * @callback_parameter:
340 *
341 * This method handles destruct calls from the various state handlers. The
342 * remote node context can be requested to destroy from any state. If there was
343 * a user callback it is always replaced with the request to destroy user
344 * callback. enum sci_status
345 */
346static enum sci_status scic_sds_remote_node_context_general_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000347 struct scic_sds_remote_node_context *sci_rnc,
348 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700349 void *callback_parameter)
350{
351 scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000352 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700353 );
354
355 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000356 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700357 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
358 );
359
360 return SCI_SUCCESS;
361}
362
363/* --------------------------------------------------------------------------- */
364
365static enum sci_status scic_sds_remote_node_context_initial_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000366 struct scic_sds_remote_node_context *sci_rnc,
367 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700368 void *callback_parameter)
369{
Dave Jiange2023b82011-04-21 05:34:49 +0000370 if (sci_rnc->remote_node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700371 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000372 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700373 );
374
Dave Jiange2023b82011-04-21 05:34:49 +0000375 scic_sds_remote_node_context_construct_buffer(sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700376
377 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000378 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700379 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
380 );
381
382 return SCI_SUCCESS;
383 }
384
385 return SCI_FAILURE_INVALID_STATE;
386}
387
388/* --------------------------------------------------------------------------- */
389
390static enum sci_status scic_sds_remote_node_context_posting_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000391 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700392 u32 event_code)
393{
394 enum sci_status status;
395
396 switch (scu_get_event_code(event_code)) {
397 case SCU_EVENT_POST_RNC_COMPLETE:
398 status = SCI_SUCCESS;
399
400 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000401 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700402 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
403 );
404 break;
405
406 default:
407 status = SCI_FAILURE;
Dan Williams96143952011-04-19 18:35:58 -0700408 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700409 "%s: SCIC Remote Node Context 0x%p requested to "
410 "process unexpected event 0x%x while in posting "
411 "state\n",
412 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000413 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700414 event_code);
415 break;
416 }
417
418 return status;
419}
420
421/* --------------------------------------------------------------------------- */
422
423static enum sci_status scic_sds_remote_node_context_invalidating_state_destruct_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000424 struct scic_sds_remote_node_context *sci_rnc,
425 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700426 void *callback_parameter)
427{
428 scic_sds_remote_node_context_setup_to_destory(
Dave Jiange2023b82011-04-21 05:34:49 +0000429 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700430 );
431
432 return SCI_SUCCESS;
433}
434
435static enum sci_status scic_sds_remote_node_context_invalidating_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000436 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700437 u32 event_code)
438{
439 enum sci_status status;
440
441 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
442 status = SCI_SUCCESS;
443
Dave Jiange2023b82011-04-21 05:34:49 +0000444 if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700445 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000446 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700447 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
448 );
449 } else {
450 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000451 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700452 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
453 );
454 }
455 } else {
456 switch (scu_get_event_type(event_code)) {
457 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
458 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
459 /*
460 * We really dont care if the hardware is going to suspend
461 * the device since it's being invalidated anyway */
Dan Williams96143952011-04-19 18:35:58 -0700462 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700463 "%s: SCIC Remote Node Context 0x%p was "
464 "suspeneded by hardware while being "
465 "invalidated.\n",
466 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000467 sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700468 status = SCI_SUCCESS;
469 break;
470
471 default:
Dan Williams96143952011-04-19 18:35:58 -0700472 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700473 "%s: SCIC Remote Node Context 0x%p "
474 "requested to process event 0x%x while "
475 "in state %d.\n",
476 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000477 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700478 event_code,
479 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000480 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700481 status = SCI_FAILURE;
482 break;
483 }
484 }
485
486 return status;
487}
488
489/* --------------------------------------------------------------------------- */
490
491
492static enum sci_status scic_sds_remote_node_context_resuming_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000493 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700494 u32 event_code)
495{
496 enum sci_status status;
497
498 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
499 status = SCI_SUCCESS;
500
501 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000502 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700503 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
504 );
505 } else {
506 switch (scu_get_event_type(event_code)) {
507 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
508 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
509 /*
510 * We really dont care if the hardware is going to suspend
511 * the device since it's being resumed anyway */
Dan Williams96143952011-04-19 18:35:58 -0700512 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700513 "%s: SCIC Remote Node Context 0x%p was "
514 "suspeneded by hardware while being resumed.\n",
515 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000516 sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -0700517 status = SCI_SUCCESS;
518 break;
519
520 default:
Dan Williams96143952011-04-19 18:35:58 -0700521 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700522 "%s: SCIC Remote Node Context 0x%p requested "
523 "to process event 0x%x while in state %d.\n",
524 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000525 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700526 event_code,
527 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000528 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700529 status = SCI_FAILURE;
530 break;
531 }
532 }
533
534 return status;
535}
536
537/* --------------------------------------------------------------------------- */
538
539/**
540 *
Dave Jiange2023b82011-04-21 05:34:49 +0000541 * @sci_rnc: The remote node context object being suspended.
542 * @callback: The callback when the suspension is complete.
Dan Williams6f231dd2011-07-02 22:56:22 -0700543 * @callback_parameter: The parameter that is to be passed into the callback.
544 *
545 * This method will handle the suspend requests from the ready state.
546 * SCI_SUCCESS
547 */
548static enum sci_status scic_sds_remote_node_context_ready_state_suspend_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000549 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700550 u32 suspend_type,
Dave Jiange2023b82011-04-21 05:34:49 +0000551 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700552 void *callback_parameter)
553{
Dave Jiange2023b82011-04-21 05:34:49 +0000554 sci_rnc->user_callback = callback;
555 sci_rnc->user_cookie = callback_parameter;
556 sci_rnc->suspension_code = suspend_type;
Dan Williams6f231dd2011-07-02 22:56:22 -0700557
558 if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
Dan Williams96143952011-04-19 18:35:58 -0700559 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc),
560 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX);
Dan Williams6f231dd2011-07-02 22:56:22 -0700561 }
562
563 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000564 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700565 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
566 );
567
568 return SCI_SUCCESS;
569}
570
571/**
572 *
Dave Jiange2023b82011-04-21 05:34:49 +0000573 * @sci_rnc: The rnc for which the io request is targeted.
574 * @sci_req: The request which is going to be started.
Dan Williams6f231dd2011-07-02 22:56:22 -0700575 *
576 * This method determines if the io request can be started by the SCU hardware.
577 * When the RNC is in the ready state any io request can be started. enum sci_status
578 * SCI_SUCCESS
579 */
580static enum sci_status scic_sds_remote_node_context_ready_state_start_io_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000581 struct scic_sds_remote_node_context *sci_rnc,
582 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700583{
584 return SCI_SUCCESS;
585}
586
587
588static enum sci_status scic_sds_remote_node_context_ready_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000589 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700590 u32 event_code)
591{
592 enum sci_status status;
593
594 switch (scu_get_event_type(event_code)) {
595 case SCU_EVENT_TL_RNC_SUSPEND_TX:
596 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000597 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700598 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
599 );
600
Dave Jiange2023b82011-04-21 05:34:49 +0000601 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700602 status = SCI_SUCCESS;
603 break;
604
605 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
606 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000607 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700608 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
609 );
610
Dave Jiange2023b82011-04-21 05:34:49 +0000611 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700612 status = SCI_SUCCESS;
613 break;
614
615 default:
Dan Williams96143952011-04-19 18:35:58 -0700616 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700617 "%s: SCIC Remote Node Context 0x%p requested to "
618 "process event 0x%x while in state %d.\n",
619 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000620 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700621 event_code,
622 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000623 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700624
625 status = SCI_FAILURE;
626 break;
627 }
628
629 return status;
630}
631
632/* --------------------------------------------------------------------------- */
633
634static enum sci_status scic_sds_remote_node_context_tx_suspended_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000635 struct scic_sds_remote_node_context *sci_rnc,
636 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700637 void *callback_parameter)
638{
Dan Williamsa1a113b2011-04-21 18:44:45 -0700639 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
640 struct domain_device *dev = sci_dev_to_domain(sci_dev);
641 enum sci_status status = SCI_SUCCESS;
Dan Williams6f231dd2011-07-02 22:56:22 -0700642
Dan Williamsa1a113b2011-04-21 18:44:45 -0700643 scic_sds_remote_node_context_setup_to_resume(sci_rnc, callback,
644 callback_parameter);
Dan Williams6f231dd2011-07-02 22:56:22 -0700645
646 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
Dan Williamsa1a113b2011-04-21 18:44:45 -0700647 if (dev->dev_type == SAS_END_DEV || dev_is_expander(dev))
648 sci_base_state_machine_change_state(&sci_rnc->state_machine,
649 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE);
650 else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
651 if (sci_dev->is_direct_attached) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700652 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
Dan Williams6f231dd2011-07-02 22:56:22 -0700653 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000654 &sci_rnc->state_machine,
Dan Williamsa1a113b2011-04-21 18:44:45 -0700655 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700656 } else {
657 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000658 &sci_rnc->state_machine,
Dan Williamsa1a113b2011-04-21 18:44:45 -0700659 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700660 }
Dan Williamsa1a113b2011-04-21 18:44:45 -0700661 } else
Dan Williams6f231dd2011-07-02 22:56:22 -0700662 status = SCI_FAILURE;
Dan Williams6f231dd2011-07-02 22:56:22 -0700663
664 return status;
665}
666
667/**
668 *
Dave Jiange2023b82011-04-21 05:34:49 +0000669 * @sci_rnc: The remote node context which is to receive the task request.
670 * @sci_req: The task request to be transmitted to to the remote target
Dan Williams6f231dd2011-07-02 22:56:22 -0700671 * device.
672 *
673 * This method will report a success or failure attempt to start a new task
674 * request to the hardware. Since all task requests are sent on the high
675 * priority queue they can be sent when the RCN is in a TX suspend state.
676 * enum sci_status SCI_SUCCESS
677 */
678static enum sci_status scic_sds_remote_node_context_suspended_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000679 struct scic_sds_remote_node_context *sci_rnc,
680 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700681{
Dave Jiange2023b82011-04-21 05:34:49 +0000682 scic_sds_remote_node_context_resume(sci_rnc, NULL, NULL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700683
684 return SCI_SUCCESS;
685}
686
687/* --------------------------------------------------------------------------- */
688
689static enum sci_status scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000690 struct scic_sds_remote_node_context *sci_rnc,
691 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700692 void *callback_parameter)
693{
694 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000695 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700696 );
697
698 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000699 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700700 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
701 );
702
703 return SCI_FAILURE_INVALID_STATE;
704}
705
706/* --------------------------------------------------------------------------- */
707
708/**
709 *
710 *
711 *
712 */
713static enum sci_status scic_sds_remote_node_context_await_suspension_state_resume_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000714 struct scic_sds_remote_node_context *sci_rnc,
715 scics_sds_remote_node_context_callback callback,
Dan Williams6f231dd2011-07-02 22:56:22 -0700716 void *callback_parameter)
717{
718 scic_sds_remote_node_context_setup_to_resume(
Dave Jiange2023b82011-04-21 05:34:49 +0000719 sci_rnc, callback, callback_parameter
Dan Williams6f231dd2011-07-02 22:56:22 -0700720 );
721
722 return SCI_SUCCESS;
723}
724
725/**
726 *
Dave Jiange2023b82011-04-21 05:34:49 +0000727 * @sci_rnc: The remote node context which is to receive the task request.
728 * @sci_req: The task request to be transmitted to to the remote target
Dan Williams6f231dd2011-07-02 22:56:22 -0700729 * device.
730 *
731 * This method will report a success or failure attempt to start a new task
732 * request to the hardware. Since all task requests are sent on the high
733 * priority queue they can be sent when the RCN is in a TX suspend state.
734 * enum sci_status SCI_SUCCESS
735 */
736static enum sci_status scic_sds_remote_node_context_await_suspension_state_start_task_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000737 struct scic_sds_remote_node_context *sci_rnc,
738 struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -0700739{
740 return SCI_SUCCESS;
741}
742
743static enum sci_status scic_sds_remote_node_context_await_suspension_state_event_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000744 struct scic_sds_remote_node_context *sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700745 u32 event_code)
746{
747 enum sci_status status;
748
749 switch (scu_get_event_type(event_code)) {
750 case SCU_EVENT_TL_RNC_SUSPEND_TX:
751 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000752 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700753 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
754 );
755
Dave Jiange2023b82011-04-21 05:34:49 +0000756 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700757 status = SCI_SUCCESS;
758 break;
759
760 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
761 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000762 &sci_rnc->state_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700763 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
764 );
765
Dave Jiange2023b82011-04-21 05:34:49 +0000766 sci_rnc->suspension_code = scu_get_event_specifier(event_code);
Dan Williams6f231dd2011-07-02 22:56:22 -0700767 status = SCI_SUCCESS;
768 break;
769
770 default:
Dan Williams96143952011-04-19 18:35:58 -0700771 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
Dan Williams6f231dd2011-07-02 22:56:22 -0700772 "%s: SCIC Remote Node Context 0x%p requested to "
773 "process event 0x%x while in state %d.\n",
774 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000775 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700776 event_code,
777 sci_base_state_machine_get_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000778 &sci_rnc->state_machine));
Dan Williams6f231dd2011-07-02 22:56:22 -0700779
780 status = SCI_FAILURE;
781 break;
782 }
783
784 return status;
785}
786
787/* --------------------------------------------------------------------------- */
788
Dan Williams35173d52011-03-26 16:43:01 -0700789static struct scic_sds_remote_node_context_handlers
Jacek Daneckia98a7422011-05-03 04:21:07 +0000790scic_sds_remote_node_context_state_handler_table[] = {
791 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE] = {
792 .destruct_handler = scic_sds_remote_node_context_default_destruct_handler,
793 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
794 .resume_handler = scic_sds_remote_node_context_initial_state_resume_handler,
795 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
796 .start_task_handler = scic_sds_remote_node_context_default_start_task_handler,
797 .event_handler = scic_sds_remote_node_context_default_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700798 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000799 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE] = {
800 .destruct_handler = scic_sds_remote_node_context_general_destruct_handler,
801 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
802 .resume_handler = scic_sds_remote_node_context_continue_to_resume_handler,
803 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
804 .start_task_handler = scic_sds_remote_node_context_default_start_task_handler,
805 .event_handler = scic_sds_remote_node_context_posting_state_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700806 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000807 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE] = {
808 .destruct_handler = scic_sds_remote_node_context_invalidating_state_destruct_handler,
809 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
810 .resume_handler = scic_sds_remote_node_context_continue_to_resume_handler,
811 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
812 .start_task_handler = scic_sds_remote_node_context_default_start_task_handler,
813 .event_handler = scic_sds_remote_node_context_invalidating_state_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700814 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000815 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE] = {
816 .destruct_handler = scic_sds_remote_node_context_general_destruct_handler,
817 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
818 .resume_handler = scic_sds_remote_node_context_continue_to_resume_handler,
819 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
820 .start_task_handler = scic_sds_remote_node_context_success_start_task_handler,
821 .event_handler = scic_sds_remote_node_context_resuming_state_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700822 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000823 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE] = {
824 .destruct_handler = scic_sds_remote_node_context_general_destruct_handler,
825 .suspend_handler = scic_sds_remote_node_context_ready_state_suspend_handler,
826 .resume_handler = scic_sds_remote_node_context_default_resume_handler,
827 .start_io_handler = scic_sds_remote_node_context_ready_state_start_io_handler,
828 .start_task_handler = scic_sds_remote_node_context_success_start_task_handler,
829 .event_handler = scic_sds_remote_node_context_ready_state_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700830 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000831 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE] = {
832 .destruct_handler = scic_sds_remote_node_context_general_destruct_handler,
833 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
834 .resume_handler = scic_sds_remote_node_context_tx_suspended_state_resume_handler,
835 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
836 .start_task_handler = scic_sds_remote_node_context_suspended_start_task_handler,
837 .event_handler = scic_sds_remote_node_context_default_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700838 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000839 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE] = {
840 .destruct_handler = scic_sds_remote_node_context_general_destruct_handler,
841 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
842 .resume_handler = scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler,
843 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
844 .start_task_handler = scic_sds_remote_node_context_suspended_start_task_handler,
845 .event_handler = scic_sds_remote_node_context_default_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700846 },
Jacek Daneckia98a7422011-05-03 04:21:07 +0000847 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE] = {
848 .destruct_handler = scic_sds_remote_node_context_general_destruct_handler,
849 .suspend_handler = scic_sds_remote_node_context_default_suspend_handler,
850 .resume_handler = scic_sds_remote_node_context_await_suspension_state_resume_handler,
851 .start_io_handler = scic_sds_remote_node_context_default_start_io_handler,
852 .start_task_handler = scic_sds_remote_node_context_await_suspension_state_start_task_handler,
853 .event_handler = scic_sds_remote_node_context_await_suspension_state_event_handler
Dan Williams6f231dd2011-07-02 22:56:22 -0700854 }
855};
856
857/*
858 * *****************************************************************************
859 * * REMOTE NODE CONTEXT PRIVATE METHODS
860 * ***************************************************************************** */
861
862/**
863 *
864 *
865 * This method just calls the user callback function and then resets the
866 * callback.
867 */
868static void scic_sds_remote_node_context_notify_user(
869 struct scic_sds_remote_node_context *rnc)
870{
871 if (rnc->user_callback != NULL) {
872 (*rnc->user_callback)(rnc->user_cookie);
873
874 rnc->user_callback = NULL;
875 rnc->user_cookie = NULL;
876 }
877}
878
879/**
880 *
881 *
882 * This method will continue the remote node context state machine by
883 * requesting to resume the remote node context state machine from its current
884 * state.
885 */
886static void scic_sds_remote_node_context_continue_state_transitions(
887 struct scic_sds_remote_node_context *rnc)
888{
889 if (rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) {
890 rnc->state_handlers->resume_handler(
891 rnc, rnc->user_callback, rnc->user_cookie
892 );
893 }
894}
895
896/**
897 *
Dave Jiange2023b82011-04-21 05:34:49 +0000898 * @sci_rnc: The remote node context object that is to be validated.
Dan Williams6f231dd2011-07-02 22:56:22 -0700899 *
900 * This method will mark the rnc buffer as being valid and post the request to
901 * the hardware. none
902 */
903static void scic_sds_remote_node_context_validate_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000904 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700905{
Dan Williams96143952011-04-19 18:35:58 -0700906 struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -0700907 struct domain_device *dev = sci_dev_to_domain(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700908 union scu_remote_node_context *rnc_buffer;
909
910 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
Dan Williams96143952011-04-19 18:35:58 -0700911 scic_sds_remote_device_get_controller(sci_dev),
Dave Jiange2023b82011-04-21 05:34:49 +0000912 sci_rnc->remote_node_index
Dan Williams6f231dd2011-07-02 22:56:22 -0700913 );
914
915 rnc_buffer->ssp.is_valid = true;
916
Dan Williams96143952011-04-19 18:35:58 -0700917 if (!sci_dev->is_direct_attached &&
Dan Williamsa1a113b2011-04-21 18:44:45 -0700918 (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) {
Dan Williams96143952011-04-19 18:35:58 -0700919 scic_sds_remote_device_post_request(sci_dev,
920 SCU_CONTEXT_COMMAND_POST_RNC_96);
Dan Williams6f231dd2011-07-02 22:56:22 -0700921 } else {
Dan Williams96143952011-04-19 18:35:58 -0700922 scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_32);
Dan Williams6f231dd2011-07-02 22:56:22 -0700923
Dan Williams96143952011-04-19 18:35:58 -0700924 if (sci_dev->is_direct_attached) {
925 scic_sds_port_setup_transports(sci_dev->owning_port,
926 sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700927 }
928 }
929}
930
931/**
932 *
Dave Jiange2023b82011-04-21 05:34:49 +0000933 * @sci_rnc: The remote node context object that is to be invalidated.
Dan Williams6f231dd2011-07-02 22:56:22 -0700934 *
935 * This method will update the RNC buffer and post the invalidate request. none
936 */
937static void scic_sds_remote_node_context_invalidate_context_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000938 struct scic_sds_remote_node_context *sci_rnc)
Dan Williams6f231dd2011-07-02 22:56:22 -0700939{
940 union scu_remote_node_context *rnc_buffer;
941
942 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
Dan Williams96143952011-04-19 18:35:58 -0700943 scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc)),
944 sci_rnc->remote_node_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700945
946 rnc_buffer->ssp.is_valid = false;
947
Dan Williams96143952011-04-19 18:35:58 -0700948 scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc),
949 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
Dan Williams6f231dd2011-07-02 22:56:22 -0700950}
951
952/*
953 * *****************************************************************************
954 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
955 * ***************************************************************************** */
956
957/**
958 *
959 *
960 *
961 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000962static void scic_sds_remote_node_context_initial_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700963{
Maciej Patelczykaf23e852011-04-28 22:06:26 +0000964 struct scic_sds_remote_node_context *rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -0700965
966 SET_STATE_HANDLER(
967 rnc,
968 scic_sds_remote_node_context_state_handler_table,
969 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
970 );
971
972 /*
973 * Check to see if we have gotten back to the initial state because someone
974 * requested to destroy the remote node context object. */
975 if (
976 rnc->state_machine.previous_state_id
977 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
978 ) {
979 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
980
981 scic_sds_remote_node_context_notify_user(rnc);
982 }
983}
984
985/**
986 *
987 *
988 *
989 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000990static void scic_sds_remote_node_context_posting_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700991{
Maciej Patelczykaf23e852011-04-28 22:06:26 +0000992 struct scic_sds_remote_node_context *sci_rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -0700993
994 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +0000995 sci_rnc,
Dan Williams6f231dd2011-07-02 22:56:22 -0700996 scic_sds_remote_node_context_state_handler_table,
997 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
998 );
999
Dave Jiange2023b82011-04-21 05:34:49 +00001000 scic_sds_remote_node_context_validate_context_buffer(sci_rnc);
Dan Williams6f231dd2011-07-02 22:56:22 -07001001}
1002
1003/**
1004 *
1005 *
1006 *
1007 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001008static void scic_sds_remote_node_context_invalidating_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001009{
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001010 struct scic_sds_remote_node_context *rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001011
1012 SET_STATE_HANDLER(
1013 rnc,
1014 scic_sds_remote_node_context_state_handler_table,
1015 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1016 );
1017
1018 scic_sds_remote_node_context_invalidate_context_buffer(rnc);
1019}
1020
1021/**
1022 *
1023 *
1024 *
1025 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001026static void scic_sds_remote_node_context_resuming_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001027{
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001028 struct scic_sds_remote_node_context *rnc = object;
Dan Williams96143952011-04-19 18:35:58 -07001029 struct scic_sds_remote_device *sci_dev;
Dan Williamsa1a113b2011-04-21 18:44:45 -07001030 struct domain_device *dev;
Dan Williams6f231dd2011-07-02 22:56:22 -07001031
Dan Williams96143952011-04-19 18:35:58 -07001032 sci_dev = rnc_to_dev(rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -07001033 dev = sci_dev_to_domain(sci_dev);
Dan Williams6f231dd2011-07-02 22:56:22 -07001034
1035 SET_STATE_HANDLER(
1036 rnc,
1037 scic_sds_remote_node_context_state_handler_table,
1038 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1039 );
1040
Henryk Dembkowski24621462011-02-23 00:08:52 -08001041 /*
1042 * For direct attached SATA devices we need to clear the TLCR
1043 * NCQ to TCi tag mapping on the phy and in cases where we
1044 * resume because of a target reset we also need to update
1045 * the STPTLDARNI register with the RNi of the device
1046 */
Dan Williamsa1a113b2011-04-21 18:44:45 -07001047 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
1048 sci_dev->is_direct_attached)
Dan Williams96143952011-04-19 18:35:58 -07001049 scic_sds_port_setup_transports(sci_dev->owning_port,
1050 rnc->remote_node_index);
Henryk Dembkowski24621462011-02-23 00:08:52 -08001051
Dan Williams96143952011-04-19 18:35:58 -07001052 scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
Dan Williams6f231dd2011-07-02 22:56:22 -07001053}
1054
1055/**
1056 *
1057 *
1058 *
1059 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001060static void scic_sds_remote_node_context_ready_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001061{
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001062 struct scic_sds_remote_node_context *rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001063
1064 SET_STATE_HANDLER(
1065 rnc,
1066 scic_sds_remote_node_context_state_handler_table,
1067 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1068 );
1069
1070 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1071
1072 if (rnc->user_callback != NULL) {
1073 scic_sds_remote_node_context_notify_user(rnc);
1074 }
1075}
1076
1077/**
1078 *
1079 *
1080 *
1081 */
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001082static void scic_sds_remote_node_context_tx_suspended_state_enter(void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001083{
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001084 struct scic_sds_remote_node_context *rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001085
1086 SET_STATE_HANDLER(
1087 rnc,
1088 scic_sds_remote_node_context_state_handler_table,
1089 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1090 );
1091
1092 scic_sds_remote_node_context_continue_state_transitions(rnc);
1093}
1094
1095/**
1096 *
1097 *
1098 *
1099 */
1100static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001101 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001102{
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001103 struct scic_sds_remote_node_context *rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001104
1105 SET_STATE_HANDLER(
1106 rnc,
1107 scic_sds_remote_node_context_state_handler_table,
1108 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1109 );
1110
1111 scic_sds_remote_node_context_continue_state_transitions(rnc);
1112}
1113
1114/**
1115 *
1116 *
1117 *
1118 */
1119static void scic_sds_remote_node_context_await_suspension_state_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +00001120 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -07001121{
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001122 struct scic_sds_remote_node_context *rnc = object;
Dan Williams6f231dd2011-07-02 22:56:22 -07001123
1124 SET_STATE_HANDLER(
1125 rnc,
1126 scic_sds_remote_node_context_state_handler_table,
1127 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1128 );
1129}
1130
1131/* --------------------------------------------------------------------------- */
1132
Dan Williams35173d52011-03-26 16:43:01 -07001133static const struct sci_base_state scic_sds_remote_node_context_state_table[] = {
Dan Williams6f231dd2011-07-02 22:56:22 -07001134 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE] = {
1135 .enter_state = scic_sds_remote_node_context_initial_state_enter,
1136 },
1137 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE] = {
1138 .enter_state = scic_sds_remote_node_context_posting_state_enter,
1139 },
1140 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE] = {
1141 .enter_state = scic_sds_remote_node_context_invalidating_state_enter,
1142 },
1143 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE] = {
1144 .enter_state = scic_sds_remote_node_context_resuming_state_enter,
1145 },
1146 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE] = {
1147 .enter_state = scic_sds_remote_node_context_ready_state_enter,
1148 },
1149 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE] = {
1150 .enter_state = scic_sds_remote_node_context_tx_suspended_state_enter,
1151 },
1152 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE] = {
1153 .enter_state = scic_sds_remote_node_context_tx_rx_suspended_state_enter,
1154 },
1155 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE] = {
1156 .enter_state = scic_sds_remote_node_context_await_suspension_state_enter,
1157 },
1158};
1159
Dan Williams96143952011-04-19 18:35:58 -07001160void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context *rnc,
1161 u16 remote_node_index)
Dan Williams35173d52011-03-26 16:43:01 -07001162{
1163 memset(rnc, 0, sizeof(struct scic_sds_remote_node_context));
1164
1165 rnc->remote_node_index = remote_node_index;
Dan Williams35173d52011-03-26 16:43:01 -07001166 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1167
1168 sci_base_state_machine_construct(
1169 &rnc->state_machine,
Maciej Patelczykaf23e852011-04-28 22:06:26 +00001170 rnc,
Dan Williams35173d52011-03-26 16:43:01 -07001171 scic_sds_remote_node_context_state_table,
1172 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1173 );
1174
1175 sci_base_state_machine_start(&rnc->state_machine);
1176}