162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 362306a36Sopenharmony_ci * redistributing this file, you may do so under either license. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * GPL LICENSE SUMMARY 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 1062306a36Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 1162306a36Sopenharmony_ci * published by the Free Software Foundation. 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 1462306a36Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 1562306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1662306a36Sopenharmony_ci * General Public License for more details. 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License 1962306a36Sopenharmony_ci * along with this program; if not, write to the Free Software 2062306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 2162306a36Sopenharmony_ci * The full GNU General Public License is included in this distribution 2262306a36Sopenharmony_ci * in the file called LICENSE.GPL. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * BSD LICENSE 2562306a36Sopenharmony_ci * 2662306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 2762306a36Sopenharmony_ci * All rights reserved. 2862306a36Sopenharmony_ci * 2962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 3062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 3162306a36Sopenharmony_ci * are met: 3262306a36Sopenharmony_ci * 3362306a36Sopenharmony_ci * * Redistributions of source code must retain the above copyright 3462306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 3562306a36Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 3662306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 3762306a36Sopenharmony_ci * the documentation and/or other materials provided with the 3862306a36Sopenharmony_ci * distribution. 3962306a36Sopenharmony_ci * * Neither the name of Intel Corporation nor the names of its 4062306a36Sopenharmony_ci * contributors may be used to endorse or promote products derived 4162306a36Sopenharmony_ci * from this software without specific prior written permission. 4262306a36Sopenharmony_ci * 4362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4462306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4562306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4662306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4762306a36Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4862306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4962306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 5062306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5162306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5262306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5362306a36Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#ifndef _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ 5762306a36Sopenharmony_ci#define _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/** 6062306a36Sopenharmony_ci * This file contains the structures, constants, and prototypes associated with 6162306a36Sopenharmony_ci * the remote node context in the silicon. It exists to model and manage 6262306a36Sopenharmony_ci * the remote node context in the silicon. 6362306a36Sopenharmony_ci * 6462306a36Sopenharmony_ci * 6562306a36Sopenharmony_ci */ 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#include "isci.h" 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/** 7062306a36Sopenharmony_ci * 7162306a36Sopenharmony_ci * 7262306a36Sopenharmony_ci * This constant represents an invalid remote device id, it is used to program 7362306a36Sopenharmony_ci * the STPDARNI register so the driver knows when it has received a SIGNATURE 7462306a36Sopenharmony_ci * FIS from the SCU. 7562306a36Sopenharmony_ci */ 7662306a36Sopenharmony_ci#define SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX 0x0FFF 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cienum sci_remote_node_suspension_reasons { 7962306a36Sopenharmony_ci SCI_HW_SUSPEND, 8062306a36Sopenharmony_ci SCI_SW_SUSPEND_NORMAL, 8162306a36Sopenharmony_ci SCI_SW_SUSPEND_LINKHANG_DETECT 8262306a36Sopenharmony_ci}; 8362306a36Sopenharmony_ci#define SCI_SOFTWARE_SUSPEND_CMD SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX 8462306a36Sopenharmony_ci#define SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT SCU_EVENT_TL_RNC_SUSPEND_TX_RX 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistruct isci_request; 8762306a36Sopenharmony_cistruct isci_remote_device; 8862306a36Sopenharmony_cistruct sci_remote_node_context; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_citypedef void (*scics_sds_remote_node_context_callback)(void *); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/** 9362306a36Sopenharmony_ci * enum sci_remote_node_context_states 9462306a36Sopenharmony_ci * @SCI_RNC_INITIAL initial state for a remote node context. On a resume 9562306a36Sopenharmony_ci * request the remote node context will transition to the posting state. 9662306a36Sopenharmony_ci * 9762306a36Sopenharmony_ci * @SCI_RNC_POSTING: transition state that posts the RNi to the hardware. Once 9862306a36Sopenharmony_ci * the RNC is posted the remote node context will be made ready. 9962306a36Sopenharmony_ci * 10062306a36Sopenharmony_ci * @SCI_RNC_INVALIDATING: transition state that will post an RNC invalidate to 10162306a36Sopenharmony_ci * the hardware. Once the invalidate is complete the remote node context will 10262306a36Sopenharmony_ci * transition to the posting state. 10362306a36Sopenharmony_ci * 10462306a36Sopenharmony_ci * @SCI_RNC_RESUMING: transition state that will post an RNC resume to the 10562306a36Sopenharmony_ci * hardare. Once the event notification of resume complete is received the 10662306a36Sopenharmony_ci * remote node context will transition to the ready state. 10762306a36Sopenharmony_ci * 10862306a36Sopenharmony_ci * @SCI_RNC_READY: state that the remote node context must be in to accept io 10962306a36Sopenharmony_ci * request operations. 11062306a36Sopenharmony_ci * 11162306a36Sopenharmony_ci * @SCI_RNC_TX_SUSPENDED: state that the remote node context transitions to when 11262306a36Sopenharmony_ci * it gets a TX suspend notification from the hardware. 11362306a36Sopenharmony_ci * 11462306a36Sopenharmony_ci * @SCI_RNC_TX_RX_SUSPENDED: state that the remote node context transitions to 11562306a36Sopenharmony_ci * when it gets a TX RX suspend notification from the hardware. 11662306a36Sopenharmony_ci * 11762306a36Sopenharmony_ci * @SCI_RNC_AWAIT_SUSPENSION: wait state for the remote node context that waits 11862306a36Sopenharmony_ci * for a suspend notification from the hardware. This state is entered when 11962306a36Sopenharmony_ci * either there is a request to supend the remote node context or when there is 12062306a36Sopenharmony_ci * a TC completion where the remote node will be suspended by the hardware. 12162306a36Sopenharmony_ci */ 12262306a36Sopenharmony_ci#define RNC_STATES {\ 12362306a36Sopenharmony_ci C(RNC_INITIAL),\ 12462306a36Sopenharmony_ci C(RNC_POSTING),\ 12562306a36Sopenharmony_ci C(RNC_INVALIDATING),\ 12662306a36Sopenharmony_ci C(RNC_RESUMING),\ 12762306a36Sopenharmony_ci C(RNC_READY),\ 12862306a36Sopenharmony_ci C(RNC_TX_SUSPENDED),\ 12962306a36Sopenharmony_ci C(RNC_TX_RX_SUSPENDED),\ 13062306a36Sopenharmony_ci C(RNC_AWAIT_SUSPENSION),\ 13162306a36Sopenharmony_ci } 13262306a36Sopenharmony_ci#undef C 13362306a36Sopenharmony_ci#define C(a) SCI_##a 13462306a36Sopenharmony_cienum scis_sds_remote_node_context_states RNC_STATES; 13562306a36Sopenharmony_ci#undef C 13662306a36Sopenharmony_ciconst char *rnc_state_name(enum scis_sds_remote_node_context_states state); 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/** 13962306a36Sopenharmony_ci * 14062306a36Sopenharmony_ci * 14162306a36Sopenharmony_ci * This enumeration is used to define the end destination state for the remote 14262306a36Sopenharmony_ci * node context. 14362306a36Sopenharmony_ci */ 14462306a36Sopenharmony_cienum sci_remote_node_context_destination_state { 14562306a36Sopenharmony_ci RNC_DEST_UNSPECIFIED, 14662306a36Sopenharmony_ci RNC_DEST_READY, 14762306a36Sopenharmony_ci RNC_DEST_FINAL, 14862306a36Sopenharmony_ci RNC_DEST_SUSPENDED, /* Set when suspend during post/invalidate */ 14962306a36Sopenharmony_ci RNC_DEST_SUSPENDED_RESUME /* Set when a resume was done during posting 15062306a36Sopenharmony_ci * or invalidating and already suspending. 15162306a36Sopenharmony_ci */ 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci/** 15562306a36Sopenharmony_ci * struct sci_remote_node_context - This structure contains the data 15662306a36Sopenharmony_ci * associated with the remote node context object. The remote node context 15762306a36Sopenharmony_ci * (RNC) object models the the remote device information necessary to manage 15862306a36Sopenharmony_ci * the silicon RNC. 15962306a36Sopenharmony_ci */ 16062306a36Sopenharmony_cistruct sci_remote_node_context { 16162306a36Sopenharmony_ci /** 16262306a36Sopenharmony_ci * This field indicates the remote node index (RNI) associated with 16362306a36Sopenharmony_ci * this RNC. 16462306a36Sopenharmony_ci */ 16562306a36Sopenharmony_ci u16 remote_node_index; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci /** 16862306a36Sopenharmony_ci * This field is the recored suspension type of the remote node 16962306a36Sopenharmony_ci * context suspension. 17062306a36Sopenharmony_ci */ 17162306a36Sopenharmony_ci u32 suspend_type; 17262306a36Sopenharmony_ci enum sci_remote_node_suspension_reasons suspend_reason; 17362306a36Sopenharmony_ci u32 suspend_count; 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci /** 17662306a36Sopenharmony_ci * This field is true if the remote node context is resuming from its current 17762306a36Sopenharmony_ci * state. This can cause an automatic resume on receiving a suspension 17862306a36Sopenharmony_ci * notification. 17962306a36Sopenharmony_ci */ 18062306a36Sopenharmony_ci enum sci_remote_node_context_destination_state destination_state; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci /** 18362306a36Sopenharmony_ci * This field contains the callback function that the user requested to be 18462306a36Sopenharmony_ci * called when the requested state transition is complete. 18562306a36Sopenharmony_ci */ 18662306a36Sopenharmony_ci scics_sds_remote_node_context_callback user_callback; 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci /** 18962306a36Sopenharmony_ci * This field contains the parameter that is called when the user requested 19062306a36Sopenharmony_ci * state transition is completed. 19162306a36Sopenharmony_ci */ 19262306a36Sopenharmony_ci void *user_cookie; 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci /** 19562306a36Sopenharmony_ci * This field contains the data for the object's state machine. 19662306a36Sopenharmony_ci */ 19762306a36Sopenharmony_ci struct sci_base_state_machine sm; 19862306a36Sopenharmony_ci}; 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_civoid sci_remote_node_context_construct(struct sci_remote_node_context *rnc, 20162306a36Sopenharmony_ci u16 remote_node_index); 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_cibool sci_remote_node_context_is_ready( 20562306a36Sopenharmony_ci struct sci_remote_node_context *sci_rnc); 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_cibool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc); 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_cienum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc, 21062306a36Sopenharmony_ci u32 event_code); 21162306a36Sopenharmony_cienum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc, 21262306a36Sopenharmony_ci scics_sds_remote_node_context_callback callback, 21362306a36Sopenharmony_ci void *callback_parameter); 21462306a36Sopenharmony_cienum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc, 21562306a36Sopenharmony_ci enum sci_remote_node_suspension_reasons reason, 21662306a36Sopenharmony_ci u32 suspension_code); 21762306a36Sopenharmony_cienum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc, 21862306a36Sopenharmony_ci scics_sds_remote_node_context_callback cb_fn, 21962306a36Sopenharmony_ci void *cb_p); 22062306a36Sopenharmony_cienum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc, 22162306a36Sopenharmony_ci struct isci_request *ireq, 22262306a36Sopenharmony_ci scics_sds_remote_node_context_callback cb_fn, 22362306a36Sopenharmony_ci void *cb_p); 22462306a36Sopenharmony_cienum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc, 22562306a36Sopenharmony_ci struct isci_request *ireq); 22662306a36Sopenharmony_ciint sci_remote_node_context_is_safe_to_abort( 22762306a36Sopenharmony_ci struct sci_remote_node_context *sci_rnc); 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_cistatic inline bool sci_remote_node_context_is_being_destroyed( 23062306a36Sopenharmony_ci struct sci_remote_node_context *sci_rnc) 23162306a36Sopenharmony_ci{ 23262306a36Sopenharmony_ci return (sci_rnc->destination_state == RNC_DEST_FINAL) 23362306a36Sopenharmony_ci || ((sci_rnc->sm.current_state_id == SCI_RNC_INITIAL) 23462306a36Sopenharmony_ci && (sci_rnc->destination_state == RNC_DEST_UNSPECIFIED)); 23562306a36Sopenharmony_ci} 23662306a36Sopenharmony_ci#endif /* _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ */ 237