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 "sci_base_state_machine.h"
57 #include "scic_remote_device.h"
58 #include "scic_sds_controller.h"
59 #include "scic_sds_port.h"
60 #include "scic_sds_remote_device.h"
61 #include "scic_sds_remote_node_context.h"
62 #include "sci_environment.h"
64 #include "scu_event_codes.h"
65 #include "scu_task_context.h"
67 void scic_sds_remote_node_context_construct(
68 struct scic_sds_remote_device *device,
69 struct scic_sds_remote_node_context *rnc,
70 u16 remote_node_index)
72 memset(rnc, 0, sizeof(struct scic_sds_remote_node_context));
74 rnc->remote_node_index = remote_node_index;
76 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
78 sci_base_state_machine_construct(
81 scic_sds_remote_node_context_state_table,
82 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
85 sci_base_state_machine_start(&rnc->state_machine);
90 * @this_rnc: The RNC for which the is posted request is being made.
92 * This method will return true if the RNC is not in the initial state. In all
93 * other states the RNC is considered active and this will return true. The
94 * destroy request of the state machine drives the RNC back to the initial
95 * state. If the state machine changes then this routine will also have to be
96 * changed. bool true if the state machine is not in the initial state false if
97 * the state machine is in the initial state
102 * @this_rnc: The state of the remote node context object to check.
104 * This method will return true if the remote node context is in a READY state
105 * otherwise it will return false bool true if the remote node context is in
106 * the ready state. false if the remote node context is not in the ready state.
108 bool scic_sds_remote_node_context_is_ready(
109 struct scic_sds_remote_node_context *this_rnc)
111 u32 current_state = sci_base_state_machine_get_state(&this_rnc->state_machine);
113 if (current_state == SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE) {
122 * @this_device: The remote device to use to construct the RNC buffer.
123 * @rnc: The buffer into which the remote device data will be copied.
125 * This method will construct the RNC buffer for this remote device object. none
127 void scic_sds_remote_node_context_construct_buffer(
128 struct scic_sds_remote_node_context *this_rnc)
130 union scu_remote_node_context *rnc;
131 struct scic_sds_controller *the_controller;
133 the_controller = scic_sds_remote_device_get_controller(this_rnc->device);
135 rnc = scic_sds_controller_get_remote_node_context_buffer(
136 the_controller, this_rnc->remote_node_index);
141 sizeof(union scu_remote_node_context)
142 * scic_sds_remote_device_node_count(this_rnc->device)
145 rnc->ssp.remote_node_index = this_rnc->remote_node_index;
146 rnc->ssp.remote_node_port_width = this_rnc->device->device_port_width;
147 rnc->ssp.logical_port_index =
148 scic_sds_remote_device_get_port_index(this_rnc->device);
150 rnc->ssp.remote_sas_address_hi = SCIC_SWAP_DWORD(this_rnc->device->device_address.high);
151 rnc->ssp.remote_sas_address_lo = SCIC_SWAP_DWORD(this_rnc->device->device_address.low);
153 rnc->ssp.nexus_loss_timer_enable = true;
154 rnc->ssp.check_bit = false;
155 rnc->ssp.is_valid = false;
156 rnc->ssp.is_remote_node_context = true;
157 rnc->ssp.function_number = 0;
159 rnc->ssp.arbitration_wait_time = 0;
163 this_rnc->device->target_protocols.u.bits.attached_sata_device
164 || this_rnc->device->target_protocols.u.bits.attached_stp_target
166 rnc->ssp.connection_occupancy_timeout =
167 the_controller->user_parameters.sds1.stp_max_occupancy_timeout;
168 rnc->ssp.connection_inactivity_timeout =
169 the_controller->user_parameters.sds1.stp_inactivity_timeout;
171 rnc->ssp.connection_occupancy_timeout =
172 the_controller->user_parameters.sds1.ssp_max_occupancy_timeout;
173 rnc->ssp.connection_inactivity_timeout =
174 the_controller->user_parameters.sds1.ssp_inactivity_timeout;
177 rnc->ssp.initial_arbitration_wait_time = 0;
179 /* Open Address Frame Parameters */
180 rnc->ssp.oaf_connection_rate = this_rnc->device->connection_rate;
181 rnc->ssp.oaf_features = 0;
182 rnc->ssp.oaf_source_zone_group = 0;
183 rnc->ssp.oaf_more_compatibility_features = 0;
190 * @callback_parameter:
192 * This method will setup the remote node context object so it will transition
193 * to its ready state. If the remote node context is already setup to
194 * transition to its final state then this function does nothing. none
196 static void scic_sds_remote_node_context_setup_to_resume(
197 struct scic_sds_remote_node_context *this_rnc,
198 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
199 void *callback_parameter)
201 if (this_rnc->destination_state != SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
202 this_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY;
203 this_rnc->user_callback = the_callback;
204 this_rnc->user_cookie = callback_parameter;
212 * @callback_parameter:
214 * This method will setup the remote node context object so it will transistion
215 * to its final state. none
217 static void scic_sds_remote_node_context_setup_to_destory(
218 struct scic_sds_remote_node_context *this_rnc,
219 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
220 void *callback_parameter)
222 this_rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL;
223 this_rnc->user_callback = the_callback;
224 this_rnc->user_cookie = callback_parameter;
232 * This method will continue to resume a remote node context. This is used in
233 * the states where a resume is requested while a resume is in progress.
235 static enum sci_status scic_sds_remote_node_context_continue_to_resume_handler(
236 struct scic_sds_remote_node_context *this_rnc,
237 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
238 void *callback_parameter)
240 if (this_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) {
241 this_rnc->user_callback = the_callback;
242 this_rnc->user_cookie = callback_parameter;
247 return SCI_FAILURE_INVALID_STATE;
250 /* --------------------------------------------------------------------------- */
252 static enum sci_status scic_sds_remote_node_context_default_destruct_handler(
253 struct scic_sds_remote_node_context *this_rnc,
254 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
255 void *callback_parameter)
257 dev_warn(scirdev_to_dev(this_rnc->device),
258 "%s: SCIC Remote Node Context 0x%p requested to stop while "
259 "in unexpected state %d\n",
262 sci_base_state_machine_get_state(&this_rnc->state_machine));
265 * We have decided that the destruct request on the remote node context can not fail
266 * since it is either in the initial/destroyed state or is can be destroyed. */
270 static enum sci_status scic_sds_remote_node_context_default_suspend_handler(
271 struct scic_sds_remote_node_context *this_rnc,
273 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
274 void *callback_parameter)
276 dev_warn(scirdev_to_dev(this_rnc->device),
277 "%s: SCIC Remote Node Context 0x%p requested to suspend "
278 "while in wrong state %d\n",
281 sci_base_state_machine_get_state(&this_rnc->state_machine));
283 return SCI_FAILURE_INVALID_STATE;
286 static enum sci_status scic_sds_remote_node_context_default_resume_handler(
287 struct scic_sds_remote_node_context *this_rnc,
288 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
289 void *callback_parameter)
291 dev_warn(scirdev_to_dev(this_rnc->device),
292 "%s: SCIC Remote Node Context 0x%p requested to resume "
293 "while in wrong state %d\n",
296 sci_base_state_machine_get_state(&this_rnc->state_machine));
298 return SCI_FAILURE_INVALID_STATE;
301 static enum sci_status scic_sds_remote_node_context_default_start_io_handler(
302 struct scic_sds_remote_node_context *this_rnc,
303 struct scic_sds_request *the_request)
305 dev_warn(scirdev_to_dev(this_rnc->device),
306 "%s: SCIC Remote Node Context 0x%p requested to start io "
307 "0x%p while in wrong state %d\n",
311 sci_base_state_machine_get_state(&this_rnc->state_machine));
313 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
316 static enum sci_status scic_sds_remote_node_context_default_start_task_handler(
317 struct scic_sds_remote_node_context *this_rnc,
318 struct scic_sds_request *the_request)
320 dev_warn(scirdev_to_dev(this_rnc->device),
321 "%s: SCIC Remote Node Context 0x%p requested to start "
322 "task 0x%p while in wrong state %d\n",
326 sci_base_state_machine_get_state(&this_rnc->state_machine));
331 static enum sci_status scic_sds_remote_node_context_default_event_handler(
332 struct scic_sds_remote_node_context *this_rnc,
335 dev_warn(scirdev_to_dev(this_rnc->device),
336 "%s: SCIC Remote Node Context 0x%p requested to process "
337 "event 0x%x while in wrong state %d\n",
341 sci_base_state_machine_get_state(&this_rnc->state_machine));
343 return SCI_FAILURE_INVALID_STATE;
348 * @this_rnc: The rnc for which the task request is targeted.
349 * @the_request: The request which is going to be started.
351 * This method determines if the task request can be started by the SCU
352 * hardware. When the RNC is in the ready state any task can be started.
353 * enum sci_status SCI_SUCCESS
355 static enum sci_status scic_sds_remote_node_context_success_start_task_handler(
356 struct scic_sds_remote_node_context *this_rnc,
357 struct scic_sds_request *the_request)
366 * @callback_parameter:
368 * This method handles destruct calls from the various state handlers. The
369 * remote node context can be requested to destroy from any state. If there was
370 * a user callback it is always replaced with the request to destroy user
371 * callback. enum sci_status
373 static enum sci_status scic_sds_remote_node_context_general_destruct_handler(
374 struct scic_sds_remote_node_context *this_rnc,
375 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
376 void *callback_parameter)
378 scic_sds_remote_node_context_setup_to_destory(
379 this_rnc, the_callback, callback_parameter
382 sci_base_state_machine_change_state(
383 &this_rnc->state_machine,
384 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
390 /* --------------------------------------------------------------------------- */
392 static enum sci_status scic_sds_remote_node_context_initial_state_resume_handler(
393 struct scic_sds_remote_node_context *this_rnc,
394 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
395 void *callback_parameter)
397 if (this_rnc->remote_node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
398 scic_sds_remote_node_context_setup_to_resume(
399 this_rnc, the_callback, callback_parameter
402 scic_sds_remote_node_context_construct_buffer(this_rnc);
404 sci_base_state_machine_change_state(
405 &this_rnc->state_machine,
406 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
412 return SCI_FAILURE_INVALID_STATE;
415 /* --------------------------------------------------------------------------- */
417 static enum sci_status scic_sds_remote_node_context_posting_state_event_handler(
418 struct scic_sds_remote_node_context *this_rnc,
421 enum sci_status status;
423 switch (scu_get_event_code(event_code)) {
424 case SCU_EVENT_POST_RNC_COMPLETE:
425 status = SCI_SUCCESS;
427 sci_base_state_machine_change_state(
428 &this_rnc->state_machine,
429 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
434 status = SCI_FAILURE;
435 dev_warn(scirdev_to_dev(this_rnc->device),
436 "%s: SCIC Remote Node Context 0x%p requested to "
437 "process unexpected event 0x%x while in posting "
448 /* --------------------------------------------------------------------------- */
450 static enum sci_status scic_sds_remote_node_context_invalidating_state_destruct_handler(
451 struct scic_sds_remote_node_context *this_rnc,
452 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
453 void *callback_parameter)
455 scic_sds_remote_node_context_setup_to_destory(
456 this_rnc, the_callback, callback_parameter
462 static enum sci_status scic_sds_remote_node_context_invalidating_state_event_handler(
463 struct scic_sds_remote_node_context *this_rnc,
466 enum sci_status status;
468 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
469 status = SCI_SUCCESS;
471 if (this_rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_FINAL) {
472 sci_base_state_machine_change_state(
473 &this_rnc->state_machine,
474 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
477 sci_base_state_machine_change_state(
478 &this_rnc->state_machine,
479 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
483 switch (scu_get_event_type(event_code)) {
484 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
485 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
487 * We really dont care if the hardware is going to suspend
488 * the device since it's being invalidated anyway */
489 dev_dbg(scirdev_to_dev(this_rnc->device),
490 "%s: SCIC Remote Node Context 0x%p was "
491 "suspeneded by hardware while being "
495 status = SCI_SUCCESS;
499 dev_warn(scirdev_to_dev(this_rnc->device),
500 "%s: SCIC Remote Node Context 0x%p "
501 "requested to process event 0x%x while "
506 sci_base_state_machine_get_state(
507 &this_rnc->state_machine));
508 status = SCI_FAILURE;
516 /* --------------------------------------------------------------------------- */
519 static enum sci_status scic_sds_remote_node_context_resuming_state_event_handler(
520 struct scic_sds_remote_node_context *this_rnc,
523 enum sci_status status;
525 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
526 status = SCI_SUCCESS;
528 sci_base_state_machine_change_state(
529 &this_rnc->state_machine,
530 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
533 switch (scu_get_event_type(event_code)) {
534 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
535 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
537 * We really dont care if the hardware is going to suspend
538 * the device since it's being resumed anyway */
539 dev_dbg(scirdev_to_dev(this_rnc->device),
540 "%s: SCIC Remote Node Context 0x%p was "
541 "suspeneded by hardware while being resumed.\n",
544 status = SCI_SUCCESS;
548 dev_warn(scirdev_to_dev(this_rnc->device),
549 "%s: SCIC Remote Node Context 0x%p requested "
550 "to process event 0x%x while in state %d.\n",
554 sci_base_state_machine_get_state(
555 &this_rnc->state_machine));
556 status = SCI_FAILURE;
564 /* --------------------------------------------------------------------------- */
568 * @this_rnc: The remote node context object being suspended.
569 * @the_callback: The callback when the suspension is complete.
570 * @callback_parameter: The parameter that is to be passed into the callback.
572 * This method will handle the suspend requests from the ready state.
575 static enum sci_status scic_sds_remote_node_context_ready_state_suspend_handler(
576 struct scic_sds_remote_node_context *this_rnc,
578 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
579 void *callback_parameter)
581 this_rnc->user_callback = the_callback;
582 this_rnc->user_cookie = callback_parameter;
583 this_rnc->suspension_code = suspend_type;
585 if (suspend_type == SCI_SOFTWARE_SUSPENSION) {
586 scic_sds_remote_device_post_request(
588 SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX
592 sci_base_state_machine_change_state(
593 &this_rnc->state_machine,
594 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
602 * @this_rnc: The rnc for which the io request is targeted.
603 * @the_request: The request which is going to be started.
605 * This method determines if the io request can be started by the SCU hardware.
606 * When the RNC is in the ready state any io request can be started. enum sci_status
609 static enum sci_status scic_sds_remote_node_context_ready_state_start_io_handler(
610 struct scic_sds_remote_node_context *this_rnc,
611 struct scic_sds_request *the_request)
617 static enum sci_status scic_sds_remote_node_context_ready_state_event_handler(
618 struct scic_sds_remote_node_context *this_rnc,
621 enum sci_status status;
623 switch (scu_get_event_type(event_code)) {
624 case SCU_EVENT_TL_RNC_SUSPEND_TX:
625 sci_base_state_machine_change_state(
626 &this_rnc->state_machine,
627 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
630 this_rnc->suspension_code = scu_get_event_specifier(event_code);
631 status = SCI_SUCCESS;
634 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
635 sci_base_state_machine_change_state(
636 &this_rnc->state_machine,
637 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
640 this_rnc->suspension_code = scu_get_event_specifier(event_code);
641 status = SCI_SUCCESS;
645 dev_warn(scirdev_to_dev(this_rnc->device),
646 "%s: SCIC Remote Node Context 0x%p requested to "
647 "process event 0x%x while in state %d.\n",
651 sci_base_state_machine_get_state(
652 &this_rnc->state_machine));
654 status = SCI_FAILURE;
661 /* --------------------------------------------------------------------------- */
663 static enum sci_status scic_sds_remote_node_context_tx_suspended_state_resume_handler(
664 struct scic_sds_remote_node_context *this_rnc,
665 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
666 void *callback_parameter)
668 enum sci_status status;
669 struct smp_discover_response_protocols protocols;
671 scic_sds_remote_node_context_setup_to_resume(
672 this_rnc, the_callback, callback_parameter
675 /* TODO: consider adding a resume action of NONE, INVALIDATE, WRITE_TLCR */
677 scic_remote_device_get_protocols(this_rnc->device, &protocols);
680 (protocols.u.bits.attached_ssp_target == 1)
681 || (protocols.u.bits.attached_smp_target == 1)
683 sci_base_state_machine_change_state(
684 &this_rnc->state_machine,
685 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
688 status = SCI_SUCCESS;
689 } else if (protocols.u.bits.attached_stp_target == 1) {
690 if (this_rnc->device->is_direct_attached) {
691 /* @todo Fix this since I am being silly in writing to the STPTLDARNI register. */
692 scic_sds_port_set_direct_attached_device_id(
693 this_rnc->device->owning_port,
694 this_rnc->remote_node_index
697 sci_base_state_machine_change_state(
698 &this_rnc->state_machine,
699 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
702 sci_base_state_machine_change_state(
703 &this_rnc->state_machine,
704 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
708 status = SCI_SUCCESS;
710 status = SCI_FAILURE;
718 * @this_rnc: The remote node context which is to receive the task request.
719 * @the_request: The task request to be transmitted to to the remote target
722 * This method will report a success or failure attempt to start a new task
723 * request to the hardware. Since all task requests are sent on the high
724 * priority queue they can be sent when the RCN is in a TX suspend state.
725 * enum sci_status SCI_SUCCESS
727 static enum sci_status scic_sds_remote_node_context_suspended_start_task_handler(
728 struct scic_sds_remote_node_context *this_rnc,
729 struct scic_sds_request *the_request)
731 scic_sds_remote_node_context_resume(this_rnc, NULL, NULL);
736 /* --------------------------------------------------------------------------- */
738 static enum sci_status scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler(
739 struct scic_sds_remote_node_context *this_rnc,
740 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
741 void *callback_parameter)
743 scic_sds_remote_node_context_setup_to_resume(
744 this_rnc, the_callback, callback_parameter
747 sci_base_state_machine_change_state(
748 &this_rnc->state_machine,
749 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
752 return SCI_FAILURE_INVALID_STATE;
755 /* --------------------------------------------------------------------------- */
762 static enum sci_status scic_sds_remote_node_context_await_suspension_state_resume_handler(
763 struct scic_sds_remote_node_context *this_rnc,
764 SCICS_SDS_REMOTE_NODE_CONTEXT_CALLBACK the_callback,
765 void *callback_parameter)
767 scic_sds_remote_node_context_setup_to_resume(
768 this_rnc, the_callback, callback_parameter
776 * @this_rnc: The remote node context which is to receive the task request.
777 * @the_request: The task request to be transmitted to to the remote target
780 * This method will report a success or failure attempt to start a new task
781 * request to the hardware. Since all task requests are sent on the high
782 * priority queue they can be sent when the RCN is in a TX suspend state.
783 * enum sci_status SCI_SUCCESS
785 static enum sci_status scic_sds_remote_node_context_await_suspension_state_start_task_handler(
786 struct scic_sds_remote_node_context *this_rnc,
787 struct scic_sds_request *the_request)
792 static enum sci_status scic_sds_remote_node_context_await_suspension_state_event_handler(
793 struct scic_sds_remote_node_context *this_rnc,
796 enum sci_status status;
798 switch (scu_get_event_type(event_code)) {
799 case SCU_EVENT_TL_RNC_SUSPEND_TX:
800 sci_base_state_machine_change_state(
801 &this_rnc->state_machine,
802 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
805 this_rnc->suspension_code = scu_get_event_specifier(event_code);
806 status = SCI_SUCCESS;
809 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
810 sci_base_state_machine_change_state(
811 &this_rnc->state_machine,
812 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
815 this_rnc->suspension_code = scu_get_event_specifier(event_code);
816 status = SCI_SUCCESS;
820 dev_warn(scirdev_to_dev(this_rnc->device),
821 "%s: SCIC Remote Node Context 0x%p requested to "
822 "process event 0x%x while in state %d.\n",
826 sci_base_state_machine_get_state(
827 &this_rnc->state_machine));
829 status = SCI_FAILURE;
836 /* --------------------------------------------------------------------------- */
838 struct scic_sds_remote_node_context_handlers
839 scic_sds_remote_node_context_state_handler_table[
840 SCIC_SDS_REMOTE_NODE_CONTEXT_MAX_STATES] =
842 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE */
844 scic_sds_remote_node_context_default_destruct_handler,
845 scic_sds_remote_node_context_default_suspend_handler,
846 scic_sds_remote_node_context_initial_state_resume_handler,
847 scic_sds_remote_node_context_default_start_io_handler,
848 scic_sds_remote_node_context_default_start_task_handler,
849 scic_sds_remote_node_context_default_event_handler
851 /* SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE */
853 scic_sds_remote_node_context_general_destruct_handler,
854 scic_sds_remote_node_context_default_suspend_handler,
855 scic_sds_remote_node_context_continue_to_resume_handler,
856 scic_sds_remote_node_context_default_start_io_handler,
857 scic_sds_remote_node_context_default_start_task_handler,
858 scic_sds_remote_node_context_posting_state_event_handler
860 /* SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE */
862 scic_sds_remote_node_context_invalidating_state_destruct_handler,
863 scic_sds_remote_node_context_default_suspend_handler,
864 scic_sds_remote_node_context_continue_to_resume_handler,
865 scic_sds_remote_node_context_default_start_io_handler,
866 scic_sds_remote_node_context_default_start_task_handler,
867 scic_sds_remote_node_context_invalidating_state_event_handler
869 /* SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE */
871 scic_sds_remote_node_context_general_destruct_handler,
872 scic_sds_remote_node_context_default_suspend_handler,
873 scic_sds_remote_node_context_continue_to_resume_handler,
874 scic_sds_remote_node_context_default_start_io_handler,
875 scic_sds_remote_node_context_success_start_task_handler,
876 scic_sds_remote_node_context_resuming_state_event_handler
878 /* SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE */
880 scic_sds_remote_node_context_general_destruct_handler,
881 scic_sds_remote_node_context_ready_state_suspend_handler,
882 scic_sds_remote_node_context_default_resume_handler,
883 scic_sds_remote_node_context_ready_state_start_io_handler,
884 scic_sds_remote_node_context_success_start_task_handler,
885 scic_sds_remote_node_context_ready_state_event_handler
887 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE */
889 scic_sds_remote_node_context_general_destruct_handler,
890 scic_sds_remote_node_context_default_suspend_handler,
891 scic_sds_remote_node_context_tx_suspended_state_resume_handler,
892 scic_sds_remote_node_context_default_start_io_handler,
893 scic_sds_remote_node_context_suspended_start_task_handler,
894 scic_sds_remote_node_context_default_event_handler
896 /* SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE */
898 scic_sds_remote_node_context_general_destruct_handler,
899 scic_sds_remote_node_context_default_suspend_handler,
900 scic_sds_remote_node_context_tx_rx_suspended_state_resume_handler,
901 scic_sds_remote_node_context_default_start_io_handler,
902 scic_sds_remote_node_context_suspended_start_task_handler,
903 scic_sds_remote_node_context_default_event_handler
905 /* SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE */
907 scic_sds_remote_node_context_general_destruct_handler,
908 scic_sds_remote_node_context_default_suspend_handler,
909 scic_sds_remote_node_context_await_suspension_state_resume_handler,
910 scic_sds_remote_node_context_default_start_io_handler,
911 scic_sds_remote_node_context_await_suspension_state_start_task_handler,
912 scic_sds_remote_node_context_await_suspension_state_event_handler
917 * *****************************************************************************
918 * * REMOTE NODE CONTEXT PRIVATE METHODS
919 * ***************************************************************************** */
924 * This method just calls the user callback function and then resets the
927 static void scic_sds_remote_node_context_notify_user(
928 struct scic_sds_remote_node_context *rnc)
930 if (rnc->user_callback != NULL) {
931 (*rnc->user_callback)(rnc->user_cookie);
933 rnc->user_callback = NULL;
934 rnc->user_cookie = NULL;
941 * This method will continue the remote node context state machine by
942 * requesting to resume the remote node context state machine from its current
945 static void scic_sds_remote_node_context_continue_state_transitions(
946 struct scic_sds_remote_node_context *rnc)
948 if (rnc->destination_state == SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_READY) {
949 rnc->state_handlers->resume_handler(
950 rnc, rnc->user_callback, rnc->user_cookie
957 * @this_rnc: The remote node context object that is to be validated.
959 * This method will mark the rnc buffer as being valid and post the request to
962 static void scic_sds_remote_node_context_validate_context_buffer(
963 struct scic_sds_remote_node_context *this_rnc)
965 union scu_remote_node_context *rnc_buffer;
967 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
968 scic_sds_remote_device_get_controller(this_rnc->device),
969 this_rnc->remote_node_index
972 rnc_buffer->ssp.is_valid = true;
975 !this_rnc->device->is_direct_attached
976 && this_rnc->device->target_protocols.u.bits.attached_stp_target
978 scic_sds_remote_device_post_request(
980 SCU_CONTEXT_COMMAND_POST_RNC_96
983 scic_sds_remote_device_post_request(
985 SCU_CONTEXT_COMMAND_POST_RNC_32
988 if (this_rnc->device->is_direct_attached) {
989 scic_sds_port_set_direct_attached_device_id(
990 this_rnc->device->owning_port,
991 this_rnc->remote_node_index
999 * @this_rnc: The remote node context object that is to be invalidated.
1001 * This method will update the RNC buffer and post the invalidate request. none
1003 static void scic_sds_remote_node_context_invalidate_context_buffer(
1004 struct scic_sds_remote_node_context *this_rnc)
1006 union scu_remote_node_context *rnc_buffer;
1008 rnc_buffer = scic_sds_controller_get_remote_node_context_buffer(
1009 scic_sds_remote_device_get_controller(this_rnc->device),
1010 this_rnc->remote_node_index
1013 rnc_buffer->ssp.is_valid = false;
1015 scic_sds_remote_device_post_request(
1017 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
1020 if (this_rnc->device->is_direct_attached) {
1021 scic_sds_port_set_direct_attached_device_id(
1022 this_rnc->device->owning_port,
1023 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
1029 * *****************************************************************************
1030 * * REMOTE NODE CONTEXT STATE ENTER AND EXIT METHODS
1031 * ***************************************************************************** */
1038 static void scic_sds_remote_node_context_initial_state_enter(
1039 struct sci_base_object *object)
1041 struct scic_sds_remote_node_context *rnc;
1043 rnc = (struct scic_sds_remote_node_context *)object;
1047 scic_sds_remote_node_context_state_handler_table,
1048 SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE
1052 * Check to see if we have gotten back to the initial state because someone
1053 * requested to destroy the remote node context object. */
1055 rnc->state_machine.previous_state_id
1056 == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1058 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1060 scic_sds_remote_node_context_notify_user(rnc);
1069 static void scic_sds_remote_node_context_posting_state_enter(
1070 struct sci_base_object *object)
1072 struct scic_sds_remote_node_context *this_rnc;
1074 this_rnc = (struct scic_sds_remote_node_context *)object;
1078 scic_sds_remote_node_context_state_handler_table,
1079 SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE
1082 scic_sds_remote_node_context_validate_context_buffer(this_rnc);
1090 static void scic_sds_remote_node_context_invalidating_state_enter(
1091 struct sci_base_object *object)
1093 struct scic_sds_remote_node_context *rnc;
1095 rnc = (struct scic_sds_remote_node_context *)object;
1099 scic_sds_remote_node_context_state_handler_table,
1100 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE
1103 scic_sds_remote_node_context_invalidate_context_buffer(rnc);
1111 static void scic_sds_remote_node_context_resuming_state_enter(
1112 struct sci_base_object *object)
1114 struct scic_sds_remote_node_context *rnc;
1116 rnc = (struct scic_sds_remote_node_context *)object;
1120 scic_sds_remote_node_context_state_handler_table,
1121 SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE
1124 scic_sds_remote_device_post_request(
1126 SCU_CONTEXT_COMMAND_POST_RNC_RESUME
1135 static void scic_sds_remote_node_context_ready_state_enter(
1136 struct sci_base_object *object)
1138 struct scic_sds_remote_node_context *rnc;
1140 rnc = (struct scic_sds_remote_node_context *)object;
1144 scic_sds_remote_node_context_state_handler_table,
1145 SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE
1148 rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;
1150 if (rnc->user_callback != NULL) {
1151 scic_sds_remote_node_context_notify_user(rnc);
1160 static void scic_sds_remote_node_context_tx_suspended_state_enter(
1161 struct sci_base_object *object)
1163 struct scic_sds_remote_node_context *rnc;
1165 rnc = (struct scic_sds_remote_node_context *)object;
1169 scic_sds_remote_node_context_state_handler_table,
1170 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE
1173 scic_sds_remote_node_context_continue_state_transitions(rnc);
1181 static void scic_sds_remote_node_context_tx_rx_suspended_state_enter(
1182 struct sci_base_object *object)
1184 struct scic_sds_remote_node_context *rnc;
1186 rnc = (struct scic_sds_remote_node_context *)object;
1190 scic_sds_remote_node_context_state_handler_table,
1191 SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE
1194 scic_sds_remote_node_context_continue_state_transitions(rnc);
1202 static void scic_sds_remote_node_context_await_suspension_state_enter(
1203 struct sci_base_object *object)
1205 struct scic_sds_remote_node_context *rnc;
1207 rnc = (struct scic_sds_remote_node_context *)object;
1211 scic_sds_remote_node_context_state_handler_table,
1212 SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE
1216 /* --------------------------------------------------------------------------- */
1218 const struct sci_base_state scic_sds_remote_node_context_state_table[] = {
1219 [SCIC_SDS_REMOTE_NODE_CONTEXT_INITIAL_STATE] = {
1220 .enter_state = scic_sds_remote_node_context_initial_state_enter,
1222 [SCIC_SDS_REMOTE_NODE_CONTEXT_POSTING_STATE] = {
1223 .enter_state = scic_sds_remote_node_context_posting_state_enter,
1225 [SCIC_SDS_REMOTE_NODE_CONTEXT_INVALIDATING_STATE] = {
1226 .enter_state = scic_sds_remote_node_context_invalidating_state_enter,
1228 [SCIC_SDS_REMOTE_NODE_CONTEXT_RESUMING_STATE] = {
1229 .enter_state = scic_sds_remote_node_context_resuming_state_enter,
1231 [SCIC_SDS_REMOTE_NODE_CONTEXT_READY_STATE] = {
1232 .enter_state = scic_sds_remote_node_context_ready_state_enter,
1234 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_SUSPENDED_STATE] = {
1235 .enter_state = scic_sds_remote_node_context_tx_suspended_state_enter,
1237 [SCIC_SDS_REMOTE_NODE_CONTEXT_TX_RX_SUSPENDED_STATE] = {
1238 .enter_state = scic_sds_remote_node_context_tx_rx_suspended_state_enter,
1240 [SCIC_SDS_REMOTE_NODE_CONTEXT_AWAIT_SUSPENSION_STATE] = {
1241 .enter_state = scic_sds_remote_node_context_await_suspension_state_enter,