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)
87 + sizeof(struct scic_sds_remote_node_context);
90 /* --------------------------------------------------------------------------- */
92 void scic_remote_device_construct(struct scic_sds_port *sci_port,
93 struct scic_sds_remote_device *sci_dev)
95 sci_dev->owning_port = sci_port;
96 sci_dev->started_request_count = 0;
97 sci_dev->rnc = (struct scic_sds_remote_node_context *) &sci_dev[1];
99 sci_base_remote_device_construct(
101 scic_sds_remote_device_state_table
104 scic_sds_remote_node_context_construct(
107 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
110 sci_object_set_association(sci_dev->rnc, sci_dev);
114 enum sci_status scic_remote_device_da_construct(
115 struct scic_sds_remote_device *sci_dev)
117 enum sci_status status;
118 u16 remote_node_index;
119 struct sci_sas_identify_address_frame_protocols protocols;
122 * This information is request to determine how many remote node context
123 * entries will be needed to store the remote node.
125 scic_sds_port_get_attached_protocols(sci_dev->owning_port, &protocols);
126 sci_dev->target_protocols.u.all = protocols.u.all;
127 sci_dev->is_direct_attached = true;
128 #if !defined(DISABLE_ATAPI)
129 sci_dev->is_atapi = scic_sds_remote_device_is_atapi(sci_dev);
132 status = scic_sds_controller_allocate_remote_node_context(
133 sci_dev->owning_port->owning_controller,
137 if (status == SCI_SUCCESS) {
138 scic_sds_remote_node_context_set_remote_node_index(
139 sci_dev->rnc, remote_node_index);
141 scic_sds_port_get_attached_sas_address(
142 sci_dev->owning_port, &sci_dev->device_address);
144 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
145 sci_dev->has_ready_substate_machine = false;
146 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
147 sci_dev->has_ready_substate_machine = true;
149 sci_base_state_machine_construct(
150 &sci_dev->ready_substate_machine,
151 &sci_dev->parent.parent,
152 scic_sds_stp_remote_device_ready_substate_table,
153 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
154 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
155 sci_dev->has_ready_substate_machine = true;
157 /* add the SMP ready substate machine construction here */
158 sci_base_state_machine_construct(
159 &sci_dev->ready_substate_machine,
160 &sci_dev->parent.parent,
161 scic_sds_smp_remote_device_ready_substate_table,
162 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
165 sci_dev->connection_rate = scic_sds_port_get_max_allowed_speed(
166 sci_dev->owning_port);
168 /* / @todo Should I assign the port width by reading all of the phys on the port? */
169 sci_dev->device_port_width = 1;
176 static void scic_sds_remote_device_get_info_from_smp_discover_response(
177 struct scic_sds_remote_device *this_device,
178 struct smp_response_discover *discover_response)
180 /* decode discover_response to set sas_address to this_device. */
181 this_device->device_address.high =
182 discover_response->attached_sas_address.high;
184 this_device->device_address.low =
185 discover_response->attached_sas_address.low;
187 this_device->target_protocols.u.all = discover_response->protocols.u.all;
191 enum sci_status scic_remote_device_ea_construct(
192 struct scic_sds_remote_device *sci_dev,
193 struct smp_response_discover *discover_response)
195 enum sci_status status;
196 struct scic_sds_controller *the_controller;
198 the_controller = scic_sds_port_get_controller(sci_dev->owning_port);
200 scic_sds_remote_device_get_info_from_smp_discover_response(
201 sci_dev, discover_response);
203 status = scic_sds_controller_allocate_remote_node_context(
204 the_controller, sci_dev, &sci_dev->rnc->remote_node_index);
206 if (status == SCI_SUCCESS) {
207 if (sci_dev->target_protocols.u.bits.attached_ssp_target) {
208 sci_dev->has_ready_substate_machine = false;
209 } else if (sci_dev->target_protocols.u.bits.attached_smp_target) {
210 sci_dev->has_ready_substate_machine = true;
212 /* add the SMP ready substate machine construction here */
213 sci_base_state_machine_construct(
214 &sci_dev->ready_substate_machine,
215 &sci_dev->parent.parent,
216 scic_sds_smp_remote_device_ready_substate_table,
217 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
218 } else if (sci_dev->target_protocols.u.bits.attached_stp_target) {
219 sci_dev->has_ready_substate_machine = true;
221 sci_base_state_machine_construct(
222 &sci_dev->ready_substate_machine,
223 &sci_dev->parent.parent,
224 scic_sds_stp_remote_device_ready_substate_table,
225 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
229 * For SAS-2 the physical link rate is actually a logical link
230 * rate that incorporates multiplexing. The SCU doesn't
231 * incorporate multiplexing and for the purposes of the
232 * connection the logical link rate is that same as the
233 * physical. Furthermore, the SAS-2 and SAS-1.1 fields overlay
234 * one another, so this code works for both situations. */
235 sci_dev->connection_rate = min_t(u16,
236 scic_sds_port_get_max_allowed_speed(sci_dev->owning_port),
237 discover_response->u2.sas1_1.negotiated_physical_link_rate
240 /* / @todo Should I assign the port width by reading all of the phys on the port? */
241 sci_dev->device_port_width = 1;
247 enum sci_status scic_remote_device_destruct(
248 struct scic_sds_remote_device *sci_dev)
250 return sci_dev->state_handlers->parent.destruct_handler(&sci_dev->parent);
254 enum sci_status scic_remote_device_start(
255 struct scic_sds_remote_device *sci_dev,
258 return sci_dev->state_handlers->parent.start_handler(&sci_dev->parent);
262 enum sci_status scic_remote_device_stop(
263 struct scic_sds_remote_device *sci_dev,
266 return sci_dev->state_handlers->parent.stop_handler(&sci_dev->parent);
270 enum sci_status scic_remote_device_reset(
271 struct scic_sds_remote_device *sci_dev)
273 return sci_dev->state_handlers->parent.reset_handler(&sci_dev->parent);
277 enum sci_status scic_remote_device_reset_complete(
278 struct scic_sds_remote_device *sci_dev)
280 return sci_dev->state_handlers->parent.reset_complete_handler(&sci_dev->parent);
284 enum sci_sas_link_rate scic_remote_device_get_connection_rate(
285 struct scic_sds_remote_device *sci_dev)
287 return sci_dev->connection_rate;
291 void scic_remote_device_get_protocols(
292 struct scic_sds_remote_device *sci_dev,
293 struct smp_discover_response_protocols *pr)
295 pr->u.all = sci_dev->target_protocols.u.all;
298 #if !defined(DISABLE_ATAPI)
299 bool scic_remote_device_is_atapi(struct scic_sds_remote_device *sci_dev)
301 return sci_dev->is_atapi;
307 * *****************************************************************************
308 * * SCU DRIVER STANDARD (SDS) REMOTE DEVICE IMPLEMENTATIONS
309 * ***************************************************************************** */
314 * Remote device timer requirements
316 #define SCIC_SDS_REMOTE_DEVICE_MINIMUM_TIMER_COUNT (0)
317 #define SCIC_SDS_REMOTE_DEVICE_MAXIMUM_TIMER_COUNT (SCI_MAX_REMOTE_DEVICES)
322 * @this_device: The remote device for which the suspend is being requested.
324 * This method invokes the remote device suspend state handler. enum sci_status
326 enum sci_status scic_sds_remote_device_suspend(
327 struct scic_sds_remote_device *this_device,
330 return this_device->state_handlers->suspend_handler(this_device, suspend_type);
335 * @this_device: The remote device for which the resume is being requested.
337 * This method invokes the remote device resume state handler. enum sci_status
339 enum sci_status scic_sds_remote_device_resume(
340 struct scic_sds_remote_device *this_device)
342 return this_device->state_handlers->resume_handler(this_device);
347 * @this_device: The remote device for which the event handling is being
349 * @frame_index: This is the frame index that is being processed.
351 * This method invokes the frame handler for the remote device state machine
354 enum sci_status scic_sds_remote_device_frame_handler(
355 struct scic_sds_remote_device *this_device,
358 return this_device->state_handlers->frame_handler(this_device, frame_index);
363 * @this_device: The remote device for which the event handling is being
365 * @event_code: This is the event code that is to be processed.
367 * This method invokes the remote device event handler. enum sci_status
369 enum sci_status scic_sds_remote_device_event_handler(
370 struct scic_sds_remote_device *this_device,
373 return this_device->state_handlers->event_handler(this_device, event_code);
378 * @controller: The controller that is starting the io request.
379 * @this_device: The remote device for which the start io handling is being
381 * @io_request: The io request that is being started.
383 * This method invokes the remote device start io handler. enum sci_status
385 enum sci_status scic_sds_remote_device_start_io(
386 struct scic_sds_controller *controller,
387 struct scic_sds_remote_device *this_device,
388 struct scic_sds_request *io_request)
390 return this_device->state_handlers->parent.start_io_handler(
391 &this_device->parent, &io_request->parent);
396 * @controller: The controller that is completing the io request.
397 * @this_device: The remote device for which the complete io handling is being
399 * @io_request: The io request that is being completed.
401 * This method invokes the remote device complete io handler. enum sci_status
403 enum sci_status scic_sds_remote_device_complete_io(
404 struct scic_sds_controller *controller,
405 struct scic_sds_remote_device *this_device,
406 struct scic_sds_request *io_request)
408 return this_device->state_handlers->parent.complete_io_handler(
409 &this_device->parent, &io_request->parent);
414 * @controller: The controller that is starting the task request.
415 * @this_device: The remote device for which the start task handling is being
417 * @io_request: The task request that is being started.
419 * This method invokes the remote device start task handler. enum sci_status
421 enum sci_status scic_sds_remote_device_start_task(
422 struct scic_sds_controller *controller,
423 struct scic_sds_remote_device *this_device,
424 struct scic_sds_request *io_request)
426 return this_device->state_handlers->parent.start_task_handler(
427 &this_device->parent, &io_request->parent);
432 * @controller: The controller that is completing the task request.
433 * @this_device: The remote device for which the complete task handling is
435 * @io_request: The task request that is being completed.
437 * This method invokes the remote device complete task handler. enum sci_status
445 * This method takes the request and bulids an appropriate SCU context for the
446 * request and then requests the controller to post the request. none
448 void scic_sds_remote_device_post_request(
449 struct scic_sds_remote_device *this_device,
454 context = scic_sds_remote_device_build_command_context(this_device, request);
456 scic_sds_controller_post_request(
457 scic_sds_remote_device_get_controller(this_device),
462 #if !defined(DISABLE_ATAPI)
465 * @this_device: The device to be checked.
467 * This method check the signature fis of a stp device to decide whether a
468 * device is atapi or not. true if a device is atapi device. False if a device
471 bool scic_sds_remote_device_is_atapi(
472 struct scic_sds_remote_device *this_device)
474 if (!this_device->target_protocols.u.bits.attached_stp_target)
476 else if (this_device->is_direct_attached) {
477 struct scic_sds_phy *phy;
478 struct scic_sata_phy_properties properties;
479 struct sata_fis_reg_d2h *signature_fis;
480 phy = scic_sds_port_get_a_connected_phy(this_device->owning_port);
481 scic_sata_phy_get_properties(phy, &properties);
483 /* decode the signature fis. */
484 signature_fis = &(properties.signature_fis);
486 if ((signature_fis->sector_count == 0x01)
487 && (signature_fis->lba_low == 0x01)
488 && (signature_fis->lba_mid == 0x14)
489 && (signature_fis->lba_high == 0xEB)
490 && ((signature_fis->device & 0x5F) == 0x00)
492 /* An ATA device supporting the PACKET command set. */
497 /* Expander supported ATAPI device is not currently supported. */
505 * @user_parameter: This is cast to a remote device object.
507 * This method is called once the remote node context is ready to be freed.
508 * The remote device can now report that its stop operation is complete. none
510 static void scic_sds_cb_remote_device_rnc_destruct_complete(
511 void *user_parameter)
513 struct scic_sds_remote_device *this_device;
515 this_device = (struct scic_sds_remote_device *)user_parameter;
517 BUG_ON(this_device->started_request_count != 0);
519 sci_base_state_machine_change_state(
520 scic_sds_remote_device_get_base_state_machine(this_device),
521 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
527 * @user_parameter: This is cast to a remote device object.
529 * This method is called once the remote node context has transisitioned to a
530 * ready state. This is the indication that the remote device object can also
531 * transition to ready. none
533 static void scic_sds_remote_device_resume_complete_handler(
534 void *user_parameter)
536 struct scic_sds_remote_device *this_device;
538 this_device = (struct scic_sds_remote_device *)user_parameter;
541 sci_base_state_machine_get_state(&this_device->parent.state_machine)
542 != SCI_BASE_REMOTE_DEVICE_STATE_READY
544 sci_base_state_machine_change_state(
545 &this_device->parent.state_machine,
546 SCI_BASE_REMOTE_DEVICE_STATE_READY
553 * @device: This parameter specifies the device for which the request is being
555 * @request: This parameter specifies the request being started.
556 * @status: This parameter specifies the current start operation status.
558 * This method will perform the STP request start processing common to IO
559 * requests and task requests of all types. none
561 void scic_sds_remote_device_start_request(
562 struct scic_sds_remote_device *this_device,
563 struct scic_sds_request *the_request,
564 enum sci_status status)
566 /* We still have a fault in starting the io complete it on the port */
567 if (status == SCI_SUCCESS)
568 scic_sds_remote_device_increment_request_count(this_device);
570 this_device->owning_port->state_handlers->complete_io_handler(
571 this_device->owning_port, this_device, the_request
579 * @request: This parameter specifies the request being continued.
581 * This method will continue to post tc for a STP request. This method usually
582 * serves as a callback when RNC gets resumed during a task management
585 void scic_sds_remote_device_continue_request(void *dev)
587 struct scic_sds_remote_device *sci_dev = dev;
588 struct scic_sds_request *sci_req = sci_dev->working_request;
590 /* we need to check if this request is still valid to continue. */
592 struct scic_sds_controller *scic = sci_req->owning_controller;
593 u32 state = scic->parent.state_machine.current_state_id;
594 sci_base_controller_request_handler_t continue_io;
596 continue_io = scic_sds_controller_state_handler_table[state].base.continue_io;
597 continue_io(&scic->parent, &sci_req->target_device->parent,
604 * @user_parameter: This is cast to a remote device object.
606 * This method is called once the remote node context has reached a suspended
607 * state. The remote device can now report that its suspend operation is
612 * This method will terminate all of the IO requests in the controllers IO
613 * request table that were targeted for this device.
614 * @this_device: This parameter specifies the remote device for which to
615 * attempt to terminate all requests.
617 * This method returns an indication as to whether all requests were
618 * successfully terminated. If a single request fails to be terminated, then
619 * this method will return the failure.
621 static enum sci_status scic_sds_remote_device_terminate_requests(
622 struct scic_sds_remote_device *this_device)
624 enum sci_status status = SCI_SUCCESS;
625 enum sci_status terminate_status = SCI_SUCCESS;
626 struct scic_sds_request *the_request;
628 u32 request_count = this_device->started_request_count;
631 (index < SCI_MAX_IO_REQUESTS) && (request_count > 0);
633 the_request = this_device->owning_port->owning_controller->io_request_table[index];
635 if ((the_request != NULL) && (the_request->target_device == this_device)) {
636 terminate_status = scic_controller_terminate_request(
637 this_device->owning_port->owning_controller,
642 if (terminate_status != SCI_SUCCESS)
643 status = terminate_status;
653 * *****************************************************************************
654 * * DEFAULT STATE HANDLERS
655 * ***************************************************************************** */
659 * @device: The struct sci_base_remote_device which is then cast into a
660 * struct scic_sds_remote_device.
662 * This method is the default start handler. It logs a warning and returns a
663 * failure. enum sci_status SCI_FAILURE_INVALID_STATE
665 enum sci_status scic_sds_remote_device_default_start_handler(
666 struct sci_base_remote_device *device)
668 struct scic_sds_remote_device *sds_device =
669 (struct scic_sds_remote_device *)device;
671 dev_warn(scirdev_to_dev(sds_device),
672 "%s: SCIC Remote Device requested to start while in wrong "
675 sci_base_state_machine_get_state(
676 scic_sds_remote_device_get_base_state_machine(
679 return SCI_FAILURE_INVALID_STATE;
684 * @device: The struct sci_base_remote_device which is then cast into a
685 * struct scic_sds_remote_device.
687 * This method is the default stop handler. It logs a warning and returns a
688 * failure. enum sci_status SCI_FAILURE_INVALID_STATE
690 static enum sci_status scic_sds_remote_device_default_stop_handler(
691 struct sci_base_remote_device *device)
693 struct scic_sds_remote_device *sds_device =
694 (struct scic_sds_remote_device *)device;
696 dev_warn(scirdev_to_dev(sds_device),
697 "%s: SCIC Remote Device requested to stop while in wrong "
700 sci_base_state_machine_get_state(
701 scic_sds_remote_device_get_base_state_machine(
704 return SCI_FAILURE_INVALID_STATE;
709 * @device: The struct sci_base_remote_device which is then cast into a
710 * struct scic_sds_remote_device.
712 * This method is the default fail handler. It logs a warning and returns a
713 * failure. enum sci_status SCI_FAILURE_INVALID_STATE
715 enum sci_status scic_sds_remote_device_default_fail_handler(
716 struct sci_base_remote_device *device)
718 struct scic_sds_remote_device *sds_device =
719 (struct scic_sds_remote_device *)device;
721 dev_warn(scirdev_to_dev(sds_device),
722 "%s: SCIC Remote Device requested to fail while in wrong "
725 sci_base_state_machine_get_state(
726 scic_sds_remote_device_get_base_state_machine(
729 return SCI_FAILURE_INVALID_STATE;
734 * @device: The struct sci_base_remote_device which is then cast into a
735 * struct scic_sds_remote_device.
737 * This method is the default destruct handler. It logs a warning and returns
738 * a failure. enum sci_status SCI_FAILURE_INVALID_STATE
740 enum sci_status scic_sds_remote_device_default_destruct_handler(
741 struct sci_base_remote_device *device)
743 struct scic_sds_remote_device *sds_device =
744 (struct scic_sds_remote_device *)device;
746 dev_warn(scirdev_to_dev(sds_device),
747 "%s: SCIC Remote Device requested to destroy while in "
750 sci_base_state_machine_get_state(
751 scic_sds_remote_device_get_base_state_machine(
754 return SCI_FAILURE_INVALID_STATE;
759 * @device: The struct sci_base_remote_device which is then cast into a
760 * struct scic_sds_remote_device.
762 * This method is the default reset handler. It logs a warning and returns a
763 * failure. enum sci_status SCI_FAILURE_INVALID_STATE
765 enum sci_status scic_sds_remote_device_default_reset_handler(
766 struct sci_base_remote_device *device)
768 struct scic_sds_remote_device *sds_device =
769 (struct scic_sds_remote_device *)device;
771 dev_warn(scirdev_to_dev(sds_device),
772 "%s: SCIC Remote Device requested to reset while in wrong "
775 sci_base_state_machine_get_state(
776 scic_sds_remote_device_get_base_state_machine(
779 return SCI_FAILURE_INVALID_STATE;
784 * @device: The struct sci_base_remote_device which is then cast into a
785 * struct scic_sds_remote_device.
787 * This method is the default reset complete handler. It logs a warning and
788 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
790 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
791 struct sci_base_remote_device *device)
793 struct scic_sds_remote_device *sds_device =
794 (struct scic_sds_remote_device *)device;
796 dev_warn(scirdev_to_dev(sds_device),
797 "%s: SCIC Remote Device requested to complete reset while "
798 "in wrong state %d\n",
800 sci_base_state_machine_get_state(
801 scic_sds_remote_device_get_base_state_machine(
804 return SCI_FAILURE_INVALID_STATE;
809 * @device: The struct sci_base_remote_device which is then cast into a
810 * struct scic_sds_remote_device.
812 * This method is the default suspend handler. It logs a warning and returns a
813 * failure. enum sci_status SCI_FAILURE_INVALID_STATE
815 enum sci_status scic_sds_remote_device_default_suspend_handler(
816 struct scic_sds_remote_device *this_device,
819 dev_warn(scirdev_to_dev(this_device),
820 "%s: SCIC Remote Device 0x%p requested to suspend %d while "
821 "in wrong state %d\n",
825 sci_base_state_machine_get_state(
826 scic_sds_remote_device_get_base_state_machine(
829 return SCI_FAILURE_INVALID_STATE;
834 * @device: The struct sci_base_remote_device which is then cast into a
835 * struct scic_sds_remote_device.
837 * This method is the default resume handler. It logs a warning and returns a
838 * failure. enum sci_status SCI_FAILURE_INVALID_STATE
840 enum sci_status scic_sds_remote_device_default_resume_handler(
841 struct scic_sds_remote_device *this_device)
843 dev_warn(scirdev_to_dev(this_device),
844 "%s: SCIC Remote Device requested to resume while in "
847 sci_base_state_machine_get_state(
848 scic_sds_remote_device_get_base_state_machine(
851 return SCI_FAILURE_INVALID_STATE;
856 * @device: The struct sci_base_remote_device which is then cast into a
857 * struct scic_sds_remote_device.
858 * @event_code: The event code that the struct scic_sds_controller wants the device
861 * This method is the default event handler. It will call the RNC state
862 * machine handler for any RNC events otherwise it will log a warning and
863 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
865 static enum sci_status scic_sds_remote_device_core_event_handler(
866 struct scic_sds_remote_device *this_device,
870 enum sci_status status;
872 switch (scu_get_event_type(event_code)) {
873 case SCU_EVENT_TYPE_RNC_OPS_MISC:
874 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
875 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
876 status = scic_sds_remote_node_context_event_handler(this_device->rnc, event_code);
878 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
880 if (scu_get_event_code(event_code) == SCU_EVENT_IT_NEXUS_TIMEOUT) {
881 status = SCI_SUCCESS;
883 /* Suspend the associated RNC */
884 scic_sds_remote_node_context_suspend(this_device->rnc,
885 SCI_SOFTWARE_SUSPENSION,
888 dev_dbg(scirdev_to_dev(this_device),
889 "%s: device: %p event code: %x: %s\n",
890 __func__, this_device, event_code,
892 ? "I_T_Nexus_Timeout event"
893 : "I_T_Nexus_Timeout event in wrong state");
897 /* Else, fall through and treat as unhandled... */
900 dev_dbg(scirdev_to_dev(this_device),
901 "%s: device: %p event code: %x: %s\n",
902 __func__, this_device, event_code,
905 : "unexpected event in wrong state");
906 status = SCI_FAILURE_INVALID_STATE;
914 * @device: The struct sci_base_remote_device which is then cast into a
915 * struct scic_sds_remote_device.
916 * @event_code: The event code that the struct scic_sds_controller wants the device
919 * This method is the default event handler. It will call the RNC state
920 * machine handler for any RNC events otherwise it will log a warning and
921 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
923 static enum sci_status scic_sds_remote_device_default_event_handler(
924 struct scic_sds_remote_device *this_device,
927 return scic_sds_remote_device_core_event_handler(this_device,
934 * @device: The struct sci_base_remote_device which is then cast into a
935 * struct scic_sds_remote_device.
936 * @frame_index: The frame index for which the struct scic_sds_controller wants this
937 * device object to process.
939 * This method is the default unsolicited frame handler. It logs a warning,
940 * releases the frame and returns a failure. enum sci_status
941 * SCI_FAILURE_INVALID_STATE
943 enum sci_status scic_sds_remote_device_default_frame_handler(
944 struct scic_sds_remote_device *this_device,
947 dev_warn(scirdev_to_dev(this_device),
948 "%s: SCIC Remote Device requested to handle frame %x "
949 "while in wrong state %d\n",
952 sci_base_state_machine_get_state(
953 &this_device->parent.state_machine));
955 /* Return the frame back to the controller */
956 scic_sds_controller_release_frame(
957 scic_sds_remote_device_get_controller(this_device), frame_index
960 return SCI_FAILURE_INVALID_STATE;
965 * @device: The struct sci_base_remote_device which is then cast into a
966 * struct scic_sds_remote_device.
967 * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
970 * This method is the default start io handler. It logs a warning and returns
971 * a failure. enum sci_status SCI_FAILURE_INVALID_STATE
973 enum sci_status scic_sds_remote_device_default_start_request_handler(
974 struct sci_base_remote_device *device,
975 struct sci_base_request *request)
977 struct scic_sds_remote_device *sds_device =
978 (struct scic_sds_remote_device *)device;
980 dev_warn(scirdev_to_dev(sds_device),
981 "%s: SCIC Remote Device requested to start io request %p "
982 "while in wrong state %d\n",
985 sci_base_state_machine_get_state(
986 scic_sds_remote_device_get_base_state_machine(
987 (struct scic_sds_remote_device *)device)));
989 return SCI_FAILURE_INVALID_STATE;
994 * @device: The struct sci_base_remote_device which is then cast into a
995 * struct scic_sds_remote_device.
996 * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
999 * This method is the default complete io handler. It logs a warning and
1000 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
1002 enum sci_status scic_sds_remote_device_default_complete_request_handler(
1003 struct sci_base_remote_device *device,
1004 struct sci_base_request *request)
1006 struct scic_sds_remote_device *sds_device =
1007 (struct scic_sds_remote_device *)device;
1009 dev_warn(scirdev_to_dev(sds_device),
1010 "%s: SCIC Remote Device requested to complete io_request %p "
1011 "while in wrong state %d\n",
1014 sci_base_state_machine_get_state(
1015 scic_sds_remote_device_get_base_state_machine(
1018 return SCI_FAILURE_INVALID_STATE;
1023 * @device: The struct sci_base_remote_device which is then cast into a
1024 * struct scic_sds_remote_device.
1025 * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
1028 * This method is the default continue io handler. It logs a warning and
1029 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
1031 enum sci_status scic_sds_remote_device_default_continue_request_handler(
1032 struct sci_base_remote_device *device,
1033 struct sci_base_request *request)
1035 struct scic_sds_remote_device *sds_device =
1036 (struct scic_sds_remote_device *)device;
1038 dev_warn(scirdev_to_dev(sds_device),
1039 "%s: SCIC Remote Device requested to continue io request %p "
1040 "while in wrong state %d\n",
1043 sci_base_state_machine_get_state(
1044 scic_sds_remote_device_get_base_state_machine(
1047 return SCI_FAILURE_INVALID_STATE;
1052 * @device: The struct sci_base_remote_device which is then cast into a
1053 * struct scic_sds_remote_device.
1054 * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
1057 * This method is the default complete task handler. It logs a warning and
1058 * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
1062 * *****************************************************************************
1063 * * NORMAL STATE HANDLERS
1064 * ***************************************************************************** */
1068 * @device: The struct sci_base_remote_device which is then cast into a
1069 * struct scic_sds_remote_device.
1070 * @frame_index: The frame index for which the struct scic_sds_controller wants this
1071 * device object to process.
1073 * This method is a general ssp frame handler. In most cases the device object
1074 * needs to route the unsolicited frame processing to the io request object.
1075 * This method decodes the tag for the io request object and routes the
1076 * unsolicited frame to that object. enum sci_status SCI_FAILURE_INVALID_STATE
1078 enum sci_status scic_sds_remote_device_general_frame_handler(
1079 struct scic_sds_remote_device *this_device,
1082 enum sci_status result;
1083 struct sci_ssp_frame_header *frame_header;
1084 struct scic_sds_request *io_request;
1086 result = scic_sds_unsolicited_frame_control_get_header(
1087 &(scic_sds_remote_device_get_controller(this_device)->uf_control),
1089 (void **)&frame_header
1092 if (SCI_SUCCESS == result) {
1093 io_request = scic_sds_controller_get_io_request_from_tag(
1094 scic_sds_remote_device_get_controller(this_device), frame_header->tag);
1096 if ((io_request == NULL)
1097 || (io_request->target_device != this_device)) {
1099 * We could not map this tag to a valid IO request
1100 * Just toss the frame and continue */
1101 scic_sds_controller_release_frame(
1102 scic_sds_remote_device_get_controller(this_device), frame_index
1105 /* The IO request is now in charge of releasing the frame */
1106 result = io_request->state_handlers->frame_handler(
1107 io_request, frame_index);
1116 * @[in]: this_device This is the device object that is receiving the event.
1117 * @[in]: event_code The event code to process.
1119 * This is a common method for handling events reported to the remote device
1120 * from the controller object. enum sci_status
1122 enum sci_status scic_sds_remote_device_general_event_handler(
1123 struct scic_sds_remote_device *this_device,
1126 return scic_sds_remote_device_core_event_handler(this_device,
1132 * *****************************************************************************
1133 * * STOPPED STATE HANDLERS
1134 * ***************************************************************************** */
1140 * This method takes the struct scic_sds_remote_device from a stopped state and
1141 * attempts to start it. The RNC buffer for the device is constructed and the
1142 * device state machine is transitioned to the
1143 * SCIC_BASE_REMOTE_DEVICE_STATE_STARTING. enum sci_status SCI_SUCCESS if there is
1144 * an RNC buffer available to construct the remote device.
1145 * SCI_FAILURE_INSUFFICIENT_RESOURCES if there is no RNC buffer available in
1146 * which to construct the remote device.
1148 static enum sci_status scic_sds_remote_device_stopped_state_start_handler(
1149 struct sci_base_remote_device *device)
1151 enum sci_status status;
1152 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1154 status = scic_sds_remote_node_context_resume(
1156 scic_sds_remote_device_resume_complete_handler,
1160 if (status == SCI_SUCCESS) {
1161 sci_base_state_machine_change_state(
1162 scic_sds_remote_device_get_base_state_machine(this_device),
1163 SCI_BASE_REMOTE_DEVICE_STATE_STARTING
1172 * @this_device: The struct sci_base_remote_device which is cast into a
1173 * struct scic_sds_remote_device.
1175 * This method will stop a struct scic_sds_remote_device that is already in a stopped
1176 * state. This is not considered an error since the device is already stopped.
1177 * enum sci_status SCI_SUCCESS
1179 static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
1180 struct sci_base_remote_device *this_device)
1187 * @this_device: The struct sci_base_remote_device which is cast into a
1188 * struct scic_sds_remote_device.
1190 * This method will destruct a struct scic_sds_remote_device that is in a stopped
1191 * state. This is the only state from which a destruct request will succeed.
1192 * The RNi for this struct scic_sds_remote_device is returned to the free pool and the
1193 * device object transitions to the SCI_BASE_REMOTE_DEVICE_STATE_FINAL.
1194 * enum sci_status SCI_SUCCESS
1196 static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
1197 struct sci_base_remote_device *device)
1199 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1201 scic_sds_controller_free_remote_node_context(
1202 scic_sds_remote_device_get_controller(this_device),
1204 this_device->rnc->remote_node_index
1207 scic_sds_remote_node_context_set_remote_node_index(
1209 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
1212 sci_base_state_machine_change_state(
1213 scic_sds_remote_device_get_base_state_machine(this_device),
1214 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
1221 * *****************************************************************************
1222 * * STARTING STATE HANDLERS
1223 * ***************************************************************************** */
1225 static enum sci_status scic_sds_remote_device_starting_state_stop_handler(
1226 struct sci_base_remote_device *device)
1228 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1231 * This device has not yet started so there had better be no IO requests
1233 BUG_ON(this_device->started_request_count != 0);
1236 * Destroy the remote node context
1238 scic_sds_remote_node_context_destruct(
1240 scic_sds_cb_remote_device_rnc_destruct_complete,
1245 * Transition to the stopping state and wait for the remote node to
1246 * complete being posted and invalidated.
1248 sci_base_state_machine_change_state(
1249 scic_sds_remote_device_get_base_state_machine(this_device),
1250 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1257 * *****************************************************************************
1258 * * INITIALIZING STATE HANDLERS
1259 * ***************************************************************************** */
1261 /* There is nothing to do here for SSP devices */
1264 * *****************************************************************************
1265 * * READY STATE HANDLERS
1266 * ***************************************************************************** */
1270 * @this_device: The struct scic_sds_remote_device object to be suspended.
1272 * This method is the resume handler for the struct scic_sds_remote_device object. It
1273 * will post an RNC resume to the SCU hardware. enum sci_status SCI_SUCCESS
1278 * @device: The struct sci_base_remote_device object which is cast to a
1279 * struct scic_sds_remote_device object.
1281 * This method is the default stop handler for the struct scic_sds_remote_device ready
1282 * substate machine. It will stop the current substate machine and transition
1283 * the base state machine to SCI_BASE_REMOTE_DEVICE_STATE_STOPPING. enum sci_status
1286 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
1287 struct sci_base_remote_device *device)
1289 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1290 enum sci_status status = SCI_SUCCESS;
1292 /* Request the parent state machine to transition to the stopping state */
1293 sci_base_state_machine_change_state(
1294 scic_sds_remote_device_get_base_state_machine(this_device),
1295 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1298 if (this_device->started_request_count == 0) {
1299 scic_sds_remote_node_context_destruct(
1301 scic_sds_cb_remote_device_rnc_destruct_complete,
1305 status = scic_sds_remote_device_terminate_requests(this_device);
1312 * @device: The struct sci_base_remote_device object which is cast to a
1313 * struct scic_sds_remote_device object.
1315 * This is the ready state device reset handler enum sci_status
1317 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
1318 struct sci_base_remote_device *device)
1320 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1322 /* Request the parent state machine to transition to the stopping state */
1323 sci_base_state_machine_change_state(
1324 scic_sds_remote_device_get_base_state_machine(this_device),
1325 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
1333 * @device: The struct sci_base_remote_device object which is cast to a
1334 * struct scic_sds_remote_device object.
1336 * This is the default fail handler for the struct scic_sds_remote_device ready
1337 * substate machine. It will stop the current ready substate and transition
1338 * the remote device object to the SCI_BASE_REMOTE_DEVICE_STATE_FAILED.
1339 * enum sci_status SCI_SUCCESS
1344 * @device: The struct sci_base_remote_device which is cast to a
1345 * struct scic_sds_remote_device for which the request is to be started.
1346 * @request: The struct sci_base_request which is cast to a SCIC_SDS_IO_REQUEST that
1349 * This method will attempt to start a task request for this device object. The
1350 * remote device object will issue the start request for the task and if
1351 * successful it will start the request for the port object then increment its
1352 * own requet count. enum sci_status SCI_SUCCESS if the task request is started for
1353 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1354 * object could not get the resources to start.
1356 static enum sci_status scic_sds_remote_device_ready_state_start_task_handler(
1357 struct sci_base_remote_device *device,
1358 struct sci_base_request *request)
1360 enum sci_status result;
1361 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1362 struct scic_sds_request *task_request = (struct scic_sds_request *)request;
1364 /* See if the port is in a state where we can start the IO request */
1365 result = scic_sds_port_start_io(
1366 scic_sds_remote_device_get_port(this_device), this_device, task_request);
1368 if (result == SCI_SUCCESS) {
1369 result = scic_sds_remote_node_context_start_task(
1370 this_device->rnc, task_request
1373 if (result == SCI_SUCCESS) {
1374 result = scic_sds_request_start(task_request);
1377 scic_sds_remote_device_start_request(this_device, task_request, result);
1385 * @device: The struct sci_base_remote_device which is cast to a
1386 * struct scic_sds_remote_device for which the request is to be started.
1387 * @request: The struct sci_base_request which is cast to a SCIC_SDS_IO_REQUEST that
1390 * This method will attempt to start an io request for this device object. The
1391 * remote device object will issue the start request for the io and if
1392 * successful it will start the request for the port object then increment its
1393 * own requet count. enum sci_status SCI_SUCCESS if the io request is started for
1394 * this device object. SCI_FAILURE_INSUFFICIENT_RESOURCES if the io request
1395 * object could not get the resources to start.
1397 static enum sci_status scic_sds_remote_device_ready_state_start_io_handler(
1398 struct sci_base_remote_device *device,
1399 struct sci_base_request *request)
1401 enum sci_status result;
1402 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1403 struct scic_sds_request *io_request = (struct scic_sds_request *)request;
1405 /* See if the port is in a state where we can start the IO request */
1406 result = scic_sds_port_start_io(
1407 scic_sds_remote_device_get_port(this_device), this_device, io_request);
1409 if (result == SCI_SUCCESS) {
1410 result = scic_sds_remote_node_context_start_io(
1411 this_device->rnc, io_request
1414 if (result == SCI_SUCCESS) {
1415 result = scic_sds_request_start(io_request);
1418 scic_sds_remote_device_start_request(this_device, io_request, result);
1426 * @device: The struct sci_base_remote_device which is cast to a
1427 * struct scic_sds_remote_device for which the request is to be completed.
1428 * @request: The struct sci_base_request which is cast to a SCIC_SDS_IO_REQUEST that
1429 * is to be completed.
1431 * This method will complete the request for the remote device object. The
1432 * method will call the completion handler for the request object and if
1433 * successful it will complete the request on the port object then decrement
1434 * its own started_request_count. enum sci_status
1436 static enum sci_status scic_sds_remote_device_ready_state_complete_request_handler(
1437 struct sci_base_remote_device *device,
1438 struct sci_base_request *request)
1440 enum sci_status result;
1441 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1442 struct scic_sds_request *the_request = (struct scic_sds_request *)request;
1444 result = scic_sds_request_complete(the_request);
1446 if (result == SCI_SUCCESS) {
1447 /* See if the port is in a state where we can start the IO request */
1448 result = scic_sds_port_complete_io(
1449 scic_sds_remote_device_get_port(this_device), this_device, the_request);
1451 if (result == SCI_SUCCESS) {
1452 scic_sds_remote_device_decrement_request_count(this_device);
1460 * *****************************************************************************
1461 * * STOPPING STATE HANDLERS
1462 * ***************************************************************************** */
1466 * @this_device: The struct sci_base_remote_device which is cast into a
1467 * struct scic_sds_remote_device.
1469 * This method will stop a struct scic_sds_remote_device that is already in the
1470 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This is not considered an error
1471 * since we allow a stop request on a device that is alreay stopping or
1472 * stopped. enum sci_status SCI_SUCCESS
1474 static enum sci_status scic_sds_remote_device_stopping_state_stop_handler(
1475 struct sci_base_remote_device *device)
1478 * All requests should have been terminated, but if there is an
1479 * attempt to stop a device already in the stopping state, then
1480 * try again to terminate. */
1481 return scic_sds_remote_device_terminate_requests(
1482 (struct scic_sds_remote_device *)device);
1488 * @device: The device object for which the request is completing.
1489 * @request: The task request that is being completed.
1491 * This method completes requests for this struct scic_sds_remote_device while it is
1492 * in the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING state. This method calls the
1493 * complete method for the request object and if that is successful the port
1494 * object is called to complete the task request. Then the device object itself
1495 * completes the task request. If struct scic_sds_remote_device started_request_count
1496 * goes to 0 and the invalidate RNC request has completed the device object can
1497 * transition to the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED. enum sci_status
1499 static enum sci_status scic_sds_remote_device_stopping_state_complete_request_handler(
1500 struct sci_base_remote_device *device,
1501 struct sci_base_request *request)
1503 enum sci_status status = SCI_SUCCESS;
1504 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1505 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1507 status = scic_sds_request_complete(this_request);
1508 if (status == SCI_SUCCESS) {
1509 status = scic_sds_port_complete_io(
1510 scic_sds_remote_device_get_port(this_device),
1515 if (status == SCI_SUCCESS) {
1516 scic_sds_remote_device_decrement_request_count(this_device);
1518 if (scic_sds_remote_device_get_request_count(this_device) == 0) {
1519 scic_sds_remote_node_context_destruct(
1521 scic_sds_cb_remote_device_rnc_destruct_complete,
1532 * *****************************************************************************
1533 * * RESETTING STATE HANDLERS
1534 * ***************************************************************************** */
1538 * @device: The struct sci_base_remote_device which is to be cast into a
1539 * struct scic_sds_remote_device object.
1541 * This method will complete the reset operation when the device is in the
1542 * resetting state. enum sci_status
1544 static enum sci_status scic_sds_remote_device_resetting_state_reset_complete_handler(
1545 struct sci_base_remote_device *device)
1547 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1549 sci_base_state_machine_change_state(
1550 &this_device->parent.state_machine,
1551 SCI_BASE_REMOTE_DEVICE_STATE_READY
1559 * @device: The struct sci_base_remote_device which is to be cast into a
1560 * struct scic_sds_remote_device object.
1562 * This method will stop the remote device while in the resetting state.
1565 static enum sci_status scic_sds_remote_device_resetting_state_stop_handler(
1566 struct sci_base_remote_device *device)
1568 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1570 sci_base_state_machine_change_state(
1571 &this_device->parent.state_machine,
1572 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1580 * @device: The device object for which the request is completing.
1581 * @request: The task request that is being completed.
1583 * This method completes requests for this struct scic_sds_remote_device while it is
1584 * in the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING state. This method calls the
1585 * complete method for the request object and if that is successful the port
1586 * object is called to complete the task request. Then the device object itself
1587 * completes the task request. enum sci_status
1589 static enum sci_status scic_sds_remote_device_resetting_state_complete_request_handler(
1590 struct sci_base_remote_device *device,
1591 struct sci_base_request *request)
1593 enum sci_status status = SCI_SUCCESS;
1594 struct scic_sds_request *this_request = (struct scic_sds_request *)request;
1595 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
1597 status = scic_sds_request_complete(this_request);
1599 if (status == SCI_SUCCESS) {
1600 status = scic_sds_port_complete_io(
1601 scic_sds_remote_device_get_port(this_device), this_device, this_request);
1603 if (status == SCI_SUCCESS) {
1604 scic_sds_remote_device_decrement_request_count(this_device);
1612 * *****************************************************************************
1613 * * FAILED STATE HANDLERS
1614 * ***************************************************************************** */
1618 * @device: The struct sci_base_remote_device which is to be cast into a
1619 * struct scic_sds_remote_device object.
1621 * This method handles the remove request for a failed struct scic_sds_remote_device
1622 * object. The method will transition the device object to the
1623 * SCIC_BASE_REMOTE_DEVICE_STATE_STOPPING. enum sci_status SCI_SUCCESS
1626 /* --------------------------------------------------------------------------- */
1628 const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_handler_table[] = {
1629 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
1630 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1631 .parent.stop_handler = scic_sds_remote_device_default_stop_handler,
1632 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1633 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1634 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1635 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1636 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1637 .parent.complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1638 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1639 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1640 .parent.complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1641 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1642 .resume_handler = scic_sds_remote_device_default_resume_handler,
1643 .event_handler = scic_sds_remote_device_default_event_handler,
1644 .frame_handler = scic_sds_remote_device_default_frame_handler
1646 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
1647 .parent.start_handler = scic_sds_remote_device_stopped_state_start_handler,
1648 .parent.stop_handler = scic_sds_remote_device_stopped_state_stop_handler,
1649 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1650 .parent.destruct_handler = scic_sds_remote_device_stopped_state_destruct_handler,
1651 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1652 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1653 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1654 .parent.complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1655 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1656 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1657 .parent.complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1658 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1659 .resume_handler = scic_sds_remote_device_default_resume_handler,
1660 .event_handler = scic_sds_remote_device_default_event_handler,
1661 .frame_handler = scic_sds_remote_device_default_frame_handler
1663 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
1664 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1665 .parent.stop_handler = scic_sds_remote_device_starting_state_stop_handler,
1666 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1667 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1668 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1669 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1670 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1671 .parent.complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1672 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1673 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1674 .parent.complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1675 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1676 .resume_handler = scic_sds_remote_device_default_resume_handler,
1677 .event_handler = scic_sds_remote_device_general_event_handler,
1678 .frame_handler = scic_sds_remote_device_default_frame_handler
1680 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
1681 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1682 .parent.stop_handler = scic_sds_remote_device_ready_state_stop_handler,
1683 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1684 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1685 .parent.reset_handler = scic_sds_remote_device_ready_state_reset_handler,
1686 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1687 .parent.start_io_handler = scic_sds_remote_device_ready_state_start_io_handler,
1688 .parent.complete_io_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1689 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1690 .parent.start_task_handler = scic_sds_remote_device_ready_state_start_task_handler,
1691 .parent.complete_task_handler = scic_sds_remote_device_ready_state_complete_request_handler,
1692 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1693 .resume_handler = scic_sds_remote_device_default_resume_handler,
1694 .event_handler = scic_sds_remote_device_general_event_handler,
1695 .frame_handler = scic_sds_remote_device_general_frame_handler,
1697 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
1698 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1699 .parent.stop_handler = scic_sds_remote_device_stopping_state_stop_handler,
1700 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1701 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1702 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1703 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1704 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1705 .parent.complete_io_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1706 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1707 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1708 .parent.complete_task_handler = scic_sds_remote_device_stopping_state_complete_request_handler,
1709 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1710 .resume_handler = scic_sds_remote_device_default_resume_handler,
1711 .event_handler = scic_sds_remote_device_general_event_handler,
1712 .frame_handler = scic_sds_remote_device_general_frame_handler
1714 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
1715 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1716 .parent.stop_handler = scic_sds_remote_device_default_stop_handler,
1717 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1718 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1719 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1720 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1721 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1722 .parent.complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1723 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1724 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1725 .parent.complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1726 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1727 .resume_handler = scic_sds_remote_device_default_resume_handler,
1728 .event_handler = scic_sds_remote_device_default_event_handler,
1729 .frame_handler = scic_sds_remote_device_general_frame_handler
1731 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
1732 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1733 .parent.stop_handler = scic_sds_remote_device_resetting_state_stop_handler,
1734 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1735 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1736 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1737 .parent.reset_complete_handler = scic_sds_remote_device_resetting_state_reset_complete_handler,
1738 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1739 .parent.complete_io_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1740 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1741 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1742 .parent.complete_task_handler = scic_sds_remote_device_resetting_state_complete_request_handler,
1743 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1744 .resume_handler = scic_sds_remote_device_default_resume_handler,
1745 .event_handler = scic_sds_remote_device_default_event_handler,
1746 .frame_handler = scic_sds_remote_device_general_frame_handler
1748 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
1749 .parent.start_handler = scic_sds_remote_device_default_start_handler,
1750 .parent.stop_handler = scic_sds_remote_device_default_stop_handler,
1751 .parent.fail_handler = scic_sds_remote_device_default_fail_handler,
1752 .parent.destruct_handler = scic_sds_remote_device_default_destruct_handler,
1753 .parent.reset_handler = scic_sds_remote_device_default_reset_handler,
1754 .parent.reset_complete_handler = scic_sds_remote_device_default_reset_complete_handler,
1755 .parent.start_io_handler = scic_sds_remote_device_default_start_request_handler,
1756 .parent.complete_io_handler = scic_sds_remote_device_default_complete_request_handler,
1757 .parent.continue_io_handler = scic_sds_remote_device_default_continue_request_handler,
1758 .parent.start_task_handler = scic_sds_remote_device_default_start_request_handler,
1759 .parent.complete_task_handler = scic_sds_remote_device_default_complete_request_handler,
1760 .suspend_handler = scic_sds_remote_device_default_suspend_handler,
1761 .resume_handler = scic_sds_remote_device_default_resume_handler,
1762 .event_handler = scic_sds_remote_device_default_event_handler,
1763 .frame_handler = scic_sds_remote_device_default_frame_handler
1769 * @object: This is the struct sci_base_object that is cast into a
1770 * struct scic_sds_remote_device.
1772 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1773 * immediatly transitions the remote device object to the stopped state. none
1775 static void scic_sds_remote_device_initial_state_enter(
1776 struct sci_base_object *object)
1778 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1782 scic_sds_remote_device_state_handler_table,
1783 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
1786 /* Initial state is a transitional state to the stopped state */
1787 sci_base_state_machine_change_state(
1788 scic_sds_remote_device_get_base_state_machine(this_device),
1789 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
1795 * @object: This is the struct sci_base_object that is cast into a
1796 * struct scic_sds_remote_device.
1798 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_INITIAL it
1799 * sets the stopped state handlers and if this state is entered from the
1800 * SCI_BASE_REMOTE_DEVICE_STATE_STOPPING then the SCI User is informed that the
1801 * device stop is complete. none
1803 static void scic_sds_remote_device_stopped_state_enter(
1804 struct sci_base_object *object)
1806 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1810 scic_sds_remote_device_state_handler_table,
1811 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
1815 * If we are entering from the stopping state let the SCI User know that
1816 * the stop operation has completed. */
1817 if (this_device->parent.state_machine.previous_state_id
1818 == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING) {
1819 isci_event_remote_device_stop_complete(
1820 scic_sds_remote_device_get_controller(this_device),
1826 scic_sds_controller_remote_device_stopped(
1827 scic_sds_remote_device_get_controller(this_device),
1834 * @object: This is the struct sci_base_object that is cast into a
1835 * struct scic_sds_remote_device.
1837 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_STARTING it
1838 * sets the starting state handlers, sets the device not ready, and posts the
1839 * remote node context to the hardware. none
1841 static void scic_sds_remote_device_starting_state_enter(
1842 struct sci_base_object *object)
1844 struct scic_sds_controller *the_controller;
1845 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1847 the_controller = scic_sds_remote_device_get_controller(this_device);
1851 scic_sds_remote_device_state_handler_table,
1852 SCI_BASE_REMOTE_DEVICE_STATE_STARTING
1855 isci_event_remote_device_not_ready(
1858 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED
1864 * @object: This is the struct sci_base_object that is cast into a
1865 * struct scic_sds_remote_device.
1867 * This is the exit method for the SCI_BASE_REMOTE_DEVICE_STATE_STARTING it
1868 * reports that the device start is complete. none
1870 static void scic_sds_remote_device_starting_state_exit(
1871 struct sci_base_object *object)
1873 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1876 * / @todo Check the device object for the proper return code for this
1878 isci_event_remote_device_start_complete(
1879 scic_sds_remote_device_get_controller(this_device),
1884 scic_sds_controller_remote_device_started(
1885 scic_sds_remote_device_get_controller(this_device),
1892 * @object: This is the struct sci_base_object that is cast into a
1893 * struct scic_sds_remote_device.
1895 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_READY it sets
1896 * the ready state handlers, and starts the ready substate machine. none
1898 static void scic_sds_remote_device_ready_state_enter(
1899 struct sci_base_object *object)
1901 struct scic_sds_controller *the_controller;
1902 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1904 the_controller = scic_sds_remote_device_get_controller(this_device);
1908 scic_sds_remote_device_state_handler_table,
1909 SCI_BASE_REMOTE_DEVICE_STATE_READY
1912 the_controller->remote_device_sequence[this_device->rnc->remote_node_index]++;
1914 if (this_device->has_ready_substate_machine) {
1915 sci_base_state_machine_start(&this_device->ready_substate_machine);
1917 isci_event_remote_device_ready(the_controller, this_device);
1923 * @object: This is the struct sci_base_object that is cast into a
1924 * struct scic_sds_remote_device.
1926 * This is the exit method for the SCI_BASE_REMOTE_DEVICE_STATE_READY it does
1929 static void scic_sds_remote_device_ready_state_exit(
1930 struct sci_base_object *object)
1932 struct scic_sds_controller *the_controller;
1933 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1935 the_controller = scic_sds_remote_device_get_controller(this_device);
1937 if (this_device->has_ready_substate_machine) {
1938 sci_base_state_machine_stop(&this_device->ready_substate_machine);
1940 isci_event_remote_device_not_ready(
1943 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED
1950 * @object: This is the struct sci_base_object that is cast into a
1951 * struct scic_sds_remote_device.
1953 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_STOPPING it
1954 * sets the stopping state handlers and posts an RNC invalidate request to the
1955 * SCU hardware. none
1957 static void scic_sds_remote_device_stopping_state_enter(
1958 struct sci_base_object *object)
1960 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1964 scic_sds_remote_device_state_handler_table,
1965 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
1971 * @object: This is the struct sci_base_object that is cast into a
1972 * struct scic_sds_remote_device.
1974 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FAILED it sets
1975 * the stopping state handlers. none
1977 static void scic_sds_remote_device_failed_state_enter(
1978 struct sci_base_object *object)
1980 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
1984 scic_sds_remote_device_state_handler_table,
1985 SCI_BASE_REMOTE_DEVICE_STATE_FAILED
1991 * @object: This is the struct sci_base_object that is cast into a
1992 * struct scic_sds_remote_device.
1994 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
1995 * sets the resetting state handlers. none
1997 static void scic_sds_remote_device_resetting_state_enter(
1998 struct sci_base_object *object)
2000 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
2004 scic_sds_remote_device_state_handler_table,
2005 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
2008 scic_sds_remote_node_context_suspend(
2009 this_device->rnc, SCI_SOFTWARE_SUSPENSION, NULL, NULL);
2014 * @object: This is the struct sci_base_object that is cast into a
2015 * struct scic_sds_remote_device.
2017 * This is the exit method for the SCI_BASE_REMOTE_DEVICE_STATE_RESETTING it
2018 * does nothing. none
2020 static void scic_sds_remote_device_resetting_state_exit(
2021 struct sci_base_object *object)
2023 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
2025 scic_sds_remote_node_context_resume(this_device->rnc, NULL, NULL);
2030 * @object: This is the struct sci_base_object that is cast into a
2031 * struct scic_sds_remote_device.
2033 * This is the enter method for the SCI_BASE_REMOTE_DEVICE_STATE_FINAL it sets
2034 * the final state handlers. none
2036 static void scic_sds_remote_device_final_state_enter(
2037 struct sci_base_object *object)
2039 struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
2043 scic_sds_remote_device_state_handler_table,
2044 SCI_BASE_REMOTE_DEVICE_STATE_FINAL
2048 /* --------------------------------------------------------------------------- */
2050 const struct sci_base_state scic_sds_remote_device_state_table[] = {
2051 [SCI_BASE_REMOTE_DEVICE_STATE_INITIAL] = {
2052 .enter_state = scic_sds_remote_device_initial_state_enter,
2054 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPED] = {
2055 .enter_state = scic_sds_remote_device_stopped_state_enter,
2057 [SCI_BASE_REMOTE_DEVICE_STATE_STARTING] = {
2058 .enter_state = scic_sds_remote_device_starting_state_enter,
2059 .exit_state = scic_sds_remote_device_starting_state_exit
2061 [SCI_BASE_REMOTE_DEVICE_STATE_READY] = {
2062 .enter_state = scic_sds_remote_device_ready_state_enter,
2063 .exit_state = scic_sds_remote_device_ready_state_exit
2065 [SCI_BASE_REMOTE_DEVICE_STATE_STOPPING] = {
2066 .enter_state = scic_sds_remote_device_stopping_state_enter,
2068 [SCI_BASE_REMOTE_DEVICE_STATE_FAILED] = {
2069 .enter_state = scic_sds_remote_device_failed_state_enter,
2071 [SCI_BASE_REMOTE_DEVICE_STATE_RESETTING] = {
2072 .enter_state = scic_sds_remote_device_resetting_state_enter,
2073 .exit_state = scic_sds_remote_device_resetting_state_exit
2075 [SCI_BASE_REMOTE_DEVICE_STATE_FINAL] = {
2076 .enter_state = scic_sds_remote_device_final_state_enter,