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 | */ |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 55 | #include "intel_sas.h" |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 56 | #include "intel_ata.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #include "isci.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 58 | #include "port.h" |
| 59 | #include "remote_device.h" |
| 60 | #include "request.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 61 | #include "scic_controller.h" |
| 62 | #include "scic_io_request.h" |
| 63 | #include "scic_phy.h" |
| 64 | #include "scic_port.h" |
| 65 | #include "scic_sds_controller.h" |
| 66 | #include "scic_sds_phy.h" |
| 67 | #include "scic_sds_port.h" |
| 68 | #include "remote_node_context.h" |
| 69 | #include "scic_sds_request.h" |
| 70 | #include "sci_environment.h" |
| 71 | #include "sci_util.h" |
| 72 | #include "scu_event_codes.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 73 | #include "task.h" |
| 74 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 75 | /** |
| 76 | * isci_remote_device_change_state() - This function gets the status of the |
| 77 | * remote_device object. |
| 78 | * @isci_device: This parameter points to the isci_remote_device object |
| 79 | * |
| 80 | * status of the object as a isci_status enum. |
| 81 | */ |
| 82 | void isci_remote_device_change_state( |
| 83 | struct isci_remote_device *isci_device, |
| 84 | enum isci_status status) |
| 85 | { |
| 86 | unsigned long flags; |
| 87 | |
| 88 | spin_lock_irqsave(&isci_device->state_lock, flags); |
| 89 | isci_device->status = status; |
| 90 | spin_unlock_irqrestore(&isci_device->state_lock, flags); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * isci_remote_device_not_ready() - This function is called by the scic when |
| 95 | * the remote device is not ready. We mark the isci device as ready (not |
| 96 | * "ready_for_io") and signal the waiting proccess. |
| 97 | * @isci_host: This parameter specifies the isci host object. |
| 98 | * @isci_device: This parameter specifies the remote device |
| 99 | * |
| 100 | */ |
| 101 | static void isci_remote_device_not_ready(struct isci_host *ihost, |
| 102 | struct isci_remote_device *idev, u32 reason) |
| 103 | { |
| 104 | dev_dbg(&ihost->pdev->dev, |
| 105 | "%s: isci_device = %p\n", __func__, idev); |
| 106 | |
| 107 | if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED) |
| 108 | isci_remote_device_change_state(idev, isci_stopping); |
| 109 | else |
| 110 | /* device ready is actually a "not ready for io" state. */ |
| 111 | isci_remote_device_change_state(idev, isci_ready); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * isci_remote_device_ready() - This function is called by the scic when the |
| 116 | * remote device is ready. We mark the isci device as ready and signal the |
| 117 | * waiting proccess. |
| 118 | * @ihost: our valid isci_host |
| 119 | * @idev: remote device |
| 120 | * |
| 121 | */ |
| 122 | static void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev) |
| 123 | { |
| 124 | dev_dbg(&ihost->pdev->dev, |
| 125 | "%s: idev = %p\n", __func__, idev); |
| 126 | |
| 127 | isci_remote_device_change_state(idev, isci_ready_for_io); |
| 128 | if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags)) |
| 129 | wake_up(&ihost->eventq); |
| 130 | } |
| 131 | |
Dan Williams | ec57566 | 2011-05-01 14:19:25 -0700 | [diff] [blame] | 132 | /* called once the remote node context is ready to be freed. |
| 133 | * The remote device can now report that its stop operation is complete. none |
| 134 | */ |
| 135 | static void rnc_destruct_done(void *_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 136 | { |
Dan Williams | ec57566 | 2011-05-01 14:19:25 -0700 | [diff] [blame] | 137 | struct scic_sds_remote_device *sci_dev = _dev; |
| 138 | |
| 139 | BUG_ON(sci_dev->started_request_count != 0); |
| 140 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 141 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 142 | } |
| 143 | |
| 144 | static enum sci_status scic_sds_remote_device_terminate_requests(struct scic_sds_remote_device *sci_dev) |
| 145 | { |
| 146 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 147 | u32 i, request_count = sci_dev->started_request_count; |
| 148 | enum sci_status status = SCI_SUCCESS; |
| 149 | |
| 150 | for (i = 0; i < SCI_MAX_IO_REQUESTS && i < request_count; i++) { |
| 151 | struct scic_sds_request *sci_req; |
| 152 | enum sci_status s; |
| 153 | |
| 154 | sci_req = scic->io_request_table[i]; |
| 155 | if (!sci_req || sci_req->target_device != sci_dev) |
| 156 | continue; |
| 157 | s = scic_controller_terminate_request(scic, sci_dev, sci_req); |
| 158 | if (s != SCI_SUCCESS) |
| 159 | status = s; |
| 160 | } |
| 161 | |
| 162 | return status; |
| 163 | } |
| 164 | |
| 165 | enum sci_status scic_remote_device_stop(struct scic_sds_remote_device *sci_dev, |
| 166 | u32 timeout) |
| 167 | { |
| 168 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 169 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 170 | |
| 171 | switch (state) { |
| 172 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 173 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 174 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 175 | default: |
| 176 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 177 | __func__, state); |
| 178 | return SCI_FAILURE_INVALID_STATE; |
| 179 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 180 | return SCI_SUCCESS; |
| 181 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 182 | /* device not started so there had better be no requests */ |
| 183 | BUG_ON(sci_dev->started_request_count != 0); |
| 184 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 185 | rnc_destruct_done, sci_dev); |
| 186 | /* Transition to the stopping state and wait for the |
| 187 | * remote node to complete being posted and invalidated. |
| 188 | */ |
| 189 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 190 | return SCI_SUCCESS; |
| 191 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 192 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 193 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 194 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 195 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 196 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 197 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 198 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 199 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 200 | if (sci_dev->started_request_count == 0) { |
| 201 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 202 | rnc_destruct_done, sci_dev); |
| 203 | return SCI_SUCCESS; |
| 204 | } else |
| 205 | return scic_sds_remote_device_terminate_requests(sci_dev); |
| 206 | break; |
| 207 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 208 | /* All requests should have been terminated, but if there is an |
| 209 | * attempt to stop a device already in the stopping state, then |
| 210 | * try again to terminate. |
| 211 | */ |
| 212 | return scic_sds_remote_device_terminate_requests(sci_dev); |
| 213 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 214 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 215 | return SCI_SUCCESS; |
| 216 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 217 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 218 | |
Dan Williams | 4fd0d2e | 2011-05-01 14:48:54 -0700 | [diff] [blame] | 219 | enum sci_status scic_remote_device_reset(struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 220 | { |
Dan Williams | 4fd0d2e | 2011-05-01 14:48:54 -0700 | [diff] [blame] | 221 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 222 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 223 | |
| 224 | switch (state) { |
| 225 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 226 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 227 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 228 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 229 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 230 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 231 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 232 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 233 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 234 | default: |
| 235 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 236 | __func__, state); |
| 237 | return SCI_FAILURE_INVALID_STATE; |
| 238 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 239 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 240 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 241 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 242 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 243 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 244 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_RESETTING); |
| 245 | return SCI_SUCCESS; |
| 246 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Dan Williams | 8151518 | 2011-05-01 14:53:00 -0700 | [diff] [blame] | 249 | enum sci_status scic_remote_device_reset_complete(struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 250 | { |
Dan Williams | 8151518 | 2011-05-01 14:53:00 -0700 | [diff] [blame] | 251 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 252 | enum scic_sds_remote_device_states state = sm->current_state_id; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 253 | |
Dan Williams | 8151518 | 2011-05-01 14:53:00 -0700 | [diff] [blame] | 254 | if (state != SCI_BASE_REMOTE_DEVICE_STATE_RESETTING) { |
| 255 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 256 | __func__, state); |
| 257 | return SCI_FAILURE_INVALID_STATE; |
| 258 | } |
| 259 | |
| 260 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_READY); |
| 261 | return SCI_SUCCESS; |
| 262 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 263 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 264 | /** |
| 265 | * |
| 266 | * @sci_dev: The remote device for which the suspend is being requested. |
| 267 | * |
| 268 | * This method invokes the remote device suspend state handler. enum sci_status |
| 269 | */ |
| 270 | enum sci_status scic_sds_remote_device_suspend( |
| 271 | struct scic_sds_remote_device *sci_dev, |
| 272 | u32 suspend_type) |
| 273 | { |
| 274 | return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * |
| 279 | * @sci_dev: The remote device for which the event handling is being |
| 280 | * requested. |
| 281 | * @frame_index: This is the frame index that is being processed. |
| 282 | * |
| 283 | * This method invokes the frame handler for the remote device state machine |
| 284 | * enum sci_status |
| 285 | */ |
| 286 | enum sci_status scic_sds_remote_device_frame_handler( |
| 287 | struct scic_sds_remote_device *sci_dev, |
| 288 | u32 frame_index) |
| 289 | { |
| 290 | return sci_dev->state_handlers->frame_handler(sci_dev, frame_index); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * |
| 295 | * @sci_dev: The remote device for which the event handling is being |
| 296 | * requested. |
| 297 | * @event_code: This is the event code that is to be processed. |
| 298 | * |
| 299 | * This method invokes the remote device event handler. enum sci_status |
| 300 | */ |
| 301 | enum sci_status scic_sds_remote_device_event_handler( |
| 302 | struct scic_sds_remote_device *sci_dev, |
| 303 | u32 event_code) |
| 304 | { |
| 305 | return sci_dev->state_handlers->event_handler(sci_dev, event_code); |
| 306 | } |
| 307 | |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 308 | static void scic_sds_remote_device_start_request(struct scic_sds_remote_device *sci_dev, |
| 309 | struct scic_sds_request *sci_req, |
| 310 | enum sci_status status) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 311 | { |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 312 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
| 313 | |
| 314 | /* cleanup requests that failed after starting on the port */ |
| 315 | if (status != SCI_SUCCESS) |
| 316 | scic_sds_port_complete_io(sci_port, sci_dev, sci_req); |
| 317 | else |
| 318 | scic_sds_remote_device_increment_request_count(sci_dev); |
| 319 | } |
| 320 | |
| 321 | enum sci_status scic_sds_remote_device_start_io(struct scic_sds_controller *scic, |
| 322 | struct scic_sds_remote_device *sci_dev, |
| 323 | struct scic_sds_request *sci_req) |
| 324 | { |
| 325 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 326 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 327 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
| 328 | enum sci_status status; |
| 329 | |
| 330 | switch (state) { |
| 331 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 332 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 333 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 334 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 335 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 336 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 337 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 338 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 339 | default: |
| 340 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 341 | __func__, state); |
| 342 | return SCI_FAILURE_INVALID_STATE; |
| 343 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 344 | /* attempt to start an io request for this device object. The remote |
| 345 | * device object will issue the start request for the io and if |
| 346 | * successful it will start the request for the port object then |
| 347 | * increment its own request count. |
| 348 | */ |
| 349 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 350 | if (status != SCI_SUCCESS) |
| 351 | return status; |
| 352 | |
| 353 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 354 | if (status != SCI_SUCCESS) |
| 355 | break; |
| 356 | |
| 357 | status = scic_sds_request_start(sci_req); |
| 358 | break; |
| 359 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: { |
| 360 | /* handle the start io operation for a sata device that is in |
| 361 | * the command idle state. - Evalute the type of IO request to |
| 362 | * be started - If its an NCQ request change to NCQ substate - |
| 363 | * If its any other command change to the CMD substate |
| 364 | * |
| 365 | * If this is a softreset we may want to have a different |
| 366 | * substate. |
| 367 | */ |
| 368 | enum scic_sds_remote_device_states new_state; |
| 369 | |
| 370 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 371 | if (status != SCI_SUCCESS) |
| 372 | return status; |
| 373 | |
| 374 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 375 | if (status != SCI_SUCCESS) |
| 376 | break; |
| 377 | |
| 378 | status = sci_req->state_handlers->start_handler(sci_req); |
| 379 | if (status != SCI_SUCCESS) |
| 380 | break; |
| 381 | |
| 382 | if (isci_sata_get_sat_protocol(sci_req->ireq) == SAT_PROTOCOL_FPDMA) |
| 383 | new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ; |
| 384 | else { |
| 385 | sci_dev->working_request = sci_req; |
| 386 | new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD; |
| 387 | } |
| 388 | sci_base_state_machine_change_state(sm, new_state); |
| 389 | break; |
| 390 | } |
| 391 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 392 | if (isci_sata_get_sat_protocol(sci_req->ireq) == SAT_PROTOCOL_FPDMA) { |
| 393 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 394 | if (status != SCI_SUCCESS) |
| 395 | return status; |
| 396 | |
| 397 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 398 | if (status != SCI_SUCCESS) |
| 399 | break; |
| 400 | |
| 401 | status = sci_req->state_handlers->start_handler(sci_req); |
| 402 | } else |
| 403 | return SCI_FAILURE_INVALID_STATE; |
| 404 | break; |
| 405 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 406 | return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; |
| 407 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 408 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 409 | if (status != SCI_SUCCESS) |
| 410 | return status; |
| 411 | |
| 412 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 413 | if (status != SCI_SUCCESS) |
| 414 | break; |
| 415 | |
| 416 | status = scic_sds_request_start(sci_req); |
| 417 | if (status != SCI_SUCCESS) |
| 418 | break; |
| 419 | |
| 420 | sci_dev->working_request = sci_req; |
| 421 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 422 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD); |
| 423 | break; |
| 424 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 425 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 426 | /* device is already handling a command it can not accept new commands |
| 427 | * until this one is complete. |
| 428 | */ |
| 429 | return SCI_FAILURE_INVALID_STATE; |
| 430 | } |
| 431 | |
| 432 | scic_sds_remote_device_start_request(sci_dev, sci_req, status); |
| 433 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Dan Williams | 10a09e6 | 2011-05-01 15:33:43 -0700 | [diff] [blame^] | 436 | static enum sci_status common_complete_io(struct scic_sds_port *sci_port, |
| 437 | struct scic_sds_remote_device *sci_dev, |
| 438 | struct scic_sds_request *sci_req) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 439 | { |
Dan Williams | 10a09e6 | 2011-05-01 15:33:43 -0700 | [diff] [blame^] | 440 | enum sci_status status; |
| 441 | |
| 442 | status = scic_sds_request_complete(sci_req); |
| 443 | if (status != SCI_SUCCESS) |
| 444 | return status; |
| 445 | |
| 446 | status = scic_sds_port_complete_io(sci_port, sci_dev, sci_req); |
| 447 | if (status != SCI_SUCCESS) |
| 448 | return status; |
| 449 | |
| 450 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 451 | return status; |
| 452 | } |
| 453 | |
| 454 | enum sci_status scic_sds_remote_device_complete_io(struct scic_sds_controller *scic, |
| 455 | struct scic_sds_remote_device *sci_dev, |
| 456 | struct scic_sds_request *sci_req) |
| 457 | { |
| 458 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 459 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 460 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
| 461 | enum sci_status status; |
| 462 | |
| 463 | switch (state) { |
| 464 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 465 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 466 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 467 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 468 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 469 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 470 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 471 | default: |
| 472 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 473 | __func__, state); |
| 474 | return SCI_FAILURE_INVALID_STATE; |
| 475 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 476 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 477 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 478 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 479 | break; |
| 480 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 481 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 482 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 483 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 484 | if (status != SCI_SUCCESS) |
| 485 | break; |
| 486 | |
| 487 | if (sci_req->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { |
| 488 | /* This request causes hardware error, device needs to be Lun Reset. |
| 489 | * So here we force the state machine to IDLE state so the rest IOs |
| 490 | * can reach RNC state handler, these IOs will be completed by RNC with |
| 491 | * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE". |
| 492 | */ |
| 493 | sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET); |
| 494 | } else if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 495 | sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 496 | break; |
| 497 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 498 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 499 | if (status != SCI_SUCCESS) |
| 500 | break; |
| 501 | sci_base_state_machine_change_state(sm, SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 502 | break; |
| 503 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 504 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 505 | if (status != SCI_SUCCESS) |
| 506 | break; |
| 507 | |
| 508 | if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 509 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 510 | rnc_destruct_done, |
| 511 | sci_dev); |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | if (status != SCI_SUCCESS) |
| 516 | dev_err(scirdev_to_dev(sci_dev), |
| 517 | "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x " |
| 518 | "could not complete\n", __func__, sci_port, |
| 519 | sci_dev, sci_req, status); |
| 520 | |
| 521 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | /** |
| 525 | * |
| 526 | * @controller: The controller that is starting the task request. |
| 527 | * @sci_dev: The remote device for which the start task handling is being |
| 528 | * requested. |
| 529 | * @io_request: The task request that is being started. |
| 530 | * |
| 531 | * This method invokes the remote device start task handler. enum sci_status |
| 532 | */ |
| 533 | enum sci_status scic_sds_remote_device_start_task( |
| 534 | struct scic_sds_controller *controller, |
| 535 | struct scic_sds_remote_device *sci_dev, |
| 536 | struct scic_sds_request *io_request) |
| 537 | { |
| 538 | return sci_dev->state_handlers->start_task_handler( |
| 539 | sci_dev, io_request); |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 544 | * @sci_dev: |
| 545 | * @request: |
| 546 | * |
| 547 | * This method takes the request and bulids an appropriate SCU context for the |
| 548 | * request and then requests the controller to post the request. none |
| 549 | */ |
| 550 | void scic_sds_remote_device_post_request( |
| 551 | struct scic_sds_remote_device *sci_dev, |
| 552 | u32 request) |
| 553 | { |
| 554 | u32 context; |
| 555 | |
| 556 | context = scic_sds_remote_device_build_command_context(sci_dev, request); |
| 557 | |
| 558 | scic_sds_controller_post_request( |
| 559 | scic_sds_remote_device_get_controller(sci_dev), |
| 560 | context |
| 561 | ); |
| 562 | } |
| 563 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 564 | /* called once the remote node context has transisitioned to a |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 565 | * ready state. This is the indication that the remote device object can also |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 566 | * transition to ready. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 567 | */ |
Dan Williams | eb22967 | 2011-05-01 14:05:57 -0700 | [diff] [blame] | 568 | static void remote_device_resume_done(void *_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 569 | { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 570 | struct scic_sds_remote_device *sci_dev = _dev; |
| 571 | enum scic_sds_remote_device_states state; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 572 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 573 | state = sci_dev->state_machine.current_state_id; |
| 574 | switch (state) { |
| 575 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 576 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 577 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 578 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 579 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 580 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 581 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 582 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 583 | break; |
| 584 | default: |
| 585 | /* go 'ready' if we are not already in a ready state */ |
| 586 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 587 | SCI_BASE_REMOTE_DEVICE_STATE_READY); |
| 588 | break; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 594 | * @request: This parameter specifies the request being continued. |
| 595 | * |
| 596 | * This method will continue to post tc for a STP request. This method usually |
| 597 | * serves as a callback when RNC gets resumed during a task management |
| 598 | * sequence. none |
| 599 | */ |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 600 | static void scic_sds_remote_device_continue_request(void *dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 601 | { |
| 602 | struct scic_sds_remote_device *sci_dev = dev; |
| 603 | |
| 604 | /* we need to check if this request is still valid to continue. */ |
| 605 | if (sci_dev->working_request) |
| 606 | scic_controller_continue_io(sci_dev->working_request); |
| 607 | } |
| 608 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 609 | static enum sci_status |
| 610 | default_device_handler(struct scic_sds_remote_device *sci_dev, |
| 611 | const char *func) |
| 612 | { |
| 613 | dev_warn(scirdev_to_dev(sci_dev), |
| 614 | "%s: in wrong state: %d\n", func, |
| 615 | sci_base_state_machine_get_state(&sci_dev->state_machine)); |
| 616 | return SCI_FAILURE_INVALID_STATE; |
| 617 | } |
| 618 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 619 | static enum sci_status scic_sds_remote_device_default_suspend_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 620 | struct scic_sds_remote_device *sci_dev, u32 suspend_type) |
| 621 | { |
| 622 | return default_device_handler(sci_dev, __func__); |
| 623 | } |
| 624 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 625 | static enum sci_status scic_sds_remote_device_default_resume_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 626 | struct scic_sds_remote_device *sci_dev) |
| 627 | { |
| 628 | return default_device_handler(sci_dev, __func__); |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * |
| 633 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 634 | * struct scic_sds_remote_device. |
| 635 | * @event_code: The event code that the struct scic_sds_controller wants the device |
| 636 | * object to process. |
| 637 | * |
| 638 | * This method is the default event handler. It will call the RNC state |
| 639 | * machine handler for any RNC events otherwise it will log a warning and |
| 640 | * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE |
| 641 | */ |
| 642 | static enum sci_status scic_sds_remote_device_core_event_handler( |
| 643 | struct scic_sds_remote_device *sci_dev, |
| 644 | u32 event_code, |
| 645 | bool is_ready_state) |
| 646 | { |
| 647 | enum sci_status status; |
| 648 | |
| 649 | switch (scu_get_event_type(event_code)) { |
| 650 | case SCU_EVENT_TYPE_RNC_OPS_MISC: |
| 651 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 652 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 653 | status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code); |
| 654 | break; |
| 655 | case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT: |
| 656 | |
| 657 | if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) { |
| 658 | status = SCI_SUCCESS; |
| 659 | |
| 660 | /* Suspend the associated RNC */ |
| 661 | scic_sds_remote_node_context_suspend(&sci_dev->rnc, |
| 662 | SCI_SOFTWARE_SUSPENSION, |
| 663 | NULL, NULL); |
| 664 | |
| 665 | dev_dbg(scirdev_to_dev(sci_dev), |
| 666 | "%s: device: %p event code: %x: %s\n", |
| 667 | __func__, sci_dev, event_code, |
| 668 | (is_ready_state) |
| 669 | ? "I_T_Nexus_Timeout event" |
| 670 | : "I_T_Nexus_Timeout event in wrong state"); |
| 671 | |
| 672 | break; |
| 673 | } |
| 674 | /* Else, fall through and treat as unhandled... */ |
| 675 | |
| 676 | default: |
| 677 | dev_dbg(scirdev_to_dev(sci_dev), |
| 678 | "%s: device: %p event code: %x: %s\n", |
| 679 | __func__, sci_dev, event_code, |
| 680 | (is_ready_state) |
| 681 | ? "unexpected event" |
| 682 | : "unexpected event in wrong state"); |
| 683 | status = SCI_FAILURE_INVALID_STATE; |
| 684 | break; |
| 685 | } |
| 686 | |
| 687 | return status; |
| 688 | } |
| 689 | /** |
| 690 | * |
| 691 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 692 | * struct scic_sds_remote_device. |
| 693 | * @event_code: The event code that the struct scic_sds_controller wants the device |
| 694 | * object to process. |
| 695 | * |
| 696 | * This method is the default event handler. It will call the RNC state |
| 697 | * machine handler for any RNC events otherwise it will log a warning and |
| 698 | * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE |
| 699 | */ |
| 700 | static enum sci_status scic_sds_remote_device_default_event_handler( |
| 701 | struct scic_sds_remote_device *sci_dev, |
| 702 | u32 event_code) |
| 703 | { |
| 704 | return scic_sds_remote_device_core_event_handler(sci_dev, |
| 705 | event_code, |
| 706 | false); |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * |
| 711 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 712 | * struct scic_sds_remote_device. |
| 713 | * @frame_index: The frame index for which the struct scic_sds_controller wants this |
| 714 | * device object to process. |
| 715 | * |
| 716 | * This method is the default unsolicited frame handler. It logs a warning, |
| 717 | * releases the frame and returns a failure. enum sci_status |
| 718 | * SCI_FAILURE_INVALID_STATE |
| 719 | */ |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 720 | static enum sci_status scic_sds_remote_device_default_frame_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 721 | struct scic_sds_remote_device *sci_dev, |
| 722 | u32 frame_index) |
| 723 | { |
| 724 | dev_warn(scirdev_to_dev(sci_dev), |
| 725 | "%s: SCIC Remote Device requested to handle frame %x " |
| 726 | "while in wrong state %d\n", |
| 727 | __func__, |
| 728 | frame_index, |
| 729 | sci_base_state_machine_get_state( |
| 730 | &sci_dev->state_machine)); |
| 731 | |
| 732 | /* Return the frame back to the controller */ |
| 733 | scic_sds_controller_release_frame( |
| 734 | scic_sds_remote_device_get_controller(sci_dev), frame_index |
| 735 | ); |
| 736 | |
| 737 | return SCI_FAILURE_INVALID_STATE; |
| 738 | } |
| 739 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 740 | static enum sci_status scic_sds_remote_device_default_start_request_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 741 | struct scic_sds_remote_device *sci_dev, |
| 742 | struct scic_sds_request *request) |
| 743 | { |
| 744 | return default_device_handler(sci_dev, __func__); |
| 745 | } |
| 746 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 747 | static enum sci_status scic_sds_remote_device_default_complete_request_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 748 | struct scic_sds_remote_device *sci_dev, |
| 749 | struct scic_sds_request *request) |
| 750 | { |
| 751 | return default_device_handler(sci_dev, __func__); |
| 752 | } |
| 753 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 754 | static enum sci_status scic_sds_remote_device_default_continue_request_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 755 | struct scic_sds_remote_device *sci_dev, |
| 756 | struct scic_sds_request *request) |
| 757 | { |
| 758 | return default_device_handler(sci_dev, __func__); |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * |
| 763 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 764 | * struct scic_sds_remote_device. |
| 765 | * @frame_index: The frame index for which the struct scic_sds_controller wants this |
| 766 | * device object to process. |
| 767 | * |
| 768 | * This method is a general ssp frame handler. In most cases the device object |
| 769 | * needs to route the unsolicited frame processing to the io request object. |
| 770 | * This method decodes the tag for the io request object and routes the |
| 771 | * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE |
| 772 | */ |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 773 | static enum sci_status scic_sds_remote_device_general_frame_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 774 | struct scic_sds_remote_device *sci_dev, |
| 775 | u32 frame_index) |
| 776 | { |
| 777 | enum sci_status result; |
| 778 | struct sci_ssp_frame_header *frame_header; |
| 779 | struct scic_sds_request *io_request; |
| 780 | |
| 781 | result = scic_sds_unsolicited_frame_control_get_header( |
| 782 | &(scic_sds_remote_device_get_controller(sci_dev)->uf_control), |
| 783 | frame_index, |
| 784 | (void **)&frame_header |
| 785 | ); |
| 786 | |
| 787 | if (SCI_SUCCESS == result) { |
| 788 | io_request = scic_sds_controller_get_io_request_from_tag( |
| 789 | scic_sds_remote_device_get_controller(sci_dev), frame_header->tag); |
| 790 | |
| 791 | if ((io_request == NULL) |
| 792 | || (io_request->target_device != sci_dev)) { |
| 793 | /* |
| 794 | * We could not map this tag to a valid IO request |
| 795 | * Just toss the frame and continue */ |
| 796 | scic_sds_controller_release_frame( |
| 797 | scic_sds_remote_device_get_controller(sci_dev), frame_index |
| 798 | ); |
| 799 | } else { |
| 800 | /* The IO request is now in charge of releasing the frame */ |
| 801 | result = io_request->state_handlers->frame_handler( |
| 802 | io_request, frame_index); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | return result; |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * |
| 811 | * @[in]: sci_dev This is the device object that is receiving the event. |
| 812 | * @[in]: event_code The event code to process. |
| 813 | * |
| 814 | * This is a common method for handling events reported to the remote device |
| 815 | * from the controller object. enum sci_status |
| 816 | */ |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 817 | static enum sci_status scic_sds_remote_device_general_event_handler( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 818 | struct scic_sds_remote_device *sci_dev, |
| 819 | u32 event_code) |
| 820 | { |
| 821 | return scic_sds_remote_device_core_event_handler(sci_dev, |
| 822 | event_code, |
| 823 | true); |
| 824 | } |
| 825 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 826 | /* |
| 827 | * This method will attempt to start a task request for this device object. The |
| 828 | * remote device object will issue the start request for the task and if |
| 829 | * successful it will start the request for the port object then increment its |
| 830 | * own requet count. enum sci_status SCI_SUCCESS if the task request is started for |
| 831 | * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request |
| 832 | * object could not get the resources to start. |
| 833 | */ |
| 834 | static enum sci_status scic_sds_remote_device_ready_state_start_task_handler( |
| 835 | struct scic_sds_remote_device *sci_dev, |
| 836 | struct scic_sds_request *request) |
| 837 | { |
| 838 | enum sci_status result; |
| 839 | |
| 840 | /* See if the port is in a state where we can start the IO request */ |
| 841 | result = scic_sds_port_start_io( |
| 842 | scic_sds_remote_device_get_port(sci_dev), sci_dev, request); |
| 843 | |
| 844 | if (result == SCI_SUCCESS) { |
| 845 | result = scic_sds_remote_node_context_start_task(&sci_dev->rnc, |
| 846 | request); |
| 847 | if (result == SCI_SUCCESS) |
| 848 | result = scic_sds_request_start(request); |
| 849 | |
| 850 | scic_sds_remote_device_start_request(sci_dev, request, result); |
| 851 | } |
| 852 | |
| 853 | return result; |
| 854 | } |
| 855 | |
| 856 | /* |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 857 | * This method will complete the request for the remote device object. The |
| 858 | * method will call the completion handler for the request object and if |
| 859 | * successful it will complete the request on the port object then decrement |
| 860 | * its own started_request_count. enum sci_status |
| 861 | */ |
| 862 | static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler( |
| 863 | struct scic_sds_remote_device *sci_dev, |
| 864 | struct scic_sds_request *request) |
| 865 | { |
| 866 | enum sci_status result; |
| 867 | |
| 868 | result = scic_sds_request_complete(request); |
| 869 | |
| 870 | if (result != SCI_SUCCESS) |
| 871 | return result; |
| 872 | |
| 873 | /* See if the port is in a state |
| 874 | * where we can start the IO request */ |
| 875 | result = scic_sds_port_complete_io( |
| 876 | scic_sds_remote_device_get_port(sci_dev), |
| 877 | sci_dev, request); |
| 878 | |
| 879 | if (result == SCI_SUCCESS) |
| 880 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 881 | |
| 882 | return result; |
| 883 | } |
| 884 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 885 | /** |
| 886 | * |
| 887 | * @device: The device object for which the request is completing. |
| 888 | * @request: The task request that is being completed. |
| 889 | * |
| 890 | * This method completes requests for this struct scic_sds_remote_device while it is |
| 891 | * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the |
| 892 | * complete method for the request object and if that is successful the port |
| 893 | * object is called to complete the task request. Then the device object itself |
| 894 | * completes the task request. If struct scic_sds_remote_device started_request_count |
| 895 | * goes to 0 and the invalidate RNC request has completed the device object can |
| 896 | * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status |
| 897 | */ |
| 898 | static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler( |
| 899 | struct scic_sds_remote_device *sci_dev, |
| 900 | struct scic_sds_request *request) |
| 901 | { |
| 902 | enum sci_status status = SCI_SUCCESS; |
| 903 | |
| 904 | status = scic_sds_request_complete(request); |
| 905 | |
| 906 | if (status != SCI_SUCCESS) |
| 907 | return status; |
| 908 | |
| 909 | status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev), |
| 910 | sci_dev, request); |
| 911 | if (status != SCI_SUCCESS) |
| 912 | return status; |
| 913 | |
| 914 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 915 | |
| 916 | if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 917 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
Dan Williams | ec57566 | 2011-05-01 14:19:25 -0700 | [diff] [blame] | 918 | rnc_destruct_done, sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 919 | return SCI_SUCCESS; |
| 920 | } |
| 921 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 922 | /* complete requests for this device while it is in the |
| 923 | * SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the complete |
| 924 | * method for the request object and if that is successful the port object is |
| 925 | * called to complete the task request. Then the device object itself completes |
| 926 | * the task request. enum sci_status |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 927 | */ |
| 928 | static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler( |
| 929 | struct scic_sds_remote_device *sci_dev, |
| 930 | struct scic_sds_request *request) |
| 931 | { |
| 932 | enum sci_status status = SCI_SUCCESS; |
| 933 | |
| 934 | status = scic_sds_request_complete(request); |
| 935 | |
| 936 | if (status == SCI_SUCCESS) { |
| 937 | status = scic_sds_port_complete_io( |
| 938 | scic_sds_remote_device_get_port(sci_dev), |
| 939 | sci_dev, request); |
| 940 | |
| 941 | if (status == SCI_SUCCESS) { |
| 942 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | return status; |
| 947 | } |
| 948 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 949 | static enum sci_status scic_sds_stp_remote_device_complete_request(struct scic_sds_remote_device *sci_dev, |
| 950 | struct scic_sds_request *sci_req) |
| 951 | { |
| 952 | enum sci_status status; |
| 953 | |
| 954 | status = scic_sds_io_request_complete(sci_req); |
| 955 | if (status != SCI_SUCCESS) |
| 956 | goto out; |
| 957 | |
| 958 | status = scic_sds_port_complete_io(sci_dev->owning_port, sci_dev, sci_req); |
| 959 | if (status != SCI_SUCCESS) |
| 960 | goto out; |
| 961 | |
| 962 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 963 | if (sci_req->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { |
| 964 | /* This request causes hardware error, device needs to be Lun Reset. |
| 965 | * So here we force the state machine to IDLE state so the rest IOs |
| 966 | * can reach RNC state handler, these IOs will be completed by RNC with |
| 967 | * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE". |
| 968 | */ |
| 969 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 970 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET); |
| 971 | } else if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 972 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 973 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 974 | |
| 975 | |
| 976 | out: |
| 977 | if (status != SCI_SUCCESS) |
| 978 | dev_err(scirdev_to_dev(sci_dev), |
| 979 | "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x " |
| 980 | "could not complete\n", __func__, sci_dev->owning_port, |
| 981 | sci_dev, sci_req, status); |
| 982 | |
| 983 | return status; |
| 984 | } |
| 985 | |
| 986 | /* scic_sds_stp_remote_device_ready_substate_start_request_handler - start stp |
| 987 | * @device: The target device a task management request towards to. |
| 988 | * @request: The task request. |
| 989 | * |
| 990 | * This is the READY NCQ substate handler to start task management request. In |
| 991 | * this routine, we suspend and resume the RNC. enum sci_status Always return |
| 992 | * SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS status to let |
| 993 | * controller_start_task_handler know that the controller can't post TC for |
| 994 | * task request yet, instead, when RNC gets resumed, a controller_continue_task |
| 995 | * callback will be called. |
| 996 | */ |
| 997 | static enum sci_status scic_sds_stp_remote_device_ready_substate_start_request_handler( |
| 998 | struct scic_sds_remote_device *device, |
| 999 | struct scic_sds_request *request) |
| 1000 | { |
| 1001 | enum sci_status status; |
| 1002 | |
| 1003 | /* Will the port allow the io request to start? */ |
| 1004 | status = device->owning_port->state_handlers->start_io_handler( |
| 1005 | device->owning_port, device, request); |
| 1006 | if (status != SCI_SUCCESS) |
| 1007 | return status; |
| 1008 | |
| 1009 | status = scic_sds_remote_node_context_start_task(&device->rnc, request); |
| 1010 | if (status != SCI_SUCCESS) |
| 1011 | goto out; |
| 1012 | |
| 1013 | status = request->state_handlers->start_handler(request); |
| 1014 | if (status != SCI_SUCCESS) |
| 1015 | goto out; |
| 1016 | |
| 1017 | /* |
| 1018 | * Note: If the remote device state is not IDLE this will replace |
| 1019 | * the request that probably resulted in the task management request. |
| 1020 | */ |
| 1021 | device->working_request = request; |
| 1022 | sci_base_state_machine_change_state(&device->state_machine, |
| 1023 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD); |
| 1024 | |
| 1025 | /* |
| 1026 | * The remote node context must cleanup the TCi to NCQ mapping table. |
| 1027 | * The only way to do this correctly is to either write to the TLCR |
| 1028 | * register or to invalidate and repost the RNC. In either case the |
| 1029 | * remote node context state machine will take the correct action when |
| 1030 | * the remote node context is suspended and later resumed. |
| 1031 | */ |
| 1032 | scic_sds_remote_node_context_suspend(&device->rnc, |
| 1033 | SCI_SOFTWARE_SUSPENSION, NULL, NULL); |
| 1034 | scic_sds_remote_node_context_resume(&device->rnc, |
| 1035 | scic_sds_remote_device_continue_request, |
| 1036 | device); |
| 1037 | |
| 1038 | out: |
| 1039 | scic_sds_remote_device_start_request(device, request, status); |
| 1040 | /* |
| 1041 | * We need to let the controller start request handler know that it can't |
| 1042 | * post TC yet. We will provide a callback function to post TC when RNC gets |
| 1043 | * resumed. |
| 1044 | */ |
| 1045 | return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS; |
| 1046 | } |
| 1047 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1048 | static enum sci_status scic_sds_stp_remote_device_ready_idle_substate_event_handler( |
| 1049 | struct scic_sds_remote_device *sci_dev, |
| 1050 | u32 event_code) |
| 1051 | { |
| 1052 | enum sci_status status; |
| 1053 | |
| 1054 | status = scic_sds_remote_device_general_event_handler(sci_dev, event_code); |
| 1055 | if (status != SCI_SUCCESS) |
| 1056 | return status; |
| 1057 | |
| 1058 | /* We pick up suspension events to handle specifically to this state. We |
| 1059 | * resume the RNC right away. enum sci_status |
| 1060 | */ |
| 1061 | if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX || |
| 1062 | scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX) |
| 1063 | status = scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL); |
| 1064 | |
| 1065 | return status; |
| 1066 | } |
| 1067 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1068 | static enum sci_status scic_sds_stp_remote_device_ready_ncq_substate_frame_handler(struct scic_sds_remote_device *sci_dev, |
| 1069 | u32 frame_index) |
| 1070 | { |
| 1071 | enum sci_status status; |
| 1072 | struct sata_fis_header *frame_header; |
| 1073 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 1074 | |
| 1075 | status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control, |
| 1076 | frame_index, |
| 1077 | (void **)&frame_header); |
| 1078 | if (status != SCI_SUCCESS) |
| 1079 | return status; |
| 1080 | |
| 1081 | if (frame_header->fis_type == SATA_FIS_TYPE_SETDEVBITS && |
| 1082 | (frame_header->status & ATA_STATUS_REG_ERROR_BIT)) { |
| 1083 | sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED; |
| 1084 | |
| 1085 | /* TODO Check sactive and complete associated IO if any. */ |
| 1086 | |
| 1087 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 1088 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR); |
| 1089 | } else if (frame_header->fis_type == SATA_FIS_TYPE_REGD2H && |
| 1090 | (frame_header->status & ATA_STATUS_REG_ERROR_BIT)) { |
| 1091 | /* |
| 1092 | * Some devices return D2H FIS when an NCQ error is detected. |
| 1093 | * Treat this like an SDB error FIS ready reason. |
| 1094 | */ |
| 1095 | sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED; |
| 1096 | |
| 1097 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 1098 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR); |
| 1099 | } else |
| 1100 | status = SCI_FAILURE; |
| 1101 | |
| 1102 | scic_sds_controller_release_frame(scic, frame_index); |
| 1103 | |
| 1104 | return status; |
| 1105 | } |
| 1106 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1107 | static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler( |
| 1108 | struct scic_sds_remote_device *sci_dev, |
| 1109 | u32 suspend_type) |
| 1110 | { |
| 1111 | enum sci_status status; |
| 1112 | |
| 1113 | status = scic_sds_remote_node_context_suspend(&sci_dev->rnc, |
| 1114 | suspend_type, NULL, NULL); |
| 1115 | |
| 1116 | return status; |
| 1117 | } |
| 1118 | |
| 1119 | static enum sci_status scic_sds_stp_remote_device_ready_cmd_substate_frame_handler( |
| 1120 | struct scic_sds_remote_device *sci_dev, |
| 1121 | u32 frame_index) |
| 1122 | { |
| 1123 | /* The device doe not process any UF received from the hardware while |
| 1124 | * in this state. All unsolicited frames are forwarded to the io |
| 1125 | * request object. |
| 1126 | */ |
| 1127 | return scic_sds_io_request_frame_handler(sci_dev->working_request, |
| 1128 | frame_index); |
| 1129 | } |
| 1130 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1131 | static void scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev) |
| 1132 | { |
| 1133 | struct scic_sds_remote_device *sci_dev = _dev; |
| 1134 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
| 1135 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 1136 | |
| 1137 | /* For NCQ operation we do not issue a isci_remote_device_not_ready(). |
| 1138 | * As a result, avoid sending the ready notification. |
| 1139 | */ |
| 1140 | if (sci_dev->state_machine.previous_state_id != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ) |
| 1141 | isci_remote_device_ready(scic->ihost, idev); |
| 1142 | } |
| 1143 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1144 | static enum sci_status scic_sds_smp_remote_device_ready_cmd_substate_frame_handler( |
| 1145 | struct scic_sds_remote_device *sci_dev, |
| 1146 | u32 frame_index) |
| 1147 | { |
| 1148 | enum sci_status status; |
| 1149 | |
| 1150 | /* The device does not process any UF received from the hardware while |
| 1151 | * in this state. All unsolicited frames are forwarded to the io request |
| 1152 | * object. |
| 1153 | */ |
| 1154 | status = scic_sds_io_request_frame_handler( |
| 1155 | sci_dev->working_request, |
| 1156 | frame_index |
| 1157 | ); |
| 1158 | |
| 1159 | return status; |
| 1160 | } |
| 1161 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1162 | static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = { |
| 1163 | [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1164 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1165 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1166 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1167 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1168 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1169 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1170 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1171 | }, |
| 1172 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1173 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1174 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1175 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1176 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1177 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1178 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1179 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1180 | }, |
| 1181 | [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1182 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1183 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1184 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1185 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1186 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1187 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1188 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1189 | }, |
| 1190 | [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1191 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1192 | .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler, |
| 1193 | .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler, |
| 1194 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1195 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1196 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1197 | .frame_handler = scic_sds_remote_device_general_frame_handler, |
| 1198 | }, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1199 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1200 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1201 | .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler, |
| 1202 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1203 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1204 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1205 | .event_handler = scic_sds_stp_remote_device_ready_idle_substate_event_handler, |
| 1206 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1207 | }, |
| 1208 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1209 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1210 | .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler, |
| 1211 | .complete_task_handler = scic_sds_stp_remote_device_complete_request, |
| 1212 | .suspend_handler = scic_sds_stp_remote_device_ready_cmd_substate_suspend_handler, |
| 1213 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1214 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1215 | .frame_handler = scic_sds_stp_remote_device_ready_cmd_substate_frame_handler |
| 1216 | }, |
| 1217 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1218 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1219 | .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler, |
| 1220 | .complete_task_handler = scic_sds_stp_remote_device_complete_request, |
| 1221 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1222 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1223 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1224 | .frame_handler = scic_sds_stp_remote_device_ready_ncq_substate_frame_handler |
| 1225 | }, |
| 1226 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1227 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1228 | .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler, |
| 1229 | .complete_task_handler = scic_sds_stp_remote_device_complete_request, |
| 1230 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1231 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1232 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1233 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1234 | }, |
| 1235 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1236 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1237 | .start_task_handler = scic_sds_stp_remote_device_ready_substate_start_request_handler, |
| 1238 | .complete_task_handler = scic_sds_stp_remote_device_complete_request, |
| 1239 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1240 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1241 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1242 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1243 | }, |
| 1244 | [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1245 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1246 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1247 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1248 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1249 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1250 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1251 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1252 | }, |
| 1253 | [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1254 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1255 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1256 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1257 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1258 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1259 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1260 | .frame_handler = scic_sds_smp_remote_device_ready_cmd_substate_frame_handler |
| 1261 | }, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1262 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1263 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1264 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1265 | .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler, |
| 1266 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1267 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1268 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1269 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1270 | }, |
| 1271 | [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1272 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1273 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1274 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1275 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1276 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1277 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1278 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1279 | }, |
| 1280 | [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1281 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1282 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1283 | .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler, |
| 1284 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1285 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1286 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1287 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1288 | }, |
| 1289 | [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1290 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1291 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1292 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1293 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1294 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1295 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1296 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1297 | } |
| 1298 | }; |
| 1299 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1300 | static void scic_sds_remote_device_initial_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1301 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1302 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1303 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1304 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1305 | SCI_BASE_REMOTE_DEVICE_STATE_INITIAL); |
| 1306 | |
| 1307 | /* Initial state is a transitional state to the stopped state */ |
| 1308 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 1309 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 1310 | } |
| 1311 | |
| 1312 | /** |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1313 | * scic_remote_device_destruct() - free remote node context and destruct |
| 1314 | * @remote_device: This parameter specifies the remote device to be destructed. |
| 1315 | * |
| 1316 | * Remote device objects are a limited resource. As such, they must be |
| 1317 | * protected. Thus calls to construct and destruct are mutually exclusive and |
| 1318 | * non-reentrant. The return value shall indicate if the device was |
| 1319 | * successfully destructed or if some failure occurred. enum sci_status This value |
| 1320 | * is returned if the device is successfully destructed. |
| 1321 | * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied |
| 1322 | * device isn't valid (e.g. it's already been destoryed, the handle isn't |
| 1323 | * valid, etc.). |
| 1324 | */ |
| 1325 | static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev) |
| 1326 | { |
Dan Williams | b8d82f6 | 2011-05-01 14:38:26 -0700 | [diff] [blame] | 1327 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 1328 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 1329 | struct scic_sds_controller *scic; |
| 1330 | |
| 1331 | if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) { |
| 1332 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 1333 | __func__, state); |
| 1334 | return SCI_FAILURE_INVALID_STATE; |
| 1335 | } |
| 1336 | |
| 1337 | scic = sci_dev->owning_port->owning_controller; |
| 1338 | scic_sds_controller_free_remote_node_context(scic, sci_dev, |
| 1339 | sci_dev->rnc.remote_node_index); |
| 1340 | sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX; |
| 1341 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_FINAL); |
| 1342 | |
| 1343 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1346 | /** |
| 1347 | * isci_remote_device_deconstruct() - This function frees an isci_remote_device. |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1348 | * @ihost: This parameter specifies the isci host object. |
| 1349 | * @idev: This parameter specifies the remote device to be freed. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1350 | * |
| 1351 | */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1352 | static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1353 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1354 | dev_dbg(&ihost->pdev->dev, |
| 1355 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1356 | |
| 1357 | /* There should not be any outstanding io's. All paths to |
| 1358 | * here should go through isci_remote_device_nuke_requests. |
| 1359 | * If we hit this condition, we will need a way to complete |
| 1360 | * io requests in process */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1361 | while (!list_empty(&idev->reqs_in_process)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1362 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1363 | dev_err(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1364 | "%s: ** request list not empty! **\n", __func__); |
| 1365 | BUG(); |
| 1366 | } |
| 1367 | |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1368 | scic_remote_device_destruct(&idev->sci); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1369 | idev->domain_dev->lldd_dev = NULL; |
| 1370 | idev->domain_dev = NULL; |
| 1371 | idev->isci_port = NULL; |
| 1372 | list_del_init(&idev->node); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1373 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1374 | clear_bit(IDEV_START_PENDING, &idev->flags); |
| 1375 | clear_bit(IDEV_STOP_PENDING, &idev->flags); |
| 1376 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1379 | /** |
| 1380 | * isci_remote_device_stop_complete() - This function is called by the scic |
| 1381 | * when the remote device stop has completed. We mark the isci device as not |
| 1382 | * ready and remove the isci remote device. |
| 1383 | * @ihost: This parameter specifies the isci host object. |
| 1384 | * @idev: This parameter specifies the remote device. |
| 1385 | * @status: This parameter specifies status of the completion. |
| 1386 | * |
| 1387 | */ |
| 1388 | static void isci_remote_device_stop_complete(struct isci_host *ihost, |
| 1389 | struct isci_remote_device *idev) |
| 1390 | { |
| 1391 | dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev); |
| 1392 | |
| 1393 | isci_remote_device_change_state(idev, isci_stopped); |
| 1394 | |
| 1395 | /* after stop, we can tear down resources. */ |
| 1396 | isci_remote_device_deconstruct(ihost, idev); |
| 1397 | } |
| 1398 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1399 | static void scic_sds_remote_device_stopped_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1400 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1401 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1402 | struct scic_sds_controller *scic; |
| 1403 | struct isci_remote_device *idev; |
| 1404 | struct isci_host *ihost; |
| 1405 | u32 prev_state; |
| 1406 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1407 | scic = scic_sds_remote_device_get_controller(sci_dev); |
Maciej Patelczyk | d3757c3 | 2011-04-28 22:06:06 +0000 | [diff] [blame] | 1408 | ihost = scic->ihost; |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1409 | idev = sci_dev_to_idev(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1410 | |
| 1411 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1412 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 1413 | |
| 1414 | /* If we are entering from the stopping state let the SCI User know that |
| 1415 | * the stop operation has completed. |
| 1416 | */ |
| 1417 | prev_state = sci_dev->state_machine.previous_state_id; |
| 1418 | if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING) |
| 1419 | isci_remote_device_stop_complete(ihost, idev); |
| 1420 | |
| 1421 | scic_sds_controller_remote_device_stopped(scic, sci_dev); |
| 1422 | } |
| 1423 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1424 | static void scic_sds_remote_device_starting_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1425 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1426 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1427 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
Maciej Patelczyk | d3757c3 | 2011-04-28 22:06:06 +0000 | [diff] [blame] | 1428 | struct isci_host *ihost = scic->ihost; |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1429 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1430 | |
| 1431 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1432 | SCI_BASE_REMOTE_DEVICE_STATE_STARTING); |
| 1433 | |
| 1434 | isci_remote_device_not_ready(ihost, idev, |
| 1435 | SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED); |
| 1436 | } |
| 1437 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1438 | static void scic_sds_remote_device_ready_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1439 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1440 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1441 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 1442 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1443 | |
| 1444 | SET_STATE_HANDLER(sci_dev, |
| 1445 | scic_sds_remote_device_state_handler_table, |
| 1446 | SCI_BASE_REMOTE_DEVICE_STATE_READY); |
| 1447 | |
| 1448 | scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++; |
| 1449 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1450 | if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_SATA)) { |
| 1451 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 1452 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 1453 | } else if (dev_is_expander(dev)) { |
| 1454 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 1455 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 1456 | } else |
| 1457 | isci_remote_device_ready(scic->ihost, sci_dev_to_idev(sci_dev)); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1460 | static void scic_sds_remote_device_ready_state_exit(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1461 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1462 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1463 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
| 1464 | |
| 1465 | if (dev->dev_type == SAS_END_DEV) { |
| 1466 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1467 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1468 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1469 | isci_remote_device_not_ready(scic->ihost, idev, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1470 | SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED); |
| 1471 | } |
| 1472 | } |
| 1473 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1474 | static void scic_sds_remote_device_stopping_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1475 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1476 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1477 | |
| 1478 | SET_STATE_HANDLER( |
| 1479 | sci_dev, |
| 1480 | scic_sds_remote_device_state_handler_table, |
| 1481 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPING |
| 1482 | ); |
| 1483 | } |
| 1484 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1485 | static void scic_sds_remote_device_failed_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1486 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1487 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1488 | |
| 1489 | SET_STATE_HANDLER( |
| 1490 | sci_dev, |
| 1491 | scic_sds_remote_device_state_handler_table, |
| 1492 | SCI_BASE_REMOTE_DEVICE_STATE_FAILED |
| 1493 | ); |
| 1494 | } |
| 1495 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1496 | static void scic_sds_remote_device_resetting_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1497 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1498 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1499 | |
| 1500 | SET_STATE_HANDLER( |
| 1501 | sci_dev, |
| 1502 | scic_sds_remote_device_state_handler_table, |
| 1503 | SCI_BASE_REMOTE_DEVICE_STATE_RESETTING |
| 1504 | ); |
| 1505 | |
| 1506 | scic_sds_remote_node_context_suspend( |
| 1507 | &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL); |
| 1508 | } |
| 1509 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1510 | static void scic_sds_remote_device_resetting_state_exit(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1511 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1512 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1513 | |
| 1514 | scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL); |
| 1515 | } |
| 1516 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 1517 | static void scic_sds_remote_device_final_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1518 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1519 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1520 | |
| 1521 | SET_STATE_HANDLER( |
| 1522 | sci_dev, |
| 1523 | scic_sds_remote_device_state_handler_table, |
| 1524 | SCI_BASE_REMOTE_DEVICE_STATE_FINAL |
| 1525 | ); |
| 1526 | } |
| 1527 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1528 | static void scic_sds_stp_remote_device_ready_idle_substate_enter(void *object) |
| 1529 | { |
| 1530 | struct scic_sds_remote_device *sci_dev = object; |
| 1531 | |
| 1532 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1533 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 1534 | |
| 1535 | sci_dev->working_request = NULL; |
| 1536 | if (scic_sds_remote_node_context_is_ready(&sci_dev->rnc)) { |
| 1537 | /* |
| 1538 | * Since the RNC is ready, it's alright to finish completion |
| 1539 | * processing (e.g. signal the remote device is ready). */ |
| 1540 | scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(sci_dev); |
| 1541 | } else { |
| 1542 | scic_sds_remote_node_context_resume(&sci_dev->rnc, |
| 1543 | scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler, |
| 1544 | sci_dev); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | static void scic_sds_stp_remote_device_ready_cmd_substate_enter(void *object) |
| 1549 | { |
| 1550 | struct scic_sds_remote_device *sci_dev = object; |
| 1551 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1552 | |
| 1553 | BUG_ON(sci_dev->working_request == NULL); |
| 1554 | |
| 1555 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1556 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD); |
| 1557 | |
| 1558 | isci_remote_device_not_ready(scic->ihost, sci_dev_to_idev(sci_dev), |
| 1559 | SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED); |
| 1560 | } |
| 1561 | |
| 1562 | static void scic_sds_stp_remote_device_ready_ncq_substate_enter(void *object) |
| 1563 | { |
| 1564 | struct scic_sds_remote_device *sci_dev = object; |
| 1565 | |
| 1566 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1567 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ); |
| 1568 | } |
| 1569 | |
| 1570 | static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(void *object) |
| 1571 | { |
| 1572 | struct scic_sds_remote_device *sci_dev = object; |
| 1573 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1574 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
| 1575 | |
| 1576 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1577 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR); |
| 1578 | |
| 1579 | if (sci_dev->not_ready_reason == SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED) |
| 1580 | isci_remote_device_not_ready(scic->ihost, idev, |
| 1581 | sci_dev->not_ready_reason); |
| 1582 | } |
| 1583 | |
| 1584 | static void scic_sds_stp_remote_device_ready_await_reset_substate_enter(void *object) |
| 1585 | { |
| 1586 | struct scic_sds_remote_device *sci_dev = object; |
| 1587 | |
| 1588 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1589 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET); |
| 1590 | } |
| 1591 | |
| 1592 | static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object) |
| 1593 | { |
| 1594 | struct scic_sds_remote_device *sci_dev = object; |
| 1595 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1596 | |
| 1597 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1598 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 1599 | |
| 1600 | isci_remote_device_ready(scic->ihost, sci_dev_to_idev(sci_dev)); |
| 1601 | } |
| 1602 | |
| 1603 | static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object) |
| 1604 | { |
| 1605 | struct scic_sds_remote_device *sci_dev = object; |
| 1606 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1607 | |
| 1608 | BUG_ON(sci_dev->working_request == NULL); |
| 1609 | |
| 1610 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1611 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD); |
| 1612 | |
| 1613 | isci_remote_device_not_ready(scic->ihost, sci_dev_to_idev(sci_dev), |
| 1614 | SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED); |
| 1615 | } |
| 1616 | |
| 1617 | static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object) |
| 1618 | { |
| 1619 | struct scic_sds_remote_device *sci_dev = object; |
| 1620 | |
| 1621 | sci_dev->working_request = NULL; |
| 1622 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1623 | |
| 1624 | static const struct sci_base_state scic_sds_remote_device_state_table[] = { |
| 1625 | [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { |
| 1626 | .enter_state = scic_sds_remote_device_initial_state_enter, |
| 1627 | }, |
| 1628 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { |
| 1629 | .enter_state = scic_sds_remote_device_stopped_state_enter, |
| 1630 | }, |
| 1631 | [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { |
| 1632 | .enter_state = scic_sds_remote_device_starting_state_enter, |
| 1633 | }, |
| 1634 | [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { |
| 1635 | .enter_state = scic_sds_remote_device_ready_state_enter, |
| 1636 | .exit_state = scic_sds_remote_device_ready_state_exit |
| 1637 | }, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1638 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = { |
| 1639 | .enter_state = scic_sds_stp_remote_device_ready_idle_substate_enter, |
| 1640 | }, |
| 1641 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = { |
| 1642 | .enter_state = scic_sds_stp_remote_device_ready_cmd_substate_enter, |
| 1643 | }, |
| 1644 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = { |
| 1645 | .enter_state = scic_sds_stp_remote_device_ready_ncq_substate_enter, |
| 1646 | }, |
| 1647 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = { |
| 1648 | .enter_state = scic_sds_stp_remote_device_ready_ncq_error_substate_enter, |
| 1649 | }, |
| 1650 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = { |
| 1651 | .enter_state = scic_sds_stp_remote_device_ready_await_reset_substate_enter, |
| 1652 | }, |
| 1653 | [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = { |
| 1654 | .enter_state = scic_sds_smp_remote_device_ready_idle_substate_enter, |
| 1655 | }, |
| 1656 | [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = { |
| 1657 | .enter_state = scic_sds_smp_remote_device_ready_cmd_substate_enter, |
| 1658 | .exit_state = scic_sds_smp_remote_device_ready_cmd_substate_exit, |
| 1659 | }, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1660 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { |
| 1661 | .enter_state = scic_sds_remote_device_stopping_state_enter, |
| 1662 | }, |
| 1663 | [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { |
| 1664 | .enter_state = scic_sds_remote_device_failed_state_enter, |
| 1665 | }, |
| 1666 | [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { |
| 1667 | .enter_state = scic_sds_remote_device_resetting_state_enter, |
| 1668 | .exit_state = scic_sds_remote_device_resetting_state_exit |
| 1669 | }, |
| 1670 | [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { |
| 1671 | .enter_state = scic_sds_remote_device_final_state_enter, |
| 1672 | }, |
| 1673 | }; |
| 1674 | |
| 1675 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1676 | * scic_remote_device_construct() - common construction |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1677 | * @sci_port: SAS/SATA port through which this device is accessed. |
| 1678 | * @sci_dev: remote device to construct |
| 1679 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1680 | * This routine just performs benign initialization and does not |
| 1681 | * allocate the remote_node_context which is left to |
| 1682 | * scic_remote_device_[de]a_construct(). scic_remote_device_destruct() |
| 1683 | * frees the remote_node_context(s) for the device. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1684 | */ |
| 1685 | static void scic_remote_device_construct(struct scic_sds_port *sci_port, |
| 1686 | struct scic_sds_remote_device *sci_dev) |
| 1687 | { |
| 1688 | sci_dev->owning_port = sci_port; |
| 1689 | sci_dev->started_request_count = 0; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1690 | |
| 1691 | sci_base_state_machine_construct( |
| 1692 | &sci_dev->state_machine, |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1693 | sci_dev, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1694 | scic_sds_remote_device_state_table, |
| 1695 | SCI_BASE_REMOTE_DEVICE_STATE_INITIAL |
| 1696 | ); |
| 1697 | |
| 1698 | sci_base_state_machine_start( |
| 1699 | &sci_dev->state_machine |
| 1700 | ); |
| 1701 | |
| 1702 | scic_sds_remote_node_context_construct(&sci_dev->rnc, |
| 1703 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1707 | * scic_remote_device_da_construct() - construct direct attached device. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1708 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1709 | * The information (e.g. IAF, Signature FIS, etc.) necessary to build |
| 1710 | * the device is known to the SCI Core since it is contained in the |
| 1711 | * scic_phy object. Remote node context(s) is/are a global resource |
| 1712 | * allocated by this routine, freed by scic_remote_device_destruct(). |
| 1713 | * |
| 1714 | * Returns: |
| 1715 | * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed. |
| 1716 | * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to |
| 1717 | * sata-only controller instance. |
| 1718 | * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1719 | */ |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1720 | static enum sci_status scic_remote_device_da_construct(struct scic_sds_port *sci_port, |
| 1721 | struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1722 | { |
| 1723 | enum sci_status status; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1724 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1725 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1726 | scic_remote_device_construct(sci_port, sci_dev); |
| 1727 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1728 | /* |
| 1729 | * This information is request to determine how many remote node context |
| 1730 | * entries will be needed to store the remote node. |
| 1731 | */ |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1732 | sci_dev->is_direct_attached = true; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1733 | status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller, |
| 1734 | sci_dev, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1735 | &sci_dev->rnc.remote_node_index); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1736 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1737 | if (status != SCI_SUCCESS) |
| 1738 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1739 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1740 | if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV || |
| 1741 | (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev)) |
| 1742 | /* pass */; |
| 1743 | else |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1744 | return SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1745 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1746 | sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(sci_port); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1747 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1748 | /* / @todo Should I assign the port width by reading all of the phys on the port? */ |
| 1749 | sci_dev->device_port_width = 1; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1750 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1751 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1754 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1755 | * scic_remote_device_ea_construct() - construct expander attached device |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1756 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1757 | * Remote node context(s) is/are a global resource allocated by this |
| 1758 | * routine, freed by scic_remote_device_destruct(). |
| 1759 | * |
| 1760 | * Returns: |
| 1761 | * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed. |
| 1762 | * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to |
| 1763 | * sata-only controller instance. |
| 1764 | * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1765 | */ |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1766 | static enum sci_status scic_remote_device_ea_construct(struct scic_sds_port *sci_port, |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1767 | struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1768 | { |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1769 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1770 | enum sci_status status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1771 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1772 | scic_remote_device_construct(sci_port, sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1773 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1774 | status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller, |
| 1775 | sci_dev, |
| 1776 | &sci_dev->rnc.remote_node_index); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1777 | if (status != SCI_SUCCESS) |
| 1778 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1779 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1780 | if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV || |
| 1781 | (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev)) |
| 1782 | /* pass */; |
| 1783 | else |
| 1784 | return SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1785 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1786 | /* |
| 1787 | * For SAS-2 the physical link rate is actually a logical link |
| 1788 | * rate that incorporates multiplexing. The SCU doesn't |
| 1789 | * incorporate multiplexing and for the purposes of the |
| 1790 | * connection the logical link rate is that same as the |
| 1791 | * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay |
| 1792 | * one another, so this code works for both situations. */ |
| 1793 | sci_dev->connection_rate = min_t(u16, scic_sds_port_get_max_allowed_speed(sci_port), |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1794 | dev->linkrate); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1795 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1796 | /* / @todo Should I assign the port width by reading all of the phys on the port? */ |
| 1797 | sci_dev->device_port_width = 1; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1798 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1799 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | /** |
| 1803 | * scic_remote_device_start() - This method will start the supplied remote |
| 1804 | * device. This method enables normal IO requests to flow through to the |
| 1805 | * remote device. |
| 1806 | * @remote_device: This parameter specifies the device to be started. |
| 1807 | * @timeout: This parameter specifies the number of milliseconds in which the |
| 1808 | * start operation should complete. |
| 1809 | * |
| 1810 | * An indication of whether the device was successfully started. SCI_SUCCESS |
| 1811 | * This value is returned if the device was successfully started. |
| 1812 | * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start |
| 1813 | * the device when there have been no phys added to it. |
| 1814 | */ |
| 1815 | static enum sci_status scic_remote_device_start(struct scic_sds_remote_device *sci_dev, |
Dan Williams | eb22967 | 2011-05-01 14:05:57 -0700 | [diff] [blame] | 1816 | u32 timeout) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1817 | { |
Dan Williams | eb22967 | 2011-05-01 14:05:57 -0700 | [diff] [blame] | 1818 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 1819 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 1820 | enum sci_status status; |
| 1821 | |
| 1822 | if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) { |
| 1823 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 1824 | __func__, state); |
| 1825 | return SCI_FAILURE_INVALID_STATE; |
| 1826 | } |
| 1827 | |
| 1828 | status = scic_sds_remote_node_context_resume(&sci_dev->rnc, |
| 1829 | remote_device_resume_done, |
| 1830 | sci_dev); |
| 1831 | if (status != SCI_SUCCESS) |
| 1832 | return status; |
| 1833 | |
| 1834 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STARTING); |
| 1835 | |
| 1836 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1837 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1838 | |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1839 | static enum sci_status isci_remote_device_construct(struct isci_port *iport, |
| 1840 | struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1841 | { |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1842 | struct scic_sds_port *sci_port = iport->sci_port_handle; |
| 1843 | struct isci_host *ihost = iport->isci_host; |
| 1844 | struct domain_device *dev = idev->domain_dev; |
| 1845 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1846 | |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1847 | if (dev->parent && dev_is_expander(dev->parent)) |
| 1848 | status = scic_remote_device_ea_construct(sci_port, &idev->sci); |
| 1849 | else |
| 1850 | status = scic_remote_device_da_construct(sci_port, &idev->sci); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1851 | |
| 1852 | if (status != SCI_SUCCESS) { |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1853 | dev_dbg(&ihost->pdev->dev, "%s: construct failed: %d\n", |
| 1854 | __func__, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1855 | |
| 1856 | return status; |
| 1857 | } |
| 1858 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1859 | /* start the device. */ |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1860 | status = scic_remote_device_start(&idev->sci, ISCI_REMOTE_DEVICE_START_TIMEOUT); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1861 | |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1862 | if (status != SCI_SUCCESS) |
| 1863 | dev_warn(&ihost->pdev->dev, "remote device start failed: %d\n", |
| 1864 | status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1865 | |
| 1866 | return status; |
| 1867 | } |
| 1868 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1869 | void isci_remote_device_nuke_requests(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1870 | { |
| 1871 | DECLARE_COMPLETION_ONSTACK(aborted_task_completion); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1872 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1873 | dev_dbg(&ihost->pdev->dev, |
| 1874 | "%s: idev = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1875 | |
| 1876 | /* Cleanup all requests pending for this device. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1877 | isci_terminate_pending_requests(ihost, idev, terminating); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1878 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1879 | dev_dbg(&ihost->pdev->dev, |
| 1880 | "%s: idev = %p, done\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1883 | /** |
| 1884 | * This function builds the isci_remote_device when a libsas dev_found message |
| 1885 | * is received. |
| 1886 | * @isci_host: This parameter specifies the isci host object. |
| 1887 | * @port: This parameter specifies the isci_port conected to this device. |
| 1888 | * |
| 1889 | * pointer to new isci_remote_device. |
| 1890 | */ |
| 1891 | static struct isci_remote_device * |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1892 | isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1893 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1894 | struct isci_remote_device *idev; |
| 1895 | int i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1896 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1897 | for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1898 | idev = &ihost->devices[i]; |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1899 | if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags)) |
| 1900 | break; |
| 1901 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1902 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1903 | if (i >= SCI_MAX_REMOTE_DEVICES) { |
| 1904 | dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1905 | return NULL; |
| 1906 | } |
| 1907 | |
Bartosz Barcinski | 6cb4d6b | 2011-04-12 17:28:43 -0700 | [diff] [blame] | 1908 | if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n")) |
| 1909 | return NULL; |
| 1910 | |
| 1911 | if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n")) |
| 1912 | return NULL; |
| 1913 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1914 | isci_remote_device_change_state(idev, isci_freed); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1915 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1916 | return idev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1917 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1918 | |
| 1919 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1920 | * isci_remote_device_stop() - This function is called internally to stop the |
| 1921 | * remote device. |
| 1922 | * @isci_host: This parameter specifies the isci host object. |
| 1923 | * @isci_device: This parameter specifies the remote device. |
| 1924 | * |
| 1925 | * The status of the scic request to stop. |
| 1926 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1927 | enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1928 | { |
| 1929 | enum sci_status status; |
| 1930 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1931 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1932 | dev_dbg(&ihost->pdev->dev, |
| 1933 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1934 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1935 | isci_remote_device_change_state(idev, isci_stopping); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 1936 | |
| 1937 | /* Kill all outstanding requests. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1938 | isci_remote_device_nuke_requests(ihost, idev); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 1939 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1940 | set_bit(IDEV_STOP_PENDING, &idev->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1941 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1942 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1943 | status = scic_remote_device_stop(&idev->sci, 50); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1944 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1945 | |
| 1946 | /* Wait for the stop complete callback. */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1947 | if (status == SCI_SUCCESS) { |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1948 | wait_for_device_stop(ihost, idev); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1949 | clear_bit(IDEV_ALLOCATED, &idev->flags); |
| 1950 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1951 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1952 | dev_dbg(&ihost->pdev->dev, |
| 1953 | "%s: idev = %p - after completion wait\n", |
| 1954 | __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1955 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1956 | return status; |
| 1957 | } |
| 1958 | |
| 1959 | /** |
| 1960 | * isci_remote_device_gone() - This function is called by libsas when a domain |
| 1961 | * device is removed. |
| 1962 | * @domain_device: This parameter specifies the libsas domain device. |
| 1963 | * |
| 1964 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1965 | void isci_remote_device_gone(struct domain_device *dev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1966 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1967 | struct isci_host *ihost = dev_to_ihost(dev); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1968 | struct isci_remote_device *idev = dev->lldd_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1969 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1970 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1971 | "%s: domain_device = %p, isci_device = %p, isci_port = %p\n", |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1972 | __func__, dev, idev, idev->isci_port); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1973 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1974 | isci_remote_device_stop(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | |
| 1978 | /** |
| 1979 | * isci_remote_device_found() - This function is called by libsas when a remote |
| 1980 | * device is discovered. A remote device object is created and started. the |
| 1981 | * function then sleeps until the sci core device started message is |
| 1982 | * received. |
| 1983 | * @domain_device: This parameter specifies the libsas domain device. |
| 1984 | * |
| 1985 | * status, zero indicates success. |
| 1986 | */ |
| 1987 | int isci_remote_device_found(struct domain_device *domain_dev) |
| 1988 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1989 | struct isci_host *isci_host = dev_to_ihost(domain_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1990 | struct isci_port *isci_port; |
| 1991 | struct isci_phy *isci_phy; |
| 1992 | struct asd_sas_port *sas_port; |
| 1993 | struct asd_sas_phy *sas_phy; |
| 1994 | struct isci_remote_device *isci_device; |
| 1995 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1996 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1997 | dev_dbg(&isci_host->pdev->dev, |
| 1998 | "%s: domain_device = %p\n", __func__, domain_dev); |
| 1999 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 2000 | wait_for_start(isci_host); |
| 2001 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2002 | sas_port = domain_dev->port; |
| 2003 | sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy, |
| 2004 | port_phy_el); |
| 2005 | isci_phy = to_isci_phy(sas_phy); |
| 2006 | isci_port = isci_phy->isci_port; |
| 2007 | |
| 2008 | /* we are being called for a device on this port, |
| 2009 | * so it has to come up eventually |
| 2010 | */ |
| 2011 | wait_for_completion(&isci_port->start_complete); |
| 2012 | |
| 2013 | if ((isci_stopping == isci_port_get_state(isci_port)) || |
| 2014 | (isci_stopped == isci_port_get_state(isci_port))) |
| 2015 | return -ENODEV; |
| 2016 | |
| 2017 | isci_device = isci_remote_device_alloc(isci_host, isci_port); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2018 | if (!isci_device) |
| 2019 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2020 | |
| 2021 | INIT_LIST_HEAD(&isci_device->node); |
| 2022 | domain_dev->lldd_dev = isci_device; |
| 2023 | isci_device->domain_dev = domain_dev; |
| 2024 | isci_device->isci_port = isci_port; |
| 2025 | isci_remote_device_change_state(isci_device, isci_starting); |
| 2026 | |
| 2027 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 2028 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2029 | list_add_tail(&isci_device->node, &isci_port->remote_dev_list); |
| 2030 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 2031 | set_bit(IDEV_START_PENDING, &isci_device->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2032 | status = isci_remote_device_construct(isci_port, isci_device); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 2033 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2034 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2035 | dev_dbg(&isci_host->pdev->dev, |
| 2036 | "%s: isci_device = %p\n", |
| 2037 | __func__, isci_device); |
| 2038 | |
| 2039 | if (status != SCI_SUCCESS) { |
| 2040 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 2041 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2042 | isci_remote_device_deconstruct( |
| 2043 | isci_host, |
| 2044 | isci_device |
| 2045 | ); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 2046 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2047 | return -ENODEV; |
| 2048 | } |
| 2049 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 2050 | /* wait for the device ready callback. */ |
| 2051 | wait_for_device_start(isci_host, isci_device); |
| 2052 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2053 | return 0; |
| 2054 | } |
| 2055 | /** |
| 2056 | * isci_device_is_reset_pending() - This function will check if there is any |
| 2057 | * pending reset condition on the device. |
| 2058 | * @request: This parameter is the isci_device object. |
| 2059 | * |
| 2060 | * true if there is a reset pending for the device. |
| 2061 | */ |
| 2062 | bool isci_device_is_reset_pending( |
| 2063 | struct isci_host *isci_host, |
| 2064 | struct isci_remote_device *isci_device) |
| 2065 | { |
| 2066 | struct isci_request *isci_request; |
| 2067 | struct isci_request *tmp_req; |
| 2068 | bool reset_is_pending = false; |
| 2069 | unsigned long flags; |
| 2070 | |
| 2071 | dev_dbg(&isci_host->pdev->dev, |
| 2072 | "%s: isci_device = %p\n", __func__, isci_device); |
| 2073 | |
| 2074 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 2075 | |
| 2076 | /* Check for reset on all pending requests. */ |
| 2077 | list_for_each_entry_safe(isci_request, tmp_req, |
| 2078 | &isci_device->reqs_in_process, dev_node) { |
| 2079 | dev_dbg(&isci_host->pdev->dev, |
| 2080 | "%s: isci_device = %p request = %p\n", |
| 2081 | __func__, isci_device, isci_request); |
| 2082 | |
| 2083 | if (isci_request->ttype == io_task) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2084 | struct sas_task *task = isci_request_access_task( |
| 2085 | isci_request); |
| 2086 | |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 2087 | spin_lock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2088 | if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) |
| 2089 | reset_is_pending = true; |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 2090 | spin_unlock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 2095 | |
| 2096 | dev_dbg(&isci_host->pdev->dev, |
| 2097 | "%s: isci_device = %p reset_is_pending = %d\n", |
| 2098 | __func__, isci_device, reset_is_pending); |
| 2099 | |
| 2100 | return reset_is_pending; |
| 2101 | } |
| 2102 | |
| 2103 | /** |
| 2104 | * isci_device_clear_reset_pending() - This function will clear if any pending |
| 2105 | * reset condition flags on the device. |
| 2106 | * @request: This parameter is the isci_device object. |
| 2107 | * |
| 2108 | * true if there is a reset pending for the device. |
| 2109 | */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2110 | void isci_device_clear_reset_pending(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2111 | { |
| 2112 | struct isci_request *isci_request; |
| 2113 | struct isci_request *tmp_req; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2114 | unsigned long flags = 0; |
| 2115 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2116 | dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n", |
| 2117 | __func__, idev, ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2118 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2119 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2120 | |
| 2121 | /* Clear reset pending on all pending requests. */ |
| 2122 | list_for_each_entry_safe(isci_request, tmp_req, |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2123 | &idev->reqs_in_process, dev_node) { |
| 2124 | dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n", |
| 2125 | __func__, idev, isci_request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2126 | |
| 2127 | if (isci_request->ttype == io_task) { |
| 2128 | |
| 2129 | unsigned long flags2; |
| 2130 | struct sas_task *task = isci_request_access_task( |
| 2131 | isci_request); |
| 2132 | |
| 2133 | spin_lock_irqsave(&task->task_state_lock, flags2); |
| 2134 | task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; |
| 2135 | spin_unlock_irqrestore(&task->task_state_lock, flags2); |
| 2136 | } |
| 2137 | } |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2138 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2139 | } |