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 #include "unsolicited_frame_control.h"
58 #include "registers.h"
61 * This method will program the unsolicited frames (UFs) into the UF address
62 * table and construct the UF frame structure being modeled in the core. It
63 * will handle the case where some of the UFs are not being used and thus
64 * should have entries programmed to zero in the address table.
65 * @uf_control: This parameter specifies the unsolicted frame control object
66 * for which to construct the unsolicited frames objects.
67 * @uf_buffer_phys_address: This parameter specifies the physical address for
68 * the first unsolicited frame buffer.
69 * @uf_buffer_virt_address: This parameter specifies the virtual address for
70 * the first unsolicited frame buffer.
71 * @unused_uf_header_entries: This parameter specifies the number of unused UF
72 * headers. This value can be non-zero when there are a non-power of 2
73 * number of unsolicited frames being supported.
74 * @used_uf_header_entries: This parameter specifies the number of actually
75 * utilized UF headers.
78 static void scic_sds_unsolicited_frame_control_construct_frames(
79 struct scic_sds_unsolicited_frame_control
*uf_control
,
80 dma_addr_t uf_buffer_phys_address
,
81 void *uf_buffer_virt_address
,
82 u32 unused_uf_header_entries
,
83 u32 used_uf_header_entries
)
86 struct scic_sds_unsolicited_frame
*uf
;
89 * Program the unused buffers into the UF address table and the
90 * controller's array of UFs.
92 for (index
= 0; index
< unused_uf_header_entries
; index
++) {
93 uf
= &uf_control
->buffers
.array
[index
];
96 uf_control
->address_table
.array
[index
] = 0;
97 uf
->header
= &uf_control
->headers
.array
[index
];
98 uf
->state
= UNSOLICITED_FRAME_EMPTY
;
102 * Program the actual used UF buffers into the UF address table and
103 * the controller's array of UFs.
105 for (index
= unused_uf_header_entries
;
106 index
< unused_uf_header_entries
+ used_uf_header_entries
;
108 uf
= &uf_control
->buffers
.array
[index
];
110 uf_control
->address_table
.array
[index
] = uf_buffer_phys_address
;
112 uf
->buffer
= uf_buffer_virt_address
;
113 uf
->header
= &uf_control
->headers
.array
[index
];
114 uf
->state
= UNSOLICITED_FRAME_EMPTY
;
117 * Increment the address of the physical and virtual memory
118 * pointers. Everything is aligned on 1k boundary with an
121 uf_buffer_virt_address
+= SCU_UNSOLICITED_FRAME_BUFFER_SIZE
;
122 uf_buffer_phys_address
+= SCU_UNSOLICITED_FRAME_BUFFER_SIZE
;
126 int scic_sds_unsolicited_frame_control_construct(struct scic_sds_controller
*scic
)
128 struct scic_sds_unsolicited_frame_control
*uf_control
= &scic
->uf_control
;
129 u32 unused_uf_header_entries
;
130 u32 used_uf_header_entries
;
131 u32 used_uf_buffer_bytes
;
132 u32 unused_uf_header_bytes
;
133 u32 used_uf_header_bytes
;
134 dma_addr_t uf_buffer_phys_address
;
135 void *uf_buffer_virt_address
;
139 * The UF buffer address table size must be programmed to a power
140 * of 2. Find the first power of 2 that is equal to or greater then
141 * the number of unsolicited frame buffers to be utilized.
143 uf_control
->address_table
.count
= SCU_MIN_UF_TABLE_ENTRIES
;
144 while (uf_control
->address_table
.count
< uf_control
->buffers
.count
&&
145 uf_control
->address_table
.count
< SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES
)
146 uf_control
->address_table
.count
<<= 1;
149 * Prepare all of the memory sizes for the UF headers, UF address
150 * table, and UF buffers themselves.
152 used_uf_buffer_bytes
= uf_control
->buffers
.count
153 * SCU_UNSOLICITED_FRAME_BUFFER_SIZE
;
154 unused_uf_header_entries
= uf_control
->address_table
.count
155 - uf_control
->buffers
.count
;
156 used_uf_header_entries
= uf_control
->buffers
.count
;
157 unused_uf_header_bytes
= unused_uf_header_entries
158 * sizeof(struct scu_unsolicited_frame_header
);
159 used_uf_header_bytes
= used_uf_header_entries
160 * sizeof(struct scu_unsolicited_frame_header
);
162 size
= used_uf_buffer_bytes
+ used_uf_header_bytes
+
163 uf_control
->address_table
.count
* sizeof(dma_addr_t
);
167 * The Unsolicited Frame buffers are set at the start of the UF
168 * memory descriptor entry. The headers and address table will be
169 * placed after the buffers.
171 uf_buffer_virt_address
= dmam_alloc_coherent(scic_to_dev(scic
), size
,
172 &uf_buffer_phys_address
, GFP_KERNEL
);
173 if (!uf_buffer_virt_address
)
177 * Program the location of the UF header table into the SCU.
179 * - The address must align on a 64-byte boundary. Guaranteed to be
180 * on 64-byte boundary already 1KB boundary for unsolicited frames.
181 * - Program unused header entries to overlap with the last
182 * unsolicited frame. The silicon will never DMA to these unused
183 * headers, since we program the UF address table pointers to
186 uf_control
->headers
.physical_address
=
187 uf_buffer_phys_address
+
188 used_uf_buffer_bytes
-
189 unused_uf_header_bytes
;
191 uf_control
->headers
.array
=
192 uf_buffer_virt_address
+
193 used_uf_buffer_bytes
-
194 unused_uf_header_bytes
;
197 * Program the location of the UF address table into the SCU.
199 * - The address must align on a 64-bit boundary. Guaranteed to be on 64
200 * byte boundary already due to above programming headers being on a
201 * 64-bit boundary and headers are on a 64-bytes in size.
203 uf_control
->address_table
.physical_address
=
204 uf_buffer_phys_address
+
205 used_uf_buffer_bytes
+
206 used_uf_header_bytes
;
208 uf_control
->address_table
.array
=
209 uf_buffer_virt_address
+
210 used_uf_buffer_bytes
+
211 used_uf_header_bytes
;
216 * UF buffer requirements are:
217 * - The last entry in the UF queue is not NULL.
218 * - There is a power of 2 number of entries (NULL or not-NULL)
219 * programmed into the queue.
220 * - Aligned on a 1KB boundary. */
223 * If the user provided less then the maximum amount of memory,
224 * then be sure that we programm the first entries in the UF
225 * address table to NULL. */
226 scic_sds_unsolicited_frame_control_construct_frames(
228 uf_buffer_phys_address
,
229 uf_buffer_virt_address
,
230 unused_uf_header_entries
,
231 used_uf_header_entries
238 * This method returns the frame header for the specified frame index.
245 enum sci_status
scic_sds_unsolicited_frame_control_get_header(
246 struct scic_sds_unsolicited_frame_control
*uf_control
,
250 if (frame_index
< uf_control
->address_table
.count
) {
252 * Skip the first word in the frame since this is a controll word used
253 * by the hardware. */
254 *frame_header
= &uf_control
->buffers
.array
[frame_index
].header
->data
;
259 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
263 * This method returns the frame buffer for the specified frame index.
270 enum sci_status
scic_sds_unsolicited_frame_control_get_buffer(
271 struct scic_sds_unsolicited_frame_control
*uf_control
,
275 if (frame_index
< uf_control
->address_table
.count
) {
276 *frame_buffer
= uf_control
->buffers
.array
[frame_index
].buffer
;
281 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
285 * This method releases the frame once this is done the frame is available for
286 * re-use by the hardware. The data contained in the frame header and frame
287 * buffer is no longer valid.
288 * @uf_control: This parameter specifies the UF control object
289 * @frame_index: This parameter specifies the frame index to attempt to release.
291 * This method returns an indication to the caller as to whether the
292 * unsolicited frame get pointer should be updated.
294 bool scic_sds_unsolicited_frame_control_release_frame(
295 struct scic_sds_unsolicited_frame_control
*uf_control
,
301 frame_get
= uf_control
->get
& (uf_control
->address_table
.count
- 1);
302 frame_cycle
= uf_control
->get
& uf_control
->address_table
.count
;
305 * In the event there are NULL entries in the UF table, we need to
306 * advance the get pointer in order to find out if this frame should
307 * be released (i.e. update the get pointer). */
308 while (((lower_32_bits(uf_control
->address_table
.array
[frame_get
])
310 (upper_32_bits(uf_control
->address_table
.array
[frame_get
])
312 (frame_get
< uf_control
->address_table
.count
))
316 * The table has a NULL entry as it's last element. This is
318 BUG_ON(frame_get
>= uf_control
->address_table
.count
);
320 if (frame_index
< uf_control
->address_table
.count
) {
321 uf_control
->buffers
.array
[frame_index
].state
= UNSOLICITED_FRAME_RELEASED
;
324 * The frame index is equal to the current get pointer so we
325 * can now free up all of the frame entries that */
326 if (frame_get
== frame_index
) {
328 uf_control
->buffers
.array
[frame_get
].state
329 == UNSOLICITED_FRAME_RELEASED
331 uf_control
->buffers
.array
[frame_get
].state
= UNSOLICITED_FRAME_EMPTY
;
336 uf_control
->address_table
.count
- 1,
337 uf_control
->address_table
.count
342 (SCU_UFQGP_GEN_BIT(ENABLE_BIT
) | frame_cycle
| frame_get
);
347 * Frames remain in use until we advance the get pointer
348 * so there is nothing we can do here */