remote_device.c (57f20f4ed6fb702339be2ef4dea9d15e6a7d0d07) | remote_device.c (88f3b62ac131e2549b6c262cacbd47e8cca42d6e) |
---|---|
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 * --- 38 unchanged lines hidden (view full) --- 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 */ | 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 * --- 38 unchanged lines hidden (view full) --- 47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 */ |
55 | 55#include "intel_sas.h" |
56#include "isci.h" | 56#include "isci.h" |
57#include "scic_io_request.h" 58#include "scic_remote_device.h" 59#include "scic_phy.h" 60#include "scic_port.h" | |
61#include "port.h" 62#include "remote_device.h" 63#include "request.h" | 57#include "port.h" 58#include "remote_device.h" 59#include "request.h" |
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" |
|
64#include "task.h" 65 | 72#include "task.h" 73 |
74enum 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} |
|
66 67 | 80 81 |
82enum 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 89enum 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 96enum 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 103void scic_remote_device_get_protocols( 104 struct scic_sds_remote_device *sci_dev, 105 struct smp_discover_response_protocols *pr) 106{ 107 pr->u.all = sci_dev->target_protocols.u.all; 108} 109 110#if !defined(DISABLE_ATAPI) 111bool scic_remote_device_is_atapi(struct scic_sds_remote_device *sci_dev) 112{ 113 return sci_dev->is_atapi; 114} 115#endif 116 117 |
|
68/** | 118/** |
119 * 120 * 121 * Remote device timer requirements 122 */ 123#define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0) 124#define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES) 125 126 127/** 128 * 129 * @sci_dev: The remote device for which the suspend is being requested. 130 * 131 * This method invokes the remote device suspend state handler. enum sci_status 132 */ 133enum sci_status scic_sds_remote_device_suspend( 134 struct scic_sds_remote_device *sci_dev, 135 u32 suspend_type) 136{ 137 return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type); 138} 139 140/** 141 * 142 * @sci_dev: The remote device for which the event handling is being 143 * requested. 144 * @frame_index: This is the frame index that is being processed. 145 * 146 * This method invokes the frame handler for the remote device state machine 147 * enum sci_status 148 */ 149enum sci_status scic_sds_remote_device_frame_handler( 150 struct scic_sds_remote_device *sci_dev, 151 u32 frame_index) 152{ 153 return sci_dev->state_handlers->frame_handler(sci_dev, frame_index); 154} 155 156/** 157 * 158 * @sci_dev: The remote device for which the event handling is being 159 * requested. 160 * @event_code: This is the event code that is to be processed. 161 * 162 * This method invokes the remote device event handler. enum sci_status 163 */ 164enum sci_status scic_sds_remote_device_event_handler( 165 struct scic_sds_remote_device *sci_dev, 166 u32 event_code) 167{ 168 return sci_dev->state_handlers->event_handler(sci_dev, event_code); 169} 170 171/** 172 * 173 * @controller: The controller that is starting the io request. 174 * @sci_dev: The remote device for which the start io handling is being 175 * requested. 176 * @io_request: The io request that is being started. 177 * 178 * This method invokes the remote device start io handler. enum sci_status 179 */ 180enum sci_status scic_sds_remote_device_start_io( 181 struct scic_sds_controller *controller, 182 struct scic_sds_remote_device *sci_dev, 183 struct scic_sds_request *io_request) 184{ 185 return sci_dev->state_handlers->start_io_handler( 186 sci_dev, io_request); 187} 188 189/** 190 * 191 * @controller: The controller that is completing the io request. 192 * @sci_dev: The remote device for which the complete io handling is being 193 * requested. 194 * @io_request: The io request that is being completed. 195 * 196 * This method invokes the remote device complete io handler. enum sci_status 197 */ 198enum sci_status scic_sds_remote_device_complete_io( 199 struct scic_sds_controller *controller, 200 struct scic_sds_remote_device *sci_dev, 201 struct scic_sds_request *io_request) 202{ 203 return sci_dev->state_handlers->complete_io_handler( 204 sci_dev, io_request); 205} 206 207/** 208 * 209 * @controller: The controller that is starting the task request. 210 * @sci_dev: The remote device for which the start task handling is being 211 * requested. 212 * @io_request: The task request that is being started. 213 * 214 * This method invokes the remote device start task handler. enum sci_status 215 */ 216enum sci_status scic_sds_remote_device_start_task( 217 struct scic_sds_controller *controller, 218 struct scic_sds_remote_device *sci_dev, 219 struct scic_sds_request *io_request) 220{ 221 return sci_dev->state_handlers->start_task_handler( 222 sci_dev, io_request); 223} 224 225/** 226 * 227 * @controller: The controller that is completing the task request. 228 * @sci_dev: The remote device for which the complete task handling is 229 * being requested. 230 * @io_request: The task request that is being completed. 231 * 232 * This method invokes the remote device complete task handler. enum sci_status 233 */ 234 235/** 236 * 237 * @sci_dev: 238 * @request: 239 * 240 * This method takes the request and bulids an appropriate SCU context for the 241 * request and then requests the controller to post the request. none 242 */ 243void scic_sds_remote_device_post_request( 244 struct scic_sds_remote_device *sci_dev, 245 u32 request) 246{ 247 u32 context; 248 249 context = scic_sds_remote_device_build_command_context(sci_dev, request); 250 251 scic_sds_controller_post_request( 252 scic_sds_remote_device_get_controller(sci_dev), 253 context 254 ); 255} 256 257#if !defined(DISABLE_ATAPI) 258/** 259 * 260 * @sci_dev: The device to be checked. 261 * 262 * This method check the signature fis of a stp device to decide whether a 263 * device is atapi or not. true if a device is atapi device. False if a device 264 * is not atapi. 265 */ 266bool scic_sds_remote_device_is_atapi( 267 struct scic_sds_remote_device *sci_dev) 268{ 269 if (!sci_dev->target_protocols.u.bits.attached_stp_target) 270 return false; 271 else if (sci_dev->is_direct_attached) { 272 struct scic_sds_phy *phy; 273 struct scic_sata_phy_properties properties; 274 struct sata_fis_reg_d2h *signature_fis; 275 phy = scic_sds_port_get_a_connected_phy(sci_dev->owning_port); 276 scic_sata_phy_get_properties(phy, &properties); 277 278 /* decode the signature fis. */ 279 signature_fis = &(properties.signature_fis); 280 281 if ((signature_fis->sector_count == 0x01) 282 && (signature_fis->lba_low == 0x01) 283 && (signature_fis->lba_mid == 0x14) 284 && (signature_fis->lba_high == 0xEB) 285 && ((signature_fis->device & 0x5F) == 0x00) 286 ) { 287 /* An ATA device supporting the PACKET command set. */ 288 return true; 289 } else 290 return false; 291 } else { 292 /* Expander supported ATAPI device is not currently supported. */ 293 return false; 294 } 295} 296#endif 297 298/** 299 * 300 * @user_parameter: This is cast to a remote device object. 301 * 302 * This method is called once the remote node context is ready to be freed. 303 * The remote device can now report that its stop operation is complete. none 304 */ 305static void scic_sds_cb_remote_device_rnc_destruct_complete( 306 void *user_parameter) 307{ 308 struct scic_sds_remote_device *sci_dev; 309 310 sci_dev = (struct scic_sds_remote_device *)user_parameter; 311 312 BUG_ON(sci_dev->started_request_count != 0); 313 314 sci_base_state_machine_change_state(&sci_dev->state_machine, 315 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); 316} 317 318/** 319 * 320 * @user_parameter: This is cast to a remote device object. 321 * 322 * This method is called once the remote node context has transisitioned to a 323 * ready state. This is the indication that the remote device object can also 324 * transition to ready. none 325 */ 326static void scic_sds_remote_device_resume_complete_handler( 327 void *user_parameter) 328{ 329 struct scic_sds_remote_device *sci_dev; 330 331 sci_dev = (struct scic_sds_remote_device *)user_parameter; 332 333 if ( 334 sci_base_state_machine_get_state(&sci_dev->state_machine) 335 != SCI_BASE_REMOTE_DEVICE_STATE_READY 336 ) { 337 sci_base_state_machine_change_state( 338 &sci_dev->state_machine, 339 SCI_BASE_REMOTE_DEVICE_STATE_READY 340 ); 341 } 342} 343 344/** 345 * 346 * @device: This parameter specifies the device for which the request is being 347 * started. 348 * @request: This parameter specifies the request being started. 349 * @status: This parameter specifies the current start operation status. 350 * 351 * This method will perform the STP request start processing common to IO 352 * requests and task requests of all types. none 353 */ 354void scic_sds_remote_device_start_request( 355 struct scic_sds_remote_device *sci_dev, 356 struct scic_sds_request *sci_req, 357 enum sci_status status) 358{ 359 /* We still have a fault in starting the io complete it on the port */ 360 if (status == SCI_SUCCESS) 361 scic_sds_remote_device_increment_request_count(sci_dev); 362 else{ 363 sci_dev->owning_port->state_handlers->complete_io_handler( 364 sci_dev->owning_port, sci_dev, sci_req 365 ); 366 } 367} 368 369 370/** 371 * 372 * @request: This parameter specifies the request being continued. 373 * 374 * This method will continue to post tc for a STP request. This method usually 375 * serves as a callback when RNC gets resumed during a task management 376 * sequence. none 377 */ 378void scic_sds_remote_device_continue_request(void *dev) 379{ 380 struct scic_sds_remote_device *sci_dev = dev; 381 382 /* we need to check if this request is still valid to continue. */ 383 if (sci_dev->working_request) 384 scic_controller_continue_io(sci_dev->working_request); 385} 386 387/** 388 * This method will terminate all of the IO requests in the controllers IO 389 * request table that were targeted for this device. 390 * @sci_dev: This parameter specifies the remote device for which to 391 * attempt to terminate all requests. 392 * 393 * This method returns an indication as to whether all requests were 394 * successfully terminated. If a single request fails to be terminated, then 395 * this method will return the failure. 396 */ 397static enum sci_status scic_sds_remote_device_terminate_requests( 398 struct scic_sds_remote_device *sci_dev) 399{ 400 enum sci_status status = SCI_SUCCESS; 401 enum sci_status terminate_status = SCI_SUCCESS; 402 struct scic_sds_request *sci_req; 403 u32 index; 404 u32 request_count = sci_dev->started_request_count; 405 406 for (index = 0; 407 (index < SCI_MAX_IO_REQUESTS) && (request_count > 0); 408 index++) { 409 sci_req = sci_dev->owning_port->owning_controller->io_request_table[index]; 410 411 if ((sci_req != NULL) && (sci_req->target_device == sci_dev)) { 412 terminate_status = scic_controller_terminate_request( 413 sci_dev->owning_port->owning_controller, 414 sci_dev, 415 sci_req 416 ); 417 418 if (terminate_status != SCI_SUCCESS) 419 status = terminate_status; 420 421 request_count--; 422 } 423 } 424 425 return status; 426} 427 428static enum sci_status 429default_device_handler(struct scic_sds_remote_device *sci_dev, 430 const char *func) 431{ 432 dev_warn(scirdev_to_dev(sci_dev), 433 "%s: in wrong state: %d\n", func, 434 sci_base_state_machine_get_state(&sci_dev->state_machine)); 435 return SCI_FAILURE_INVALID_STATE; 436} 437 438enum sci_status scic_sds_remote_device_default_start_handler( 439 struct scic_sds_remote_device *sci_dev) 440{ 441 return default_device_handler(sci_dev, __func__); 442} 443 444static enum sci_status scic_sds_remote_device_default_stop_handler( 445 struct scic_sds_remote_device *sci_dev) 446{ 447 return default_device_handler(sci_dev, __func__); 448} 449 450enum sci_status scic_sds_remote_device_default_fail_handler( 451 struct scic_sds_remote_device *sci_dev) 452{ 453 return default_device_handler(sci_dev, __func__); 454} 455 456enum sci_status scic_sds_remote_device_default_destruct_handler( 457 struct scic_sds_remote_device *sci_dev) 458{ 459 return default_device_handler(sci_dev, __func__); 460} 461 462enum sci_status scic_sds_remote_device_default_reset_handler( 463 struct scic_sds_remote_device *sci_dev) 464{ 465 return default_device_handler(sci_dev, __func__); 466} 467 468enum sci_status scic_sds_remote_device_default_reset_complete_handler( 469 struct scic_sds_remote_device *sci_dev) 470{ 471 return default_device_handler(sci_dev, __func__); 472} 473 474enum sci_status scic_sds_remote_device_default_suspend_handler( 475 struct scic_sds_remote_device *sci_dev, u32 suspend_type) 476{ 477 return default_device_handler(sci_dev, __func__); 478} 479 480enum sci_status scic_sds_remote_device_default_resume_handler( 481 struct scic_sds_remote_device *sci_dev) 482{ 483 return default_device_handler(sci_dev, __func__); 484} 485 486/** 487 * 488 * @device: The struct scic_sds_remote_device which is then cast into a 489 * struct scic_sds_remote_device. 490 * @event_code: The event code that the struct scic_sds_controller wants the device 491 * object to process. 492 * 493 * This method is the default event handler. It will call the RNC state 494 * machine handler for any RNC events otherwise it will log a warning and 495 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE 496 */ 497static enum sci_status scic_sds_remote_device_core_event_handler( 498 struct scic_sds_remote_device *sci_dev, 499 u32 event_code, 500 bool is_ready_state) 501{ 502 enum sci_status status; 503 504 switch (scu_get_event_type(event_code)) { 505 case SCU_EVENT_TYPE_RNC_OPS_MISC: 506 case SCU_EVENT_TYPE_RNC_SUSPEND_TX: 507 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: 508 status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code); 509 break; 510 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT: 511 512 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) { 513 status = SCI_SUCCESS; 514 515 /* Suspend the associated RNC */ 516 scic_sds_remote_node_context_suspend(&sci_dev->rnc, 517 SCI_SOFTWARE_SUSPENSION, 518 NULL, NULL); 519 520 dev_dbg(scirdev_to_dev(sci_dev), 521 "%s: device: %p event code: %x: %s\n", 522 __func__, sci_dev, event_code, 523 (is_ready_state) 524 ? "I_T_Nexus_Timeout event" 525 : "I_T_Nexus_Timeout event in wrong state"); 526 527 break; 528 } 529 /* Else, fall through and treat as unhandled... */ 530 531 default: 532 dev_dbg(scirdev_to_dev(sci_dev), 533 "%s: device: %p event code: %x: %s\n", 534 __func__, sci_dev, event_code, 535 (is_ready_state) 536 ? "unexpected event" 537 : "unexpected event in wrong state"); 538 status = SCI_FAILURE_INVALID_STATE; 539 break; 540 } 541 542 return status; 543} 544/** 545 * 546 * @device: The struct scic_sds_remote_device which is then cast into a 547 * struct scic_sds_remote_device. 548 * @event_code: The event code that the struct scic_sds_controller wants the device 549 * object to process. 550 * 551 * This method is the default event handler. It will call the RNC state 552 * machine handler for any RNC events otherwise it will log a warning and 553 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE 554 */ 555static enum sci_status scic_sds_remote_device_default_event_handler( 556 struct scic_sds_remote_device *sci_dev, 557 u32 event_code) 558{ 559 return scic_sds_remote_device_core_event_handler(sci_dev, 560 event_code, 561 false); 562} 563 564/** 565 * 566 * @device: The struct scic_sds_remote_device which is then cast into a 567 * struct scic_sds_remote_device. 568 * @frame_index: The frame index for which the struct scic_sds_controller wants this 569 * device object to process. 570 * 571 * This method is the default unsolicited frame handler. It logs a warning, 572 * releases the frame and returns a failure. enum sci_status 573 * SCI_FAILURE_INVALID_STATE 574 */ 575enum sci_status scic_sds_remote_device_default_frame_handler( 576 struct scic_sds_remote_device *sci_dev, 577 u32 frame_index) 578{ 579 dev_warn(scirdev_to_dev(sci_dev), 580 "%s: SCIC Remote Device requested to handle frame %x " 581 "while in wrong state %d\n", 582 __func__, 583 frame_index, 584 sci_base_state_machine_get_state( 585 &sci_dev->state_machine)); 586 587 /* Return the frame back to the controller */ 588 scic_sds_controller_release_frame( 589 scic_sds_remote_device_get_controller(sci_dev), frame_index 590 ); 591 592 return SCI_FAILURE_INVALID_STATE; 593} 594 595enum sci_status scic_sds_remote_device_default_start_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 602enum sci_status scic_sds_remote_device_default_complete_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 609enum sci_status scic_sds_remote_device_default_continue_request_handler( 610 struct scic_sds_remote_device *sci_dev, 611 struct scic_sds_request *request) 612{ 613 return default_device_handler(sci_dev, __func__); 614} 615 616/** 617 * 618 * @device: The struct scic_sds_remote_device which is then cast into a 619 * struct scic_sds_remote_device. 620 * @frame_index: The frame index for which the struct scic_sds_controller wants this 621 * device object to process. 622 * 623 * This method is a general ssp frame handler. In most cases the device object 624 * needs to route the unsolicited frame processing to the io request object. 625 * This method decodes the tag for the io request object and routes the 626 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE 627 */ 628enum sci_status scic_sds_remote_device_general_frame_handler( 629 struct scic_sds_remote_device *sci_dev, 630 u32 frame_index) 631{ 632 enum sci_status result; 633 struct sci_ssp_frame_header *frame_header; 634 struct scic_sds_request *io_request; 635 636 result = scic_sds_unsolicited_frame_control_get_header( 637 &(scic_sds_remote_device_get_controller(sci_dev)->uf_control), 638 frame_index, 639 (void **)&frame_header 640 ); 641 642 if (SCI_SUCCESS == result) { 643 io_request = scic_sds_controller_get_io_request_from_tag( 644 scic_sds_remote_device_get_controller(sci_dev), frame_header->tag); 645 646 if ((io_request == NULL) 647 || (io_request->target_device != sci_dev)) { 648 /* 649 * We could not map this tag to a valid IO request 650 * Just toss the frame and continue */ 651 scic_sds_controller_release_frame( 652 scic_sds_remote_device_get_controller(sci_dev), frame_index 653 ); 654 } else { 655 /* The IO request is now in charge of releasing the frame */ 656 result = io_request->state_handlers->frame_handler( 657 io_request, frame_index); 658 } 659 } 660 661 return result; 662} 663 664/** 665 * 666 * @[in]: sci_dev This is the device object that is receiving the event. 667 * @[in]: event_code The event code to process. 668 * 669 * This is a common method for handling events reported to the remote device 670 * from the controller object. enum sci_status 671 */ 672enum sci_status scic_sds_remote_device_general_event_handler( 673 struct scic_sds_remote_device *sci_dev, 674 u32 event_code) 675{ 676 return scic_sds_remote_device_core_event_handler(sci_dev, 677 event_code, 678 true); 679} 680 681/* 682 * ***************************************************************************** 683 * * STOPPED STATE HANDLERS 684 * ***************************************************************************** */ 685 686/** 687 * 688 * @device: 689 * 690 * This method takes the struct scic_sds_remote_device from a stopped state and 691 * attempts to start it. The RNC buffer for the device is constructed and the 692 * device state machine is transitioned to the 693 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is 694 * an RNC buffer available to construct the remote device. 695 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in 696 * which to construct the remote device. 697 */ 698static enum sci_status scic_sds_remote_device_stopped_state_start_handler( 699 struct scic_sds_remote_device *sci_dev) 700{ 701 enum sci_status status; 702 703 status = scic_sds_remote_node_context_resume(&sci_dev->rnc, 704 scic_sds_remote_device_resume_complete_handler, sci_dev); 705 706 if (status == SCI_SUCCESS) 707 sci_base_state_machine_change_state(&sci_dev->state_machine, 708 SCI_BASE_REMOTE_DEVICE_STATE_STARTING); 709 710 return status; 711} 712 713static enum sci_status scic_sds_remote_device_stopped_state_stop_handler( 714 struct scic_sds_remote_device *sci_dev) 715{ 716 return SCI_SUCCESS; 717} 718 719/** 720 * 721 * @sci_dev: The struct scic_sds_remote_device which is cast into a 722 * struct scic_sds_remote_device. 723 * 724 * This method will destruct a struct scic_sds_remote_device that is in a stopped 725 * state. This is the only state from which a destruct request will succeed. 726 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the 727 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL. 728 * enum sci_status SCI_SUCCESS 729 */ 730static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler( 731 struct scic_sds_remote_device *sci_dev) 732{ 733 struct scic_sds_controller *scic; 734 735 scic = scic_sds_remote_device_get_controller(sci_dev); 736 scic_sds_controller_free_remote_node_context(scic, sci_dev, 737 sci_dev->rnc.remote_node_index); 738 sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX; 739 740 sci_base_state_machine_change_state(&sci_dev->state_machine, 741 SCI_BASE_REMOTE_DEVICE_STATE_FINAL); 742 743 return SCI_SUCCESS; 744} 745 746/* 747 * ***************************************************************************** 748 * * STARTING STATE HANDLERS 749 * ***************************************************************************** */ 750 751static enum sci_status scic_sds_remote_device_starting_state_stop_handler( 752 struct scic_sds_remote_device *sci_dev) 753{ 754 /* 755 * This device has not yet started so there had better be no IO requests 756 */ 757 BUG_ON(sci_dev->started_request_count != 0); 758 759 /* 760 * Destroy the remote node context 761 */ 762 scic_sds_remote_node_context_destruct(&sci_dev->rnc, 763 scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev); 764 765 /* 766 * Transition to the stopping state and wait for the remote node to 767 * complete being posted and invalidated. 768 */ 769 sci_base_state_machine_change_state(&sci_dev->state_machine, 770 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); 771 772 return SCI_SUCCESS; 773} 774 775enum sci_status scic_sds_remote_device_ready_state_stop_handler( 776 struct scic_sds_remote_device *sci_dev) 777{ 778 enum sci_status status = SCI_SUCCESS; 779 780 /* Request the parent state machine to transition to the stopping state */ 781 sci_base_state_machine_change_state(&sci_dev->state_machine, 782 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING); 783 784 if (sci_dev->started_request_count == 0) { 785 scic_sds_remote_node_context_destruct(&sci_dev->rnc, 786 scic_sds_cb_remote_device_rnc_destruct_complete, 787 sci_dev); 788 } else 789 status = scic_sds_remote_device_terminate_requests(sci_dev); 790 791 return status; 792} 793 794/** 795 * 796 * @device: The struct scic_sds_remote_device object which is cast to a 797 * struct scic_sds_remote_device object. 798 * 799 * This is the ready state device reset handler enum sci_status 800 */ 801enum sci_status scic_sds_remote_device_ready_state_reset_handler( 802 struct scic_sds_remote_device *sci_dev) 803{ 804 /* Request the parent state machine to transition to the stopping state */ 805 sci_base_state_machine_change_state(&sci_dev->state_machine, 806 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING); 807 808 return SCI_SUCCESS; 809} 810 811/* 812 * This method will attempt to start a task request for this device object. The 813 * remote device object will issue the start request for the task and if 814 * successful it will start the request for the port object then increment its 815 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for 816 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request 817 * object could not get the resources to start. 818 */ 819static enum sci_status scic_sds_remote_device_ready_state_start_task_handler( 820 struct scic_sds_remote_device *sci_dev, 821 struct scic_sds_request *request) 822{ 823 enum sci_status result; 824 825 /* See if the port is in a state where we can start the IO request */ 826 result = scic_sds_port_start_io( 827 scic_sds_remote_device_get_port(sci_dev), sci_dev, request); 828 829 if (result == SCI_SUCCESS) { 830 result = scic_sds_remote_node_context_start_task(&sci_dev->rnc, 831 request); 832 if (result == SCI_SUCCESS) 833 result = scic_sds_request_start(request); 834 835 scic_sds_remote_device_start_request(sci_dev, request, result); 836 } 837 838 return result; 839} 840 841/* 842 * This method will attempt to start an io request for this device object. The 843 * remote device object will issue the start request for the io and if 844 * successful it will start the request for the port object then increment its 845 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for 846 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request 847 * object could not get the resources to start. 848 */ 849static enum sci_status scic_sds_remote_device_ready_state_start_io_handler( 850 struct scic_sds_remote_device *sci_dev, 851 struct scic_sds_request *request) 852{ 853 enum sci_status result; 854 855 /* See if the port is in a state where we can start the IO request */ 856 result = scic_sds_port_start_io( 857 scic_sds_remote_device_get_port(sci_dev), sci_dev, request); 858 859 if (result == SCI_SUCCESS) { 860 result = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request); 861 if (result == SCI_SUCCESS) 862 result = scic_sds_request_start(request); 863 864 scic_sds_remote_device_start_request(sci_dev, request, result); 865 } 866 867 return result; 868} 869 870/* 871 * This method will complete the request for the remote device object. The 872 * method will call the completion handler for the request object and if 873 * successful it will complete the request on the port object then decrement 874 * its own started_request_count. enum sci_status 875 */ 876static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler( 877 struct scic_sds_remote_device *sci_dev, 878 struct scic_sds_request *request) 879{ 880 enum sci_status result; 881 882 result = scic_sds_request_complete(request); 883 884 if (result != SCI_SUCCESS) 885 return result; 886 887 /* See if the port is in a state 888 * where we can start the IO request */ 889 result = scic_sds_port_complete_io( 890 scic_sds_remote_device_get_port(sci_dev), 891 sci_dev, request); 892 893 if (result == SCI_SUCCESS) 894 scic_sds_remote_device_decrement_request_count(sci_dev); 895 896 return result; 897} 898 899/* 900 * ***************************************************************************** 901 * * STOPPING STATE HANDLERS 902 * ***************************************************************************** */ 903 904/** 905 * 906 * @sci_dev: The struct scic_sds_remote_device which is cast into a 907 * struct scic_sds_remote_device. 908 * 909 * This method will stop a struct scic_sds_remote_device that is already in the 910 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error 911 * since we allow a stop request on a device that is alreay stopping or 912 * stopped. enum sci_status SCI_SUCCESS 913 */ 914static enum sci_status scic_sds_remote_device_stopping_state_stop_handler( 915 struct scic_sds_remote_device *device) 916{ 917 /* 918 * All requests should have been terminated, but if there is an 919 * attempt to stop a device already in the stopping state, then 920 * try again to terminate. */ 921 return scic_sds_remote_device_terminate_requests(device); 922} 923 924 925/** 926 * 927 * @device: The device object for which the request is completing. 928 * @request: The task request that is being completed. 929 * 930 * This method completes requests for this struct scic_sds_remote_device while it is 931 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the 932 * complete method for the request object and if that is successful the port 933 * object is called to complete the task request. Then the device object itself 934 * completes the task request. If struct scic_sds_remote_device started_request_count 935 * goes to 0 and the invalidate RNC request has completed the device object can 936 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status 937 */ 938static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler( 939 struct scic_sds_remote_device *sci_dev, 940 struct scic_sds_request *request) 941{ 942 enum sci_status status = SCI_SUCCESS; 943 944 status = scic_sds_request_complete(request); 945 946 if (status != SCI_SUCCESS) 947 return status; 948 949 status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev), 950 sci_dev, request); 951 if (status != SCI_SUCCESS) 952 return status; 953 954 scic_sds_remote_device_decrement_request_count(sci_dev); 955 956 if (scic_sds_remote_device_get_request_count(sci_dev) == 0) 957 scic_sds_remote_node_context_destruct(&sci_dev->rnc, 958 scic_sds_cb_remote_device_rnc_destruct_complete, 959 sci_dev); 960 return SCI_SUCCESS; 961} 962 963/** 964 * 965 * @device: The struct scic_sds_remote_device which is to be cast into a 966 * struct scic_sds_remote_device object. 967 * 968 * This method will complete the reset operation when the device is in the 969 * resetting state. enum sci_status 970 */ 971static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler( 972 struct scic_sds_remote_device *sci_dev) 973{ 974 975 sci_base_state_machine_change_state( 976 &sci_dev->state_machine, 977 SCI_BASE_REMOTE_DEVICE_STATE_READY 978 ); 979 980 return SCI_SUCCESS; 981} 982 983/** 984 * 985 * @device: The struct scic_sds_remote_device which is to be cast into a 986 * struct scic_sds_remote_device object. 987 * 988 * This method will stop the remote device while in the resetting state. 989 * enum sci_status 990 */ 991static enum sci_status scic_sds_remote_device_resetting_state_stop_handler( 992 struct scic_sds_remote_device *sci_dev) 993{ 994 sci_base_state_machine_change_state( 995 &sci_dev->state_machine, 996 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING 997 ); 998 999 return SCI_SUCCESS; 1000} 1001 1002/* 1003 * This method completes requests for this struct scic_sds_remote_device while it is 1004 * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the 1005 * complete method for the request object and if that is successful the port 1006 * object is called to complete the task request. Then the device object itself 1007 * completes the task request. enum sci_status 1008 */ 1009static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler( 1010 struct scic_sds_remote_device *sci_dev, 1011 struct scic_sds_request *request) 1012{ 1013 enum sci_status status = SCI_SUCCESS; 1014 1015 status = scic_sds_request_complete(request); 1016 1017 if (status == SCI_SUCCESS) { 1018 status = scic_sds_port_complete_io( 1019 scic_sds_remote_device_get_port(sci_dev), 1020 sci_dev, request); 1021 1022 if (status == SCI_SUCCESS) { 1023 scic_sds_remote_device_decrement_request_count(sci_dev); 1024 } 1025 } 1026 1027 return status; 1028} 1029 1030static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = { 1031 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { 1032 .start_handler = scic_sds_remote_device_default_start_handler, 1033 .stop_handler = scic_sds_remote_device_default_stop_handler, 1034 .fail_handler = scic_sds_remote_device_default_fail_handler, 1035 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1036 .reset_handler = scic_sds_remote_device_default_reset_handler, 1037 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1038 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1039 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, 1040 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1041 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1042 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, 1043 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1044 .resume_handler = scic_sds_remote_device_default_resume_handler, 1045 .event_handler = scic_sds_remote_device_default_event_handler, 1046 .frame_handler = scic_sds_remote_device_default_frame_handler 1047 }, 1048 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { 1049 .start_handler = scic_sds_remote_device_stopped_state_start_handler, 1050 .stop_handler = scic_sds_remote_device_stopped_state_stop_handler, 1051 .fail_handler = scic_sds_remote_device_default_fail_handler, 1052 .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler, 1053 .reset_handler = scic_sds_remote_device_default_reset_handler, 1054 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1055 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1056 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, 1057 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1058 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1059 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, 1060 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1061 .resume_handler = scic_sds_remote_device_default_resume_handler, 1062 .event_handler = scic_sds_remote_device_default_event_handler, 1063 .frame_handler = scic_sds_remote_device_default_frame_handler 1064 }, 1065 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { 1066 .start_handler = scic_sds_remote_device_default_start_handler, 1067 .stop_handler = scic_sds_remote_device_starting_state_stop_handler, 1068 .fail_handler = scic_sds_remote_device_default_fail_handler, 1069 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1070 .reset_handler = scic_sds_remote_device_default_reset_handler, 1071 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1072 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1073 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, 1074 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1075 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1076 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, 1077 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1078 .resume_handler = scic_sds_remote_device_default_resume_handler, 1079 .event_handler = scic_sds_remote_device_general_event_handler, 1080 .frame_handler = scic_sds_remote_device_default_frame_handler 1081 }, 1082 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { 1083 .start_handler = scic_sds_remote_device_default_start_handler, 1084 .stop_handler = scic_sds_remote_device_ready_state_stop_handler, 1085 .fail_handler = scic_sds_remote_device_default_fail_handler, 1086 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1087 .reset_handler = scic_sds_remote_device_ready_state_reset_handler, 1088 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1089 .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler, 1090 .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler, 1091 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1092 .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler, 1093 .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler, 1094 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1095 .resume_handler = scic_sds_remote_device_default_resume_handler, 1096 .event_handler = scic_sds_remote_device_general_event_handler, 1097 .frame_handler = scic_sds_remote_device_general_frame_handler, 1098 }, 1099 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { 1100 .start_handler = scic_sds_remote_device_default_start_handler, 1101 .stop_handler = scic_sds_remote_device_stopping_state_stop_handler, 1102 .fail_handler = scic_sds_remote_device_default_fail_handler, 1103 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1104 .reset_handler = scic_sds_remote_device_default_reset_handler, 1105 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1106 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1107 .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler, 1108 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1109 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1110 .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler, 1111 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1112 .resume_handler = scic_sds_remote_device_default_resume_handler, 1113 .event_handler = scic_sds_remote_device_general_event_handler, 1114 .frame_handler = scic_sds_remote_device_general_frame_handler 1115 }, 1116 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { 1117 .start_handler = scic_sds_remote_device_default_start_handler, 1118 .stop_handler = scic_sds_remote_device_default_stop_handler, 1119 .fail_handler = scic_sds_remote_device_default_fail_handler, 1120 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1121 .reset_handler = scic_sds_remote_device_default_reset_handler, 1122 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1123 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1124 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, 1125 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1126 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1127 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, 1128 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1129 .resume_handler = scic_sds_remote_device_default_resume_handler, 1130 .event_handler = scic_sds_remote_device_default_event_handler, 1131 .frame_handler = scic_sds_remote_device_general_frame_handler 1132 }, 1133 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { 1134 .start_handler = scic_sds_remote_device_default_start_handler, 1135 .stop_handler = scic_sds_remote_device_resetting_state_stop_handler, 1136 .fail_handler = scic_sds_remote_device_default_fail_handler, 1137 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1138 .reset_handler = scic_sds_remote_device_default_reset_handler, 1139 .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler, 1140 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1141 .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler, 1142 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1143 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1144 .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler, 1145 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1146 .resume_handler = scic_sds_remote_device_default_resume_handler, 1147 .event_handler = scic_sds_remote_device_default_event_handler, 1148 .frame_handler = scic_sds_remote_device_general_frame_handler 1149 }, 1150 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { 1151 .start_handler = scic_sds_remote_device_default_start_handler, 1152 .stop_handler = scic_sds_remote_device_default_stop_handler, 1153 .fail_handler = scic_sds_remote_device_default_fail_handler, 1154 .destruct_handler = scic_sds_remote_device_default_destruct_handler, 1155 .reset_handler = scic_sds_remote_device_default_reset_handler, 1156 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler, 1157 .start_io_handler = scic_sds_remote_device_default_start_request_handler, 1158 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler, 1159 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler, 1160 .start_task_handler = scic_sds_remote_device_default_start_request_handler, 1161 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler, 1162 .suspend_handler = scic_sds_remote_device_default_suspend_handler, 1163 .resume_handler = scic_sds_remote_device_default_resume_handler, 1164 .event_handler = scic_sds_remote_device_default_event_handler, 1165 .frame_handler = scic_sds_remote_device_default_frame_handler 1166 } 1167}; 1168 1169static void scic_sds_remote_device_initial_state_enter( 1170 struct sci_base_object *object) 1171{ 1172 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; 1173 1174 sci_dev = container_of(object, typeof(*sci_dev), parent); 1175 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, 1176 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL); 1177 1178 /* Initial state is a transitional state to the stopped state */ 1179 sci_base_state_machine_change_state(&sci_dev->state_machine, 1180 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); 1181} 1182 1183/** 1184 * isci_remote_device_change_state() - This function gets the status of the 1185 * remote_device object. 1186 * @isci_device: This parameter points to the isci_remote_device object 1187 * 1188 * status of the object as a isci_status enum. 1189 */ 1190void isci_remote_device_change_state( 1191 struct isci_remote_device *isci_device, 1192 enum isci_status status) 1193{ 1194 unsigned long flags; 1195 1196 spin_lock_irqsave(&isci_device->state_lock, flags); 1197 isci_device->status = status; 1198 spin_unlock_irqrestore(&isci_device->state_lock, flags); 1199} 1200 1201/** 1202 * scic_remote_device_destruct() - free remote node context and destruct 1203 * @remote_device: This parameter specifies the remote device to be destructed. 1204 * 1205 * Remote device objects are a limited resource. As such, they must be 1206 * protected. Thus calls to construct and destruct are mutually exclusive and 1207 * non-reentrant. The return value shall indicate if the device was 1208 * successfully destructed or if some failure occurred. enum sci_status This value 1209 * is returned if the device is successfully destructed. 1210 * SCI_FAILURE_INVALID_REMOTE_DEVICE This value is returned if the supplied 1211 * device isn't valid (e.g. it's already been destoryed, the handle isn't 1212 * valid, etc.). 1213 */ 1214static enum sci_status scic_remote_device_destruct(struct scic_sds_remote_device *sci_dev) 1215{ 1216 return sci_dev->state_handlers->destruct_handler(sci_dev); 1217} 1218 1219/** |
|
69 * isci_remote_device_deconstruct() - This function frees an isci_remote_device. 70 * @ihost: This parameter specifies the isci host object. 71 * @idev: This parameter specifies the remote device to be freed. 72 * 73 */ 74static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev) 75{ 76 dev_dbg(&ihost->pdev->dev, --- 16 unchanged lines hidden (view full) --- 93 idev->isci_port = NULL; 94 list_del_init(&idev->node); 95 96 clear_bit(IDEV_START_PENDING, &idev->flags); 97 clear_bit(IDEV_STOP_PENDING, &idev->flags); 98 wake_up(&ihost->eventq); 99} 100 | 1220 * isci_remote_device_deconstruct() - This function frees an isci_remote_device. 1221 * @ihost: This parameter specifies the isci host object. 1222 * @idev: This parameter specifies the remote device to be freed. 1223 * 1224 */ 1225static void isci_remote_device_deconstruct(struct isci_host *ihost, struct isci_remote_device *idev) 1226{ 1227 dev_dbg(&ihost->pdev->dev, --- 16 unchanged lines hidden (view full) --- 1244 idev->isci_port = NULL; 1245 list_del_init(&idev->node); 1246 1247 clear_bit(IDEV_START_PENDING, &idev->flags); 1248 clear_bit(IDEV_STOP_PENDING, &idev->flags); 1249 wake_up(&ihost->eventq); 1250} 1251 |
1252/** 1253 * isci_remote_device_stop_complete() - This function is called by the scic 1254 * when the remote device stop has completed. We mark the isci device as not 1255 * ready and remove the isci remote device. 1256 * @ihost: This parameter specifies the isci host object. 1257 * @idev: This parameter specifies the remote device. 1258 * @status: This parameter specifies status of the completion. 1259 * 1260 */ 1261static void isci_remote_device_stop_complete(struct isci_host *ihost, 1262 struct isci_remote_device *idev) 1263{ 1264 dev_dbg(&ihost->pdev->dev, "%s: complete idev = %p\n", __func__, idev); |
|
101 | 1265 |
1266 isci_remote_device_change_state(idev, isci_stopped); 1267 1268 /* after stop, we can tear down resources. */ 1269 isci_remote_device_deconstruct(ihost, idev); 1270} 1271 1272static void scic_sds_remote_device_stopped_state_enter( 1273 struct sci_base_object *object) 1274{ 1275 struct scic_sds_remote_device *sci_dev; 1276 struct scic_sds_controller *scic; 1277 struct isci_remote_device *idev; 1278 struct isci_host *ihost; 1279 u32 prev_state; 1280 1281 sci_dev = container_of(object, typeof(*sci_dev), parent); 1282 scic = scic_sds_remote_device_get_controller(sci_dev); 1283 ihost = sci_object_get_association(scic); 1284 idev = sci_object_get_association(sci_dev); 1285 1286 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, 1287 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED); 1288 1289 /* If we are entering from the stopping state let the SCI User know that 1290 * the stop operation has completed. 1291 */ 1292 prev_state = sci_dev->state_machine.previous_state_id; 1293 if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING) 1294 isci_remote_device_stop_complete(ihost, idev); 1295 1296 scic_sds_controller_remote_device_stopped(scic, sci_dev); 1297} 1298 1299static void scic_sds_remote_device_starting_state_enter(struct sci_base_object *object) 1300{ 1301 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev), 1302 parent); 1303 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); 1304 struct isci_host *ihost = sci_object_get_association(scic); 1305 struct isci_remote_device *idev = sci_object_get_association(sci_dev); 1306 1307 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table, 1308 SCI_BASE_REMOTE_DEVICE_STATE_STARTING); 1309 1310 isci_remote_device_not_ready(ihost, idev, 1311 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED); 1312} 1313 1314static void scic_sds_remote_device_ready_state_enter(struct sci_base_object *object) 1315{ 1316 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev), 1317 parent); 1318 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); 1319 struct isci_host *ihost = sci_object_get_association(scic); 1320 struct isci_remote_device *idev = sci_object_get_association(sci_dev); 1321 1322 SET_STATE_HANDLER(sci_dev, 1323 scic_sds_remote_device_state_handler_table, 1324 SCI_BASE_REMOTE_DEVICE_STATE_READY); 1325 1326 scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++; 1327 1328 if (sci_dev->has_ready_substate_machine) 1329 sci_base_state_machine_start(&sci_dev->ready_substate_machine); 1330 else 1331 isci_remote_device_ready(ihost, idev); 1332} 1333 1334static void scic_sds_remote_device_ready_state_exit( 1335 struct sci_base_object *object) 1336{ 1337 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev), 1338 parent); 1339 if (sci_dev->has_ready_substate_machine) 1340 sci_base_state_machine_stop(&sci_dev->ready_substate_machine); 1341 else { 1342 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev); 1343 struct isci_host *ihost = sci_object_get_association(scic); 1344 struct isci_remote_device *idev = sci_object_get_association(sci_dev); 1345 1346 isci_remote_device_not_ready(ihost, idev, 1347 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED); 1348 } 1349} 1350 1351static void scic_sds_remote_device_stopping_state_enter( 1352 struct sci_base_object *object) 1353{ 1354 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; 1355 1356 SET_STATE_HANDLER( 1357 sci_dev, 1358 scic_sds_remote_device_state_handler_table, 1359 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING 1360 ); 1361} 1362 1363static void scic_sds_remote_device_failed_state_enter( 1364 struct sci_base_object *object) 1365{ 1366 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; 1367 1368 SET_STATE_HANDLER( 1369 sci_dev, 1370 scic_sds_remote_device_state_handler_table, 1371 SCI_BASE_REMOTE_DEVICE_STATE_FAILED 1372 ); 1373} 1374 1375static void scic_sds_remote_device_resetting_state_enter( 1376 struct sci_base_object *object) 1377{ 1378 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; 1379 1380 SET_STATE_HANDLER( 1381 sci_dev, 1382 scic_sds_remote_device_state_handler_table, 1383 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING 1384 ); 1385 1386 scic_sds_remote_node_context_suspend( 1387 &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL); 1388} 1389 1390static void scic_sds_remote_device_resetting_state_exit( 1391 struct sci_base_object *object) 1392{ 1393 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; 1394 1395 scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL); 1396} 1397 1398static void scic_sds_remote_device_final_state_enter( 1399 struct sci_base_object *object) 1400{ 1401 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object; 1402 1403 SET_STATE_HANDLER( 1404 sci_dev, 1405 scic_sds_remote_device_state_handler_table, 1406 SCI_BASE_REMOTE_DEVICE_STATE_FINAL 1407 ); 1408} 1409 1410 1411static const struct sci_base_state scic_sds_remote_device_state_table[] = { 1412 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = { 1413 .enter_state = scic_sds_remote_device_initial_state_enter, 1414 }, 1415 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = { 1416 .enter_state = scic_sds_remote_device_stopped_state_enter, 1417 }, 1418 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = { 1419 .enter_state = scic_sds_remote_device_starting_state_enter, 1420 }, 1421 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = { 1422 .enter_state = scic_sds_remote_device_ready_state_enter, 1423 .exit_state = scic_sds_remote_device_ready_state_exit 1424 }, 1425 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = { 1426 .enter_state = scic_sds_remote_device_stopping_state_enter, 1427 }, 1428 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = { 1429 .enter_state = scic_sds_remote_device_failed_state_enter, 1430 }, 1431 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = { 1432 .enter_state = scic_sds_remote_device_resetting_state_enter, 1433 .exit_state = scic_sds_remote_device_resetting_state_exit 1434 }, 1435 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = { 1436 .enter_state = scic_sds_remote_device_final_state_enter, 1437 }, 1438}; 1439 |
|
102/** | 1440/** |
1441 * scic_remote_device_construct() - This method will perform the construction 1442 * common to all remote device objects. 1443 * @sci_port: SAS/SATA port through which this device is accessed. 1444 * @sci_dev: remote device to construct 1445 * 1446 * It isn't necessary to call scic_remote_device_destruct() for device objects 1447 * that have only called this method for construction. Once subsequent 1448 * construction methods have been invoked (e.g. 1449 * scic_remote_device_da_construct()), then destruction should occur. none 1450 */ 1451static void scic_remote_device_construct(struct scic_sds_port *sci_port, 1452 struct scic_sds_remote_device *sci_dev) 1453{ 1454 sci_dev->owning_port = sci_port; 1455 sci_dev->started_request_count = 0; 1456 sci_dev->parent.private = NULL; 1457 1458 sci_base_state_machine_construct( 1459 &sci_dev->state_machine, 1460 &sci_dev->parent, 1461 scic_sds_remote_device_state_table, 1462 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL 1463 ); 1464 1465 sci_base_state_machine_start( 1466 &sci_dev->state_machine 1467 ); 1468 1469 scic_sds_remote_node_context_construct(&sci_dev->rnc, 1470 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); 1471 1472 sci_object_set_association(&sci_dev->rnc, sci_dev); 1473} 1474 1475/** 1476 * scic_remote_device_da_construct() - This method will construct a 1477 * SCIC_REMOTE_DEVICE object for a direct attached (da) device. The 1478 * information (e.g. IAF, Signature FIS, etc.) necessary to build the device 1479 * is known to the SCI Core since it is contained in the scic_phy object. 1480 * @remote_device: This parameter specifies the remote device to be destructed. 1481 * 1482 * The user must have previously called scic_remote_device_construct() Remote 1483 * device objects are a limited resource. As such, they must be protected. 1484 * Thus calls to construct and destruct are mutually exclusive and 1485 * non-reentrant. Indicate if the remote device was successfully constructed. 1486 * SCI_SUCCESS Returned if the device was successfully constructed. 1487 * SCI_FAILURE_DEVICE_EXISTS Returned if the device has already been 1488 * constructed. If it's an additional phy for the target, then call 1489 * scic_remote_device_da_add_phy(). SCI_FAILURE_UNSUPPORTED_PROTOCOL Returned 1490 * if the supplied parameters necessitate creation of a remote device for which 1491 * the protocol is not supported by the underlying controller hardware. 1492 * SCI_FAILURE_INSUFFICIENT_RESOURCES This value is returned if the core 1493 * controller associated with the supplied parameters is unable to support 1494 * additional remote devices. 1495 */ 1496static enum sci_status scic_remote_device_da_construct(struct scic_sds_remote_device *sci_dev) 1497{ 1498 enum sci_status status; 1499 u16 remote_node_index; 1500 struct sci_sas_identify_address_frame_protocols protocols; 1501 1502 /* 1503 * This information is request to determine how many remote node context 1504 * entries will be needed to store the remote node. 1505 */ 1506 scic_sds_port_get_attached_protocols(sci_dev->owning_port, &protocols); 1507 sci_dev->target_protocols.u.all = protocols.u.all; 1508 sci_dev->is_direct_attached = true; 1509#if !defined(DISABLE_ATAPI) 1510 sci_dev->is_atapi = scic_sds_remote_device_is_atapi(sci_dev); 1511#endif 1512 1513 status = scic_sds_controller_allocate_remote_node_context( 1514 sci_dev->owning_port->owning_controller, 1515 sci_dev, 1516 &remote_node_index); 1517 1518 if (status == SCI_SUCCESS) { 1519 sci_dev->rnc.remote_node_index = remote_node_index; 1520 1521 scic_sds_port_get_attached_sas_address( 1522 sci_dev->owning_port, &sci_dev->device_address); 1523 1524 if (sci_dev->target_protocols.u.bits.attached_ssp_target) { 1525 sci_dev->has_ready_substate_machine = false; 1526 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) { 1527 sci_dev->has_ready_substate_machine = true; 1528 1529 sci_base_state_machine_construct( 1530 &sci_dev->ready_substate_machine, 1531 &sci_dev->parent, 1532 scic_sds_stp_remote_device_ready_substate_table, 1533 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); 1534 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) { 1535 sci_dev->has_ready_substate_machine = true; 1536 1537 /* add the SMP ready substate machine construction here */ 1538 sci_base_state_machine_construct( 1539 &sci_dev->ready_substate_machine, 1540 &sci_dev->parent, 1541 scic_sds_smp_remote_device_ready_substate_table, 1542 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); 1543 } 1544 1545 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed( 1546 sci_dev->owning_port); 1547 1548 /* / @todo Should I assign the port width by reading all of the phys on the port? */ 1549 sci_dev->device_port_width = 1; 1550 } 1551 1552 return status; 1553} 1554 1555static void scic_sds_remote_device_get_info_from_smp_discover_response( 1556 struct scic_sds_remote_device *sci_dev, 1557 struct smp_response_discover *discover_response) 1558{ 1559 /* decode discover_response to set sas_address to sci_dev. */ 1560 sci_dev->device_address.high = 1561 discover_response->attached_sas_address.high; 1562 1563 sci_dev->device_address.low = 1564 discover_response->attached_sas_address.low; 1565 1566 sci_dev->target_protocols.u.all = discover_response->protocols.u.all; 1567} 1568 1569/** 1570 * scic_remote_device_ea_construct() - This method will construct an 1571 * SCIC_REMOTE_DEVICE object for an expander attached (ea) device from an 1572 * SMP Discover Response. 1573 * @remote_device: This parameter specifies the remote device to be destructed. 1574 * @discover_response: This parameter specifies the SMP Discovery Response to 1575 * be used in device creation. 1576 * 1577 * The user must have previously called scic_remote_device_construct() Remote 1578 * device objects are a limited resource. As such, they must be protected. 1579 * Thus calls to construct and destruct are mutually exclusive and 1580 * non-reentrant. Indicate if the remote device was successfully constructed. 1581 * SCI_SUCCESS Returned if the device was successfully constructed. 1582 * SCI_FAILURE_DEVICE_EXISTS Returned if the device has already been 1583 * constructed. If it's an additional phy for the target, then call 1584 * scic_ea_remote_device_add_phy(). SCI_FAILURE_UNSUPPORTED_PROTOCOL Returned 1585 * if the supplied parameters necessitate creation of a remote device for which 1586 * the protocol is not supported by the underlying controller hardware. 1587 * SCI_FAILURE_INSUFFICIENT_RESOURCES This value is returned if the core 1588 * controller associated with the supplied parameters is unable to support 1589 * additional remote devices. 1590 */ 1591static enum sci_status scic_remote_device_ea_construct(struct scic_sds_remote_device *sci_dev, 1592 struct smp_response_discover *discover_response) 1593{ 1594 enum sci_status status; 1595 struct scic_sds_controller *scic; 1596 1597 scic = scic_sds_port_get_controller(sci_dev->owning_port); 1598 1599 scic_sds_remote_device_get_info_from_smp_discover_response( 1600 sci_dev, discover_response); 1601 1602 status = scic_sds_controller_allocate_remote_node_context( 1603 scic, sci_dev, &sci_dev->rnc.remote_node_index); 1604 1605 if (status == SCI_SUCCESS) { 1606 if (sci_dev->target_protocols.u.bits.attached_ssp_target) { 1607 sci_dev->has_ready_substate_machine = false; 1608 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) { 1609 sci_dev->has_ready_substate_machine = true; 1610 1611 /* add the SMP ready substate machine construction here */ 1612 sci_base_state_machine_construct( 1613 &sci_dev->ready_substate_machine, 1614 &sci_dev->parent, 1615 scic_sds_smp_remote_device_ready_substate_table, 1616 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); 1617 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) { 1618 sci_dev->has_ready_substate_machine = true; 1619 1620 sci_base_state_machine_construct( 1621 &sci_dev->ready_substate_machine, 1622 &sci_dev->parent, 1623 scic_sds_stp_remote_device_ready_substate_table, 1624 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE); 1625 } 1626 1627 /* 1628 * For SAS-2 the physical link rate is actually a logical link 1629 * rate that incorporates multiplexing. The SCU doesn't 1630 * incorporate multiplexing and for the purposes of the 1631 * connection the logical link rate is that same as the 1632 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay 1633 * one another, so this code works for both situations. */ 1634 sci_dev->connection_rate = min_t(u16, 1635 scic_sds_port_get_max_allowed_speed(sci_dev->owning_port), 1636 discover_response->u2.sas1_1.negotiated_physical_link_rate 1637 ); 1638 1639 /* / @todo Should I assign the port width by reading all of the phys on the port? */ 1640 sci_dev->device_port_width = 1; 1641 } 1642 1643 return status; 1644} 1645 1646/** 1647 * scic_remote_device_start() - This method will start the supplied remote 1648 * device. This method enables normal IO requests to flow through to the 1649 * remote device. 1650 * @remote_device: This parameter specifies the device to be started. 1651 * @timeout: This parameter specifies the number of milliseconds in which the 1652 * start operation should complete. 1653 * 1654 * An indication of whether the device was successfully started. SCI_SUCCESS 1655 * This value is returned if the device was successfully started. 1656 * SCI_FAILURE_INVALID_PHY This value is returned if the user attempts to start 1657 * the device when there have been no phys added to it. 1658 */ 1659static enum sci_status scic_remote_device_start(struct scic_sds_remote_device *sci_dev, 1660 u32 timeout) 1661{ 1662 return sci_dev->state_handlers->start_handler(sci_dev); 1663} 1664 1665/** |
|
103 * isci_remote_device_construct() - This function calls the scic remote device 104 * construct and start functions, it waits on the remote device start 105 * completion. 106 * @port: This parameter specifies the isci port with the remote device. 107 * @isci_device: This parameter specifies the isci remote device 108 * 109 * status from the scic calls, the caller to this function should clean up 110 * resources as appropriate. --- 191 unchanged lines hidden (view full) --- 302 if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED) 303 isci_remote_device_change_state(idev, isci_stopping); 304 else 305 /* device ready is actually a "not ready for io" state. */ 306 isci_remote_device_change_state(idev, isci_ready); 307} 308 309/** | 1666 * isci_remote_device_construct() - This function calls the scic remote device 1667 * construct and start functions, it waits on the remote device start 1668 * completion. 1669 * @port: This parameter specifies the isci port with the remote device. 1670 * @isci_device: This parameter specifies the isci remote device 1671 * 1672 * status from the scic calls, the caller to this function should clean up 1673 * resources as appropriate. --- 191 unchanged lines hidden (view full) --- 1865 if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED) 1866 isci_remote_device_change_state(idev, isci_stopping); 1867 else 1868 /* device ready is actually a "not ready for io" state. */ 1869 isci_remote_device_change_state(idev, isci_ready); 1870} 1871 1872/** |
310 * isci_remote_device_stop_complete() - This function is called by the scic 311 * when the remote device stop has completed. We mark the isci device as not 312 * ready and remove the isci remote device. 313 * @isci_host: This parameter specifies the isci host object. 314 * @isci_device: This parameter specifies the remote device. 315 * @status: This parameter specifies status of the completion. 316 * 317 */ 318void isci_remote_device_stop_complete( 319 struct isci_host *isci_host, 320 struct isci_remote_device *isci_device, 321 enum sci_status status) 322{ 323 dev_dbg(&isci_host->pdev->dev, 324 "%s: complete isci_device = %p, status = 0x%x\n", 325 __func__, 326 isci_device, 327 status); 328 329 isci_remote_device_change_state(isci_device, isci_stopped); 330 331 /* after stop, we can tear down resources. */ 332 isci_remote_device_deconstruct(isci_host, isci_device); 333 334} 335 336/** 337 * isci_remote_device_start_complete() - This function is called by the scic 338 * when the remote device start has completed 339 * @isci_host: This parameter specifies the isci host object. 340 * @isci_device: This parameter specifies the remote device. 341 * @status: This parameter specifies status of the completion. 342 * 343 */ 344void isci_remote_device_start_complete( 345 struct isci_host *isci_host, 346 struct isci_remote_device *isci_device, 347 enum sci_status status) 348{ 349 350 351} 352 353 354/** | |
355 * isci_remote_device_stop() - This function is called internally to stop the 356 * remote device. 357 * @isci_host: This parameter specifies the isci host object. 358 * @isci_device: This parameter specifies the remote device. 359 * 360 * The status of the scic request to stop. 361 */ 362enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) --- 204 unchanged lines hidden (view full) --- 567 568 spin_lock_irqsave(&task->task_state_lock, flags2); 569 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; 570 spin_unlock_irqrestore(&task->task_state_lock, flags2); 571 } 572 } 573 spin_unlock_irqrestore(&ihost->scic_lock, flags); 574} | 1873 * isci_remote_device_stop() - This function is called internally to stop the 1874 * remote device. 1875 * @isci_host: This parameter specifies the isci host object. 1876 * @isci_device: This parameter specifies the remote device. 1877 * 1878 * The status of the scic request to stop. 1879 */ 1880enum sci_status isci_remote_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) --- 204 unchanged lines hidden (view full) --- 2085 2086 spin_lock_irqsave(&task->task_state_lock, flags2); 2087 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET; 2088 spin_unlock_irqrestore(&task->task_state_lock, flags2); 2089 } 2090 } 2091 spin_unlock_irqrestore(&ihost->scic_lock, flags); 2092} |
575 576/** 577 * isci_remote_device_change_state() - This function gets the status of the 578 * remote_device object. 579 * @isci_device: This parameter points to the isci_remote_device object 580 * 581 * status of the object as a isci_status enum. 582 */ 583void isci_remote_device_change_state( 584 struct isci_remote_device *isci_device, 585 enum isci_status status) 586{ 587 unsigned long flags; 588 589 spin_lock_irqsave(&isci_device->state_lock, flags); 590 isci_device->status = status; 591 spin_unlock_irqrestore(&isci_device->state_lock, flags); 592} | |