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 | */ |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 55 | #include "intel_sas.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 56 | #include "isci.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #include "port.h" |
| 58 | #include "remote_device.h" |
| 59 | #include "request.h" |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 60 | #include "scic_controller.h" |
| 61 | #include "scic_io_request.h" |
| 62 | #include "scic_phy.h" |
| 63 | #include "scic_port.h" |
| 64 | #include "scic_sds_controller.h" |
| 65 | #include "scic_sds_phy.h" |
| 66 | #include "scic_sds_port.h" |
| 67 | #include "remote_node_context.h" |
| 68 | #include "scic_sds_request.h" |
| 69 | #include "sci_environment.h" |
| 70 | #include "sci_util.h" |
| 71 | #include "scu_event_codes.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 72 | #include "task.h" |
| 73 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 74 | enum sci_status scic_remote_device_stop( |
| 75 | struct scic_sds_remote_device *sci_dev, |
| 76 | u32 timeout) |
| 77 | { |
| 78 | return sci_dev->state_handlers->stop_handler(sci_dev); |
| 79 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 80 | |
| 81 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 82 | enum sci_status scic_remote_device_reset( |
| 83 | struct scic_sds_remote_device *sci_dev) |
| 84 | { |
| 85 | return sci_dev->state_handlers->reset_handler(sci_dev); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | enum sci_status scic_remote_device_reset_complete( |
| 90 | struct scic_sds_remote_device *sci_dev) |
| 91 | { |
| 92 | return sci_dev->state_handlers->reset_complete_handler(sci_dev); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | enum sas_linkrate scic_remote_device_get_connection_rate( |
| 97 | struct scic_sds_remote_device *sci_dev) |
| 98 | { |
| 99 | return sci_dev->connection_rate; |
| 100 | } |
| 101 | |
| 102 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 103 | #if !defined(DISABLE_ATAPI) |
| 104 | bool scic_remote_device_is_atapi(struct scic_sds_remote_device *sci_dev) |
| 105 | { |
| 106 | return sci_dev->is_atapi; |
| 107 | } |
| 108 | #endif |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * |
| 113 | * |
| 114 | * Remote device timer requirements |
| 115 | */ |
| 116 | #define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0) |
| 117 | #define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES) |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * |
| 122 | * @sci_dev: The remote device for which the suspend is being requested. |
| 123 | * |
| 124 | * This method invokes the remote device suspend state handler. enum sci_status |
| 125 | */ |
| 126 | enum sci_status scic_sds_remote_device_suspend( |
| 127 | struct scic_sds_remote_device *sci_dev, |
| 128 | u32 suspend_type) |
| 129 | { |
| 130 | return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * |
| 135 | * @sci_dev: The remote device for which the event handling is being |
| 136 | * requested. |
| 137 | * @frame_index: This is the frame index that is being processed. |
| 138 | * |
| 139 | * This method invokes the frame handler for the remote device state machine |
| 140 | * enum sci_status |
| 141 | */ |
| 142 | enum sci_status scic_sds_remote_device_frame_handler( |
| 143 | struct scic_sds_remote_device *sci_dev, |
| 144 | u32 frame_index) |
| 145 | { |
| 146 | return sci_dev->state_handlers->frame_handler(sci_dev, frame_index); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * |
| 151 | * @sci_dev: The remote device for which the event handling is being |
| 152 | * requested. |
| 153 | * @event_code: This is the event code that is to be processed. |
| 154 | * |
| 155 | * This method invokes the remote device event handler. enum sci_status |
| 156 | */ |
| 157 | enum sci_status scic_sds_remote_device_event_handler( |
| 158 | struct scic_sds_remote_device *sci_dev, |
| 159 | u32 event_code) |
| 160 | { |
| 161 | return sci_dev->state_handlers->event_handler(sci_dev, event_code); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * |
| 166 | * @controller: The controller that is starting the io request. |
| 167 | * @sci_dev: The remote device for which the start io handling is being |
| 168 | * requested. |
| 169 | * @io_request: The io request that is being started. |
| 170 | * |
| 171 | * This method invokes the remote device start io handler. enum sci_status |
| 172 | */ |
| 173 | enum sci_status scic_sds_remote_device_start_io( |
| 174 | struct scic_sds_controller *controller, |
| 175 | struct scic_sds_remote_device *sci_dev, |
| 176 | struct scic_sds_request *io_request) |
| 177 | { |
| 178 | return sci_dev->state_handlers->start_io_handler( |
| 179 | sci_dev, io_request); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * |
| 184 | * @controller: The controller that is completing the io request. |
| 185 | * @sci_dev: The remote device for which the complete io handling is being |
| 186 | * requested. |
| 187 | * @io_request: The io request that is being completed. |
| 188 | * |
| 189 | * This method invokes the remote device complete io handler. enum sci_status |
| 190 | */ |
| 191 | enum sci_status scic_sds_remote_device_complete_io( |
| 192 | struct scic_sds_controller *controller, |
| 193 | struct scic_sds_remote_device *sci_dev, |
| 194 | struct scic_sds_request *io_request) |
| 195 | { |
| 196 | return sci_dev->state_handlers->complete_io_handler( |
| 197 | sci_dev, io_request); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * |
| 202 | * @controller: The controller that is starting the task request. |
| 203 | * @sci_dev: The remote device for which the start task handling is being |
| 204 | * requested. |
| 205 | * @io_request: The task request that is being started. |
| 206 | * |
| 207 | * This method invokes the remote device start task handler. enum sci_status |
| 208 | */ |
| 209 | enum sci_status scic_sds_remote_device_start_task( |
| 210 | struct scic_sds_controller *controller, |
| 211 | struct scic_sds_remote_device *sci_dev, |
| 212 | struct scic_sds_request *io_request) |
| 213 | { |
| 214 | return sci_dev->state_handlers->start_task_handler( |
| 215 | sci_dev, io_request); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * |
| 220 | * @controller: The controller that is completing the task request. |
| 221 | * @sci_dev: The remote device for which the complete task handling is |
| 222 | * being requested. |
| 223 | * @io_request: The task request that is being completed. |
| 224 | * |
| 225 | * This method invokes the remote device complete task handler. enum sci_status |
| 226 | */ |
| 227 | |
| 228 | /** |
| 229 | * |
| 230 | * @sci_dev: |
| 231 | * @request: |
| 232 | * |
| 233 | * This method takes the request and bulids an appropriate SCU context for the |
| 234 | * request and then requests the controller to post the request. none |
| 235 | */ |
| 236 | void scic_sds_remote_device_post_request( |
| 237 | struct scic_sds_remote_device *sci_dev, |
| 238 | u32 request) |
| 239 | { |
| 240 | u32 context; |
| 241 | |
| 242 | context = scic_sds_remote_device_build_command_context(sci_dev, request); |
| 243 | |
| 244 | scic_sds_controller_post_request( |
| 245 | scic_sds_remote_device_get_controller(sci_dev), |
| 246 | context |
| 247 | ); |
| 248 | } |
| 249 | |
| 250 | #if !defined(DISABLE_ATAPI) |
| 251 | /** |
| 252 | * |
| 253 | * @sci_dev: The device to be checked. |
| 254 | * |
| 255 | * This method check the signature fis of a stp device to decide whether a |
| 256 | * device is atapi or not. true if a device is atapi device. False if a device |
| 257 | * is not atapi. |
| 258 | */ |
| 259 | bool scic_sds_remote_device_is_atapi( |
| 260 | struct scic_sds_remote_device *sci_dev) |
| 261 | { |
| 262 | if (!sci_dev->target_protocols.u.bits.attached_stp_target) |
| 263 | return false; |
| 264 | else if (sci_dev->is_direct_attached) { |
| 265 | struct scic_sds_phy *phy; |
| 266 | struct scic_sata_phy_properties properties; |
| 267 | struct sata_fis_reg_d2h *signature_fis; |
| 268 | phy = scic_sds_port_get_a_connected_phy(sci_dev->owning_port); |
| 269 | scic_sata_phy_get_properties(phy, &properties); |
| 270 | |
| 271 | /* decode the signature fis. */ |
| 272 | signature_fis = &(properties.signature_fis); |
| 273 | |
| 274 | if ((signature_fis->sector_count == 0x01) |
| 275 | && (signature_fis->lba_low == 0x01) |
| 276 | && (signature_fis->lba_mid == 0x14) |
| 277 | && (signature_fis->lba_high == 0xEB) |
| 278 | && ((signature_fis->device & 0x5F) == 0x00) |
| 279 | ) { |
| 280 | /* An ATA device supporting the PACKET command set. */ |
| 281 | return true; |
| 282 | } else |
| 283 | return false; |
| 284 | } else { |
| 285 | /* Expander supported ATAPI device is not currently supported. */ |
| 286 | return false; |
| 287 | } |
| 288 | } |
| 289 | #endif |
| 290 | |
| 291 | /** |
| 292 | * |
| 293 | * @user_parameter: This is cast to a remote device object. |
| 294 | * |
| 295 | * This method is called once the remote node context is ready to be freed. |
| 296 | * The remote device can now report that its stop operation is complete. none |
| 297 | */ |
| 298 | static void scic_sds_cb_remote_device_rnc_destruct_complete( |
| 299 | void *user_parameter) |
| 300 | { |
| 301 | struct scic_sds_remote_device *sci_dev; |
| 302 | |
| 303 | sci_dev = (struct scic_sds_remote_device *)user_parameter; |
| 304 | |
| 305 | BUG_ON(sci_dev->started_request_count != 0); |
| 306 | |
| 307 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 308 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * |
| 313 | * @user_parameter: This is cast to a remote device object. |
| 314 | * |
| 315 | * This method is called once the remote node context has transisitioned to a |
| 316 | * ready state. This is the indication that the remote device object can also |
| 317 | * transition to ready. none |
| 318 | */ |
| 319 | static void scic_sds_remote_device_resume_complete_handler( |
| 320 | void *user_parameter) |
| 321 | { |
| 322 | struct scic_sds_remote_device *sci_dev; |
| 323 | |
| 324 | sci_dev = (struct scic_sds_remote_device *)user_parameter; |
| 325 | |
| 326 | if ( |
| 327 | sci_base_state_machine_get_state(&sci_dev->state_machine) |
| 328 | != SCI_BASE_REMOTE_DEVICE_STATE_READY |
| 329 | ) { |
| 330 | sci_base_state_machine_change_state( |
| 331 | &sci_dev->state_machine, |
| 332 | SCI_BASE_REMOTE_DEVICE_STATE_READY |
| 333 | ); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * |
| 339 | * @device: This parameter specifies the device for which the request is being |
| 340 | * started. |
| 341 | * @request: This parameter specifies the request being started. |
| 342 | * @status: This parameter specifies the current start operation status. |
| 343 | * |
| 344 | * This method will perform the STP request start processing common to IO |
| 345 | * requests and task requests of all types. none |
| 346 | */ |
| 347 | void scic_sds_remote_device_start_request( |
| 348 | struct scic_sds_remote_device *sci_dev, |
| 349 | struct scic_sds_request *sci_req, |
| 350 | enum sci_status status) |
| 351 | { |
| 352 | /* We still have a fault in starting the io complete it on the port */ |
| 353 | if (status == SCI_SUCCESS) |
| 354 | scic_sds_remote_device_increment_request_count(sci_dev); |
| 355 | else{ |
| 356 | sci_dev->owning_port->state_handlers->complete_io_handler( |
| 357 | sci_dev->owning_port, sci_dev, sci_req |
| 358 | ); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | |
| 363 | /** |
| 364 | * |
| 365 | * @request: This parameter specifies the request being continued. |
| 366 | * |
| 367 | * This method will continue to post tc for a STP request. This method usually |
| 368 | * serves as a callback when RNC gets resumed during a task management |
| 369 | * sequence. none |
| 370 | */ |
| 371 | void scic_sds_remote_device_continue_request(void *dev) |
| 372 | { |
| 373 | struct scic_sds_remote_device *sci_dev = dev; |
| 374 | |
| 375 | /* we need to check if this request is still valid to continue. */ |
| 376 | if (sci_dev->working_request) |
| 377 | scic_controller_continue_io(sci_dev->working_request); |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * This method will terminate all of the IO requests in the controllers IO |
| 382 | * request table that were targeted for this device. |
| 383 | * @sci_dev: This parameter specifies the remote device for which to |
| 384 | * attempt to terminate all requests. |
| 385 | * |
| 386 | * This method returns an indication as to whether all requests were |
| 387 | * successfully terminated. If a single request fails to be terminated, then |
| 388 | * this method will return the failure. |
| 389 | */ |
| 390 | static enum sci_status scic_sds_remote_device_terminate_requests( |
| 391 | struct scic_sds_remote_device *sci_dev) |
| 392 | { |
| 393 | enum sci_status status = SCI_SUCCESS; |
| 394 | enum sci_status terminate_status = SCI_SUCCESS; |
| 395 | struct scic_sds_request *sci_req; |
| 396 | u32 index; |
| 397 | u32 request_count = sci_dev->started_request_count; |
| 398 | |
| 399 | for (index = 0; |
| 400 | (index < SCI_MAX_IO_REQUESTS) && (request_count > 0); |
| 401 | index++) { |
| 402 | sci_req = sci_dev->owning_port->owning_controller->io_request_table[index]; |
| 403 | |
| 404 | if ((sci_req != NULL) && (sci_req->target_device == sci_dev)) { |
| 405 | terminate_status = scic_controller_terminate_request( |
| 406 | sci_dev->owning_port->owning_controller, |
| 407 | sci_dev, |
| 408 | sci_req |
| 409 | ); |
| 410 | |
| 411 | if (terminate_status != SCI_SUCCESS) |
| 412 | status = terminate_status; |
| 413 | |
| 414 | request_count--; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | return status; |
| 419 | } |
| 420 | |
| 421 | static enum sci_status |
| 422 | default_device_handler(struct scic_sds_remote_device *sci_dev, |
| 423 | const char *func) |
| 424 | { |
| 425 | dev_warn(scirdev_to_dev(sci_dev), |
| 426 | "%s: in wrong state: %d\n", func, |
| 427 | sci_base_state_machine_get_state(&sci_dev->state_machine)); |
| 428 | return SCI_FAILURE_INVALID_STATE; |
| 429 | } |
| 430 | |
| 431 | enum sci_status scic_sds_remote_device_default_start_handler( |
| 432 | struct scic_sds_remote_device *sci_dev) |
| 433 | { |
| 434 | return default_device_handler(sci_dev, __func__); |
| 435 | } |
| 436 | |
| 437 | static enum sci_status scic_sds_remote_device_default_stop_handler( |
| 438 | struct scic_sds_remote_device *sci_dev) |
| 439 | { |
| 440 | return default_device_handler(sci_dev, __func__); |
| 441 | } |
| 442 | |
| 443 | enum sci_status scic_sds_remote_device_default_fail_handler( |
| 444 | struct scic_sds_remote_device *sci_dev) |
| 445 | { |
| 446 | return default_device_handler(sci_dev, __func__); |
| 447 | } |
| 448 | |
| 449 | enum sci_status scic_sds_remote_device_default_destruct_handler( |
| 450 | struct scic_sds_remote_device *sci_dev) |
| 451 | { |
| 452 | return default_device_handler(sci_dev, __func__); |
| 453 | } |
| 454 | |
| 455 | enum sci_status scic_sds_remote_device_default_reset_handler( |
| 456 | struct scic_sds_remote_device *sci_dev) |
| 457 | { |
| 458 | return default_device_handler(sci_dev, __func__); |
| 459 | } |
| 460 | |
| 461 | enum sci_status scic_sds_remote_device_default_reset_complete_handler( |
| 462 | struct scic_sds_remote_device *sci_dev) |
| 463 | { |
| 464 | return default_device_handler(sci_dev, __func__); |
| 465 | } |
| 466 | |
| 467 | enum sci_status scic_sds_remote_device_default_suspend_handler( |
| 468 | struct scic_sds_remote_device *sci_dev, u32 suspend_type) |
| 469 | { |
| 470 | return default_device_handler(sci_dev, __func__); |
| 471 | } |
| 472 | |
| 473 | enum sci_status scic_sds_remote_device_default_resume_handler( |
| 474 | struct scic_sds_remote_device *sci_dev) |
| 475 | { |
| 476 | return default_device_handler(sci_dev, __func__); |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * |
| 481 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 482 | * struct scic_sds_remote_device. |
| 483 | * @event_code: The event code that the struct scic_sds_controller wants the device |
| 484 | * object to process. |
| 485 | * |
| 486 | * This method is the default event handler. It will call the RNC state |
| 487 | * machine handler for any RNC events otherwise it will log a warning and |
| 488 | * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE |
| 489 | */ |
| 490 | static enum sci_status scic_sds_remote_device_core_event_handler( |
| 491 | struct scic_sds_remote_device *sci_dev, |
| 492 | u32 event_code, |
| 493 | bool is_ready_state) |
| 494 | { |
| 495 | enum sci_status status; |
| 496 | |
| 497 | switch (scu_get_event_type(event_code)) { |
| 498 | case SCU_EVENT_TYPE_RNC_OPS_MISC: |
| 499 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 500 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 501 | status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code); |
| 502 | break; |
| 503 | case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT: |
| 504 | |
| 505 | if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) { |
| 506 | status = SCI_SUCCESS; |
| 507 | |
| 508 | /* Suspend the associated RNC */ |
| 509 | scic_sds_remote_node_context_suspend(&sci_dev->rnc, |
| 510 | SCI_SOFTWARE_SUSPENSION, |
| 511 | NULL, NULL); |
| 512 | |
| 513 | dev_dbg(scirdev_to_dev(sci_dev), |
| 514 | "%s: device: %p event code: %x: %s\n", |
| 515 | __func__, sci_dev, event_code, |
| 516 | (is_ready_state) |
| 517 | ? "I_T_Nexus_Timeout event" |
| 518 | : "I_T_Nexus_Timeout event in wrong state"); |
| 519 | |
| 520 | break; |
| 521 | } |
| 522 | /* Else, fall through and treat as unhandled... */ |
| 523 | |
| 524 | default: |
| 525 | dev_dbg(scirdev_to_dev(sci_dev), |
| 526 | "%s: device: %p event code: %x: %s\n", |
| 527 | __func__, sci_dev, event_code, |
| 528 | (is_ready_state) |
| 529 | ? "unexpected event" |
| 530 | : "unexpected event in wrong state"); |
| 531 | status = SCI_FAILURE_INVALID_STATE; |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | return status; |
| 536 | } |
| 537 | /** |
| 538 | * |
| 539 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 540 | * struct scic_sds_remote_device. |
| 541 | * @event_code: The event code that the struct scic_sds_controller wants the device |
| 542 | * object to process. |
| 543 | * |
| 544 | * This method is the default event handler. It will call the RNC state |
| 545 | * machine handler for any RNC events otherwise it will log a warning and |
| 546 | * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE |
| 547 | */ |
| 548 | static enum sci_status scic_sds_remote_device_default_event_handler( |
| 549 | struct scic_sds_remote_device *sci_dev, |
| 550 | u32 event_code) |
| 551 | { |
| 552 | return scic_sds_remote_device_core_event_handler(sci_dev, |
| 553 | event_code, |
| 554 | false); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * |
| 559 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 560 | * struct scic_sds_remote_device. |
| 561 | * @frame_index: The frame index for which the struct scic_sds_controller wants this |
| 562 | * device object to process. |
| 563 | * |
| 564 | * This method is the default unsolicited frame handler. It logs a warning, |
| 565 | * releases the frame and returns a failure. enum sci_status |
| 566 | * SCI_FAILURE_INVALID_STATE |
| 567 | */ |
| 568 | enum sci_status scic_sds_remote_device_default_frame_handler( |
| 569 | struct scic_sds_remote_device *sci_dev, |
| 570 | u32 frame_index) |
| 571 | { |
| 572 | dev_warn(scirdev_to_dev(sci_dev), |
| 573 | "%s: SCIC Remote Device requested to handle frame %x " |
| 574 | "while in wrong state %d\n", |
| 575 | __func__, |
| 576 | frame_index, |
| 577 | sci_base_state_machine_get_state( |
| 578 | &sci_dev->state_machine)); |
| 579 | |
| 580 | /* Return the frame back to the controller */ |
| 581 | scic_sds_controller_release_frame( |
| 582 | scic_sds_remote_device_get_controller(sci_dev), frame_index |
| 583 | ); |
| 584 | |
| 585 | return SCI_FAILURE_INVALID_STATE; |
| 586 | } |
| 587 | |
| 588 | enum sci_status scic_sds_remote_device_default_start_request_handler( |
| 589 | struct scic_sds_remote_device *sci_dev, |
| 590 | struct scic_sds_request *request) |
| 591 | { |
| 592 | return default_device_handler(sci_dev, __func__); |
| 593 | } |
| 594 | |
| 595 | enum sci_status scic_sds_remote_device_default_complete_request_handler( |
| 596 | struct scic_sds_remote_device *sci_dev, |
| 597 | struct scic_sds_request *request) |
| 598 | { |
| 599 | return default_device_handler(sci_dev, __func__); |
| 600 | } |
| 601 | |
| 602 | enum sci_status scic_sds_remote_device_default_continue_request_handler( |
| 603 | struct scic_sds_remote_device *sci_dev, |
| 604 | struct scic_sds_request *request) |
| 605 | { |
| 606 | return default_device_handler(sci_dev, __func__); |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * |
| 611 | * @device: The struct scic_sds_remote_device which is then cast into a |
| 612 | * struct scic_sds_remote_device. |
| 613 | * @frame_index: The frame index for which the struct scic_sds_controller wants this |
| 614 | * device object to process. |
| 615 | * |
| 616 | * This method is a general ssp frame handler. In most cases the device object |
| 617 | * needs to route the unsolicited frame processing to the io request object. |
| 618 | * This method decodes the tag for the io request object and routes the |
| 619 | * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE |
| 620 | */ |
| 621 | enum sci_status scic_sds_remote_device_general_frame_handler( |
| 622 | struct scic_sds_remote_device *sci_dev, |
| 623 | u32 frame_index) |
| 624 | { |
| 625 | enum sci_status result; |
| 626 | struct sci_ssp_frame_header *frame_header; |
| 627 | struct scic_sds_request *io_request; |
| 628 | |
| 629 | result = scic_sds_unsolicited_frame_control_get_header( |
| 630 | &(scic_sds_remote_device_get_controller(sci_dev)->uf_control), |
| 631 | frame_index, |
| 632 | (void **)&frame_header |
| 633 | ); |
| 634 | |
| 635 | if (SCI_SUCCESS == result) { |
| 636 | io_request = scic_sds_controller_get_io_request_from_tag( |
| 637 | scic_sds_remote_device_get_controller(sci_dev), frame_header->tag); |
| 638 | |
| 639 | if ((io_request == NULL) |
| 640 | || (io_request->target_device != sci_dev)) { |
| 641 | /* |
| 642 | * We could not map this tag to a valid IO request |
| 643 | * Just toss the frame and continue */ |
| 644 | scic_sds_controller_release_frame( |
| 645 | scic_sds_remote_device_get_controller(sci_dev), frame_index |
| 646 | ); |
| 647 | } else { |
| 648 | /* The IO request is now in charge of releasing the frame */ |
| 649 | result = io_request->state_handlers->frame_handler( |
| 650 | io_request, frame_index); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | return result; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * |
| 659 | * @[in]: sci_dev This is the device object that is receiving the event. |
| 660 | * @[in]: event_code The event code to process. |
| 661 | * |
| 662 | * This is a common method for handling events reported to the remote device |
| 663 | * from the controller object. enum sci_status |
| 664 | */ |
| 665 | enum sci_status scic_sds_remote_device_general_event_handler( |
| 666 | struct scic_sds_remote_device *sci_dev, |
| 667 | u32 event_code) |
| 668 | { |
| 669 | return scic_sds_remote_device_core_event_handler(sci_dev, |
| 670 | event_code, |
| 671 | true); |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * ***************************************************************************** |
| 676 | * * STOPPED STATE HANDLERS |
| 677 | * ***************************************************************************** */ |
| 678 | |
| 679 | /** |
| 680 | * |
| 681 | * @device: |
| 682 | * |
| 683 | * This method takes the struct scic_sds_remote_device from a stopped state and |
| 684 | * attempts to start it. The RNC buffer for the device is constructed and the |
| 685 | * device state machine is transitioned to the |
| 686 | * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is |
| 687 | * an RNC buffer available to construct the remote device. |
| 688 | * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in |
| 689 | * which to construct the remote device. |
| 690 | */ |
| 691 | static enum sci_status scic_sds_remote_device_stopped_state_start_handler( |
| 692 | struct scic_sds_remote_device *sci_dev) |
| 693 | { |
| 694 | enum sci_status status; |
| 695 | |
| 696 | status = scic_sds_remote_node_context_resume(&sci_dev->rnc, |
| 697 | scic_sds_remote_device_resume_complete_handler, sci_dev); |
| 698 | |
| 699 | if (status == SCI_SUCCESS) |
| 700 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 701 | SCI_BASE_REMOTE_DEVICE_STATE_STARTING); |
| 702 | |
| 703 | return status; |
| 704 | } |
| 705 | |
| 706 | static enum sci_status scic_sds_remote_device_stopped_state_stop_handler( |
| 707 | struct scic_sds_remote_device *sci_dev) |
| 708 | { |
| 709 | return SCI_SUCCESS; |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * |
| 714 | * @sci_dev: The struct scic_sds_remote_device which is cast into a |
| 715 | * struct scic_sds_remote_device. |
| 716 | * |
| 717 | * This method will destruct a struct scic_sds_remote_device that is in a stopped |
| 718 | * state. This is the only state from which a destruct request will succeed. |
| 719 | * The RNi for this struct scic_sds_remote_device is returned to the free pool and the |
| 720 | * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL. |
| 721 | * enum sci_status SCI_SUCCESS |
| 722 | */ |
| 723 | static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler( |
| 724 | struct scic_sds_remote_device *sci_dev) |
| 725 | { |
| 726 | struct scic_sds_controller *scic; |
| 727 | |
| 728 | scic = scic_sds_remote_device_get_controller(sci_dev); |
| 729 | scic_sds_controller_free_remote_node_context(scic, sci_dev, |
| 730 | sci_dev->rnc.remote_node_index); |
| 731 | sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX; |
| 732 | |
| 733 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 734 | SCI_BASE_REMOTE_DEVICE_STATE_FINAL); |
| 735 | |
| 736 | return SCI_SUCCESS; |
| 737 | } |
| 738 | |
| 739 | /* |
| 740 | * ***************************************************************************** |
| 741 | * * STARTING STATE HANDLERS |
| 742 | * ***************************************************************************** */ |
| 743 | |
| 744 | static enum sci_status scic_sds_remote_device_starting_state_stop_handler( |
| 745 | struct scic_sds_remote_device *sci_dev) |
| 746 | { |
| 747 | /* |
| 748 | * This device has not yet started so there had better be no IO requests |
| 749 | */ |
| 750 | BUG_ON(sci_dev->started_request_count != 0); |
| 751 | |
| 752 | /* |
| 753 | * Destroy the remote node context |
| 754 | */ |
| 755 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 756 | scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev); |
| 757 | |
| 758 | /* |
| 759 | * Transition to the stopping state and wait for the remote node to |
| 760 | * complete being posted and invalidated. |
| 761 | */ |
| 762 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 763 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 764 | |
| 765 | return SCI_SUCCESS; |
| 766 | } |
| 767 | |
| 768 | enum sci_status scic_sds_remote_device_ready_state_stop_handler( |
| 769 | struct scic_sds_remote_device *sci_dev) |
| 770 | { |
| 771 | enum sci_status status = SCI_SUCCESS; |
| 772 | |
| 773 | /* Request the parent state machine to transition to the stopping state */ |
| 774 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 775 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); |
| 776 | |
| 777 | if (sci_dev->started_request_count == 0) { |
| 778 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 779 | scic_sds_cb_remote_device_rnc_destruct_complete, |
| 780 | sci_dev); |
| 781 | } else |
| 782 | status = scic_sds_remote_device_terminate_requests(sci_dev); |
| 783 | |
| 784 | return status; |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * |
| 789 | * @device: The struct scic_sds_remote_device object which is cast to a |
| 790 | * struct scic_sds_remote_device object. |
| 791 | * |
| 792 | * This is the ready state device reset handler enum sci_status |
| 793 | */ |
| 794 | enum sci_status scic_sds_remote_device_ready_state_reset_handler( |
| 795 | struct scic_sds_remote_device *sci_dev) |
| 796 | { |
| 797 | /* Request the parent state machine to transition to the stopping state */ |
| 798 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 799 | SCI_BASE_REMOTE_DEVICE_STATE_RESETTING); |
| 800 | |
| 801 | return SCI_SUCCESS; |
| 802 | } |
| 803 | |
| 804 | /* |
| 805 | * This method will attempt to start a task request for this device object. The |
| 806 | * remote device object will issue the start request for the task and if |
| 807 | * successful it will start the request for the port object then increment its |
| 808 | * own requet count. enum sci_status SCI_SUCCESS if the task request is started for |
| 809 | * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request |
| 810 | * object could not get the resources to start. |
| 811 | */ |
| 812 | static enum sci_status scic_sds_remote_device_ready_state_start_task_handler( |
| 813 | struct scic_sds_remote_device *sci_dev, |
| 814 | struct scic_sds_request *request) |
| 815 | { |
| 816 | enum sci_status result; |
| 817 | |
| 818 | /* See if the port is in a state where we can start the IO request */ |
| 819 | result = scic_sds_port_start_io( |
| 820 | scic_sds_remote_device_get_port(sci_dev), sci_dev, request); |
| 821 | |
| 822 | if (result == SCI_SUCCESS) { |
| 823 | result = scic_sds_remote_node_context_start_task(&sci_dev->rnc, |
| 824 | request); |
| 825 | if (result == SCI_SUCCESS) |
| 826 | result = scic_sds_request_start(request); |
| 827 | |
| 828 | scic_sds_remote_device_start_request(sci_dev, request, result); |
| 829 | } |
| 830 | |
| 831 | return result; |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | * This method will attempt to start an io request for this device object. The |
| 836 | * remote device object will issue the start request for the io and if |
| 837 | * successful it will start the request for the port object then increment its |
| 838 | * own requet count. enum sci_status SCI_SUCCESS if the io request is started for |
| 839 | * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request |
| 840 | * object could not get the resources to start. |
| 841 | */ |
| 842 | static enum sci_status scic_sds_remote_device_ready_state_start_io_handler( |
| 843 | struct scic_sds_remote_device *sci_dev, |
| 844 | struct scic_sds_request *request) |
| 845 | { |
| 846 | enum sci_status result; |
| 847 | |
| 848 | /* See if the port is in a state where we can start the IO request */ |
| 849 | result = scic_sds_port_start_io( |
| 850 | scic_sds_remote_device_get_port(sci_dev), sci_dev, request); |
| 851 | |
| 852 | if (result == SCI_SUCCESS) { |
| 853 | result = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request); |
| 854 | if (result == SCI_SUCCESS) |
| 855 | result = scic_sds_request_start(request); |
| 856 | |
| 857 | scic_sds_remote_device_start_request(sci_dev, request, result); |
| 858 | } |
| 859 | |
| 860 | return result; |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * This method will complete the request for the remote device object. The |
| 865 | * method will call the completion handler for the request object and if |
| 866 | * successful it will complete the request on the port object then decrement |
| 867 | * its own started_request_count. enum sci_status |
| 868 | */ |
| 869 | static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler( |
| 870 | struct scic_sds_remote_device *sci_dev, |
| 871 | struct scic_sds_request *request) |
| 872 | { |
| 873 | enum sci_status result; |
| 874 | |
| 875 | result = scic_sds_request_complete(request); |
| 876 | |
| 877 | if (result != SCI_SUCCESS) |
| 878 | return result; |
| 879 | |
| 880 | /* See if the port is in a state |
| 881 | * where we can start the IO request */ |
| 882 | result = scic_sds_port_complete_io( |
| 883 | scic_sds_remote_device_get_port(sci_dev), |
| 884 | sci_dev, request); |
| 885 | |
| 886 | if (result == SCI_SUCCESS) |
| 887 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 888 | |
| 889 | return result; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * ***************************************************************************** |
| 894 | * * STOPPING STATE HANDLERS |
| 895 | * ***************************************************************************** */ |
| 896 | |
| 897 | /** |
| 898 | * |
| 899 | * @sci_dev: The struct scic_sds_remote_device which is cast into a |
| 900 | * struct scic_sds_remote_device. |
| 901 | * |
| 902 | * This method will stop a struct scic_sds_remote_device that is already in the |
| 903 | * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error |
| 904 | * since we allow a stop request on a device that is alreay stopping or |
| 905 | * stopped. enum sci_status SCI_SUCCESS |
| 906 | */ |
| 907 | static enum sci_status scic_sds_remote_device_stopping_state_stop_handler( |
| 908 | struct scic_sds_remote_device *device) |
| 909 | { |
| 910 | /* |
| 911 | * All requests should have been terminated, but if there is an |
| 912 | * attempt to stop a device already in the stopping state, then |
| 913 | * try again to terminate. */ |
| 914 | return scic_sds_remote_device_terminate_requests(device); |
| 915 | } |
| 916 | |
| 917 | |
| 918 | /** |
| 919 | * |
| 920 | * @device: The device object for which the request is completing. |
| 921 | * @request: The task request that is being completed. |
| 922 | * |
| 923 | * This method completes requests for this struct scic_sds_remote_device while it is |
| 924 | * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the |
| 925 | * complete method for the request object and if that is successful the port |
| 926 | * object is called to complete the task request. Then the device object itself |
| 927 | * completes the task request. If struct scic_sds_remote_device started_request_count |
| 928 | * goes to 0 and the invalidate RNC request has completed the device object can |
| 929 | * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status |
| 930 | */ |
| 931 | static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler( |
| 932 | struct scic_sds_remote_device *sci_dev, |
| 933 | struct scic_sds_request *request) |
| 934 | { |
| 935 | enum sci_status status = SCI_SUCCESS; |
| 936 | |
| 937 | status = scic_sds_request_complete(request); |
| 938 | |
| 939 | if (status != SCI_SUCCESS) |
| 940 | return status; |
| 941 | |
| 942 | status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev), |
| 943 | sci_dev, request); |
| 944 | if (status != SCI_SUCCESS) |
| 945 | return status; |
| 946 | |
| 947 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 948 | |
| 949 | if (scic_sds_remote_device_get_request_count(sci_dev) == 0) |
| 950 | scic_sds_remote_node_context_destruct(&sci_dev->rnc, |
| 951 | scic_sds_cb_remote_device_rnc_destruct_complete, |
| 952 | sci_dev); |
| 953 | return SCI_SUCCESS; |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * |
| 958 | * @device: The struct scic_sds_remote_device which is to be cast into a |
| 959 | * struct scic_sds_remote_device object. |
| 960 | * |
| 961 | * This method will complete the reset operation when the device is in the |
| 962 | * resetting state. enum sci_status |
| 963 | */ |
| 964 | static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler( |
| 965 | struct scic_sds_remote_device *sci_dev) |
| 966 | { |
| 967 | |
| 968 | sci_base_state_machine_change_state( |
| 969 | &sci_dev->state_machine, |
| 970 | SCI_BASE_REMOTE_DEVICE_STATE_READY |
| 971 | ); |
| 972 | |
| 973 | return SCI_SUCCESS; |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * |
| 978 | * @device: The struct scic_sds_remote_device which is to be cast into a |
| 979 | * struct scic_sds_remote_device object. |
| 980 | * |
| 981 | * This method will stop the remote device while in the resetting state. |
| 982 | * enum sci_status |
| 983 | */ |
| 984 | static enum sci_status scic_sds_remote_device_resetting_state_stop_handler( |
| 985 | struct scic_sds_remote_device *sci_dev) |
| 986 | { |
| 987 | sci_base_state_machine_change_state( |
| 988 | &sci_dev->state_machine, |
| 989 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPING |
| 990 | ); |
| 991 | |
| 992 | return SCI_SUCCESS; |
| 993 | } |
| 994 | |
| 995 | /* |
| 996 | * This method completes requests for this struct scic_sds_remote_device while it is |
| 997 | * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the |
| 998 | * complete method for the request object and if that is successful the port |
| 999 | * object is called to complete the task request. Then the device object itself |
| 1000 | * completes the task request. enum sci_status |
| 1001 | */ |
| 1002 | static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler( |
| 1003 | struct scic_sds_remote_device *sci_dev, |
| 1004 | struct scic_sds_request *request) |
| 1005 | { |
| 1006 | enum sci_status status = SCI_SUCCESS; |
| 1007 | |
| 1008 | status = scic_sds_request_complete(request); |
| 1009 | |
| 1010 | if (status == SCI_SUCCESS) { |
| 1011 | status = scic_sds_port_complete_io( |
| 1012 | scic_sds_remote_device_get_port(sci_dev), |
| 1013 | sci_dev, request); |
| 1014 | |
| 1015 | if (status == SCI_SUCCESS) { |
| 1016 | scic_sds_remote_device_decrement_request_count(sci_dev); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | return status; |
| 1021 | } |
| 1022 | |
| 1023 | static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = { |
| 1024 | [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { |
| 1025 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1026 | .stop_handler = scic_sds_remote_device_default_stop_handler, |
| 1027 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1028 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1029 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1030 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1031 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1032 | .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1033 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1034 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1035 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1036 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1037 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1038 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1039 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1040 | }, |
| 1041 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { |
| 1042 | .start_handler = scic_sds_remote_device_stopped_state_start_handler, |
| 1043 | .stop_handler = scic_sds_remote_device_stopped_state_stop_handler, |
| 1044 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1045 | .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler, |
| 1046 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1047 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1048 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1049 | .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1050 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1051 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1052 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1053 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1054 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1055 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1056 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1057 | }, |
| 1058 | [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { |
| 1059 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1060 | .stop_handler = scic_sds_remote_device_starting_state_stop_handler, |
| 1061 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1062 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1063 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1064 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1065 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1066 | .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1067 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1068 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1069 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1070 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1071 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1072 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1073 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1074 | }, |
| 1075 | [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { |
| 1076 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1077 | .stop_handler = scic_sds_remote_device_ready_state_stop_handler, |
| 1078 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1079 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1080 | .reset_handler = scic_sds_remote_device_ready_state_reset_handler, |
| 1081 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1082 | .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler, |
| 1083 | .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler, |
| 1084 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1085 | .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler, |
| 1086 | .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler, |
| 1087 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1088 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1089 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1090 | .frame_handler = scic_sds_remote_device_general_frame_handler, |
| 1091 | }, |
| 1092 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { |
| 1093 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1094 | .stop_handler = scic_sds_remote_device_stopping_state_stop_handler, |
| 1095 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1096 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1097 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1098 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1099 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1100 | .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler, |
| 1101 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1102 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1103 | .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler, |
| 1104 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1105 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1106 | .event_handler = scic_sds_remote_device_general_event_handler, |
| 1107 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1108 | }, |
| 1109 | [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { |
| 1110 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1111 | .stop_handler = scic_sds_remote_device_default_stop_handler, |
| 1112 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1113 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1114 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1115 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1116 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1117 | .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1118 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1119 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1120 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1121 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1122 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1123 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1124 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1125 | }, |
| 1126 | [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { |
| 1127 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1128 | .stop_handler = scic_sds_remote_device_resetting_state_stop_handler, |
| 1129 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1130 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1131 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1132 | .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler, |
| 1133 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1134 | .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler, |
| 1135 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1136 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1137 | .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler, |
| 1138 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1139 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1140 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1141 | .frame_handler = scic_sds_remote_device_general_frame_handler |
| 1142 | }, |
| 1143 | [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { |
| 1144 | .start_handler = scic_sds_remote_device_default_start_handler, |
| 1145 | .stop_handler = scic_sds_remote_device_default_stop_handler, |
| 1146 | .fail_handler = scic_sds_remote_device_default_fail_handler, |
| 1147 | .destruct_handler = scic_sds_remote_device_default_destruct_handler, |
| 1148 | .reset_handler = scic_sds_remote_device_default_reset_handler, |
| 1149 | .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, |
| 1150 | .start_io_handler = scic_sds_remote_device_default_start_request_handler, |
| 1151 | .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1152 | .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, |
| 1153 | .start_task_handler = scic_sds_remote_device_default_start_request_handler, |
| 1154 | .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, |
| 1155 | .suspend_handler = scic_sds_remote_device_default_suspend_handler, |
| 1156 | .resume_handler = scic_sds_remote_device_default_resume_handler, |
| 1157 | .event_handler = scic_sds_remote_device_default_event_handler, |
| 1158 | .frame_handler = scic_sds_remote_device_default_frame_handler |
| 1159 | } |
| 1160 | }; |
| 1161 | |
| 1162 | static void scic_sds_remote_device_initial_state_enter( |
| 1163 | struct sci_base_object *object) |
| 1164 | { |
| 1165 | struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; |
| 1166 | |
| 1167 | sci_dev = container_of(object, typeof(*sci_dev), parent); |
| 1168 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1169 | SCI_BASE_REMOTE_DEVICE_STATE_INITIAL); |
| 1170 | |
| 1171 | /* Initial state is a transitional state to the stopped state */ |
| 1172 | sci_base_state_machine_change_state(&sci_dev->state_machine, |
| 1173 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * isci_remote_device_change_state() - This function gets the status of the |
| 1178 | * remote_device object. |
| 1179 | * @isci_device: This parameter points to the isci_remote_device object |
| 1180 | * |
| 1181 | * status of the object as a isci_status enum. |
| 1182 | */ |
| 1183 | void isci_remote_device_change_state( |
| 1184 | struct isci_remote_device *isci_device, |
| 1185 | enum isci_status status) |
| 1186 | { |
| 1187 | unsigned long flags; |
| 1188 | |
| 1189 | spin_lock_irqsave(&isci_device->state_lock, flags); |
| 1190 | isci_device->status = status; |
| 1191 | spin_unlock_irqrestore(&isci_device->state_lock, flags); |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * scic_remote_device_destruct() - free remote node context and destruct |
| 1196 | * @remote_device: This parameter specifies the remote device to be destructed. |
| 1197 | * |
| 1198 | * Remote device objects are a limited resource. As such, they must be |
| 1199 | * protected. Thus calls to construct and destruct are mutually exclusive and |
| 1200 | * non-reentrant. The return value shall indicate if the device was |
| 1201 | * successfully destructed or if some failure occurred. enum sci_status This value |
| 1202 | * is returned if the device is successfully destructed. |
| 1203 | * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied |
| 1204 | * device isn't valid (e.g. it's already been destoryed, the handle isn't |
| 1205 | * valid, etc.). |
| 1206 | */ |
| 1207 | static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev) |
| 1208 | { |
| 1209 | return sci_dev->state_handlers->destruct_handler(sci_dev); |
| 1210 | } |
| 1211 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1212 | /** |
| 1213 | * isci_remote_device_deconstruct() - This function frees an isci_remote_device. |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1214 | * @ihost: This parameter specifies the isci host object. |
| 1215 | * @idev: This parameter specifies the remote device to be freed. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1216 | * |
| 1217 | */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1218 | 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] | 1219 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1220 | dev_dbg(&ihost->pdev->dev, |
| 1221 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1222 | |
| 1223 | /* There should not be any outstanding io's. All paths to |
| 1224 | * here should go through isci_remote_device_nuke_requests. |
| 1225 | * If we hit this condition, we will need a way to complete |
| 1226 | * io requests in process */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1227 | while (!list_empty(&idev->reqs_in_process)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1228 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1229 | dev_err(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1230 | "%s: ** request list not empty! **\n", __func__); |
| 1231 | BUG(); |
| 1232 | } |
| 1233 | |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1234 | scic_remote_device_destruct(&idev->sci); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1235 | idev->domain_dev->lldd_dev = NULL; |
| 1236 | idev->domain_dev = NULL; |
| 1237 | idev->isci_port = NULL; |
| 1238 | list_del_init(&idev->node); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1239 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1240 | clear_bit(IDEV_START_PENDING, &idev->flags); |
| 1241 | clear_bit(IDEV_STOP_PENDING, &idev->flags); |
| 1242 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1245 | /** |
| 1246 | * isci_remote_device_stop_complete() - This function is called by the scic |
| 1247 | * when the remote device stop has completed. We mark the isci device as not |
| 1248 | * ready and remove the isci remote device. |
| 1249 | * @ihost: This parameter specifies the isci host object. |
| 1250 | * @idev: This parameter specifies the remote device. |
| 1251 | * @status: This parameter specifies status of the completion. |
| 1252 | * |
| 1253 | */ |
| 1254 | static void isci_remote_device_stop_complete(struct isci_host *ihost, |
| 1255 | struct isci_remote_device *idev) |
| 1256 | { |
| 1257 | dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev); |
| 1258 | |
| 1259 | isci_remote_device_change_state(idev, isci_stopped); |
| 1260 | |
| 1261 | /* after stop, we can tear down resources. */ |
| 1262 | isci_remote_device_deconstruct(ihost, idev); |
| 1263 | } |
| 1264 | |
| 1265 | static void scic_sds_remote_device_stopped_state_enter( |
| 1266 | struct sci_base_object *object) |
| 1267 | { |
| 1268 | struct scic_sds_remote_device *sci_dev; |
| 1269 | struct scic_sds_controller *scic; |
| 1270 | struct isci_remote_device *idev; |
| 1271 | struct isci_host *ihost; |
| 1272 | u32 prev_state; |
| 1273 | |
| 1274 | sci_dev = container_of(object, typeof(*sci_dev), parent); |
| 1275 | scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1276 | ihost = sci_object_get_association(scic); |
| 1277 | idev = sci_object_get_association(sci_dev); |
| 1278 | |
| 1279 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1280 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); |
| 1281 | |
| 1282 | /* If we are entering from the stopping state let the SCI User know that |
| 1283 | * the stop operation has completed. |
| 1284 | */ |
| 1285 | prev_state = sci_dev->state_machine.previous_state_id; |
| 1286 | if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING) |
| 1287 | isci_remote_device_stop_complete(ihost, idev); |
| 1288 | |
| 1289 | scic_sds_controller_remote_device_stopped(scic, sci_dev); |
| 1290 | } |
| 1291 | |
| 1292 | static void scic_sds_remote_device_starting_state_enter(struct sci_base_object *object) |
| 1293 | { |
| 1294 | struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev), |
| 1295 | parent); |
| 1296 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1297 | struct isci_host *ihost = sci_object_get_association(scic); |
| 1298 | struct isci_remote_device *idev = sci_object_get_association(sci_dev); |
| 1299 | |
| 1300 | SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, |
| 1301 | SCI_BASE_REMOTE_DEVICE_STATE_STARTING); |
| 1302 | |
| 1303 | isci_remote_device_not_ready(ihost, idev, |
| 1304 | SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED); |
| 1305 | } |
| 1306 | |
| 1307 | static void scic_sds_remote_device_ready_state_enter(struct sci_base_object *object) |
| 1308 | { |
| 1309 | struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev), |
| 1310 | parent); |
| 1311 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1312 | struct isci_host *ihost = sci_object_get_association(scic); |
| 1313 | struct isci_remote_device *idev = sci_object_get_association(sci_dev); |
| 1314 | |
| 1315 | SET_STATE_HANDLER(sci_dev, |
| 1316 | scic_sds_remote_device_state_handler_table, |
| 1317 | SCI_BASE_REMOTE_DEVICE_STATE_READY); |
| 1318 | |
| 1319 | scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++; |
| 1320 | |
| 1321 | if (sci_dev->has_ready_substate_machine) |
| 1322 | sci_base_state_machine_start(&sci_dev->ready_substate_machine); |
| 1323 | else |
| 1324 | isci_remote_device_ready(ihost, idev); |
| 1325 | } |
| 1326 | |
| 1327 | static void scic_sds_remote_device_ready_state_exit( |
| 1328 | struct sci_base_object *object) |
| 1329 | { |
| 1330 | struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev), |
| 1331 | parent); |
| 1332 | if (sci_dev->has_ready_substate_machine) |
| 1333 | sci_base_state_machine_stop(&sci_dev->ready_substate_machine); |
| 1334 | else { |
| 1335 | struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); |
| 1336 | struct isci_host *ihost = sci_object_get_association(scic); |
| 1337 | struct isci_remote_device *idev = sci_object_get_association(sci_dev); |
| 1338 | |
| 1339 | isci_remote_device_not_ready(ihost, idev, |
| 1340 | SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | static void scic_sds_remote_device_stopping_state_enter( |
| 1345 | struct sci_base_object *object) |
| 1346 | { |
| 1347 | struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; |
| 1348 | |
| 1349 | SET_STATE_HANDLER( |
| 1350 | sci_dev, |
| 1351 | scic_sds_remote_device_state_handler_table, |
| 1352 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPING |
| 1353 | ); |
| 1354 | } |
| 1355 | |
| 1356 | static void scic_sds_remote_device_failed_state_enter( |
| 1357 | struct sci_base_object *object) |
| 1358 | { |
| 1359 | struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; |
| 1360 | |
| 1361 | SET_STATE_HANDLER( |
| 1362 | sci_dev, |
| 1363 | scic_sds_remote_device_state_handler_table, |
| 1364 | SCI_BASE_REMOTE_DEVICE_STATE_FAILED |
| 1365 | ); |
| 1366 | } |
| 1367 | |
| 1368 | static void scic_sds_remote_device_resetting_state_enter( |
| 1369 | struct sci_base_object *object) |
| 1370 | { |
| 1371 | struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; |
| 1372 | |
| 1373 | SET_STATE_HANDLER( |
| 1374 | sci_dev, |
| 1375 | scic_sds_remote_device_state_handler_table, |
| 1376 | SCI_BASE_REMOTE_DEVICE_STATE_RESETTING |
| 1377 | ); |
| 1378 | |
| 1379 | scic_sds_remote_node_context_suspend( |
| 1380 | &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL); |
| 1381 | } |
| 1382 | |
| 1383 | static void scic_sds_remote_device_resetting_state_exit( |
| 1384 | struct sci_base_object *object) |
| 1385 | { |
| 1386 | struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; |
| 1387 | |
| 1388 | scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL); |
| 1389 | } |
| 1390 | |
| 1391 | static void scic_sds_remote_device_final_state_enter( |
| 1392 | struct sci_base_object *object) |
| 1393 | { |
| 1394 | struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; |
| 1395 | |
| 1396 | SET_STATE_HANDLER( |
| 1397 | sci_dev, |
| 1398 | scic_sds_remote_device_state_handler_table, |
| 1399 | SCI_BASE_REMOTE_DEVICE_STATE_FINAL |
| 1400 | ); |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | static const struct sci_base_state scic_sds_remote_device_state_table[] = { |
| 1405 | [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { |
| 1406 | .enter_state = scic_sds_remote_device_initial_state_enter, |
| 1407 | }, |
| 1408 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { |
| 1409 | .enter_state = scic_sds_remote_device_stopped_state_enter, |
| 1410 | }, |
| 1411 | [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { |
| 1412 | .enter_state = scic_sds_remote_device_starting_state_enter, |
| 1413 | }, |
| 1414 | [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { |
| 1415 | .enter_state = scic_sds_remote_device_ready_state_enter, |
| 1416 | .exit_state = scic_sds_remote_device_ready_state_exit |
| 1417 | }, |
| 1418 | [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { |
| 1419 | .enter_state = scic_sds_remote_device_stopping_state_enter, |
| 1420 | }, |
| 1421 | [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { |
| 1422 | .enter_state = scic_sds_remote_device_failed_state_enter, |
| 1423 | }, |
| 1424 | [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { |
| 1425 | .enter_state = scic_sds_remote_device_resetting_state_enter, |
| 1426 | .exit_state = scic_sds_remote_device_resetting_state_exit |
| 1427 | }, |
| 1428 | [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { |
| 1429 | .enter_state = scic_sds_remote_device_final_state_enter, |
| 1430 | }, |
| 1431 | }; |
| 1432 | |
| 1433 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1434 | * scic_remote_device_construct() - common construction |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1435 | * @sci_port: SAS/SATA port through which this device is accessed. |
| 1436 | * @sci_dev: remote device to construct |
| 1437 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1438 | * This routine just performs benign initialization and does not |
| 1439 | * allocate the remote_node_context which is left to |
| 1440 | * scic_remote_device_[de]a_construct(). scic_remote_device_destruct() |
| 1441 | * frees the remote_node_context(s) for the device. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1442 | */ |
| 1443 | static void scic_remote_device_construct(struct scic_sds_port *sci_port, |
| 1444 | struct scic_sds_remote_device *sci_dev) |
| 1445 | { |
| 1446 | sci_dev->owning_port = sci_port; |
| 1447 | sci_dev->started_request_count = 0; |
| 1448 | sci_dev->parent.private = NULL; |
| 1449 | |
| 1450 | sci_base_state_machine_construct( |
| 1451 | &sci_dev->state_machine, |
| 1452 | &sci_dev->parent, |
| 1453 | scic_sds_remote_device_state_table, |
| 1454 | SCI_BASE_REMOTE_DEVICE_STATE_INITIAL |
| 1455 | ); |
| 1456 | |
| 1457 | sci_base_state_machine_start( |
| 1458 | &sci_dev->state_machine |
| 1459 | ); |
| 1460 | |
| 1461 | scic_sds_remote_node_context_construct(&sci_dev->rnc, |
| 1462 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); |
| 1463 | |
| 1464 | sci_object_set_association(&sci_dev->rnc, sci_dev); |
| 1465 | } |
| 1466 | |
| 1467 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1468 | * scic_remote_device_da_construct() - construct direct attached device. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1469 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1470 | * The information (e.g. IAF, Signature FIS, etc.) necessary to build |
| 1471 | * the device is known to the SCI Core since it is contained in the |
| 1472 | * scic_phy object. Remote node context(s) is/are a global resource |
| 1473 | * allocated by this routine, freed by scic_remote_device_destruct(). |
| 1474 | * |
| 1475 | * Returns: |
| 1476 | * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed. |
| 1477 | * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to |
| 1478 | * sata-only controller instance. |
| 1479 | * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1480 | */ |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1481 | static enum sci_status scic_remote_device_da_construct(struct scic_sds_port *sci_port, |
| 1482 | struct scic_sds_remote_device *sci_dev) |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1483 | { |
| 1484 | enum sci_status status; |
| 1485 | u16 remote_node_index; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1486 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1487 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1488 | scic_remote_device_construct(sci_port, sci_dev); |
| 1489 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1490 | /* |
| 1491 | * This information is request to determine how many remote node context |
| 1492 | * entries will be needed to store the remote node. |
| 1493 | */ |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1494 | sci_dev->is_direct_attached = true; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1495 | status = scic_sds_controller_allocate_remote_node_context(sci_port->owning_controller, |
| 1496 | sci_dev, |
| 1497 | &remote_node_index); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1498 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1499 | if (status != SCI_SUCCESS) |
| 1500 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1501 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1502 | sci_dev->rnc.remote_node_index = remote_node_index; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1503 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1504 | scic_sds_port_get_attached_sas_address(sci_port, &sci_dev->device_address); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1505 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1506 | if (dev->dev_type == SAS_END_DEV) |
| 1507 | sci_dev->has_ready_substate_machine = false; |
| 1508 | else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { |
| 1509 | sci_dev->has_ready_substate_machine = true; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1510 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1511 | sci_base_state_machine_construct( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1512 | &sci_dev->ready_substate_machine, |
| 1513 | &sci_dev->parent, |
| 1514 | scic_sds_stp_remote_device_ready_substate_table, |
| 1515 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1516 | } else if (dev_is_expander(dev)) { |
| 1517 | sci_dev->has_ready_substate_machine = true; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1518 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1519 | /* add the SMP ready substate machine construction here */ |
| 1520 | sci_base_state_machine_construct( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1521 | &sci_dev->ready_substate_machine, |
| 1522 | &sci_dev->parent, |
| 1523 | scic_sds_smp_remote_device_ready_substate_table, |
| 1524 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1525 | } else |
| 1526 | return SCI_FAILURE_UNSUPPORTED_PROTOCOL; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1527 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1528 | sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(sci_port); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1529 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1530 | /* / @todo Should I assign the port width by reading all of the phys on the port? */ |
| 1531 | sci_dev->device_port_width = 1; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1532 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1533 | return SCI_SUCCESS; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | static void scic_sds_remote_device_get_info_from_smp_discover_response( |
| 1537 | struct scic_sds_remote_device *sci_dev, |
| 1538 | struct smp_response_discover *discover_response) |
| 1539 | { |
| 1540 | /* decode discover_response to set sas_address to sci_dev. */ |
| 1541 | sci_dev->device_address.high = |
| 1542 | discover_response->attached_sas_address.high; |
| 1543 | |
| 1544 | sci_dev->device_address.low = |
| 1545 | discover_response->attached_sas_address.low; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /** |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1549 | * scic_remote_device_ea_construct() - construct expander attached device |
| 1550 | * @discover_response: data to build remote device |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1551 | * |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1552 | * Remote node context(s) is/are a global resource allocated by this |
| 1553 | * routine, freed by scic_remote_device_destruct(). |
| 1554 | * |
| 1555 | * Returns: |
| 1556 | * SCI_FAILURE_DEVICE_EXISTS - device has already been constructed. |
| 1557 | * SCI_FAILURE_UNSUPPORTED_PROTOCOL - e.g. sas device attached to |
| 1558 | * sata-only controller instance. |
| 1559 | * SCI_FAILURE_INSUFFICIENT_RESOURCES - remote node contexts exhausted. |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1560 | */ |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1561 | static enum sci_status scic_remote_device_ea_construct(struct scic_sds_port *sci_port, |
| 1562 | struct scic_sds_remote_device *sci_dev, |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1563 | struct smp_response_discover *discover_response) |
| 1564 | { |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1565 | struct scic_sds_controller *scic = sci_port->owning_controller; |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1566 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1567 | enum sci_status status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1568 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1569 | scic_remote_device_construct(sci_port, sci_dev); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1570 | |
| 1571 | scic_sds_remote_device_get_info_from_smp_discover_response( |
| 1572 | sci_dev, discover_response); |
| 1573 | |
| 1574 | status = scic_sds_controller_allocate_remote_node_context( |
| 1575 | scic, sci_dev, &sci_dev->rnc.remote_node_index); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1576 | if (status != SCI_SUCCESS) |
| 1577 | return status; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1578 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1579 | if (dev->dev_type == SAS_END_DEV) |
| 1580 | sci_dev->has_ready_substate_machine = false; |
| 1581 | else if (dev_is_expander(dev)) { |
| 1582 | sci_dev->has_ready_substate_machine = true; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1583 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1584 | /* add the SMP ready substate machine construction here */ |
| 1585 | sci_base_state_machine_construct( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1586 | &sci_dev->ready_substate_machine, |
| 1587 | &sci_dev->parent, |
| 1588 | scic_sds_smp_remote_device_ready_substate_table, |
| 1589 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1590 | } else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) { |
| 1591 | sci_dev->has_ready_substate_machine = true; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1592 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1593 | sci_base_state_machine_construct( |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1594 | &sci_dev->ready_substate_machine, |
| 1595 | &sci_dev->parent, |
| 1596 | scic_sds_stp_remote_device_ready_substate_table, |
| 1597 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1598 | } |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1599 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1600 | /* |
| 1601 | * For SAS-2 the physical link rate is actually a logical link |
| 1602 | * rate that incorporates multiplexing. The SCU doesn't |
| 1603 | * incorporate multiplexing and for the purposes of the |
| 1604 | * connection the logical link rate is that same as the |
| 1605 | * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay |
| 1606 | * one another, so this code works for both situations. */ |
| 1607 | sci_dev->connection_rate = min_t(u16, scic_sds_port_get_max_allowed_speed(sci_port), |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1608 | discover_response->u2.sas1_1.negotiated_physical_link_rate); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1609 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1610 | /* / @todo Should I assign the port width by reading all of the phys on the port? */ |
| 1611 | sci_dev->device_port_width = 1; |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 1612 | |
| 1613 | return status; |
| 1614 | } |
| 1615 | |
| 1616 | /** |
| 1617 | * scic_remote_device_start() - This method will start the supplied remote |
| 1618 | * device. This method enables normal IO requests to flow through to the |
| 1619 | * remote device. |
| 1620 | * @remote_device: This parameter specifies the device to be started. |
| 1621 | * @timeout: This parameter specifies the number of milliseconds in which the |
| 1622 | * start operation should complete. |
| 1623 | * |
| 1624 | * An indication of whether the device was successfully started. SCI_SUCCESS |
| 1625 | * This value is returned if the device was successfully started. |
| 1626 | * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start |
| 1627 | * the device when there have been no phys added to it. |
| 1628 | */ |
| 1629 | static enum sci_status scic_remote_device_start(struct scic_sds_remote_device *sci_dev, |
| 1630 | u32 timeout) |
| 1631 | { |
| 1632 | return sci_dev->state_handlers->start_handler(sci_dev); |
| 1633 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1634 | |
| 1635 | /** |
| 1636 | * isci_remote_device_construct() - This function calls the scic remote device |
| 1637 | * construct and start functions, it waits on the remote device start |
| 1638 | * completion. |
| 1639 | * @port: This parameter specifies the isci port with the remote device. |
| 1640 | * @isci_device: This parameter specifies the isci remote device |
| 1641 | * |
| 1642 | * status from the scic calls, the caller to this function should clean up |
| 1643 | * resources as appropriate. |
| 1644 | */ |
| 1645 | static enum sci_status isci_remote_device_construct( |
| 1646 | struct isci_port *port, |
| 1647 | struct isci_remote_device *isci_device) |
| 1648 | { |
| 1649 | enum sci_status status = SCI_SUCCESS; |
| 1650 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1651 | if (isci_device->domain_dev->parent && |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 1652 | dev_is_expander(isci_device->domain_dev->parent)) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1653 | int i; |
| 1654 | |
| 1655 | /* struct smp_response_discover discover_response; */ |
| 1656 | struct discover_resp discover_response; |
| 1657 | struct domain_device *parent = |
| 1658 | isci_device->domain_dev->parent; |
| 1659 | |
| 1660 | struct expander_device *parent_ex = &parent->ex_dev; |
| 1661 | |
| 1662 | for (i = 0; i < parent_ex->num_phys; i++) { |
| 1663 | |
| 1664 | struct ex_phy *phy = &parent_ex->ex_phy[i]; |
| 1665 | |
| 1666 | if ((phy->phy_state == PHY_VACANT) || |
| 1667 | (phy->phy_state == PHY_NOT_PRESENT)) |
| 1668 | continue; |
| 1669 | |
| 1670 | if (SAS_ADDR(phy->attached_sas_addr) |
| 1671 | == SAS_ADDR(isci_device->domain_dev->sas_addr)) { |
| 1672 | |
| 1673 | discover_response.attached_dev_type |
| 1674 | = phy->attached_dev_type; |
| 1675 | discover_response.linkrate |
| 1676 | = phy->linkrate; |
| 1677 | discover_response.attached_sata_host |
| 1678 | = phy->attached_sata_host; |
| 1679 | discover_response.attached_sata_dev |
| 1680 | = phy->attached_sata_dev; |
| 1681 | discover_response.attached_sata_ps |
| 1682 | = phy->attached_sata_ps; |
| 1683 | discover_response.iproto |
| 1684 | = phy->attached_iproto >> 1; |
| 1685 | discover_response.tproto |
| 1686 | = phy->attached_tproto >> 1; |
| 1687 | memcpy( |
| 1688 | discover_response.attached_sas_addr, |
| 1689 | phy->attached_sas_addr, |
| 1690 | SAS_ADDR_SIZE |
| 1691 | ); |
| 1692 | discover_response.attached_phy_id |
| 1693 | = phy->attached_phy_id; |
| 1694 | discover_response.change_count |
| 1695 | = phy->phy_change_count; |
| 1696 | discover_response.routing_attr |
| 1697 | = phy->routing_attr; |
| 1698 | discover_response.hmin_linkrate |
| 1699 | = phy->phy->minimum_linkrate_hw; |
| 1700 | discover_response.hmax_linkrate |
| 1701 | = phy->phy->maximum_linkrate_hw; |
| 1702 | discover_response.pmin_linkrate |
| 1703 | = phy->phy->minimum_linkrate; |
| 1704 | discover_response.pmax_linkrate |
| 1705 | = phy->phy->maximum_linkrate; |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | dev_dbg(&port->isci_host->pdev->dev, |
| 1711 | "%s: parent->dev_type = EDGE_DEV\n", |
| 1712 | __func__); |
| 1713 | |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1714 | status = scic_remote_device_ea_construct(port->sci_port_handle, |
| 1715 | &isci_device->sci, |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 1716 | (struct smp_response_discover *)&discover_response); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1717 | |
| 1718 | } else |
Dan Williams | b87ee30 | 2011-04-25 11:48:29 -0700 | [diff] [blame] | 1719 | status = scic_remote_device_da_construct(port->sci_port_handle, |
| 1720 | &isci_device->sci); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1721 | |
| 1722 | |
| 1723 | if (status != SCI_SUCCESS) { |
| 1724 | dev_dbg(&port->isci_host->pdev->dev, |
| 1725 | "%s: scic_remote_device_da_construct failed - " |
| 1726 | "isci_device = %p\n", |
| 1727 | __func__, |
| 1728 | isci_device); |
| 1729 | |
| 1730 | return status; |
| 1731 | } |
| 1732 | |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1733 | /* XXX will be killed with sci_base_object removal */ |
| 1734 | sci_object_set_association(&isci_device->sci, isci_device); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1735 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1736 | /* start the device. */ |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1737 | status = scic_remote_device_start(&isci_device->sci, |
Dan Williams | 3a97eec | 2011-03-04 11:51:43 -0800 | [diff] [blame] | 1738 | ISCI_REMOTE_DEVICE_START_TIMEOUT); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1739 | |
| 1740 | if (status != SCI_SUCCESS) { |
| 1741 | dev_warn(&port->isci_host->pdev->dev, |
| 1742 | "%s: scic_remote_device_start failed\n", |
| 1743 | __func__); |
| 1744 | return status; |
| 1745 | } |
| 1746 | |
| 1747 | return status; |
| 1748 | } |
| 1749 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1750 | 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] | 1751 | { |
| 1752 | DECLARE_COMPLETION_ONSTACK(aborted_task_completion); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1753 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1754 | dev_dbg(&ihost->pdev->dev, |
| 1755 | "%s: idev = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1756 | |
| 1757 | /* Cleanup all requests pending for this device. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1758 | isci_terminate_pending_requests(ihost, idev, terminating); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1759 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1760 | dev_dbg(&ihost->pdev->dev, |
| 1761 | "%s: idev = %p, done\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1764 | /** |
| 1765 | * This function builds the isci_remote_device when a libsas dev_found message |
| 1766 | * is received. |
| 1767 | * @isci_host: This parameter specifies the isci host object. |
| 1768 | * @port: This parameter specifies the isci_port conected to this device. |
| 1769 | * |
| 1770 | * pointer to new isci_remote_device. |
| 1771 | */ |
| 1772 | static struct isci_remote_device * |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1773 | isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1774 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1775 | struct isci_remote_device *idev; |
| 1776 | int i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1777 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1778 | for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1779 | idev = &ihost->devices[i]; |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1780 | if (!test_and_set_bit(IDEV_ALLOCATED, &idev->flags)) |
| 1781 | break; |
| 1782 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1783 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1784 | if (i >= SCI_MAX_REMOTE_DEVICES) { |
| 1785 | dev_warn(&ihost->pdev->dev, "%s: failed\n", __func__); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1786 | return NULL; |
| 1787 | } |
| 1788 | |
Bartosz Barcinski | 6cb4d6b | 2011-04-12 17:28:43 -0700 | [diff] [blame] | 1789 | if (WARN_ONCE(!list_empty(&idev->reqs_in_process), "found requests in process\n")) |
| 1790 | return NULL; |
| 1791 | |
| 1792 | if (WARN_ONCE(!list_empty(&idev->node), "found non-idle remote device\n")) |
| 1793 | return NULL; |
| 1794 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1795 | isci_remote_device_change_state(idev, isci_freed); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1796 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1797 | return idev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1798 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1799 | |
| 1800 | /** |
| 1801 | * isci_remote_device_ready() - This function is called by the scic when the |
| 1802 | * remote device is ready. We mark the isci device as ready and signal the |
| 1803 | * waiting proccess. |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 1804 | * @ihost: our valid isci_host |
| 1805 | * @idev: remote device |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1806 | * |
| 1807 | */ |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 1808 | 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] | 1809 | { |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1810 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1811 | "%s: idev = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1812 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1813 | isci_remote_device_change_state(idev, isci_ready_for_io); |
| 1814 | if (test_and_clear_bit(IDEV_START_PENDING, &idev->flags)) |
| 1815 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | /** |
| 1819 | * isci_remote_device_not_ready() - This function is called by the scic when |
| 1820 | * the remote device is not ready. We mark the isci device as ready (not |
| 1821 | * "ready_for_io") and signal the waiting proccess. |
| 1822 | * @isci_host: This parameter specifies the isci host object. |
| 1823 | * @isci_device: This parameter specifies the remote device |
| 1824 | * |
| 1825 | */ |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 1826 | void isci_remote_device_not_ready(struct isci_host *ihost, |
| 1827 | struct isci_remote_device *idev, u32 reason) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1828 | { |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 1829 | dev_dbg(&ihost->pdev->dev, |
| 1830 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1831 | |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 1832 | if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED) |
| 1833 | isci_remote_device_change_state(idev, isci_stopping); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1834 | else |
| 1835 | /* device ready is actually a "not ready for io" state. */ |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 1836 | isci_remote_device_change_state(idev, isci_ready); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1840 | * isci_remote_device_stop() - This function is called internally to stop the |
| 1841 | * remote device. |
| 1842 | * @isci_host: This parameter specifies the isci host object. |
| 1843 | * @isci_device: This parameter specifies the remote device. |
| 1844 | * |
| 1845 | * The status of the scic request to stop. |
| 1846 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1847 | 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] | 1848 | { |
| 1849 | enum sci_status status; |
| 1850 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1851 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1852 | dev_dbg(&ihost->pdev->dev, |
| 1853 | "%s: isci_device = %p\n", __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1854 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1855 | isci_remote_device_change_state(idev, isci_stopping); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 1856 | |
| 1857 | /* Kill all outstanding requests. */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1858 | isci_remote_device_nuke_requests(ihost, idev); |
Jeff Skirvin | 6e2802a | 2011-03-08 20:32:16 -0700 | [diff] [blame] | 1859 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1860 | set_bit(IDEV_STOP_PENDING, &idev->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1861 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1862 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 1863 | status = scic_remote_device_stop(&idev->sci, 50); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1864 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1865 | |
| 1866 | /* Wait for the stop complete callback. */ |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1867 | if (status == SCI_SUCCESS) { |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1868 | wait_for_device_stop(ihost, idev); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1869 | clear_bit(IDEV_ALLOCATED, &idev->flags); |
| 1870 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1871 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1872 | dev_dbg(&ihost->pdev->dev, |
| 1873 | "%s: idev = %p - after completion wait\n", |
| 1874 | __func__, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1875 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1876 | return status; |
| 1877 | } |
| 1878 | |
| 1879 | /** |
| 1880 | * isci_remote_device_gone() - This function is called by libsas when a domain |
| 1881 | * device is removed. |
| 1882 | * @domain_device: This parameter specifies the libsas domain device. |
| 1883 | * |
| 1884 | */ |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1885 | void isci_remote_device_gone(struct domain_device *dev) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1886 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1887 | struct isci_host *ihost = dev_to_ihost(dev); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1888 | struct isci_remote_device *idev = dev->lldd_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1889 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1890 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1891 | "%s: domain_device = %p, isci_device = %p, isci_port = %p\n", |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1892 | __func__, dev, idev, idev->isci_port); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1893 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1894 | isci_remote_device_stop(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | |
| 1898 | /** |
| 1899 | * isci_remote_device_found() - This function is called by libsas when a remote |
| 1900 | * device is discovered. A remote device object is created and started. the |
| 1901 | * function then sleeps until the sci core device started message is |
| 1902 | * received. |
| 1903 | * @domain_device: This parameter specifies the libsas domain device. |
| 1904 | * |
| 1905 | * status, zero indicates success. |
| 1906 | */ |
| 1907 | int isci_remote_device_found(struct domain_device *domain_dev) |
| 1908 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1909 | struct isci_host *isci_host = dev_to_ihost(domain_dev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1910 | struct isci_port *isci_port; |
| 1911 | struct isci_phy *isci_phy; |
| 1912 | struct asd_sas_port *sas_port; |
| 1913 | struct asd_sas_phy *sas_phy; |
| 1914 | struct isci_remote_device *isci_device; |
| 1915 | enum sci_status status; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1916 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1917 | dev_dbg(&isci_host->pdev->dev, |
| 1918 | "%s: domain_device = %p\n", __func__, domain_dev); |
| 1919 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1920 | wait_for_start(isci_host); |
| 1921 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1922 | sas_port = domain_dev->port; |
| 1923 | sas_phy = list_first_entry(&sas_port->phy_list, struct asd_sas_phy, |
| 1924 | port_phy_el); |
| 1925 | isci_phy = to_isci_phy(sas_phy); |
| 1926 | isci_port = isci_phy->isci_port; |
| 1927 | |
| 1928 | /* we are being called for a device on this port, |
| 1929 | * so it has to come up eventually |
| 1930 | */ |
| 1931 | wait_for_completion(&isci_port->start_complete); |
| 1932 | |
| 1933 | if ((isci_stopping == isci_port_get_state(isci_port)) || |
| 1934 | (isci_stopped == isci_port_get_state(isci_port))) |
| 1935 | return -ENODEV; |
| 1936 | |
| 1937 | isci_device = isci_remote_device_alloc(isci_host, isci_port); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 1938 | if (!isci_device) |
| 1939 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1940 | |
| 1941 | INIT_LIST_HEAD(&isci_device->node); |
| 1942 | domain_dev->lldd_dev = isci_device; |
| 1943 | isci_device->domain_dev = domain_dev; |
| 1944 | isci_device->isci_port = isci_port; |
| 1945 | isci_remote_device_change_state(isci_device, isci_starting); |
| 1946 | |
| 1947 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1948 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1949 | list_add_tail(&isci_device->node, &isci_port->remote_dev_list); |
| 1950 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1951 | set_bit(IDEV_START_PENDING, &isci_device->flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1952 | status = isci_remote_device_construct(isci_port, isci_device); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1953 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1954 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1955 | dev_dbg(&isci_host->pdev->dev, |
| 1956 | "%s: isci_device = %p\n", |
| 1957 | __func__, isci_device); |
| 1958 | |
| 1959 | if (status != SCI_SUCCESS) { |
| 1960 | |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1961 | spin_lock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1962 | isci_remote_device_deconstruct( |
| 1963 | isci_host, |
| 1964 | isci_device |
| 1965 | ); |
Dan Williams | 1a38045 | 2011-03-03 18:01:43 -0800 | [diff] [blame] | 1966 | spin_unlock_irq(&isci_host->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1967 | return -ENODEV; |
| 1968 | } |
| 1969 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 1970 | /* wait for the device ready callback. */ |
| 1971 | wait_for_device_start(isci_host, isci_device); |
| 1972 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1973 | return 0; |
| 1974 | } |
| 1975 | /** |
| 1976 | * isci_device_is_reset_pending() - This function will check if there is any |
| 1977 | * pending reset condition on the device. |
| 1978 | * @request: This parameter is the isci_device object. |
| 1979 | * |
| 1980 | * true if there is a reset pending for the device. |
| 1981 | */ |
| 1982 | bool isci_device_is_reset_pending( |
| 1983 | struct isci_host *isci_host, |
| 1984 | struct isci_remote_device *isci_device) |
| 1985 | { |
| 1986 | struct isci_request *isci_request; |
| 1987 | struct isci_request *tmp_req; |
| 1988 | bool reset_is_pending = false; |
| 1989 | unsigned long flags; |
| 1990 | |
| 1991 | dev_dbg(&isci_host->pdev->dev, |
| 1992 | "%s: isci_device = %p\n", __func__, isci_device); |
| 1993 | |
| 1994 | spin_lock_irqsave(&isci_host->scic_lock, flags); |
| 1995 | |
| 1996 | /* Check for reset on all pending requests. */ |
| 1997 | list_for_each_entry_safe(isci_request, tmp_req, |
| 1998 | &isci_device->reqs_in_process, dev_node) { |
| 1999 | dev_dbg(&isci_host->pdev->dev, |
| 2000 | "%s: isci_device = %p request = %p\n", |
| 2001 | __func__, isci_device, isci_request); |
| 2002 | |
| 2003 | if (isci_request->ttype == io_task) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2004 | struct sas_task *task = isci_request_access_task( |
| 2005 | isci_request); |
| 2006 | |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 2007 | spin_lock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2008 | if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) |
| 2009 | reset_is_pending = true; |
Bartosz Barcinski | 467e855 | 2011-04-12 17:28:41 -0700 | [diff] [blame] | 2010 | spin_unlock(&task->task_state_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | spin_unlock_irqrestore(&isci_host->scic_lock, flags); |
| 2015 | |
| 2016 | dev_dbg(&isci_host->pdev->dev, |
| 2017 | "%s: isci_device = %p reset_is_pending = %d\n", |
| 2018 | __func__, isci_device, reset_is_pending); |
| 2019 | |
| 2020 | return reset_is_pending; |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * isci_device_clear_reset_pending() - This function will clear if any pending |
| 2025 | * reset condition flags on the device. |
| 2026 | * @request: This parameter is the isci_device object. |
| 2027 | * |
| 2028 | * true if there is a reset pending for the device. |
| 2029 | */ |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2030 | 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] | 2031 | { |
| 2032 | struct isci_request *isci_request; |
| 2033 | struct isci_request *tmp_req; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2034 | unsigned long flags = 0; |
| 2035 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2036 | dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n", |
| 2037 | __func__, idev, ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2038 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2039 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2040 | |
| 2041 | /* Clear reset pending on all pending requests. */ |
| 2042 | list_for_each_entry_safe(isci_request, tmp_req, |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2043 | &idev->reqs_in_process, dev_node) { |
| 2044 | dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n", |
| 2045 | __func__, idev, isci_request); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2046 | |
| 2047 | if (isci_request->ttype == io_task) { |
| 2048 | |
| 2049 | unsigned long flags2; |
| 2050 | struct sas_task *task = isci_request_access_task( |
| 2051 | isci_request); |
| 2052 | |
| 2053 | spin_lock_irqsave(&task->task_state_lock, flags2); |
| 2054 | task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; |
| 2055 | spin_unlock_irqrestore(&task->task_state_lock, flags2); |
| 2056 | } |
| 2057 | } |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 2058 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2059 | } |