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 the implementation of the public methods for a
60 * SCIC_SDS_LIBRARY object.
63 #include <dev/isci/scil/scic_library.h>
64 #include <dev/isci/scil/scic_sds_library.h>
65 #include <dev/isci/scil/scic_sds_controller.h>
66 #include <dev/isci/scil/scic_sds_request.h>
67 #include <dev/isci/scil/scic_sds_remote_device.h>
68 #include <dev/isci/scil/intel_pci.h>
69 #include <dev/isci/scil/scic_sds_pci.h>
70 #include <dev/isci/scil/scu_constants.h>
72 struct SCIC_SDS_CONTROLLER;
74 #define SCIC_LIBRARY_CONTROLLER_MEMORY_START(library) \
75 ((char *)(library) + sizeof(SCIC_SDS_LIBRARY_T))
77 // ---------------------------------------------------------------------------
79 U32 scic_library_get_object_size(
80 U8 max_controller_count
83 return sizeof(SCIC_SDS_LIBRARY_T)
84 + scic_sds_controller_get_object_size() * max_controller_count;
87 // ---------------------------------------------------------------------------
89 SCI_LIBRARY_HANDLE_T scic_library_construct(
90 void * library_memory,
91 U8 max_controller_count
95 SCIC_SDS_LIBRARY_T *this_library;
97 this_library = (SCIC_SDS_LIBRARY_T *)library_memory;
99 this_library->max_controller_count = max_controller_count;
101 this_library->controllers =
102 (SCIC_SDS_CONTROLLER_T *)((char *)library_memory + sizeof(SCIC_SDS_LIBRARY_T));
104 SCI_BASE_LIBRARY_CONSTRUCT(this_library,
105 &this_library->parent,
106 max_controller_count,
107 struct SCIC_SDS_CONTROLLER,
112 // ---------------------------------------------------------------------------
114 void scic_library_set_pci_info(
115 SCI_LIBRARY_HANDLE_T library,
116 SCI_PCI_COMMON_HEADER_T * pci_header
119 SCIC_SDS_LIBRARY_T *this_library;
120 this_library = (SCIC_SDS_LIBRARY_T *)library;
122 this_library->pci_device = pci_header->device_id;
124 #if defined(PBG_HBA_A0_BUILD)
125 this_library->pci_revision = SCIC_SDS_PCI_REVISION_A0;
126 #elif defined(PBG_HBA_A2_BUILD)
127 this_library->pci_revision = SCIC_SDS_PCI_REVISION_A2;
128 #elif defined(PBG_HBA_BETA_BUILD)
129 this_library->pci_revision = SCIC_SDS_PCI_REVISION_B0;
130 #elif defined(PBG_BUILD)
131 // The SCU PCI function revision ID for A0/A2 is not populated
132 // properly. As a result, we force the revision ID to A2 for
133 // this situation. Therefore, the standard PBG build will not
135 if (pci_header->revision == SCIC_SDS_PCI_REVISION_A0)
136 this_library->pci_revision = SCIC_SDS_PCI_REVISION_A2;
138 this_library->pci_revision = pci_header->revision;
142 // ---------------------------------------------------------------------------
144 SCI_STATUS scic_library_allocate_controller(
145 SCI_LIBRARY_HANDLE_T library,
146 SCI_CONTROLLER_HANDLE_T *new_controller
150 SCIC_SDS_LIBRARY_T *this_library;
152 this_library = (SCIC_SDS_LIBRARY_T *)library;
155 ( (this_library->pci_device >= 0x1D60)
156 && (this_library->pci_device <= 0x1D62)
158 || ( (this_library->pci_device >= 0x1D64)
159 && (this_library->pci_device <= 0x1D65)
161 || ( (this_library->pci_device >= 0x1D68)
162 && (this_library->pci_device <= 0x1D6F)
166 SCI_BASE_LIBRARY_ALLOCATE_CONTROLLER(
167 this_library, new_controller, &status);
170 status = SCI_FAILURE_UNSUPPORTED_PCI_DEVICE_ID;
175 // ---------------------------------------------------------------------------
177 SCI_STATUS scic_library_free_controller(
178 SCI_LIBRARY_HANDLE_T library,
179 SCI_CONTROLLER_HANDLE_T controller
183 SCIC_SDS_LIBRARY_T *this_library;
184 this_library = (SCIC_SDS_LIBRARY_T *)library;
186 SCI_BASE_LIBRARY_FREE_CONTROLLER(
187 this_library, controller, struct SCIC_SDS_CONTROLLER, &status);
192 // ---------------------------------------------------------------------------
194 U8 scic_library_get_pci_device_controller_count(
195 SCI_LIBRARY_HANDLE_T library
198 SCIC_SDS_LIBRARY_T *this_library;
201 this_library = (SCIC_SDS_LIBRARY_T *)library;
202 device_id = this_library->pci_device;
204 //Check if we are on a b0 or c0 which has 2 controllers
206 // Warning: If 0x1d66 is ever defined to be a single controller
207 // this logic will fail.
208 // If 0x1d63 or 0x1d67 is ever defined to be dual
209 // controller this logic will fail.
210 ((device_id & 0xFFF1) == 0x1D60)
212 (this_library->pci_revision == SCU_PBG_HBA_REV_B0)
213 || (this_library->pci_revision == SCU_PBG_HBA_REV_C0)
214 || (this_library->pci_revision == SCU_PBG_HBA_REV_C1)
222 // ---------------------------------------------------------------------------
224 U32 scic_library_get_max_sge_size(
225 SCI_LIBRARY_HANDLE_T library
228 return SCU_IO_REQUEST_MAX_SGE_SIZE;
231 // ---------------------------------------------------------------------------
233 U32 scic_library_get_max_sge_count(
234 SCI_LIBRARY_HANDLE_T library
237 return SCU_IO_REQUEST_SGE_COUNT;
240 // ---------------------------------------------------------------------------
242 U32 scic_library_get_max_io_length(
243 SCI_LIBRARY_HANDLE_T library
246 return SCU_IO_REQUEST_MAX_TRANSFER_LENGTH;
249 // ---------------------------------------------------------------------------
251 U16 scic_library_get_min_timer_count(void)
253 return (U16) (scic_sds_controller_get_min_timer_count()
254 + scic_sds_remote_device_get_min_timer_count()
255 + scic_sds_request_get_min_timer_count());
258 // ---------------------------------------------------------------------------
260 U16 scic_library_get_max_timer_count(void)
262 return (U16) (scic_sds_controller_get_max_timer_count()
263 + scic_sds_remote_device_get_max_timer_count()
264 + scic_sds_request_get_max_timer_count());
270 U8 scic_sds_library_get_controller_index(
271 SCIC_SDS_LIBRARY_T * library,
272 SCIC_SDS_CONTROLLER_T * controller
277 for (index = 0; index < library->max_controller_count; index++)
279 if (controller == &library->controllers[index])