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