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 | */ |
| 55 | |
| 56 | #include "isci.h" |
| 57 | #include "scic_io_request.h" |
| 58 | #include "scic_remote_device.h" |
| 59 | #include "scic_phy.h" |
| 60 | #include "scic_port.h" |
| 61 | #include "port.h" |
| 62 | #include "remote_device.h" |
| 63 | #include "request.h" |
| 64 | #include "task.h" |
| 65 | |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * isci_remote_device_deconstruct() - This function frees an isci_remote_device. |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 70 | * @ihost: This parameter specifies the isci host object. |
| 71 | * @idev: This parameter specifies the remote device to be freed. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 72 | * |
| 73 | */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 74 | 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] | 75 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 76 | dev_dbg(&ihost->pdev->dev, |
| 77 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 78 | |
| 79 | /* There should not be any outstanding io's. All paths to |
| 80 | * here should go through isci_remote_device_nuke_requests. |
| 81 | * If we hit this condition, we will need a way to complete |
| 82 | * io requests in process */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 83 | while (!list_empty(&idev->reqs_in_process)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 84 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 85 | dev_err(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 86 | "%s: ** request list not empty! **\n", __func__); |
| 87 | BUG(); |
| 88 | } |
| 89 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 90 | scic_remote_device_destruct(to_sci_dev(idev)); |
| 91 | idev->domain_dev->lldd_dev = NULL; |
| 92 | idev->domain_dev = NULL; |
| 93 | idev->isci_port = NULL; |
| 94 | list_del_init(&idev->node); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 95 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 96 | clear_bit(IDEV_START_PENDING, &idev->flags); |
| 97 | clear_bit(IDEV_STOP_PENDING, &idev->flags); |
| 98 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * isci_remote_device_construct() - This function calls the scic remote device |
| 104 | * construct and start functions, it waits on the remote device start |
| 105 | * completion. |
| 106 | * @port: This parameter specifies the isci port with the remote device. |
| 107 | * @isci_device: This parameter specifies the isci remote device |
| 108 | * |
| 109 | * status from the scic calls, the caller to this function should clean up |
| 110 | * resources as appropriate. |
| 111 | */ |
| 112 | static enum sci_status isci_remote_device_construct( |
| 113 | struct isci_port *port, |
| 114 | struct isci_remote_device *isci_device) |
| 115 | { |
| 116 | enum sci_status status = SCI_SUCCESS; |
| 117 | |
| 118 | /* let the core do it's common constuction. */ |
| 119 | scic_remote_device_construct(port->sci_port_handle, |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 120 | to_sci_dev(isci_device)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 121 | |
| 122 | /* let the core do it's device specific constuction. */ |
| 123 | if (isci_device->domain_dev->parent && |
| 124 | (isci_device->domain_dev->parent->dev_type == EDGE_DEV)) { |
| 125 | int i; |
| 126 | |
| 127 | /* struct smp_response_discover discover_response; */ |
| 128 | struct discover_resp discover_response; |
| 129 | struct domain_device *parent = |
| 130 | isci_device->domain_dev->parent; |
| 131 | |
| 132 | struct expander_device *parent_ex = &parent->ex_dev; |
| 133 | |
| 134 | for (i = 0; i < parent_ex->num_phys; i++) { |
| 135 | |
| 136 | struct ex_phy *phy = &parent_ex->ex_phy[i]; |
| 137 | |
| 138 | if ((phy->phy_state == PHY_VACANT) || |
| 139 | (phy->phy_state == PHY_NOT_PRESENT)) |
| 140 | continue; |
| 141 | |
| 142 | if (SAS_ADDR(phy->attached_sas_addr) |
| 143 | == SAS_ADDR(isci_device->domain_dev->sas_addr)) { |
| 144 | |
| 145 | discover_response.attached_dev_type |
| 146 | = phy->attached_dev_type; |
| 147 | discover_response.linkrate |
| 148 | = phy->linkrate; |
| 149 | discover_response.attached_sata_host |
| 150 | = phy->attached_sata_host; |
| 151 | discover_response.attached_sata_dev |
| 152 | = phy->attached_sata_dev; |
| 153 | discover_response.attached_sata_ps |
| 154 | = phy->attached_sata_ps; |
| 155 | discover_response.iproto |
| 156 | = phy->attached_iproto >> 1; |
| 157 | discover_response.tproto |
| 158 | = phy->attached_tproto >> 1; |
| 159 | memcpy( |
| 160 | discover_response.attached_sas_addr, |
| 161 | phy->attached_sas_addr, |
| 162 | SAS_ADDR_SIZE |
| 163 | ); |
| 164 | discover_response.attached_phy_id |
| 165 | = phy->attached_phy_id; |
| 166 | discover_response.change_count |
| 167 | = phy->phy_change_count; |
| 168 | discover_response.routing_attr |
| 169 | = phy->routing_attr; |
| 170 | discover_response.hmin_linkrate |
| 171 | = phy->phy->minimum_linkrate_hw; |
| 172 | discover_response.hmax_linkrate |
| 173 | = phy->phy->maximum_linkrate_hw; |
| 174 | discover_response.pmin_linkrate |
| 175 | = phy->phy->minimum_linkrate; |
| 176 | discover_response.pmax_linkrate |
| 177 | = phy->phy->maximum_linkrate; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | |
| 182 | dev_dbg(&port->isci_host->pdev->dev, |
| 183 | "%s: parent->dev_type = EDGE_DEV\n", |
| 184 | __func__); |
| 185 | |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 186 | status = scic_remote_device_ea_construct(to_sci_dev(isci_device), |
| 187 | (struct smp_response_discover *)&discover_response); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 188 | |
| 189 | } else |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 190 | status = scic_remote_device_da_construct(to_sci_dev(isci_device)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 191 | |
| 192 | |
| 193 | if (status != SCI_SUCCESS) { |
| 194 | dev_dbg(&port->isci_host->pdev->dev, |
| 195 | "%s: scic_remote_device_da_construct failed - " |
| 196 | "isci_device = %p\n", |
| 197 | __func__, |
| 198 | isci_device); |
| 199 | |
| 200 | return status; |
| 201 | } |
| 202 | |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 203 | sci_object_set_association(to_sci_dev(isci_device), isci_device); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 204 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 205 | /* start the device. */ |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 206 | status = scic_remote_device_start(to_sci_dev(isci_device), |
| 207 | ISCI_REMOTE_DEVICE_START_TIMEOUT); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 208 | |
| 209 | if (status != SCI_SUCCESS) { |
| 210 | dev_warn(&port->isci_host->pdev->dev, |
| 211 | "%s: scic_remote_device_start failed\n", |
| 212 | __func__); |
| 213 | return status; |
| 214 | } |
| 215 | |
| 216 | return status; |
| 217 | } |
| 218 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 219 | void isci_remote_device_nuke_requests(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 220 | { |
| 221 | DECLARE_COMPLETION_ONSTACK(aborted_task_completion); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 222 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 223 | dev_dbg(&ihost->pdev->dev, |
| 224 | "%s: idev = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 225 | |
| 226 | /* Cleanup all requests pending for this device. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 227 | isci_terminate_pending_requests(ihost, idev, terminating); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 228 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 229 | dev_dbg(&ihost->pdev->dev, |
| 230 | "%s: idev = %p, done\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 233 | /** |
| 234 | * This function builds the isci_remote_device when a libsas dev_found message |
| 235 | * is received. |
| 236 | * @isci_host: This parameter specifies the isci host object. |
| 237 | * @port: This parameter specifies the isci_port conected to this device. |
| 238 | * |
| 239 | * pointer to new isci_remote_device. |
| 240 | */ |
| 241 | static struct isci_remote_device * |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 242 | isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 243 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 244 | struct isci_remote_device *idev; |
| 245 | int i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 246 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 247 | for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { |
| 248 | idev = idev_by_id(ihost, i); |
| 249 | if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags)) |
| 250 | break; |
| 251 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 252 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 253 | if (i >= SCI_MAX_REMOTE_DEVICES) { |
| 254 | dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 255 | return NULL; |
| 256 | } |
| 257 | |
Bartosz Barcinski | 6cb4d6b | 2011-04-12 17:28:43 -0700 | [diff] [blame^] | 258 | if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n")) |
| 259 | return NULL; |
| 260 | |
| 261 | if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n")) |
| 262 | return NULL; |
| 263 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 264 | isci_remote_device_change_state(idev, isci_freed); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 265 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 266 | return idev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 267 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * isci_remote_device_ready() - This function is called by the scic when the |
| 271 | * remote device is ready. We mark the isci device as ready and signal the |
| 272 | * waiting proccess. |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 273 | * @ihost: our valid isci_host |
| 274 | * @idev: remote device |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 275 | * |
| 276 | */ |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 277 | void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 278 | { |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 279 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 280 | "%s: idev = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 281 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 282 | isci_remote_device_change_state(idev, isci_ready_for_io); |
| 283 | if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags)) |
| 284 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** |
| 288 | * isci_remote_device_not_ready() - This function is called by the scic when |
| 289 | * the remote device is not ready. We mark the isci device as ready (not |
| 290 | * "ready_for_io") and signal the waiting proccess. |
| 291 | * @isci_host: This parameter specifies the isci host object. |
| 292 | * @isci_device: This parameter specifies the remote device |
| 293 | * |
| 294 | */ |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 295 | void isci_remote_device_not_ready(struct isci_host *ihost, |
| 296 | struct isci_remote_device *idev, u32 reason) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 297 | { |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 298 | dev_dbg(&ihost->pdev->dev, |
| 299 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 300 | |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 301 | if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED) |
| 302 | isci_remote_device_change_state(idev, isci_stopping); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 303 | else |
| 304 | /* device ready is actually a "not ready for io" state. */ |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 305 | isci_remote_device_change_state(idev, isci_ready); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /** |
| 309 | * isci_remote_device_stop_complete() - This function is called by the scic |
| 310 | * when the remote device stop has completed. We mark the isci device as not |
| 311 | * ready and remove the isci remote device. |
| 312 | * @isci_host: This parameter specifies the isci host object. |
| 313 | * @isci_device: This parameter specifies the remote device. |
| 314 | * @status: This parameter specifies status of the completion. |
| 315 | * |
| 316 | */ |
| 317 | void isci_remote_device_stop_complete( |
| 318 | struct isci_host *isci_host, |
| 319 | struct isci_remote_device *isci_device, |
| 320 | enum sci_status status) |
| 321 | { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 322 | dev_dbg(&isci_host->pdev->dev, |
| 323 | "%s: complete isci_device = %p, status = 0x%x\n", |
| 324 | __func__, |
| 325 | isci_device, |
| 326 | status); |
| 327 | |
| 328 | isci_remote_device_change_state(isci_device, isci_stopped); |
| 329 | |
| 330 | /* after stop, we can tear down resources. */ |
| 331 | isci_remote_device_deconstruct(isci_host, isci_device); |
| 332 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
| 336 | * isci_remote_device_start_complete() - This function is called by the scic |
| 337 | * when the remote device start has completed |
| 338 | * @isci_host: This parameter specifies the isci host object. |
| 339 | * @isci_device: This parameter specifies the remote device. |
| 340 | * @status: This parameter specifies status of the completion. |
| 341 | * |
| 342 | */ |
| 343 | void isci_remote_device_start_complete( |
| 344 | struct isci_host *isci_host, |
| 345 | struct isci_remote_device *isci_device, |
| 346 | enum sci_status status) |
| 347 | { |
| 348 | |
| 349 | |
| 350 | } |
| 351 | |
| 352 | |
| 353 | /** |
| 354 | * isci_remote_device_stop() - This function is called internally to stop the |
| 355 | * remote device. |
| 356 | * @isci_host: This parameter specifies the isci host object. |
| 357 | * @isci_device: This parameter specifies the remote device. |
| 358 | * |
| 359 | * The status of the scic request to stop. |
| 360 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 361 | 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] | 362 | { |
| 363 | enum sci_status status; |
| 364 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 365 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 366 | dev_dbg(&ihost->pdev->dev, |
| 367 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 368 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 369 | isci_remote_device_change_state(idev, isci_stopping); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 370 | |
| 371 | /* Kill all outstanding requests. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 372 | isci_remote_device_nuke_requests(ihost, idev); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 373 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 374 | set_bit(IDEV_STOP_PENDING, &idev->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 375 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 376 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 377 | status = scic_remote_device_stop(to_sci_dev(idev), 50); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 378 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 379 | |
| 380 | /* Wait for the stop complete callback. */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 381 | if (status == SCI_SUCCESS) { |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 382 | wait_for_device_stop(ihost, idev); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 383 | clear_bit(IDEV_ALLOCATED, &idev->flags); |
| 384 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 385 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 386 | dev_dbg(&ihost->pdev->dev, |
| 387 | "%s: idev = %p - after completion wait\n", |
| 388 | __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 389 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 390 | return status; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * isci_remote_device_gone() - This function is called by libsas when a domain |
| 395 | * device is removed. |
| 396 | * @domain_device: This parameter specifies the libsas domain device. |
| 397 | * |
| 398 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 399 | void isci_remote_device_gone(struct domain_device *dev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 400 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 401 | struct isci_host *ihost = dev_to_ihost(dev); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 402 | struct isci_remote_device *idev = dev->lldd_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 403 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 404 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 405 | "%s: domain_device = %p, isci_device = %p, isci_port = %p\n", |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 406 | __func__, dev, idev, idev->isci_port); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 407 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 408 | isci_remote_device_stop(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
| 412 | /** |
| 413 | * isci_remote_device_found() - This function is called by libsas when a remote |
| 414 | * device is discovered. A remote device object is created and started. the |
| 415 | * function then sleeps until the sci core device started message is |
| 416 | * received. |
| 417 | * @domain_device: This parameter specifies the libsas domain device. |
| 418 | * |
| 419 | * status, zero indicates success. |
| 420 | */ |
| 421 | int isci_remote_device_found(struct domain_device *domain_dev) |
| 422 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 423 | struct isci_host *isci_host = dev_to_ihost(domain_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 424 | struct isci_port *isci_port; |
| 425 | struct isci_phy *isci_phy; |
| 426 | struct asd_sas_port *sas_port; |
| 427 | struct asd_sas_phy *sas_phy; |
| 428 | struct isci_remote_device *isci_device; |
| 429 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 430 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 431 | dev_dbg(&isci_host->pdev->dev, |
| 432 | "%s: domain_device = %p\n", __func__, domain_dev); |
| 433 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 434 | wait_for_start(isci_host); |
| 435 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 436 | sas_port = domain_dev->port; |
| 437 | sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy, |
| 438 | port_phy_el); |
| 439 | isci_phy = to_isci_phy(sas_phy); |
| 440 | isci_port = isci_phy->isci_port; |
| 441 | |
| 442 | /* we are being called for a device on this port, |
| 443 | * so it has to come up eventually |
| 444 | */ |
| 445 | wait_for_completion(&isci_port->start_complete); |
| 446 | |
| 447 | if ((isci_stopping == isci_port_get_state(isci_port)) || |
| 448 | (isci_stopped == isci_port_get_state(isci_port))) |
| 449 | return -ENODEV; |
| 450 | |
| 451 | isci_device = isci_remote_device_alloc(isci_host, isci_port); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 452 | if (!isci_device) |
| 453 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 454 | |
| 455 | INIT_LIST_HEAD(&isci_device->node); |
| 456 | domain_dev->lldd_dev = isci_device; |
| 457 | isci_device->domain_dev = domain_dev; |
| 458 | isci_device->isci_port = isci_port; |
| 459 | isci_remote_device_change_state(isci_device, isci_starting); |
| 460 | |
| 461 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 462 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 463 | list_add_tail(&isci_device->node, &isci_port->remote_dev_list); |
| 464 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 465 | set_bit(IDEV_START_PENDING, &isci_device->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 466 | status = isci_remote_device_construct(isci_port, isci_device); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 467 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 468 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 469 | dev_dbg(&isci_host->pdev->dev, |
| 470 | "%s: isci_device = %p\n", |
| 471 | __func__, isci_device); |
| 472 | |
| 473 | if (status != SCI_SUCCESS) { |
| 474 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 475 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 476 | isci_remote_device_deconstruct( |
| 477 | isci_host, |
| 478 | isci_device |
| 479 | ); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 480 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 481 | return -ENODEV; |
| 482 | } |
| 483 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 484 | /* wait for the device ready callback. */ |
| 485 | wait_for_device_start(isci_host, isci_device); |
| 486 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | /** |
| 490 | * isci_device_is_reset_pending() - This function will check if there is any |
| 491 | * pending reset condition on the device. |
| 492 | * @request: This parameter is the isci_device object. |
| 493 | * |
| 494 | * true if there is a reset pending for the device. |
| 495 | */ |
| 496 | bool isci_device_is_reset_pending( |
| 497 | struct isci_host *isci_host, |
| 498 | struct isci_remote_device *isci_device) |
| 499 | { |
| 500 | struct isci_request *isci_request; |
| 501 | struct isci_request *tmp_req; |
| 502 | bool reset_is_pending = false; |
| 503 | unsigned long flags; |
| 504 | |
| 505 | dev_dbg(&isci_host->pdev->dev, |
| 506 | "%s: isci_device = %p\n", __func__, isci_device); |
| 507 | |
| 508 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 509 | |
| 510 | /* Check for reset on all pending requests. */ |
| 511 | list_for_each_entry_safe(isci_request, tmp_req, |
| 512 | &isci_device->reqs_in_process, dev_node) { |
| 513 | dev_dbg(&isci_host->pdev->dev, |
| 514 | "%s: isci_device = %p request = %p\n", |
| 515 | __func__, isci_device, isci_request); |
| 516 | |
| 517 | if (isci_request->ttype == io_task) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 518 | struct sas_task *task = isci_request_access_task( |
| 519 | isci_request); |
| 520 | |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 521 | spin_lock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 522 | if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) |
| 523 | reset_is_pending = true; |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 524 | spin_unlock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
| 528 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 529 | |
| 530 | dev_dbg(&isci_host->pdev->dev, |
| 531 | "%s: isci_device = %p reset_is_pending = %d\n", |
| 532 | __func__, isci_device, reset_is_pending); |
| 533 | |
| 534 | return reset_is_pending; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * isci_device_clear_reset_pending() - This function will clear if any pending |
| 539 | * reset condition flags on the device. |
| 540 | * @request: This parameter is the isci_device object. |
| 541 | * |
| 542 | * true if there is a reset pending for the device. |
| 543 | */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 544 | void isci_device_clear_reset_pending(struct isci_host *ihost, struct isci_remote_device *idev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 545 | { |
| 546 | struct isci_request *isci_request; |
| 547 | struct isci_request *tmp_req; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 548 | unsigned long flags = 0; |
| 549 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 550 | dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n", |
| 551 | __func__, idev, ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 552 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 553 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 554 | |
| 555 | /* Clear reset pending on all pending requests. */ |
| 556 | list_for_each_entry_safe(isci_request, tmp_req, |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 557 | &idev->reqs_in_process, dev_node) { |
| 558 | dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n", |
| 559 | __func__, idev, isci_request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 560 | |
| 561 | if (isci_request->ttype == io_task) { |
| 562 | |
| 563 | unsigned long flags2; |
| 564 | struct sas_task *task = isci_request_access_task( |
| 565 | isci_request); |
| 566 | |
| 567 | spin_lock_irqsave(&task->task_state_lock, flags2); |
| 568 | task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; |
| 569 | spin_unlock_irqrestore(&task->task_state_lock, flags2); |
| 570 | } |
| 571 | } |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 572 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * isci_remote_device_change_state() - This function gets the status of the |
| 577 | * remote_device object. |
| 578 | * @isci_device: This parameter points to the isci_remote_device object |
| 579 | * |
| 580 | * status of the object as a isci_status enum. |
| 581 | */ |
| 582 | void isci_remote_device_change_state( |
| 583 | struct isci_remote_device *isci_device, |
| 584 | enum isci_status status) |
| 585 | { |
| 586 | unsigned long flags; |
| 587 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 588 | spin_lock_irqsave(&isci_device->state_lock, flags); |
| 589 | isci_device->status = status; |
| 590 | spin_unlock_irqrestore(&isci_device->state_lock, flags); |
| 591 | } |