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;
164 static void sci_remote_node_context_save_cbparams(
165 struct sci_remote_node_context *sci_rnc,
166 scics_sds_remote_node_context_callback callback,
167 void *callback_parameter)
169 sci_rnc->user_callback = callback;
170 sci_rnc->user_cookie = callback_parameter;
176 * @callback_parameter:
178 * This method will setup the remote node context object so it will transition
179 * to its ready state. If the remote node context is already setup to
180 * transition to its final state then this function does nothing. none
182 static void sci_remote_node_context_setup_to_resume(
183 struct sci_remote_node_context *sci_rnc,
184 scics_sds_remote_node_context_callback callback,
185 void *callback_parameter,
186 enum sci_remote_node_context_destination_state dest_param)
188 if (sci_rnc->destination_state != RNC_DEST_FINAL) {
189 sci_rnc->destination_state = dest_param;
190 if (callback != NULL)
191 sci_remote_node_context_save_cbparams(
192 sci_rnc, callback, callback_parameter);
196 static void sci_remote_node_context_setup_to_destroy(
197 struct sci_remote_node_context *sci_rnc,
198 scics_sds_remote_node_context_callback callback,
199 void *callback_parameter)
201 sci_rnc->destination_state = RNC_DEST_FINAL;
202 sci_rnc->user_callback = callback;
203 sci_rnc->user_cookie = callback_parameter;
209 * This method just calls the user callback function and then resets the
212 static void sci_remote_node_context_notify_user(
213 struct sci_remote_node_context *rnc)
215 if (rnc->user_callback != NULL) {
216 (*rnc->user_callback)(rnc->user_cookie);
218 rnc->user_callback = NULL;
219 rnc->user_cookie = NULL;
223 static void sci_remote_node_context_continue_state_transitions(struct sci_remote_node_context *rnc)
225 if ((rnc->destination_state == RNC_DEST_READY) ||
226 (rnc->destination_state == RNC_DEST_SUSPENDED_RESUME)) {
227 rnc->destination_state = RNC_DEST_READY;
228 sci_remote_node_context_resume(rnc, rnc->user_callback,
231 rnc->destination_state = RNC_DEST_UNSPECIFIED;
234 static void sci_remote_node_context_validate_context_buffer(struct sci_remote_node_context *sci_rnc)
236 union scu_remote_node_context *rnc_buffer;
237 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
238 struct domain_device *dev = idev->domain_dev;
239 struct isci_host *ihost = idev->owning_port->owning_controller;
241 rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
243 rnc_buffer->ssp.is_valid = true;
245 if (dev_is_sata(dev) && dev->parent) {
246 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_96);
248 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_32);
251 sci_port_setup_transports(idev->owning_port,
252 sci_rnc->remote_node_index);
256 static void sci_remote_node_context_invalidate_context_buffer(struct sci_remote_node_context *sci_rnc)
258 union scu_remote_node_context *rnc_buffer;
259 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
260 struct isci_host *ihost = idev->owning_port->owning_controller;
262 rnc_buffer = sci_rnc_by_id(ihost, sci_rnc->remote_node_index);
264 rnc_buffer->ssp.is_valid = false;
266 sci_remote_device_post_request(rnc_to_dev(sci_rnc),
267 SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE);
270 static void sci_remote_node_context_initial_state_enter(struct sci_base_state_machine *sm)
272 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
274 /* Check to see if we have gotten back to the initial state because
275 * someone requested to destroy the remote node context object.
277 if (sm->previous_state_id == SCI_RNC_INVALIDATING) {
278 rnc->destination_state = RNC_DEST_UNSPECIFIED;
279 sci_remote_node_context_notify_user(rnc);
283 static void sci_remote_node_context_posting_state_enter(struct sci_base_state_machine *sm)
285 struct sci_remote_node_context *sci_rnc = container_of(sm, typeof(*sci_rnc), sm);
287 sci_remote_node_context_validate_context_buffer(sci_rnc);
290 static void sci_remote_node_context_invalidating_state_enter(struct sci_base_state_machine *sm)
292 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
294 /* Terminate all outstanding requests. */
295 sci_remote_device_terminate_requests(rnc_to_dev(rnc));
296 sci_remote_node_context_invalidate_context_buffer(rnc);
299 static void sci_remote_node_context_resuming_state_enter(struct sci_base_state_machine *sm)
301 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
302 struct isci_remote_device *idev;
303 struct domain_device *dev;
305 idev = rnc_to_dev(rnc);
306 dev = idev->domain_dev;
309 * For direct attached SATA devices we need to clear the TLCR
310 * NCQ to TCi tag mapping on the phy and in cases where we
311 * resume because of a target reset we also need to update
312 * the STPTLDARNI register with the RNi of the device
314 if (dev_is_sata(dev) && !dev->parent)
315 sci_port_setup_transports(idev->owning_port, rnc->remote_node_index);
317 sci_remote_device_post_request(idev, SCU_CONTEXT_COMMAND_POST_RNC_RESUME);
320 static void sci_remote_node_context_ready_state_enter(struct sci_base_state_machine *sm)
322 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
323 enum sci_remote_node_context_destination_state dest_select;
326 dest_select = rnc->destination_state;
327 rnc->destination_state = RNC_DEST_UNSPECIFIED;
329 if ((dest_select == RNC_DEST_SUSPENDED) ||
330 (dest_select == RNC_DEST_SUSPENDED_RESUME)) {
331 sci_remote_node_context_suspend(
332 rnc, rnc->suspend_reason,
333 SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT);
335 if (dest_select == RNC_DEST_SUSPENDED_RESUME)
336 tell_user = 0; /* Wait until ready again. */
339 sci_remote_node_context_notify_user(rnc);
342 static void sci_remote_node_context_tx_suspended_state_enter(struct sci_base_state_machine *sm)
344 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
346 sci_remote_node_context_continue_state_transitions(rnc);
349 static void sci_remote_node_context_tx_rx_suspended_state_enter(struct sci_base_state_machine *sm)
351 struct sci_remote_node_context *rnc = container_of(sm, typeof(*rnc), sm);
352 struct isci_remote_device *idev = rnc_to_dev(rnc);
353 struct isci_host *ihost = idev->owning_port->owning_controller;
354 u32 new_count = rnc->suspend_count + 1;
357 rnc->suspend_count = 1;
359 rnc->suspend_count = new_count;
362 /* Terminate outstanding requests pending abort. */
363 sci_remote_device_abort_requests_pending_abort(idev);
365 wake_up(&ihost->eventq);
366 sci_remote_node_context_continue_state_transitions(rnc);
369 static void sci_remote_node_context_await_suspend_state_exit(
370 struct sci_base_state_machine *sm)
372 struct sci_remote_node_context *rnc
373 = container_of(sm, typeof(*rnc), sm);
374 struct isci_remote_device *idev = rnc_to_dev(rnc);
376 if (dev_is_sata(idev->domain_dev))
377 isci_dev_set_hang_detection_timeout(idev, 0);
380 static const struct sci_base_state sci_remote_node_context_state_table[] = {
381 [SCI_RNC_INITIAL] = {
382 .enter_state = sci_remote_node_context_initial_state_enter,
384 [SCI_RNC_POSTING] = {
385 .enter_state = sci_remote_node_context_posting_state_enter,
387 [SCI_RNC_INVALIDATING] = {
388 .enter_state = sci_remote_node_context_invalidating_state_enter,
390 [SCI_RNC_RESUMING] = {
391 .enter_state = sci_remote_node_context_resuming_state_enter,
394 .enter_state = sci_remote_node_context_ready_state_enter,
396 [SCI_RNC_TX_SUSPENDED] = {
397 .enter_state = sci_remote_node_context_tx_suspended_state_enter,
399 [SCI_RNC_TX_RX_SUSPENDED] = {
400 .enter_state = sci_remote_node_context_tx_rx_suspended_state_enter,
402 [SCI_RNC_AWAIT_SUSPENSION] = {
403 .exit_state = sci_remote_node_context_await_suspend_state_exit,
407 void sci_remote_node_context_construct(struct sci_remote_node_context *rnc,
408 u16 remote_node_index)
410 memset(rnc, 0, sizeof(struct sci_remote_node_context));
412 rnc->remote_node_index = remote_node_index;
413 rnc->destination_state = RNC_DEST_UNSPECIFIED;
415 sci_init_sm(&rnc->sm, sci_remote_node_context_state_table, SCI_RNC_INITIAL);
418 enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc,
421 enum scis_sds_remote_node_context_states state;
424 state = sci_rnc->sm.current_state_id;
426 case SCI_RNC_POSTING:
427 switch (scu_get_event_code(event_code)) {
428 case SCU_EVENT_POST_RNC_COMPLETE:
429 sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
435 case SCI_RNC_INVALIDATING:
436 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RNC_INVALIDATE_COMPLETE) {
437 if (sci_rnc->destination_state == RNC_DEST_FINAL)
438 next_state = SCI_RNC_INITIAL;
440 next_state = SCI_RNC_POSTING;
441 sci_change_state(&sci_rnc->sm, next_state);
443 switch (scu_get_event_type(event_code)) {
444 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
445 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
446 /* We really dont care if the hardware is going to suspend
447 * the device since it's being invalidated anyway */
448 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
449 "%s: SCIC Remote Node Context 0x%p was "
450 "suspeneded by hardware while being "
451 "invalidated.\n", __func__, sci_rnc);
458 case SCI_RNC_RESUMING:
459 if (scu_get_event_code(event_code) == SCU_EVENT_POST_RCN_RELEASE) {
460 sci_change_state(&sci_rnc->sm, SCI_RNC_READY);
462 switch (scu_get_event_type(event_code)) {
463 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
464 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
465 /* We really dont care if the hardware is going to suspend
466 * the device since it's being resumed anyway */
467 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
468 "%s: SCIC Remote Node Context 0x%p was "
469 "suspeneded by hardware while being resumed.\n",
478 switch (scu_get_event_type(event_code)) {
479 case SCU_EVENT_TL_RNC_SUSPEND_TX:
480 sci_change_state(&sci_rnc->sm, SCI_RNC_TX_SUSPENDED);
481 sci_rnc->suspend_type = scu_get_event_type(event_code);
483 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
484 sci_change_state(&sci_rnc->sm, SCI_RNC_TX_RX_SUSPENDED);
485 sci_rnc->suspend_type = scu_get_event_type(event_code);
491 case SCI_RNC_AWAIT_SUSPENSION:
492 switch (scu_get_event_type(event_code)) {
493 case SCU_EVENT_TL_RNC_SUSPEND_TX:
494 next_state = SCI_RNC_TX_SUSPENDED;
496 case SCU_EVENT_TL_RNC_SUSPEND_TX_RX:
497 next_state = SCI_RNC_TX_RX_SUSPENDED;
502 if (sci_rnc->suspend_type == scu_get_event_type(event_code))
503 sci_change_state(&sci_rnc->sm, next_state);
506 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
507 "%s: invalid state: %s\n", __func__,
508 rnc_state_name(state));
509 return SCI_FAILURE_INVALID_STATE;
514 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
515 "%s: code: %#x state: %s\n", __func__, event_code,
516 rnc_state_name(state));
521 enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc,
522 scics_sds_remote_node_context_callback cb_fn,
525 enum scis_sds_remote_node_context_states state;
527 state = sci_rnc->sm.current_state_id;
529 case SCI_RNC_INVALIDATING:
530 sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p);
532 case SCI_RNC_POSTING:
533 case SCI_RNC_RESUMING:
535 case SCI_RNC_TX_SUSPENDED:
536 case SCI_RNC_TX_RX_SUSPENDED:
537 case SCI_RNC_AWAIT_SUSPENSION:
538 sci_remote_node_context_setup_to_destroy(sci_rnc, cb_fn, cb_p);
539 sci_change_state(&sci_rnc->sm, SCI_RNC_INVALIDATING);
541 case SCI_RNC_INITIAL:
542 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
543 "%s: invalid state: %s\n", __func__,
544 rnc_state_name(state));
545 /* We have decided that the destruct request on the remote node context
546 * can not fail since it is either in the initial/destroyed state or is
551 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
552 "%s: invalid state %s\n", __func__,
553 rnc_state_name(state));
554 return SCI_FAILURE_INVALID_STATE;
558 enum sci_status sci_remote_node_context_suspend(
559 struct sci_remote_node_context *sci_rnc,
560 enum sci_remote_node_suspension_reasons suspend_reason,
563 enum scis_sds_remote_node_context_states state
564 = sci_rnc->sm.current_state_id;
565 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
566 enum sci_status status = SCI_FAILURE_INVALID_STATE;
567 enum sci_remote_node_context_destination_state dest_param =
568 RNC_DEST_UNSPECIFIED;
570 dev_dbg(scirdev_to_dev(idev),
571 "%s: current state %d, current suspend_type %x dest state %d,"
572 " arg suspend_reason %d, arg suspend_type %x",
573 __func__, state, sci_rnc->suspend_type,
574 sci_rnc->destination_state, suspend_reason,
577 /* Disable automatic state continuations if explicitly suspending. */
578 if ((suspend_reason == SCI_HW_SUSPEND) ||
579 (sci_rnc->destination_state == RNC_DEST_FINAL))
580 dest_param = sci_rnc->destination_state;
585 case SCI_RNC_INVALIDATING:
586 if (sci_rnc->destination_state == RNC_DEST_FINAL) {
587 dev_warn(scirdev_to_dev(idev),
588 "%s: already destroying %p\n",
590 return SCI_FAILURE_INVALID_STATE;
592 /* Fall through and handle like SCI_RNC_POSTING */
593 case SCI_RNC_RESUMING:
594 /* Fall through and handle like SCI_RNC_POSTING */
595 case SCI_RNC_POSTING:
596 /* Set the destination state to AWAIT - this signals the
597 * entry into the SCI_RNC_READY state that a suspension
598 * needs to be done immediately.
600 sci_rnc->destination_state = RNC_DEST_SUSPENDED;
601 sci_rnc->suspend_type = suspend_type;
602 sci_rnc->suspend_reason = suspend_reason;
605 case SCI_RNC_TX_SUSPENDED:
606 if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX)
607 status = SCI_SUCCESS;
609 case SCI_RNC_TX_RX_SUSPENDED:
610 if (suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX)
611 status = SCI_SUCCESS;
613 case SCI_RNC_AWAIT_SUSPENSION:
614 if ((sci_rnc->suspend_type == SCU_EVENT_TL_RNC_SUSPEND_TX_RX)
615 || (suspend_type == sci_rnc->suspend_type))
619 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
620 "%s: invalid state %s\n", __func__,
621 rnc_state_name(state));
622 return SCI_FAILURE_INVALID_STATE;
624 sci_rnc->destination_state = dest_param;
625 sci_rnc->suspend_type = suspend_type;
626 sci_rnc->suspend_reason = suspend_reason;
628 if (status == SCI_SUCCESS) { /* Already in the destination state? */
629 struct isci_host *ihost = idev->owning_port->owning_controller;
631 wake_up_all(&ihost->eventq); /* Let observers look. */
634 if ((suspend_reason == SCI_SW_SUSPEND_NORMAL) ||
635 (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)) {
637 if (suspend_reason == SCI_SW_SUSPEND_LINKHANG_DETECT)
638 isci_dev_set_hang_detection_timeout(idev, 0x00000001);
640 sci_remote_device_post_request(
641 idev, SCI_SOFTWARE_SUSPEND_CMD);
643 if (state != SCI_RNC_AWAIT_SUSPENSION)
644 sci_change_state(&sci_rnc->sm, SCI_RNC_AWAIT_SUSPENSION);
649 enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc,
650 scics_sds_remote_node_context_callback cb_fn,
653 enum scis_sds_remote_node_context_states state;
654 struct isci_remote_device *idev = rnc_to_dev(sci_rnc);
656 state = sci_rnc->sm.current_state_id;
657 dev_dbg(scirdev_to_dev(idev),
658 "%s: state %s, cb_fn = %p, cb_p = %p; dest_state = %d; "
659 "dev resume path %s\n",
660 __func__, rnc_state_name(state), cb_fn, cb_p,
661 sci_rnc->destination_state,
662 test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags)
663 ? "<abort active>" : "<normal>");
666 case SCI_RNC_INITIAL:
667 if (sci_rnc->remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
668 return SCI_FAILURE_INVALID_STATE;
670 if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags))
671 sci_remote_node_context_save_cbparams(sci_rnc, cb_fn,
674 sci_remote_node_context_setup_to_resume(sci_rnc, cb_fn,
675 cb_p, RNC_DEST_READY);
676 sci_remote_node_context_construct_buffer(sci_rnc);
677 sci_change_state(&sci_rnc->sm, SCI_RNC_POSTING);
681 case SCI_RNC_POSTING:
682 case SCI_RNC_INVALIDATING:
683 case SCI_RNC_RESUMING:
684 if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags))
685 sci_remote_node_context_save_cbparams(sci_rnc, cb_fn,
688 /* We are still waiting to post when a resume was
691 switch (sci_rnc->destination_state) {
692 case RNC_DEST_SUSPENDED:
693 case RNC_DEST_SUSPENDED_RESUME:
694 /* Previously waiting to suspend after posting.
695 * Now continue onto resumption.
697 sci_remote_node_context_setup_to_resume(
698 sci_rnc, cb_fn, cb_p,
699 RNC_DEST_SUSPENDED_RESUME);
702 sci_remote_node_context_setup_to_resume(
703 sci_rnc, cb_fn, cb_p,
710 case SCI_RNC_TX_SUSPENDED:
711 case SCI_RNC_TX_RX_SUSPENDED:
712 if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags))
713 sci_remote_node_context_save_cbparams(sci_rnc, cb_fn,
716 struct domain_device *dev = idev->domain_dev;
717 /* If this is an expander attached SATA device we must
718 * invalidate and repost the RNC since this is the only
719 * way to clear the TCi to NCQ tag mapping table for
720 * the RNi. All other device types we can just resume.
722 sci_remote_node_context_setup_to_resume(
723 sci_rnc, cb_fn, cb_p, RNC_DEST_READY);
725 if (dev_is_sata(dev) && dev->parent)
726 sci_change_state(&sci_rnc->sm,
727 SCI_RNC_INVALIDATING);
729 sci_change_state(&sci_rnc->sm,
734 case SCI_RNC_AWAIT_SUSPENSION:
735 if (test_bit(IDEV_ABORT_PATH_ACTIVE, &idev->flags))
736 sci_remote_node_context_save_cbparams(sci_rnc, cb_fn,
739 sci_remote_node_context_setup_to_resume(
740 sci_rnc, cb_fn, cb_p,
741 RNC_DEST_SUSPENDED_RESUME);
744 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
745 "%s: invalid state %s\n", __func__,
746 rnc_state_name(state));
747 return SCI_FAILURE_INVALID_STATE;
751 enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc,
752 struct isci_request *ireq)
754 enum scis_sds_remote_node_context_states state;
756 state = sci_rnc->sm.current_state_id;
761 case SCI_RNC_TX_SUSPENDED:
762 case SCI_RNC_TX_RX_SUSPENDED:
763 case SCI_RNC_AWAIT_SUSPENSION:
764 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
765 "%s: invalid state %s\n", __func__,
766 rnc_state_name(state));
767 return SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED;
769 dev_dbg(scirdev_to_dev(rnc_to_dev(sci_rnc)),
770 "%s: invalid state %s\n", __func__,
771 rnc_state_name(state));
772 return SCI_FAILURE_INVALID_STATE;
776 enum sci_status sci_remote_node_context_start_task(
777 struct sci_remote_node_context *sci_rnc,
778 struct isci_request *ireq,
779 scics_sds_remote_node_context_callback cb_fn,
782 enum sci_status status = sci_remote_node_context_resume(sci_rnc,
784 if (status != SCI_SUCCESS)
785 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
786 "%s: resume failed: %d\n", __func__, status);
790 int sci_remote_node_context_is_safe_to_abort(
791 struct sci_remote_node_context *sci_rnc)
793 enum scis_sds_remote_node_context_states state;
795 state = sci_rnc->sm.current_state_id;
797 case SCI_RNC_INVALIDATING:
798 case SCI_RNC_TX_RX_SUSPENDED:
800 case SCI_RNC_POSTING:
801 case SCI_RNC_RESUMING:
803 case SCI_RNC_TX_SUSPENDED:
804 case SCI_RNC_AWAIT_SUSPENSION:
805 case SCI_RNC_INITIAL:
808 dev_warn(scirdev_to_dev(rnc_to_dev(sci_rnc)),
809 "%s: invalid state %d\n", __func__, state);