xref: /freebsd/sys/dev/isci/scil/scic_library.h (revision f11c7f63056671247335df83a3fe80b94c6616ac)
1*f11c7f63SJim Harris /*-
2*f11c7f63SJim Harris  * This file is provided under a dual BSD/GPLv2 license.  When using or
3*f11c7f63SJim Harris  * redistributing this file, you may do so under either license.
4*f11c7f63SJim Harris  *
5*f11c7f63SJim Harris  * GPL LICENSE SUMMARY
6*f11c7f63SJim Harris  *
7*f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8*f11c7f63SJim Harris  *
9*f11c7f63SJim Harris  * This program is free software; you can redistribute it and/or modify
10*f11c7f63SJim Harris  * it under the terms of version 2 of the GNU General Public License as
11*f11c7f63SJim Harris  * published by the Free Software Foundation.
12*f11c7f63SJim Harris  *
13*f11c7f63SJim Harris  * This program is distributed in the hope that it will be useful, but
14*f11c7f63SJim Harris  * WITHOUT ANY WARRANTY; without even the implied warranty of
15*f11c7f63SJim Harris  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*f11c7f63SJim Harris  * General Public License for more details.
17*f11c7f63SJim Harris  *
18*f11c7f63SJim Harris  * You should have received a copy of the GNU General Public License
19*f11c7f63SJim Harris  * along with this program; if not, write to the Free Software
20*f11c7f63SJim Harris  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21*f11c7f63SJim Harris  * The full GNU General Public License is included in this distribution
22*f11c7f63SJim Harris  * in the file called LICENSE.GPL.
23*f11c7f63SJim Harris  *
24*f11c7f63SJim Harris  * BSD LICENSE
25*f11c7f63SJim Harris  *
26*f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27*f11c7f63SJim Harris  * All rights reserved.
28*f11c7f63SJim Harris  *
29*f11c7f63SJim Harris  * Redistribution and use in source and binary forms, with or without
30*f11c7f63SJim Harris  * modification, are permitted provided that the following conditions
31*f11c7f63SJim Harris  * are met:
32*f11c7f63SJim Harris  *
33*f11c7f63SJim Harris  *   * Redistributions of source code must retain the above copyright
34*f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer.
35*f11c7f63SJim Harris  *   * Redistributions in binary form must reproduce the above copyright
36*f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer in
37*f11c7f63SJim Harris  *     the documentation and/or other materials provided with the
38*f11c7f63SJim Harris  *     distribution.
39*f11c7f63SJim Harris  *
40*f11c7f63SJim Harris  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41*f11c7f63SJim Harris  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42*f11c7f63SJim Harris  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43*f11c7f63SJim Harris  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44*f11c7f63SJim Harris  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45*f11c7f63SJim Harris  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46*f11c7f63SJim Harris  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47*f11c7f63SJim Harris  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48*f11c7f63SJim Harris  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49*f11c7f63SJim Harris  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50*f11c7f63SJim Harris  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51*f11c7f63SJim Harris  *
52*f11c7f63SJim Harris  * $FreeBSD$
53*f11c7f63SJim Harris  */
54*f11c7f63SJim Harris #ifndef _SCIC_LIBRARY_H_
55*f11c7f63SJim Harris #define _SCIC_LIBRARY_H_
56*f11c7f63SJim Harris 
57*f11c7f63SJim Harris /**
58*f11c7f63SJim Harris  * @file
59*f11c7f63SJim Harris  *
60*f11c7f63SJim Harris  * @brief This file contains all of the interface methods that can be called
61*f11c7f63SJim Harris  *        by an SCI Core user on the library object.  The library is the
62*f11c7f63SJim Harris  *        container of all other objects being managed (i.e. controllers,
63*f11c7f63SJim Harris  *        target devices, sas ports, etc.).
64*f11c7f63SJim Harris  */
65*f11c7f63SJim Harris 
66*f11c7f63SJim Harris #ifdef __cplusplus
67*f11c7f63SJim Harris extern "C" {
68*f11c7f63SJim Harris #endif // __cplusplus
69*f11c7f63SJim Harris 
70*f11c7f63SJim Harris #include <dev/isci/scil/sci_types.h>
71*f11c7f63SJim Harris #include <dev/isci/scil/sci_status.h>
72*f11c7f63SJim Harris 
73*f11c7f63SJim Harris 
74*f11c7f63SJim Harris /**
75*f11c7f63SJim Harris  * @enum  _SCIC_LIBRARY_IO_MODE
76*f11c7f63SJim Harris  * @brief This enumeration depicts the different IO modes in which the SCI
77*f11c7f63SJim Harris  *        library and it's controllers can operate.
78*f11c7f63SJim Harris  */
79*f11c7f63SJim Harris typedef enum _SCIC_LIBRARY_IO_MODE
80*f11c7f63SJim Harris {
81*f11c7f63SJim Harris    /**
82*f11c7f63SJim Harris     * In this mode the SCI library will operate in a polling mode for
83*f11c7f63SJim Harris     * operations.  In other words, the library will not return from a
84*f11c7f63SJim Harris     * send io method until the completion for the IO has been received.
85*f11c7f63SJim Harris     */
86*f11c7f63SJim Harris    SCIC_IO_MODE_POLLING,
87*f11c7f63SJim Harris 
88*f11c7f63SJim Harris    /**
89*f11c7f63SJim Harris     * In this mode the SCI library returns after committing the IO request
90*f11c7f63SJim Harris     * to the controller hardware.  Completion of the request will occur
91*f11c7f63SJim Harris     * asynchronously.
92*f11c7f63SJim Harris     */
93*f11c7f63SJim Harris    SCIC_IO_MODE_ASYNCHRONOUS
94*f11c7f63SJim Harris 
95*f11c7f63SJim Harris } SCIC_LIBRARY_IO_MODE;
96*f11c7f63SJim Harris 
97*f11c7f63SJim Harris 
98*f11c7f63SJim Harris struct sci_pci_common_header;
99*f11c7f63SJim Harris 
100*f11c7f63SJim Harris /**
101*f11c7f63SJim Harris  * @brief This method will contsruct the core library based on the supplied
102*f11c7f63SJim Harris  *        parameter information.  By default, libraries are considered
103*f11c7f63SJim Harris  *        "ready" as soon as they are constructed.
104*f11c7f63SJim Harris  *
105*f11c7f63SJim Harris  * @param[in]  library_memory a pointer to the memory at which the
106*f11c7f63SJim Harris  *             library object is located.
107*f11c7f63SJim Harris  * @param[in]  max_controller_count the maximum number of controllers that
108*f11c7f63SJim Harris  *             this library can manage.
109*f11c7f63SJim Harris  *
110*f11c7f63SJim Harris  * @return An opaque library handle to be used by the SCI user for all
111*f11c7f63SJim Harris  *         subsequent library operations.
112*f11c7f63SJim Harris  */
113*f11c7f63SJim Harris SCI_LIBRARY_HANDLE_T scic_library_construct(
114*f11c7f63SJim Harris    void *                         library_memory,
115*f11c7f63SJim Harris    U8                             max_controller_count
116*f11c7f63SJim Harris );
117*f11c7f63SJim Harris 
118*f11c7f63SJim Harris /**
119*f11c7f63SJim Harris  * This method sets the PCI header information required for proper
120*f11c7f63SJim Harris  * controller object creation/allocation.
121*f11c7f63SJim Harris  *
122*f11c7f63SJim Harris  * @param[in]  library the handle to the library object for which to allocate
123*f11c7f63SJim Harris  *             a controller.
124*f11c7f63SJim Harris  * @param[in]  pci_header a pointer to the pci header data for the pci
125*f11c7f63SJim Harris  *             device for which this library is being created.
126*f11c7f63SJim Harris  *
127*f11c7f63SJim Harris  * @return none
128*f11c7f63SJim Harris  */
129*f11c7f63SJim Harris void scic_library_set_pci_info(
130*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T           library,
131*f11c7f63SJim Harris    struct sci_pci_common_header * pci_header
132*f11c7f63SJim Harris );
133*f11c7f63SJim Harris 
134*f11c7f63SJim Harris /**
135*f11c7f63SJim Harris  * @brief This method returns the size of the core library object.
136*f11c7f63SJim Harris  *
137*f11c7f63SJim Harris  * @param[in]  max_controller_count the maximum number of controllers that
138*f11c7f63SJim Harris  *             this library can manage.
139*f11c7f63SJim Harris  *
140*f11c7f63SJim Harris  * @return a positive integer value indicating the size (in bytes) of the
141*f11c7f63SJim Harris  *         library object.
142*f11c7f63SJim Harris  */
143*f11c7f63SJim Harris U32 scic_library_get_object_size(
144*f11c7f63SJim Harris    U8  max_controller_count
145*f11c7f63SJim Harris );
146*f11c7f63SJim Harris 
147*f11c7f63SJim Harris /**
148*f11c7f63SJim Harris  *
149*f11c7f63SJim Harris  *
150*f11c7f63SJim Harris  */
151*f11c7f63SJim Harris U8 scic_library_get_pci_device_controller_count(
152*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T  library
153*f11c7f63SJim Harris );
154*f11c7f63SJim Harris 
155*f11c7f63SJim Harris /**
156*f11c7f63SJim Harris  * @brief This method will allocate the next available core controller object
157*f11c7f63SJim Harris  *        that can be managed by this core library.
158*f11c7f63SJim Harris  *
159*f11c7f63SJim Harris  * @param[in]  library the handle to the library object for which to allocate
160*f11c7f63SJim Harris  *             a controller.
161*f11c7f63SJim Harris  * @param[out] new_controller This parameter specifies a pointer to the
162*f11c7f63SJim Harris  *             controller handle that was added to the library.
163*f11c7f63SJim Harris 
164*f11c7f63SJim Harris  * @return Indicate if the controller was successfully allocated or if iti
165*f11c7f63SJim Harris  *         failed in some way.
166*f11c7f63SJim Harris  * @retval SCI_SUCCESS if the controller was successfully allocated.
167*f11c7f63SJim Harris  * @retval SCI_FAILURE_INSUFFICIENT_RESOURCES if the library has no more
168*f11c7f63SJim Harris  *         available controller objects to allocate.
169*f11c7f63SJim Harris  */
170*f11c7f63SJim Harris SCI_STATUS scic_library_allocate_controller(
171*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T      library,
172*f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T * new_controller
173*f11c7f63SJim Harris );
174*f11c7f63SJim Harris 
175*f11c7f63SJim Harris /**
176*f11c7f63SJim Harris  * @brief This method will attempt to free the supplied controller to the
177*f11c7f63SJim Harris  *        library.
178*f11c7f63SJim Harris  *
179*f11c7f63SJim Harris  * @param[in]  library the handle to the library object for which to free
180*f11c7f63SJim Harris  *             a controller.
181*f11c7f63SJim Harris  * @param[in]  controller the handle to the controller object to be freed
182*f11c7f63SJim Harris  *             from the library.
183*f11c7f63SJim Harris  *
184*f11c7f63SJim Harris  * @return Indicate if the controller was successfully freed or if it failed
185*f11c7f63SJim Harris  *         in some way.
186*f11c7f63SJim Harris  * @retval SCI_SUCCESS if the controller was successfully freed.
187*f11c7f63SJim Harris  * @retval SCI_FAILURE_CONTROLLER_NOT_FOUND if the supplied controller is
188*f11c7f63SJim Harris  *         not managed by the supplied library.
189*f11c7f63SJim Harris  */
190*f11c7f63SJim Harris SCI_STATUS scic_library_free_controller(
191*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T     library,
192*f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T  controller
193*f11c7f63SJim Harris );
194*f11c7f63SJim Harris 
195*f11c7f63SJim Harris /**
196*f11c7f63SJim Harris  * @brief This method returns the maximum size (in bytes) that an individual
197*f11c7f63SJim Harris  *        SGL element can address using this library.
198*f11c7f63SJim Harris  *
199*f11c7f63SJim Harris  * @note  SGL size is restricted to the lowest common denominator across all
200*f11c7f63SJim Harris  *        controllers managed by the library.
201*f11c7f63SJim Harris  * @todo  Does the byte count have to be DWORD aligned?
202*f11c7f63SJim Harris  *
203*f11c7f63SJim Harris  * @param[in]  library the handle to the library object for which to
204*f11c7f63SJim Harris  *             determine the maximum SGL size.
205*f11c7f63SJim Harris  *
206*f11c7f63SJim Harris  * @return Return the maximum size (in bytes) for an SGE for any controller
207*f11c7f63SJim Harris  *         managed by this library.
208*f11c7f63SJim Harris  */
209*f11c7f63SJim Harris U32 scic_library_get_max_sge_size(
210*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T  library
211*f11c7f63SJim Harris );
212*f11c7f63SJim Harris 
213*f11c7f63SJim Harris /**
214*f11c7f63SJim Harris  * @brief This method returns the maximum number of SGL elements for a
215*f11c7f63SJim Harris  *        single IO request using this library.
216*f11c7f63SJim Harris  *
217*f11c7f63SJim Harris  * @note  SGE count is restricted to the lowest common denominator across all
218*f11c7f63SJim Harris  *        controllers managed by the library.
219*f11c7f63SJim Harris  *
220*f11c7f63SJim Harris  * @param[in]  library the handle to the library object for which to
221*f11c7f63SJim Harris  *             determine the maximum number of SGEs per IO request.
222*f11c7f63SJim Harris  *
223*f11c7f63SJim Harris  * @return Return the maximum number of SGEs for an IO request for any
224*f11c7f63SJim Harris  *         controller in this library.
225*f11c7f63SJim Harris  */
226*f11c7f63SJim Harris U32 scic_library_get_max_sge_count(
227*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T  library
228*f11c7f63SJim Harris );
229*f11c7f63SJim Harris 
230*f11c7f63SJim Harris /**
231*f11c7f63SJim Harris  * @brief This method returns the maximum length for any IO request that
232*f11c7f63SJim Harris  *        can be handled by the underlying controllers
233*f11c7f63SJim Harris  *
234*f11c7f63SJim Harris  * @note  IO length is restricted to the lowest common denominator across all
235*f11c7f63SJim Harris  *        controllers managed by the library.
236*f11c7f63SJim Harris  *
237*f11c7f63SJim Harris  * @param[in]  library the handle to the library object for which to
238*f11c7f63SJim Harris  *             determine the maximum length for all IO requests.
239*f11c7f63SJim Harris  *
240*f11c7f63SJim Harris  * @return Return the maximum length for all IO requests for any
241*f11c7f63SJim Harris  *         controller in this library.
242*f11c7f63SJim Harris  */
243*f11c7f63SJim Harris U32 scic_library_get_max_io_length(
244*f11c7f63SJim Harris    SCI_LIBRARY_HANDLE_T  library
245*f11c7f63SJim Harris );
246*f11c7f63SJim Harris 
247*f11c7f63SJim Harris /**
248*f11c7f63SJim Harris  * @brief This method returns the minimum number of timers needed.  If the
249*f11c7f63SJim Harris  *        user supplies timers less then the number specified via this
250*f11c7f63SJim Harris  *        call, then the user runs the risk of improper operation.
251*f11c7f63SJim Harris  *
252*f11c7f63SJim Harris  * @return This method returns a value representing the minimum number of
253*f11c7f63SJim Harris  *         timers required by this framework implementation
254*f11c7f63SJim Harris  */
255*f11c7f63SJim Harris U16 scic_library_get_min_timer_count(
256*f11c7f63SJim Harris    void
257*f11c7f63SJim Harris );
258*f11c7f63SJim Harris 
259*f11c7f63SJim Harris /**
260*f11c7f63SJim Harris  * @brief This method returns the maximum number of timers that could
261*f11c7f63SJim Harris  *        be ever be in use by this component at a given time.
262*f11c7f63SJim Harris  *
263*f11c7f63SJim Harris  * @return This method returns a value representing the minimum number of
264*f11c7f63SJim Harris  *         timers required by this framework implementation
265*f11c7f63SJim Harris  */
266*f11c7f63SJim Harris U16 scic_library_get_max_timer_count(
267*f11c7f63SJim Harris    void
268*f11c7f63SJim Harris );
269*f11c7f63SJim Harris 
270*f11c7f63SJim Harris #ifdef __cplusplus
271*f11c7f63SJim Harris }
272*f11c7f63SJim Harris #endif // __cplusplus
273*f11c7f63SJim Harris 
274*f11c7f63SJim Harris #endif // _SCIC_LIBRARY_H_
275*f11c7f63SJim Harris 
276