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
62 * SCIC_SDS_UNSOLICITED_FRAME_CONTROL object and it's public,
63 * protected, and private methods.
66 #include <dev/isci/scil/scic_sds_unsolicited_frame_control.h>
67 #include <dev/isci/scil/scu_registers.h>
68 #include <dev/isci/scil/scic_sds_controller.h>
69 #include <dev/isci/scil/scic_user_callback.h>
70 #include <dev/isci/scil/sci_util.h>
73 * @brief The UF buffer address table size must be programmed to a power
74 * of 2. Find the first power of 2 that is equal to or greater then
75 * the number of unsolicited frame buffers to be utilized.
77 * @param[in,out] uf_control This parameter specifies the UF control
78 * object for which to update the address table count.
82 void scic_sds_unsolicited_frame_control_set_address_table_count(
83 SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control
86 uf_control->address_table.count = SCU_MIN_UF_TABLE_ENTRIES;
88 (uf_control->address_table.count < uf_control->buffers.count)
89 && (uf_control->address_table.count < SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES)
92 uf_control->address_table.count <<= 1;
97 * @brief This method will program the unsolicited frames (UFs) into
98 * the UF address table and construct the UF frame structure
99 * being modeled in the core. It will handle the case where
100 * some of the UFs are not being used and thus should have
101 * entries programmed to zero in the address table.
103 * @param[in,out] uf_control This parameter specifies the unsolicted
104 * frame control object for which to construct the
105 * unsolicited frames objects.
106 * @param[in] uf_buffer_phys_address This parameter specifies the
107 * physical address for the first unsolicited frame
109 * @param[in] uf_buffer_virt_address This parameter specifies the
110 * virtual address for the first unsolicited frame
112 * @param[in] unused_uf_header_entries This parameter specifies
113 * the number of unused UF headers. This value can
114 * be non-zero when there are a non-power of 2 number
115 * of unsolicited frames being supported.
116 * @param[in] used_uf_header_entries This parameter specifies
117 * the number of actually utilized UF headers.
122 void scic_sds_unsolicited_frame_control_construct_frames(
123 SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
124 SCI_PHYSICAL_ADDRESS uf_buffer_phys_address,
125 POINTER_UINT uf_buffer_virt_address,
126 U32 unused_uf_header_entries,
127 U32 used_uf_header_entries
131 SCIC_SDS_UNSOLICITED_FRAME_T *uf;
133 // Program the unused buffers into the UF address table and the
134 // controller's array of UFs.
135 for (index = 0; index < unused_uf_header_entries; index++)
137 uf = &uf_control->buffers.array[index];
139 sci_cb_make_physical_address(
140 uf_control->address_table.array[index], 0, 0
143 uf->header = &uf_control->headers.array[index];
144 uf->state = UNSOLICITED_FRAME_EMPTY;
147 // Program the actual used UF buffers into the UF address table and
148 // the controller's array of UFs.
149 for (index = unused_uf_header_entries;
150 index < unused_uf_header_entries + used_uf_header_entries;
153 uf = &uf_control->buffers.array[index];
155 uf_control->address_table.array[index] = uf_buffer_phys_address;
157 uf->buffer = (void*) uf_buffer_virt_address;
158 uf->header = &uf_control->headers.array[index];
159 uf->state = UNSOLICITED_FRAME_EMPTY;
161 // Increment the address of the physical and virtual memory pointers
162 // Everything is aligned on 1k boundary with an increment of 1k
163 uf_buffer_virt_address += SCU_UNSOLICITED_FRAME_BUFFER_SIZE;
164 sci_physical_address_add(
165 uf_buffer_phys_address, SCU_UNSOLICITED_FRAME_BUFFER_SIZE
171 * @brief This method constructs the various members of the unsolicted
172 * frame control object (buffers, headers, address, table, etc).
174 * @param[in,out] uf_control This parameter specifies the unsolicited
175 * frame control object to construct.
176 * @param[in] mde This parameter specifies the memory descriptor
177 * from which to derive all of the address information
178 * needed to get the unsolicited frame functionality
180 * @param[in] controller This parameter specifies the controller
181 * object associated with the uf_control being constructed.
185 void scic_sds_unsolicited_frame_control_construct(
186 SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
187 SCI_PHYSICAL_MEMORY_DESCRIPTOR_T *mde,
188 SCIC_SDS_CONTROLLER_T *controller
191 U32 unused_uf_header_entries;
192 U32 used_uf_header_entries;
193 U32 used_uf_buffer_bytes;
194 U32 unused_uf_header_bytes;
195 U32 used_uf_header_bytes;
196 SCI_PHYSICAL_ADDRESS uf_buffer_phys_address;
198 // Prepare all of the memory sizes for the UF headers, UF address
199 // table, and UF buffers themselves.
200 used_uf_buffer_bytes = uf_control->buffers.count
201 * SCU_UNSOLICITED_FRAME_BUFFER_SIZE;
202 unused_uf_header_entries = uf_control->address_table.count
203 - uf_control->buffers.count;
204 used_uf_header_entries = uf_control->buffers.count;
205 unused_uf_header_bytes = unused_uf_header_entries
206 * sizeof(SCU_UNSOLICITED_FRAME_HEADER_T);
207 used_uf_header_bytes = used_uf_header_entries
208 * sizeof(SCU_UNSOLICITED_FRAME_HEADER_T);
210 // The Unsolicited Frame buffers are set at the start of the UF
211 // memory descriptor entry. The headers and address table will be
212 // placed after the buffers.
213 uf_buffer_phys_address = mde->physical_address;
215 // Program the location of the UF header table into the SCU.
217 // - The address must align on a 64-byte boundary. Guaranteed to be
218 // on 64-byte boundary already 1KB boundary for unsolicited frames.
219 // - Program unused header entries to overlap with the last
220 // unsolicited frame. The silicon will never DMA to these unused
221 // headers, since we program the UF address table pointers to
223 uf_control->headers.physical_address = uf_buffer_phys_address;
224 sci_physical_address_add(
225 uf_control->headers.physical_address, used_uf_buffer_bytes);
226 sci_physical_address_subtract(
227 uf_control->headers.physical_address, unused_uf_header_bytes);
229 uf_control->headers.array = (SCU_UNSOLICITED_FRAME_HEADER_T*)
230 ((U8 *)mde->virtual_address + used_uf_buffer_bytes - unused_uf_header_bytes);
232 // Program the location of the UF address table into the SCU.
234 // - The address must align on a 64-bit boundary. Guaranteed to be on 64
235 // byte boundary already due to above programming headers being on a
236 // 64-bit boundary and headers are on a 64-bytes in size.
237 uf_control->address_table.physical_address = uf_buffer_phys_address;
238 sci_physical_address_add(
239 uf_control->address_table.physical_address, used_uf_buffer_bytes);
240 sci_physical_address_add(
241 uf_control->address_table.physical_address, used_uf_header_bytes);
243 uf_control->address_table.array = (SCI_PHYSICAL_ADDRESS*)
244 ((U8 *)mde->virtual_address + used_uf_buffer_bytes + used_uf_header_bytes);
248 // UF buffer requirements are:
249 // - The last entry in the UF queue is not NULL.
250 // - There is a power of 2 number of entries (NULL or not-NULL)
251 // programmed into the queue.
252 // - Aligned on a 1KB boundary.
254 // If the user provided less then the maximum amount of memory,
255 // then be sure that we programm the first entries in the UF
256 // address table to NULL.
257 scic_sds_unsolicited_frame_control_construct_frames(
259 uf_buffer_phys_address,
260 (POINTER_UINT) mde->virtual_address,
261 unused_uf_header_entries,
262 used_uf_header_entries
267 * @brief This method returns the frame header for the specified frame
270 * @param[in] uf_control
271 * @param[in] frame_index
272 * @param[out] frame_header
276 SCI_STATUS scic_sds_unsolicited_frame_control_get_header(
277 SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
282 if (frame_index < uf_control->address_table.count)
284 // Skip the first word in the frame since this is a control word used
286 *frame_header = &uf_control->buffers.array[frame_index].header->data;
291 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
295 * @brief This method returns the frame buffer for the specified frame
298 * @param[in] uf_control
299 * @param[in] frame_index
300 * @param[out] frame_buffer
304 SCI_STATUS scic_sds_unsolicited_frame_control_get_buffer(
305 SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
310 if (frame_index < uf_control->address_table.count)
312 *frame_buffer = uf_control->buffers.array[frame_index].buffer;
317 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
321 * @brief This method releases the frame once this is done the frame is
322 * available for re-use by the hardware. The data contained in the
323 * frame header and frame buffer is no longer valid.
325 * @param[in] uf_control This parameter specifies the UF control object
326 * @param[in] frame_index This parameter specifies the frame index to
327 * attempt to release.
329 * @return This method returns an indication to the caller as to whether
330 * the unsolicited frame get pointer should be updated.
331 * @retval TRUE This value indicates the unsolicited frame get pointer
332 * should be updated (i.e. write SCU_UFQGP_WRITE).
333 * @retval FALSE This value indicates the get pointer should not be
336 BOOL scic_sds_unsolicited_frame_control_release_frame(
337 SCIC_SDS_UNSOLICITED_FRAME_CONTROL_T *uf_control,
344 frame_get = uf_control->get & (uf_control->address_table.count - 1);
345 frame_cycle = uf_control->get & uf_control->address_table.count;
347 // In the event there are NULL entries in the UF table, we need to
348 // advance the get pointer in order to find out if this frame should
349 // be released (i.e. update the get pointer).
352 (sci_cb_physical_address_lower(
353 uf_control->address_table.array[frame_get]) == 0)
354 && (sci_cb_physical_address_upper(
355 uf_control->address_table.array[frame_get]) == 0)
357 && (frame_get < uf_control->address_table.count)
363 // The table has a NULL entry as it's last element. This is
365 ASSERT(frame_get < uf_control->address_table.count);
367 if (frame_index < uf_control->address_table.count)
369 uf_control->buffers.array[frame_index].state = UNSOLICITED_FRAME_RELEASED;
371 // The frame index is equal to the current get pointer so we
372 // can now free up all of the frame entries that
373 if (frame_get == frame_index)
376 uf_control->buffers.array[frame_get].state
377 == UNSOLICITED_FRAME_RELEASED
380 uf_control->buffers.array[frame_get].state = UNSOLICITED_FRAME_EMPTY;
385 uf_control->address_table.count - 1,
386 uf_control->address_table.count
391 (SCU_UFQGP_GEN_BIT(ENABLE_BIT) | frame_cycle | frame_get);
397 // Frames remain in use until we advance the get pointer
398 // so there is nothing we can do here