1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2008 - 2015 Freescale Semiconductor Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
5*4882a593Smuzhiyun * modification, are permitted provided that the following conditions are met:
6*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
7*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
8*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
9*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in the
10*4882a593Smuzhiyun * documentation and/or other materials provided with the distribution.
11*4882a593Smuzhiyun * * Neither the name of Freescale Semiconductor nor the
12*4882a593Smuzhiyun * names of its contributors may be used to endorse or promote products
13*4882a593Smuzhiyun * derived from this software without specific prior written permission.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * ALTERNATIVELY, this software may be distributed under the terms of the
17*4882a593Smuzhiyun * GNU General Public License ("GPL") as published by the Free Software
18*4882a593Smuzhiyun * Foundation, either version 2 of that License or (at your option) any
19*4882a593Smuzhiyun * later version.
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22*4882a593Smuzhiyun * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23*4882a593Smuzhiyun * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24*4882a593Smuzhiyun * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25*4882a593Smuzhiyun * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26*4882a593Smuzhiyun * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27*4882a593Smuzhiyun * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28*4882a593Smuzhiyun * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30*4882a593Smuzhiyun * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include "fman_sp.h"
34*4882a593Smuzhiyun #include "fman.h"
35*4882a593Smuzhiyun
fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools * fm_ext_pools,u8 * ordered_array,u16 * sizes_array)36*4882a593Smuzhiyun void fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools
37*4882a593Smuzhiyun *fm_ext_pools,
38*4882a593Smuzhiyun u8 *ordered_array,
39*4882a593Smuzhiyun u16 *sizes_array)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun u16 buf_size = 0;
42*4882a593Smuzhiyun int i = 0, j = 0, k = 0;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun /* First we copy the external buffers pools information
45*4882a593Smuzhiyun * to an ordered local array
46*4882a593Smuzhiyun */
47*4882a593Smuzhiyun for (i = 0; i < fm_ext_pools->num_of_pools_used; i++) {
48*4882a593Smuzhiyun /* get pool size */
49*4882a593Smuzhiyun buf_size = fm_ext_pools->ext_buf_pool[i].size;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /* keep sizes in an array according to poolId
52*4882a593Smuzhiyun * for direct access
53*4882a593Smuzhiyun */
54*4882a593Smuzhiyun sizes_array[fm_ext_pools->ext_buf_pool[i].id] = buf_size;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* save poolId in an ordered array according to size */
57*4882a593Smuzhiyun for (j = 0; j <= i; j++) {
58*4882a593Smuzhiyun /* this is the next free place in the array */
59*4882a593Smuzhiyun if (j == i)
60*4882a593Smuzhiyun ordered_array[i] =
61*4882a593Smuzhiyun fm_ext_pools->ext_buf_pool[i].id;
62*4882a593Smuzhiyun else {
63*4882a593Smuzhiyun /* find the right place for this poolId */
64*4882a593Smuzhiyun if (buf_size < sizes_array[ordered_array[j]]) {
65*4882a593Smuzhiyun /* move the pool_ids one place ahead
66*4882a593Smuzhiyun * to make room for this poolId
67*4882a593Smuzhiyun */
68*4882a593Smuzhiyun for (k = i; k > j; k--)
69*4882a593Smuzhiyun ordered_array[k] =
70*4882a593Smuzhiyun ordered_array[k - 1];
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /* now k==j, this is the place for
73*4882a593Smuzhiyun * the new size
74*4882a593Smuzhiyun */
75*4882a593Smuzhiyun ordered_array[k] =
76*4882a593Smuzhiyun fm_ext_pools->ext_buf_pool[i].id;
77*4882a593Smuzhiyun break;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun EXPORT_SYMBOL(fman_sp_set_buf_pools_in_asc_order_of_buf_sizes);
84*4882a593Smuzhiyun
fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy * int_context_data_copy,struct fman_buffer_prefix_content * buffer_prefix_content,struct fman_sp_buf_margins * buf_margins,struct fman_sp_buffer_offsets * buffer_offsets,u8 * internal_buf_offset)85*4882a593Smuzhiyun int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *
86*4882a593Smuzhiyun int_context_data_copy,
87*4882a593Smuzhiyun struct fman_buffer_prefix_content *
88*4882a593Smuzhiyun buffer_prefix_content,
89*4882a593Smuzhiyun struct fman_sp_buf_margins *buf_margins,
90*4882a593Smuzhiyun struct fman_sp_buffer_offsets *buffer_offsets,
91*4882a593Smuzhiyun u8 *internal_buf_offset)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun u32 tmp;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* Align start of internal context data to 16 byte */
96*4882a593Smuzhiyun int_context_data_copy->ext_buf_offset = (u16)
97*4882a593Smuzhiyun ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS - 1)) ?
98*4882a593Smuzhiyun ((buffer_prefix_content->priv_data_size + OFFSET_UNITS) &
99*4882a593Smuzhiyun ~(u16)(OFFSET_UNITS - 1)) :
100*4882a593Smuzhiyun buffer_prefix_content->priv_data_size);
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Translate margin and int_context params to FM parameters */
103*4882a593Smuzhiyun /* Initialize with illegal value. Later we'll set legal values. */
104*4882a593Smuzhiyun buffer_offsets->prs_result_offset = (u32)ILLEGAL_BASE;
105*4882a593Smuzhiyun buffer_offsets->time_stamp_offset = (u32)ILLEGAL_BASE;
106*4882a593Smuzhiyun buffer_offsets->hash_result_offset = (u32)ILLEGAL_BASE;
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun /* Internally the driver supports 4 options
109*4882a593Smuzhiyun * 1. prsResult/timestamp/hashResult selection (in fact 8 options,
110*4882a593Smuzhiyun * but for simplicity we'll
111*4882a593Smuzhiyun * relate to it as 1).
112*4882a593Smuzhiyun * 2. All IC context (from AD) not including debug.
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* This case covers the options under 1 */
116*4882a593Smuzhiyun /* Copy size must be in 16-byte granularity. */
117*4882a593Smuzhiyun int_context_data_copy->size =
118*4882a593Smuzhiyun (u16)((buffer_prefix_content->pass_prs_result ? 32 : 0) +
119*4882a593Smuzhiyun ((buffer_prefix_content->pass_time_stamp ||
120*4882a593Smuzhiyun buffer_prefix_content->pass_hash_result) ? 16 : 0));
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* Align start of internal context data to 16 byte */
123*4882a593Smuzhiyun int_context_data_copy->int_context_offset =
124*4882a593Smuzhiyun (u8)(buffer_prefix_content->pass_prs_result ? 32 :
125*4882a593Smuzhiyun ((buffer_prefix_content->pass_time_stamp ||
126*4882a593Smuzhiyun buffer_prefix_content->pass_hash_result) ? 64 : 0));
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun if (buffer_prefix_content->pass_prs_result)
129*4882a593Smuzhiyun buffer_offsets->prs_result_offset =
130*4882a593Smuzhiyun int_context_data_copy->ext_buf_offset;
131*4882a593Smuzhiyun if (buffer_prefix_content->pass_time_stamp)
132*4882a593Smuzhiyun buffer_offsets->time_stamp_offset =
133*4882a593Smuzhiyun buffer_prefix_content->pass_prs_result ?
134*4882a593Smuzhiyun (int_context_data_copy->ext_buf_offset +
135*4882a593Smuzhiyun sizeof(struct fman_prs_result)) :
136*4882a593Smuzhiyun int_context_data_copy->ext_buf_offset;
137*4882a593Smuzhiyun if (buffer_prefix_content->pass_hash_result)
138*4882a593Smuzhiyun /* If PR is not requested, whether TS is
139*4882a593Smuzhiyun * requested or not, IC will be copied from TS
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun buffer_offsets->hash_result_offset =
142*4882a593Smuzhiyun buffer_prefix_content->pass_prs_result ?
143*4882a593Smuzhiyun (int_context_data_copy->ext_buf_offset +
144*4882a593Smuzhiyun sizeof(struct fman_prs_result) + 8) :
145*4882a593Smuzhiyun int_context_data_copy->ext_buf_offset + 8;
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun if (int_context_data_copy->size)
148*4882a593Smuzhiyun buf_margins->start_margins =
149*4882a593Smuzhiyun (u16)(int_context_data_copy->ext_buf_offset +
150*4882a593Smuzhiyun int_context_data_copy->size);
151*4882a593Smuzhiyun else
152*4882a593Smuzhiyun /* No Internal Context passing, STartMargin is
153*4882a593Smuzhiyun * immediately after private_info
154*4882a593Smuzhiyun */
155*4882a593Smuzhiyun buf_margins->start_margins =
156*4882a593Smuzhiyun buffer_prefix_content->priv_data_size;
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /* align data start */
159*4882a593Smuzhiyun tmp = (u32)(buf_margins->start_margins %
160*4882a593Smuzhiyun buffer_prefix_content->data_align);
161*4882a593Smuzhiyun if (tmp)
162*4882a593Smuzhiyun buf_margins->start_margins +=
163*4882a593Smuzhiyun (buffer_prefix_content->data_align - tmp);
164*4882a593Smuzhiyun buffer_offsets->data_offset = buf_margins->start_margins;
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun return 0;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun EXPORT_SYMBOL(fman_sp_build_buffer_struct);
169*4882a593Smuzhiyun
170