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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
59 * @brief This file contains all of the method implementations for the
60 * SCIF_SAS_LIBRARY object.
64 #include <dev/isci/scil/scic_library.h>
65 #include <dev/isci/scil/sci_pool.h>
67 #include <dev/isci/scil/scif_sas_library.h>
68 #include <dev/isci/scil/scif_sas_logger.h>
69 #include <dev/isci/scil/scif_sas_controller.h>
73 * This macro simply calculates the size of the framework library. This
74 * includes the memory for each controller object.
76 #define SCIF_LIBRARY_SIZE(max_controllers) \
78 sizeof(SCIF_SAS_LIBRARY_T) + \
79 (sizeof(SCIF_SAS_CONTROLLER_T) * (max_controllers)) \
83 //******************************************************************************
84 //* P U B L I C M E T H O D S
85 //******************************************************************************
88 U32 scif_library_get_object_size(
89 U8 max_controller_count
92 return ( SCIF_LIBRARY_SIZE(max_controller_count) +
93 scic_library_get_object_size(max_controller_count) );
96 // ---------------------------------------------------------------------------
98 SCI_LIBRARY_HANDLE_T scif_library_construct(
99 void * library_memory,
100 U8 max_controller_count
104 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T *) library_memory;
106 // Just clear out the memory of the structure to be safe.
107 memset(fw_library, 0, scif_library_get_object_size(max_controller_count));
109 // Invoke the parent object constructor.
110 SCI_BASE_LIBRARY_CONSTRUCT(fw_library,
112 max_controller_count,
113 struct SCIF_SAS_CONTROLLER,
116 // The memory for the framework controller objects start immediately
117 // after the library object.
118 fw_library->controllers = (SCIF_SAS_CONTROLLER_T*)
119 ((U8*)library_memory + sizeof(SCIF_SAS_LIBRARY_T));
121 // Construct the core library.
122 fw_library->core_object = scic_library_construct(
123 (U8 *)library_memory +
124 SCIF_LIBRARY_SIZE(max_controller_count),
128 // Ensure construction completed successfully for the core.
129 if (fw_library->core_object != SCI_INVALID_HANDLE)
131 // Set the association in the core library to this framework library.
132 sci_object_set_association(
133 (SCI_OBJECT_HANDLE_T) fw_library->core_object,
140 return SCI_INVALID_HANDLE;
143 // ---------------------------------------------------------------------------
145 SCI_STATUS scif_library_allocate_controller(
146 SCI_LIBRARY_HANDLE_T library,
147 SCI_CONTROLLER_HANDLE_T * new_controller
152 // Ensure the user supplied a valid library handle.
153 if (library != SCI_INVALID_HANDLE)
155 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T *) library;
157 // Allocate the framework library.
158 SCI_BASE_LIBRARY_ALLOCATE_CONTROLLER(fw_library, new_controller, &status);
159 if (status == SCI_SUCCESS)
161 SCIF_SAS_CONTROLLER_T * fw_controller;
163 // Allocate the core controller and save the handle in the framework
164 // controller object.
165 fw_controller = (SCIF_SAS_CONTROLLER_T*) *new_controller;
167 // Just clear out the memory of the structure to be safe.
168 memset(fw_controller, 0, sizeof(SCIF_SAS_CONTROLLER_T));
170 status = scic_library_allocate_controller(
171 fw_library->core_object, &(fw_controller->core_object)
174 // Free the framework controller if the core controller allocation
176 if (status != SCI_SUCCESS)
177 scif_library_free_controller(library, fw_controller);
180 if (status != SCI_SUCCESS)
183 sci_base_object_get_logger(fw_library),
184 SCIF_LOG_OBJECT_LIBRARY,
185 "Library:0x%x Status:0x%x controller allocation failed\n",
191 status = SCI_FAILURE_INVALID_PARAMETER_VALUE;
196 // ---------------------------------------------------------------------------
198 SCI_STATUS scif_library_free_controller(
199 SCI_LIBRARY_HANDLE_T library,
200 SCI_CONTROLLER_HANDLE_T controller
205 if ( (library != SCI_INVALID_HANDLE) && (controller != SCI_INVALID_HANDLE) )
207 SCI_STATUS core_status;
208 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T*) library;
209 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T*) controller;
211 core_status = scic_library_free_controller(
212 fw_library->core_object, fw_controller->core_object
215 scif_sas_controller_destruct(fw_controller);
217 SCI_BASE_LIBRARY_FREE_CONTROLLER(
218 (SCIF_SAS_LIBRARY_T *) library,
220 SCIF_SAS_CONTROLLER_T,
224 if ( (status == SCI_SUCCESS) && (core_status != SCI_SUCCESS) )
225 status = core_status;
227 if (status != SCI_SUCCESS)
230 sci_base_object_get_logger(fw_library),
231 SCIF_LOG_OBJECT_LIBRARY,
232 "Library:0x%x Controller:0x%x Status:0x%x free controller failed\n",
233 fw_library, fw_controller, status
238 status = SCI_FAILURE_INVALID_PARAMETER_VALUE;
243 // ---------------------------------------------------------------------------
245 SCI_LIBRARY_HANDLE_T scif_library_get_scic_handle(
246 SCI_LIBRARY_HANDLE_T scif_library
249 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T*) scif_library;
251 return fw_library->core_object;
254 // ---------------------------------------------------------------------------
256 #define SCIF_SAS_LIBRARY_MAX_TIMERS 32
258 U16 scif_library_get_max_timer_count(
262 /// @todo Need to calculate the exact maximum number of timers needed.
263 return SCIF_SAS_LIBRARY_MAX_TIMERS + scic_library_get_max_timer_count();
266 //******************************************************************************
267 //* P R O T E C T E D M E T H O D S
268 //******************************************************************************