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