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