Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1 | /* |
| 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 Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #include "scic_sds_controller.h" |
| 58 | #include "scic_sds_port.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 59 | #include "remote_device.h" |
| 60 | #include "remote_node_context.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 61 | #include "sci_environment.h" |
| 62 | #include "sci_util.h" |
| 63 | #include "scu_event_codes.h" |
| 64 | #include "scu_task_context.h" |
| 65 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 69 | * @sci_rnc: The RNC for which the is posted request is being made. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 70 | * |
| 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 81 | * @sci_rnc: The state of the remote node context object to check. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 82 | * |
| 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 | */ |
| 87 | bool scic_sds_remote_node_context_is_ready( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 88 | struct scic_sds_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 89 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 90 | u32 current_state = sci_base_state_machine_get_state(&sci_rnc->state_machine); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 91 | |
| 92 | if (current_state == SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE) { |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 101 | * @sci_dev: The remote device to use to construct the RNC buffer. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 102 | * @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 Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 106 | static void scic_sds_remote_node_context_construct_buffer( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 107 | struct scic_sds_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 108 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 109 | struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 110 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
| 111 | union scu_remote_node_context *rnc; |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 112 | struct scic_sds_controller *scic; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 113 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 114 | scic = scic_sds_remote_device_get_controller(sci_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 115 | |
| 116 | rnc = scic_sds_controller_get_remote_node_context_buffer( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 117 | scic, sci_rnc->remote_node_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 118 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 119 | memset(rnc, 0, sizeof(union scu_remote_node_context) |
| 120 | * scic_sds_remote_device_node_count(sci_dev)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 121 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 122 | rnc->ssp.remote_node_index = sci_rnc->remote_node_index; |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 123 | rnc->ssp.remote_node_port_width = sci_dev->device_port_width; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 124 | rnc->ssp.logical_port_index = |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 125 | scic_sds_remote_device_get_port_index(sci_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 126 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 127 | rnc->ssp.remote_sas_address_hi = SCIC_SWAP_DWORD(sci_dev->device_address.high); |
| 128 | rnc->ssp.remote_sas_address_lo = SCIC_SWAP_DWORD(sci_dev->device_address.low); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 129 | |
| 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 Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 138 | if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 139 | rnc->ssp.connection_occupancy_timeout = |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 140 | scic->user_parameters.sds1.stp_max_occupancy_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 141 | rnc->ssp.connection_inactivity_timeout = |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 142 | scic->user_parameters.sds1.stp_inactivity_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 143 | } else { |
| 144 | rnc->ssp.connection_occupancy_timeout = |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 145 | scic->user_parameters.sds1.ssp_max_occupancy_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 146 | rnc->ssp.connection_inactivity_timeout = |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 147 | scic->user_parameters.sds1.ssp_inactivity_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | rnc->ssp.initial_arbitration_wait_time = 0; |
| 151 | |
| 152 | /* Open Address Frame Parameters */ |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 153 | rnc->ssp.oaf_connection_rate = sci_dev->connection_rate; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 154 | 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 161 | * @sci_rnc: |
| 162 | * @callback: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 163 | * @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 | */ |
| 169 | static void scic_sds_remote_node_context_setup_to_resume( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 170 | struct scic_sds_remote_node_context *sci_rnc, |
| 171 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 172 | void *callback_parameter) |
| 173 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 174 | if (sci_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) { |
| 175 | sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY; |
| 176 | sci_rnc->user_callback = callback; |
| 177 | sci_rnc->user_cookie = callback_parameter; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 183 | * @sci_rnc: |
| 184 | * @callback: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 185 | * @callback_parameter: |
| 186 | * |
| 187 | * This method will setup the remote node context object so it will transistion |
| 188 | * to its final state. none |
| 189 | */ |
| 190 | static void scic_sds_remote_node_context_setup_to_destory( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 191 | struct scic_sds_remote_node_context *sci_rnc, |
| 192 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 193 | void *callback_parameter) |
| 194 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 195 | sci_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL; |
| 196 | sci_rnc->user_callback = callback; |
| 197 | sci_rnc->user_cookie = callback_parameter; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 202 | * @sci_rnc: |
| 203 | * @callback: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 204 | * |
| 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 | */ |
| 208 | static enum sci_status scic_sds_remote_node_context_continue_to_resume_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 209 | struct scic_sds_remote_node_context *sci_rnc, |
| 210 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 211 | void *callback_parameter) |
| 212 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 213 | if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) { |
| 214 | sci_rnc->user_callback = callback; |
| 215 | sci_rnc->user_cookie = callback_parameter; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 216 | |
| 217 | return SCI_SUCCESS; |
| 218 | } |
| 219 | |
| 220 | return SCI_FAILURE_INVALID_STATE; |
| 221 | } |
| 222 | |
| 223 | /* --------------------------------------------------------------------------- */ |
| 224 | |
| 225 | static enum sci_status scic_sds_remote_node_context_default_destruct_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 226 | struct scic_sds_remote_node_context *sci_rnc, |
| 227 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 228 | void *callback_parameter) |
| 229 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 230 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 231 | "%s: SCIC Remote Node Context 0x%p requested to stop while " |
| 232 | "in unexpected state %d\n", |
| 233 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 234 | sci_rnc, |
| 235 | sci_base_state_machine_get_state(&sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 236 | |
| 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 | |
| 243 | static enum sci_status scic_sds_remote_node_context_default_suspend_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 244 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 245 | u32 suspend_type, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 246 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 247 | void *callback_parameter) |
| 248 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 249 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 250 | "%s: SCIC Remote Node Context 0x%p requested to suspend " |
| 251 | "while in wrong state %d\n", |
| 252 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 253 | sci_rnc, |
| 254 | sci_base_state_machine_get_state(&sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 255 | |
| 256 | return SCI_FAILURE_INVALID_STATE; |
| 257 | } |
| 258 | |
| 259 | static enum sci_status scic_sds_remote_node_context_default_resume_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 260 | struct scic_sds_remote_node_context *sci_rnc, |
| 261 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 262 | void *callback_parameter) |
| 263 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 264 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 265 | "%s: SCIC Remote Node Context 0x%p requested to resume " |
| 266 | "while in wrong state %d\n", |
| 267 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 268 | sci_rnc, |
| 269 | sci_base_state_machine_get_state(&sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 270 | |
| 271 | return SCI_FAILURE_INVALID_STATE; |
| 272 | } |
| 273 | |
| 274 | static enum sci_status scic_sds_remote_node_context_default_start_io_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 275 | struct scic_sds_remote_node_context *sci_rnc, |
| 276 | struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 277 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 278 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 279 | "%s: SCIC Remote Node Context 0x%p requested to start io " |
| 280 | "0x%p while in wrong state %d\n", |
| 281 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 282 | sci_rnc, |
| 283 | sci_req, |
| 284 | sci_base_state_machine_get_state(&sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 285 | |
| 286 | return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; |
| 287 | } |
| 288 | |
| 289 | static enum sci_status scic_sds_remote_node_context_default_start_task_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 290 | struct scic_sds_remote_node_context *sci_rnc, |
| 291 | struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 292 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 293 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 294 | "%s: SCIC Remote Node Context 0x%p requested to start " |
| 295 | "task 0x%p while in wrong state %d\n", |
| 296 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 297 | sci_rnc, |
| 298 | sci_req, |
| 299 | sci_base_state_machine_get_state(&sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 300 | |
| 301 | return SCI_FAILURE; |
| 302 | } |
| 303 | |
| 304 | static enum sci_status scic_sds_remote_node_context_default_event_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 305 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 306 | u32 event_code) |
| 307 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 308 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 309 | "%s: SCIC Remote Node Context 0x%p requested to process " |
| 310 | "event 0x%x while in wrong state %d\n", |
| 311 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 312 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 313 | event_code, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 314 | sci_base_state_machine_get_state(&sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 315 | |
| 316 | return SCI_FAILURE_INVALID_STATE; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 321 | * @sci_rnc: The rnc for which the task request is targeted. |
| 322 | * @sci_req: The request which is going to be started. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 323 | * |
| 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 | */ |
| 328 | static enum sci_status scic_sds_remote_node_context_success_start_task_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 329 | struct scic_sds_remote_node_context *sci_rnc, |
| 330 | struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 331 | { |
| 332 | return SCI_SUCCESS; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 337 | * @sci_rnc: |
| 338 | * @callback: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 339 | * @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 | */ |
| 346 | static enum sci_status scic_sds_remote_node_context_general_destruct_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 347 | struct scic_sds_remote_node_context *sci_rnc, |
| 348 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 349 | void *callback_parameter) |
| 350 | { |
| 351 | scic_sds_remote_node_context_setup_to_destory( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 352 | sci_rnc, callback, callback_parameter |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 353 | ); |
| 354 | |
| 355 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 356 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 357 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE |
| 358 | ); |
| 359 | |
| 360 | return SCI_SUCCESS; |
| 361 | } |
| 362 | |
| 363 | /* --------------------------------------------------------------------------- */ |
| 364 | |
| 365 | static enum sci_status scic_sds_remote_node_context_initial_state_resume_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 366 | struct scic_sds_remote_node_context *sci_rnc, |
| 367 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 368 | void *callback_parameter) |
| 369 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 370 | if (sci_rnc->remote_node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 371 | scic_sds_remote_node_context_setup_to_resume( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 372 | sci_rnc, callback, callback_parameter |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 373 | ); |
| 374 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 375 | scic_sds_remote_node_context_construct_buffer(sci_rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 376 | |
| 377 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 378 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 379 | 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 | |
| 390 | static enum sci_status scic_sds_remote_node_context_posting_state_event_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 391 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 392 | 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 401 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 402 | SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE |
| 403 | ); |
| 404 | break; |
| 405 | |
| 406 | default: |
| 407 | status = SCI_FAILURE; |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 408 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 409 | "%s: SCIC Remote Node Context 0x%p requested to " |
| 410 | "process unexpected event 0x%x while in posting " |
| 411 | "state\n", |
| 412 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 413 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 414 | event_code); |
| 415 | break; |
| 416 | } |
| 417 | |
| 418 | return status; |
| 419 | } |
| 420 | |
| 421 | /* --------------------------------------------------------------------------- */ |
| 422 | |
| 423 | static enum sci_status scic_sds_remote_node_context_invalidating_state_destruct_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 424 | struct scic_sds_remote_node_context *sci_rnc, |
| 425 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 426 | void *callback_parameter) |
| 427 | { |
| 428 | scic_sds_remote_node_context_setup_to_destory( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 429 | sci_rnc, callback, callback_parameter |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 430 | ); |
| 431 | |
| 432 | return SCI_SUCCESS; |
| 433 | } |
| 434 | |
| 435 | static enum sci_status scic_sds_remote_node_context_invalidating_state_event_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 436 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 437 | 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 444 | if (sci_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 445 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 446 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 447 | SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE |
| 448 | ); |
| 449 | } else { |
| 450 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 451 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 452 | 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 Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 462 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 463 | "%s: SCIC Remote Node Context 0x%p was " |
| 464 | "suspeneded by hardware while being " |
| 465 | "invalidated.\n", |
| 466 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 467 | sci_rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 468 | status = SCI_SUCCESS; |
| 469 | break; |
| 470 | |
| 471 | default: |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 472 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 473 | "%s: SCIC Remote Node Context 0x%p " |
| 474 | "requested to process event 0x%x while " |
| 475 | "in state %d.\n", |
| 476 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 477 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 478 | event_code, |
| 479 | sci_base_state_machine_get_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 480 | &sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 481 | status = SCI_FAILURE; |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return status; |
| 487 | } |
| 488 | |
| 489 | /* --------------------------------------------------------------------------- */ |
| 490 | |
| 491 | |
| 492 | static enum sci_status scic_sds_remote_node_context_resuming_state_event_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 493 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 494 | 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 502 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 503 | 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 Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 512 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 513 | "%s: SCIC Remote Node Context 0x%p was " |
| 514 | "suspeneded by hardware while being resumed.\n", |
| 515 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 516 | sci_rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 517 | status = SCI_SUCCESS; |
| 518 | break; |
| 519 | |
| 520 | default: |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 521 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 522 | "%s: SCIC Remote Node Context 0x%p requested " |
| 523 | "to process event 0x%x while in state %d.\n", |
| 524 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 525 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 526 | event_code, |
| 527 | sci_base_state_machine_get_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 528 | &sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 529 | status = SCI_FAILURE; |
| 530 | break; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | return status; |
| 535 | } |
| 536 | |
| 537 | /* --------------------------------------------------------------------------- */ |
| 538 | |
| 539 | /** |
| 540 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 541 | * @sci_rnc: The remote node context object being suspended. |
| 542 | * @callback: The callback when the suspension is complete. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 543 | * @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 | */ |
| 548 | static enum sci_status scic_sds_remote_node_context_ready_state_suspend_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 549 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 550 | u32 suspend_type, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 551 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 552 | void *callback_parameter) |
| 553 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 554 | sci_rnc->user_callback = callback; |
| 555 | sci_rnc->user_cookie = callback_parameter; |
| 556 | sci_rnc->suspension_code = suspend_type; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 557 | |
| 558 | if (suspend_type == SCI_SOFTWARE_SUSPENSION) { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 559 | scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc), |
| 560 | SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 564 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 565 | SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE |
| 566 | ); |
| 567 | |
| 568 | return SCI_SUCCESS; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 573 | * @sci_rnc: The rnc for which the io request is targeted. |
| 574 | * @sci_req: The request which is going to be started. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 575 | * |
| 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 | */ |
| 580 | static enum sci_status scic_sds_remote_node_context_ready_state_start_io_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 581 | struct scic_sds_remote_node_context *sci_rnc, |
| 582 | struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 583 | { |
| 584 | return SCI_SUCCESS; |
| 585 | } |
| 586 | |
| 587 | |
| 588 | static enum sci_status scic_sds_remote_node_context_ready_state_event_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 589 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 590 | 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 597 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 598 | SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE |
| 599 | ); |
| 600 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 601 | sci_rnc->suspension_code = scu_get_event_specifier(event_code); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 602 | status = SCI_SUCCESS; |
| 603 | break; |
| 604 | |
| 605 | case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: |
| 606 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 607 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 608 | SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE |
| 609 | ); |
| 610 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 611 | sci_rnc->suspension_code = scu_get_event_specifier(event_code); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 612 | status = SCI_SUCCESS; |
| 613 | break; |
| 614 | |
| 615 | default: |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 616 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 617 | "%s: SCIC Remote Node Context 0x%p requested to " |
| 618 | "process event 0x%x while in state %d.\n", |
| 619 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 620 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 621 | event_code, |
| 622 | sci_base_state_machine_get_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 623 | &sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 624 | |
| 625 | status = SCI_FAILURE; |
| 626 | break; |
| 627 | } |
| 628 | |
| 629 | return status; |
| 630 | } |
| 631 | |
| 632 | /* --------------------------------------------------------------------------- */ |
| 633 | |
| 634 | static enum sci_status scic_sds_remote_node_context_tx_suspended_state_resume_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 635 | struct scic_sds_remote_node_context *sci_rnc, |
| 636 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 637 | void *callback_parameter) |
| 638 | { |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 639 | struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc); |
| 640 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
| 641 | enum sci_status status = SCI_SUCCESS; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 642 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 643 | scic_sds_remote_node_context_setup_to_resume(sci_rnc, callback, |
| 644 | callback_parameter); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 645 | |
| 646 | /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */ |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 647 | if (dev->dev_type == SAS_END_DEV || dev_is_expander(dev)) |
| 648 | sci_base_state_machine_change_state(&sci_rnc->state_machine, |
| 649 | SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE); |
| 650 | else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { |
| 651 | if (sci_dev->is_direct_attached) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 652 | /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 653 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 654 | &sci_rnc->state_machine, |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 655 | SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 656 | } else { |
| 657 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 658 | &sci_rnc->state_machine, |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 659 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 660 | } |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 661 | } else |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 662 | status = SCI_FAILURE; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 663 | |
| 664 | return status; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 669 | * @sci_rnc: The remote node context which is to receive the task request. |
| 670 | * @sci_req: The task request to be transmitted to to the remote target |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 671 | * 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 | */ |
| 678 | static enum sci_status scic_sds_remote_node_context_suspended_start_task_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 679 | struct scic_sds_remote_node_context *sci_rnc, |
| 680 | struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 681 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 682 | scic_sds_remote_node_context_resume(sci_rnc, NULL, NULL); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 683 | |
| 684 | return SCI_SUCCESS; |
| 685 | } |
| 686 | |
| 687 | /* --------------------------------------------------------------------------- */ |
| 688 | |
| 689 | static enum sci_status scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 690 | struct scic_sds_remote_node_context *sci_rnc, |
| 691 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 692 | void *callback_parameter) |
| 693 | { |
| 694 | scic_sds_remote_node_context_setup_to_resume( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 695 | sci_rnc, callback, callback_parameter |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 696 | ); |
| 697 | |
| 698 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 699 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 700 | SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE |
| 701 | ); |
| 702 | |
| 703 | return SCI_FAILURE_INVALID_STATE; |
| 704 | } |
| 705 | |
| 706 | /* --------------------------------------------------------------------------- */ |
| 707 | |
| 708 | /** |
| 709 | * |
| 710 | * |
| 711 | * |
| 712 | */ |
| 713 | static enum sci_status scic_sds_remote_node_context_await_suspension_state_resume_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 714 | struct scic_sds_remote_node_context *sci_rnc, |
| 715 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 716 | void *callback_parameter) |
| 717 | { |
| 718 | scic_sds_remote_node_context_setup_to_resume( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 719 | sci_rnc, callback, callback_parameter |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 720 | ); |
| 721 | |
| 722 | return SCI_SUCCESS; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 727 | * @sci_rnc: The remote node context which is to receive the task request. |
| 728 | * @sci_req: The task request to be transmitted to to the remote target |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 729 | * 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 | */ |
| 736 | static enum sci_status scic_sds_remote_node_context_await_suspension_state_start_task_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 737 | struct scic_sds_remote_node_context *sci_rnc, |
| 738 | struct scic_sds_request *sci_req) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 739 | { |
| 740 | return SCI_SUCCESS; |
| 741 | } |
| 742 | |
| 743 | static enum sci_status scic_sds_remote_node_context_await_suspension_state_event_handler( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 744 | struct scic_sds_remote_node_context *sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 745 | 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 Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 752 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 753 | SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE |
| 754 | ); |
| 755 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 756 | sci_rnc->suspension_code = scu_get_event_specifier(event_code); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 757 | status = SCI_SUCCESS; |
| 758 | break; |
| 759 | |
| 760 | case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: |
| 761 | sci_base_state_machine_change_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 762 | &sci_rnc->state_machine, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 763 | SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE |
| 764 | ); |
| 765 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 766 | sci_rnc->suspension_code = scu_get_event_specifier(event_code); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 767 | status = SCI_SUCCESS; |
| 768 | break; |
| 769 | |
| 770 | default: |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 771 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 772 | "%s: SCIC Remote Node Context 0x%p requested to " |
| 773 | "process event 0x%x while in state %d.\n", |
| 774 | __func__, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 775 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 776 | event_code, |
| 777 | sci_base_state_machine_get_state( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 778 | &sci_rnc->state_machine)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 779 | |
| 780 | status = SCI_FAILURE; |
| 781 | break; |
| 782 | } |
| 783 | |
| 784 | return status; |
| 785 | } |
| 786 | |
| 787 | /* --------------------------------------------------------------------------- */ |
| 788 | |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 789 | static struct scic_sds_remote_node_context_handlers |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 790 | scic_sds_remote_node_context_state_handler_table[ |
| 791 | SCIC_SDS_REMOTE_NODE_CONTEXT_MAX_STATES] = |
| 792 | { |
| 793 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE */ |
| 794 | { |
| 795 | scic_sds_remote_node_context_default_destruct_handler, |
| 796 | scic_sds_remote_node_context_default_suspend_handler, |
| 797 | scic_sds_remote_node_context_initial_state_resume_handler, |
| 798 | scic_sds_remote_node_context_default_start_io_handler, |
| 799 | scic_sds_remote_node_context_default_start_task_handler, |
| 800 | scic_sds_remote_node_context_default_event_handler |
| 801 | }, |
| 802 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE */ |
| 803 | { |
| 804 | scic_sds_remote_node_context_general_destruct_handler, |
| 805 | scic_sds_remote_node_context_default_suspend_handler, |
| 806 | scic_sds_remote_node_context_continue_to_resume_handler, |
| 807 | scic_sds_remote_node_context_default_start_io_handler, |
| 808 | scic_sds_remote_node_context_default_start_task_handler, |
| 809 | scic_sds_remote_node_context_posting_state_event_handler |
| 810 | }, |
| 811 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE */ |
| 812 | { |
| 813 | scic_sds_remote_node_context_invalidating_state_destruct_handler, |
| 814 | scic_sds_remote_node_context_default_suspend_handler, |
| 815 | scic_sds_remote_node_context_continue_to_resume_handler, |
| 816 | scic_sds_remote_node_context_default_start_io_handler, |
| 817 | scic_sds_remote_node_context_default_start_task_handler, |
| 818 | scic_sds_remote_node_context_invalidating_state_event_handler |
| 819 | }, |
| 820 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE */ |
| 821 | { |
| 822 | scic_sds_remote_node_context_general_destruct_handler, |
| 823 | scic_sds_remote_node_context_default_suspend_handler, |
| 824 | scic_sds_remote_node_context_continue_to_resume_handler, |
| 825 | scic_sds_remote_node_context_default_start_io_handler, |
| 826 | scic_sds_remote_node_context_success_start_task_handler, |
| 827 | scic_sds_remote_node_context_resuming_state_event_handler |
| 828 | }, |
| 829 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE */ |
| 830 | { |
| 831 | scic_sds_remote_node_context_general_destruct_handler, |
| 832 | scic_sds_remote_node_context_ready_state_suspend_handler, |
| 833 | scic_sds_remote_node_context_default_resume_handler, |
| 834 | scic_sds_remote_node_context_ready_state_start_io_handler, |
| 835 | scic_sds_remote_node_context_success_start_task_handler, |
| 836 | scic_sds_remote_node_context_ready_state_event_handler |
| 837 | }, |
| 838 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE */ |
| 839 | { |
| 840 | scic_sds_remote_node_context_general_destruct_handler, |
| 841 | scic_sds_remote_node_context_default_suspend_handler, |
| 842 | scic_sds_remote_node_context_tx_suspended_state_resume_handler, |
| 843 | scic_sds_remote_node_context_default_start_io_handler, |
| 844 | scic_sds_remote_node_context_suspended_start_task_handler, |
| 845 | scic_sds_remote_node_context_default_event_handler |
| 846 | }, |
| 847 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE */ |
| 848 | { |
| 849 | scic_sds_remote_node_context_general_destruct_handler, |
| 850 | scic_sds_remote_node_context_default_suspend_handler, |
| 851 | scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler, |
| 852 | scic_sds_remote_node_context_default_start_io_handler, |
| 853 | scic_sds_remote_node_context_suspended_start_task_handler, |
| 854 | scic_sds_remote_node_context_default_event_handler |
| 855 | }, |
| 856 | /* SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE */ |
| 857 | { |
| 858 | scic_sds_remote_node_context_general_destruct_handler, |
| 859 | scic_sds_remote_node_context_default_suspend_handler, |
| 860 | scic_sds_remote_node_context_await_suspension_state_resume_handler, |
| 861 | scic_sds_remote_node_context_default_start_io_handler, |
| 862 | scic_sds_remote_node_context_await_suspension_state_start_task_handler, |
| 863 | scic_sds_remote_node_context_await_suspension_state_event_handler |
| 864 | } |
| 865 | }; |
| 866 | |
| 867 | /* |
| 868 | * ***************************************************************************** |
| 869 | * * REMOTE NODE CONTEXT PRIVATE METHODS |
| 870 | * ***************************************************************************** */ |
| 871 | |
| 872 | /** |
| 873 | * |
| 874 | * |
| 875 | * This method just calls the user callback function and then resets the |
| 876 | * callback. |
| 877 | */ |
| 878 | static void scic_sds_remote_node_context_notify_user( |
| 879 | struct scic_sds_remote_node_context *rnc) |
| 880 | { |
| 881 | if (rnc->user_callback != NULL) { |
| 882 | (*rnc->user_callback)(rnc->user_cookie); |
| 883 | |
| 884 | rnc->user_callback = NULL; |
| 885 | rnc->user_cookie = NULL; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * |
| 891 | * |
| 892 | * This method will continue the remote node context state machine by |
| 893 | * requesting to resume the remote node context state machine from its current |
| 894 | * state. |
| 895 | */ |
| 896 | static void scic_sds_remote_node_context_continue_state_transitions( |
| 897 | struct scic_sds_remote_node_context *rnc) |
| 898 | { |
| 899 | if (rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) { |
| 900 | rnc->state_handlers->resume_handler( |
| 901 | rnc, rnc->user_callback, rnc->user_cookie |
| 902 | ); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 908 | * @sci_rnc: The remote node context object that is to be validated. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 909 | * |
| 910 | * This method will mark the rnc buffer as being valid and post the request to |
| 911 | * the hardware. none |
| 912 | */ |
| 913 | static void scic_sds_remote_node_context_validate_context_buffer( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 914 | struct scic_sds_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 915 | { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 916 | struct scic_sds_remote_device *sci_dev = rnc_to_dev(sci_rnc); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 917 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 918 | union scu_remote_node_context *rnc_buffer; |
| 919 | |
| 920 | rnc_buffer = scic_sds_controller_get_remote_node_context_buffer( |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 921 | scic_sds_remote_device_get_controller(sci_dev), |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 922 | sci_rnc->remote_node_index |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 923 | ); |
| 924 | |
| 925 | rnc_buffer->ssp.is_valid = true; |
| 926 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 927 | if (!sci_dev->is_direct_attached && |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 928 | (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))) { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 929 | scic_sds_remote_device_post_request(sci_dev, |
| 930 | SCU_CONTEXT_COMMAND_POST_RNC_96); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 931 | } else { |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 932 | scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_32); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 933 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 934 | if (sci_dev->is_direct_attached) { |
| 935 | scic_sds_port_setup_transports(sci_dev->owning_port, |
| 936 | sci_rnc->remote_node_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /** |
| 942 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 943 | * @sci_rnc: The remote node context object that is to be invalidated. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 944 | * |
| 945 | * This method will update the RNC buffer and post the invalidate request. none |
| 946 | */ |
| 947 | static void scic_sds_remote_node_context_invalidate_context_buffer( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 948 | struct scic_sds_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 949 | { |
| 950 | union scu_remote_node_context *rnc_buffer; |
| 951 | |
| 952 | rnc_buffer = scic_sds_controller_get_remote_node_context_buffer( |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 953 | scic_sds_remote_device_get_controller(rnc_to_dev(sci_rnc)), |
| 954 | sci_rnc->remote_node_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 955 | |
| 956 | rnc_buffer->ssp.is_valid = false; |
| 957 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 958 | scic_sds_remote_device_post_request(rnc_to_dev(sci_rnc), |
| 959 | SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* |
| 963 | * ***************************************************************************** |
| 964 | * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS |
| 965 | * ***************************************************************************** */ |
| 966 | |
| 967 | /** |
| 968 | * |
| 969 | * |
| 970 | * |
| 971 | */ |
| 972 | static void scic_sds_remote_node_context_initial_state_enter( |
| 973 | struct sci_base_object *object) |
| 974 | { |
| 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 | */ |
| 1003 | static void scic_sds_remote_node_context_posting_state_enter( |
| 1004 | struct sci_base_object *object) |
| 1005 | { |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 1006 | struct scic_sds_remote_node_context *sci_rnc; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1007 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 1008 | sci_rnc = (struct scic_sds_remote_node_context *)object; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1009 | |
| 1010 | SET_STATE_HANDLER( |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 1011 | sci_rnc, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1012 | scic_sds_remote_node_context_state_handler_table, |
| 1013 | SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE |
| 1014 | ); |
| 1015 | |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 1016 | scic_sds_remote_node_context_validate_context_buffer(sci_rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * |
| 1021 | * |
| 1022 | * |
| 1023 | */ |
| 1024 | static void scic_sds_remote_node_context_invalidating_state_enter( |
| 1025 | struct sci_base_object *object) |
| 1026 | { |
| 1027 | struct scic_sds_remote_node_context *rnc; |
| 1028 | |
| 1029 | rnc = (struct scic_sds_remote_node_context *)object; |
| 1030 | |
| 1031 | SET_STATE_HANDLER( |
| 1032 | rnc, |
| 1033 | scic_sds_remote_node_context_state_handler_table, |
| 1034 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE |
| 1035 | ); |
| 1036 | |
| 1037 | scic_sds_remote_node_context_invalidate_context_buffer(rnc); |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * |
| 1042 | * |
| 1043 | * |
| 1044 | */ |
| 1045 | static void scic_sds_remote_node_context_resuming_state_enter( |
| 1046 | struct sci_base_object *object) |
| 1047 | { |
| 1048 | struct scic_sds_remote_node_context *rnc; |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 1049 | struct scic_sds_remote_device *sci_dev; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1050 | struct domain_device *dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1051 | |
| 1052 | rnc = (struct scic_sds_remote_node_context *)object; |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 1053 | sci_dev = rnc_to_dev(rnc); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1054 | dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1055 | |
| 1056 | SET_STATE_HANDLER( |
| 1057 | rnc, |
| 1058 | scic_sds_remote_node_context_state_handler_table, |
| 1059 | SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE |
| 1060 | ); |
| 1061 | |
Henryk Dembkowski | 2462146 | 2011-02-23 00:08:52 -0800 | [diff] [blame] | 1062 | /* |
| 1063 | * For direct attached SATA devices we need to clear the TLCR |
| 1064 | * NCQ to TCi tag mapping on the phy and in cases where we |
| 1065 | * resume because of a target reset we also need to update |
| 1066 | * the STPTLDARNI register with the RNi of the device |
| 1067 | */ |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1068 | if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) && |
| 1069 | sci_dev->is_direct_attached) |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 1070 | scic_sds_port_setup_transports(sci_dev->owning_port, |
| 1071 | rnc->remote_node_index); |
Henryk Dembkowski | 2462146 | 2011-02-23 00:08:52 -0800 | [diff] [blame] | 1072 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 1073 | scic_sds_remote_device_post_request(sci_dev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * |
| 1078 | * |
| 1079 | * |
| 1080 | */ |
| 1081 | static void scic_sds_remote_node_context_ready_state_enter( |
| 1082 | struct sci_base_object *object) |
| 1083 | { |
| 1084 | struct scic_sds_remote_node_context *rnc; |
| 1085 | |
| 1086 | rnc = (struct scic_sds_remote_node_context *)object; |
| 1087 | |
| 1088 | SET_STATE_HANDLER( |
| 1089 | rnc, |
| 1090 | scic_sds_remote_node_context_state_handler_table, |
| 1091 | SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE |
| 1092 | ); |
| 1093 | |
| 1094 | rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; |
| 1095 | |
| 1096 | if (rnc->user_callback != NULL) { |
| 1097 | scic_sds_remote_node_context_notify_user(rnc); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * |
| 1103 | * |
| 1104 | * |
| 1105 | */ |
| 1106 | static void scic_sds_remote_node_context_tx_suspended_state_enter( |
| 1107 | struct sci_base_object *object) |
| 1108 | { |
| 1109 | struct scic_sds_remote_node_context *rnc; |
| 1110 | |
| 1111 | rnc = (struct scic_sds_remote_node_context *)object; |
| 1112 | |
| 1113 | SET_STATE_HANDLER( |
| 1114 | rnc, |
| 1115 | scic_sds_remote_node_context_state_handler_table, |
| 1116 | SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE |
| 1117 | ); |
| 1118 | |
| 1119 | scic_sds_remote_node_context_continue_state_transitions(rnc); |
| 1120 | } |
| 1121 | |
| 1122 | /** |
| 1123 | * |
| 1124 | * |
| 1125 | * |
| 1126 | */ |
| 1127 | static void scic_sds_remote_node_context_tx_rx_suspended_state_enter( |
| 1128 | struct sci_base_object *object) |
| 1129 | { |
| 1130 | struct scic_sds_remote_node_context *rnc; |
| 1131 | |
| 1132 | rnc = (struct scic_sds_remote_node_context *)object; |
| 1133 | |
| 1134 | SET_STATE_HANDLER( |
| 1135 | rnc, |
| 1136 | scic_sds_remote_node_context_state_handler_table, |
| 1137 | SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE |
| 1138 | ); |
| 1139 | |
| 1140 | scic_sds_remote_node_context_continue_state_transitions(rnc); |
| 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * |
| 1145 | * |
| 1146 | * |
| 1147 | */ |
| 1148 | static void scic_sds_remote_node_context_await_suspension_state_enter( |
| 1149 | struct sci_base_object *object) |
| 1150 | { |
| 1151 | struct scic_sds_remote_node_context *rnc; |
| 1152 | |
| 1153 | rnc = (struct scic_sds_remote_node_context *)object; |
| 1154 | |
| 1155 | SET_STATE_HANDLER( |
| 1156 | rnc, |
| 1157 | scic_sds_remote_node_context_state_handler_table, |
| 1158 | SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE |
| 1159 | ); |
| 1160 | } |
| 1161 | |
| 1162 | /* --------------------------------------------------------------------------- */ |
| 1163 | |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 1164 | static const struct sci_base_state scic_sds_remote_node_context_state_table[] = { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1165 | [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE] = { |
| 1166 | .enter_state = scic_sds_remote_node_context_initial_state_enter, |
| 1167 | }, |
| 1168 | [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE] = { |
| 1169 | .enter_state = scic_sds_remote_node_context_posting_state_enter, |
| 1170 | }, |
| 1171 | [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE] = { |
| 1172 | .enter_state = scic_sds_remote_node_context_invalidating_state_enter, |
| 1173 | }, |
| 1174 | [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE] = { |
| 1175 | .enter_state = scic_sds_remote_node_context_resuming_state_enter, |
| 1176 | }, |
| 1177 | [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE] = { |
| 1178 | .enter_state = scic_sds_remote_node_context_ready_state_enter, |
| 1179 | }, |
| 1180 | [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE] = { |
| 1181 | .enter_state = scic_sds_remote_node_context_tx_suspended_state_enter, |
| 1182 | }, |
| 1183 | [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE] = { |
| 1184 | .enter_state = scic_sds_remote_node_context_tx_rx_suspended_state_enter, |
| 1185 | }, |
| 1186 | [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE] = { |
| 1187 | .enter_state = scic_sds_remote_node_context_await_suspension_state_enter, |
| 1188 | }, |
| 1189 | }; |
| 1190 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 1191 | void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context *rnc, |
| 1192 | u16 remote_node_index) |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 1193 | { |
| 1194 | memset(rnc, 0, sizeof(struct scic_sds_remote_node_context)); |
| 1195 | |
| 1196 | rnc->remote_node_index = remote_node_index; |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 1197 | rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; |
| 1198 | |
| 1199 | sci_base_state_machine_construct( |
| 1200 | &rnc->state_machine, |
| 1201 | &rnc->parent, |
| 1202 | scic_sds_remote_node_context_state_table, |
| 1203 | SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE |
| 1204 | ); |
| 1205 | |
| 1206 | sci_base_state_machine_start(&rnc->state_machine); |
| 1207 | } |