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
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 * This file contains the implementation of the
58 * struct scic_sds_unsolicited_frame_control object and it's public, protected, and
64 #include "scic_sds_unsolicited_frame_control.h"
65 #include "scu_registers.h"
66 #include "scic_sds_controller.h"
67 #include "scic_user_callback.h"
69 #include "sci_environment.h"
72 * The UF buffer address table size must be programmed to a power of 2. Find
73 * the first power of 2 that is equal to or greater then the number of
74 * unsolicited frame buffers to be utilized.
75 * @uf_control: This parameter specifies the UF control object for which to
76 * update the address table count.
79 void scic_sds_unsolicited_frame_control_set_address_table_count(
80 struct scic_sds_unsolicited_frame_control *uf_control)
82 uf_control->address_table.count = SCU_MIN_UF_TABLE_ENTRIES;
84 (uf_control->address_table.count < uf_control->buffers.count)
85 && (uf_control->address_table.count < SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES)
87 uf_control->address_table.count <<= 1;
92 * This method will program the unsolicited frames (UFs) into the UF address
93 * table and construct the UF frame structure being modeled in the core. It
94 * will handle the case where some of the UFs are not being used and thus
95 * should have entries programmed to zero in the address table.
96 * @uf_control: This parameter specifies the unsolicted frame control object
97 * for which to construct the unsolicited frames objects.
98 * @uf_buffer_phys_address: This parameter specifies the physical address for
99 * the first unsolicited frame buffer.
100 * @uf_buffer_virt_address: This parameter specifies the virtual address for
101 * the first unsolicited frame buffer.
102 * @unused_uf_header_entries: This parameter specifies the number of unused UF
103 * headers. This value can be non-zero when there are a non-power of 2
104 * number of unsolicited frames being supported.
105 * @used_uf_header_entries: This parameter specifies the number of actually
106 * utilized UF headers.
109 static void scic_sds_unsolicited_frame_control_construct_frames(
110 struct scic_sds_unsolicited_frame_control *uf_control,
111 dma_addr_t uf_buffer_phys_address,
112 unsigned long uf_buffer_virt_address,
113 u32 unused_uf_header_entries,
114 u32 used_uf_header_entries)
117 struct scic_sds_unsolicited_frame *uf;
120 * Program the unused buffers into the UF address table and the
121 * controller's array of UFs. */
122 for (index = 0; index < unused_uf_header_entries; index++) {
123 uf = &uf_control->buffers.array[index];
125 sci_cb_make_physical_address(
126 uf_control->address_table.array[index], 0, 0
129 uf->header = &uf_control->headers.array[index];
130 uf->state = UNSOLICITED_FRAME_EMPTY;
134 * Program the actual used UF buffers into the UF address table and
135 * the controller's array of UFs. */
136 for (index = unused_uf_header_entries;
137 index < unused_uf_header_entries + used_uf_header_entries;
139 uf = &uf_control->buffers.array[index];
141 uf_control->address_table.array[index] = uf_buffer_phys_address;
143 uf->buffer = (void *)uf_buffer_virt_address;
144 uf->header = &uf_control->headers.array[index];
145 uf->state = UNSOLICITED_FRAME_EMPTY;
148 * Increment the address of the physical and virtual memory pointers
149 * Everything is aligned on 1k boundary with an increment of 1k */
150 uf_buffer_virt_address += SCU_UNSOLICITED_FRAME_BUFFER_SIZE;
151 sci_physical_address_add(
152 uf_buffer_phys_address, SCU_UNSOLICITED_FRAME_BUFFER_SIZE
158 * This method constructs the various members of the unsolicted frame control
159 * object (buffers, headers, address, table, etc).
160 * @uf_control: This parameter specifies the unsolicited frame control object
162 * @mde: This parameter specifies the memory descriptor from which to derive
163 * all of the address information needed to get the unsolicited frame
164 * functionality working.
165 * @controller: This parameter specifies the controller object associated with
166 * the uf_control being constructed.
169 void scic_sds_unsolicited_frame_control_construct(
170 struct scic_sds_unsolicited_frame_control *uf_control,
171 struct sci_physical_memory_descriptor *mde,
172 struct scic_sds_controller *controller)
174 u32 unused_uf_header_entries;
175 u32 used_uf_header_entries;
176 u32 used_uf_buffer_bytes;
177 u32 unused_uf_header_bytes;
178 u32 used_uf_header_bytes;
179 dma_addr_t uf_buffer_phys_address;
182 * Prepare all of the memory sizes for the UF headers, UF address
183 * table, and UF buffers themselves. */
184 used_uf_buffer_bytes = uf_control->buffers.count
185 * SCU_UNSOLICITED_FRAME_BUFFER_SIZE;
186 unused_uf_header_entries = uf_control->address_table.count
187 - uf_control->buffers.count;
188 used_uf_header_entries = uf_control->buffers.count;
189 unused_uf_header_bytes = unused_uf_header_entries
190 * sizeof(struct scu_unsolicited_frame_header);
191 used_uf_header_bytes = used_uf_header_entries
192 * sizeof(struct scu_unsolicited_frame_header);
195 * The Unsolicited Frame buffers are set at the start of the UF
196 * memory descriptor entry. The headers and address table will be
197 * placed after the buffers. */
198 uf_buffer_phys_address = mde->physical_address;
201 * Program the location of the UF header table into the SCU.
203 * - The address must align on a 64-byte boundary. Guaranteed to be
204 * on 64-byte boundary already 1KB boundary for unsolicited frames.
205 * - Program unused header entries to overlap with the last
206 * unsolicited frame. The silicon will never DMA to these unused
207 * headers, since we program the UF address table pointers to
209 uf_control->headers.physical_address = uf_buffer_phys_address;
210 sci_physical_address_add(
211 uf_control->headers.physical_address, used_uf_buffer_bytes);
212 sci_physical_address_subtract(
213 uf_control->headers.physical_address, unused_uf_header_bytes);
214 uf_control->headers.array
215 = (struct scu_unsolicited_frame_header *)
216 scic_cb_get_virtual_address(
217 controller, uf_control->headers.physical_address
221 * Program the location of the UF address table into the SCU.
223 * - The address must align on a 64-bit boundary. Guaranteed to be on 64
224 * byte boundary already due to above programming headers being on a
225 * 64-bit boundary and headers are on a 64-bytes in size. */
226 uf_control->address_table.physical_address = uf_buffer_phys_address;
227 sci_physical_address_add(
228 uf_control->address_table.physical_address, used_uf_buffer_bytes);
229 sci_physical_address_add(
230 uf_control->address_table.physical_address, used_uf_header_bytes);
231 uf_control->address_table.array
233 scic_cb_get_virtual_address(
234 controller, uf_control->address_table.physical_address
240 * UF buffer requirements are:
241 * - The last entry in the UF queue is not NULL.
242 * - There is a power of 2 number of entries (NULL or not-NULL)
243 * programmed into the queue.
244 * - Aligned on a 1KB boundary. */
247 * If the user provided less then the maximum amount of memory,
248 * then be sure that we programm the first entries in the UF
249 * address table to NULL. */
250 scic_sds_unsolicited_frame_control_construct_frames(
252 uf_buffer_phys_address,
253 (unsigned long)mde->virtual_address,
254 unused_uf_header_entries,
255 used_uf_header_entries
260 * This method returns the frame header for the specified frame index.
267 enum sci_status scic_sds_unsolicited_frame_control_get_header(
268 struct scic_sds_unsolicited_frame_control *uf_control,
272 if (frame_index < uf_control->address_table.count) {
274 * Skip the first word in the frame since this is a controll word used
275 * by the hardware. */
276 *frame_header = &uf_control->buffers.array[frame_index].header->data;
281 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
285 * This method returns the frame buffer for the specified frame index.
292 enum sci_status scic_sds_unsolicited_frame_control_get_buffer(
293 struct scic_sds_unsolicited_frame_control *uf_control,
297 if (frame_index < uf_control->address_table.count) {
298 *frame_buffer = uf_control->buffers.array[frame_index].buffer;
303 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
307 * This method releases the frame once this is done the frame is available for
308 * re-use by the hardware. The data contained in the frame header and frame
309 * buffer is no longer valid.
310 * @uf_control: This parameter specifies the UF control object
311 * @frame_index: This parameter specifies the frame index to attempt to release.
313 * This method returns an indication to the caller as to whether the
314 * unsolicited frame get pointer should be updated. true This value indicates
315 * the unsolicited frame get pointer should be updated (i.e. write
316 * SCU_UFQGP_WRITE). false This value indicates the get pointer should not be
319 bool scic_sds_unsolicited_frame_control_release_frame(
320 struct scic_sds_unsolicited_frame_control *uf_control,
326 frame_get = uf_control->get & (uf_control->address_table.count - 1);
327 frame_cycle = uf_control->get & uf_control->address_table.count;
330 * In the event there are NULL entries in the UF table, we need to
331 * advance the get pointer in order to find out if this frame should
332 * be released (i.e. update the get pointer). */
333 while (((lower_32_bits(uf_control->address_table.array[frame_get])
335 (upper_32_bits(uf_control->address_table.array[frame_get])
337 (frame_get < uf_control->address_table.count))
341 * The table has a NULL entry as it's last element. This is
343 BUG_ON(frame_get >= uf_control->address_table.count);
345 if (frame_index < uf_control->address_table.count) {
346 uf_control->buffers.array[frame_index].state = UNSOLICITED_FRAME_RELEASED;
349 * The frame index is equal to the current get pointer so we
350 * can now free up all of the frame entries that */
351 if (frame_get == frame_index) {
353 uf_control->buffers.array[frame_get].state
354 == UNSOLICITED_FRAME_RELEASED
356 uf_control->buffers.array[frame_get].state = UNSOLICITED_FRAME_EMPTY;
361 uf_control->address_table.count - 1,
362 uf_control->address_table.count
367 (SCU_UFQGP_GEN_BIT(ENABLE_BIT) | frame_cycle | frame_get);
372 * Frames remain in use until we advance the get pointer
373 * so there is nothing we can do here */