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