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 | */ |
Dave Jiang | 2d9c224 | 2011-05-04 18:45:05 -0700 | [diff] [blame] | 55 | #include <scsi/sas.h> |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 56 | #include "isci.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #include "port.h" |
| 58 | #include "remote_device.h" |
| 59 | #include "request.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 60 | #include "remote_node_context.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 61 | #include "scu_event_codes.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 62 | #include "task.h" |
| 63 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 64 | /** |
| 65 | * isci_remote_device_change_state() - This function gets the status of the |
| 66 | * remote_device object. |
| 67 | * @isci_device: This parameter points to the isci_remote_device object |
| 68 | * |
| 69 | * status of the object as a isci_status enum. |
| 70 | */ |
| 71 | void isci_remote_device_change_state( |
| 72 | struct isci_remote_device *isci_device, |
| 73 | enum isci_status status) |
| 74 | { |
| 75 | unsigned long flags; |
| 76 | |
| 77 | spin_lock_irqsave(&isci_device->state_lock, flags); |
| 78 | isci_device->status = status; |
| 79 | spin_unlock_irqrestore(&isci_device->state_lock, flags); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * isci_remote_device_not_ready() - This function is called by the scic when |
| 84 | * the remote device is not ready. We mark the isci device as ready (not |
| 85 | * "ready_for_io") and signal the waiting proccess. |
| 86 | * @isci_host: This parameter specifies the isci host object. |
| 87 | * @isci_device: This parameter specifies the remote device |
| 88 | * |
| 89 | */ |
| 90 | static void isci_remote_device_not_ready(struct isci_host *ihost, |
| 91 | struct isci_remote_device *idev, u32 reason) |
| 92 | { |
| 93 | dev_dbg(&ihost->pdev->dev, |
| 94 | "%s: isci_device = %p\n", __func__, idev); |
| 95 | |
| 96 | if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED) |
| 97 | isci_remote_device_change_state(idev, isci_stopping); |
| 98 | else |
| 99 | /* device ready is actually a "not ready for io" state. */ |
| 100 | isci_remote_device_change_state(idev, isci_ready); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * isci_remote_device_ready() - This function is called by the scic when the |
| 105 | * remote device is ready. We mark the isci device as ready and signal the |
| 106 | * waiting proccess. |
| 107 | * @ihost: our valid isci_host |
| 108 | * @idev: remote device |
| 109 | * |
| 110 | */ |
| 111 | static void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev) |
| 112 | { |
| 113 | dev_dbg(&ihost->pdev->dev, |
| 114 | "%s: idev = %p\n", __func__, idev); |
| 115 | |
| 116 | isci_remote_device_change_state(idev, isci_ready_for_io); |
| 117 | if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags)) |
| 118 | wake_up(&ihost->eventq); |
| 119 | } |
| 120 | |
Dan Williams | ec57566 | 2011-05-01 14:19:25 -0700 | [diff] [blame] | 121 | /* called once the remote node context is ready to be freed. |
| 122 | * The remote device can now report that its stop operation is complete. none |
| 123 | */ |
| 124 | static void rnc_destruct_done(void *_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 125 | { |
Dan Williams | ec57566 | 2011-05-01 14:19:25 -0700 | [diff] [blame] | 126 | struct scic_sds_remote_device *sci_dev = _dev; |
| 127 | |
| 128 | BUG_ON(sci_dev->started_request_count != 0); |
| 129 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 130 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 131 | } |
| 132 | |
| 133 | static enum sci_status scic_sds_remote_device_terminate_requests(struct scic_sds_remote_device *sci_dev) |
| 134 | { |
| 135 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 136 | u32 i, request_count = sci_dev->started_request_count; |
| 137 | enum sci_status status = SCI_SUCCESS; |
| 138 | |
| 139 | for (i = 0; i < SCI_MAX_IO_REQUESTS && i < request_count; i++) { |
| 140 | struct scic_sds_request *sci_req; |
| 141 | enum sci_status s; |
| 142 | |
| 143 | sci_req = scic->io_request_table[i]; |
| 144 | if (!sci_req || sci_req->target_device != sci_dev) |
| 145 | continue; |
| 146 | s = scic_controller_terminate_request(scic, sci_dev, sci_req); |
| 147 | if (s != SCI_SUCCESS) |
| 148 | status = s; |
| 149 | } |
| 150 | |
| 151 | return status; |
| 152 | } |
| 153 | |
| 154 | enum sci_status scic_remote_device_stop(struct scic_sds_remote_device *sci_dev, |
| 155 | u32 timeout) |
| 156 | { |
| 157 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 158 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 159 | |
| 160 | switch (state) { |
| 161 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 162 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 163 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 164 | default: |
| 165 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 166 | __func__, state); |
| 167 | return SCI_FAILURE_INVALID_STATE; |
| 168 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 169 | return SCI_SUCCESS; |
| 170 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 171 | /* device not started so there had better be no requests */ |
| 172 | BUG_ON(sci_dev->started_request_count != 0); |
| 173 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 174 | rnc_destruct_done, sci_dev); |
| 175 | /* Transition to the stopping state and wait for the |
| 176 | * remote node to complete being posted and invalidated. |
| 177 | */ |
| 178 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 179 | return SCI_SUCCESS; |
| 180 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 181 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 182 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 183 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 184 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 185 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 186 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 187 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 188 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 189 | if (sci_dev->started_request_count == 0) { |
| 190 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 191 | rnc_destruct_done, sci_dev); |
| 192 | return SCI_SUCCESS; |
| 193 | } else |
| 194 | return scic_sds_remote_device_terminate_requests(sci_dev); |
| 195 | break; |
| 196 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 197 | /* All requests should have been terminated, but if there is an |
| 198 | * attempt to stop a device already in the stopping state, then |
| 199 | * try again to terminate. |
| 200 | */ |
| 201 | return scic_sds_remote_device_terminate_requests(sci_dev); |
| 202 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 203 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 204 | return SCI_SUCCESS; |
| 205 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 206 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 207 | |
Dan Williams | 4fd0d2e | 2011-05-01 14:48:54 -0700 | [diff] [blame] | 208 | 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] | 209 | { |
Dan Williams | 4fd0d2e | 2011-05-01 14:48:54 -0700 | [diff] [blame] | 210 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 211 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 212 | |
| 213 | switch (state) { |
| 214 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 215 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 216 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 217 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 218 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 219 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 220 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 221 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 222 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 223 | default: |
| 224 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 225 | __func__, state); |
| 226 | return SCI_FAILURE_INVALID_STATE; |
| 227 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 228 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 229 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 230 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 231 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 232 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 233 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_RESETTING); |
| 234 | return SCI_SUCCESS; |
| 235 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Dan Williams | 8151518 | 2011-05-01 14:53:00 -0700 | [diff] [blame] | 238 | 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] | 239 | { |
Dan Williams | 8151518 | 2011-05-01 14:53:00 -0700 | [diff] [blame] | 240 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 241 | enum scic_sds_remote_device_states state = sm->current_state_id; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 242 | |
Dan Williams | 8151518 | 2011-05-01 14:53:00 -0700 | [diff] [blame] | 243 | if (state != SCI_BASE_REMOTE_DEVICE_STATE_RESETTING) { |
| 244 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 245 | __func__, state); |
| 246 | return SCI_FAILURE_INVALID_STATE; |
| 247 | } |
| 248 | |
| 249 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_READY); |
| 250 | return SCI_SUCCESS; |
| 251 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 252 | |
Dan Williams | 323f0ec | 2011-05-01 16:15:47 -0700 | [diff] [blame] | 253 | enum sci_status scic_sds_remote_device_suspend(struct scic_sds_remote_device *sci_dev, |
| 254 | u32 suspend_type) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 255 | { |
Dan Williams | 323f0ec | 2011-05-01 16:15:47 -0700 | [diff] [blame] | 256 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 257 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 258 | |
| 259 | if (state != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD) { |
| 260 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 261 | __func__, state); |
| 262 | return SCI_FAILURE_INVALID_STATE; |
| 263 | } |
| 264 | |
| 265 | return scic_sds_remote_node_context_suspend(&sci_dev->rnc, |
| 266 | suspend_type, NULL, NULL); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 269 | enum sci_status scic_sds_remote_device_frame_handler(struct scic_sds_remote_device *sci_dev, |
| 270 | u32 frame_index) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 271 | { |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 272 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 273 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 274 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 275 | enum sci_status status; |
| 276 | |
| 277 | switch (state) { |
| 278 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 279 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 280 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 281 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 282 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 283 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 284 | default: |
| 285 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 286 | __func__, state); |
| 287 | /* Return the frame back to the controller */ |
| 288 | scic_sds_controller_release_frame(scic, frame_index); |
| 289 | return SCI_FAILURE_INVALID_STATE; |
| 290 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 291 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 292 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 293 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 294 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 295 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: { |
| 296 | struct scic_sds_request *sci_req; |
Dave Jiang | 2d9c224 | 2011-05-04 18:45:05 -0700 | [diff] [blame] | 297 | struct ssp_frame_hdr hdr; |
| 298 | void *frame_header; |
| 299 | ssize_t word_cnt; |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 300 | |
| 301 | status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control, |
| 302 | frame_index, |
Dave Jiang | 2d9c224 | 2011-05-04 18:45:05 -0700 | [diff] [blame] | 303 | &frame_header); |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 304 | if (status != SCI_SUCCESS) |
| 305 | return status; |
| 306 | |
Dave Jiang | 2d9c224 | 2011-05-04 18:45:05 -0700 | [diff] [blame] | 307 | word_cnt = sizeof(hdr) / sizeof(u32); |
| 308 | sci_swab32_cpy(&hdr, frame_header, word_cnt); |
| 309 | |
| 310 | sci_req = scic_request_by_tag(scic, be16_to_cpu(hdr.tag)); |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 311 | if (sci_req && sci_req->target_device == sci_dev) { |
| 312 | /* The IO request is now in charge of releasing the frame */ |
| 313 | status = sci_req->state_handlers->frame_handler(sci_req, |
| 314 | frame_index); |
| 315 | } else { |
| 316 | /* We could not map this tag to a valid IO |
| 317 | * request Just toss the frame and continue |
| 318 | */ |
| 319 | scic_sds_controller_release_frame(scic, frame_index); |
| 320 | } |
| 321 | break; |
| 322 | } |
| 323 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: { |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 324 | struct dev_to_host_fis *hdr; |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 325 | |
| 326 | status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control, |
| 327 | frame_index, |
| 328 | (void **)&hdr); |
| 329 | if (status != SCI_SUCCESS) |
| 330 | return status; |
| 331 | |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 332 | if (hdr->fis_type == FIS_SETDEVBITS && |
| 333 | (hdr->status & ATA_ERR)) { |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 334 | sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED; |
| 335 | |
| 336 | /* TODO Check sactive and complete associated IO if any. */ |
| 337 | sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR); |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 338 | } else if (hdr->fis_type == FIS_REGD2H && |
| 339 | (hdr->status & ATA_ERR)) { |
Dan Williams | 01bec77 | 2011-05-01 16:51:11 -0700 | [diff] [blame] | 340 | /* |
| 341 | * Some devices return D2H FIS when an NCQ error is detected. |
| 342 | * Treat this like an SDB error FIS ready reason. |
| 343 | */ |
| 344 | sci_dev->not_ready_reason = SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED; |
| 345 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 346 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR); |
| 347 | } else |
| 348 | status = SCI_FAILURE; |
| 349 | |
| 350 | scic_sds_controller_release_frame(scic, frame_index); |
| 351 | break; |
| 352 | } |
| 353 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 354 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 355 | /* The device does not process any UF received from the hardware while |
| 356 | * in this state. All unsolicited frames are forwarded to the io request |
| 357 | * object. |
| 358 | */ |
| 359 | status = scic_sds_io_request_frame_handler(sci_dev->working_request, frame_index); |
| 360 | break; |
| 361 | } |
| 362 | |
| 363 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Dan Williams | e622571 | 2011-05-01 16:26:09 -0700 | [diff] [blame] | 366 | 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] | 367 | { |
Dan Williams | e622571 | 2011-05-01 16:26:09 -0700 | [diff] [blame] | 368 | |
| 369 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 370 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 371 | |
| 372 | switch (state) { |
| 373 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 374 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 375 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 376 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 377 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 378 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 379 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 380 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 381 | return true; |
| 382 | default: |
| 383 | return false; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | enum sci_status scic_sds_remote_device_event_handler(struct scic_sds_remote_device *sci_dev, |
| 388 | u32 event_code) |
| 389 | { |
| 390 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 391 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 392 | enum sci_status status; |
| 393 | |
| 394 | switch (scu_get_event_type(event_code)) { |
| 395 | case SCU_EVENT_TYPE_RNC_OPS_MISC: |
| 396 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 397 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 398 | status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code); |
| 399 | break; |
| 400 | case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT: |
| 401 | if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) { |
| 402 | status = SCI_SUCCESS; |
| 403 | |
| 404 | /* Suspend the associated RNC */ |
| 405 | scic_sds_remote_node_context_suspend(&sci_dev->rnc, |
| 406 | SCI_SOFTWARE_SUSPENSION, |
| 407 | NULL, NULL); |
| 408 | |
| 409 | dev_dbg(scirdev_to_dev(sci_dev), |
| 410 | "%s: device: %p event code: %x: %s\n", |
| 411 | __func__, sci_dev, event_code, |
| 412 | is_remote_device_ready(sci_dev) |
| 413 | ? "I_T_Nexus_Timeout event" |
| 414 | : "I_T_Nexus_Timeout event in wrong state"); |
| 415 | |
| 416 | break; |
| 417 | } |
| 418 | /* Else, fall through and treat as unhandled... */ |
| 419 | default: |
| 420 | dev_dbg(scirdev_to_dev(sci_dev), |
| 421 | "%s: device: %p event code: %x: %s\n", |
| 422 | __func__, sci_dev, event_code, |
| 423 | is_remote_device_ready(sci_dev) |
| 424 | ? "unexpected event" |
| 425 | : "unexpected event in wrong state"); |
| 426 | status = SCI_FAILURE_INVALID_STATE; |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | if (status != SCI_SUCCESS) |
| 431 | return status; |
| 432 | |
| 433 | if (state == SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE) { |
| 434 | |
| 435 | /* We pick up suspension events to handle specifically to this |
| 436 | * state. We resume the RNC right away. |
| 437 | */ |
| 438 | if (scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX || |
| 439 | scu_get_event_type(event_code) == SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX) |
| 440 | status = scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL); |
| 441 | } |
| 442 | |
| 443 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 446 | static void scic_sds_remote_device_start_request(struct scic_sds_remote_device *sci_dev, |
| 447 | struct scic_sds_request *sci_req, |
| 448 | enum sci_status status) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 449 | { |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 450 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
| 451 | |
| 452 | /* cleanup requests that failed after starting on the port */ |
| 453 | if (status != SCI_SUCCESS) |
| 454 | scic_sds_port_complete_io(sci_port, sci_dev, sci_req); |
| 455 | else |
| 456 | scic_sds_remote_device_increment_request_count(sci_dev); |
| 457 | } |
| 458 | |
| 459 | enum sci_status scic_sds_remote_device_start_io(struct scic_sds_controller *scic, |
| 460 | struct scic_sds_remote_device *sci_dev, |
| 461 | struct scic_sds_request *sci_req) |
| 462 | { |
| 463 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 464 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 465 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
Dan Williams | 67ea838 | 2011-05-08 11:47:15 -0700 | [diff] [blame] | 466 | struct isci_request *ireq = sci_req_to_ireq(sci_req); |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 467 | enum sci_status status; |
| 468 | |
| 469 | switch (state) { |
| 470 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 471 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 472 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 473 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 474 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 475 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 476 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 477 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 478 | default: |
| 479 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 480 | __func__, state); |
| 481 | return SCI_FAILURE_INVALID_STATE; |
| 482 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 483 | /* attempt to start an io request for this device object. The remote |
| 484 | * device object will issue the start request for the io and if |
| 485 | * successful it will start the request for the port object then |
| 486 | * increment its own request count. |
| 487 | */ |
| 488 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 489 | if (status != SCI_SUCCESS) |
| 490 | return status; |
| 491 | |
| 492 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 493 | if (status != SCI_SUCCESS) |
| 494 | break; |
| 495 | |
| 496 | status = scic_sds_request_start(sci_req); |
| 497 | break; |
| 498 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: { |
| 499 | /* handle the start io operation for a sata device that is in |
| 500 | * the command idle state. - Evalute the type of IO request to |
| 501 | * be started - If its an NCQ request change to NCQ substate - |
| 502 | * If its any other command change to the CMD substate |
| 503 | * |
| 504 | * If this is a softreset we may want to have a different |
| 505 | * substate. |
| 506 | */ |
| 507 | enum scic_sds_remote_device_states new_state; |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 508 | struct sas_task *task = isci_request_access_task(ireq); |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 509 | |
| 510 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 511 | if (status != SCI_SUCCESS) |
| 512 | return status; |
| 513 | |
| 514 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 515 | if (status != SCI_SUCCESS) |
| 516 | break; |
| 517 | |
Piotr Sawicki | f4636a7 | 2011-05-10 23:50:32 +0000 | [diff] [blame^] | 518 | status = scic_sds_request_start(sci_req); |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 519 | if (status != SCI_SUCCESS) |
| 520 | break; |
| 521 | |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 522 | if (task->ata_task.use_ncq) |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 523 | new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ; |
| 524 | else { |
| 525 | sci_dev->working_request = sci_req; |
| 526 | new_state = SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD; |
| 527 | } |
| 528 | sci_base_state_machine_change_state(sm, new_state); |
| 529 | break; |
| 530 | } |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 531 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: { |
| 532 | struct sas_task *task = isci_request_access_task(ireq); |
| 533 | |
| 534 | if (task->ata_task.use_ncq) { |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 535 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 536 | if (status != SCI_SUCCESS) |
| 537 | return status; |
| 538 | |
| 539 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 540 | if (status != SCI_SUCCESS) |
| 541 | break; |
| 542 | |
Piotr Sawicki | f4636a7 | 2011-05-10 23:50:32 +0000 | [diff] [blame^] | 543 | status = scic_sds_request_start(sci_req); |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 544 | } else |
| 545 | return SCI_FAILURE_INVALID_STATE; |
| 546 | break; |
Dave Jiang | e76d618 | 2011-05-04 15:02:03 -0700 | [diff] [blame] | 547 | } |
Dan Williams | 1860655 | 2011-05-01 14:57:11 -0700 | [diff] [blame] | 548 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 549 | return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; |
| 550 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 551 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 552 | if (status != SCI_SUCCESS) |
| 553 | return status; |
| 554 | |
| 555 | status = scic_sds_remote_node_context_start_io(&sci_dev->rnc, sci_req); |
| 556 | if (status != SCI_SUCCESS) |
| 557 | break; |
| 558 | |
| 559 | status = scic_sds_request_start(sci_req); |
| 560 | if (status != SCI_SUCCESS) |
| 561 | break; |
| 562 | |
| 563 | sci_dev->working_request = sci_req; |
| 564 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 565 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD); |
| 566 | break; |
| 567 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 568 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 569 | /* device is already handling a command it can not accept new commands |
| 570 | * until this one is complete. |
| 571 | */ |
| 572 | return SCI_FAILURE_INVALID_STATE; |
| 573 | } |
| 574 | |
| 575 | scic_sds_remote_device_start_request(sci_dev, sci_req, status); |
| 576 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Dan Williams | 10a09e6 | 2011-05-01 15:33:43 -0700 | [diff] [blame] | 579 | static enum sci_status common_complete_io(struct scic_sds_port *sci_port, |
| 580 | struct scic_sds_remote_device *sci_dev, |
| 581 | struct scic_sds_request *sci_req) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 582 | { |
Dan Williams | 10a09e6 | 2011-05-01 15:33:43 -0700 | [diff] [blame] | 583 | enum sci_status status; |
| 584 | |
| 585 | status = scic_sds_request_complete(sci_req); |
| 586 | if (status != SCI_SUCCESS) |
| 587 | return status; |
| 588 | |
| 589 | status = scic_sds_port_complete_io(sci_port, sci_dev, sci_req); |
| 590 | if (status != SCI_SUCCESS) |
| 591 | return status; |
| 592 | |
| 593 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 594 | return status; |
| 595 | } |
| 596 | |
| 597 | enum sci_status scic_sds_remote_device_complete_io(struct scic_sds_controller *scic, |
| 598 | struct scic_sds_remote_device *sci_dev, |
| 599 | struct scic_sds_request *sci_req) |
| 600 | { |
| 601 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 602 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 603 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
| 604 | enum sci_status status; |
| 605 | |
| 606 | switch (state) { |
| 607 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 608 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 609 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 610 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 611 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 612 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 613 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 614 | default: |
| 615 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 616 | __func__, state); |
| 617 | return SCI_FAILURE_INVALID_STATE; |
| 618 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 619 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 620 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 621 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 622 | break; |
| 623 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 624 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 625 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 626 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 627 | if (status != SCI_SUCCESS) |
| 628 | break; |
| 629 | |
| 630 | if (sci_req->sci_status == SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) { |
| 631 | /* This request causes hardware error, device needs to be Lun Reset. |
| 632 | * So here we force the state machine to IDLE state so the rest IOs |
| 633 | * can reach RNC state handler, these IOs will be completed by RNC with |
| 634 | * status of "DEVICE_RESET_REQUIRED", instead of "INVALID STATE". |
| 635 | */ |
| 636 | sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET); |
| 637 | } else if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 638 | sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 639 | break; |
| 640 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 641 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 642 | if (status != SCI_SUCCESS) |
| 643 | break; |
| 644 | sci_base_state_machine_change_state(sm, SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 645 | break; |
| 646 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 647 | status = common_complete_io(sci_port, sci_dev, sci_req); |
| 648 | if (status != SCI_SUCCESS) |
| 649 | break; |
| 650 | |
| 651 | if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 652 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 653 | rnc_destruct_done, |
| 654 | sci_dev); |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | if (status != SCI_SUCCESS) |
| 659 | dev_err(scirdev_to_dev(sci_dev), |
| 660 | "%s: Port:0x%p Device:0x%p Request:0x%p Status:0x%x " |
| 661 | "could not complete\n", __func__, sci_port, |
| 662 | sci_dev, sci_req, status); |
| 663 | |
| 664 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Dan Williams | 84b9b02 | 2011-05-01 15:53:25 -0700 | [diff] [blame] | 667 | static void scic_sds_remote_device_continue_request(void *dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 668 | { |
Dan Williams | 84b9b02 | 2011-05-01 15:53:25 -0700 | [diff] [blame] | 669 | struct scic_sds_remote_device *sci_dev = dev; |
| 670 | |
| 671 | /* we need to check if this request is still valid to continue. */ |
| 672 | if (sci_dev->working_request) |
| 673 | scic_controller_continue_io(sci_dev->working_request); |
| 674 | } |
| 675 | |
| 676 | enum sci_status scic_sds_remote_device_start_task(struct scic_sds_controller *scic, |
| 677 | struct scic_sds_remote_device *sci_dev, |
| 678 | struct scic_sds_request *sci_req) |
| 679 | { |
| 680 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 681 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 682 | struct scic_sds_port *sci_port = sci_dev->owning_port; |
| 683 | enum sci_status status; |
| 684 | |
| 685 | switch (state) { |
| 686 | case SCI_BASE_REMOTE_DEVICE_STATE_INITIAL: |
| 687 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPED: |
| 688 | case SCI_BASE_REMOTE_DEVICE_STATE_STARTING: |
| 689 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 690 | case SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 691 | case SCI_BASE_REMOTE_DEVICE_STATE_STOPPING: |
| 692 | case SCI_BASE_REMOTE_DEVICE_STATE_FAILED: |
| 693 | case SCI_BASE_REMOTE_DEVICE_STATE_RESETTING: |
| 694 | case SCI_BASE_REMOTE_DEVICE_STATE_FINAL: |
| 695 | default: |
| 696 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 697 | __func__, state); |
| 698 | return SCI_FAILURE_INVALID_STATE; |
| 699 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE: |
| 700 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD: |
| 701 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ: |
| 702 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR: |
| 703 | case SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET: |
| 704 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 705 | if (status != SCI_SUCCESS) |
| 706 | return status; |
| 707 | |
| 708 | status = scic_sds_remote_node_context_start_task(&sci_dev->rnc, sci_req); |
| 709 | if (status != SCI_SUCCESS) |
| 710 | goto out; |
| 711 | |
Piotr Sawicki | f4636a7 | 2011-05-10 23:50:32 +0000 | [diff] [blame^] | 712 | status = scic_sds_request_start(sci_req); |
Dan Williams | 84b9b02 | 2011-05-01 15:53:25 -0700 | [diff] [blame] | 713 | if (status != SCI_SUCCESS) |
| 714 | goto out; |
| 715 | |
| 716 | /* Note: If the remote device state is not IDLE this will |
| 717 | * replace the request that probably resulted in the task |
| 718 | * management request. |
| 719 | */ |
| 720 | sci_dev->working_request = sci_req; |
| 721 | sci_base_state_machine_change_state(sm, SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD); |
| 722 | |
| 723 | /* The remote node context must cleanup the TCi to NCQ mapping |
| 724 | * table. The only way to do this correctly is to either write |
| 725 | * to the TLCR register or to invalidate and repost the RNC. In |
| 726 | * either case the remote node context state machine will take |
| 727 | * the correct action when the remote node context is suspended |
| 728 | * and later resumed. |
| 729 | */ |
| 730 | scic_sds_remote_node_context_suspend(&sci_dev->rnc, |
| 731 | SCI_SOFTWARE_SUSPENSION, NULL, NULL); |
| 732 | scic_sds_remote_node_context_resume(&sci_dev->rnc, |
| 733 | scic_sds_remote_device_continue_request, |
| 734 | sci_dev); |
| 735 | |
| 736 | out: |
| 737 | scic_sds_remote_device_start_request(sci_dev, sci_req, status); |
| 738 | /* We need to let the controller start request handler know that |
| 739 | * it can't post TC yet. We will provide a callback function to |
| 740 | * post TC when RNC gets resumed. |
| 741 | */ |
| 742 | return SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS; |
| 743 | case SCI_BASE_REMOTE_DEVICE_STATE_READY: |
| 744 | status = scic_sds_port_start_io(sci_port, sci_dev, sci_req); |
| 745 | if (status != SCI_SUCCESS) |
| 746 | return status; |
| 747 | |
| 748 | status = scic_sds_remote_node_context_start_task(&sci_dev->rnc, sci_req); |
| 749 | if (status != SCI_SUCCESS) |
| 750 | break; |
| 751 | |
| 752 | status = scic_sds_request_start(sci_req); |
| 753 | break; |
| 754 | } |
| 755 | scic_sds_remote_device_start_request(sci_dev, sci_req, status); |
| 756 | |
| 757 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /** |
| 761 | * |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 762 | * @sci_dev: |
| 763 | * @request: |
| 764 | * |
| 765 | * This method takes the request and bulids an appropriate SCU context for the |
| 766 | * request and then requests the controller to post the request. none |
| 767 | */ |
| 768 | void scic_sds_remote_device_post_request( |
| 769 | struct scic_sds_remote_device *sci_dev, |
| 770 | u32 request) |
| 771 | { |
| 772 | u32 context; |
| 773 | |
| 774 | context = scic_sds_remote_device_build_command_context(sci_dev, request); |
| 775 | |
| 776 | scic_sds_controller_post_request( |
| 777 | scic_sds_remote_device_get_controller(sci_dev), |
| 778 | context |
| 779 | ); |
| 780 | } |
| 781 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 782 | /* called once the remote node context has transisitioned to a |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 783 | * 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] | 784 | * transition to ready. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 785 | */ |
Dan Williams | eb22967 | 2011-05-01 14:05:57 -0700 | [diff] [blame] | 786 | static void remote_device_resume_done(void *_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 787 | { |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 788 | struct scic_sds_remote_device *sci_dev = _dev; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 789 | |
Dan Williams | e622571 | 2011-05-01 16:26:09 -0700 | [diff] [blame] | 790 | if (is_remote_device_ready(sci_dev)) |
| 791 | return; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 792 | |
Dan Williams | e622571 | 2011-05-01 16:26:09 -0700 | [diff] [blame] | 793 | /* go 'ready' if we are not already in a ready state */ |
| 794 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 795 | SCI_BASE_REMOTE_DEVICE_STATE_READY); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 798 | static void scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *_dev) |
| 799 | { |
| 800 | struct scic_sds_remote_device *sci_dev = _dev; |
| 801 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
| 802 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 803 | |
| 804 | /* For NCQ operation we do not issue a isci_remote_device_not_ready(). |
| 805 | * As a result, avoid sending the ready notification. |
| 806 | */ |
| 807 | if (sci_dev->state_machine.previous_state_id != SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ) |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 808 | isci_remote_device_ready(scic_to_ihost(scic), idev); |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 811 | static void scic_sds_remote_device_initial_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 812 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 813 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 814 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 815 | /* Initial state is a transitional state to the stopped state */ |
| 816 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 817 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 818 | } |
| 819 | |
| 820 | /** |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 821 | * scic_remote_device_destruct() - free remote node context and destruct |
| 822 | * @remote_device: This parameter specifies the remote device to be destructed. |
| 823 | * |
| 824 | * Remote device objects are a limited resource. As such, they must be |
| 825 | * protected. Thus calls to construct and destruct are mutually exclusive and |
| 826 | * non-reentrant. The return value shall indicate if the device was |
| 827 | * successfully destructed or if some failure occurred. enum sci_status This value |
| 828 | * is returned if the device is successfully destructed. |
| 829 | * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied |
| 830 | * device isn't valid (e.g. it's already been destoryed, the handle isn't |
| 831 | * valid, etc.). |
| 832 | */ |
| 833 | static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev) |
| 834 | { |
Dan Williams | b8d82f6 | 2011-05-01 14:38:26 -0700 | [diff] [blame] | 835 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 836 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 837 | struct scic_sds_controller *scic; |
| 838 | |
| 839 | if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) { |
| 840 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 841 | __func__, state); |
| 842 | return SCI_FAILURE_INVALID_STATE; |
| 843 | } |
| 844 | |
| 845 | scic = sci_dev->owning_port->owning_controller; |
| 846 | scic_sds_controller_free_remote_node_context(scic, sci_dev, |
| 847 | sci_dev->rnc.remote_node_index); |
| 848 | sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX; |
| 849 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_FINAL); |
| 850 | |
| 851 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 854 | /** |
| 855 | * isci_remote_device_deconstruct() - This function frees an isci_remote_device. |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 856 | * @ihost: This parameter specifies the isci host object. |
| 857 | * @idev: This parameter specifies the remote device to be freed. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 858 | * |
| 859 | */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 860 | 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] | 861 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 862 | dev_dbg(&ihost->pdev->dev, |
| 863 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 864 | |
| 865 | /* There should not be any outstanding io's. All paths to |
| 866 | * here should go through isci_remote_device_nuke_requests. |
| 867 | * If we hit this condition, we will need a way to complete |
| 868 | * io requests in process */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 869 | while (!list_empty(&idev->reqs_in_process)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 870 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 871 | dev_err(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 872 | "%s: ** request list not empty! **\n", __func__); |
| 873 | BUG(); |
| 874 | } |
| 875 | |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 876 | scic_remote_device_destruct(&idev->sci); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 877 | idev->domain_dev->lldd_dev = NULL; |
| 878 | idev->domain_dev = NULL; |
| 879 | idev->isci_port = NULL; |
| 880 | list_del_init(&idev->node); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 881 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 882 | clear_bit(IDEV_START_PENDING, &idev->flags); |
| 883 | clear_bit(IDEV_STOP_PENDING, &idev->flags); |
Dan Williams | d06b487 | 2011-05-02 13:59:25 -0700 | [diff] [blame] | 884 | clear_bit(IDEV_EH, &idev->flags); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 885 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 888 | /** |
| 889 | * isci_remote_device_stop_complete() - This function is called by the scic |
| 890 | * when the remote device stop has completed. We mark the isci device as not |
| 891 | * ready and remove the isci remote device. |
| 892 | * @ihost: This parameter specifies the isci host object. |
| 893 | * @idev: This parameter specifies the remote device. |
| 894 | * @status: This parameter specifies status of the completion. |
| 895 | * |
| 896 | */ |
| 897 | static void isci_remote_device_stop_complete(struct isci_host *ihost, |
| 898 | struct isci_remote_device *idev) |
| 899 | { |
| 900 | dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev); |
| 901 | |
| 902 | isci_remote_device_change_state(idev, isci_stopped); |
| 903 | |
| 904 | /* after stop, we can tear down resources. */ |
| 905 | isci_remote_device_deconstruct(ihost, idev); |
| 906 | } |
| 907 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 908 | static void scic_sds_remote_device_stopped_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 909 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 910 | struct scic_sds_remote_device *sci_dev = object; |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 911 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
| 912 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 913 | u32 prev_state; |
| 914 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 915 | /* If we are entering from the stopping state let the SCI User know that |
| 916 | * the stop operation has completed. |
| 917 | */ |
| 918 | prev_state = sci_dev->state_machine.previous_state_id; |
| 919 | if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING) |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 920 | isci_remote_device_stop_complete(scic_to_ihost(scic), idev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 921 | |
| 922 | scic_sds_controller_remote_device_stopped(scic, sci_dev); |
| 923 | } |
| 924 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 925 | static void scic_sds_remote_device_starting_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 926 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 927 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 928 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 929 | struct isci_host *ihost = scic_to_ihost(scic); |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 930 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 931 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 932 | isci_remote_device_not_ready(ihost, idev, |
| 933 | SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED); |
| 934 | } |
| 935 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 936 | static void scic_sds_remote_device_ready_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 937 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 938 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 939 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 940 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
| 941 | struct domain_device *dev = idev->domain_dev; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 942 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 943 | scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++; |
| 944 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 945 | if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_SATA)) { |
| 946 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 947 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 948 | } else if (dev_is_expander(dev)) { |
| 949 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 950 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
| 951 | } else |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 952 | isci_remote_device_ready(scic_to_ihost(scic), idev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 955 | static void scic_sds_remote_device_ready_state_exit(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 956 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 957 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 958 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
| 959 | |
| 960 | if (dev->dev_type == SAS_END_DEV) { |
| 961 | struct scic_sds_controller *scic = sci_dev->owning_port->owning_controller; |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 962 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 963 | |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 964 | isci_remote_device_not_ready(scic_to_ihost(scic), idev, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 965 | SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED); |
| 966 | } |
| 967 | } |
| 968 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 969 | static void scic_sds_remote_device_resetting_state_enter(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 970 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 971 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 972 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 973 | scic_sds_remote_node_context_suspend( |
| 974 | &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL); |
| 975 | } |
| 976 | |
Maciej Patelczyk | 9a0fff7 | 2011-04-28 22:06:01 +0000 | [diff] [blame] | 977 | static void scic_sds_remote_device_resetting_state_exit(void *object) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 978 | { |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 979 | struct scic_sds_remote_device *sci_dev = object; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 980 | |
| 981 | scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL); |
| 982 | } |
| 983 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 984 | static void scic_sds_stp_remote_device_ready_idle_substate_enter(void *object) |
| 985 | { |
| 986 | struct scic_sds_remote_device *sci_dev = object; |
| 987 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 988 | sci_dev->working_request = NULL; |
| 989 | if (scic_sds_remote_node_context_is_ready(&sci_dev->rnc)) { |
| 990 | /* |
| 991 | * Since the RNC is ready, it's alright to finish completion |
| 992 | * processing (e.g. signal the remote device is ready). */ |
| 993 | scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(sci_dev); |
| 994 | } else { |
| 995 | scic_sds_remote_node_context_resume(&sci_dev->rnc, |
| 996 | scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler, |
| 997 | sci_dev); |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | static void scic_sds_stp_remote_device_ready_cmd_substate_enter(void *object) |
| 1002 | { |
| 1003 | struct scic_sds_remote_device *sci_dev = object; |
| 1004 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1005 | |
| 1006 | BUG_ON(sci_dev->working_request == NULL); |
| 1007 | |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 1008 | isci_remote_device_not_ready(scic_to_ihost(scic), sci_dev_to_idev(sci_dev), |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1009 | SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED); |
| 1010 | } |
| 1011 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1012 | static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(void *object) |
| 1013 | { |
| 1014 | struct scic_sds_remote_device *sci_dev = object; |
| 1015 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1016 | struct isci_remote_device *idev = sci_dev_to_idev(sci_dev); |
| 1017 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1018 | if (sci_dev->not_ready_reason == SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED) |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 1019 | isci_remote_device_not_ready(scic_to_ihost(scic), idev, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1020 | sci_dev->not_ready_reason); |
| 1021 | } |
| 1022 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1023 | static void scic_sds_smp_remote_device_ready_idle_substate_enter(void *object) |
| 1024 | { |
| 1025 | struct scic_sds_remote_device *sci_dev = object; |
| 1026 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1027 | |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 1028 | isci_remote_device_ready(scic_to_ihost(scic), sci_dev_to_idev(sci_dev)); |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static void scic_sds_smp_remote_device_ready_cmd_substate_enter(void *object) |
| 1032 | { |
| 1033 | struct scic_sds_remote_device *sci_dev = object; |
| 1034 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1035 | |
| 1036 | BUG_ON(sci_dev->working_request == NULL); |
| 1037 | |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 1038 | isci_remote_device_not_ready(scic_to_ihost(scic), sci_dev_to_idev(sci_dev), |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1039 | SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED); |
| 1040 | } |
| 1041 | |
| 1042 | static void scic_sds_smp_remote_device_ready_cmd_substate_exit(void *object) |
| 1043 | { |
| 1044 | struct scic_sds_remote_device *sci_dev = object; |
| 1045 | |
| 1046 | sci_dev->working_request = NULL; |
| 1047 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1048 | |
| 1049 | static const struct sci_base_state scic_sds_remote_device_state_table[] = { |
| 1050 | [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { |
| 1051 | .enter_state = scic_sds_remote_device_initial_state_enter, |
| 1052 | }, |
| 1053 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { |
| 1054 | .enter_state = scic_sds_remote_device_stopped_state_enter, |
| 1055 | }, |
| 1056 | [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { |
| 1057 | .enter_state = scic_sds_remote_device_starting_state_enter, |
| 1058 | }, |
| 1059 | [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { |
| 1060 | .enter_state = scic_sds_remote_device_ready_state_enter, |
| 1061 | .exit_state = scic_sds_remote_device_ready_state_exit |
| 1062 | }, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1063 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = { |
| 1064 | .enter_state = scic_sds_stp_remote_device_ready_idle_substate_enter, |
| 1065 | }, |
| 1066 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = { |
| 1067 | .enter_state = scic_sds_stp_remote_device_ready_cmd_substate_enter, |
| 1068 | }, |
Dan Williams | 971cc2f | 2011-05-01 16:58:46 -0700 | [diff] [blame] | 1069 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ] = { }, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1070 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR] = { |
| 1071 | .enter_state = scic_sds_stp_remote_device_ready_ncq_error_substate_enter, |
| 1072 | }, |
Dan Williams | 971cc2f | 2011-05-01 16:58:46 -0700 | [diff] [blame] | 1073 | [SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET] = { }, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1074 | [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE] = { |
| 1075 | .enter_state = scic_sds_smp_remote_device_ready_idle_substate_enter, |
| 1076 | }, |
| 1077 | [SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD] = { |
| 1078 | .enter_state = scic_sds_smp_remote_device_ready_cmd_substate_enter, |
| 1079 | .exit_state = scic_sds_smp_remote_device_ready_cmd_substate_exit, |
| 1080 | }, |
Dan Williams | 971cc2f | 2011-05-01 16:58:46 -0700 | [diff] [blame] | 1081 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { }, |
| 1082 | [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { }, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1083 | [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { |
| 1084 | .enter_state = scic_sds_remote_device_resetting_state_enter, |
| 1085 | .exit_state = scic_sds_remote_device_resetting_state_exit |
| 1086 | }, |
Dan Williams | 971cc2f | 2011-05-01 16:58:46 -0700 | [diff] [blame] | 1087 | [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { }, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1088 | }; |
| 1089 | |
| 1090 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1091 | * scic_remote_device_construct() - common construction |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1092 | * @sci_port: SAS/SATA port through which this device is accessed. |
| 1093 | * @sci_dev: remote device to construct |
| 1094 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1095 | * This routine just performs benign initialization and does not |
| 1096 | * allocate the remote_node_context which is left to |
| 1097 | * scic_remote_device_[de]a_construct(). scic_remote_device_destruct() |
| 1098 | * frees the remote_node_context(s) for the device. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1099 | */ |
| 1100 | static void scic_remote_device_construct(struct scic_sds_port *sci_port, |
| 1101 | struct scic_sds_remote_device *sci_dev) |
| 1102 | { |
| 1103 | sci_dev->owning_port = sci_port; |
| 1104 | sci_dev->started_request_count = 0; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1105 | |
| 1106 | sci_base_state_machine_construct( |
| 1107 | &sci_dev->state_machine, |
Maciej Patelczyk | 5d937e9 | 2011-04-28 22:06:21 +0000 | [diff] [blame] | 1108 | sci_dev, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1109 | scic_sds_remote_device_state_table, |
| 1110 | SCI_BASE_REMOTE_DEVICE_STATE_INITIAL |
| 1111 | ); |
| 1112 | |
| 1113 | sci_base_state_machine_start( |
| 1114 | &sci_dev->state_machine |
| 1115 | ); |
| 1116 | |
| 1117 | scic_sds_remote_node_context_construct(&sci_dev->rnc, |
| 1118 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1122 | * scic_remote_device_da_construct() - construct direct attached device. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1123 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1124 | * The information (e.g. IAF, Signature FIS, etc.) necessary to build |
| 1125 | * the device is known to the SCI Core since it is contained in the |
| 1126 | * scic_phy object. Remote node context(s) is/are a global resource |
| 1127 | * allocated by this routine, freed by scic_remote_device_destruct(). |
| 1128 | * |
| 1129 | * Returns: |
| 1130 | * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed. |
| 1131 | * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to |
| 1132 | * sata-only controller instance. |
| 1133 | * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1134 | */ |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1135 | static enum sci_status scic_remote_device_da_construct(struct scic_sds_port *sci_port, |
| 1136 | struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1137 | { |
| 1138 | enum sci_status status; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1139 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1140 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1141 | scic_remote_device_construct(sci_port, sci_dev); |
| 1142 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1143 | /* |
| 1144 | * This information is request to determine how many remote node context |
| 1145 | * entries will be needed to store the remote node. |
| 1146 | */ |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1147 | sci_dev->is_direct_attached = true; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1148 | status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller, |
| 1149 | sci_dev, |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1150 | &sci_dev->rnc.remote_node_index); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1151 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1152 | if (status != SCI_SUCCESS) |
| 1153 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1154 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1155 | if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV || |
| 1156 | (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev)) |
| 1157 | /* pass */; |
| 1158 | else |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1159 | return SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1160 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1161 | 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] | 1162 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1163 | /* / @todo Should I assign the port width by reading all of the phys on the port? */ |
| 1164 | sci_dev->device_port_width = 1; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1165 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1166 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1169 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1170 | * scic_remote_device_ea_construct() - construct expander attached device |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1171 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1172 | * Remote node context(s) is/are a global resource allocated by this |
| 1173 | * routine, freed by scic_remote_device_destruct(). |
| 1174 | * |
| 1175 | * Returns: |
| 1176 | * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed. |
| 1177 | * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to |
| 1178 | * sata-only controller instance. |
| 1179 | * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1180 | */ |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1181 | 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] | 1182 | struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1183 | { |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1184 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1185 | enum sci_status status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1186 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1187 | scic_remote_device_construct(sci_port, sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1188 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1189 | status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller, |
| 1190 | sci_dev, |
| 1191 | &sci_dev->rnc.remote_node_index); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1192 | if (status != SCI_SUCCESS) |
| 1193 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1194 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1195 | if (dev->dev_type == SAS_END_DEV || dev->dev_type == SATA_DEV || |
| 1196 | (dev->tproto & SAS_PROTOCOL_STP) || dev_is_expander(dev)) |
| 1197 | /* pass */; |
| 1198 | else |
| 1199 | return SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1200 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1201 | /* |
| 1202 | * For SAS-2 the physical link rate is actually a logical link |
| 1203 | * rate that incorporates multiplexing. The SCU doesn't |
| 1204 | * incorporate multiplexing and for the purposes of the |
| 1205 | * connection the logical link rate is that same as the |
| 1206 | * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay |
| 1207 | * one another, so this code works for both situations. */ |
| 1208 | 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] | 1209 | dev->linkrate); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1210 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame] | 1211 | /* / @todo Should I assign the port width by reading all of the phys on the port? */ |
| 1212 | sci_dev->device_port_width = 1; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1213 | |
Dan Williams | ab2e8f7 | 2011-04-27 16:32:45 -0700 | [diff] [blame] | 1214 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * scic_remote_device_start() - This method will start the supplied remote |
| 1219 | * device. This method enables normal IO requests to flow through to the |
| 1220 | * remote device. |
| 1221 | * @remote_device: This parameter specifies the device to be started. |
| 1222 | * @timeout: This parameter specifies the number of milliseconds in which the |
| 1223 | * start operation should complete. |
| 1224 | * |
| 1225 | * An indication of whether the device was successfully started. SCI_SUCCESS |
| 1226 | * This value is returned if the device was successfully started. |
| 1227 | * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start |
| 1228 | * the device when there have been no phys added to it. |
| 1229 | */ |
| 1230 | 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] | 1231 | u32 timeout) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1232 | { |
Dan Williams | eb22967 | 2011-05-01 14:05:57 -0700 | [diff] [blame] | 1233 | struct sci_base_state_machine *sm = &sci_dev->state_machine; |
| 1234 | enum scic_sds_remote_device_states state = sm->current_state_id; |
| 1235 | enum sci_status status; |
| 1236 | |
| 1237 | if (state != SCI_BASE_REMOTE_DEVICE_STATE_STOPPED) { |
| 1238 | dev_warn(scirdev_to_dev(sci_dev), "%s: in wrong state: %d\n", |
| 1239 | __func__, state); |
| 1240 | return SCI_FAILURE_INVALID_STATE; |
| 1241 | } |
| 1242 | |
| 1243 | status = scic_sds_remote_node_context_resume(&sci_dev->rnc, |
| 1244 | remote_device_resume_done, |
| 1245 | sci_dev); |
| 1246 | if (status != SCI_SUCCESS) |
| 1247 | return status; |
| 1248 | |
| 1249 | sci_base_state_machine_change_state(sm, SCI_BASE_REMOTE_DEVICE_STATE_STARTING); |
| 1250 | |
| 1251 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1252 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1253 | |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1254 | static enum sci_status isci_remote_device_construct(struct isci_port *iport, |
| 1255 | struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1256 | { |
Dan Williams | e531381 | 2011-05-07 10:11:43 -0700 | [diff] [blame] | 1257 | struct scic_sds_port *sci_port = &iport->sci; |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1258 | struct isci_host *ihost = iport->isci_host; |
| 1259 | struct domain_device *dev = idev->domain_dev; |
| 1260 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1261 | |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1262 | if (dev->parent && dev_is_expander(dev->parent)) |
| 1263 | status = scic_remote_device_ea_construct(sci_port, &idev->sci); |
| 1264 | else |
| 1265 | status = scic_remote_device_da_construct(sci_port, &idev->sci); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1266 | |
| 1267 | if (status != SCI_SUCCESS) { |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1268 | dev_dbg(&ihost->pdev->dev, "%s: construct failed: %d\n", |
| 1269 | __func__, status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1270 | |
| 1271 | return status; |
| 1272 | } |
| 1273 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1274 | /* start the device. */ |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1275 | status = scic_remote_device_start(&idev->sci, ISCI_REMOTE_DEVICE_START_TIMEOUT); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1276 | |
Dan Williams | 00d680e | 2011-04-25 14:29:29 -0700 | [diff] [blame] | 1277 | if (status != SCI_SUCCESS) |
| 1278 | dev_warn(&ihost->pdev->dev, "remote device start failed: %d\n", |
| 1279 | status); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1280 | |
| 1281 | return status; |
| 1282 | } |
| 1283 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1284 | 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] | 1285 | { |
| 1286 | DECLARE_COMPLETION_ONSTACK(aborted_task_completion); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1287 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1288 | dev_dbg(&ihost->pdev->dev, |
| 1289 | "%s: idev = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1290 | |
| 1291 | /* Cleanup all requests pending for this device. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1292 | isci_terminate_pending_requests(ihost, idev, terminating); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1293 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1294 | dev_dbg(&ihost->pdev->dev, |
| 1295 | "%s: idev = %p, done\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1298 | /** |
| 1299 | * This function builds the isci_remote_device when a libsas dev_found message |
| 1300 | * is received. |
| 1301 | * @isci_host: This parameter specifies the isci host object. |
| 1302 | * @port: This parameter specifies the isci_port conected to this device. |
| 1303 | * |
| 1304 | * pointer to new isci_remote_device. |
| 1305 | */ |
| 1306 | static struct isci_remote_device * |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1307 | isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1308 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1309 | struct isci_remote_device *idev; |
| 1310 | int i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1311 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1312 | for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1313 | idev = &ihost->devices[i]; |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1314 | if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags)) |
| 1315 | break; |
| 1316 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1317 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1318 | if (i >= SCI_MAX_REMOTE_DEVICES) { |
| 1319 | dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1320 | return NULL; |
| 1321 | } |
| 1322 | |
Bartosz Barcinski | 6cb4d6b | 2011-04-12 17:28:43 -0700 | [diff] [blame] | 1323 | if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n")) |
| 1324 | return NULL; |
| 1325 | |
| 1326 | if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n")) |
| 1327 | return NULL; |
| 1328 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1329 | isci_remote_device_change_state(idev, isci_freed); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1330 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1331 | return idev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1332 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1333 | |
| 1334 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1335 | * isci_remote_device_stop() - This function is called internally to stop the |
| 1336 | * remote device. |
| 1337 | * @isci_host: This parameter specifies the isci host object. |
| 1338 | * @isci_device: This parameter specifies the remote device. |
| 1339 | * |
| 1340 | * The status of the scic request to stop. |
| 1341 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1342 | 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] | 1343 | { |
| 1344 | enum sci_status status; |
| 1345 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1346 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1347 | dev_dbg(&ihost->pdev->dev, |
| 1348 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1349 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1350 | isci_remote_device_change_state(idev, isci_stopping); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 1351 | |
| 1352 | /* Kill all outstanding requests. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1353 | isci_remote_device_nuke_requests(ihost, idev); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 1354 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1355 | set_bit(IDEV_STOP_PENDING, &idev->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1356 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1357 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1358 | status = scic_remote_device_stop(&idev->sci, 50); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1359 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1360 | |
| 1361 | /* Wait for the stop complete callback. */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1362 | if (status == SCI_SUCCESS) { |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1363 | wait_for_device_stop(ihost, idev); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1364 | clear_bit(IDEV_ALLOCATED, &idev->flags); |
| 1365 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1366 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1367 | dev_dbg(&ihost->pdev->dev, |
| 1368 | "%s: idev = %p - after completion wait\n", |
| 1369 | __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1370 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1371 | return status; |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * isci_remote_device_gone() - This function is called by libsas when a domain |
| 1376 | * device is removed. |
| 1377 | * @domain_device: This parameter specifies the libsas domain device. |
| 1378 | * |
| 1379 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1380 | void isci_remote_device_gone(struct domain_device *dev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1381 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1382 | struct isci_host *ihost = dev_to_ihost(dev); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1383 | struct isci_remote_device *idev = dev->lldd_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1384 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1385 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1386 | "%s: domain_device = %p, isci_device = %p, isci_port = %p\n", |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1387 | __func__, dev, idev, idev->isci_port); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1388 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1389 | isci_remote_device_stop(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | |
| 1393 | /** |
| 1394 | * isci_remote_device_found() - This function is called by libsas when a remote |
| 1395 | * device is discovered. A remote device object is created and started. the |
| 1396 | * function then sleeps until the sci core device started message is |
| 1397 | * received. |
| 1398 | * @domain_device: This parameter specifies the libsas domain device. |
| 1399 | * |
| 1400 | * status, zero indicates success. |
| 1401 | */ |
| 1402 | int isci_remote_device_found(struct domain_device *domain_dev) |
| 1403 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1404 | struct isci_host *isci_host = dev_to_ihost(domain_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1405 | struct isci_port *isci_port; |
| 1406 | struct isci_phy *isci_phy; |
| 1407 | struct asd_sas_port *sas_port; |
| 1408 | struct asd_sas_phy *sas_phy; |
| 1409 | struct isci_remote_device *isci_device; |
| 1410 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1411 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1412 | dev_dbg(&isci_host->pdev->dev, |
| 1413 | "%s: domain_device = %p\n", __func__, domain_dev); |
| 1414 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1415 | wait_for_start(isci_host); |
| 1416 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1417 | sas_port = domain_dev->port; |
| 1418 | sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy, |
| 1419 | port_phy_el); |
| 1420 | isci_phy = to_isci_phy(sas_phy); |
| 1421 | isci_port = isci_phy->isci_port; |
| 1422 | |
| 1423 | /* we are being called for a device on this port, |
| 1424 | * so it has to come up eventually |
| 1425 | */ |
| 1426 | wait_for_completion(&isci_port->start_complete); |
| 1427 | |
| 1428 | if ((isci_stopping == isci_port_get_state(isci_port)) || |
| 1429 | (isci_stopped == isci_port_get_state(isci_port))) |
| 1430 | return -ENODEV; |
| 1431 | |
| 1432 | isci_device = isci_remote_device_alloc(isci_host, isci_port); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1433 | if (!isci_device) |
| 1434 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1435 | |
| 1436 | INIT_LIST_HEAD(&isci_device->node); |
| 1437 | domain_dev->lldd_dev = isci_device; |
| 1438 | isci_device->domain_dev = domain_dev; |
| 1439 | isci_device->isci_port = isci_port; |
| 1440 | isci_remote_device_change_state(isci_device, isci_starting); |
| 1441 | |
| 1442 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1443 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1444 | list_add_tail(&isci_device->node, &isci_port->remote_dev_list); |
| 1445 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1446 | set_bit(IDEV_START_PENDING, &isci_device->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1447 | status = isci_remote_device_construct(isci_port, isci_device); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1448 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1449 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1450 | dev_dbg(&isci_host->pdev->dev, |
| 1451 | "%s: isci_device = %p\n", |
| 1452 | __func__, isci_device); |
| 1453 | |
| 1454 | if (status != SCI_SUCCESS) { |
| 1455 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1456 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1457 | isci_remote_device_deconstruct( |
| 1458 | isci_host, |
| 1459 | isci_device |
| 1460 | ); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1461 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1462 | return -ENODEV; |
| 1463 | } |
| 1464 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1465 | /* wait for the device ready callback. */ |
| 1466 | wait_for_device_start(isci_host, isci_device); |
| 1467 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1468 | return 0; |
| 1469 | } |
| 1470 | /** |
| 1471 | * isci_device_is_reset_pending() - This function will check if there is any |
| 1472 | * pending reset condition on the device. |
| 1473 | * @request: This parameter is the isci_device object. |
| 1474 | * |
| 1475 | * true if there is a reset pending for the device. |
| 1476 | */ |
| 1477 | bool isci_device_is_reset_pending( |
| 1478 | struct isci_host *isci_host, |
| 1479 | struct isci_remote_device *isci_device) |
| 1480 | { |
| 1481 | struct isci_request *isci_request; |
| 1482 | struct isci_request *tmp_req; |
| 1483 | bool reset_is_pending = false; |
| 1484 | unsigned long flags; |
| 1485 | |
| 1486 | dev_dbg(&isci_host->pdev->dev, |
| 1487 | "%s: isci_device = %p\n", __func__, isci_device); |
| 1488 | |
| 1489 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 1490 | |
| 1491 | /* Check for reset on all pending requests. */ |
| 1492 | list_for_each_entry_safe(isci_request, tmp_req, |
| 1493 | &isci_device->reqs_in_process, dev_node) { |
| 1494 | dev_dbg(&isci_host->pdev->dev, |
| 1495 | "%s: isci_device = %p request = %p\n", |
| 1496 | __func__, isci_device, isci_request); |
| 1497 | |
| 1498 | if (isci_request->ttype == io_task) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1499 | struct sas_task *task = isci_request_access_task( |
| 1500 | isci_request); |
| 1501 | |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 1502 | spin_lock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1503 | if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) |
| 1504 | reset_is_pending = true; |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 1505 | spin_unlock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 1510 | |
| 1511 | dev_dbg(&isci_host->pdev->dev, |
| 1512 | "%s: isci_device = %p reset_is_pending = %d\n", |
| 1513 | __func__, isci_device, reset_is_pending); |
| 1514 | |
| 1515 | return reset_is_pending; |
| 1516 | } |
| 1517 | |
| 1518 | /** |
| 1519 | * isci_device_clear_reset_pending() - This function will clear if any pending |
| 1520 | * reset condition flags on the device. |
| 1521 | * @request: This parameter is the isci_device object. |
| 1522 | * |
| 1523 | * true if there is a reset pending for the device. |
| 1524 | */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1525 | 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] | 1526 | { |
| 1527 | struct isci_request *isci_request; |
| 1528 | struct isci_request *tmp_req; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1529 | unsigned long flags = 0; |
| 1530 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1531 | dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n", |
| 1532 | __func__, idev, ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1533 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1534 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1535 | |
| 1536 | /* Clear reset pending on all pending requests. */ |
| 1537 | list_for_each_entry_safe(isci_request, tmp_req, |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1538 | &idev->reqs_in_process, dev_node) { |
| 1539 | dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n", |
| 1540 | __func__, idev, isci_request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1541 | |
| 1542 | if (isci_request->ttype == io_task) { |
| 1543 | |
| 1544 | unsigned long flags2; |
| 1545 | struct sas_task *task = isci_request_access_task( |
| 1546 | isci_request); |
| 1547 | |
| 1548 | spin_lock_irqsave(&task->task_state_lock, flags2); |
| 1549 | task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; |
| 1550 | spin_unlock_irqrestore(&task->task_state_lock, flags2); |
| 1551 | } |
| 1552 | } |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1553 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1554 | } |