xref: /OK3568_Linux_fs/kernel/drivers/scsi/isci/remote_node_context.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
3*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*4882a593Smuzhiyun  * General Public License for more details.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
19*4882a593Smuzhiyun  * along with this program; if not, write to the Free Software
20*4882a593Smuzhiyun  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution
22*4882a593Smuzhiyun  * in the file called LICENSE.GPL.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * BSD LICENSE
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27*4882a593Smuzhiyun  * All rights reserved.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
30*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
31*4882a593Smuzhiyun  * are met:
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  *   * Redistributions of source code must retain the above copyright
34*4882a593Smuzhiyun  *     notice, this list of conditions and the following disclaimer.
35*4882a593Smuzhiyun  *   * Redistributions in binary form must reproduce the above copyright
36*4882a593Smuzhiyun  *     notice, this list of conditions and the following disclaimer in
37*4882a593Smuzhiyun  *     the documentation and/or other materials provided with the
38*4882a593Smuzhiyun  *     distribution.
39*4882a593Smuzhiyun  *   * Neither the name of Intel Corporation nor the names of its
40*4882a593Smuzhiyun  *     contributors may be used to endorse or promote products derived
41*4882a593Smuzhiyun  *     from this software without specific prior written permission.
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #ifndef _SCIC_SDS_REMOTE_NODE_CONTEXT_H_
57*4882a593Smuzhiyun #define _SCIC_SDS_REMOTE_NODE_CONTEXT_H_
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /**
60*4882a593Smuzhiyun  * This file contains the structures, constants, and prototypes associated with
61*4882a593Smuzhiyun  *    the remote node context in the silicon.  It exists to model and manage
62*4882a593Smuzhiyun  *    the remote node context in the silicon.
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #include "isci.h"
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /**
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  *
72*4882a593Smuzhiyun  * This constant represents an invalid remote device id, it is used to program
73*4882a593Smuzhiyun  * the STPDARNI register so the driver knows when it has received a SIGNATURE
74*4882a593Smuzhiyun  * FIS from the SCU.
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX    0x0FFF
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun enum sci_remote_node_suspension_reasons {
79*4882a593Smuzhiyun 	SCI_HW_SUSPEND,
80*4882a593Smuzhiyun 	SCI_SW_SUSPEND_NORMAL,
81*4882a593Smuzhiyun 	SCI_SW_SUSPEND_LINKHANG_DETECT
82*4882a593Smuzhiyun };
83*4882a593Smuzhiyun #define SCI_SOFTWARE_SUSPEND_CMD SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
84*4882a593Smuzhiyun #define SCI_SOFTWARE_SUSPEND_EXPECTED_EVENT SCU_EVENT_TL_RNC_SUSPEND_TX_RX
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun struct isci_request;
87*4882a593Smuzhiyun struct isci_remote_device;
88*4882a593Smuzhiyun struct sci_remote_node_context;
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun typedef void (*scics_sds_remote_node_context_callback)(void *);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /**
93*4882a593Smuzhiyun  * enum sci_remote_node_context_states
94*4882a593Smuzhiyun  * @SCI_RNC_INITIAL initial state for a remote node context.  On a resume
95*4882a593Smuzhiyun  * request the remote node context will transition to the posting state.
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  * @SCI_RNC_POSTING: transition state that posts the RNi to the hardware. Once
98*4882a593Smuzhiyun  * the RNC is posted the remote node context will be made ready.
99*4882a593Smuzhiyun  *
100*4882a593Smuzhiyun  * @SCI_RNC_INVALIDATING: transition state that will post an RNC invalidate to
101*4882a593Smuzhiyun  * the hardware.  Once the invalidate is complete the remote node context will
102*4882a593Smuzhiyun  * transition to the posting state.
103*4882a593Smuzhiyun  *
104*4882a593Smuzhiyun  * @SCI_RNC_RESUMING: transition state that will post an RNC resume to the
105*4882a593Smuzhiyun  * hardare.  Once the event notification of resume complete is received the
106*4882a593Smuzhiyun  * remote node context will transition to the ready state.
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @SCI_RNC_READY: state that the remote node context must be in to accept io
109*4882a593Smuzhiyun  * request operations.
110*4882a593Smuzhiyun  *
111*4882a593Smuzhiyun  * @SCI_RNC_TX_SUSPENDED: state that the remote node context transitions to when
112*4882a593Smuzhiyun  * it gets a TX suspend notification from the hardware.
113*4882a593Smuzhiyun  *
114*4882a593Smuzhiyun  * @SCI_RNC_TX_RX_SUSPENDED: state that the remote node context transitions to
115*4882a593Smuzhiyun  * when it gets a TX RX suspend notification from the hardware.
116*4882a593Smuzhiyun  *
117*4882a593Smuzhiyun  * @SCI_RNC_AWAIT_SUSPENSION: wait state for the remote node context that waits
118*4882a593Smuzhiyun  * for a suspend notification from the hardware.  This state is entered when
119*4882a593Smuzhiyun  * either there is a request to supend the remote node context or when there is
120*4882a593Smuzhiyun  * a TC completion where the remote node will be suspended by the hardware.
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun #define RNC_STATES {\
123*4882a593Smuzhiyun 	C(RNC_INITIAL),\
124*4882a593Smuzhiyun 	C(RNC_POSTING),\
125*4882a593Smuzhiyun 	C(RNC_INVALIDATING),\
126*4882a593Smuzhiyun 	C(RNC_RESUMING),\
127*4882a593Smuzhiyun 	C(RNC_READY),\
128*4882a593Smuzhiyun 	C(RNC_TX_SUSPENDED),\
129*4882a593Smuzhiyun 	C(RNC_TX_RX_SUSPENDED),\
130*4882a593Smuzhiyun 	C(RNC_AWAIT_SUSPENSION),\
131*4882a593Smuzhiyun 	}
132*4882a593Smuzhiyun #undef C
133*4882a593Smuzhiyun #define C(a) SCI_##a
134*4882a593Smuzhiyun enum scis_sds_remote_node_context_states RNC_STATES;
135*4882a593Smuzhiyun #undef C
136*4882a593Smuzhiyun const char *rnc_state_name(enum scis_sds_remote_node_context_states state);
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun  *
140*4882a593Smuzhiyun  *
141*4882a593Smuzhiyun  * This enumeration is used to define the end destination state for the remote
142*4882a593Smuzhiyun  * node context.
143*4882a593Smuzhiyun  */
144*4882a593Smuzhiyun enum sci_remote_node_context_destination_state {
145*4882a593Smuzhiyun 	RNC_DEST_UNSPECIFIED,
146*4882a593Smuzhiyun 	RNC_DEST_READY,
147*4882a593Smuzhiyun 	RNC_DEST_FINAL,
148*4882a593Smuzhiyun 	RNC_DEST_SUSPENDED,       /* Set when suspend during post/invalidate */
149*4882a593Smuzhiyun 	RNC_DEST_SUSPENDED_RESUME /* Set when a resume was done during posting
150*4882a593Smuzhiyun 				   * or invalidating and already suspending.
151*4882a593Smuzhiyun 				   */
152*4882a593Smuzhiyun };
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /**
155*4882a593Smuzhiyun  * struct sci_remote_node_context - This structure contains the data
156*4882a593Smuzhiyun  *    associated with the remote node context object.  The remote node context
157*4882a593Smuzhiyun  *    (RNC) object models the the remote device information necessary to manage
158*4882a593Smuzhiyun  *    the silicon RNC.
159*4882a593Smuzhiyun  */
160*4882a593Smuzhiyun struct sci_remote_node_context {
161*4882a593Smuzhiyun 	/**
162*4882a593Smuzhiyun 	 * This field indicates the remote node index (RNI) associated with
163*4882a593Smuzhiyun 	 * this RNC.
164*4882a593Smuzhiyun 	 */
165*4882a593Smuzhiyun 	u16 remote_node_index;
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	/**
168*4882a593Smuzhiyun 	 * This field is the recored suspension type of the remote node
169*4882a593Smuzhiyun 	 * context suspension.
170*4882a593Smuzhiyun 	 */
171*4882a593Smuzhiyun 	u32 suspend_type;
172*4882a593Smuzhiyun 	enum sci_remote_node_suspension_reasons suspend_reason;
173*4882a593Smuzhiyun 	u32 suspend_count;
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	/**
176*4882a593Smuzhiyun 	 * This field is true if the remote node context is resuming from its current
177*4882a593Smuzhiyun 	 * state.  This can cause an automatic resume on receiving a suspension
178*4882a593Smuzhiyun 	 * notification.
179*4882a593Smuzhiyun 	 */
180*4882a593Smuzhiyun 	enum sci_remote_node_context_destination_state destination_state;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	/**
183*4882a593Smuzhiyun 	 * This field contains the callback function that the user requested to be
184*4882a593Smuzhiyun 	 * called when the requested state transition is complete.
185*4882a593Smuzhiyun 	 */
186*4882a593Smuzhiyun 	scics_sds_remote_node_context_callback user_callback;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	/**
189*4882a593Smuzhiyun 	 * This field contains the parameter that is called when the user requested
190*4882a593Smuzhiyun 	 * state transition is completed.
191*4882a593Smuzhiyun 	 */
192*4882a593Smuzhiyun 	void *user_cookie;
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	/**
195*4882a593Smuzhiyun 	 * This field contains the data for the object's state machine.
196*4882a593Smuzhiyun 	 */
197*4882a593Smuzhiyun 	struct sci_base_state_machine sm;
198*4882a593Smuzhiyun };
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun void sci_remote_node_context_construct(struct sci_remote_node_context *rnc,
201*4882a593Smuzhiyun 					    u16 remote_node_index);
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun bool sci_remote_node_context_is_ready(
205*4882a593Smuzhiyun 	struct sci_remote_node_context *sci_rnc);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun bool sci_remote_node_context_is_suspended(struct sci_remote_node_context *sci_rnc);
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun enum sci_status sci_remote_node_context_event_handler(struct sci_remote_node_context *sci_rnc,
210*4882a593Smuzhiyun 							   u32 event_code);
211*4882a593Smuzhiyun enum sci_status sci_remote_node_context_destruct(struct sci_remote_node_context *sci_rnc,
212*4882a593Smuzhiyun 						      scics_sds_remote_node_context_callback callback,
213*4882a593Smuzhiyun 						      void *callback_parameter);
214*4882a593Smuzhiyun enum sci_status sci_remote_node_context_suspend(struct sci_remote_node_context *sci_rnc,
215*4882a593Smuzhiyun 						     enum sci_remote_node_suspension_reasons reason,
216*4882a593Smuzhiyun 						     u32 suspension_code);
217*4882a593Smuzhiyun enum sci_status sci_remote_node_context_resume(struct sci_remote_node_context *sci_rnc,
218*4882a593Smuzhiyun 						    scics_sds_remote_node_context_callback cb_fn,
219*4882a593Smuzhiyun 						    void *cb_p);
220*4882a593Smuzhiyun enum sci_status sci_remote_node_context_start_task(struct sci_remote_node_context *sci_rnc,
221*4882a593Smuzhiyun 						   struct isci_request *ireq,
222*4882a593Smuzhiyun 						   scics_sds_remote_node_context_callback cb_fn,
223*4882a593Smuzhiyun 						   void *cb_p);
224*4882a593Smuzhiyun enum sci_status sci_remote_node_context_start_io(struct sci_remote_node_context *sci_rnc,
225*4882a593Smuzhiyun 						      struct isci_request *ireq);
226*4882a593Smuzhiyun int sci_remote_node_context_is_safe_to_abort(
227*4882a593Smuzhiyun 	struct sci_remote_node_context *sci_rnc);
228*4882a593Smuzhiyun 
sci_remote_node_context_is_being_destroyed(struct sci_remote_node_context * sci_rnc)229*4882a593Smuzhiyun static inline bool sci_remote_node_context_is_being_destroyed(
230*4882a593Smuzhiyun 	struct sci_remote_node_context *sci_rnc)
231*4882a593Smuzhiyun {
232*4882a593Smuzhiyun 	return (sci_rnc->destination_state == RNC_DEST_FINAL)
233*4882a593Smuzhiyun 		|| ((sci_rnc->sm.current_state_id == SCI_RNC_INITIAL)
234*4882a593Smuzhiyun 		    && (sci_rnc->destination_state == RNC_DEST_UNSPECIFIED));
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun #endif  /* _SCIC_SDS_REMOTE_NODE_CONTEXT_H_ */
237