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