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