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