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)
74 enum sci_status scic_remote_device_da_construct(
75 struct scic_sds_remote_device *sci_dev)
77 enum sci_status status;
78 u16 remote_node_index;
79 struct sci_sas_identify_address_frame_protocols protocols;
82 * This information is request to determine how many remote node context
83 * entries will be needed to store the remote node.
85 scic_sds_port_get_attached_protocols(sci_dev->owning_port, &protocols);
86 sci_dev->target_protocols.u.all = protocols.u.all;
87 sci_dev->is_direct_attached = true;
88 #if !defined(DISABLE_ATAPI)
89 sci_dev->is_atapi = scic_sds_remote_device_is_atapi(sci_dev);
92 status = scic_sds_controller_allocate_remote_node_context(
93 sci_dev->owning_port->owning_controller,
97 if (status == SCI_SUCCESS) {
98 sci_dev->rnc.remote_node_index = remote_node_index;
100 scic_sds_port_get_attached_sas_address(
101 sci_dev->owning_port, &sci_dev->device_address);
103 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
104 sci_dev->has_ready_substate_machine = false;
105 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
106 sci_dev->has_ready_substate_machine = true;
108 sci_base_state_machine_construct(
109 &sci_dev->ready_substate_machine,
111 scic_sds_stp_remote_device_ready_substate_table,
112 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
113 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
114 sci_dev->has_ready_substate_machine = true;
116 /* add the SMP ready substate machine construction here */
117 sci_base_state_machine_construct(
118 &sci_dev->ready_substate_machine,
120 scic_sds_smp_remote_device_ready_substate_table,
121 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
124 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(
125 sci_dev->owning_port);
127 /* / @todo Should I assign the port width by reading all of the phys on the port? */
128 sci_dev->device_port_width = 1;
135 static void scic_sds_remote_device_get_info_from_smp_discover_response(
136 struct scic_sds_remote_device *sci_dev,
137 struct smp_response_discover *discover_response)
139 /* decode discover_response to set sas_address to sci_dev. */
140 sci_dev->device_address.high =
141 discover_response->attached_sas_address.high;
143 sci_dev->device_address.low =
144 discover_response->attached_sas_address.low;
146 sci_dev->target_protocols.u.all = discover_response->protocols.u.all;
150 enum sci_status scic_remote_device_ea_construct(
151 struct scic_sds_remote_device *sci_dev,
152 struct smp_response_discover *discover_response)
154 enum sci_status status;
155 struct scic_sds_controller *scic;
157 scic = scic_sds_port_get_controller(sci_dev->owning_port);
159 scic_sds_remote_device_get_info_from_smp_discover_response(
160 sci_dev, discover_response);
162 status = scic_sds_controller_allocate_remote_node_context(
163 scic, sci_dev, &sci_dev->rnc.remote_node_index);
165 if (status == SCI_SUCCESS) {
166 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
167 sci_dev->has_ready_substate_machine = false;
168 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
169 sci_dev->has_ready_substate_machine = true;
171 /* add the SMP ready substate machine construction here */
172 sci_base_state_machine_construct(
173 &sci_dev->ready_substate_machine,
175 scic_sds_smp_remote_device_ready_substate_table,
176 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
177 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
178 sci_dev->has_ready_substate_machine = true;
180 sci_base_state_machine_construct(
181 &sci_dev->ready_substate_machine,
183 scic_sds_stp_remote_device_ready_substate_table,
184 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
188 * For SAS-2 the physical link rate is actually a logical link
189 * rate that incorporates multiplexing. The SCU doesn't
190 * incorporate multiplexing and for the purposes of the
191 * connection the logical link rate is that same as the
192 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
193 * one another, so this code works for both situations. */
194 sci_dev->connection_rate = min_t(u16,
195 scic_sds_port_get_max_allowed_speed(sci_dev->owning_port),
196 discover_response->u2.sas1_1.negotiated_physical_link_rate
199 /* / @todo Should I assign the port width by reading all of the phys on the port? */
200 sci_dev->device_port_width = 1;
206 enum sci_status scic_remote_device_destruct(
207 struct scic_sds_remote_device *sci_dev)
209 return sci_dev->state_handlers->destruct_handler(sci_dev);
213 enum sci_status scic_remote_device_start(
214 struct scic_sds_remote_device *sci_dev,
217 return sci_dev->state_handlers->start_handler(sci_dev);
221 enum sci_status scic_remote_device_stop(
222 struct scic_sds_remote_device *sci_dev,
225 return sci_dev->state_handlers->stop_handler(sci_dev);
229 enum sci_status scic_remote_device_reset(
230 struct scic_sds_remote_device *sci_dev)
232 return sci_dev->state_handlers->reset_handler(sci_dev);
236 enum sci_status scic_remote_device_reset_complete(
237 struct scic_sds_remote_device *sci_dev)
239 return sci_dev->state_handlers->reset_complete_handler(sci_dev);
243 enum sas_linkrate scic_remote_device_get_connection_rate(
244 struct scic_sds_remote_device *sci_dev)
246 return sci_dev->connection_rate;
250 void scic_remote_device_get_protocols(
251 struct scic_sds_remote_device *sci_dev,
252 struct smp_discover_response_protocols *pr)
254 pr->u.all = sci_dev->target_protocols.u.all;
257 #if !defined(DISABLE_ATAPI)
258 bool scic_remote_device_is_atapi(struct scic_sds_remote_device *sci_dev)
260 return sci_dev->is_atapi;
266 * *****************************************************************************
267 * * SCU DRIVER STANDARD (SDS) REMOTE DEVICE IMPLEMENTATIONS
268 * ***************************************************************************** */
273 * Remote device timer requirements
275 #define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
276 #define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
281 * @sci_dev: The remote device for which the suspend is being requested.
283 * This method invokes the remote device suspend state handler. enum sci_status
285 enum sci_status scic_sds_remote_device_suspend(
286 struct scic_sds_remote_device *sci_dev,
289 return sci_dev->state_handlers->suspend_handler(sci_dev, suspend_type);
294 * @sci_dev: The remote device for which the resume is being requested.
296 * This method invokes the remote device resume state handler. enum sci_status
298 enum sci_status scic_sds_remote_device_resume(
299 struct scic_sds_remote_device *sci_dev)
301 return sci_dev->state_handlers->resume_handler(sci_dev);
306 * @sci_dev: The remote device for which the event handling is being
308 * @frame_index: This is the frame index that is being processed.
310 * This method invokes the frame handler for the remote device state machine
313 enum sci_status scic_sds_remote_device_frame_handler(
314 struct scic_sds_remote_device *sci_dev,
317 return sci_dev->state_handlers->frame_handler(sci_dev, frame_index);
322 * @sci_dev: The remote device for which the event handling is being
324 * @event_code: This is the event code that is to be processed.
326 * This method invokes the remote device event handler. enum sci_status
328 enum sci_status scic_sds_remote_device_event_handler(
329 struct scic_sds_remote_device *sci_dev,
332 return sci_dev->state_handlers->event_handler(sci_dev, event_code);
337 * @controller: The controller that is starting the io request.
338 * @sci_dev: The remote device for which the start io handling is being
340 * @io_request: The io request that is being started.
342 * This method invokes the remote device start io handler. enum sci_status
344 enum sci_status scic_sds_remote_device_start_io(
345 struct scic_sds_controller *controller,
346 struct scic_sds_remote_device *sci_dev,
347 struct scic_sds_request *io_request)
349 return sci_dev->state_handlers->start_io_handler(
350 sci_dev, io_request);
355 * @controller: The controller that is completing the io request.
356 * @sci_dev: The remote device for which the complete io handling is being
358 * @io_request: The io request that is being completed.
360 * This method invokes the remote device complete io handler. enum sci_status
362 enum sci_status scic_sds_remote_device_complete_io(
363 struct scic_sds_controller *controller,
364 struct scic_sds_remote_device *sci_dev,
365 struct scic_sds_request *io_request)
367 return sci_dev->state_handlers->complete_io_handler(
368 sci_dev, io_request);
373 * @controller: The controller that is starting the task request.
374 * @sci_dev: The remote device for which the start task handling is being
376 * @io_request: The task request that is being started.
378 * This method invokes the remote device start task handler. enum sci_status
380 enum sci_status scic_sds_remote_device_start_task(
381 struct scic_sds_controller *controller,
382 struct scic_sds_remote_device *sci_dev,
383 struct scic_sds_request *io_request)
385 return sci_dev->state_handlers->start_task_handler(
386 sci_dev, io_request);
391 * @controller: The controller that is completing the task request.
392 * @sci_dev: The remote device for which the complete task handling is
394 * @io_request: The task request that is being completed.
396 * This method invokes the remote device complete task handler. enum sci_status
404 * This method takes the request and bulids an appropriate SCU context for the
405 * request and then requests the controller to post the request. none
407 void scic_sds_remote_device_post_request(
408 struct scic_sds_remote_device *sci_dev,
413 context = scic_sds_remote_device_build_command_context(sci_dev, request);
415 scic_sds_controller_post_request(
416 scic_sds_remote_device_get_controller(sci_dev),
421 #if !defined(DISABLE_ATAPI)
424 * @sci_dev: The device to be checked.
426 * This method check the signature fis of a stp device to decide whether a
427 * device is atapi or not. true if a device is atapi device. False if a device
430 bool scic_sds_remote_device_is_atapi(
431 struct scic_sds_remote_device *sci_dev)
433 if (!sci_dev->target_protocols.u.bits.attached_stp_target)
435 else if (sci_dev->is_direct_attached) {
436 struct scic_sds_phy *phy;
437 struct scic_sata_phy_properties properties;
438 struct sata_fis_reg_d2h *signature_fis;
439 phy = scic_sds_port_get_a_connected_phy(sci_dev->owning_port);
440 scic_sata_phy_get_properties(phy, &properties);
442 /* decode the signature fis. */
443 signature_fis = &(properties.signature_fis);
445 if ((signature_fis->sector_count == 0x01)
446 && (signature_fis->lba_low == 0x01)
447 && (signature_fis->lba_mid == 0x14)
448 && (signature_fis->lba_high == 0xEB)
449 && ((signature_fis->device & 0x5F) == 0x00)
451 /* An ATA device supporting the PACKET command set. */
456 /* Expander supported ATAPI device is not currently supported. */
464 * @user_parameter: This is cast to a remote device object.
466 * This method is called once the remote node context is ready to be freed.
467 * The remote device can now report that its stop operation is complete. none
469 static void scic_sds_cb_remote_device_rnc_destruct_complete(
470 void *user_parameter)
472 struct scic_sds_remote_device *sci_dev;
474 sci_dev = (struct scic_sds_remote_device *)user_parameter;
476 BUG_ON(sci_dev->started_request_count != 0);
478 sci_base_state_machine_change_state(&sci_dev->state_machine,
479 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
484 * @user_parameter: This is cast to a remote device object.
486 * This method is called once the remote node context has transisitioned to a
487 * ready state. This is the indication that the remote device object can also
488 * transition to ready. none
490 static void scic_sds_remote_device_resume_complete_handler(
491 void *user_parameter)
493 struct scic_sds_remote_device *sci_dev;
495 sci_dev = (struct scic_sds_remote_device *)user_parameter;
498 sci_base_state_machine_get_state(&sci_dev->state_machine)
499 != SCI_BASE_REMOTE_DEVICE_STATE_READY
501 sci_base_state_machine_change_state(
502 &sci_dev->state_machine,
503 SCI_BASE_REMOTE_DEVICE_STATE_READY
510 * @device: This parameter specifies the device for which the request is being
512 * @request: This parameter specifies the request being started.
513 * @status: This parameter specifies the current start operation status.
515 * This method will perform the STP request start processing common to IO
516 * requests and task requests of all types. none
518 void scic_sds_remote_device_start_request(
519 struct scic_sds_remote_device *sci_dev,
520 struct scic_sds_request *sci_req,
521 enum sci_status status)
523 /* We still have a fault in starting the io complete it on the port */
524 if (status == SCI_SUCCESS)
525 scic_sds_remote_device_increment_request_count(sci_dev);
527 sci_dev->owning_port->state_handlers->complete_io_handler(
528 sci_dev->owning_port, sci_dev, sci_req
536 * @request: This parameter specifies the request being continued.
538 * This method will continue to post tc for a STP request. This method usually
539 * serves as a callback when RNC gets resumed during a task management
542 void scic_sds_remote_device_continue_request(void *dev)
544 struct scic_sds_remote_device *sci_dev = dev;
546 /* we need to check if this request is still valid to continue. */
547 if (sci_dev->working_request)
548 scic_controller_continue_io(sci_dev->working_request);
553 * @user_parameter: This is cast to a remote device object.
555 * This method is called once the remote node context has reached a suspended
556 * state. The remote device can now report that its suspend operation is
561 * This method will terminate all of the IO requests in the controllers IO
562 * request table that were targeted for this device.
563 * @sci_dev: This parameter specifies the remote device for which to
564 * attempt to terminate all requests.
566 * This method returns an indication as to whether all requests were
567 * successfully terminated. If a single request fails to be terminated, then
568 * this method will return the failure.
570 static enum sci_status scic_sds_remote_device_terminate_requests(
571 struct scic_sds_remote_device *sci_dev)
573 enum sci_status status = SCI_SUCCESS;
574 enum sci_status terminate_status = SCI_SUCCESS;
575 struct scic_sds_request *sci_req;
577 u32 request_count = sci_dev->started_request_count;
580 (index < SCI_MAX_IO_REQUESTS) && (request_count > 0);
582 sci_req = sci_dev->owning_port->owning_controller->io_request_table[index];
584 if ((sci_req != NULL) && (sci_req->target_device == sci_dev)) {
585 terminate_status = scic_controller_terminate_request(
586 sci_dev->owning_port->owning_controller,
591 if (terminate_status != SCI_SUCCESS)
592 status = terminate_status;
601 static enum sci_status
602 default_device_handler(struct scic_sds_remote_device *sci_dev,
605 dev_warn(scirdev_to_dev(sci_dev),
606 "%s: in wrong state: %d\n", func,
607 sci_base_state_machine_get_state(&sci_dev->state_machine));
608 return SCI_FAILURE_INVALID_STATE;
611 enum sci_status scic_sds_remote_device_default_start_handler(
612 struct scic_sds_remote_device *sci_dev)
614 return default_device_handler(sci_dev, __func__);
617 static enum sci_status scic_sds_remote_device_default_stop_handler(
618 struct scic_sds_remote_device *sci_dev)
620 return default_device_handler(sci_dev, __func__);
623 enum sci_status scic_sds_remote_device_default_fail_handler(
624 struct scic_sds_remote_device *sci_dev)
626 return default_device_handler(sci_dev, __func__);
629 enum sci_status scic_sds_remote_device_default_destruct_handler(
630 struct scic_sds_remote_device *sci_dev)
632 return default_device_handler(sci_dev, __func__);
635 enum sci_status scic_sds_remote_device_default_reset_handler(
636 struct scic_sds_remote_device *sci_dev)
638 return default_device_handler(sci_dev, __func__);
641 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
642 struct scic_sds_remote_device *sci_dev)
644 return default_device_handler(sci_dev, __func__);
647 enum sci_status scic_sds_remote_device_default_suspend_handler(
648 struct scic_sds_remote_device *sci_dev, u32 suspend_type)
650 return default_device_handler(sci_dev, __func__);
653 enum sci_status scic_sds_remote_device_default_resume_handler(
654 struct scic_sds_remote_device *sci_dev)
656 return default_device_handler(sci_dev, __func__);
661 * @device: The struct scic_sds_remote_device which is then cast into a
662 * struct scic_sds_remote_device.
663 * @event_code: The event code that the struct scic_sds_controller wants the device
666 * This method is the default event handler. It will call the RNC state
667 * machine handler for any RNC events otherwise it will log a warning and
668 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
670 static enum sci_status scic_sds_remote_device_core_event_handler(
671 struct scic_sds_remote_device *sci_dev,
675 enum sci_status status;
677 switch (scu_get_event_type(event_code)) {
678 case SCU_EVENT_TYPE_RNC_OPS_MISC:
679 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
680 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
681 status = scic_sds_remote_node_context_event_handler(&sci_dev->rnc, event_code);
683 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
685 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
686 status = SCI_SUCCESS;
688 /* Suspend the associated RNC */
689 scic_sds_remote_node_context_suspend(&sci_dev->rnc,
690 SCI_SOFTWARE_SUSPENSION,
693 dev_dbg(scirdev_to_dev(sci_dev),
694 "%s: device: %p event code: %x: %s\n",
695 __func__, sci_dev, event_code,
697 ? "I_T_Nexus_Timeout event"
698 : "I_T_Nexus_Timeout event in wrong state");
702 /* Else, fall through and treat as unhandled... */
705 dev_dbg(scirdev_to_dev(sci_dev),
706 "%s: device: %p event code: %x: %s\n",
707 __func__, sci_dev, event_code,
710 : "unexpected event in wrong state");
711 status = SCI_FAILURE_INVALID_STATE;
719 * @device: The struct scic_sds_remote_device which is then cast into a
720 * struct scic_sds_remote_device.
721 * @event_code: The event code that the struct scic_sds_controller wants the device
724 * This method is the default event handler. It will call the RNC state
725 * machine handler for any RNC events otherwise it will log a warning and
726 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
728 static enum sci_status scic_sds_remote_device_default_event_handler(
729 struct scic_sds_remote_device *sci_dev,
732 return scic_sds_remote_device_core_event_handler(sci_dev,
739 * @device: The struct scic_sds_remote_device which is then cast into a
740 * struct scic_sds_remote_device.
741 * @frame_index: The frame index for which the struct scic_sds_controller wants this
742 * device object to process.
744 * This method is the default unsolicited frame handler. It logs a warning,
745 * releases the frame and returns a failure. enum sci_status
746 * SCI_FAILURE_INVALID_STATE
748 enum sci_status scic_sds_remote_device_default_frame_handler(
749 struct scic_sds_remote_device *sci_dev,
752 dev_warn(scirdev_to_dev(sci_dev),
753 "%s: SCIC Remote Device requested to handle frame %x "
754 "while in wrong state %d\n",
757 sci_base_state_machine_get_state(
758 &sci_dev->state_machine));
760 /* Return the frame back to the controller */
761 scic_sds_controller_release_frame(
762 scic_sds_remote_device_get_controller(sci_dev), frame_index
765 return SCI_FAILURE_INVALID_STATE;
768 enum sci_status scic_sds_remote_device_default_start_request_handler(
769 struct scic_sds_remote_device *sci_dev,
770 struct scic_sds_request *request)
772 return default_device_handler(sci_dev, __func__);
775 enum sci_status scic_sds_remote_device_default_complete_request_handler(
776 struct scic_sds_remote_device *sci_dev,
777 struct scic_sds_request *request)
779 return default_device_handler(sci_dev, __func__);
782 enum sci_status scic_sds_remote_device_default_continue_request_handler(
783 struct scic_sds_remote_device *sci_dev,
784 struct scic_sds_request *request)
786 return default_device_handler(sci_dev, __func__);
791 * @device: The struct scic_sds_remote_device which is then cast into a
792 * struct scic_sds_remote_device.
793 * @frame_index: The frame index for which the struct scic_sds_controller wants this
794 * device object to process.
796 * This method is a general ssp frame handler. In most cases the device object
797 * needs to route the unsolicited frame processing to the io request object.
798 * This method decodes the tag for the io request object and routes the
799 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
801 enum sci_status scic_sds_remote_device_general_frame_handler(
802 struct scic_sds_remote_device *sci_dev,
805 enum sci_status result;
806 struct sci_ssp_frame_header *frame_header;
807 struct scic_sds_request *io_request;
809 result = scic_sds_unsolicited_frame_control_get_header(
810 &(scic_sds_remote_device_get_controller(sci_dev)->uf_control),
812 (void **)&frame_header
815 if (SCI_SUCCESS == result) {
816 io_request = scic_sds_controller_get_io_request_from_tag(
817 scic_sds_remote_device_get_controller(sci_dev), frame_header->tag);
819 if ((io_request == NULL)
820 || (io_request->target_device != sci_dev)) {
822 * We could not map this tag to a valid IO request
823 * Just toss the frame and continue */
824 scic_sds_controller_release_frame(
825 scic_sds_remote_device_get_controller(sci_dev), frame_index
828 /* The IO request is now in charge of releasing the frame */
829 result = io_request->state_handlers->frame_handler(
830 io_request, frame_index);
839 * @[in]: sci_dev This is the device object that is receiving the event.
840 * @[in]: event_code The event code to process.
842 * This is a common method for handling events reported to the remote device
843 * from the controller object. enum sci_status
845 enum sci_status scic_sds_remote_device_general_event_handler(
846 struct scic_sds_remote_device *sci_dev,
849 return scic_sds_remote_device_core_event_handler(sci_dev,
855 * *****************************************************************************
856 * * STOPPED STATE HANDLERS
857 * ***************************************************************************** */
863 * This method takes the struct scic_sds_remote_device from a stopped state and
864 * attempts to start it. The RNC buffer for the device is constructed and the
865 * device state machine is transitioned to the
866 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is
867 * an RNC buffer available to construct the remote device.
868 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in
869 * which to construct the remote device.
871 static enum sci_status scic_sds_remote_device_stopped_state_start_handler(
872 struct scic_sds_remote_device *sci_dev)
874 enum sci_status status;
876 status = scic_sds_remote_node_context_resume(&sci_dev->rnc,
877 scic_sds_remote_device_resume_complete_handler, sci_dev);
879 if (status == SCI_SUCCESS)
880 sci_base_state_machine_change_state(&sci_dev->state_machine,
881 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
886 static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
887 struct scic_sds_remote_device *sci_dev)
894 * @sci_dev: The struct scic_sds_remote_device which is cast into a
895 * struct scic_sds_remote_device.
897 * This method will destruct a struct scic_sds_remote_device that is in a stopped
898 * state. This is the only state from which a destruct request will succeed.
899 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
900 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
901 * enum sci_status SCI_SUCCESS
903 static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
904 struct scic_sds_remote_device *sci_dev)
906 struct scic_sds_controller *scic;
908 scic = scic_sds_remote_device_get_controller(sci_dev);
909 scic_sds_controller_free_remote_node_context(scic, sci_dev,
910 sci_dev->rnc.remote_node_index);
911 sci_dev->rnc.remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
913 sci_base_state_machine_change_state(&sci_dev->state_machine,
914 SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
920 * *****************************************************************************
921 * * STARTING STATE HANDLERS
922 * ***************************************************************************** */
924 static enum sci_status scic_sds_remote_device_starting_state_stop_handler(
925 struct scic_sds_remote_device *sci_dev)
928 * This device has not yet started so there had better be no IO requests
930 BUG_ON(sci_dev->started_request_count != 0);
933 * Destroy the remote node context
935 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
936 scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev);
939 * Transition to the stopping state and wait for the remote node to
940 * complete being posted and invalidated.
942 sci_base_state_machine_change_state(&sci_dev->state_machine,
943 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
948 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
949 struct scic_sds_remote_device *sci_dev)
951 enum sci_status status = SCI_SUCCESS;
953 /* Request the parent state machine to transition to the stopping state */
954 sci_base_state_machine_change_state(&sci_dev->state_machine,
955 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
957 if (sci_dev->started_request_count == 0) {
958 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
959 scic_sds_cb_remote_device_rnc_destruct_complete,
962 status = scic_sds_remote_device_terminate_requests(sci_dev);
969 * @device: The struct scic_sds_remote_device object which is cast to a
970 * struct scic_sds_remote_device object.
972 * This is the ready state device reset handler enum sci_status
974 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
975 struct scic_sds_remote_device *sci_dev)
977 /* Request the parent state machine to transition to the stopping state */
978 sci_base_state_machine_change_state(&sci_dev->state_machine,
979 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
985 * This method will attempt to start a task request for this device object. The
986 * remote device object will issue the start request for the task and if
987 * successful it will start the request for the port object then increment its
988 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
989 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
990 * object could not get the resources to start.
992 static enum sci_status scic_sds_remote_device_ready_state_start_task_handler(
993 struct scic_sds_remote_device *sci_dev,
994 struct scic_sds_request *request)
996 enum sci_status result;
998 /* See if the port is in a state where we can start the IO request */
999 result = scic_sds_port_start_io(
1000 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
1002 if (result == SCI_SUCCESS) {
1003 result = scic_sds_remote_node_context_start_task(&sci_dev->rnc,
1005 if (result == SCI_SUCCESS)
1006 result = scic_sds_request_start(request);
1008 scic_sds_remote_device_start_request(sci_dev, request, result);
1015 * This method will attempt to start an io request for this device object. The
1016 * remote device object will issue the start request for the io and if
1017 * successful it will start the request for the port object then increment its
1018 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
1019 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1020 * object could not get the resources to start.
1022 static enum sci_status scic_sds_remote_device_ready_state_start_io_handler(
1023 struct scic_sds_remote_device *sci_dev,
1024 struct scic_sds_request *request)
1026 enum sci_status result;
1028 /* See if the port is in a state where we can start the IO request */
1029 result = scic_sds_port_start_io(
1030 scic_sds_remote_device_get_port(sci_dev), sci_dev, request);
1032 if (result == SCI_SUCCESS) {
1033 result = scic_sds_remote_node_context_start_io(&sci_dev->rnc, request);
1034 if (result == SCI_SUCCESS)
1035 result = scic_sds_request_start(request);
1037 scic_sds_remote_device_start_request(sci_dev, request, result);
1044 * This method will complete the request for the remote device object. The
1045 * method will call the completion handler for the request object and if
1046 * successful it will complete the request on the port object then decrement
1047 * its own started_request_count. enum sci_status
1049 static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler(
1050 struct scic_sds_remote_device *sci_dev,
1051 struct scic_sds_request *request)
1053 enum sci_status result;
1055 result = scic_sds_request_complete(request);
1057 if (result != SCI_SUCCESS)
1060 /* See if the port is in a state
1061 * where we can start the IO request */
1062 result = scic_sds_port_complete_io(
1063 scic_sds_remote_device_get_port(sci_dev),
1066 if (result == SCI_SUCCESS)
1067 scic_sds_remote_device_decrement_request_count(sci_dev);
1073 * *****************************************************************************
1074 * * STOPPING STATE HANDLERS
1075 * ***************************************************************************** */
1079 * @sci_dev: The struct scic_sds_remote_device which is cast into a
1080 * struct scic_sds_remote_device.
1082 * This method will stop a struct scic_sds_remote_device that is already in the
1083 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error
1084 * since we allow a stop request on a device that is alreay stopping or
1085 * stopped. enum sci_status SCI_SUCCESS
1087 static enum sci_status scic_sds_remote_device_stopping_state_stop_handler(
1088 struct scic_sds_remote_device *device)
1091 * All requests should have been terminated, but if there is an
1092 * attempt to stop a device already in the stopping state, then
1093 * try again to terminate. */
1094 return scic_sds_remote_device_terminate_requests(device);
1100 * @device: The device object for which the request is completing.
1101 * @request: The task request that is being completed.
1103 * This method completes requests for this struct scic_sds_remote_device while it is
1104 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
1105 * complete method for the request object and if that is successful the port
1106 * object is called to complete the task request. Then the device object itself
1107 * completes the task request. If struct scic_sds_remote_device started_request_count
1108 * goes to 0 and the invalidate RNC request has completed the device object can
1109 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
1111 static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler(
1112 struct scic_sds_remote_device *sci_dev,
1113 struct scic_sds_request *request)
1115 enum sci_status status = SCI_SUCCESS;
1117 status = scic_sds_request_complete(request);
1119 if (status != SCI_SUCCESS)
1122 status = scic_sds_port_complete_io(scic_sds_remote_device_get_port(sci_dev),
1124 if (status != SCI_SUCCESS)
1127 scic_sds_remote_device_decrement_request_count(sci_dev);
1129 if (scic_sds_remote_device_get_request_count(sci_dev) == 0)
1130 scic_sds_remote_node_context_destruct(&sci_dev->rnc,
1131 scic_sds_cb_remote_device_rnc_destruct_complete,
1138 * @device: The struct scic_sds_remote_device which is to be cast into a
1139 * struct scic_sds_remote_device object.
1141 * This method will complete the reset operation when the device is in the
1142 * resetting state. enum sci_status
1144 static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler(
1145 struct scic_sds_remote_device *sci_dev)
1148 sci_base_state_machine_change_state(
1149 &sci_dev->state_machine,
1150 SCI_BASE_REMOTE_DEVICE_STATE_READY
1158 * @device: The struct scic_sds_remote_device which is to be cast into a
1159 * struct scic_sds_remote_device object.
1161 * This method will stop the remote device while in the resetting state.
1164 static enum sci_status scic_sds_remote_device_resetting_state_stop_handler(
1165 struct scic_sds_remote_device *sci_dev)
1167 sci_base_state_machine_change_state(
1168 &sci_dev->state_machine,
1169 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1176 * This method completes requests for this struct scic_sds_remote_device while it is
1177 * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the
1178 * complete method for the request object and if that is successful the port
1179 * object is called to complete the task request. Then the device object itself
1180 * completes the task request. enum sci_status
1182 static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler(
1183 struct scic_sds_remote_device *sci_dev,
1184 struct scic_sds_request *request)
1186 enum sci_status status = SCI_SUCCESS;
1188 status = scic_sds_request_complete(request);
1190 if (status == SCI_SUCCESS) {
1191 status = scic_sds_port_complete_io(
1192 scic_sds_remote_device_get_port(sci_dev),
1195 if (status == SCI_SUCCESS) {
1196 scic_sds_remote_device_decrement_request_count(sci_dev);
1204 * *****************************************************************************
1205 * * FAILED STATE HANDLERS
1206 * ***************************************************************************** */
1210 * @device: The struct scic_sds_remote_device which is to be cast into a
1211 * struct scic_sds_remote_device object.
1213 * This method handles the remove request for a failed struct scic_sds_remote_device
1214 * object. The method will transition the device object to the
1215 * SCIC_BASE_REMOTE_DEVICE_STATE_STOPPING. enum sci_status SCI_SUCCESS
1218 /* --------------------------------------------------------------------------- */
1220 static const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = {
1221 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1222 .start_handler = scic_sds_remote_device_default_start_handler,
1223 .stop_handler = scic_sds_remote_device_default_stop_handler,
1224 .fail_handler = scic_sds_remote_device_default_fail_handler,
1225 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1226 .reset_handler = scic_sds_remote_device_default_reset_handler,
1227 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1228 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1229 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1230 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1231 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1232 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1233 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1234 .resume_handler = scic_sds_remote_device_default_resume_handler,
1235 .event_handler = scic_sds_remote_device_default_event_handler,
1236 .frame_handler = scic_sds_remote_device_default_frame_handler
1238 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1239 .start_handler = scic_sds_remote_device_stopped_state_start_handler,
1240 .stop_handler = scic_sds_remote_device_stopped_state_stop_handler,
1241 .fail_handler = scic_sds_remote_device_default_fail_handler,
1242 .destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler,
1243 .reset_handler = scic_sds_remote_device_default_reset_handler,
1244 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1245 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1246 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1247 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1248 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1249 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1250 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1251 .resume_handler = scic_sds_remote_device_default_resume_handler,
1252 .event_handler = scic_sds_remote_device_default_event_handler,
1253 .frame_handler = scic_sds_remote_device_default_frame_handler
1255 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1256 .start_handler = scic_sds_remote_device_default_start_handler,
1257 .stop_handler = scic_sds_remote_device_starting_state_stop_handler,
1258 .fail_handler = scic_sds_remote_device_default_fail_handler,
1259 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1260 .reset_handler = scic_sds_remote_device_default_reset_handler,
1261 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1262 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1263 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1264 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1265 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1266 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1267 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1268 .resume_handler = scic_sds_remote_device_default_resume_handler,
1269 .event_handler = scic_sds_remote_device_general_event_handler,
1270 .frame_handler = scic_sds_remote_device_default_frame_handler
1272 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1273 .start_handler = scic_sds_remote_device_default_start_handler,
1274 .stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1275 .fail_handler = scic_sds_remote_device_default_fail_handler,
1276 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1277 .reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1278 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1279 .start_io_handler = scic_sds_remote_device_ready_state_start_io_handler,
1280 .complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1281 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1282 .start_task_handler = scic_sds_remote_device_ready_state_start_task_handler,
1283 .complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1284 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1285 .resume_handler = scic_sds_remote_device_default_resume_handler,
1286 .event_handler = scic_sds_remote_device_general_event_handler,
1287 .frame_handler = scic_sds_remote_device_general_frame_handler,
1289 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1290 .start_handler = scic_sds_remote_device_default_start_handler,
1291 .stop_handler = scic_sds_remote_device_stopping_state_stop_handler,
1292 .fail_handler = scic_sds_remote_device_default_fail_handler,
1293 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1294 .reset_handler = scic_sds_remote_device_default_reset_handler,
1295 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1296 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1297 .complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1298 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1299 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1300 .complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1301 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1302 .resume_handler = scic_sds_remote_device_default_resume_handler,
1303 .event_handler = scic_sds_remote_device_general_event_handler,
1304 .frame_handler = scic_sds_remote_device_general_frame_handler
1306 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1307 .start_handler = scic_sds_remote_device_default_start_handler,
1308 .stop_handler = scic_sds_remote_device_default_stop_handler,
1309 .fail_handler = scic_sds_remote_device_default_fail_handler,
1310 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1311 .reset_handler = scic_sds_remote_device_default_reset_handler,
1312 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1313 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1314 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1315 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1316 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1317 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1318 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1319 .resume_handler = scic_sds_remote_device_default_resume_handler,
1320 .event_handler = scic_sds_remote_device_default_event_handler,
1321 .frame_handler = scic_sds_remote_device_general_frame_handler
1323 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1324 .start_handler = scic_sds_remote_device_default_start_handler,
1325 .stop_handler = scic_sds_remote_device_resetting_state_stop_handler,
1326 .fail_handler = scic_sds_remote_device_default_fail_handler,
1327 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1328 .reset_handler = scic_sds_remote_device_default_reset_handler,
1329 .reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler,
1330 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1331 .complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1332 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1333 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1334 .complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1335 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1336 .resume_handler = scic_sds_remote_device_default_resume_handler,
1337 .event_handler = scic_sds_remote_device_default_event_handler,
1338 .frame_handler = scic_sds_remote_device_general_frame_handler
1340 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1341 .start_handler = scic_sds_remote_device_default_start_handler,
1342 .stop_handler = scic_sds_remote_device_default_stop_handler,
1343 .fail_handler = scic_sds_remote_device_default_fail_handler,
1344 .destruct_handler = scic_sds_remote_device_default_destruct_handler,
1345 .reset_handler = scic_sds_remote_device_default_reset_handler,
1346 .reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1347 .start_io_handler = scic_sds_remote_device_default_start_request_handler,
1348 .complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1349 .continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1350 .start_task_handler = scic_sds_remote_device_default_start_request_handler,
1351 .complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1352 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1353 .resume_handler = scic_sds_remote_device_default_resume_handler,
1354 .event_handler = scic_sds_remote_device_default_event_handler,
1355 .frame_handler = scic_sds_remote_device_default_frame_handler
1361 * @object: This is the struct sci_base_object that is cast into a
1362 * struct scic_sds_remote_device.
1364 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1365 * immediatly transitions the remote device object to the stopped state. none
1367 static void scic_sds_remote_device_initial_state_enter(
1368 struct sci_base_object *object)
1370 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1372 sci_dev = container_of(object, typeof(*sci_dev), parent);
1373 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1374 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL);
1376 /* Initial state is a transitional state to the stopped state */
1377 sci_base_state_machine_change_state(&sci_dev->state_machine,
1378 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1383 * @object: This is the struct sci_base_object that is cast into a
1384 * struct scic_sds_remote_device.
1386 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1387 * sets the stopped state handlers and if this state is entered from the
1388 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING then the SCI User is informed that the
1389 * device stop is complete. none
1391 static void scic_sds_remote_device_stopped_state_enter(
1392 struct sci_base_object *object)
1394 struct scic_sds_remote_device *sci_dev;
1395 struct scic_sds_controller *scic;
1396 struct isci_remote_device *idev;
1397 struct isci_host *ihost;
1400 sci_dev = container_of(object, typeof(*sci_dev), parent);
1401 scic = scic_sds_remote_device_get_controller(sci_dev);
1402 ihost = sci_object_get_association(scic);
1403 idev = sci_object_get_association(sci_dev);
1405 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1406 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
1408 /* If we are entering from the stopping state let the SCI User know that
1409 * the stop operation has completed.
1411 prev_state = sci_dev->state_machine.previous_state_id;
1412 if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
1413 isci_remote_device_stop_complete(ihost, idev, SCI_SUCCESS);
1415 scic_sds_controller_remote_device_stopped(scic, sci_dev);
1420 * @object: This is the struct sci_base_object that is cast into a
1421 * struct scic_sds_remote_device.
1423 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_STARTING it
1424 * sets the starting state handlers, sets the device not ready, and posts the
1425 * remote node context to the hardware. none
1427 static void scic_sds_remote_device_starting_state_enter(struct sci_base_object *object)
1429 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1431 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1432 struct isci_host *ihost = sci_object_get_association(scic);
1433 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1435 SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
1436 SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
1438 isci_remote_device_not_ready(ihost, idev,
1439 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
1442 static void scic_sds_remote_device_starting_state_exit(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);
1451 * @todo Check the device object for the proper return code for this
1454 isci_remote_device_start_complete(ihost, idev, SCI_SUCCESS);
1459 * @object: This is the struct sci_base_object that is cast into a
1460 * struct scic_sds_remote_device.
1462 * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it sets
1463 * the ready state handlers, and starts the ready substate machine. none
1465 static void scic_sds_remote_device_ready_state_enter(struct sci_base_object *object)
1467 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1469 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1470 struct isci_host *ihost = sci_object_get_association(scic);
1471 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1473 SET_STATE_HANDLER(sci_dev,
1474 scic_sds_remote_device_state_handler_table,
1475 SCI_BASE_REMOTE_DEVICE_STATE_READY);
1477 scic->remote_device_sequence[sci_dev->rnc.remote_node_index]++;
1479 if (sci_dev->has_ready_substate_machine)
1480 sci_base_state_machine_start(&sci_dev->ready_substate_machine);
1482 isci_remote_device_ready(ihost, idev);
1487 * @object: This is the struct sci_base_object that is cast into a
1488 * struct scic_sds_remote_device.
1490 * This is the exit function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it does
1493 static void scic_sds_remote_device_ready_state_exit(
1494 struct sci_base_object *object)
1496 struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
1498 if (sci_dev->has_ready_substate_machine)
1499 sci_base_state_machine_stop(&sci_dev->ready_substate_machine);
1501 struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
1502 struct isci_host *ihost = sci_object_get_association(scic);
1503 struct isci_remote_device *idev = sci_object_get_association(sci_dev);
1505 isci_remote_device_not_ready(ihost, idev,
1506 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
1512 * @object: This is the struct sci_base_object that is cast into a
1513 * struct scic_sds_remote_device.
1515 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING it
1516 * sets the stopping state handlers and posts an RNC invalidate request to the
1517 * SCU hardware. none
1519 static void scic_sds_remote_device_stopping_state_enter(
1520 struct sci_base_object *object)
1522 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1526 scic_sds_remote_device_state_handler_table,
1527 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1533 * @object: This is the struct sci_base_object that is cast into a
1534 * struct scic_sds_remote_device.
1536 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FAILED it sets
1537 * the stopping state handlers. none
1539 static void scic_sds_remote_device_failed_state_enter(
1540 struct sci_base_object *object)
1542 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1546 scic_sds_remote_device_state_handler_table,
1547 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1553 * @object: This is the struct sci_base_object that is cast into a
1554 * struct scic_sds_remote_device.
1556 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1557 * sets the resetting state handlers. none
1559 static void scic_sds_remote_device_resetting_state_enter(
1560 struct sci_base_object *object)
1562 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1566 scic_sds_remote_device_state_handler_table,
1567 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1570 scic_sds_remote_node_context_suspend(
1571 &sci_dev->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
1576 * @object: This is the struct sci_base_object that is cast into a
1577 * struct scic_sds_remote_device.
1579 * This is the exit method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1580 * does nothing. none
1582 static void scic_sds_remote_device_resetting_state_exit(
1583 struct sci_base_object *object)
1585 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1587 scic_sds_remote_node_context_resume(&sci_dev->rnc, NULL, NULL);
1592 * @object: This is the struct sci_base_object that is cast into a
1593 * struct scic_sds_remote_device.
1595 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FINAL it sets
1596 * the final state handlers. none
1598 static void scic_sds_remote_device_final_state_enter(
1599 struct sci_base_object *object)
1601 struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
1605 scic_sds_remote_device_state_handler_table,
1606 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1610 /* --------------------------------------------------------------------------- */
1612 static const struct sci_base_state scic_sds_remote_device_state_table[] = {
1613 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1614 .enter_state = scic_sds_remote_device_initial_state_enter,
1616 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1617 .enter_state = scic_sds_remote_device_stopped_state_enter,
1619 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1620 .enter_state = scic_sds_remote_device_starting_state_enter,
1621 .exit_state = scic_sds_remote_device_starting_state_exit
1623 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1624 .enter_state = scic_sds_remote_device_ready_state_enter,
1625 .exit_state = scic_sds_remote_device_ready_state_exit
1627 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1628 .enter_state = scic_sds_remote_device_stopping_state_enter,
1630 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1631 .enter_state = scic_sds_remote_device_failed_state_enter,
1633 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1634 .enter_state = scic_sds_remote_device_resetting_state_enter,
1635 .exit_state = scic_sds_remote_device_resetting_state_exit
1637 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1638 .enter_state = scic_sds_remote_device_final_state_enter,
1642 void scic_remote_device_construct(struct scic_sds_port *sci_port,
1643 struct scic_sds_remote_device *sci_dev)
1645 sci_dev->owning_port = sci_port;
1646 sci_dev->started_request_count = 0;
1647 sci_dev->parent.private = NULL;
1649 sci_base_state_machine_construct(
1650 &sci_dev->state_machine,
1652 scic_sds_remote_device_state_table,
1653 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1656 sci_base_state_machine_start(
1657 &sci_dev->state_machine
1660 scic_sds_remote_node_context_construct(&sci_dev->rnc,
1661 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
1663 sci_object_set_association(&sci_dev->rnc, sci_dev);