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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
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.
56 #include "intel_sas.h"
57 #include "scic_controller.h"
59 #include "scic_port.h"
60 #include "scic_remote_device.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "scic_sds_remote_device.h"
65 #include "scic_sds_remote_node_context.h"
66 #include "scic_sds_request.h"
67 #include "sci_environment.h"
69 #include "scu_event_codes.h"
72 #define SCIC_SDS_REMOTE_DEVICE_RESET_TIMEOUT (1000)
75 * *****************************************************************************
76 * * CORE REMOTE DEVICE PRIVATE METHODS
77 * ***************************************************************************** */
80 * *****************************************************************************
81 * * CORE REMOTE DEVICE PUBLIC METHODS
82 * ***************************************************************************** */
84 u32 scic_remote_device_get_object_size(void)
86 return sizeof (struct scic_sds_remote_device);
89 enum sci_status scic_remote_device_da_construct(
90 struct scic_sds_remote_device *sci_dev)
92 enum sci_status status;
93 u16 remote_node_index;
94 struct sci_sas_identify_address_frame_protocols protocols;
97 * This information is request to determine how many remote node context
98 * entries will be needed to store the remote node.
100 scic_sds_port_get_attached_protocols(sci_dev->owning_port, &protocols);
101 sci_dev->target_protocols.u.all = protocols.u.all;
102 sci_dev->is_direct_attached = true;
103 #if !defined(DISABLE_ATAPI)
104 sci_dev->is_atapi = scic_sds_remote_device_is_atapi(sci_dev);
107 status = scic_sds_controller_allocate_remote_node_context(
108 sci_dev->owning_port->owning_controller,
112 if (status == SCI_SUCCESS) {
113 sci_dev->rnc.remote_node_index = remote_node_index;
115 scic_sds_port_get_attached_sas_address(
116 sci_dev->owning_port, &sci_dev->device_address);
118 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
119 sci_dev->has_ready_substate_machine = false;
120 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
121 sci_dev->has_ready_substate_machine = true;
123 sci_base_state_machine_construct(
124 &sci_dev->ready_substate_machine,
126 scic_sds_stp_remote_device_ready_substate_table,
127 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
128 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
129 sci_dev->has_ready_substate_machine = true;
131 /* add the SMP ready substate machine construction here */
132 sci_base_state_machine_construct(
133 &sci_dev->ready_substate_machine,
135 scic_sds_smp_remote_device_ready_substate_table,
136 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
139 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(
140 sci_dev->owning_port);
142 /* / @todo Should I assign the port width by reading all of the phys on the port? */
143 sci_dev->device_port_width = 1;
150 static void scic_sds_remote_device_get_info_from_smp_discover_response(
151 struct scic_sds_remote_device *sci_dev,
152 struct smp_response_discover *discover_response)
154 /* decode discover_response to set sas_address to sci_dev. */
155 sci_dev->device_address.high =
156 discover_response->attached_sas_address.high;
158 sci_dev->device_address.low =
159 discover_response->attached_sas_address.low;
161 sci_dev->target_protocols.u.all = discover_response->protocols.u.all;
165 enum sci_status scic_remote_device_ea_construct(
166 struct scic_sds_remote_device *sci_dev,
167 struct smp_response_discover *discover_response)
169 enum sci_status status;
170 struct scic_sds_controller *scic;
172 scic = scic_sds_port_get_controller(sci_dev->owning_port);
174 scic_sds_remote_device_get_info_from_smp_discover_response(
175 sci_dev, discover_response);
177 status = scic_sds_controller_allocate_remote_node_context(
178 scic, sci_dev, &sci_dev->rnc.remote_node_index);
180 if (status == SCI_SUCCESS) {
181 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
182 sci_dev->has_ready_substate_machine = false;
183 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
184 sci_dev->has_ready_substate_machine = true;
186 /* add the SMP ready substate machine construction here */
187 sci_base_state_machine_construct(
188 &sci_dev->ready_substate_machine,
190 scic_sds_smp_remote_device_ready_substate_table,
191 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
192 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
193 sci_dev->has_ready_substate_machine = true;
195 sci_base_state_machine_construct(
196 &sci_dev->ready_substate_machine,
198 scic_sds_stp_remote_device_ready_substate_table,
199 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
203 * For SAS-2 the physical link rate is actually a logical link
204 * rate that incorporates multiplexing. The SCU doesn't
205 * incorporate multiplexing and for the purposes of the
206 * connection the logical link rate is that same as the
207 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
208 * one another, so this code works for both situations. */
209 sci_dev->connection_rate = min_t(u16,
210 scic_sds_port_get_max_allowed_speed(sci_dev->owning_port),
211 discover_response->u2.sas1_1.negotiated_physical_link_rate
214 /* / @todo Should I assign the port width by reading all of the phys on the port? */
215 sci_dev->device_port_width = 1;
221 enum sci_status scic_remote_device_destruct(
222 struct scic_sds_remote_device *sci_dev)
224 return sci_dev->state_handlers->destruct_handler(sci_dev);
228 enum sci_status scic_remote_device_start(
229 struct scic_sds_remote_device *sci_dev,
232 return sci_dev->state_handlers->start_handler(sci_dev);
236 enum sci_status scic_remote_device_stop(
237 struct scic_sds_remote_device *sci_dev,
240 return sci_dev->state_handlers->stop_handler(sci_dev);
244 enum sci_status scic_remote_device_reset(
245 struct scic_sds_remote_device *sci_dev)
247 return sci_dev->state_handlers->reset_handler(sci_dev);
251 enum sci_status scic_remote_device_reset_complete(
252 struct scic_sds_remote_device *sci_dev)
254 return sci_dev->state_handlers->reset_complete_handler(sci_dev);
258 enum sas_linkrate scic_remote_device_get_connection_rate(
259 struct scic_sds_remote_device *sci_dev)
261 return sci_dev->connection_rate;
265 void scic_remote_device_get_protocols(
266 struct scic_sds_remote_device *sci_dev,
267 struct smp_discover_response_protocols *pr)
269 pr->u.all = sci_dev->target_protocols.u.all;
272 #if !defined(DISABLE_ATAPI)
273 bool scic_remote_device_is_atapi(struct scic_sds_remote_device *sci_dev)
275 return sci_dev->is_atapi;
281 * *****************************************************************************
282 * * SCU DRIVER STANDARD (SDS) REMOTE DEVICE IMPLEMENTATIONS
283 * ***************************************************************************** */
288 * Remote device timer requirements
290 #define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
291 #define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
296 * @sci_dev: The remote device for which the suspend is being requested.
298 * This method invokes the remote device suspend state handler. enum sci_status
300 enum sci_status scic_sds_remote_device_suspend(
301 struct scic_sds_remote_device *sci_dev,
304 return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type);
309 * @sci_dev: The remote device for which the resume is being requested.
311 * This method invokes the remote device resume state handler. enum sci_status
313 enum sci_status scic_sds_remote_device_resume(
314 struct scic_sds_remote_device *sci_dev)
316 return sci_dev->state_handlers->resume_handler(sci_dev);
321 * @sci_dev: The remote device for which the event handling is being
323 * @frame_index: This is the frame index that is being processed.
325 * This method invokes the frame handler for the remote device state machine
328 enum sci_status scic_sds_remote_device_frame_handler(
329 struct scic_sds_remote_device *sci_dev,
332 return sci_dev->state_handlers->frame_handler(sci_dev, frame_index);
337 * @sci_dev: The remote device for which the event handling is being
339 * @event_code: This is the event code that is to be processed.
341 * This method invokes the remote device event handler. enum sci_status
343 enum sci_status scic_sds_remote_device_event_handler(
344 struct scic_sds_remote_device *sci_dev,
347 return sci_dev->state_handlers->event_handler(sci_dev, event_code);
352 * @controller: The controller that is starting the io request.
353 * @sci_dev: The remote device for which the start io handling is being
355 * @io_request: The io request that is being started.
357 * This method invokes the remote device start io handler. enum sci_status
359 enum sci_status scic_sds_remote_device_start_io(
360 struct scic_sds_controller *controller,
361 struct scic_sds_remote_device *sci_dev,
362 struct scic_sds_request *io_request)
364 return sci_dev->state_handlers->start_io_handler(
365 sci_dev, io_request);
370 * @controller: The controller that is completing the io request.
371 * @sci_dev: The remote device for which the complete io handling is being
373 * @io_request: The io request that is being completed.
375 * This method invokes the remote device complete io handler. enum sci_status
377 enum sci_status scic_sds_remote_device_complete_io(
378 struct scic_sds_controller *controller,
379 struct scic_sds_remote_device *sci_dev,
380 struct scic_sds_request *io_request)
382 return sci_dev->state_handlers->complete_io_handler(
383 sci_dev, io_request);
388 * @controller: The controller that is starting the task request.
389 * @sci_dev: The remote device for which the start task handling is being
391 * @io_request: The task request that is being started.
393 * This method invokes the remote device start task handler. enum sci_status
395 enum sci_status scic_sds_remote_device_start_task(
396 struct scic_sds_controller *controller,
397 struct scic_sds_remote_device *sci_dev,
398 struct scic_sds_request *io_request)
400 return sci_dev->state_handlers->start_task_handler(
401 sci_dev, io_request);
406 * @controller: The controller that is completing the task request.
407 * @sci_dev: The remote device for which the complete task handling is
409 * @io_request: The task request that is being completed.
411 * This method invokes the remote device complete task handler. enum sci_status
419 * This method takes the request and bulids an appropriate SCU context for the
420 * request and then requests the controller to post the request. none
422 void scic_sds_remote_device_post_request(
423 struct scic_sds_remote_device *sci_dev,
428 context = scic_sds_remote_device_build_command_context(sci_dev, request);
430 scic_sds_controller_post_request(
431 scic_sds_remote_device_get_controller(sci_dev),
436 #if !defined(DISABLE_ATAPI)
439 * @sci_dev: The device to be checked.
441 * This method check the signature fis of a stp device to decide whether a
442 * device is atapi or not. true if a device is atapi device. False if a device
445 bool scic_sds_remote_device_is_atapi(
446 struct scic_sds_remote_device *sci_dev)
448 if (!sci_dev->target_protocols.u.bits.attached_stp_target)
450 else if (sci_dev->is_direct_attached) {
451 struct scic_sds_phy *phy;
452 struct scic_sata_phy_properties properties;
453 struct sata_fis_reg_d2h *signature_fis;
454 phy = scic_sds_port_get_a_connected_phy(sci_dev->owning_port);
455 scic_sata_phy_get_properties(phy, &properties);
457 /* decode the signature fis. */
458 signature_fis = &(properties.signature_fis);
460 if ((signature_fis->sector_count == 0x01)
461 && (signature_fis->lba_low == 0x01)
462 && (signature_fis->lba_mid == 0x14)
463 && (signature_fis->lba_high == 0xEB)
464 && ((signature_fis->device & 0x5F) == 0x00)
466 /* An ATA device supporting the PACKET command set. */
471 /* Expander supported ATAPI device is not currently supported. */
479 * @user_parameter: This is cast to a remote device object.
481 * This method is called once the remote node context is ready to be freed.
482 * The remote device can now report that its stop operation is complete. none
484 static void scic_sds_cb_remote_device_rnc_destruct_complete(
485 void *user_parameter)
487 struct scic_sds_remote_device *sci_dev;
489 sci_dev = (struct scic_sds_remote_device *)user_parameter;
491 BUG_ON(sci_dev->started_request_count != 0);
493 sci_base_state_machine_change_state(&sci_dev->state_machine,
494 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
499 * @user_parameter: This is cast to a remote device object.
501 * This method is called once the remote node context has transisitioned to a
502 * ready state. This is the indication that the remote device object can also
503 * transition to ready. none
505 static void scic_sds_remote_device_resume_complete_handler(
506 void *user_parameter)
508 struct scic_sds_remote_device *sci_dev;
510 sci_dev = (struct scic_sds_remote_device *)user_parameter;
513 sci_base_state_machine_get_state(&sci_dev->state_machine)
514 != SCI_BASE_REMOTE_DEVICE_STATE_READY
516 sci_base_state_machine_change_state(
517 &sci_dev->state_machine,
518 SCI_BASE_REMOTE_DEVICE_STATE_READY
525 * @device: This parameter specifies the device for which the request is being
527 * @request: This parameter specifies the request being started.
528 * @status: This parameter specifies the current start operation status.
530 * This method will perform the STP request start processing common to IO
531 * requests and task requests of all types. none
533 void scic_sds_remote_device_start_request(
534 struct scic_sds_remote_device *sci_dev,
535 struct scic_sds_request *sci_req,
536 enum sci_status status)
538 /* We still have a fault in starting the io complete it on the port */
539 if (status == SCI_SUCCESS)
540 scic_sds_remote_device_increment_request_count(sci_dev);
542 sci_dev->owning_port->state_handlers->complete_io_handler(
543 sci_dev->owning_port, sci_dev, sci_req
551 * @request: This parameter specifies the request being continued.
553 * This method will continue to post tc for a STP request. This method usually
554 * serves as a callback when RNC gets resumed during a task management
557 void scic_sds_remote_device_continue_request(void *dev)
559 struct scic_sds_remote_device *sci_dev = dev;
561 /* we need to check if this request is still valid to continue. */
562 if (sci_dev->working_request)
563 scic_controller_continue_io(sci_dev->working_request);
568 * @user_parameter: This is cast to a remote device object.
570 * This method is called once the remote node context has reached a suspended
571 * state. The remote device can now report that its suspend operation is
576 * This method will terminate all of the IO requests in the controllers IO
577 * request table that were targeted for this device.
578 * @sci_dev: This parameter specifies the remote device for which to
579 * attempt to terminate all requests.
581 * This method returns an indication as to whether all requests were
582 * successfully terminated. If a single request fails to be terminated, then
583 * this method will return the failure.
585 static enum sci_status scic_sds_remote_device_terminate_requests(
586 struct scic_sds_remote_device *sci_dev)
588 enum sci_status status = SCI_SUCCESS;
589 enum sci_status terminate_status = SCI_SUCCESS;
590 struct scic_sds_request *sci_req;
592 u32 request_count = sci_dev->started_request_count;
595 (index < SCI_MAX_IO_REQUESTS) && (request_count > 0);
597 sci_req = sci_dev->owning_port->owning_controller->io_request_table[index];
599 if ((sci_req != NULL) && (sci_req->target_device == sci_dev)) {
600 terminate_status = scic_controller_terminate_request(
601 sci_dev->owning_port->owning_controller,
606 if (terminate_status != SCI_SUCCESS)
607 status = terminate_status;
616 static enum sci_status
617 default_device_handler(struct scic_sds_remote_device *sci_dev,
620 dev_warn(scirdev_to_dev(sci_dev),
621 "%s: in wrong state: %d\n", func,
622 sci_base_state_machine_get_state(&sci_dev->state_machine));
623 return SCI_FAILURE_INVALID_STATE;
626 enum sci_status scic_sds_remote_device_default_start_handler(
627 struct scic_sds_remote_device *sci_dev)
629 return default_device_handler(sci_dev, __func__);
632 static enum sci_status scic_sds_remote_device_default_stop_handler(
633 struct scic_sds_remote_device *sci_dev)
635 return default_device_handler(sci_dev, __func__);
638 enum sci_status scic_sds_remote_device_default_fail_handler(
639 struct scic_sds_remote_device *sci_dev)
641 return default_device_handler(sci_dev, __func__);
644 enum sci_status scic_sds_remote_device_default_destruct_handler(
645 struct scic_sds_remote_device *sci_dev)
647 return default_device_handler(sci_dev, __func__);
650 enum sci_status scic_sds_remote_device_default_reset_handler(
651 struct scic_sds_remote_device *sci_dev)
653 return default_device_handler(sci_dev, __func__);
656 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
657 struct scic_sds_remote_device *sci_dev)
659 return default_device_handler(sci_dev, __func__);
662 enum sci_status scic_sds_remote_device_default_suspend_handler(
663 struct scic_sds_remote_device *sci_dev, u32 suspend_type)
665 return default_device_handler(sci_dev, __func__);
668 enum sci_status scic_sds_remote_device_default_resume_handler(
669 struct scic_sds_remote_device *sci_dev)
671 return default_device_handler(sci_dev, __func__);
676 * @device: The struct scic_sds_remote_device which is then cast into a
677 * struct scic_sds_remote_device.
678 * @event_code: The event code that the struct scic_sds_controller wants the device
681 * This method is the default event handler. It will call the RNC state
682 * machine handler for any RNC events otherwise it will log a warning and
683 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
685 static enum sci_status scic_sds_remote_device_core_event_handler(
686 struct scic_sds_remote_device *sci_dev,
690 enum sci_status status;
692 switch (scu_get_event_type(event_code)) {
693 case SCU_EVENT_TYPE_RNC_OPS_MISC:
694 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
695 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
696 status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code);
698 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
700 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
701 status = SCI_SUCCESS;
703 /* Suspend the associated RNC */
704 scic_sds_remote_node_context_suspend(&sci_dev->rnc,
705 SCI_SOFTWARE_SUSPENSION,
708 dev_dbg(scirdev_to_dev(sci_dev),
709 "%s: device: %p event code: %x: %s\n",
710 __func__, sci_dev, event_code,
712 ? "I_T_Nexus_Timeout event"
713 : "I_T_Nexus_Timeout event in wrong state");
717 /* Else, fall through and treat as unhandled... */
720 dev_dbg(scirdev_to_dev(sci_dev),
721 "%s: device: %p event code: %x: %s\n",
722 __func__, sci_dev, event_code,
725 : "unexpected event in wrong state");
726 status = SCI_FAILURE_INVALID_STATE;
734 * @device: The struct scic_sds_remote_device which is then cast into a
735 * struct scic_sds_remote_device.
736 * @event_code: The event code that the struct scic_sds_controller wants the device
739 * This method is the default event handler. It will call the RNC state
740 * machine handler for any RNC events otherwise it will log a warning and
741 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
743 static enum sci_status scic_sds_remote_device_default_event_handler(
744 struct scic_sds_remote_device *sci_dev,
747 return scic_sds_remote_device_core_event_handler(sci_dev,
754 * @device: The struct scic_sds_remote_device which is then cast into a
755 * struct scic_sds_remote_device.
756 * @frame_index: The frame index for which the struct scic_sds_controller wants this
757 * device object to process.
759 * This method is the default unsolicited frame handler. It logs a warning,
760 * releases the frame and returns a failure. enum sci_status
761 * SCI_FAILURE_INVALID_STATE
763 enum sci_status scic_sds_remote_device_default_frame_handler(
764 struct scic_sds_remote_device *sci_dev,
767 dev_warn(scirdev_to_dev(sci_dev),
768 "%s: SCIC Remote Device requested to handle frame %x "
769 "while in wrong state %d\n",
772 sci_base_state_machine_get_state(
773 &sci_dev->state_machine));
775 /* Return the frame back to the controller */
776 scic_sds_controller_release_frame(
777 scic_sds_remote_device_get_controller(sci_dev), frame_index
780 return SCI_FAILURE_INVALID_STATE;
783 enum sci_status scic_sds_remote_device_default_start_request_handler(
784 struct scic_sds_remote_device *sci_dev,
785 struct scic_sds_request *request)
787 return default_device_handler(sci_dev, __func__);
790 enum sci_status scic_sds_remote_device_default_complete_request_handler(
791 struct scic_sds_remote_device *sci_dev,
792 struct scic_sds_request *request)
794 return default_device_handler(sci_dev, __func__);
797 enum sci_status scic_sds_remote_device_default_continue_request_handler(
798 struct scic_sds_remote_device *sci_dev,
799 struct scic_sds_request *request)
801 return default_device_handler(sci_dev, __func__);
806 * @device: The struct scic_sds_remote_device which is then cast into a
807 * struct scic_sds_remote_device.
808 * @frame_index: The frame index for which the struct scic_sds_controller wants this
809 * device object to process.
811 * This method is a general ssp frame handler. In most cases the device object
812 * needs to route the unsolicited frame processing to the io request object.
813 * This method decodes the tag for the io request object and routes the
814 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
816 enum sci_status scic_sds_remote_device_general_frame_handler(
817 struct scic_sds_remote_device *sci_dev,
820 enum sci_status result;
821 struct sci_ssp_frame_header *frame_header;
822 struct scic_sds_request *io_request;
824 result = scic_sds_unsolicited_frame_control_get_header(
825 &(scic_sds_remote_device_get_controller(sci_dev)->uf_control),
827 (void **)&frame_header
830 if (SCI_SUCCESS == result) {
831 io_request = scic_sds_controller_get_io_request_from_tag(
832 scic_sds_remote_device_get_controller(sci_dev), frame_header->tag);
834 if ((io_request == NULL)
835 || (io_request->target_device != sci_dev)) {
837 * We could not map this tag to a valid IO request
838 * Just toss the frame and continue */
839 scic_sds_controller_release_frame(
840 scic_sds_remote_device_get_controller(sci_dev), frame_index
843 /* The IO request is now in charge of releasing the frame */
844 result = io_request->state_handlers->frame_handler(
845 io_request, frame_index);
854 * @[in]: sci_dev This is the device object that is receiving the event.
855 * @[in]: event_code The event code to process.
857 * This is a common method for handling events reported to the remote device
858 * from the controller object. enum sci_status
860 enum sci_status scic_sds_remote_device_general_event_handler(
861 struct scic_sds_remote_device *sci_dev,
864 return scic_sds_remote_device_core_event_handler(sci_dev,
870 * *****************************************************************************
871 * * STOPPED STATE HANDLERS
872 * ***************************************************************************** */
878 * This method takes the struct scic_sds_remote_device from a stopped state and
879 * attempts to start it. The RNC buffer for the device is constructed and the
880 * device state machine is transitioned to the
881 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is
882 * an RNC buffer available to construct the remote device.
883 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in
884 * which to construct the remote device.
886 static enum sci_status scic_sds_remote_device_stopped_state_start_handler(
887 struct scic_sds_remote_device *sci_dev)
889 enum sci_status status;
891 status = scic_sds_remote_node_context_resume(&sci_dev->rnc,
892 scic_sds_remote_device_resume_complete_handler, sci_dev);
894 if (status == SCI_SUCCESS)
895 sci_base_state_machine_change_state(&sci_dev->state_machine,
896 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
901 static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
902 struct scic_sds_remote_device *sci_dev)
909 * @sci_dev: The struct scic_sds_remote_device which is cast into a
910 * struct scic_sds_remote_device.
912 * This method will destruct a struct scic_sds_remote_device that is in a stopped
913 * state. This is the only state from which a destruct request will succeed.
914 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
915 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
916 * enum sci_status SCI_SUCCESS
918 static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
919 struct scic_sds_remote_device *sci_dev)
921 struct scic_sds_controller *scic;
923 scic = scic_sds_remote_device_get_controller(sci_dev);
924 scic_sds_controller_free_remote_node_context(scic, sci_dev,
925 sci_dev->rnc.remote_node_index);
926 sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
928 sci_base_state_machine_change_state(&sci_dev->state_machine,
929 SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
935 * *****************************************************************************
936 * * STARTING STATE HANDLERS
937 * ***************************************************************************** */
939 static enum sci_status scic_sds_remote_device_starting_state_stop_handler(
940 struct scic_sds_remote_device *sci_dev)
943 * This device has not yet started so there had better be no IO requests
945 BUG_ON(sci_dev->started_request_count != 0);
948 * Destroy the remote node context
950 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
951 scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev);
954 * Transition to the stopping state and wait for the remote node to
955 * complete being posted and invalidated.
957 sci_base_state_machine_change_state(&sci_dev->state_machine,
958 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
963 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
964 struct scic_sds_remote_device *sci_dev)
966 enum sci_status status = SCI_SUCCESS;
968 /* Request the parent state machine to transition to the stopping state */
969 sci_base_state_machine_change_state(&sci_dev->state_machine,
970 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
972 if (sci_dev->started_request_count == 0) {
973 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
974 scic_sds_cb_remote_device_rnc_destruct_complete,
977 status = scic_sds_remote_device_terminate_requests(sci_dev);
984 * @device: The struct scic_sds_remote_device object which is cast to a
985 * struct scic_sds_remote_device object.
987 * This is the ready state device reset handler enum sci_status
989 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
990 struct scic_sds_remote_device *sci_dev)
992 /* Request the parent state machine to transition to the stopping state */
993 sci_base_state_machine_change_state(&sci_dev->state_machine,
994 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
1000 * This method will attempt to start a task request for this device object. The
1001 * remote device object will issue the start request for the task and if
1002 * successful it will start the request for the port object then increment its
1003 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
1004 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1005 * object could not get the resources to start.
1007 static enum sci_status scic_sds_remote_device_ready_state_start_task_handler(
1008 struct scic_sds_remote_device *sci_dev,
1009 struct scic_sds_request *request)
1011 enum sci_status result;
1013 /* See if the port is in a state where we can start the IO request */
1014 result = scic_sds_port_start_io(
1015 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
1017 if (result == SCI_SUCCESS) {
1018 result = scic_sds_remote_node_context_start_task(&sci_dev->rnc,
1020 if (result == SCI_SUCCESS)
1021 result = scic_sds_request_start(request);
1023 scic_sds_remote_device_start_request(sci_dev, request, result);
1030 * This method will attempt to start an io request for this device object. The
1031 * remote device object will issue the start request for the io and if
1032 * successful it will start the request for the port object then increment its
1033 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
1034 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1035 * object could not get the resources to start.
1037 static enum sci_status scic_sds_remote_device_ready_state_start_io_handler(
1038 struct scic_sds_remote_device *sci_dev,
1039 struct scic_sds_request *request)
1041 enum sci_status result;
1043 /* See if the port is in a state where we can start the IO request */
1044 result = scic_sds_port_start_io(
1045 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
1047 if (result == SCI_SUCCESS) {
1048 result = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
1049 if (result == SCI_SUCCESS)
1050 result = scic_sds_request_start(request);
1052 scic_sds_remote_device_start_request(sci_dev, request, result);
1059 * This method will complete the request for the remote device object. The
1060 * method will call the completion handler for the request object and if
1061 * successful it will complete the request on the port object then decrement
1062 * its own started_request_count. enum sci_status
1064 static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler(
1065 struct scic_sds_remote_device *sci_dev,
1066 struct scic_sds_request *request)
1068 enum sci_status result;
1070 result = scic_sds_request_complete(request);
1072 if (result != SCI_SUCCESS)
1075 /* See if the port is in a state
1076 * where we can start the IO request */
1077 result = scic_sds_port_complete_io(
1078 scic_sds_remote_device_get_port(sci_dev),
1081 if (result == SCI_SUCCESS)
1082 scic_sds_remote_device_decrement_request_count(sci_dev);
1088 * *****************************************************************************
1089 * * STOPPING STATE HANDLERS
1090 * ***************************************************************************** */
1094 * @sci_dev: The struct scic_sds_remote_device which is cast into a
1095 * struct scic_sds_remote_device.
1097 * This method will stop a struct scic_sds_remote_device that is already in the
1098 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error
1099 * since we allow a stop request on a device that is alreay stopping or
1100 * stopped. enum sci_status SCI_SUCCESS
1102 static enum sci_status scic_sds_remote_device_stopping_state_stop_handler(
1103 struct scic_sds_remote_device *device)
1106 * All requests should have been terminated, but if there is an
1107 * attempt to stop a device already in the stopping state, then
1108 * try again to terminate. */
1109 return scic_sds_remote_device_terminate_requests(device);
1115 * @device: The device object for which the request is completing.
1116 * @request: The task request that is being completed.
1118 * This method completes requests for this struct scic_sds_remote_device while it is
1119 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
1120 * complete method for the request object and if that is successful the port
1121 * object is called to complete the task request. Then the device object itself
1122 * completes the task request. If struct scic_sds_remote_device started_request_count
1123 * goes to 0 and the invalidate RNC request has completed the device object can
1124 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
1126 static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler(
1127 struct scic_sds_remote_device *sci_dev,
1128 struct scic_sds_request *request)
1130 enum sci_status status = SCI_SUCCESS;
1132 status = scic_sds_request_complete(request);
1134 if (status != SCI_SUCCESS)
1137 status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev),
1139 if (status != SCI_SUCCESS)
1142 scic_sds_remote_device_decrement_request_count(sci_dev);
1144 if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
1145 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
1146 scic_sds_cb_remote_device_rnc_destruct_complete,
1153 * @device: The struct scic_sds_remote_device which is to be cast into a
1154 * struct scic_sds_remote_device object.
1156 * This method will complete the reset operation when the device is in the
1157 * resetting state. enum sci_status
1159 static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler(
1160 struct scic_sds_remote_device *sci_dev)
1163 sci_base_state_machine_change_state(
1164 &sci_dev->state_machine,
1165 SCI_BASE_REMOTE_DEVICE_STATE_READY
1173 * @device: The struct scic_sds_remote_device which is to be cast into a
1174 * struct scic_sds_remote_device object.
1176 * This method will stop the remote device while in the resetting state.
1179 static enum sci_status scic_sds_remote_device_resetting_state_stop_handler(
1180 struct scic_sds_remote_device *sci_dev)
1182 sci_base_state_machine_change_state(
1183 &sci_dev->state_machine,
1184 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1191 * This method completes requests for this struct scic_sds_remote_device while it is
1192 * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the
1193 * complete method for the request object and if that is successful the port
1194 * object is called to complete the task request. Then the device object itself
1195 * completes the task request. enum sci_status
1197 static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler(
1198 struct scic_sds_remote_device *sci_dev,
1199 struct scic_sds_request *request)
1201 enum sci_status status = SCI_SUCCESS;
1203 status = scic_sds_request_complete(request);
1205 if (status == SCI_SUCCESS) {
1206 status = scic_sds_port_complete_io(
1207 scic_sds_remote_device_get_port(sci_dev),
1210 if (status == SCI_SUCCESS) {
1211 scic_sds_remote_device_decrement_request_count(sci_dev);
1219 * *****************************************************************************
1220 * * FAILED STATE HANDLERS
1221 * ***************************************************************************** */
1225 * @device: The struct scic_sds_remote_device which is to be cast into a
1226 * struct scic_sds_remote_device object.
1228 * This method handles the remove request for a failed struct scic_sds_remote_device
1229 * object. The method will transition the device object to the
1230 * SCIC_BASE_REMOTE_DEVICE_STATE_STOPPING. enum sci_status SCI_SUCCESS
1233 /* --------------------------------------------------------------------------- */
1235 static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = {
1236 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1237 .start_handler = scic_sds_remote_device_default_start_handler,
1238 .stop_handler = scic_sds_remote_device_default_stop_handler,
1239 .fail_handler = scic_sds_remote_device_default_fail_handler,
1240 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1241 .reset_handler = scic_sds_remote_device_default_reset_handler,
1242 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1243 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1244 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1245 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1246 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1247 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1248 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1249 .resume_handler = scic_sds_remote_device_default_resume_handler,
1250 .event_handler = scic_sds_remote_device_default_event_handler,
1251 .frame_handler = scic_sds_remote_device_default_frame_handler
1253 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1254 .start_handler = scic_sds_remote_device_stopped_state_start_handler,
1255 .stop_handler = scic_sds_remote_device_stopped_state_stop_handler,
1256 .fail_handler = scic_sds_remote_device_default_fail_handler,
1257 .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler,
1258 .reset_handler = scic_sds_remote_device_default_reset_handler,
1259 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1260 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1261 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1262 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1263 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1264 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1265 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1266 .resume_handler = scic_sds_remote_device_default_resume_handler,
1267 .event_handler = scic_sds_remote_device_default_event_handler,
1268 .frame_handler = scic_sds_remote_device_default_frame_handler
1270 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1271 .start_handler = scic_sds_remote_device_default_start_handler,
1272 .stop_handler = scic_sds_remote_device_starting_state_stop_handler,
1273 .fail_handler = scic_sds_remote_device_default_fail_handler,
1274 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1275 .reset_handler = scic_sds_remote_device_default_reset_handler,
1276 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1277 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1278 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1279 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1280 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1281 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1282 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1283 .resume_handler = scic_sds_remote_device_default_resume_handler,
1284 .event_handler = scic_sds_remote_device_general_event_handler,
1285 .frame_handler = scic_sds_remote_device_default_frame_handler
1287 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1288 .start_handler = scic_sds_remote_device_default_start_handler,
1289 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1290 .fail_handler = scic_sds_remote_device_default_fail_handler,
1291 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1292 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1293 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1294 .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler,
1295 .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1296 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1297 .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler,
1298 .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1299 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1300 .resume_handler = scic_sds_remote_device_default_resume_handler,
1301 .event_handler = scic_sds_remote_device_general_event_handler,
1302 .frame_handler = scic_sds_remote_device_general_frame_handler,
1304 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1305 .start_handler = scic_sds_remote_device_default_start_handler,
1306 .stop_handler = scic_sds_remote_device_stopping_state_stop_handler,
1307 .fail_handler = scic_sds_remote_device_default_fail_handler,
1308 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1309 .reset_handler = scic_sds_remote_device_default_reset_handler,
1310 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1311 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1312 .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1313 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1314 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1315 .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1316 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1317 .resume_handler = scic_sds_remote_device_default_resume_handler,
1318 .event_handler = scic_sds_remote_device_general_event_handler,
1319 .frame_handler = scic_sds_remote_device_general_frame_handler
1321 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1322 .start_handler = scic_sds_remote_device_default_start_handler,
1323 .stop_handler = scic_sds_remote_device_default_stop_handler,
1324 .fail_handler = scic_sds_remote_device_default_fail_handler,
1325 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1326 .reset_handler = scic_sds_remote_device_default_reset_handler,
1327 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1328 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1329 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1330 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1331 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1332 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1333 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1334 .resume_handler = scic_sds_remote_device_default_resume_handler,
1335 .event_handler = scic_sds_remote_device_default_event_handler,
1336 .frame_handler = scic_sds_remote_device_general_frame_handler
1338 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1339 .start_handler = scic_sds_remote_device_default_start_handler,
1340 .stop_handler = scic_sds_remote_device_resetting_state_stop_handler,
1341 .fail_handler = scic_sds_remote_device_default_fail_handler,
1342 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1343 .reset_handler = scic_sds_remote_device_default_reset_handler,
1344 .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler,
1345 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1346 .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1347 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1348 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1349 .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1350 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1351 .resume_handler = scic_sds_remote_device_default_resume_handler,
1352 .event_handler = scic_sds_remote_device_default_event_handler,
1353 .frame_handler = scic_sds_remote_device_general_frame_handler
1355 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1356 .start_handler = scic_sds_remote_device_default_start_handler,
1357 .stop_handler = scic_sds_remote_device_default_stop_handler,
1358 .fail_handler = scic_sds_remote_device_default_fail_handler,
1359 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1360 .reset_handler = scic_sds_remote_device_default_reset_handler,
1361 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1362 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1363 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1364 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1365 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1366 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1367 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1368 .resume_handler = scic_sds_remote_device_default_resume_handler,
1369 .event_handler = scic_sds_remote_device_default_event_handler,
1370 .frame_handler = scic_sds_remote_device_default_frame_handler
1376 * @object: This is the struct sci_base_object that is cast into a
1377 * struct scic_sds_remote_device.
1379 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1380 * immediatly transitions the remote device object to the stopped state. none
1382 static void scic_sds_remote_device_initial_state_enter(
1383 struct sci_base_object *object)
1385 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1387 sci_dev = container_of(object, typeof(*sci_dev), parent);
1388 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1389 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL);
1391 /* Initial state is a transitional state to the stopped state */
1392 sci_base_state_machine_change_state(&sci_dev->state_machine,
1393 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1398 * @object: This is the struct sci_base_object that is cast into a
1399 * struct scic_sds_remote_device.
1401 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1402 * sets the stopped state handlers and if this state is entered from the
1403 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING then the SCI User is informed that the
1404 * device stop is complete. none
1406 static void scic_sds_remote_device_stopped_state_enter(
1407 struct sci_base_object *object)
1409 struct scic_sds_remote_device *sci_dev;
1410 struct scic_sds_controller *scic;
1411 struct isci_remote_device *idev;
1412 struct isci_host *ihost;
1415 sci_dev = container_of(object, typeof(*sci_dev), parent);
1416 scic = scic_sds_remote_device_get_controller(sci_dev);
1417 ihost = sci_object_get_association(scic);
1418 idev = sci_object_get_association(sci_dev);
1420 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1421 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1423 /* If we are entering from the stopping state let the SCI User know that
1424 * the stop operation has completed.
1426 prev_state = sci_dev->state_machine.previous_state_id;
1427 if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
1428 isci_remote_device_stop_complete(ihost, idev, SCI_SUCCESS);
1430 scic_sds_controller_remote_device_stopped(scic, sci_dev);
1435 * @object: This is the struct sci_base_object that is cast into a
1436 * struct scic_sds_remote_device.
1438 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_STARTING it
1439 * sets the starting state handlers, sets the device not ready, and posts the
1440 * remote node context to the hardware. none
1442 static void scic_sds_remote_device_starting_state_enter(struct sci_base_object *object)
1444 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1446 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1447 struct isci_host *ihost = sci_object_get_association(scic);
1448 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1450 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1451 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
1453 isci_remote_device_not_ready(ihost, idev,
1454 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
1457 static void scic_sds_remote_device_starting_state_exit(struct sci_base_object *object)
1459 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1461 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1462 struct isci_host *ihost = sci_object_get_association(scic);
1463 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1466 * @todo Check the device object for the proper return code for this
1469 isci_remote_device_start_complete(ihost, idev, SCI_SUCCESS);
1474 * @object: This is the struct sci_base_object that is cast into a
1475 * struct scic_sds_remote_device.
1477 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it sets
1478 * the ready state handlers, and starts the ready substate machine. none
1480 static void scic_sds_remote_device_ready_state_enter(struct sci_base_object *object)
1482 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1484 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1485 struct isci_host *ihost = sci_object_get_association(scic);
1486 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1488 SET_STATE_HANDLER(sci_dev,
1489 scic_sds_remote_device_state_handler_table,
1490 SCI_BASE_REMOTE_DEVICE_STATE_READY);
1492 scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++;
1494 if (sci_dev->has_ready_substate_machine)
1495 sci_base_state_machine_start(&sci_dev->ready_substate_machine);
1497 isci_remote_device_ready(ihost, idev);
1502 * @object: This is the struct sci_base_object that is cast into a
1503 * struct scic_sds_remote_device.
1505 * This is the exit function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it does
1508 static void scic_sds_remote_device_ready_state_exit(
1509 struct sci_base_object *object)
1511 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1513 if (sci_dev->has_ready_substate_machine)
1514 sci_base_state_machine_stop(&sci_dev->ready_substate_machine);
1516 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1517 struct isci_host *ihost = sci_object_get_association(scic);
1518 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1520 isci_remote_device_not_ready(ihost, idev,
1521 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
1527 * @object: This is the struct sci_base_object that is cast into a
1528 * struct scic_sds_remote_device.
1530 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING it
1531 * sets the stopping state handlers and posts an RNC invalidate request to the
1532 * SCU hardware. none
1534 static void scic_sds_remote_device_stopping_state_enter(
1535 struct sci_base_object *object)
1537 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1541 scic_sds_remote_device_state_handler_table,
1542 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1548 * @object: This is the struct sci_base_object that is cast into a
1549 * struct scic_sds_remote_device.
1551 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FAILED it sets
1552 * the stopping state handlers. none
1554 static void scic_sds_remote_device_failed_state_enter(
1555 struct sci_base_object *object)
1557 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1561 scic_sds_remote_device_state_handler_table,
1562 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1568 * @object: This is the struct sci_base_object that is cast into a
1569 * struct scic_sds_remote_device.
1571 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1572 * sets the resetting state handlers. none
1574 static void scic_sds_remote_device_resetting_state_enter(
1575 struct sci_base_object *object)
1577 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1581 scic_sds_remote_device_state_handler_table,
1582 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1585 scic_sds_remote_node_context_suspend(
1586 &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
1591 * @object: This is the struct sci_base_object that is cast into a
1592 * struct scic_sds_remote_device.
1594 * This is the exit method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1595 * does nothing. none
1597 static void scic_sds_remote_device_resetting_state_exit(
1598 struct sci_base_object *object)
1600 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1602 scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
1607 * @object: This is the struct sci_base_object that is cast into a
1608 * struct scic_sds_remote_device.
1610 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FINAL it sets
1611 * the final state handlers. none
1613 static void scic_sds_remote_device_final_state_enter(
1614 struct sci_base_object *object)
1616 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1620 scic_sds_remote_device_state_handler_table,
1621 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1625 /* --------------------------------------------------------------------------- */
1627 static const struct sci_base_state scic_sds_remote_device_state_table[] = {
1628 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1629 .enter_state = scic_sds_remote_device_initial_state_enter,
1631 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1632 .enter_state = scic_sds_remote_device_stopped_state_enter,
1634 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1635 .enter_state = scic_sds_remote_device_starting_state_enter,
1636 .exit_state = scic_sds_remote_device_starting_state_exit
1638 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1639 .enter_state = scic_sds_remote_device_ready_state_enter,
1640 .exit_state = scic_sds_remote_device_ready_state_exit
1642 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1643 .enter_state = scic_sds_remote_device_stopping_state_enter,
1645 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1646 .enter_state = scic_sds_remote_device_failed_state_enter,
1648 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1649 .enter_state = scic_sds_remote_device_resetting_state_enter,
1650 .exit_state = scic_sds_remote_device_resetting_state_exit
1652 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1653 .enter_state = scic_sds_remote_device_final_state_enter,
1657 void scic_remote_device_construct(struct scic_sds_port *sci_port,
1658 struct scic_sds_remote_device *sci_dev)
1660 sci_dev->owning_port = sci_port;
1661 sci_dev->started_request_count = 0;
1662 sci_dev->parent.private = NULL;
1664 sci_base_state_machine_construct(
1665 &sci_dev->state_machine,
1667 scic_sds_remote_device_state_table,
1668 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1671 sci_base_state_machine_start(
1672 &sci_dev->state_machine
1675 scic_sds_remote_node_context_construct(&sci_dev->rnc,
1676 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
1678 sci_object_set_association(&sci_dev->rnc, sci_dev);