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 the implementation of the public methods for a
62 * SCIC_SDS_LIBRARY object.
65 #include <dev/isci/scil/scic_library.h>
66 #include <dev/isci/scil/scic_sds_library.h>
67 #include <dev/isci/scil/scic_sds_controller.h>
68 #include <dev/isci/scil/scic_sds_request.h>
69 #include <dev/isci/scil/scic_sds_remote_device.h>
70 #include <dev/isci/scil/intel_pci.h>
71 #include <dev/isci/scil/scic_sds_pci.h>
72 #include <dev/isci/scil/scu_constants.h>
74 struct SCIC_SDS_CONTROLLER;
76 #define SCIC_LIBRARY_CONTROLLER_MEMORY_START(library) \
77 ((char *)(library) + sizeof(SCIC_SDS_LIBRARY_T))
79 // ---------------------------------------------------------------------------
81 U32 scic_library_get_object_size(
82 U8 max_controller_count
85 return sizeof(SCIC_SDS_LIBRARY_T)
86 + scic_sds_controller_get_object_size() * max_controller_count;
89 // ---------------------------------------------------------------------------
91 SCI_LIBRARY_HANDLE_T scic_library_construct(
92 void * library_memory,
93 U8 max_controller_count
97 SCIC_SDS_LIBRARY_T *this_library;
99 this_library = (SCIC_SDS_LIBRARY_T *)library_memory;
101 this_library->max_controller_count = max_controller_count;
103 this_library->controllers =
104 (SCIC_SDS_CONTROLLER_T *)((char *)library_memory + sizeof(SCIC_SDS_LIBRARY_T));
106 SCI_BASE_LIBRARY_CONSTRUCT(this_library,
107 &this_library->parent,
108 max_controller_count,
109 struct SCIC_SDS_CONTROLLER,
114 // ---------------------------------------------------------------------------
116 void scic_library_set_pci_info(
117 SCI_LIBRARY_HANDLE_T library,
118 SCI_PCI_COMMON_HEADER_T * pci_header
121 SCIC_SDS_LIBRARY_T *this_library;
122 this_library = (SCIC_SDS_LIBRARY_T *)library;
124 this_library->pci_device = pci_header->device_id;
126 #if defined(PBG_HBA_A0_BUILD)
127 this_library->pci_revision = SCIC_SDS_PCI_REVISION_A0;
128 #elif defined(PBG_HBA_A2_BUILD)
129 this_library->pci_revision = SCIC_SDS_PCI_REVISION_A2;
130 #elif defined(PBG_HBA_BETA_BUILD)
131 this_library->pci_revision = SCIC_SDS_PCI_REVISION_B0;
132 #elif defined(PBG_BUILD)
133 // The SCU PCI function revision ID for A0/A2 is not populated
134 // properly. As a result, we force the revision ID to A2 for
135 // this situation. Therefore, the standard PBG build will not
137 if (pci_header->revision == SCIC_SDS_PCI_REVISION_A0)
138 this_library->pci_revision = SCIC_SDS_PCI_REVISION_A2;
140 this_library->pci_revision = pci_header->revision;
144 // ---------------------------------------------------------------------------
146 SCI_STATUS scic_library_allocate_controller(
147 SCI_LIBRARY_HANDLE_T library,
148 SCI_CONTROLLER_HANDLE_T *new_controller
152 SCIC_SDS_LIBRARY_T *this_library;
154 this_library = (SCIC_SDS_LIBRARY_T *)library;
157 ( (this_library->pci_device >= 0x1D60)
158 && (this_library->pci_device <= 0x1D62)
160 || ( (this_library->pci_device >= 0x1D64)
161 && (this_library->pci_device <= 0x1D65)
163 || ( (this_library->pci_device >= 0x1D68)
164 && (this_library->pci_device <= 0x1D6F)
168 SCI_BASE_LIBRARY_ALLOCATE_CONTROLLER(
169 this_library, new_controller, &status);
172 status = SCI_FAILURE_UNSUPPORTED_PCI_DEVICE_ID;
177 // ---------------------------------------------------------------------------
179 SCI_STATUS scic_library_free_controller(
180 SCI_LIBRARY_HANDLE_T library,
181 SCI_CONTROLLER_HANDLE_T controller
185 SCIC_SDS_LIBRARY_T *this_library;
186 this_library = (SCIC_SDS_LIBRARY_T *)library;
188 SCI_BASE_LIBRARY_FREE_CONTROLLER(
189 this_library, controller, struct SCIC_SDS_CONTROLLER, &status);
194 // ---------------------------------------------------------------------------
196 U8 scic_library_get_pci_device_controller_count(
197 SCI_LIBRARY_HANDLE_T library
200 SCIC_SDS_LIBRARY_T *this_library;
203 this_library = (SCIC_SDS_LIBRARY_T *)library;
204 device_id = this_library->pci_device;
206 //Check if we are on a b0 or c0 which has 2 controllers
208 // Warning: If 0x1d66 is ever defined to be a single controller
209 // this logic will fail.
210 // If 0x1d63 or 0x1d67 is ever defined to be dual
211 // controller this logic will fail.
212 ((device_id & 0xFFF1) == 0x1D60)
214 (this_library->pci_revision == SCU_PBG_HBA_REV_B0)
215 || (this_library->pci_revision == SCU_PBG_HBA_REV_C0)
216 || (this_library->pci_revision == SCU_PBG_HBA_REV_C1)
224 // ---------------------------------------------------------------------------
226 U32 scic_library_get_max_sge_size(
227 SCI_LIBRARY_HANDLE_T library
230 return SCU_IO_REQUEST_MAX_SGE_SIZE;
233 // ---------------------------------------------------------------------------
235 U32 scic_library_get_max_sge_count(
236 SCI_LIBRARY_HANDLE_T library
239 return SCU_IO_REQUEST_SGE_COUNT;
242 // ---------------------------------------------------------------------------
244 U32 scic_library_get_max_io_length(
245 SCI_LIBRARY_HANDLE_T library
248 return SCU_IO_REQUEST_MAX_TRANSFER_LENGTH;
251 // ---------------------------------------------------------------------------
253 U16 scic_library_get_min_timer_count(void)
255 return (U16) (scic_sds_controller_get_min_timer_count()
256 + scic_sds_remote_device_get_min_timer_count()
257 + scic_sds_request_get_min_timer_count());
260 // ---------------------------------------------------------------------------
262 U16 scic_library_get_max_timer_count(void)
264 return (U16) (scic_sds_controller_get_max_timer_count()
265 + scic_sds_remote_device_get_max_timer_count()
266 + scic_sds_request_get_max_timer_count());
272 U8 scic_sds_library_get_controller_index(
273 SCIC_SDS_LIBRARY_T * library,
274 SCIC_SDS_CONTROLLER_T * controller
279 for (index = 0; index < library->max_controller_count; index++)
281 if (controller == &library->controllers[index])