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