1230557Sjimharris/*-
2230557Sjimharris * This file is provided under a dual BSD/GPLv2 license.  When using or
3230557Sjimharris * redistributing this file, you may do so under either license.
4230557Sjimharris *
5230557Sjimharris * GPL LICENSE SUMMARY
6230557Sjimharris *
7230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8230557Sjimharris *
9230557Sjimharris * This program is free software; you can redistribute it and/or modify
10230557Sjimharris * it under the terms of version 2 of the GNU General Public License as
11230557Sjimharris * published by the Free Software Foundation.
12230557Sjimharris *
13230557Sjimharris * This program is distributed in the hope that it will be useful, but
14230557Sjimharris * WITHOUT ANY WARRANTY; without even the implied warranty of
15230557Sjimharris * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16230557Sjimharris * General Public License for more details.
17230557Sjimharris *
18230557Sjimharris * You should have received a copy of the GNU General Public License
19230557Sjimharris * along with this program; if not, write to the Free Software
20230557Sjimharris * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21230557Sjimharris * The full GNU General Public License is included in this distribution
22230557Sjimharris * in the file called LICENSE.GPL.
23230557Sjimharris *
24230557Sjimharris * BSD LICENSE
25230557Sjimharris *
26230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27230557Sjimharris * All rights reserved.
28230557Sjimharris *
29230557Sjimharris * Redistribution and use in source and binary forms, with or without
30230557Sjimharris * modification, are permitted provided that the following conditions
31230557Sjimharris * are met:
32230557Sjimharris *
33230557Sjimharris *   * Redistributions of source code must retain the above copyright
34230557Sjimharris *     notice, this list of conditions and the following disclaimer.
35230557Sjimharris *   * Redistributions in binary form must reproduce the above copyright
36230557Sjimharris *     notice, this list of conditions and the following disclaimer in
37230557Sjimharris *     the documentation and/or other materials provided with the
38230557Sjimharris *     distribution.
39230557Sjimharris *
40230557Sjimharris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41230557Sjimharris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42230557Sjimharris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43230557Sjimharris * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44230557Sjimharris * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45230557Sjimharris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46230557Sjimharris * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47230557Sjimharris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48230557Sjimharris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49230557Sjimharris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50230557Sjimharris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51230557Sjimharris *
52230557Sjimharris * $FreeBSD$
53230557Sjimharris */
54230557Sjimharris/**
55230557Sjimharris * @file
56230557Sjimharris *
57230557Sjimharris * @brief This file contains all of the unsolicited frame related
58230557Sjimharris *        management for the address table, the headers, and actual
59230557Sjimharris *        payload buffers.
60230557Sjimharris */
61230557Sjimharris
62230557Sjimharris#ifndef _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
63230557Sjimharris#define _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
64230557Sjimharris
65230557Sjimharris#ifdef __cplusplus
66230557Sjimharrisextern "C" {
67230557Sjimharris#endif // __cplusplus
68230557Sjimharris
69230557Sjimharris#include <dev/isci/types.h>
70230557Sjimharris#include <dev/isci/scil/scu_unsolicited_frame.h>
71230557Sjimharris#include <dev/isci/scil/sci_memory_descriptor_list.h>
72230557Sjimharris#include <dev/isci/scil/scu_constants.h>
73230557Sjimharris#include <dev/isci/scil/sci_status.h>
74230557Sjimharris
75230557Sjimharris/**
76230557Sjimharris * @enum UNSOLICITED_FRAME_STATE
77230557Sjimharris *
78230557Sjimharris * This enumeration represents the current unsolicited frame state.  The
79230557Sjimharris * controller object can not updtate the hardware unsolicited frame put
80230557Sjimharris * pointer unless it has already processed the priror unsolicited frames.
81230557Sjimharris */
82230557Sjimharrisenum UNSOLICITED_FRAME_STATE
83230557Sjimharris{
84230557Sjimharris   /**
85230557Sjimharris    * This state is when the frame is empty and not in use.  It is
86230557Sjimharris    * different from the released state in that the hardware could DMA
87230557Sjimharris    * data to this frame buffer.
88230557Sjimharris    */
89230557Sjimharris   UNSOLICITED_FRAME_EMPTY,
90230557Sjimharris
91230557Sjimharris   /**
92230557Sjimharris    * This state is set when the frame buffer is in use by by some
93230557Sjimharris    * object in the system.
94230557Sjimharris    */
95230557Sjimharris   UNSOLICITED_FRAME_IN_USE,
96230557Sjimharris
97230557Sjimharris   /**
98230557Sjimharris    * This state is set when the frame is returned to the free pool
99230557Sjimharris    * but one or more frames prior to this one are still in use.
100230557Sjimharris    * Once all of the frame before this one are freed it will go to
101230557Sjimharris    * the empty state.
102230557Sjimharris    */
103230557Sjimharris   UNSOLICITED_FRAME_RELEASED,
104230557Sjimharris
105230557Sjimharris   UNSOLICITED_FRAME_MAX_STATES
106230557Sjimharris};
107230557Sjimharris
108230557Sjimharris/**
109230557Sjimharris * @struct SCIC_SDS_UNSOLICITED_FRAME
110230557Sjimharris *
111230557Sjimharris * This is the unsolicited frame data structure it acts as the container for
112230557Sjimharris * the current frame state, frame header and frame buffer.
113230557Sjimharris */
114230557Sjimharristypedef struct SCIC_SDS_UNSOLICITED_FRAME
115230557Sjimharris{
116230557Sjimharris   /**
117230557Sjimharris    * This field contains the current frame state
118230557Sjimharris    */
119230557Sjimharris   enum UNSOLICITED_FRAME_STATE state;
120230557Sjimharris
121230557Sjimharris   /**
122230557Sjimharris    * This field points to the frame header data.
123230557Sjimharris    */
124230557Sjimharris   SCU_UNSOLICITED_FRAME_HEADER_T *header;
125230557Sjimharris
126230557Sjimharris   /**
127230557Sjimharris    * This field points to the frame buffer data.
128230557Sjimharris    */
129230557Sjimharris   void *buffer;
130230557Sjimharris
131230557Sjimharris} SCIC_SDS_UNSOLICITED_FRAME_T;
132230557Sjimharris
133230557Sjimharris/**
134230557Sjimharris * @struct SCIC_SDS_UF_HEADER_ARRAY
135230557Sjimharris *
136230557Sjimharris * This structure contains all of the unsolicited frame header
137230557Sjimharris * information.
138230557Sjimharris */
139230557Sjimharristypedef struct SCIC_SDS_UF_HEADER_ARRAY
140230557Sjimharris{
141230557Sjimharris   /**
142230557Sjimharris    * This field is represents a virtual pointer to the start
143230557Sjimharris    * address of the UF address table.  The table contains
144230557Sjimharris    * 64-bit pointers as required by the hardware.
145230557Sjimharris    */
146230557Sjimharris   SCU_UNSOLICITED_FRAME_HEADER_T *array;
147230557Sjimharris
148230557Sjimharris   /**
149230557Sjimharris    * This field specifies the physical address location for the UF
150230557Sjimharris    * buffer array.
151230557Sjimharris    */
152230557Sjimharris   SCI_PHYSICAL_ADDRESS physical_address;
153230557Sjimharris
154230557Sjimharris} SCIC_SDS_UF_HEADER_ARRAY_T;
155230557Sjimharris
156230557Sjimharris// Determine the size of the unsolicited frame array including
157230557Sjimharris// unused buffers.
158230557Sjimharris#if SCU_UNSOLICITED_FRAME_COUNT <= SCU_MIN_UF_TABLE_ENTRIES
159230557Sjimharris#define SCU_UNSOLICITED_FRAME_CONTROL_ARRAY_SIZE SCU_MIN_UF_TABLE_ENTRIES
160230557Sjimharris#else
161230557Sjimharris#define SCU_UNSOLICITED_FRAME_CONTROL_ARRAY_SIZE SCU_MAX_UNSOLICITED_FRAMES
162230557Sjimharris#endif // SCU_UNSOLICITED_FRAME_COUNT <= SCU_MIN_UF_TABLE_ENTRIES
163230557Sjimharris
164230557Sjimharris/**
165230557Sjimharris * @struct SCIC_SDS_UF_BUFFER_ARRAY
166230557Sjimharris *
167230557Sjimharris * This structure contains all of the unsolicited frame buffer (actual
168230557Sjimharris * payload) information.
169230557Sjimharris */
170230557Sjimharristypedef struct SCIC_SDS_UF_BUFFER_ARRAY
171230557Sjimharris{
172230557Sjimharris   /**
173230557Sjimharris    * This field is the minimum number of unsolicited frames supported by the
174230557Sjimharris    * hardware and the number of unsolicited frames requested by the software.
175230557Sjimharris    */
176230557Sjimharris   U32 count;
177230557Sjimharris
178230557Sjimharris   /**
179230557Sjimharris    * This field is the SCIC_UNSOLICITED_FRAME data its used to manage
180230557Sjimharris    * the data for the unsolicited frame requests.  It also represents
181230557Sjimharris    * the virtual address location that corresponds to the
182230557Sjimharris    * physical_address field.
183230557Sjimharris    */
184230557Sjimharris   SCIC_SDS_UNSOLICITED_FRAME_T array[SCU_UNSOLICITED_FRAME_CONTROL_ARRAY_SIZE];
185230557Sjimharris
186230557Sjimharris   /**
187230557Sjimharris    * This field specifies the physical address location for the UF
188230557Sjimharris    * buffer array.
189230557Sjimharris    */
190230557Sjimharris   SCI_PHYSICAL_ADDRESS physical_address;
191230557Sjimharris
192230557Sjimharris} SCIC_SDS_UF_BUFFER_ARRAY_T;
193230557Sjimharris
194230557Sjimharris/**
195230557Sjimharris * @struct SCIC_SDS_UF_ADDRESS_TABLE_ARRAY
196230557Sjimharris *
197230557Sjimharris * This object maintains all of the unsolicited frame address
198230557Sjimharris * table specific data.  The address table is a collection of
199230557Sjimharris * 64-bit pointers that point to 1KB buffers into which
200230557Sjimharris * the silicon will DMA unsolicited frames.
201230557Sjimharris */
202230557Sjimharristypedef struct SCIC_SDS_UF_ADDRESS_TABLE_ARRAY
203230557Sjimharris{
204230557Sjimharris   /**
205230557Sjimharris    * This field specifies the actual programmed size of the
206230557Sjimharris    * unsolicited frame buffer address table.  The size of the table
207230557Sjimharris    * can be larger than the actual number of UF buffers, but it must
208230557Sjimharris    * be a power of 2 and the last entry in the table is not allowed
209230557Sjimharris    * to be NULL.
210230557Sjimharris    */
211230557Sjimharris   U32 count;
212230557Sjimharris
213230557Sjimharris   /**
214230557Sjimharris    * This field represents a virtual pointer that refers to the
215230557Sjimharris    * starting address of the UF address table.
216230557Sjimharris    * 64-bit pointers are required by the hardware.
217230557Sjimharris    */
218230557Sjimharris   SCI_PHYSICAL_ADDRESS * array;
219230557Sjimharris
220230557Sjimharris   /**
221230557Sjimharris    * This field specifies the physical address location for the UF
222230557Sjimharris    * address table.
223230557Sjimharris    */
224230557Sjimharris   SCI_PHYSICAL_ADDRESS physical_address;
225230557Sjimharris
226230557Sjimharris} SCIC_SDS_UF_ADDRESS_TABLE_ARRAY_T;
227230557Sjimharris
228230557Sjimharris/**
229230557Sjimharris * @struct SCIC_SDS_UNSOLICITED_FRAME_CONTROL
230230557Sjimharris *
231230557Sjimharris * This object contains all of the data necessary to handle
232230557Sjimharris * unsolicited frames.
233230557Sjimharris */
234230557Sjimharristypedef struct SCIC_SDS_UNSOLICITED_FRAME_CONTROL
235230557Sjimharris{
236230557Sjimharris   /**
237230557Sjimharris    * This field is the software copy of the unsolicited frame queue
238230557Sjimharris    * get pointer.  The controller object writes this value to the
239230557Sjimharris    * hardware to let the hardware put more unsolicited frame entries.
240230557Sjimharris    */
241230557Sjimharris   U32 get;
242230557Sjimharris
243230557Sjimharris   /**
244230557Sjimharris    * This field contains all of the unsolicited frame header
245230557Sjimharris    * specific fields.
246230557Sjimharris    */
247230557Sjimharris   SCIC_SDS_UF_HEADER_ARRAY_T headers;
248230557Sjimharris
249230557Sjimharris   /**
250230557Sjimharris    * This field contains all of the unsolicited frame buffer
251230557Sjimharris    * specific fields.
252230557Sjimharris    */
253230557Sjimharris   SCIC_SDS_UF_BUFFER_ARRAY_T buffers;
254230557Sjimharris
255230557Sjimharris   /**
256230557Sjimharris    * This field contains all of the unsolicited frame address table
257230557Sjimharris    * specific fields.
258230557Sjimharris    */
259230557Sjimharris   SCIC_SDS_UF_ADDRESS_TABLE_ARRAY_T address_table;
260230557Sjimharris
261230557Sjimharris} SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T;
262230557Sjimharris
263230557Sjimharrisvoid scic_sds_unsolicited_frame_control_set_address_table_count(
264230557Sjimharris   SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control
265230557Sjimharris);
266230557Sjimharris
267230557Sjimharrisstruct SCIC_SDS_CONTROLLER;
268230557Sjimharrisvoid scic_sds_unsolicited_frame_control_construct(
269230557Sjimharris   SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
270230557Sjimharris   SCI_PHYSICAL_MEMORY_DESCRIPTOR_T     *mde,
271230557Sjimharris   struct SCIC_SDS_CONTROLLER           *this_controller
272230557Sjimharris);
273230557Sjimharris
274230557SjimharrisSCI_STATUS scic_sds_unsolicited_frame_control_get_header(
275230557Sjimharris   SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
276230557Sjimharris   U32                                   frame_index,
277230557Sjimharris   void                                **frame_header
278230557Sjimharris);
279230557Sjimharris
280230557SjimharrisSCI_STATUS scic_sds_unsolicited_frame_control_get_buffer(
281230557Sjimharris   SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
282230557Sjimharris   U32                                   frame_index,
283230557Sjimharris   void                                **frame_buffer
284230557Sjimharris);
285230557Sjimharris
286230557SjimharrisBOOL scic_sds_unsolicited_frame_control_release_frame(
287230557Sjimharris   SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
288230557Sjimharris   U32                                   frame_index
289230557Sjimharris);
290230557Sjimharris
291230557Sjimharris/**
292230557Sjimharris * This macro simply calculates the size of the memory descriptor
293230557Sjimharris * entry that relates to unsolicited frames and the surrounding
294230557Sjimharris * silicon memory required to utilize it.
295230557Sjimharris */
296230557Sjimharris#define scic_sds_unsolicited_frame_control_get_mde_size(uf_control) \
297230557Sjimharris   ( ((uf_control).buffers.count * SCU_UNSOLICITED_FRAME_BUFFER_SIZE) \
298230557Sjimharris   + ((uf_control).address_table.count * sizeof(SCI_PHYSICAL_ADDRESS)) \
299230557Sjimharris   + ((uf_control).buffers.count * sizeof(SCU_UNSOLICITED_FRAME_HEADER_T)) )
300230557Sjimharris
301230557Sjimharris#ifdef __cplusplus
302230557Sjimharris}
303230557Sjimharris#endif // __cplusplus
304230557Sjimharris
305230557Sjimharris#endif // _SCIC_SDS_UNSOLICITED_FRAME_CONTROL_H_
306