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; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 324 | int tell_user = 1; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 325 | |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 326 | dest_select = rnc->destination_state; |
| 327 | rnc->destination_state = RNC_DEST_UNSPECIFIED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 328 | |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 329 | if ((dest_select == RNC_DEST_SUSPENDED) || |
| 330 | (dest_select == RNC_DEST_SUSPENDED_RESUME)) { |
| 331 | sci_remote_node_context_suspend( |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 332 | rnc, rnc->suspend_reason, |
| 333 | SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT); |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 334 | |
Jeff Skirvin | d76689e | 2012-03-08 22:42:04 -0800 | [diff] [blame] | 335 | if (dest_select == RNC_DEST_SUSPENDED_RESUME) |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 336 | tell_user = 0; /* Wait until ready again. */ |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 337 | } |
Jeff Skirvin | d76689e | 2012-03-08 22:42:04 -0800 | [diff] [blame] | 338 | if (tell_user) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 339 | sci_remote_node_context_notify_user(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 342 | 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] | 343 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 344 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 345 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 346 | sci_remote_node_context_continue_state_transitions(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 349 | 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] | 350 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 351 | struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm); |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 352 | struct isci_remote_device *idev = rnc_to_dev(rnc); |
| 353 | struct isci_host *ihost = idev->owning_port->owning_controller; |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame] | 354 | u32 new_count = rnc->suspend_count + 1; |
| 355 | |
| 356 | if (new_count == 0) |
| 357 | rnc->suspend_count = 1; |
| 358 | else |
| 359 | rnc->suspend_count = new_count; |
| 360 | smp_wmb(); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 361 | |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 362 | /* Terminate outstanding requests pending abort. */ |
| 363 | sci_remote_device_abort_requests_pending_abort(idev); |
| 364 | |
| 365 | wake_up(&ihost->eventq); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 366 | sci_remote_node_context_continue_state_transitions(rnc); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 369 | static void sci_remote_node_context_await_suspend_state_exit( |
| 370 | struct sci_base_state_machine *sm) |
| 371 | { |
| 372 | struct sci_remote_node_context *rnc |
| 373 | = container_of(sm, typeof(*rnc), sm); |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 374 | struct isci_remote_device *idev = rnc_to_dev(rnc); |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 375 | |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 376 | if (dev_is_sata(idev->domain_dev)) |
| 377 | isci_dev_set_hang_detection_timeout(idev, 0); |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 380 | static const struct sci_base_state sci_remote_node_context_state_table[] = { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 381 | [SCI_RNC_INITIAL] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 382 | .enter_state = sci_remote_node_context_initial_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_POSTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 385 | .enter_state = sci_remote_node_context_posting_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_INVALIDATING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 388 | .enter_state = sci_remote_node_context_invalidating_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_RESUMING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 391 | .enter_state = sci_remote_node_context_resuming_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_READY] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 394 | .enter_state = sci_remote_node_context_ready_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_SUSPENDED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 397 | .enter_state = sci_remote_node_context_tx_suspended_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 398 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 399 | [SCI_RNC_TX_RX_SUSPENDED] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 400 | .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 401 | }, |
Jeff Skirvin | 6f48844 | 2012-03-08 22:41:48 -0800 | [diff] [blame] | 402 | [SCI_RNC_AWAIT_SUSPENSION] = { |
| 403 | .exit_state = sci_remote_node_context_await_suspend_state_exit, |
| 404 | }, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 405 | }; |
| 406 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 407 | void sci_remote_node_context_construct(struct sci_remote_node_context *rnc, |
Dan Williams | 9614395 | 2011-04-19 18:35:58 -0700 | [diff] [blame] | 408 | u16 remote_node_index) |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 409 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 410 | memset(rnc, 0, sizeof(struct sci_remote_node_context)); |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 411 | |
| 412 | rnc->remote_node_index = remote_node_index; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 413 | rnc->destination_state = RNC_DEST_UNSPECIFIED; |
Dan Williams | 35173d5 | 2011-03-26 16:43:01 -0700 | [diff] [blame] | 414 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 415 | 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] | 416 | } |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 417 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 418 | 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] | 419 | u32 event_code) |
| 420 | { |
| 421 | enum scis_sds_remote_node_context_states state; |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 422 | u32 next_state; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 423 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 424 | state = sci_rnc->sm.current_state_id; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 425 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 426 | case SCI_RNC_POSTING: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 427 | switch (scu_get_event_code(event_code)) { |
| 428 | case SCU_EVENT_POST_RNC_COMPLETE: |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 429 | sci_change_state(&sci_rnc->sm, SCI_RNC_READY); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 430 | break; |
| 431 | default: |
| 432 | goto out; |
| 433 | } |
| 434 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 435 | case SCI_RNC_INVALIDATING: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 436 | 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] | 437 | if (sci_rnc->destination_state == RNC_DEST_FINAL) |
| 438 | next_state = SCI_RNC_INITIAL; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 439 | else |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 440 | next_state = SCI_RNC_POSTING; |
| 441 | sci_change_state(&sci_rnc->sm, next_state); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 442 | } else { |
| 443 | switch (scu_get_event_type(event_code)) { |
| 444 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 445 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 446 | /* We really dont care if the hardware is going to suspend |
| 447 | * the device since it's being invalidated anyway */ |
Jeff Skirvin | 8c73188 | 2012-03-08 22:42:06 -0800 | [diff] [blame] | 448 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 449 | "%s: SCIC Remote Node Context 0x%p was " |
| 450 | "suspeneded by hardware while being " |
| 451 | "invalidated.\n", __func__, sci_rnc); |
| 452 | break; |
| 453 | default: |
| 454 | goto out; |
| 455 | } |
| 456 | } |
| 457 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 458 | case SCI_RNC_RESUMING: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 459 | if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 460 | sci_change_state(&sci_rnc->sm, SCI_RNC_READY); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 461 | } else { |
| 462 | switch (scu_get_event_type(event_code)) { |
| 463 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 464 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 465 | /* We really dont care if the hardware is going to suspend |
| 466 | * the device since it's being resumed anyway */ |
Jeff Skirvin | 8c73188 | 2012-03-08 22:42:06 -0800 | [diff] [blame] | 467 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 468 | "%s: SCIC Remote Node Context 0x%p was " |
| 469 | "suspeneded by hardware while being resumed.\n", |
| 470 | __func__, sci_rnc); |
| 471 | break; |
| 472 | default: |
| 473 | goto out; |
| 474 | } |
| 475 | } |
| 476 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 477 | case SCI_RNC_READY: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 478 | switch (scu_get_event_type(event_code)) { |
| 479 | case SCU_EVENT_TL_RNC_SUSPEND_TX: |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 480 | sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED); |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 481 | sci_rnc->suspend_type = scu_get_event_type(event_code); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 482 | break; |
| 483 | case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 484 | sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_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 | default: |
| 488 | goto out; |
| 489 | } |
| 490 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 491 | case SCI_RNC_AWAIT_SUSPENSION: |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 492 | switch (scu_get_event_type(event_code)) { |
| 493 | case SCU_EVENT_TL_RNC_SUSPEND_TX: |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 494 | next_state = SCI_RNC_TX_SUSPENDED; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 495 | break; |
| 496 | case SCU_EVENT_TL_RNC_SUSPEND_TX_RX: |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 497 | next_state = SCI_RNC_TX_RX_SUSPENDED; |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 498 | break; |
| 499 | default: |
| 500 | goto out; |
| 501 | } |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 502 | if (sci_rnc->suspend_type == scu_get_event_type(event_code)) |
| 503 | sci_change_state(&sci_rnc->sm, next_state); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 504 | break; |
| 505 | default: |
| 506 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 507 | "%s: invalid state: %s\n", __func__, |
| 508 | rnc_state_name(state)); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 509 | return SCI_FAILURE_INVALID_STATE; |
| 510 | } |
| 511 | return SCI_SUCCESS; |
| 512 | |
| 513 | out: |
| 514 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 515 | "%s: code: %#x state: %s\n", __func__, event_code, |
| 516 | rnc_state_name(state)); |
Dan Williams | 338e386 | 2011-05-12 07:46:59 -0700 | [diff] [blame] | 517 | return SCI_FAILURE; |
| 518 | |
| 519 | } |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 520 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 521 | 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] | 522 | scics_sds_remote_node_context_callback cb_fn, |
| 523 | void *cb_p) |
| 524 | { |
| 525 | enum scis_sds_remote_node_context_states state; |
| 526 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 527 | state = sci_rnc->sm.current_state_id; |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 528 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 529 | case SCI_RNC_INVALIDATING: |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 530 | 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] | 531 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 532 | case SCI_RNC_POSTING: |
| 533 | case SCI_RNC_RESUMING: |
| 534 | case SCI_RNC_READY: |
| 535 | case SCI_RNC_TX_SUSPENDED: |
| 536 | case SCI_RNC_TX_RX_SUSPENDED: |
| 537 | case SCI_RNC_AWAIT_SUSPENSION: |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 538 | 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] | 539 | sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 540 | return SCI_SUCCESS; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 541 | case SCI_RNC_INITIAL: |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 542 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 543 | "%s: invalid state: %s\n", __func__, |
| 544 | rnc_state_name(state)); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 545 | /* We have decided that the destruct request on the remote node context |
| 546 | * can not fail since it is either in the initial/destroyed state or is |
| 547 | * can be destroyed. |
| 548 | */ |
| 549 | return SCI_SUCCESS; |
| 550 | default: |
| 551 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 552 | "%s: invalid state %s\n", __func__, |
| 553 | rnc_state_name(state)); |
Dan Williams | c845ae9 | 2011-05-12 08:26:56 -0700 | [diff] [blame] | 554 | return SCI_FAILURE_INVALID_STATE; |
| 555 | } |
| 556 | } |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 557 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 558 | enum sci_status sci_remote_node_context_suspend( |
| 559 | struct sci_remote_node_context *sci_rnc, |
| 560 | enum sci_remote_node_suspension_reasons suspend_reason, |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 561 | u32 suspend_type) |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 562 | { |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 563 | enum scis_sds_remote_node_context_states state |
| 564 | = sci_rnc->sm.current_state_id; |
| 565 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
| 566 | enum sci_status status = SCI_FAILURE_INVALID_STATE; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 567 | enum sci_remote_node_context_destination_state dest_param = |
| 568 | RNC_DEST_UNSPECIFIED; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 569 | |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 570 | dev_dbg(scirdev_to_dev(idev), |
Jeff Skirvin | 8c73188 | 2012-03-08 22:42:06 -0800 | [diff] [blame] | 571 | "%s: current state %s, current suspend_type %x dest state %d," |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 572 | " arg suspend_reason %d, arg suspend_type %x", |
Jeff Skirvin | 8c73188 | 2012-03-08 22:42:06 -0800 | [diff] [blame] | 573 | __func__, rnc_state_name(state), sci_rnc->suspend_type, |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 574 | sci_rnc->destination_state, suspend_reason, |
| 575 | suspend_type); |
| 576 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 577 | /* Disable automatic state continuations if explicitly suspending. */ |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 578 | if ((suspend_reason == SCI_HW_SUSPEND) || |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 579 | (sci_rnc->destination_state == RNC_DEST_FINAL)) |
| 580 | dest_param = sci_rnc->destination_state; |
| 581 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 582 | switch (state) { |
| 583 | case SCI_RNC_READY: |
| 584 | break; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 585 | case SCI_RNC_INVALIDATING: |
| 586 | if (sci_rnc->destination_state == RNC_DEST_FINAL) { |
| 587 | dev_warn(scirdev_to_dev(idev), |
| 588 | "%s: already destroying %p\n", |
| 589 | __func__, sci_rnc); |
| 590 | return SCI_FAILURE_INVALID_STATE; |
| 591 | } |
| 592 | /* Fall through and handle like SCI_RNC_POSTING */ |
Jeff Skirvin | d76689e | 2012-03-08 22:42:04 -0800 | [diff] [blame] | 593 | case SCI_RNC_RESUMING: |
| 594 | /* Fall through and handle like SCI_RNC_POSTING */ |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 595 | case SCI_RNC_POSTING: |
| 596 | /* Set the destination state to AWAIT - this signals the |
| 597 | * entry into the SCI_RNC_READY state that a suspension |
| 598 | * needs to be done immediately. |
| 599 | */ |
| 600 | sci_rnc->destination_state = RNC_DEST_SUSPENDED; |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 601 | sci_rnc->suspend_type = suspend_type; |
| 602 | sci_rnc->suspend_reason = suspend_reason; |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 603 | return SCI_SUCCESS; |
| 604 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 605 | case SCI_RNC_TX_SUSPENDED: |
| 606 | if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX) |
| 607 | status = SCI_SUCCESS; |
| 608 | break; |
| 609 | case SCI_RNC_TX_RX_SUSPENDED: |
| 610 | if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX) |
| 611 | status = SCI_SUCCESS; |
| 612 | break; |
| 613 | case SCI_RNC_AWAIT_SUSPENSION: |
| 614 | if ((sci_rnc->suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX) |
| 615 | || (suspend_type == sci_rnc->suspend_type)) |
| 616 | return SCI_SUCCESS; |
| 617 | break; |
| 618 | default: |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 619 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 620 | "%s: invalid state %s\n", __func__, |
| 621 | rnc_state_name(state)); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 622 | return SCI_FAILURE_INVALID_STATE; |
| 623 | } |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 624 | sci_rnc->destination_state = dest_param; |
Jeff Skirvin | 447bfbc | 2012-03-08 22:41:59 -0800 | [diff] [blame] | 625 | sci_rnc->suspend_type = suspend_type; |
| 626 | sci_rnc->suspend_reason = suspend_reason; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 627 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 628 | if (status == SCI_SUCCESS) { /* Already in the destination state? */ |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 629 | struct isci_host *ihost = idev->owning_port->owning_controller; |
| 630 | |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 631 | wake_up_all(&ihost->eventq); /* Let observers look. */ |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 632 | return SCI_SUCCESS; |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 633 | } |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 634 | if ((suspend_reason == SCI_SW_SUSPEND_NORMAL) || |
| 635 | (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)) { |
| 636 | |
Jeff Skirvin | 9608b64 | 2012-03-08 22:42:00 -0800 | [diff] [blame] | 637 | if (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT) |
Jeff Skirvin | c94fc1a | 2012-03-08 22:41:58 -0800 | [diff] [blame] | 638 | isci_dev_set_hang_detection_timeout(idev, 0x00000001); |
| 639 | |
Jeff Skirvin | ac78ed0 | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 640 | sci_remote_device_post_request( |
| 641 | idev, SCI_SOFTWARE_SUSPEND_CMD); |
| 642 | } |
| 643 | if (state != SCI_RNC_AWAIT_SUSPENSION) |
| 644 | sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 645 | |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 646 | return SCI_SUCCESS; |
| 647 | } |
| 648 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 649 | 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] | 650 | scics_sds_remote_node_context_callback cb_fn, |
| 651 | void *cb_p) |
| 652 | { |
| 653 | enum scis_sds_remote_node_context_states state; |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 654 | struct isci_remote_device *idev = rnc_to_dev(sci_rnc); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 655 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 656 | state = sci_rnc->sm.current_state_id; |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 657 | dev_dbg(scirdev_to_dev(idev), |
| 658 | "%s: state %s, cb_fn = %p, cb_p = %p; dest_state = %d; " |
| 659 | "dev resume path %s\n", |
| 660 | __func__, rnc_state_name(state), cb_fn, cb_p, |
| 661 | sci_rnc->destination_state, |
| 662 | test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags) |
| 663 | ? "<abort active>" : "<normal>"); |
Jeff Skirvin | 31a38ef | 2012-03-08 22:42:01 -0800 | [diff] [blame] | 664 | |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 665 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 666 | case SCI_RNC_INITIAL: |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 667 | if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) |
| 668 | return SCI_FAILURE_INVALID_STATE; |
| 669 | |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 670 | if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) |
| 671 | sci_remote_node_context_save_cbparams(sci_rnc, cb_fn, |
| 672 | cb_p); |
| 673 | else { |
| 674 | sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, |
| 675 | cb_p, RNC_DEST_READY); |
| 676 | sci_remote_node_context_construct_buffer(sci_rnc); |
| 677 | sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING); |
| 678 | } |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 679 | return SCI_SUCCESS; |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 680 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 681 | case SCI_RNC_POSTING: |
| 682 | case SCI_RNC_INVALIDATING: |
| 683 | case SCI_RNC_RESUMING: |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 684 | if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) |
| 685 | sci_remote_node_context_save_cbparams(sci_rnc, cb_fn, |
| 686 | cb_p); |
| 687 | else { |
| 688 | /* We are still waiting to post when a resume was |
| 689 | * requested. |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 690 | */ |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 691 | switch (sci_rnc->destination_state) { |
| 692 | case RNC_DEST_SUSPENDED: |
| 693 | case RNC_DEST_SUSPENDED_RESUME: |
| 694 | /* Previously waiting to suspend after posting. |
| 695 | * Now continue onto resumption. |
| 696 | */ |
| 697 | sci_remote_node_context_setup_to_resume( |
| 698 | sci_rnc, cb_fn, cb_p, |
| 699 | RNC_DEST_SUSPENDED_RESUME); |
| 700 | break; |
| 701 | default: |
| 702 | sci_remote_node_context_setup_to_resume( |
| 703 | sci_rnc, cb_fn, cb_p, |
| 704 | RNC_DEST_READY); |
| 705 | break; |
| 706 | } |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 707 | } |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 708 | return SCI_SUCCESS; |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 709 | |
Jeff Skirvin | 56d7c01 | 2012-03-08 22:41:49 -0800 | [diff] [blame] | 710 | case SCI_RNC_TX_SUSPENDED: |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 711 | case SCI_RNC_TX_RX_SUSPENDED: |
| 712 | if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) |
| 713 | sci_remote_node_context_save_cbparams(sci_rnc, cb_fn, |
| 714 | cb_p); |
| 715 | else { |
| 716 | struct domain_device *dev = idev->domain_dev; |
| 717 | /* If this is an expander attached SATA device we must |
| 718 | * invalidate and repost the RNC since this is the only |
| 719 | * way to clear the TCi to NCQ tag mapping table for |
| 720 | * the RNi. All other device types we can just resume. |
| 721 | */ |
| 722 | sci_remote_node_context_setup_to_resume( |
| 723 | sci_rnc, cb_fn, cb_p, RNC_DEST_READY); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 724 | |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 725 | if (dev_is_sata(dev) && dev->parent) |
| 726 | sci_change_state(&sci_rnc->sm, |
| 727 | SCI_RNC_INVALIDATING); |
| 728 | else |
| 729 | sci_change_state(&sci_rnc->sm, |
| 730 | SCI_RNC_RESUMING); |
| 731 | } |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 732 | return SCI_SUCCESS; |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 733 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 734 | case SCI_RNC_AWAIT_SUSPENSION: |
Jeff Skirvin | 0c3ce38 | 2012-03-08 22:42:02 -0800 | [diff] [blame] | 735 | if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) |
| 736 | sci_remote_node_context_save_cbparams(sci_rnc, cb_fn, |
| 737 | cb_p); |
| 738 | else |
| 739 | sci_remote_node_context_setup_to_resume( |
| 740 | sci_rnc, cb_fn, cb_p, |
| 741 | RNC_DEST_SUSPENDED_RESUME); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 742 | return SCI_SUCCESS; |
| 743 | default: |
| 744 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 745 | "%s: invalid state %s\n", __func__, |
| 746 | rnc_state_name(state)); |
Dan Williams | ed3efb7 | 2011-05-12 08:50:23 -0700 | [diff] [blame] | 747 | return SCI_FAILURE_INVALID_STATE; |
| 748 | } |
| 749 | } |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 750 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 751 | 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] | 752 | struct isci_request *ireq) |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 753 | { |
| 754 | enum scis_sds_remote_node_context_states state; |
| 755 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 756 | state = sci_rnc->sm.current_state_id; |
Jeff Skirvin | fd53660 | 2011-06-20 14:09:22 -0700 | [diff] [blame] | 757 | |
| 758 | switch (state) { |
| 759 | case SCI_RNC_READY: |
| 760 | return SCI_SUCCESS; |
| 761 | case SCI_RNC_TX_SUSPENDED: |
| 762 | case SCI_RNC_TX_RX_SUSPENDED: |
| 763 | case SCI_RNC_AWAIT_SUSPENSION: |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 764 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 765 | "%s: invalid state %s\n", __func__, |
| 766 | rnc_state_name(state)); |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 767 | return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; |
Jeff Skirvin | fd53660 | 2011-06-20 14:09:22 -0700 | [diff] [blame] | 768 | default: |
Dan Williams | 14e99b4 | 2012-02-10 01:05:43 -0800 | [diff] [blame] | 769 | dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 770 | "%s: invalid state %s\n", __func__, |
| 771 | rnc_state_name(state)); |
| 772 | return SCI_FAILURE_INVALID_STATE; |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 773 | } |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Jeff Skirvin | 14aaa9f | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 776 | enum sci_status sci_remote_node_context_start_task( |
| 777 | struct sci_remote_node_context *sci_rnc, |
| 778 | struct isci_request *ireq, |
| 779 | scics_sds_remote_node_context_callback cb_fn, |
| 780 | void *cb_p) |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 781 | { |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 782 | enum sci_status status = sci_remote_node_context_resume(sci_rnc, |
| 783 | cb_fn, cb_p); |
| 784 | if (status != SCI_SUCCESS) |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 785 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
Jeff Skirvin | 59e3539 | 2012-03-08 22:41:54 -0800 | [diff] [blame] | 786 | "%s: resume failed: %d\n", __func__, status); |
| 787 | return status; |
Dan Williams | f34d9e5 | 2011-05-12 09:27:52 -0700 | [diff] [blame] | 788 | } |
Jeff Skirvin | 726980d | 2012-03-08 22:41:50 -0800 | [diff] [blame] | 789 | |
| 790 | int sci_remote_node_context_is_safe_to_abort( |
| 791 | struct sci_remote_node_context *sci_rnc) |
| 792 | { |
| 793 | enum scis_sds_remote_node_context_states state; |
| 794 | |
| 795 | state = sci_rnc->sm.current_state_id; |
| 796 | switch (state) { |
| 797 | case SCI_RNC_INVALIDATING: |
| 798 | case SCI_RNC_TX_RX_SUSPENDED: |
| 799 | return 1; |
| 800 | case SCI_RNC_POSTING: |
| 801 | case SCI_RNC_RESUMING: |
| 802 | case SCI_RNC_READY: |
| 803 | case SCI_RNC_TX_SUSPENDED: |
| 804 | case SCI_RNC_AWAIT_SUSPENSION: |
| 805 | case SCI_RNC_INITIAL: |
| 806 | return 0; |
| 807 | default: |
| 808 | dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)), |
| 809 | "%s: invalid state %d\n", __func__, state); |
| 810 | return 0; |
| 811 | } |
| 812 | } |