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.
55 #include <scsi/sas_ata.h>
58 #include "remote_device.h"
59 #include "remote_node_context.h"
60 #include "scu_event_codes.h"
61 #include "scu_task_context.h"
65 const char *rnc_state_name(enum scis_sds_remote_node_context_states state)
67 static const char * const strings[] = RNC_STATES;
69 return strings[state];
75 * @sci_rnc: The state of the remote node context object to check.
77 * This method will return true if the remote node context is in a READY state
78 * otherwise it will return false bool true if the remote node context is in
79 * the ready state. false if the remote node context is not in the ready state.
81 bool sci_remote_node_context_is_ready(
82 struct sci_remote_node_context *sci_rnc)
84 u32 current_state = sci_rnc->sm.current_state_id;
86 if (current_state == SCI_RNC_READY) {
93 bool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc)
95 u32 current_state = sci_rnc->sm.current_state_id;
97 if (current_state == SCI_RNC_TX_RX_SUSPENDED)
102 static union scu_remote_node_context *sci_rnc_by_id(struct isci_host *ihost, u16 id)
104 if (id < ihost->remote_node_entries &&
105 ihost->device_table[id])
106 return &ihost->remote_node_context_table[id];
111 static void sci_remote_node_context_construct_buffer(struct sci_remote_node_context *sci_rnc)
113 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
114 struct domain_device *dev = idev->domain_dev;
115 int rni = sci_rnc->remote_node_index;
116 union scu_remote_node_context *rnc;
117 struct isci_host *ihost;
120 ihost = idev->owning_port->owning_controller;
121 rnc = sci_rnc_by_id(ihost, rni);
123 memset(rnc, 0, sizeof(union scu_remote_node_context)
124 * sci_remote_device_node_count(idev));
126 rnc->ssp.remote_node_index = rni;
127 rnc->ssp.remote_node_port_width = idev->device_port_width;
128 rnc->ssp.logical_port_index = idev->owning_port->physical_port_index;
130 /* sas address is __be64, context ram format is __le64 */
131 sas_addr = cpu_to_le64(SAS_ADDR(dev->sas_addr));
132 rnc->ssp.remote_sas_address_hi = upper_32_bits(sas_addr);
133 rnc->ssp.remote_sas_address_lo = lower_32_bits(sas_addr);
135 rnc->ssp.nexus_loss_timer_enable = true;
136 rnc->ssp.check_bit = false;
137 rnc->ssp.is_valid = false;
138 rnc->ssp.is_remote_node_context = true;
139 rnc->ssp.function_number = 0;
141 rnc->ssp.arbitration_wait_time = 0;
143 if (dev_is_sata(dev)) {
144 rnc->ssp.connection_occupancy_timeout =
145 ihost->user_parameters.stp_max_occupancy_timeout;
146 rnc->ssp.connection_inactivity_timeout =
147 ihost->user_parameters.stp_inactivity_timeout;
149 rnc->ssp.connection_occupancy_timeout =
150 ihost->user_parameters.ssp_max_occupancy_timeout;
151 rnc->ssp.connection_inactivity_timeout =
152 ihost->user_parameters.ssp_inactivity_timeout;
155 rnc->ssp.initial_arbitration_wait_time = 0;
157 /* Open Address Frame Parameters */
158 rnc->ssp.oaf_connection_rate = idev->connection_rate;
159 rnc->ssp.oaf_features = 0;
160 rnc->ssp.oaf_source_zone_group = 0;
161 rnc->ssp.oaf_more_compatibility_features = 0;
167 * @callback_parameter:
169 * This method will setup the remote node context object so it will transition
170 * to its ready state. If the remote node context is already setup to
171 * transition to its final state then this function does nothing. none
173 static void sci_remote_node_context_setup_to_resume(
174 struct sci_remote_node_context *sci_rnc,
175 scics_sds_remote_node_context_callback callback,
176 void *callback_parameter,
177 enum sci_remote_node_context_destination_state dest_param)
179 if (sci_rnc->destination_state != RNC_DEST_FINAL) {
180 sci_rnc->destination_state = dest_param;
181 if (callback != NULL) {
182 sci_rnc->user_callback = callback;
183 sci_rnc->user_cookie = callback_parameter;
188 static void sci_remote_node_context_setup_to_destroy(
189 struct sci_remote_node_context *sci_rnc,
190 scics_sds_remote_node_context_callback callback,
191 void *callback_parameter)
193 struct isci_host *ihost = idev_to_ihost(rnc_to_dev(sci_rnc));
195 sci_rnc->destination_state = RNC_DEST_FINAL;
196 sci_rnc->user_callback = callback;
197 sci_rnc->user_cookie = callback_parameter;
199 wake_up(&ihost->eventq);
205 * This method just calls the user callback function and then resets the
208 static void sci_remote_node_context_notify_user(
209 struct sci_remote_node_context *rnc)
211 if (rnc->user_callback != NULL) {
212 (*rnc->user_callback)(rnc->user_cookie);
214 rnc->user_callback = NULL;
215 rnc->user_cookie = NULL;
219 static void sci_remote_node_context_continue_state_transitions(struct sci_remote_node_context *rnc)
221 switch (rnc->destination_state) {
223 case RNC_DEST_SUSPENDED_RESUME:
224 rnc->destination_state = RNC_DEST_READY;
225 /* Fall through... */
227 sci_remote_node_context_resume(rnc, rnc->user_callback,
231 rnc->destination_state = RNC_DEST_UNSPECIFIED;
236 static void sci_remote_node_context_validate_context_buffer(struct sci_remote_node_context *sci_rnc)
238 union scu_remote_node_context *rnc_buffer;
239 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
240 struct domain_device *dev = idev->domain_dev;
241 struct isci_host *ihost = idev->owning_port->owning_controller;
243 rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
245 rnc_buffer->ssp.is_valid = true;
247 if (dev_is_sata(dev) && dev->parent) {
248 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_96);
250 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_32);
253 sci_port_setup_transports(idev->owning_port,
254 sci_rnc->remote_node_index);
258 static void sci_remote_node_context_invalidate_context_buffer(struct sci_remote_node_context *sci_rnc)
260 union scu_remote_node_context *rnc_buffer;
261 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
262 struct isci_host *ihost = idev->owning_port->owning_controller;
264 rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
266 rnc_buffer->ssp.is_valid = false;
268 sci_remote_device_post_request(rnc_to_dev(sci_rnc),
269 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
272 static void sci_remote_node_context_initial_state_enter(struct sci_base_state_machine *sm)
274 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
275 struct isci_remote_device *idev = rnc_to_dev(rnc);
276 struct isci_host *ihost = idev->owning_port->owning_controller;
278 /* Check to see if we have gotten back to the initial state because
279 * someone requested to destroy the remote node context object.
281 if (sm->previous_state_id == SCI_RNC_INVALIDATING) {
282 rnc->destination_state = RNC_DEST_UNSPECIFIED;
283 sci_remote_node_context_notify_user(rnc);
286 wake_up(&ihost->eventq);
290 static void sci_remote_node_context_posting_state_enter(struct sci_base_state_machine *sm)
292 struct sci_remote_node_context *sci_rnc = container_of(sm, typeof(*sci_rnc), sm);
294 sci_remote_node_context_validate_context_buffer(sci_rnc);
297 static void sci_remote_node_context_invalidating_state_enter(struct sci_base_state_machine *sm)
299 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
301 /* Terminate all outstanding requests. */
302 sci_remote_device_terminate_requests(rnc_to_dev(rnc));
303 sci_remote_node_context_invalidate_context_buffer(rnc);
306 static void sci_remote_node_context_resuming_state_enter(struct sci_base_state_machine *sm)
308 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
309 struct isci_remote_device *idev;
310 struct domain_device *dev;
312 idev = rnc_to_dev(rnc);
313 dev = idev->domain_dev;
316 * For direct attached SATA devices we need to clear the TLCR
317 * NCQ to TCi tag mapping on the phy and in cases where we
318 * resume because of a target reset we also need to update
319 * the STPTLDARNI register with the RNi of the device
321 if (dev_is_sata(dev) && !dev->parent)
322 sci_port_setup_transports(idev->owning_port, rnc->remote_node_index);
324 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
327 static void sci_remote_node_context_ready_state_enter(struct sci_base_state_machine *sm)
329 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
330 enum sci_remote_node_context_destination_state dest_select;
333 dest_select = rnc->destination_state;
334 rnc->destination_state = RNC_DEST_UNSPECIFIED;
336 if ((dest_select == RNC_DEST_SUSPENDED) ||
337 (dest_select == RNC_DEST_SUSPENDED_RESUME)) {
338 sci_remote_node_context_suspend(
339 rnc, rnc->suspend_reason,
340 SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT);
342 if (dest_select == RNC_DEST_SUSPENDED_RESUME)
343 tell_user = 0; /* Wait until ready again. */
346 sci_remote_node_context_notify_user(rnc);
349 static void sci_remote_node_context_tx_suspended_state_enter(struct sci_base_state_machine *sm)
351 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
353 sci_remote_node_context_continue_state_transitions(rnc);
356 static void sci_remote_node_context_tx_rx_suspended_state_enter(struct sci_base_state_machine *sm)
358 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
359 struct isci_remote_device *idev = rnc_to_dev(rnc);
360 struct isci_host *ihost = idev->owning_port->owning_controller;
361 u32 new_count = rnc->suspend_count + 1;
364 rnc->suspend_count = 1;
366 rnc->suspend_count = new_count;
369 /* Terminate outstanding requests pending abort. */
370 sci_remote_device_abort_requests_pending_abort(idev);
372 wake_up(&ihost->eventq);
373 sci_remote_node_context_continue_state_transitions(rnc);
376 static void sci_remote_node_context_await_suspend_state_exit(
377 struct sci_base_state_machine *sm)
379 struct sci_remote_node_context *rnc
380 = container_of(sm, typeof(*rnc), sm);
381 struct isci_remote_device *idev = rnc_to_dev(rnc);
383 if (dev_is_sata(idev->domain_dev))
384 isci_dev_set_hang_detection_timeout(idev, 0);
387 static const struct sci_base_state sci_remote_node_context_state_table[] = {
388 [SCI_RNC_INITIAL] = {
389 .enter_state = sci_remote_node_context_initial_state_enter,
391 [SCI_RNC_POSTING] = {
392 .enter_state = sci_remote_node_context_posting_state_enter,
394 [SCI_RNC_INVALIDATING] = {
395 .enter_state = sci_remote_node_context_invalidating_state_enter,
397 [SCI_RNC_RESUMING] = {
398 .enter_state = sci_remote_node_context_resuming_state_enter,
401 .enter_state = sci_remote_node_context_ready_state_enter,
403 [SCI_RNC_TX_SUSPENDED] = {
404 .enter_state = sci_remote_node_context_tx_suspended_state_enter,
406 [SCI_RNC_TX_RX_SUSPENDED] = {
407 .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter,
409 [SCI_RNC_AWAIT_SUSPENSION] = {
410 .exit_state = sci_remote_node_context_await_suspend_state_exit,
414 void sci_remote_node_context_construct(struct sci_remote_node_context *rnc,
415 u16 remote_node_index)
417 memset(rnc, 0, sizeof(struct sci_remote_node_context));
419 rnc->remote_node_index = remote_node_index;
420 rnc->destination_state = RNC_DEST_UNSPECIFIED;
422 sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL);
425 enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc,
428 enum scis_sds_remote_node_context_states state;
431 state = sci_rnc->sm.current_state_id;
433 case SCI_RNC_POSTING:
434 switch (scu_get_event_code(event_code)) {
435 case SCU_EVENT_POST_RNC_COMPLETE:
436 sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
442 case SCI_RNC_INVALIDATING:
443 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
444 if (sci_rnc->destination_state == RNC_DEST_FINAL)
445 next_state = SCI_RNC_INITIAL;
447 next_state = SCI_RNC_POSTING;
448 sci_change_state(&sci_rnc->sm, next_state);
450 switch (scu_get_event_type(event_code)) {
451 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
452 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
453 /* We really dont care if the hardware is going to suspend
454 * the device since it's being invalidated anyway */
455 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
456 "%s: SCIC Remote Node Context 0x%p was "
457 "suspeneded by hardware while being "
458 "invalidated.\n", __func__, sci_rnc);
465 case SCI_RNC_RESUMING:
466 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
467 sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
469 switch (scu_get_event_type(event_code)) {
470 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
471 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
472 /* We really dont care if the hardware is going to suspend
473 * the device since it's being resumed anyway */
474 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
475 "%s: SCIC Remote Node Context 0x%p was "
476 "suspeneded by hardware while being resumed.\n",
485 switch (scu_get_event_type(event_code)) {
486 case SCU_EVENT_TL_RNC_SUSPEND_TX:
487 sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
488 sci_rnc->suspend_type = scu_get_event_type(event_code);
490 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
491 sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
492 sci_rnc->suspend_type = scu_get_event_type(event_code);
498 case SCI_RNC_AWAIT_SUSPENSION:
499 switch (scu_get_event_type(event_code)) {
500 case SCU_EVENT_TL_RNC_SUSPEND_TX:
501 next_state = SCI_RNC_TX_SUSPENDED;
503 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
504 next_state = SCI_RNC_TX_RX_SUSPENDED;
509 if (sci_rnc->suspend_type == scu_get_event_type(event_code))
510 sci_change_state(&sci_rnc->sm, next_state);
513 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
514 "%s: invalid state: %s\n", __func__,
515 rnc_state_name(state));
516 return SCI_FAILURE_INVALID_STATE;
521 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
522 "%s: code: %#x state: %s\n", __func__, event_code,
523 rnc_state_name(state));
528 enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc,
529 scics_sds_remote_node_context_callback cb_fn,
532 enum scis_sds_remote_node_context_states state;
534 state = sci_rnc->sm.current_state_id;
536 case SCI_RNC_INVALIDATING:
537 sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p);
539 case SCI_RNC_POSTING:
540 case SCI_RNC_RESUMING:
542 case SCI_RNC_TX_SUSPENDED:
543 case SCI_RNC_TX_RX_SUSPENDED:
544 sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p);
545 sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
547 case SCI_RNC_AWAIT_SUSPENSION:
548 sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p);
550 case SCI_RNC_INITIAL:
551 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
552 "%s: invalid state: %s\n", __func__,
553 rnc_state_name(state));
554 /* We have decided that the destruct request on the remote node context
555 * can not fail since it is either in the initial/destroyed state or is
560 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
561 "%s: invalid state %s\n", __func__,
562 rnc_state_name(state));
563 return SCI_FAILURE_INVALID_STATE;
567 enum sci_status sci_remote_node_context_suspend(
568 struct sci_remote_node_context *sci_rnc,
569 enum sci_remote_node_suspension_reasons suspend_reason,
572 enum scis_sds_remote_node_context_states state
573 = sci_rnc->sm.current_state_id;
574 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
575 enum sci_status status = SCI_FAILURE_INVALID_STATE;
576 enum sci_remote_node_context_destination_state dest_param =
577 RNC_DEST_UNSPECIFIED;
579 dev_dbg(scirdev_to_dev(idev),
580 "%s: current state %s, current suspend_type %x dest state %d,"
581 " arg suspend_reason %d, arg suspend_type %x",
582 __func__, rnc_state_name(state), sci_rnc->suspend_type,
583 sci_rnc->destination_state, suspend_reason,
586 /* Disable automatic state continuations if explicitly suspending. */
587 if ((suspend_reason == SCI_HW_SUSPEND) ||
588 (sci_rnc->destination_state == RNC_DEST_FINAL))
589 dest_param = sci_rnc->destination_state;
594 case SCI_RNC_INVALIDATING:
595 if (sci_rnc->destination_state == RNC_DEST_FINAL) {
596 dev_warn(scirdev_to_dev(idev),
597 "%s: already destroying %p\n",
599 return SCI_FAILURE_INVALID_STATE;
601 /* Fall through and handle like SCI_RNC_POSTING */
602 case SCI_RNC_RESUMING:
603 /* Fall through and handle like SCI_RNC_POSTING */
604 case SCI_RNC_POSTING:
605 /* Set the destination state to AWAIT - this signals the
606 * entry into the SCI_RNC_READY state that a suspension
607 * needs to be done immediately.
609 if (sci_rnc->destination_state != RNC_DEST_FINAL)
610 sci_rnc->destination_state = RNC_DEST_SUSPENDED;
611 sci_rnc->suspend_type = suspend_type;
612 sci_rnc->suspend_reason = suspend_reason;
615 case SCI_RNC_TX_SUSPENDED:
616 if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX)
617 status = SCI_SUCCESS;
619 case SCI_RNC_TX_RX_SUSPENDED:
620 if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX)
621 status = SCI_SUCCESS;
623 case SCI_RNC_AWAIT_SUSPENSION:
624 if ((sci_rnc->suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX)
625 || (suspend_type == sci_rnc->suspend_type))
629 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
630 "%s: invalid state %s\n", __func__,
631 rnc_state_name(state));
632 return SCI_FAILURE_INVALID_STATE;
634 sci_rnc->destination_state = dest_param;
635 sci_rnc->suspend_type = suspend_type;
636 sci_rnc->suspend_reason = suspend_reason;
638 if (status == SCI_SUCCESS) { /* Already in the destination state? */
639 struct isci_host *ihost = idev->owning_port->owning_controller;
641 wake_up_all(&ihost->eventq); /* Let observers look. */
644 if ((suspend_reason == SCI_SW_SUSPEND_NORMAL) ||
645 (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)) {
647 if (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)
648 isci_dev_set_hang_detection_timeout(idev, 0x00000001);
650 sci_remote_device_post_request(
651 idev, SCI_SOFTWARE_SUSPEND_CMD);
653 if (state != SCI_RNC_AWAIT_SUSPENSION)
654 sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION);
659 enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc,
660 scics_sds_remote_node_context_callback cb_fn,
663 enum scis_sds_remote_node_context_states state;
664 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
666 state = sci_rnc->sm.current_state_id;
667 dev_dbg(scirdev_to_dev(idev),
668 "%s: state %s, cb_fn = %p, cb_p = %p; dest_state = %d; "
669 "dev resume path %s\n",
670 __func__, rnc_state_name(state), cb_fn, cb_p,
671 sci_rnc->destination_state,
672 test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)
673 ? "<abort active>" : "<normal>");
676 case SCI_RNC_INITIAL:
677 if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
678 return SCI_FAILURE_INVALID_STATE;
680 sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn, cb_p,
682 if (!test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) {
683 sci_remote_node_context_construct_buffer(sci_rnc);
684 sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING);
688 case SCI_RNC_POSTING:
689 case SCI_RNC_INVALIDATING:
690 case SCI_RNC_RESUMING:
691 /* We are still waiting to post when a resume was
694 switch (sci_rnc->destination_state) {
695 case RNC_DEST_SUSPENDED:
696 case RNC_DEST_SUSPENDED_RESUME:
697 /* Previously waiting to suspend after posting.
698 * Now continue onto resumption.
700 sci_remote_node_context_setup_to_resume(
701 sci_rnc, cb_fn, cb_p,
702 RNC_DEST_SUSPENDED_RESUME);
705 sci_remote_node_context_setup_to_resume(
706 sci_rnc, cb_fn, cb_p,
712 case SCI_RNC_TX_SUSPENDED:
713 case SCI_RNC_TX_RX_SUSPENDED:
715 struct domain_device *dev = idev->domain_dev;
716 /* If this is an expander attached SATA device we must
717 * invalidate and repost the RNC since this is the only
718 * way to clear the TCi to NCQ tag mapping table for
719 * the RNi. All other device types we can just resume.
721 sci_remote_node_context_setup_to_resume(
722 sci_rnc, cb_fn, cb_p, RNC_DEST_READY);
724 if (!test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)) {
725 if ((dev_is_sata(dev) && dev->parent) ||
726 (sci_rnc->destination_state == RNC_DEST_FINAL))
727 sci_change_state(&sci_rnc->sm,
728 SCI_RNC_INVALIDATING);
730 sci_change_state(&sci_rnc->sm,
736 case SCI_RNC_AWAIT_SUSPENSION:
737 sci_remote_node_context_setup_to_resume(
738 sci_rnc, cb_fn, cb_p, RNC_DEST_SUSPENDED_RESUME);
741 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
742 "%s: invalid state %s\n", __func__,
743 rnc_state_name(state));
744 return SCI_FAILURE_INVALID_STATE;
748 enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc,
749 struct isci_request *ireq)
751 enum scis_sds_remote_node_context_states state;
753 state = sci_rnc->sm.current_state_id;
758 case SCI_RNC_TX_SUSPENDED:
759 case SCI_RNC_TX_RX_SUSPENDED:
760 case SCI_RNC_AWAIT_SUSPENSION:
761 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
762 "%s: invalid state %s\n", __func__,
763 rnc_state_name(state));
764 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
766 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
767 "%s: invalid state %s\n", __func__,
768 rnc_state_name(state));
769 return SCI_FAILURE_INVALID_STATE;
773 enum sci_status sci_remote_node_context_start_task(
774 struct sci_remote_node_context *sci_rnc,
775 struct isci_request *ireq,
776 scics_sds_remote_node_context_callback cb_fn,
779 enum sci_status status = sci_remote_node_context_resume(sci_rnc,
781 if (status != SCI_SUCCESS)
782 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
783 "%s: resume failed: %d\n", __func__, status);
787 int sci_remote_node_context_is_safe_to_abort(
788 struct sci_remote_node_context *sci_rnc)
790 enum scis_sds_remote_node_context_states state;
792 state = sci_rnc->sm.current_state_id;
794 case SCI_RNC_INVALIDATING:
795 case SCI_RNC_TX_RX_SUSPENDED:
797 case SCI_RNC_POSTING:
798 case SCI_RNC_RESUMING:
800 case SCI_RNC_TX_SUSPENDED:
801 case SCI_RNC_AWAIT_SUSPENSION:
802 case SCI_RNC_INITIAL:
805 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
806 "%s: invalid state %d\n", __func__, state);