2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
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.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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
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.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
61 * @brief This file contains all of the method implementations for the
62 * SCIF_SAS_LIBRARY object.
66 #include <dev/isci/scil/scic_library.h>
67 #include <dev/isci/scil/sci_pool.h>
69 #include <dev/isci/scil/scif_sas_library.h>
70 #include <dev/isci/scil/scif_sas_logger.h>
71 #include <dev/isci/scil/scif_sas_controller.h>
75 * This macro simply calculates the size of the framework library. This
76 * includes the memory for each controller object.
78 #define SCIF_LIBRARY_SIZE(max_controllers) \
80 sizeof(SCIF_SAS_LIBRARY_T) + \
81 (sizeof(SCIF_SAS_CONTROLLER_T) * (max_controllers)) \
85 //******************************************************************************
86 //* P U B L I C M E T H O D S
87 //******************************************************************************
90 U32 scif_library_get_object_size(
91 U8 max_controller_count
94 return ( SCIF_LIBRARY_SIZE(max_controller_count) +
95 scic_library_get_object_size(max_controller_count) );
98 // ---------------------------------------------------------------------------
100 SCI_LIBRARY_HANDLE_T scif_library_construct(
101 void * library_memory,
102 U8 max_controller_count
106 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T *) library_memory;
108 // Just clear out the memory of the structure to be safe.
109 memset(fw_library, 0, scif_library_get_object_size(max_controller_count));
111 // Invoke the parent object constructor.
112 SCI_BASE_LIBRARY_CONSTRUCT(fw_library,
114 max_controller_count,
115 struct SCIF_SAS_CONTROLLER,
118 // The memory for the framework controller objects start immediately
119 // after the library object.
120 fw_library->controllers = (SCIF_SAS_CONTROLLER_T*)
121 ((U8*)library_memory + sizeof(SCIF_SAS_LIBRARY_T));
123 // Construct the core library.
124 fw_library->core_object = scic_library_construct(
125 (U8 *)library_memory +
126 SCIF_LIBRARY_SIZE(max_controller_count),
130 // Ensure construction completed successfully for the core.
131 if (fw_library->core_object != SCI_INVALID_HANDLE)
133 // Set the association in the core library to this framework library.
134 sci_object_set_association(
135 (SCI_OBJECT_HANDLE_T) fw_library->core_object,
142 return SCI_INVALID_HANDLE;
145 // ---------------------------------------------------------------------------
147 SCI_STATUS scif_library_allocate_controller(
148 SCI_LIBRARY_HANDLE_T library,
149 SCI_CONTROLLER_HANDLE_T * new_controller
154 // Ensure the user supplied a valid library handle.
155 if (library != SCI_INVALID_HANDLE)
157 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T *) library;
159 // Allocate the framework library.
160 SCI_BASE_LIBRARY_ALLOCATE_CONTROLLER(fw_library, new_controller, &status);
161 if (status == SCI_SUCCESS)
163 SCIF_SAS_CONTROLLER_T * fw_controller;
165 // Allocate the core controller and save the handle in the framework
166 // controller object.
167 fw_controller = (SCIF_SAS_CONTROLLER_T*) *new_controller;
169 // Just clear out the memory of the structure to be safe.
170 memset(fw_controller, 0, sizeof(SCIF_SAS_CONTROLLER_T));
172 status = scic_library_allocate_controller(
173 fw_library->core_object, &(fw_controller->core_object)
176 // Free the framework controller if the core controller allocation
178 if (status != SCI_SUCCESS)
179 scif_library_free_controller(library, fw_controller);
182 if (status != SCI_SUCCESS)
185 sci_base_object_get_logger(fw_library),
186 SCIF_LOG_OBJECT_LIBRARY,
187 "Library:0x%x Status:0x%x controller allocation failed\n",
193 status = SCI_FAILURE_INVALID_PARAMETER_VALUE;
198 // ---------------------------------------------------------------------------
200 SCI_STATUS scif_library_free_controller(
201 SCI_LIBRARY_HANDLE_T library,
202 SCI_CONTROLLER_HANDLE_T controller
207 if ( (library != SCI_INVALID_HANDLE) && (controller != SCI_INVALID_HANDLE) )
209 SCI_STATUS core_status;
210 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T*) library;
211 SCIF_SAS_CONTROLLER_T * fw_controller = (SCIF_SAS_CONTROLLER_T*) controller;
213 core_status = scic_library_free_controller(
214 fw_library->core_object, fw_controller->core_object
217 scif_sas_controller_destruct(fw_controller);
219 SCI_BASE_LIBRARY_FREE_CONTROLLER(
220 (SCIF_SAS_LIBRARY_T *) library,
222 SCIF_SAS_CONTROLLER_T,
226 if ( (status == SCI_SUCCESS) && (core_status != SCI_SUCCESS) )
227 status = core_status;
229 if (status != SCI_SUCCESS)
232 sci_base_object_get_logger(fw_library),
233 SCIF_LOG_OBJECT_LIBRARY,
234 "Library:0x%x Controller:0x%x Status:0x%x free controller failed\n",
235 fw_library, fw_controller, status
240 status = SCI_FAILURE_INVALID_PARAMETER_VALUE;
245 // ---------------------------------------------------------------------------
247 SCI_LIBRARY_HANDLE_T scif_library_get_scic_handle(
248 SCI_LIBRARY_HANDLE_T scif_library
251 SCIF_SAS_LIBRARY_T * fw_library = (SCIF_SAS_LIBRARY_T*) scif_library;
253 return fw_library->core_object;
256 // ---------------------------------------------------------------------------
258 #define SCIF_SAS_LIBRARY_MAX_TIMERS 32
260 U16 scif_library_get_max_timer_count(
264 /// @todo Need to calculate the exact maximum number of timers needed.
265 return SCIF_SAS_LIBRARY_MAX_TIMERS + scic_library_get_max_timer_count();
268 //******************************************************************************
269 //* P R O T E C T E D M E T H O D S
270 //******************************************************************************