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