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