xref: /OK3568_Linux_fs/kernel/drivers/scsi/isci/unsolicited_frame_control.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_UNSOLICITED_FRAME_CONTROL_H_
57*4882a593Smuzhiyun #define _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #include "isci.h"
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun #define SCU_UNSOLICITED_FRAME_HEADER_DATA_DWORDS 15
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /**
64*4882a593Smuzhiyun  * struct scu_unsolicited_frame_header -
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * This structure delineates the format of an unsolicited frame header. The
67*4882a593Smuzhiyun  * first DWORD are UF attributes defined by the silicon architecture. The data
68*4882a593Smuzhiyun  * depicts actual header information received on the link.
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun struct scu_unsolicited_frame_header {
71*4882a593Smuzhiyun 	/**
72*4882a593Smuzhiyun 	 * This field indicates if there is an Initiator Index Table entry with
73*4882a593Smuzhiyun 	 * which this header is associated.
74*4882a593Smuzhiyun 	 */
75*4882a593Smuzhiyun 	u32 iit_exists:1;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	/**
78*4882a593Smuzhiyun 	 * This field simply indicates the protocol type (i.e. SSP, STP, SMP).
79*4882a593Smuzhiyun 	 */
80*4882a593Smuzhiyun 	u32 protocol_type:3;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	/**
83*4882a593Smuzhiyun 	 * This field indicates if the frame is an address frame (IAF or OAF)
84*4882a593Smuzhiyun 	 * or if it is a information unit frame.
85*4882a593Smuzhiyun 	 */
86*4882a593Smuzhiyun 	u32 is_address_frame:1;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	/**
89*4882a593Smuzhiyun 	 * This field simply indicates the connection rate at which the frame
90*4882a593Smuzhiyun 	 * was received.
91*4882a593Smuzhiyun 	 */
92*4882a593Smuzhiyun 	u32 connection_rate:4;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	u32 reserved:23;
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	/**
97*4882a593Smuzhiyun 	 * This field represents the actual header data received on the link.
98*4882a593Smuzhiyun 	 */
99*4882a593Smuzhiyun 	u32 data[SCU_UNSOLICITED_FRAME_HEADER_DATA_DWORDS];
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun };
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun  * enum unsolicited_frame_state -
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * This enumeration represents the current unsolicited frame state.  The
109*4882a593Smuzhiyun  * controller object can not updtate the hardware unsolicited frame put pointer
110*4882a593Smuzhiyun  * unless it has already processed the priror unsolicited frames.
111*4882a593Smuzhiyun  */
112*4882a593Smuzhiyun enum unsolicited_frame_state {
113*4882a593Smuzhiyun 	/**
114*4882a593Smuzhiyun 	 * This state is when the frame is empty and not in use.  It is
115*4882a593Smuzhiyun 	 * different from the released state in that the hardware could DMA
116*4882a593Smuzhiyun 	 * data to this frame buffer.
117*4882a593Smuzhiyun 	 */
118*4882a593Smuzhiyun 	UNSOLICITED_FRAME_EMPTY,
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	/**
121*4882a593Smuzhiyun 	 * This state is set when the frame buffer is in use by by some
122*4882a593Smuzhiyun 	 * object in the system.
123*4882a593Smuzhiyun 	 */
124*4882a593Smuzhiyun 	UNSOLICITED_FRAME_IN_USE,
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	/**
127*4882a593Smuzhiyun 	 * This state is set when the frame is returned to the free pool
128*4882a593Smuzhiyun 	 * but one or more frames prior to this one are still in use.
129*4882a593Smuzhiyun 	 * Once all of the frame before this one are freed it will go to
130*4882a593Smuzhiyun 	 * the empty state.
131*4882a593Smuzhiyun 	 */
132*4882a593Smuzhiyun 	UNSOLICITED_FRAME_RELEASED,
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 	UNSOLICITED_FRAME_MAX_STATES
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun /**
138*4882a593Smuzhiyun  * struct sci_unsolicited_frame -
139*4882a593Smuzhiyun  *
140*4882a593Smuzhiyun  * This is the unsolicited frame data structure it acts as the container for
141*4882a593Smuzhiyun  * the current frame state, frame header and frame buffer.
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun struct sci_unsolicited_frame {
144*4882a593Smuzhiyun 	/**
145*4882a593Smuzhiyun 	 * This field contains the current frame state
146*4882a593Smuzhiyun 	 */
147*4882a593Smuzhiyun 	enum unsolicited_frame_state state;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	/**
150*4882a593Smuzhiyun 	 * This field points to the frame header data.
151*4882a593Smuzhiyun 	 */
152*4882a593Smuzhiyun 	struct scu_unsolicited_frame_header *header;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	/**
155*4882a593Smuzhiyun 	 * This field points to the frame buffer data.
156*4882a593Smuzhiyun 	 */
157*4882a593Smuzhiyun 	void *buffer;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun };
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun /**
162*4882a593Smuzhiyun  * struct sci_uf_header_array -
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * This structure contains all of the unsolicited frame header information.
165*4882a593Smuzhiyun  */
166*4882a593Smuzhiyun struct sci_uf_header_array {
167*4882a593Smuzhiyun 	/**
168*4882a593Smuzhiyun 	 * This field is represents a virtual pointer to the start
169*4882a593Smuzhiyun 	 * address of the UF address table.  The table contains
170*4882a593Smuzhiyun 	 * 64-bit pointers as required by the hardware.
171*4882a593Smuzhiyun 	 */
172*4882a593Smuzhiyun 	struct scu_unsolicited_frame_header *array;
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	/**
175*4882a593Smuzhiyun 	 * This field specifies the physical address location for the UF
176*4882a593Smuzhiyun 	 * buffer array.
177*4882a593Smuzhiyun 	 */
178*4882a593Smuzhiyun 	dma_addr_t physical_address;
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun };
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun /**
183*4882a593Smuzhiyun  * struct sci_uf_buffer_array -
184*4882a593Smuzhiyun  *
185*4882a593Smuzhiyun  * This structure contains all of the unsolicited frame buffer (actual payload)
186*4882a593Smuzhiyun  * information.
187*4882a593Smuzhiyun  */
188*4882a593Smuzhiyun struct sci_uf_buffer_array {
189*4882a593Smuzhiyun 	/**
190*4882a593Smuzhiyun 	 * This field is the unsolicited frame data its used to manage
191*4882a593Smuzhiyun 	 * the data for the unsolicited frame requests.  It also represents
192*4882a593Smuzhiyun 	 * the virtual address location that corresponds to the
193*4882a593Smuzhiyun 	 * physical_address field.
194*4882a593Smuzhiyun 	 */
195*4882a593Smuzhiyun 	struct sci_unsolicited_frame array[SCU_MAX_UNSOLICITED_FRAMES];
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	/**
198*4882a593Smuzhiyun 	 * This field specifies the physical address location for the UF
199*4882a593Smuzhiyun 	 * buffer array.
200*4882a593Smuzhiyun 	 */
201*4882a593Smuzhiyun 	dma_addr_t physical_address;
202*4882a593Smuzhiyun };
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /**
205*4882a593Smuzhiyun  * struct sci_uf_address_table_array -
206*4882a593Smuzhiyun  *
207*4882a593Smuzhiyun  * This object maintains all of the unsolicited frame address table specific
208*4882a593Smuzhiyun  * data.  The address table is a collection of 64-bit pointers that point to
209*4882a593Smuzhiyun  * 1KB buffers into which the silicon will DMA unsolicited frames.
210*4882a593Smuzhiyun  */
211*4882a593Smuzhiyun struct sci_uf_address_table_array {
212*4882a593Smuzhiyun 	/**
213*4882a593Smuzhiyun 	 * This field represents a virtual pointer that refers to the
214*4882a593Smuzhiyun 	 * starting address of the UF address table.
215*4882a593Smuzhiyun 	 * 64-bit pointers are required by the hardware.
216*4882a593Smuzhiyun 	 */
217*4882a593Smuzhiyun 	u64 *array;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	/**
220*4882a593Smuzhiyun 	 * This field specifies the physical address location for the UF
221*4882a593Smuzhiyun 	 * address table.
222*4882a593Smuzhiyun 	 */
223*4882a593Smuzhiyun 	dma_addr_t physical_address;
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun };
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /**
228*4882a593Smuzhiyun  * struct sci_unsolicited_frame_control -
229*4882a593Smuzhiyun  *
230*4882a593Smuzhiyun  * This object contains all of the data necessary to handle unsolicited frames.
231*4882a593Smuzhiyun  */
232*4882a593Smuzhiyun struct sci_unsolicited_frame_control {
233*4882a593Smuzhiyun 	/**
234*4882a593Smuzhiyun 	 * This field is the software copy of the unsolicited frame queue
235*4882a593Smuzhiyun 	 * get pointer.  The controller object writes this value to the
236*4882a593Smuzhiyun 	 * hardware to let the hardware put more unsolicited frame entries.
237*4882a593Smuzhiyun 	 */
238*4882a593Smuzhiyun 	u32 get;
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	/**
241*4882a593Smuzhiyun 	 * This field contains all of the unsolicited frame header
242*4882a593Smuzhiyun 	 * specific fields.
243*4882a593Smuzhiyun 	 */
244*4882a593Smuzhiyun 	struct sci_uf_header_array headers;
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	/**
247*4882a593Smuzhiyun 	 * This field contains all of the unsolicited frame buffer
248*4882a593Smuzhiyun 	 * specific fields.
249*4882a593Smuzhiyun 	 */
250*4882a593Smuzhiyun 	struct sci_uf_buffer_array buffers;
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun 	/**
253*4882a593Smuzhiyun 	 * This field contains all of the unsolicited frame address table
254*4882a593Smuzhiyun 	 * specific fields.
255*4882a593Smuzhiyun 	 */
256*4882a593Smuzhiyun 	struct sci_uf_address_table_array address_table;
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun };
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun #define SCI_UFI_BUF_SIZE (SCU_MAX_UNSOLICITED_FRAMES * SCU_UNSOLICITED_FRAME_BUFFER_SIZE)
261*4882a593Smuzhiyun #define SCI_UFI_HDR_SIZE (SCU_MAX_UNSOLICITED_FRAMES * sizeof(struct scu_unsolicited_frame_header))
262*4882a593Smuzhiyun #define SCI_UFI_TOTAL_SIZE (SCI_UFI_BUF_SIZE + SCI_UFI_HDR_SIZE + SCU_MAX_UNSOLICITED_FRAMES * sizeof(u64))
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun struct isci_host;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun void sci_unsolicited_frame_control_construct(struct isci_host *ihost);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun enum sci_status sci_unsolicited_frame_control_get_header(
269*4882a593Smuzhiyun 	struct sci_unsolicited_frame_control *uf_control,
270*4882a593Smuzhiyun 	u32 frame_index,
271*4882a593Smuzhiyun 	void **frame_header);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun enum sci_status sci_unsolicited_frame_control_get_buffer(
274*4882a593Smuzhiyun 	struct sci_unsolicited_frame_control *uf_control,
275*4882a593Smuzhiyun 	u32 frame_index,
276*4882a593Smuzhiyun 	void **frame_buffer);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun bool sci_unsolicited_frame_control_release_frame(
279*4882a593Smuzhiyun 	struct sci_unsolicited_frame_control *uf_control,
280*4882a593Smuzhiyun 	u32 frame_index);
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun #endif /* _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_ */
283