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