xref: /freebsd/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.h (revision b1f9167f94059fd55c630891d359bcff987bd7eb)
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  *
40  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51  *
52  * $FreeBSD$
53  */
54 /**
55  * @file
56  *
57  * @brief This file contains all of the unsolicited frame related
58  *        management for the address table, the headers, and actual
59  *        payload buffers.
60  */
61 
62 #ifndef _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
63 #define _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif // __cplusplus
68 
69 #include <dev/isci/types.h>
70 #include <dev/isci/scil/scu_unsolicited_frame.h>
71 #include <dev/isci/scil/sci_memory_descriptor_list.h>
72 #include <dev/isci/scil/scu_constants.h>
73 #include <dev/isci/scil/sci_status.h>
74 
75 /**
76  * @enum UNSOLICITED_FRAME_STATE
77  *
78  * This enumeration represents the current unsolicited frame state.  The
79  * controller object can not updtate the hardware unsolicited frame put
80  * pointer unless it has already processed the priror unsolicited frames.
81  */
82 enum UNSOLICITED_FRAME_STATE
83 {
84    /**
85     * This state is when the frame is empty and not in use.  It is
86     * different from the released state in that the hardware could DMA
87     * data to this frame buffer.
88     */
89    UNSOLICITED_FRAME_EMPTY,
90 
91    /**
92     * This state is set when the frame buffer is in use by by some
93     * object in the system.
94     */
95    UNSOLICITED_FRAME_IN_USE,
96 
97    /**
98     * This state is set when the frame is returned to the free pool
99     * but one or more frames prior to this one are still in use.
100     * Once all of the frame before this one are freed it will go to
101     * the empty state.
102     */
103    UNSOLICITED_FRAME_RELEASED,
104 
105    UNSOLICITED_FRAME_MAX_STATES
106 };
107 
108 /**
109  * @struct SCIC_SDS_UNSOLICITED_FRAME
110  *
111  * This is the unsolicited frame data structure it acts as the container for
112  * the current frame state, frame header and frame buffer.
113  */
114 typedef struct SCIC_SDS_UNSOLICITED_FRAME
115 {
116    /**
117     * This field contains the current frame state
118     */
119    enum UNSOLICITED_FRAME_STATE state;
120 
121    /**
122     * This field points to the frame header data.
123     */
124    SCU_UNSOLICITED_FRAME_HEADER_T *header;
125 
126    /**
127     * This field points to the frame buffer data.
128     */
129    void *buffer;
130 
131 } SCIC_SDS_UNSOLICITED_FRAME_T;
132 
133 /**
134  * @struct SCIC_SDS_UF_HEADER_ARRAY
135  *
136  * This structure contains all of the unsolicited frame header
137  * information.
138  */
139 typedef struct SCIC_SDS_UF_HEADER_ARRAY
140 {
141    /**
142     * This field is represents a virtual pointer to the start
143     * address of the UF address table.  The table contains
144     * 64-bit pointers as required by the hardware.
145     */
146    SCU_UNSOLICITED_FRAME_HEADER_T *array;
147 
148    /**
149     * This field specifies the physical address location for the UF
150     * buffer array.
151     */
152    SCI_PHYSICAL_ADDRESS physical_address;
153 
154 } SCIC_SDS_UF_HEADER_ARRAY_T;
155 
156 // Determine the size of the unsolicited frame array including
157 // unused buffers.
158 #if SCU_UNSOLICITED_FRAME_COUNT <= SCU_MIN_UF_TABLE_ENTRIES
159 #define SCU_UNSOLICITED_FRAME_CONTROL_ARRAY_SIZE SCU_MIN_UF_TABLE_ENTRIES
160 #else
161 #define SCU_UNSOLICITED_FRAME_CONTROL_ARRAY_SIZE SCU_MAX_UNSOLICITED_FRAMES
162 #endif // SCU_UNSOLICITED_FRAME_COUNT <= SCU_MIN_UF_TABLE_ENTRIES
163 
164 /**
165  * @struct SCIC_SDS_UF_BUFFER_ARRAY
166  *
167  * This structure contains all of the unsolicited frame buffer (actual
168  * payload) information.
169  */
170 typedef struct SCIC_SDS_UF_BUFFER_ARRAY
171 {
172    /**
173     * This field is the minimum number of unsolicited frames supported by the
174     * hardware and the number of unsolicited frames requested by the software.
175     */
176    U32 count;
177 
178    /**
179     * This field is the SCIC_UNSOLICITED_FRAME data its used to manage
180     * the data for the unsolicited frame requests.  It also represents
181     * the virtual address location that corresponds to the
182     * physical_address field.
183     */
184    SCIC_SDS_UNSOLICITED_FRAME_T array[SCU_UNSOLICITED_FRAME_CONTROL_ARRAY_SIZE];
185 
186    /**
187     * This field specifies the physical address location for the UF
188     * buffer array.
189     */
190    SCI_PHYSICAL_ADDRESS physical_address;
191 
192 } SCIC_SDS_UF_BUFFER_ARRAY_T;
193 
194 /**
195  * @struct SCIC_SDS_UF_ADDRESS_TABLE_ARRAY
196  *
197  * This object maintains all of the unsolicited frame address
198  * table specific data.  The address table is a collection of
199  * 64-bit pointers that point to 1KB buffers into which
200  * the silicon will DMA unsolicited frames.
201  */
202 typedef struct SCIC_SDS_UF_ADDRESS_TABLE_ARRAY
203 {
204    /**
205     * This field specifies the actual programmed size of the
206     * unsolicited frame buffer address table.  The size of the table
207     * can be larger than the actual number of UF buffers, but it must
208     * be a power of 2 and the last entry in the table is not allowed
209     * to be NULL.
210     */
211    U32 count;
212 
213    /**
214     * This field represents a virtual pointer that refers to the
215     * starting address of the UF address table.
216     * 64-bit pointers are required by the hardware.
217     */
218    SCI_PHYSICAL_ADDRESS * array;
219 
220    /**
221     * This field specifies the physical address location for the UF
222     * address table.
223     */
224    SCI_PHYSICAL_ADDRESS physical_address;
225 
226 } SCIC_SDS_UF_ADDRESS_TABLE_ARRAY_T;
227 
228 /**
229  * @struct SCIC_SDS_UNSOLICITED_FRAME_CONTROL
230  *
231  * This object contains all of the data necessary to handle
232  * unsolicited frames.
233  */
234 typedef struct SCIC_SDS_UNSOLICITED_FRAME_CONTROL
235 {
236    /**
237     * This field is the software copy of the unsolicited frame queue
238     * get pointer.  The controller object writes this value to the
239     * hardware to let the hardware put more unsolicited frame entries.
240     */
241    U32 get;
242 
243    /**
244     * This field contains all of the unsolicited frame header
245     * specific fields.
246     */
247    SCIC_SDS_UF_HEADER_ARRAY_T headers;
248 
249    /**
250     * This field contains all of the unsolicited frame buffer
251     * specific fields.
252     */
253    SCIC_SDS_UF_BUFFER_ARRAY_T buffers;
254 
255    /**
256     * This field contains all of the unsolicited frame address table
257     * specific fields.
258     */
259    SCIC_SDS_UF_ADDRESS_TABLE_ARRAY_T address_table;
260 
261 } SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T;
262 
263 void scic_sds_unsolicited_frame_control_set_address_table_count(
264    SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control
265 );
266 
267 struct SCIC_SDS_CONTROLLER;
268 void scic_sds_unsolicited_frame_control_construct(
269    SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
270    SCI_PHYSICAL_MEMORY_DESCRIPTOR_T     *mde,
271    struct SCIC_SDS_CONTROLLER           *this_controller
272 );
273 
274 SCI_STATUS scic_sds_unsolicited_frame_control_get_header(
275    SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
276    U32                                   frame_index,
277    void                                **frame_header
278 );
279 
280 SCI_STATUS scic_sds_unsolicited_frame_control_get_buffer(
281    SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
282    U32                                   frame_index,
283    void                                **frame_buffer
284 );
285 
286 BOOL scic_sds_unsolicited_frame_control_release_frame(
287    SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
288    U32                                   frame_index
289 );
290 
291 /**
292  * This macro simply calculates the size of the memory descriptor
293  * entry that relates to unsolicited frames and the surrounding
294  * silicon memory required to utilize it.
295  */
296 #define scic_sds_unsolicited_frame_control_get_mde_size(uf_control) \
297    ( ((uf_control).buffers.count * SCU_UNSOLICITED_FRAME_BUFFER_SIZE) \
298    + ((uf_control).address_table.count * sizeof(SCI_PHYSICAL_ADDRESS)) \
299    + ((uf_control).buffers.count * sizeof(SCU_UNSOLICITED_FRAME_HEADER_T)) )
300 
301 #ifdef __cplusplus
302 }
303 #endif // __cplusplus
304 
305 #endif // _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
306