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