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