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 | */ |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 55 | #include <scsi/sas_ata.h> |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 56 | #include "host.h" |
Edmund Nadolski | 12ef654 | 2011-06-02 00:10:50 +0000 | [diff] [blame] | 57 | #include "isci.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 58 | #include "remote_device.h" |
| 59 | #include "remote_node_context.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 60 | #include "scu_event_codes.h" |
| 61 | #include "scu_task_context.h" |
| 62 | |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 63 | #undef C |
| 64 | #define C(a) (#a) |
| 65 | const char *rnc_state_name(enum scis_sds_remote_node_context_states state) |
| 66 | { |
| 67 | static const char * const strings[] = RNC_STATES; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 68 | |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 69 | return strings[state]; |
| 70 | } |
| 71 | #undef C |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 75 | * @sci_rnc: The state of the remote node context object to check. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 76 | * |
| 77 | * This method will return true if the remote node context is in a READY state |
| 78 | * otherwise it will return false bool true if the remote node context is in |
| 79 | * the ready state. false if the remote node context is not in the ready state. |
| 80 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 81 | bool sci_remote_node_context_is_ready( |
| 82 | struct sci_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 83 | { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 84 | u32 current_state = sci_rnc->sm.current_state_id; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 85 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 86 | if (current_state == SCI_RNC_READY) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 87 | return true; |
| 88 | } |
| 89 | |
| 90 | return false; |
| 91 | } |
| 92 | |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame^] | 93 | bool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc) |
| 94 | { |
| 95 | u32 current_state = sci_rnc->sm.current_state_id; |
| 96 | |
| 97 | if (current_state == SCI_RNC_TX_RX_SUSPENDED) |
| 98 | return true; |
| 99 | return false; |
| 100 | } |
| 101 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 102 | static union scu_remote_node_context *sci_rnc_by_id(struct isci_host *ihost, u16 id) |
| 103 | { |
| 104 | if (id < ihost->remote_node_entries && |
| 105 | ihost->device_table[id]) |
| 106 | return &ihost->remote_node_context_table[id]; |
| 107 | |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | static void sci_remote_node_context_construct_buffer(struct sci_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 112 | { |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 113 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
| 114 | struct domain_device *dev = idev->domain_dev; |
Dan Williams | 1f4fa1f | 2011-04-26 11:44:06 -0700 | [diff] [blame] | 115 | int rni = sci_rnc->remote_node_index; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 116 | union scu_remote_node_context *rnc; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 117 | struct isci_host *ihost; |
Dan Williams | a3d568f0 | 2011-04-26 09:41:52 -0700 | [diff] [blame] | 118 | __le64 sas_addr; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 119 | |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame] | 120 | ihost = idev->owning_port->owning_controller; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 121 | rnc = sci_rnc_by_id(ihost, rni); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 122 | |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 123 | memset(rnc, 0, sizeof(union scu_remote_node_context) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 124 | * sci_remote_device_node_count(idev)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 125 | |
Dan Williams | 1f4fa1f | 2011-04-26 11:44:06 -0700 | [diff] [blame] | 126 | rnc->ssp.remote_node_index = rni; |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 127 | rnc->ssp.remote_node_port_width = idev->device_port_width; |
| 128 | rnc->ssp.logical_port_index = idev->owning_port->physical_port_index; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 129 | |
Dan Williams | a3d568f0 | 2011-04-26 09:41:52 -0700 | [diff] [blame] | 130 | /* sas address is __be64, context ram format is __le64 */ |
| 131 | sas_addr = cpu_to_le64(SAS_ADDR(dev->sas_addr)); |
| 132 | rnc->ssp.remote_sas_address_hi = upper_32_bits(sas_addr); |
| 133 | rnc->ssp.remote_sas_address_lo = lower_32_bits(sas_addr); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 134 | |
| 135 | rnc->ssp.nexus_loss_timer_enable = true; |
| 136 | rnc->ssp.check_bit = false; |
| 137 | rnc->ssp.is_valid = false; |
| 138 | rnc->ssp.is_remote_node_context = true; |
| 139 | rnc->ssp.function_number = 0; |
| 140 | |
| 141 | rnc->ssp.arbitration_wait_time = 0; |
| 142 | |
Dan Williams | 11cc518 | 2012-02-01 00:23:10 -0800 | [diff] [blame] | 143 | if (dev_is_sata(dev)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 144 | rnc->ssp.connection_occupancy_timeout = |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 145 | ihost->user_parameters.stp_max_occupancy_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 146 | rnc->ssp.connection_inactivity_timeout = |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 147 | ihost->user_parameters.stp_inactivity_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 148 | } else { |
| 149 | rnc->ssp.connection_occupancy_timeout = |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 150 | ihost->user_parameters.ssp_max_occupancy_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 151 | rnc->ssp.connection_inactivity_timeout = |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 152 | ihost->user_parameters.ssp_inactivity_timeout; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | rnc->ssp.initial_arbitration_wait_time = 0; |
| 156 | |
| 157 | /* Open Address Frame Parameters */ |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 158 | rnc->ssp.oaf_connection_rate = idev->connection_rate; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 159 | rnc->ssp.oaf_features = 0; |
| 160 | rnc->ssp.oaf_source_zone_group = 0; |
| 161 | rnc->ssp.oaf_more_compatibility_features = 0; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 166 | * @sci_rnc: |
| 167 | * @callback: |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 168 | * @callback_parameter: |
| 169 | * |
| 170 | * This method will setup the remote node context object so it will transition |
| 171 | * to its ready state. If the remote node context is already setup to |
| 172 | * transition to its final state then this function does nothing. none |
| 173 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 174 | static void sci_remote_node_context_setup_to_resume( |
| 175 | struct sci_remote_node_context *sci_rnc, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 176 | scics_sds_remote_node_context_callback callback, |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 177 | void *callback_parameter, |
| 178 | enum sci_remote_node_context_destination_state dest_param) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 179 | { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 180 | if (sci_rnc->destination_state != RNC_DEST_FINAL) { |
| 181 | sci_rnc->destination_state = dest_param; |
| 182 | if (callback != NULL) { |
| 183 | sci_rnc->user_callback = callback; |
| 184 | sci_rnc->user_cookie = callback_parameter; |
| 185 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 189 | static void sci_remote_node_context_setup_to_destroy( |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 190 | struct sci_remote_node_context *sci_rnc, |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 191 | scics_sds_remote_node_context_callback callback, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 192 | void *callback_parameter) |
| 193 | { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 194 | sci_rnc->destination_state = RNC_DEST_FINAL; |
Dave Jiang | e2023b8 | 2011-04-21 05:34:49 +0000 | [diff] [blame] | 195 | sci_rnc->user_callback = callback; |
| 196 | sci_rnc->user_cookie = callback_parameter; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 199 | /** |
| 200 | * |
| 201 | * |
| 202 | * This method just calls the user callback function and then resets the |
| 203 | * callback. |
| 204 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 205 | static void sci_remote_node_context_notify_user( |
| 206 | struct sci_remote_node_context *rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 207 | { |
| 208 | if (rnc->user_callback != NULL) { |
| 209 | (*rnc->user_callback)(rnc->user_cookie); |
| 210 | |
| 211 | rnc->user_callback = NULL; |
| 212 | rnc->user_cookie = NULL; |
| 213 | } |
| 214 | } |
| 215 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 216 | static void sci_remote_node_context_continue_state_transitions(struct sci_remote_node_context *rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 217 | { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 218 | if ((rnc->destination_state == RNC_DEST_READY) || |
| 219 | (rnc->destination_state == RNC_DEST_SUSPENDED_RESUME)) { |
| 220 | rnc->destination_state = RNC_DEST_READY; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 221 | sci_remote_node_context_resume(rnc, rnc->user_callback, |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 222 | rnc->user_cookie); |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 223 | } else |
| 224 | rnc->destination_state = RNC_DEST_UNSPECIFIED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 227 | static void sci_remote_node_context_validate_context_buffer(struct sci_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 228 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 229 | union scu_remote_node_context *rnc_buffer; |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 230 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
| 231 | struct domain_device *dev = idev->domain_dev; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 232 | struct isci_host *ihost = idev->owning_port->owning_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 233 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 234 | rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 235 | |
| 236 | rnc_buffer->ssp.is_valid = true; |
| 237 | |
Dan Williams | 11cc518 | 2012-02-01 00:23:10 -0800 | [diff] [blame] | 238 | if (dev_is_sata(dev) && dev->parent) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 239 | sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_96); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 240 | } else { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 241 | sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_32); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 242 | |
Dan Williams | 11cc518 | 2012-02-01 00:23:10 -0800 | [diff] [blame] | 243 | if (!dev->parent) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 244 | sci_port_setup_transports(idev->owning_port, |
| 245 | sci_rnc->remote_node_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 249 | static void sci_remote_node_context_invalidate_context_buffer(struct sci_remote_node_context *sci_rnc) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 250 | { |
| 251 | union scu_remote_node_context *rnc_buffer; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 252 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
| 253 | struct isci_host *ihost = idev->owning_port->owning_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 254 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 255 | rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 256 | |
| 257 | rnc_buffer->ssp.is_valid = false; |
| 258 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 259 | sci_remote_device_post_request(rnc_to_dev(sci_rnc), |
| 260 | SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 263 | static void sci_remote_node_context_initial_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 264 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 265 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 266 | |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 267 | /* Check to see if we have gotten back to the initial state because |
| 268 | * someone requested to destroy the remote node context object. |
| 269 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 270 | if (sm->previous_state_id == SCI_RNC_INVALIDATING) { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 271 | rnc->destination_state = RNC_DEST_UNSPECIFIED; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 272 | sci_remote_node_context_notify_user(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 276 | static void sci_remote_node_context_posting_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 277 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 278 | struct sci_remote_node_context *sci_rnc = container_of(sm, typeof(*sci_rnc), sm); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 279 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 280 | sci_remote_node_context_validate_context_buffer(sci_rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 283 | static void sci_remote_node_context_invalidating_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 284 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 285 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 286 | |
Jeff Skirvin | aa20d93 | 2012-03-08 22:41:56 -0800 | [diff] [blame] | 287 | /* Terminate all outstanding requests. */ |
| 288 | sci_remote_device_terminate_requests(rnc_to_dev(rnc)); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 289 | sci_remote_node_context_invalidate_context_buffer(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 292 | static void sci_remote_node_context_resuming_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 293 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 294 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 295 | struct isci_remote_device *idev; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 296 | struct domain_device *dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 297 | |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 298 | idev = rnc_to_dev(rnc); |
| 299 | dev = idev->domain_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 300 | |
Henryk Dembkowski | 2462146 | 2011-02-23 00:08:52 -0800 | [diff] [blame] | 301 | /* |
| 302 | * For direct attached SATA devices we need to clear the TLCR |
| 303 | * NCQ to TCi tag mapping on the phy and in cases where we |
| 304 | * resume because of a target reset we also need to update |
| 305 | * the STPTLDARNI register with the RNi of the device |
| 306 | */ |
Dan Williams | 11cc518 | 2012-02-01 00:23:10 -0800 | [diff] [blame] | 307 | if (dev_is_sata(dev) && !dev->parent) |
| 308 | sci_port_setup_transports(idev->owning_port, rnc->remote_node_index); |
Henryk Dembkowski | 2462146 | 2011-02-23 00:08:52 -0800 | [diff] [blame] | 309 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 310 | sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 313 | static void sci_remote_node_context_ready_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 314 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 315 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 316 | enum sci_remote_node_context_destination_state dest_select; |
| 317 | scics_sds_remote_node_context_callback usr_cb = rnc->user_callback; |
| 318 | void *usr_param = rnc->user_cookie; |
| 319 | int tell_user = 1; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 320 | |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 321 | dest_select = rnc->destination_state; |
| 322 | rnc->destination_state = RNC_DEST_UNSPECIFIED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 323 | |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 324 | if ((dest_select == RNC_DEST_SUSPENDED) || |
| 325 | (dest_select == RNC_DEST_SUSPENDED_RESUME)) { |
| 326 | sci_remote_node_context_suspend( |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 327 | rnc, rnc->suspend_reason, |
| 328 | SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT); |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 329 | |
| 330 | if (dest_select == RNC_DEST_SUSPENDED_RESUME) { |
| 331 | sci_remote_node_context_resume(rnc, usr_cb, usr_param); |
| 332 | tell_user = 0; /* Wait until ready again. */ |
| 333 | } |
| 334 | } |
| 335 | if (tell_user && rnc->user_callback) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 336 | sci_remote_node_context_notify_user(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 339 | static void sci_remote_node_context_tx_suspended_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 340 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 341 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 342 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 343 | sci_remote_node_context_continue_state_transitions(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 346 | static void sci_remote_node_context_tx_rx_suspended_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 347 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 348 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 349 | struct isci_remote_device *idev = rnc_to_dev(rnc); |
| 350 | struct isci_host *ihost = idev->owning_port->owning_controller; |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame^] | 351 | u32 new_count = rnc->suspend_count + 1; |
| 352 | |
| 353 | if (new_count == 0) |
| 354 | rnc->suspend_count = 1; |
| 355 | else |
| 356 | rnc->suspend_count = new_count; |
| 357 | smp_wmb(); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 358 | |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 359 | /* Terminate outstanding requests pending abort. */ |
| 360 | sci_remote_device_abort_requests_pending_abort(idev); |
| 361 | |
| 362 | wake_up(&ihost->eventq); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 363 | sci_remote_node_context_continue_state_transitions(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 366 | static void sci_remote_node_context_await_suspend_state_exit( |
| 367 | struct sci_base_state_machine *sm) |
| 368 | { |
| 369 | struct sci_remote_node_context *rnc |
| 370 | = container_of(sm, typeof(*rnc), sm); |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 371 | struct isci_remote_device *idev = rnc_to_dev(rnc); |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 372 | |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 373 | if (dev_is_sata(idev->domain_dev)) |
| 374 | isci_dev_set_hang_detection_timeout(idev, 0); |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 377 | static const struct sci_base_state sci_remote_node_context_state_table[] = { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 378 | [SCI_RNC_INITIAL] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 379 | .enter_state = sci_remote_node_context_initial_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 380 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 381 | [SCI_RNC_POSTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 382 | .enter_state = sci_remote_node_context_posting_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 383 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 384 | [SCI_RNC_INVALIDATING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 385 | .enter_state = sci_remote_node_context_invalidating_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 386 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 387 | [SCI_RNC_RESUMING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 388 | .enter_state = sci_remote_node_context_resuming_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 389 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 390 | [SCI_RNC_READY] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 391 | .enter_state = sci_remote_node_context_ready_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 392 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 393 | [SCI_RNC_TX_SUSPENDED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 394 | .enter_state = sci_remote_node_context_tx_suspended_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 395 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 396 | [SCI_RNC_TX_RX_SUSPENDED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 397 | .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 398 | }, |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 399 | [SCI_RNC_AWAIT_SUSPENSION] = { |
| 400 | .exit_state = sci_remote_node_context_await_suspend_state_exit, |
| 401 | }, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 402 | }; |
| 403 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 404 | void sci_remote_node_context_construct(struct sci_remote_node_context *rnc, |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 405 | u16 remote_node_index) |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 406 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 407 | memset(rnc, 0, sizeof(struct sci_remote_node_context)); |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 408 | |
| 409 | rnc->remote_node_index = remote_node_index; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 410 | rnc->destination_state = RNC_DEST_UNSPECIFIED; |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 411 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 412 | sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL); |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 413 | } |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 414 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 415 | enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc, |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 416 | u32 event_code) |
| 417 | { |
| 418 | enum scis_sds_remote_node_context_states state; |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 419 | u32 next_state; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 420 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 421 | state = sci_rnc->sm.current_state_id; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 422 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 423 | case SCI_RNC_POSTING: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 424 | switch (scu_get_event_code(event_code)) { |
| 425 | case SCU_EVENT_POST_RNC_COMPLETE: |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 426 | sci_change_state(&sci_rnc->sm, SCI_RNC_READY); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 427 | break; |
| 428 | default: |
| 429 | goto out; |
| 430 | } |
| 431 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 432 | case SCI_RNC_INVALIDATING: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 433 | if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 434 | if (sci_rnc->destination_state == RNC_DEST_FINAL) |
| 435 | next_state = SCI_RNC_INITIAL; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 436 | else |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 437 | next_state = SCI_RNC_POSTING; |
| 438 | sci_change_state(&sci_rnc->sm, next_state); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 439 | } else { |
| 440 | switch (scu_get_event_type(event_code)) { |
| 441 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 442 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 443 | /* We really dont care if the hardware is going to suspend |
| 444 | * the device since it's being invalidated anyway */ |
| 445 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 446 | "%s: SCIC Remote Node Context 0x%p was " |
| 447 | "suspeneded by hardware while being " |
| 448 | "invalidated.\n", __func__, sci_rnc); |
| 449 | break; |
| 450 | default: |
| 451 | goto out; |
| 452 | } |
| 453 | } |
| 454 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 455 | case SCI_RNC_RESUMING: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 456 | if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 457 | sci_change_state(&sci_rnc->sm, SCI_RNC_READY); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 458 | } else { |
| 459 | switch (scu_get_event_type(event_code)) { |
| 460 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 461 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 462 | /* We really dont care if the hardware is going to suspend |
| 463 | * the device since it's being resumed anyway */ |
| 464 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 465 | "%s: SCIC Remote Node Context 0x%p was " |
| 466 | "suspeneded by hardware while being resumed.\n", |
| 467 | __func__, sci_rnc); |
| 468 | break; |
| 469 | default: |
| 470 | goto out; |
| 471 | } |
| 472 | } |
| 473 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 474 | case SCI_RNC_READY: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 475 | switch (scu_get_event_type(event_code)) { |
| 476 | case SCU_EVENT_TL_RNC_SUSPEND_TX: |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 477 | sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED); |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 478 | sci_rnc->suspend_type = scu_get_event_type(event_code); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 479 | break; |
| 480 | case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 481 | sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED); |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 482 | sci_rnc->suspend_type = scu_get_event_type(event_code); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 483 | break; |
| 484 | default: |
| 485 | goto out; |
| 486 | } |
| 487 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 488 | case SCI_RNC_AWAIT_SUSPENSION: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 489 | switch (scu_get_event_type(event_code)) { |
| 490 | case SCU_EVENT_TL_RNC_SUSPEND_TX: |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 491 | next_state = SCI_RNC_TX_SUSPENDED; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 492 | break; |
| 493 | case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 494 | next_state = SCI_RNC_TX_RX_SUSPENDED; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 495 | break; |
| 496 | default: |
| 497 | goto out; |
| 498 | } |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 499 | if (sci_rnc->suspend_type == scu_get_event_type(event_code)) |
| 500 | sci_change_state(&sci_rnc->sm, next_state); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 501 | break; |
| 502 | default: |
| 503 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 504 | "%s: invalid state: %s\n", __func__, |
| 505 | rnc_state_name(state)); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 506 | return SCI_FAILURE_INVALID_STATE; |
| 507 | } |
| 508 | return SCI_SUCCESS; |
| 509 | |
| 510 | out: |
| 511 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 512 | "%s: code: %#x state: %s\n", __func__, event_code, |
| 513 | rnc_state_name(state)); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 514 | return SCI_FAILURE; |
| 515 | |
| 516 | } |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 517 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 518 | enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc, |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 519 | scics_sds_remote_node_context_callback cb_fn, |
| 520 | void *cb_p) |
| 521 | { |
| 522 | enum scis_sds_remote_node_context_states state; |
| 523 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 524 | state = sci_rnc->sm.current_state_id; |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 525 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 526 | case SCI_RNC_INVALIDATING: |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 527 | sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 528 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 529 | case SCI_RNC_POSTING: |
| 530 | case SCI_RNC_RESUMING: |
| 531 | case SCI_RNC_READY: |
| 532 | case SCI_RNC_TX_SUSPENDED: |
| 533 | case SCI_RNC_TX_RX_SUSPENDED: |
| 534 | case SCI_RNC_AWAIT_SUSPENSION: |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 535 | sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 536 | sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 537 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 538 | case SCI_RNC_INITIAL: |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 539 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 540 | "%s: invalid state: %s\n", __func__, |
| 541 | rnc_state_name(state)); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 542 | /* We have decided that the destruct request on the remote node context |
| 543 | * can not fail since it is either in the initial/destroyed state or is |
| 544 | * can be destroyed. |
| 545 | */ |
| 546 | return SCI_SUCCESS; |
| 547 | default: |
| 548 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 549 | "%s: invalid state %s\n", __func__, |
| 550 | rnc_state_name(state)); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 551 | return SCI_FAILURE_INVALID_STATE; |
| 552 | } |
| 553 | } |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 554 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 555 | enum sci_status sci_remote_node_context_suspend( |
| 556 | struct sci_remote_node_context *sci_rnc, |
| 557 | enum sci_remote_node_suspension_reasons suspend_reason, |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 558 | u32 suspend_type) |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 559 | { |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 560 | enum scis_sds_remote_node_context_states state |
| 561 | = sci_rnc->sm.current_state_id; |
| 562 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
| 563 | enum sci_status status = SCI_FAILURE_INVALID_STATE; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 564 | enum sci_remote_node_context_destination_state dest_param = |
| 565 | RNC_DEST_UNSPECIFIED; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 566 | |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 567 | dev_dbg(scirdev_to_dev(idev), |
| 568 | "%s: current state %d, current suspend_type %x dest state %d," |
| 569 | " arg suspend_reason %d, arg suspend_type %x", |
| 570 | __func__, state, sci_rnc->suspend_type, |
| 571 | sci_rnc->destination_state, suspend_reason, |
| 572 | suspend_type); |
| 573 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 574 | /* Disable automatic state continuations if explicitly suspending. */ |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 575 | if ((suspend_reason == SCI_HW_SUSPEND) || |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 576 | (sci_rnc->destination_state == RNC_DEST_FINAL)) |
| 577 | dest_param = sci_rnc->destination_state; |
| 578 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 579 | switch (state) { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 580 | case SCI_RNC_RESUMING: |
| 581 | break; /* The RNC has been posted, so start the suspend. */ |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 582 | case SCI_RNC_READY: |
| 583 | break; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 584 | case SCI_RNC_INVALIDATING: |
| 585 | if (sci_rnc->destination_state == RNC_DEST_FINAL) { |
| 586 | dev_warn(scirdev_to_dev(idev), |
| 587 | "%s: already destroying %p\n", |
| 588 | __func__, sci_rnc); |
| 589 | return SCI_FAILURE_INVALID_STATE; |
| 590 | } |
| 591 | /* Fall through and handle like SCI_RNC_POSTING */ |
| 592 | case SCI_RNC_POSTING: |
| 593 | /* Set the destination state to AWAIT - this signals the |
| 594 | * entry into the SCI_RNC_READY state that a suspension |
| 595 | * needs to be done immediately. |
| 596 | */ |
| 597 | sci_rnc->destination_state = RNC_DEST_SUSPENDED; |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 598 | sci_rnc->suspend_type = suspend_type; |
| 599 | sci_rnc->suspend_reason = suspend_reason; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 600 | return SCI_SUCCESS; |
| 601 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 602 | case SCI_RNC_TX_SUSPENDED: |
| 603 | if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX) |
| 604 | status = SCI_SUCCESS; |
| 605 | break; |
| 606 | case SCI_RNC_TX_RX_SUSPENDED: |
| 607 | if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX) |
| 608 | status = SCI_SUCCESS; |
| 609 | break; |
| 610 | case SCI_RNC_AWAIT_SUSPENSION: |
| 611 | if ((sci_rnc->suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX) |
| 612 | || (suspend_type == sci_rnc->suspend_type)) |
| 613 | return SCI_SUCCESS; |
| 614 | break; |
| 615 | default: |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 616 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 617 | "%s: invalid state %s\n", __func__, |
| 618 | rnc_state_name(state)); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 619 | return SCI_FAILURE_INVALID_STATE; |
| 620 | } |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 621 | sci_rnc->destination_state = dest_param; |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 622 | sci_rnc->suspend_type = suspend_type; |
| 623 | sci_rnc->suspend_reason = suspend_reason; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 624 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 625 | if (status == SCI_SUCCESS) { /* Already in the destination state? */ |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 626 | struct isci_host *ihost = idev->owning_port->owning_controller; |
| 627 | |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 628 | wake_up_all(&ihost->eventq); /* Let observers look. */ |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 629 | return SCI_SUCCESS; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 630 | } |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 631 | if ((suspend_reason == SCI_SW_SUSPEND_NORMAL) || |
| 632 | (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)) { |
| 633 | |
Jeff Skirvin | 9608b64 | 2012-03-08 22:42:00 -0800 | [diff] [blame] | 634 | if (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT) |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 635 | isci_dev_set_hang_detection_timeout(idev, 0x00000001); |
| 636 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 637 | sci_remote_device_post_request( |
| 638 | idev, SCI_SOFTWARE_SUSPEND_CMD); |
| 639 | } |
| 640 | if (state != SCI_RNC_AWAIT_SUSPENSION) |
| 641 | sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 642 | |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 643 | return SCI_SUCCESS; |
| 644 | } |
| 645 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 646 | enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc, |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 647 | scics_sds_remote_node_context_callback cb_fn, |
| 648 | void *cb_p) |
| 649 | { |
| 650 | enum scis_sds_remote_node_context_states state; |
| 651 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 652 | state = sci_rnc->sm.current_state_id; |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame^] | 653 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 654 | "%s: state %s, cb_fn = %p, cb_p = %p; dest_state = %d\n", |
| 655 | __func__, rnc_state_name(state), cb_fn, cb_p, |
| 656 | sci_rnc->destination_state); |
| 657 | |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 658 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 659 | case SCI_RNC_INITIAL: |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 660 | if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) |
| 661 | return SCI_FAILURE_INVALID_STATE; |
| 662 | |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 663 | sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p, |
| 664 | RNC_DEST_READY); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 665 | sci_remote_node_context_construct_buffer(sci_rnc); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 666 | sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 667 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 668 | case SCI_RNC_POSTING: |
| 669 | case SCI_RNC_INVALIDATING: |
| 670 | case SCI_RNC_RESUMING: |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 671 | /* We are still waiting to post when a resume was requested. */ |
| 672 | switch (sci_rnc->destination_state) { |
| 673 | case RNC_DEST_SUSPENDED: |
| 674 | case RNC_DEST_SUSPENDED_RESUME: |
| 675 | /* Previously waiting to suspend after posting. Now |
| 676 | * continue onto resumption. |
| 677 | */ |
| 678 | sci_remote_node_context_setup_to_resume( |
| 679 | sci_rnc, cb_fn, cb_p, |
| 680 | RNC_DEST_SUSPENDED_RESUME); |
| 681 | break; |
| 682 | default: |
| 683 | sci_remote_node_context_setup_to_resume( |
| 684 | sci_rnc, cb_fn, cb_p, |
| 685 | RNC_DEST_READY); |
| 686 | break; |
| 687 | } |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 688 | return SCI_SUCCESS; |
Jeff Skirvin | 56d7c01 | 2012-03-08 22:41:49 -0800 | [diff] [blame] | 689 | case SCI_RNC_TX_SUSPENDED: |
| 690 | case SCI_RNC_TX_RX_SUSPENDED: { |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 691 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
| 692 | struct domain_device *dev = idev->domain_dev; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 693 | |
Jeff Skirvin | 56d7c01 | 2012-03-08 22:41:49 -0800 | [diff] [blame] | 694 | /* If this is an expander attached SATA device we must |
| 695 | * invalidate and repost the RNC since this is the only way |
| 696 | * to clear the TCi to NCQ tag mapping table for the RNi. |
| 697 | * All other device types we can just resume. |
| 698 | */ |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 699 | sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p, |
| 700 | RNC_DEST_READY); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 701 | |
Dan Williams | 11cc518 | 2012-02-01 00:23:10 -0800 | [diff] [blame] | 702 | if (dev_is_sata(dev) && dev->parent) |
| 703 | sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING); |
| 704 | else |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 705 | sci_change_state(&sci_rnc->sm, SCI_RNC_RESUMING); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 706 | return SCI_SUCCESS; |
| 707 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 708 | case SCI_RNC_AWAIT_SUSPENSION: |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 709 | sci_remote_node_context_setup_to_resume( |
| 710 | sci_rnc, cb_fn, cb_p, |
| 711 | RNC_DEST_SUSPENDED_RESUME); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 712 | return SCI_SUCCESS; |
| 713 | default: |
| 714 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 715 | "%s: invalid state %s\n", __func__, |
| 716 | rnc_state_name(state)); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 717 | return SCI_FAILURE_INVALID_STATE; |
| 718 | } |
| 719 | } |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 720 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 721 | enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 722 | struct isci_request *ireq) |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 723 | { |
| 724 | enum scis_sds_remote_node_context_states state; |
| 725 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 726 | state = sci_rnc->sm.current_state_id; |
Jeff Skirvin | fd53660 | 2011-06-20 14:09:22 -0700 | [diff] [blame] | 727 | |
| 728 | switch (state) { |
| 729 | case SCI_RNC_READY: |
| 730 | return SCI_SUCCESS; |
| 731 | case SCI_RNC_TX_SUSPENDED: |
| 732 | case SCI_RNC_TX_RX_SUSPENDED: |
| 733 | case SCI_RNC_AWAIT_SUSPENSION: |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 734 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 735 | "%s: invalid state %s\n", __func__, |
| 736 | rnc_state_name(state)); |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 737 | return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; |
Jeff Skirvin | fd53660 | 2011-06-20 14:09:22 -0700 | [diff] [blame] | 738 | default: |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 739 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 740 | "%s: invalid state %s\n", __func__, |
| 741 | rnc_state_name(state)); |
| 742 | return SCI_FAILURE_INVALID_STATE; |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 743 | } |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 746 | enum sci_status sci_remote_node_context_start_task( |
| 747 | struct sci_remote_node_context *sci_rnc, |
| 748 | struct isci_request *ireq, |
| 749 | scics_sds_remote_node_context_callback cb_fn, |
| 750 | void *cb_p) |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 751 | { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 752 | enum sci_status status = sci_remote_node_context_resume(sci_rnc, |
| 753 | cb_fn, cb_p); |
| 754 | if (status != SCI_SUCCESS) |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 755 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 756 | "%s: resume failed: %d\n", __func__, status); |
| 757 | return status; |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 758 | } |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 759 | |
| 760 | int sci_remote_node_context_is_safe_to_abort( |
| 761 | struct sci_remote_node_context *sci_rnc) |
| 762 | { |
| 763 | enum scis_sds_remote_node_context_states state; |
| 764 | |
| 765 | state = sci_rnc->sm.current_state_id; |
| 766 | switch (state) { |
| 767 | case SCI_RNC_INVALIDATING: |
| 768 | case SCI_RNC_TX_RX_SUSPENDED: |
| 769 | return 1; |
| 770 | case SCI_RNC_POSTING: |
| 771 | case SCI_RNC_RESUMING: |
| 772 | case SCI_RNC_READY: |
| 773 | case SCI_RNC_TX_SUSPENDED: |
| 774 | case SCI_RNC_AWAIT_SUSPENSION: |
| 775 | case SCI_RNC_INITIAL: |
| 776 | return 0; |
| 777 | default: |
| 778 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 779 | "%s: invalid state %d\n", __func__, state); |
| 780 | return 0; |
| 781 | } |
| 782 | } |