Renaming UE IDX to UE ID in SCH and its interfaces [Issue-ID: ODUHIGH-401]
[o-du/l2.git] / src / 5gnrsch / sch_utils.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /************************************************************************
20  
21      Name:     sch_utils.c
22   
23      Type:     C source file
24   
25      Desc:     C source code for scheduler utilities
26   
27      File:     sch_utils.c
28   
29 **********************************************************************/
30
31 /** @file sch_utils.c
32 @brief This file implements the schedulers util functions.
33 */
34
35 /* header files */
36 #include "common_def.h"
37 #include "du_app_mac_inf.h"
38 #include "lrg.h"
39 #include "tfu.h"
40 #include "tfu.x"           /* TFU types */
41 #include "lrg.x"           /* layer management typedefs for MAC */
42 #include "mac_sch_interface.h"
43 #include "sch.h"
44 #include "sch_utils.h"
45 #include "math.h"
46
47 #ifdef NR_TDD
48 /* spec-38.213 Table 13-4 for SCS=30KHz */
49 /* Note: Picking Table 13-4 and not 13-6 since band supported is n78 and
50  * corresponding minimum B/W is 10 MHz */
51 int8_t coresetIdxTable[MAX_CORESET_INDEX][4] = {
52 {   1,   24,   2,   0}, /* index 0  */
53 {   1,   24,   2,   1}, /* index 1  */
54 {   1,   24,   2,   2}, /* index 2  */
55 {   1,   24,   2,   3}, /* index 3  */
56 {   1,   24,   2,   4}, /* index 4  */
57 {   1,   24,   3,   0}, /* index 5  */
58 {   1,   24,   3,   1}, /* index 6  */
59 {   1,   24,   3,   2}, /* index 7  */
60 {   1,   24,   3,   3}, /* index 8  */
61 {   1,   24,   3,   4}, /* index 9  */
62 {   1,   48,   1,  12}, /* index 10 */
63 {   1,   48,   1,  14}, /* index 11 */
64 {   1,   48,   1,  16}, /* index 12 */
65 {   1,   48,   2,  12}, /* index 13 */
66 {   1,   48,   2,  14}, /* index 14 */
67 {   1,   48,   2,  16}, /* index 15 */
68 };
69 #else
70 /* spec-38.213 Table 13-1 for SCS=15KHz */
71 int8_t coresetIdxTable[MAX_CORESET_INDEX][4] = {
72 {   1,   24,   2,   0}, /* index 0  */
73 {   1,   24,   2,   2}, /* index 1  */
74 {   1,   24,   2,   4}, /* index 2  */
75 {   1,   24,   3,   0}, /* index 3  */
76 {   1,   24,   3,   2}, /* index 4  */
77 {   1,   24,   3,   4}, /* index 5  */
78 {   1,   48,   1,  12}, /* index 6  */
79 {   1,   48,   1,  16}, /* index 7  */
80 {   1,   48,   2,  12}, /* index 8  */
81 {   1,   48,   2,  16}, /* index 9  */
82 {   1,   48,   3,  12}, /* index 10 */
83 {   1,   48,   3,  16}, /* index 11 */
84 {   1,   96,   1,  38}, /* index 12 */
85 {   1,   96,   2,  38}, /* index 13 */
86 {   1,   96,   3,  38}, /* index 14 */
87 {   0,    0,   0,   0}, /* index 15 */
88 };
89 #endif
90
91 /* spec-38.213 Table 13-11 */
92 /* m value is scaled to 2, when using it in formula, divide by 2 */
93 /* firstSymbol will vary depends on i, hence not filled */
94 int8_t searchSpaceIdxTable[MAX_SEARCH_SPACE_INDEX][4] = {
95 {   0,    1,   2,   0}, /* index 0  */
96 {   0,    2,   1,   0}, /* index 1  */
97 {   2,    1,   2,   0}, /* index 2  */
98 {   2,    2,   1,   0}, /* index 3  */
99 {   5,    1,   2,   0}, /* index 4  */
100 {   5,    2,   1,   0}, /* index 5  */
101 {   7,    1,   2,   0}, /* index 6  */
102 {   7,    2,   1,   0}, /* index 7  */
103 {   0,    1,   4,   0}, /* index 8  */
104 {   5,    1,   4,   0}, /* index 9  */
105 {   0,    1,   2,   0}, /* index 10 */
106 {   0,    1,   2,   0}, /* index 11 */
107 {   2,    1,   2,   0}, /* index 12 */
108 {   2,    1,   2,   0}, /* index 13 */
109 {   5,    1,   2,   0}, /* index 14 */
110 {   5,    1,   2,   0}, /* index 15 */
111 };
112
113 /* RACH tables */
114
115 /* spec-38.211 Table 6.3.3.2-1 */
116 /* Lra, delFRa, delF, numRb, k' */
117 uint16_t numRbForPrachTable[MAX_RACH_NUM_RB_IDX][5] = {
118 {   839,  1.25,  15,   6,   7    }, /* index 0 */
119 {   839,  1.25,  30,   3,   1    }, /* index 1 */
120 {   839,  1.25,  60,   2,   133  }, /* index 2 */
121 {   839,  5,     15,   24,  12   }, /* index 3 */
122 {   839,  5,     30,   12,  10   }, /* index 4 */
123 {   839,  5,     60,   6,   7    }, /* index 5 */
124 {   139,  15,    15,   12,  2    }, /* index 6 */
125 {   139,  15,    30,   6,   2    }, /* index 7 */
126 {   139,  15,    60,   3,   2    }, /* index 8 */
127 {   139,  30,    15,   24,  2    }, /* index 9 */
128 {   139,  30,    30,   12,  2    }, /* index 10 */
129 {   139,  30,    60,   6,   2    }, /* index 11 */
130 {   139,  60,    60,   12,  2    }, /* index 12 */
131 {   139,  60,    120,  6,   2    }, /* index 13 */
132 {   139,  120,   60,   24,  2    }, /* index 14 */
133 {   139,  120,   120,  12,  2    }, /* index 15 */
134 };
135
136 #ifdef NR_TDD
137
138 /* prach config index Table 6.3.3.2-3 spec 38.211 
139  * PRACH format given as follows:
140  * 0 = 0
141  * 1 = 1
142  * 2 = 2
143  * 3 = 3
144  * 4 = A1
145  * 5 = A2
146  * 6 = A3
147  * 7 = B1
148  * 8 = B4
149  * 9 = C0
150  * 10 = C2
151  * 11 = A1/B1
152  * 12 = A2/B2
153  * 13 = A3/B3 
154  * Subframe num is represented considering 0-9 bits and
155  * value 1 corresponds to the subframe that is valid 
156  */
157
158 uint16_t prachCfgIdxTable[MAX_PRACH_CONFIG_IDX][8] = {
159 { 0, 16,  1,  512,  0,  0,  0,  0 }, /* index 0   */
160 { 0,  8,  1,  512,  0,  0,  0,  0 }, /* index 1   */
161 { 0,  4,  1,  512,  0,  0,  0,  0 }, /* index 2   */
162 { 0,  2,  0,  512,  0,  0,  0,  0 }, /* index 3   */
163 { 0,  2,  1,  512,  0,  0,  0,  0 }, /* index 4   */
164 { 0,  2,  0,   16,  0,  0,  0,  0 }, /* index 5   */
165 { 0,  2,  1,   16,  0,  0,  0,  0 }, /* index 6   */
166 { 0,  1,  0,  512,  0,  0,  0,  0 }, /* index 7   */
167 { 0,  1,  0,  256,  0,  0,  0,  0 }, /* index 8   */
168 { 0,  1,  0,  128,  0,  0,  0,  0 }, /* index 9   */
169 { 0,  1,  0,   64,  0,  0,  0,  0 }, /* index 10  */
170 { 0,  1,  0,   32,  0,  0,  0,  0 }, /* index 11  */
171 { 0,  1,  0,   16,  0,  0,  0,  0 }, /* index 12  */
172 { 0,  1,  0,    8,  0,  0,  0,  0 }, /* index 13  */
173 { 0,  1,  0,    4,  0,  0,  0,  0 }, /* index 14  */
174 { 0,  1,  0,   66,  0,  0,  0,  0 }, /* index 15  */
175 { 0,  1,  0,   66,  7,  0,  0,  0 }, /* index 16  */
176 { 0,  1,  0,  528,  0,  0,  0,  0 }, /* index 17  */
177 { 0,  1,  0,  264,  0,  0,  0,  0 }, /* index 18  */
178 { 0,  1,  0,  132,  0,  0,  0,  0 }, /* index 19  */
179 { 0,  1,  0,  768,  0,  0,  0,  0 }, /* index 20  */
180 { 0,  1,  0,  784,  0,  0,  0,  0 }, /* index 21  */
181 { 0,  1,  0,  536,  0,  0,  0,  0 }, /* index 22  */
182 { 0,  1,  0,  896,  0,  0,  0,  0 }, /* index 23  */
183 { 0,  1,  0,  792,  0,  0,  0,  0 }, /* index 24  */
184 { 0,  1,  0,  960,  0,  0,  0,  0 }, /* index 25  */
185 { 0,  1,  0,  594,  0,  0,  0,  0 }, /* index 26  */
186 { 0,  1,  0,  682,  0,  0,  0,  0 }, /* index 27  */
187 { 1, 16,  1,  128,  0,  0,  0,  0 }, /* index 28  */
188 { 1,  8,  1,  128,  0,  0,  0,  0 }, /* index 29  */
189 { 1,  4,  1,  128,  0,  0,  0,  0 }, /* index 30  */
190 { 1,  2,  0,  128,  0,  0,  0,  0 }, /* index 31  */
191 { 1,  2,  1,  128,  0,  0,  0,  0 }, /* index 32  */
192 { 1,  1,  0,  128,  0,  0,  0,  0 }, /* index 33  */
193 { 2, 16,  1,   64,  0,  0,  0,  0 }, /* index 34  */
194 { 2,  8,  1,   64,  0,  0,  0,  0 }, /* index 35  */
195 { 2,  4,  1,   64,  0,  0,  0,  0 }, /* index 36  */
196 { 2,  2,  0,   64,  7,  0,  0,  0 }, /* index 37  */
197 { 2,  2,  1,   64,  7,  0,  0,  0 }, /* index 38  */
198 { 2,  1,  0,   64,  7,  0,  0,  0 }, /* index 39  */
199 { 3, 16,  1,  512,  0,  0,  0,  0 }, /* index 40  */
200 { 3,  8,  1,  512,  0,  0,  0,  0 }, /* index 41  */
201 { 3,  4,  1,  512,  0,  0,  0,  0 }, /* index 42  */
202 { 3,  2,  0,  512,  0,  0,  0,  0 }, /* index 43  */
203 { 3,  2,  1,  512,  0,  0,  0,  0 }, /* index 44  */
204 { 3,  2,  0,   16,  0,  0,  0,  0 }, /* index 45  */
205 { 3,  2,  1,   16,  0,  0,  0,  0 }, /* index 46  */
206 { 3,  1,  0,  512,  0,  0,  0,  0 }, /* index 47  */
207 { 3,  1,  0,  256,  0,  0,  0,  0 }, /* index 48  */
208 { 3,  1,  0,  128,  0,  0,  0,  0 }, /* index 49  */
209 { 3,  1,  0,   64,  0,  0,  0,  0 }, /* index 50  */
210 { 3,  1,  0,   32,  0,  0,  0,  0 }, /* index 51  */
211 { 3,  1,  0,   16,  0,  0,  0,  0 }, /* index 52  */
212 { 3,  1,  0,    8,  0,  0,  0,  0 }, /* index 53  */
213 { 3,  1,  0,    4,  0,  0,  0,  0 }, /* index 54  */
214 { 3,  1,  0,   66,  0,  0,  0,  0 }, /* index 55  */
215 { 3,  1,  0,   66,  7,  0,  0,  0 }, /* index 56  */
216 { 3,  1,  0,  528,  0,  0,  0,  0 }, /* index 57  */
217 { 3,  1,  0,  264,  0,  0,  0,  0 }, /* index 58  */
218 { 3,  1,  0,  132,  0,  0,  0,  0 }, /* index 59  */
219 { 3,  1,  0,  768,  0,  0,  0,  0 }, /* index 60  */
220 { 3,  1,  0,  784,  0,  0,  0,  0 }, /* index 61  */
221 { 3,  1,  0,  536,  0,  0,  0,  0 }, /* index 62  */
222 { 3,  1,  0,  896,  0,  0,  0,  0 }, /* index 63  */
223 { 3,  1,  0,  792,  0,  0,  0,  0 }, /* index 64  */
224 { 3,  1,  0,  594,  0,  0,  0,  0 }, /* index 65  */
225 { 3,  1,  0,  682,  0,  0,  0,  0 }, /* index 66  */
226 { 4, 16,  1,  512,  0,  2,  6,  2 }, /* index 67  */
227 { 4,  8,  1,  512,  0,  2,  6,  2 }, /* index 68  */
228 { 4,  4,  1,  512,  0,  1,  6,  2 }, /* index 69  */
229 { 4,  2,  1,  512,  0,  1,  6,  2 }, /* index 70  */
230 { 4,  2,  1,  528,  7,  1,  3,  2 }, /* index 71  */
231 { 4,  2,  1,  640,  7,  1,  3,  2 }, /* index 72  */
232 { 4,  2,  1,  640,  0,  1,  6,  2 }, /* index 73  */
233 { 4,  2,  1,  768,  0,  2,  6,  2 }, /* index 74  */
234 { 4,  2,  1,  528,  0,  2,  6,  2 }, /* index 75  */
235 { 4,  2,  1,  924,  0,  1,  6,  2 }, /* index 76  */
236 { 4,  1,  0,  512,  0,  2,  6,  2 }, /* index 77  */
237 { 4,  1,  0,  512,  7,  1,  3,  2 }, /* index 78  */
238 { 4,  1,  0,  512,  0,  1,  6,  2 }, /* index 79  */
239 { 4,  1,  0,  768,  0,  2,  6,  2 }, /* index 80  */
240 { 4,  1,  0,  528,  0,  1,  6,  2 }, /* index 81  */
241 { 4,  1,  0,  640,  7,  1,  3,  2 }, /* index 82  */
242 { 4,  1,  0,  792,  0,  1,  6,  2 }, /* index 83  */
243 { 4,  1,  0,  792,  0,  2,  6,  2 }, /* index 84  */
244 { 4,  1,  0,  682,  0,  1,  6,  2 }, /* index 85  */
245 { 4,  1,  0, 1023,  7,  1,  3,  2 }, /* index 86  */
246 { 5, 16,  1,  512,  0,  2,  3,  4 }, /* index 87  */
247 { 5,  8,  1,  512,  0,  2,  3,  4 }, /* index 88  */
248 { 5,  4,  1,  512,  0,  1,  3,  4 }, /* index 89  */
249 { 5,  2,  1,  640,  0,  1,  3,  4 }, /* index 90  */
250 { 5,  2,  1,  768,  0,  2,  3,  4 }, /* index 91  */
251 { 5,  2,  1,  640,  9,  1,  1,  4 }, /* index 92  */
252 { 5,  2,  1,  528,  9,  1,  1,  4 }, /* index 93  */
253 { 5,  2,  1,  528,  0,  2,  3,  4 }, /* index 94  */
254 { 5,  2,  1,  924,  0,  1,  3,  4 }, /* index 95  */
255 { 5,  1,  0,    4,  0,  1,  3,  4 }, /* index 96  */
256 { 5,  1,  0,  128,  0,  1,  3,  4 }, /* index 97  */
257 { 5,  2,  1,  512,  0,  1,  3,  4 }, /* index 98  */
258 { 5,  1,  0,  512,  0,  2,  3,  4 }, /* index 99  */
259 { 5,  1,  0,  512,  9,  1,  1,  4 }, /* index 100  */
260 { 5,  1,  0,  512,  0,  1,  3,  4 }, /* index 101  */
261 { 5,  1,  0,  132,  0,  1,  3,  4 }, /* index 102  */
262 { 5,  1,  0,  768,  0,  2,  3,  4 }, /* index 103  */
263 { 5,  1,  0,  528,  0,  1,  3,  4 }, /* index 104  */
264 { 5,  1,  0,  640,  9,  1,  1,  4 }, /* index 105  */
265 { 5,  1,  0,  792,  0,  1,  3,  4 }, /* index 106  */
266 { 5,  1,  0,  792,  0,  2,  3,  4 }, /* index 107  */
267 { 5,  1,  0,  682,  0,  1,  3,  4 }, /* index 108  */
268 { 5,  1,  0, 1023,  9,  1,  1,  4 }, /* index 109  */
269 { 6, 16,  1,  512,  0,  2,  2,  6 }, /* index 110  */
270 { 6,  8,  1,  512,  0,  2,  2,  6 }, /* index 111  */
271 { 6,  4,  1,  512,  0,  1,  2,  6 }, /* index 112  */
272 { 6,  2,  1,  528,  7,  1,  1,  6 }, /* index 113  */
273 { 6,  2,  1,  640,  7,  1,  1,  6 }, /* index 114  */
274 { 6,  2,  1,  640,  0,  1,  2,  6 }, /* index 115  */
275 { 6,  2,  1,  528,  0,  2,  2,  6 }, /* index 116  */
276 { 6,  2,  1,  768,  0,  2,  2,  6 }, /* index 117  */
277 { 6,  2,  1,  924,  0,  1,  2,  6 }, /* index 118  */
278 { 6,  1,  0,    4,  0,  1,  2,  6 }, /* index 119  */
279 { 6,  1,  0,  128,  0,  1,  2,  6 }, /* index 120  */
280 { 6,  2,  1,  512,  0,  1,  2,  6 }, /* index 121  */
281 { 6,  1,  0,  512,  0,  2,  2,  6 }, /* index 122  */
282 { 6,  1,  0,  512,  7,  1,  1,  6 }, /* index 123  */
283 { 6,  1,  0,  512,  0,  1,  2,  6 }, /* index 124  */
284 { 6,  1,  0,  132,  0,  1,  2,  6 }, /* index 125  */
285 { 6,  1,  0,  768,  0,  2,  2,  6 }, /* index 126  */
286 { 6,  1,  0,  528,  0,  1,  2,  6 }, /* index 127  */
287 { 6,  1,  0,  640,  7,  1,  1,  6 }, /* index 128  */
288 { 6,  1,  0,  792,  0,  1,  2,  6 }, /* index 129  */
289 { 6,  1,  0,  792,  0,  2,  2,  6 }, /* index 130  */
290 { 6,  1,  0,  682,  0,  1,  2,  6 }, /* index 131  */
291 { 6,  1,  0, 1023,  7,  1,  1,  6 }, /* index 132  */
292 { 7,  4,  1,  512,  2,  1,  6,  2 }, /* index 133  */
293 { 7,  2,  1,  512,  2,  1,  6,  2 }, /* index 134  */
294 { 7,  2,  1,  640,  2,  1,  6,  2 }, /* index 135  */
295 { 7,  2,  1,  528,  8,  1,  3,  2 }, /* index 136  */
296 { 7,  2,  1,  528,  2,  2,  6,  2 }, /* index 137  */
297 { 7,  1,  0,  512,  2,  2,  6,  2 }, /* index 138  */
298 { 7,  1,  0,  512,  8,  1,  3,  2 }, /* index 139  */
299 { 7,  1,  0,  512,  2,  1,  6,  2 }, /* index 140  */
300 { 7,  1,  0,  768,  2,  2,  6,  2 }, /* index 141  */
301 { 7,  1,  0,  528,  2,  1,  6,  2 }, /* index 142  */
302 { 7,  1,  0,  640,  8,  1,  3,  2 }, /* index 143  */
303 { 7,  1,  0,  682,  2,  1,  6,  2 }, /* index 144  */
304 { 8, 16,  1,  512,  0,  2,  1, 12 }, /* index 145  */
305 { 8,  8,  1,  512,  0,  2,  1, 12 }, /* index 146  */
306 { 8,  4,  1,  512,  2,  1,  1, 12 }, /* index 147  */
307 { 8,  2,  1,  512,  0,  1,  1, 12 }, /* index 148  */
308 { 8,  2,  1,  512,  2,  1,  1, 12 }, /* index 149  */
309 { 8,  2,  1,  640,  2,  1,  1, 12 }, /* index 150  */
310 { 8,  2,  1,  528,  2,  1,  1, 12 }, /* index 151  */
311 { 8,  2,  1,  528,  0,  2,  1, 12 }, /* index 152  */
312 { 8,  2,  1,  768,  0,  2,  1, 12 }, /* index 153  */
313 { 8,  2,  1,  924,  0,  1,  1, 12 }, /* index 154  */
314 { 8,  1,  0,    2,  0,  1,  1, 12 }, /* index 155  */
315 { 8,  1,  0,    4,  0,  1,  1, 12 }, /* index 156  */
316 { 8,  1,  0,   16,  0,  1,  1, 12 }, /* index 157  */
317 { 8,  1,  0,  128,  0,  1,  1, 12 }, /* index 158  */
318 { 8,  1,  0,  512,  0,  1,  1, 12 }, /* index 159  */
319 { 8,  1,  0,  512,  2,  1,  1, 12 }, /* index 160  */
320 { 8,  1,  0,  512,  0,  2,  1, 12 }, /* index 161  */
321 { 8,  1,  0,  528,  2,  1,  1, 12 }, /* index 162  */
322 { 8,  1,  0,  640,  2,  1,  1, 12 }, /* index 163  */
323 { 8,  1,  0,  768,  0,  2,  1, 12 }, /* index 164  */
324 { 8,  1,  0,  792,  2,  1,  1, 12 }, /* index 165  */
325 { 8,  1,  0,  682,  2,  1,  1, 12 }, /* index 166  */
326 { 8,  1,  0, 1023,  0,  2,  1, 12 }, /* index 167  */
327 { 8,  1,  0, 1023,  2,  1,  1, 12 }, /* index 168  */
328 { 9, 16,  1,  512,  2,  2,  6,  2 }, /* index 169  */
329 { 9,  8,  1,  512,  2,  2,  6,  2 }, /* index 170  */
330 { 9,  4,  1,  512,  2,  1,  6,  2 }, /* index 171  */
331 { 9,  2,  1,  512,  2,  1,  6,  2 }, /* index 172  */
332 { 9,  2,  1,  768,  2,  2,  6,  2 }, /* index 173  */
333 { 9,  2,  1,  640,  2,  1,  6,  2 }, /* index 174  */
334 { 9,  2,  1,  640,  8,  1,  3,  2 }, /* index 175  */
335 { 9,  2,  1,  528,  8,  1,  3,  2 }, /* index 176  */
336 { 9,  2,  1,  528,  2,  2,  6,  2 }, /* index 177  */
337 { 9,  2,  1,  924,  2,  1,  6,  2 }, /* index 178  */
338 { 9,  1,  0,  512,  2,  2,  6,  2 }, /* index 179  */
339 { 9,  1,  0,  512,  8,  1,  3,  2 }, /* index 180  */
340 { 9,  1,  0,  512,  2,  1,  6,  2 }, /* index 181  */
341 { 9,  1,  0,  768,  2,  2,  6,  2 }, /* index 182  */
342 { 9,  1,  0,  528,  2,  1,  6,  2 }, /* index 183  */
343 { 9,  1,  0,  640,  8,  1,  3,  2 }, /* index 184  */
344 { 9,  1,  0,  792,  2,  1,  6,  2 }, /* index 185  */
345 { 9,  1,  0,  792,  2,  2,  6,  2 }, /* index 186  */
346 { 9,  1,  0,  682,  2,  1,  6,  2 }, /* index 187  */
347 { 9,  1,  0, 1023,  8,  1,  3,  2 }, /* index 188  */
348 {10, 16,  1,  512,  2,  2,  2,  6 }, /* index 189  */
349 {10,  8,  1,  512,  2,  2,  2,  6 }, /* index 190  */
350 {10,  4,  1,  512,  2,  1,  2,  6 }, /* index 191  */
351 {10,  2,  1,  512,  2,  1,  2,  6 }, /* index 192  */
352 {10,  2,  1,  768,  2,  2,  2,  6 }, /* index 193  */
353 {10,  2,  1,  640,  2,  1,  2,  6 }, /* index 194  */
354 {10,  2,  1,  640,  8,  1,  1,  6 }, /* index 195  */
355 {10,  2,  1,  528,  8,  1,  1,  6 }, /* index 196  */
356 {10,  2,  1,  528,  2,  2,  2,  6 }, /* index 197  */
357 {10,  2,  1,  924,  2,  1,  2,  6 }, /* index 198  */
358 {10,  8,  1,  512,  8,  2,  1,  6 }, /* index 199  */
359 {10,  4,  1,  512,  8,  1,  1,  6 }, /* index 200  */
360 {10,  1,  0,  512,  2,  2,  2,  6 }, /* index 201  */
361 {10,  1,  0,  512,  8,  1,  1,  6 }, /* index 202  */
362 {10,  1,  0,  512,  2,  1,  2,  6 }, /* index 203  */
363 {10,  1,  0,  768,  2,  2,  2,  6 }, /* index 204  */
364 {10,  1,  0,  528,  2,  1,  2,  6 }, /* index 205  */
365 {10,  1,  0,  640,  8,  1,  1,  6 }, /* index 206  */
366 {10,  1,  0,  792,  2,  1,  2,  6 }, /* index 207  */
367 {10,  1,  0,  792,  2,  2,  2,  6 }, /* index 208  */
368 {10,  1,  0,  682,  2,  1,  2,  6 }, /* index 209  */
369 {10,  1,  0, 1023,  8,  1,  1,  6 }, /* index 210  */
370 {11,  2,  1,  512,  2,  1,  6,  2 }, /* index 211  */
371 {11,  2,  1,  528,  8,  1,  3,  2 }, /* index 212  */
372 {11,  2,  1,  640,  8,  1,  3,  2 }, /* index 213  */
373 {11,  2,  1,  640,  2,  1,  6,  2 }, /* index 214  */
374 {11,  2,  1,  528,  2,  2,  6,  2 }, /* index 215  */
375 {11,  2,  1,  768,  2,  2,  6,  2 }, /* index 216  */
376 {11,  1,  0,  512,  2,  2,  6,  2 }, /* index 217  */
377 {11,  1,  0,  512,  8,  1,  3,  2 }, /* index 218  */
378 {11,  1,  0,  512,  2,  1,  6,  2 }, /* index 219  */
379 {11,  1,  0,  768,  2,  2,  6,  2 }, /* index 220  */
380 {11,  1,  0,  528,  2,  1,  6,  2 }, /* index 221  */
381 {11,  1,  0,  640,  8,  1,  3,  2 }, /* index 222  */
382 {11,  1,  0,  792,  2,  2,  6,  2 }, /* index 223  */
383 {11,  1,  0,  682,  2,  1,  6,  2 }, /* index 224  */
384 {11,  1,  0, 1023,  8,  1,  3,  2 }, /* index 225  */
385 {12,  2,  1,  512,  0,  1,  3,  4 }, /* index 226  */
386 {12,  2,  1,  528,  6,  1,  2,  4 }, /* index 227  */
387 {12,  2,  1,  640,  6,  1,  2,  4 }, /* index 228  */
388 {12,  2,  1,  528,  0,  2,  3,  4 }, /* index 229  */
389 {12,  2,  1,  768,  0,  2,  3,  4 }, /* index 230  */
390 {12,  1,  0,  512,  0,  2,  3,  4 }, /* index 231  */
391 {12,  1,  0,  512,  6,  1,  2,  4 }, /* index 232  */
392 {12,  1,  0,  512,  0,  1,  3,  4 }, /* index 233  */
393 {12,  1,  0,  768,  0,  2,  3,  4 }, /* index 234  */
394 {12,  1,  0,  528,  0,  1,  3,  4 }, /* index 235  */
395 {12,  1,  0,  640,  6,  1,  2,  4 }, /* index 236  */
396 {12,  1,  0,  792,  0,  1,  3,  4 }, /* index 237  */
397 {12,  1,  0,  792,  0,  2,  3,  4 }, /* index 238  */
398 {12,  1,  0,  682,  0,  1,  3,  4 }, /* index 239  */
399 {12,  1,  0, 1023,  6,  1,  2,  4 }, /* index 240  */
400 {13,  2,  1,  512,  0,  1,  2,  6 }, /* index 241  */
401 {13,  2,  1,  528,  2,  1,  2,  6 }, /* index 242  */
402 {13,  2,  1,  640,  0,  1,  2,  6 }, /* index 243  */
403 {13,  2,  1,  640,  2,  1,  2,  6 }, /* index 244  */
404 {13,  2,  1,  528,  0,  2,  2,  6 }, /* index 245  */
405 {13,  2,  1,  768,  0,  2,  2,  6 }, /* index 246  */
406 {13,  1,  0,  512,  0,  2,  2,  6 }, /* index 247  */
407 {13,  1,  0,  512,  2,  1,  2,  6 }, /* index 248  */
408 {13,  1,  0,  512,  0,  1,  2,  6 }, /* index 249  */
409 {13,  1,  0,  768,  0,  2,  2,  6 }, /* index 250  */
410 {13,  1,  0,  528,  0,  1,  2,  6 }, /* index 251  */
411 {13,  1,  0,  640,  2,  1,  2,  6 }, /* index 252  */
412 {13,  1,  0,  792,  0,  2,  2,  6 }, /* index 253  */
413 {13,  1,  0,  682,  0,  1,  2,  6 }, /* index 254  */
414 {13,  1,  0, 1023,  2,  1,  2,  6 }  /* index 255  */
415 };
416
417 #else
418 /* prach config index Table 6.3.3.2-2 spec 38.211 
419  * PRACH format given as follows:
420  * 0 = 0
421  * 1 = 1
422  * 2 = 2
423  * 3 = 3
424  * 4 = A1
425  * 5 = A2
426  * 6 = A3
427  * 7 = B1
428  * 8 = B4
429  * 9 = C0
430  * 10 = C2
431  * 11 = A1/B1
432  * 12 = A2/B2
433  * 13 = A3/B3 
434  * Subframe num is represented considering 0-9 bits and
435  * value 1 corresponds to the subframe that is valid 
436  */
437
438 uint16_t prachCfgIdxTable[MAX_PRACH_CONFIG_IDX][8] = {
439 { 0, 16,  1,    2,  0,  0,  0,  0 }, /* index 0   */
440 { 0, 16,  1,   16,  0,  0,  0,  0 }, /* index 1   */
441 { 0, 16,  1,  128,  0,  0,  0,  0 }, /* index 2   */
442 { 0, 16,  1,  512,  0,  0,  0,  0 }, /* index 3   */
443 { 0,  8,  1,    2,  0,  0,  0,  0 }, /* index 4   */
444 { 0,  8,  1,   16,  0,  0,  0,  0 }, /* index 5   */
445 { 0,  8,  1,  128,  0,  0,  0,  0 }, /* index 6   */
446 { 0,  8,  1,  512,  0,  0,  0,  0 }, /* index 7   */
447 { 0,  4,  1,    2,  0,  0,  0,  0 }, /* index 8   */
448 { 0,  4,  1,   16,  0,  0,  0,  0 }, /* index 9   */
449 { 0,  4,  1,  128,  0,  0,  0,  0 }, /* index 10  */
450 { 0,  4,  1,  512,  0,  0,  0,  0 }, /* index 11  */
451 { 0,  2,  1,    2,  0,  0,  0,  0 }, /* index 12  */
452 { 0,  2,  1,   16,  0,  0,  0,  0 }, /* index 13  */
453 { 0,  2,  1,  128,  0,  0,  0,  0 }, /* index 14  */
454 { 0,  2,  1,  512,  0,  0,  0,  0 }, /* index 15  */
455 { 0,  1,  0,    2,  0,  0,  0,  0 }, /* index 16  */
456 { 0,  1,  0,   16,  0,  0,  0,  0 }, /* index 17  */
457 { 0,  1,  0,  128,  0,  0,  0,  0 }, /* index 18  */
458 { 0,  1,  0,   66,  0,  0,  0,  0 }, /* index 19  */
459 { 0,  1,  0,  132,  0,  0,  0,  0 }, /* index 20  */
460 { 0,  1,  0,  264,  0,  0,  0,  0 }, /* index 21  */
461 { 0,  1,  0,  146,  0,  0,  0,  0 }, /* index 22  */
462 { 0,  1,  0,  292,  0,  0,  0,  0 }, /* index 23  */
463 { 0,  1,  0,  584,  0,  0,  0,  0 }, /* index 24  */
464 { 0,  1,  0,  341,  0,  0,  0,  0 }, /* index 25  */
465 { 0,  1,  0,  682,  0,  0,  0,  0 }, /* index 26  */
466 { 0,  1,  0, 1023,  0,  0,  0,  0 }, /* index 27  */
467 { 1, 16,  1,    2,  0,  0,  0,  0 }, /* index 28  */
468 { 1, 16,  1,   16,  0,  0,  0,  0 }, /* index 29  */
469 { 1, 16,  1,  128,  0,  0,  0,  0 }, /* index 30  */
470 { 1, 16,  1,  512,  0,  0,  0,  0 }, /* index 31  */
471 { 1,  8,  1,    2,  0,  0,  0,  0 }, /* index 32  */
472 { 1,  8,  1,   16,  0,  0,  0,  0 }, /* index 33  */
473 { 1,  8,  1,  128,  0,  0,  0,  0 }, /* index 34  */
474 { 1,  8,  1,  512,  0,  0,  0,  0 }, /* index 35  */
475 { 1,  4,  1,    2,  0,  0,  0,  0 }, /* index 36  */
476 { 1,  4,  1,   16,  0,  0,  0,  0 }, /* index 37  */
477 { 1,  4,  1,  128,  0,  0,  0,  0 }, /* index 38  */
478 { 1,  4,  1,  512,  0,  0,  0,  0 }, /* index 39  */
479 { 1,  2,  1,    2,  0,  0,  0,  0 }, /* index 40  */
480 { 1,  2,  1,   16,  0,  0,  0,  0 }, /* index 41  */
481 { 1,  2,  1,  128,  0,  0,  0,  0 }, /* index 42  */
482 { 1,  2,  1,  512,  0,  0,  0,  0 }, /* index 43  */
483 { 1,  1,  0,    2,  0,  0,  0,  0 }, /* index 44  */
484 { 1,  1,  0,   16,  0,  0,  0,  0 }, /* index 45  */
485 { 1,  1,  0,  128,  0,  0,  0,  0 }, /* index 46  */
486 { 1,  1,  0,   64,  0,  0,  0,  0 }, /* index 47  */
487 { 1,  1,  0,  132,  0,  0,  0,  0 }, /* index 48  */
488 { 1,  1,  0,  264,  0,  0,  0,  0 }, /* index 49  */
489 { 1,  1,  0,  146,  0,  0,  0,  0 }, /* index 50  */
490 { 1,  1,  0,  292,  0,  0,  0,  0 }, /* index 51  */
491 { 1,  1,  0,  584,  0,  0,  0,  0 }, /* index 52  */
492 { 2, 16,  1,    2,  0,  0,  0,  0 }, /* index 53  */
493 { 2,  8,  1,    2,  0,  0,  0,  0 }, /* index 54  */
494 { 2,  4,  0,    2,  0,  0,  0,  0 }, /* index 55  */
495 { 2,  2,  0,    2,  0,  0,  0,  0 }, /* index 56  */
496 { 2,  2,  0,   32,  0,  0,  0,  0 }, /* index 57  */
497 { 2,  1,  0,    2,  0,  0,  0,  0 }, /* index 58  */
498 { 2,  1,  0,   32,  0,  0,  0,  0 }, /* index 59  */
499 { 3, 16,  1,    2,  0,  0,  0,  0 }, /* index 60  */
500 { 3, 16,  1,   16,  0,  0,  0,  0 }, /* index 61  */
501 { 3, 16,  1,  128,  0,  0,  0,  0 }, /* index 62  */
502 { 3, 16,  1,  512,  0,  0,  0,  0 }, /* index 63  */
503 { 3,  8,  1,    2,  0,  0,  0,  0 }, /* index 64  */
504 { 3,  8,  1,   16,  0,  0,  0,  0 }, /* index 65  */
505 { 3,  8,  1,  128,  0,  0,  0,  0 }, /* index 66  */
506 { 3,  4,  1,    2,  0,  0,  0,  0 }, /* index 67  */
507 { 3,  4,  1,   16,  0,  0,  0,  0 }, /* index 68  */
508 { 3,  4,  1,  128,  0,  0,  0,  0 }, /* index 69  */
509 { 3,  4,  1,  512,  0,  0,  0,  0 }, /* index 70  */
510 { 3,  2,  1,    2,  0,  0,  0,  0 }, /* index 71  */
511 { 3,  2,  1,   16,  0,  0,  0,  0 }, /* index 72  */
512 { 3,  2,  1,  128,  0,  0,  0,  0 }, /* index 73  */
513 { 3,  2,  1,  512,  0,  0,  0,  0 }, /* index 74  */
514 { 3,  1,  0,    2,  0,  0,  0,  0 }, /* index 75  */
515 { 3,  1,  0,   16,  0,  0,  0,  0 }, /* index 76  */
516 { 3,  1,  0,  128,  0,  0,  0,  0 }, /* index 77  */
517 { 3,  1,  0,   66,  0,  0,  0,  0 }, /* index 78  */
518 { 3,  1,  0,  132,  0,  0,  0,  0 }, /* index 79  */
519 { 3,  1,  0,  264,  0,  0,  0,  0 }, /* index 80  */
520 { 3,  1,  0,  146,  0,  0,  0,  0 }, /* index 81  */
521 { 3,  1,  0,  292,  0,  0,  0,  0 }, /* index 82  */
522 { 3,  1,  0,  584,  0,  0,  0,  0 }, /* index 83  */
523 { 3,  1,  0,  341,  0,  0,  0,  0 }, /* index 84  */
524 { 3,  1,  0,  682,  0,  0,  0,  0 }, /* index 85  */
525 { 3,  1,  0, 1023,  0,  0,  0,  0 }, /* index 86  */
526 { 4, 16,  0,  528,  0,  1,  6,  2 }, /* index 87  */
527 { 4, 16,  1,   16,  0,  2,  6,  2 }, /* index 88  */
528 { 4,  8,  0,  528,  0,  1,  6,  2 }, /* index 89  */
529 { 4,  8,  1,   16,  0,  2,  6,  2 }, /* index 90  */
530 { 4,  4,  0,  528,  0,  1,  6,  2 }, /* index 91  */
531 { 4,  4,  1,  528,  0,  1,  6,  2 }, /* index 92  */
532 { 4,  4,  0,   16,  0,  2,  6,  2 }, /* index 93  */
533 { 4,  2,  0,  528,  0,  1,  6,  2 }, /* index 94  */
534 { 4,  2,  0,    2,  0,  2,  6,  2 }, /* index 95  */
535 { 4,  2,  0,   16,  0,  2,  6,  2 }, /* index 96  */
536 { 4,  2,  0,  128,  0,  2,  6,  2 }, /* index 97  */
537 { 4,  1,  0,   16,  0,  1,  6,  2 }, /* index 98  */
538 { 4,  1,  0,   66,  0,  1,  6,  2 }, /* index 99  */
539 { 4,  1,  0,  528,  0,  1,  6,  2 }, /* index 100  */
540 { 4,  1,  0,    2,  0,  2,  6,  2 }, /* index 101  */
541 { 4,  1,  0,  128,  0,  2,  6,  2 }, /* index 102  */
542 { 4,  1,  0,  132,  0,  2,  6,  2 }, /* index 103  */
543 { 4,  1,  0,  146,  0,  2,  6,  2 }, /* index 104  */
544 { 4,  1,  0,  341,  0,  2,  6,  2 }, /* index 105  */
545 { 4,  1,  0, 1023,  0,  2,  6,  2 }, /* index 106  */
546 { 4,  1,  0,  682,  0,  2,  6,  2 }, /* index 107  */
547 {11,  2,  0,  528,  0,  1,  7,  2 }, /* index 108  */
548 {11,  2,  0,   16,  0,  2,  7,  2 }, /* index 109  */
549 {11,  1,  0,   16,  0,  1,  7,  2 }, /* index 110  */
550 {11,  1,  0,   66,  0,  1,  7,  2 }, /* index 111  */
551 {11,  1,  0,  528,  0,  1,  7,  2 }, /* index 112  */
552 {11,  1,  0,    2,  0,  2,  7,  2 }, /* index 113  */
553 {11,  1,  0,  128,  0,  2,  7,  2 }, /* index 114  */
554 {11,  1,  0,  146,  0,  2,  7,  2 }, /* index 115  */
555 {11,  1,  0,  341,  0,  2,  7,  2 }, /* index 116  */
556 { 5, 16,  1,  580,  0,  1,  3,  4 }, /* index 117  */
557 { 5, 16,  1,   16,  0,  2,  3,  4 }, /* index 118  */
558 { 5,  8,  1,  580,  0,  1,  3,  4 }, /* index 119  */
559 { 5,  8,  1,   16,  0,  2,  3,  4 }, /* index 120  */
560 { 5,  4,  0,  580,  0,  1,  3,  4 }, /* index 121  */
561 { 5,  4,  0,   16,  0,  2,  3,  4 }, /* index 122  */
562 { 5,  2,  1,  580,  0,  1,  3,  4 }, /* index 123  */
563 { 5,  2,  0,    2,  0,  2,  3,  4 }, /* index 124  */
564 { 5,  2,  0,   16,  0,  2,  3,  4 }, /* index 125  */
565 { 5,  2,  0,  128,  0,  2,  3,  4 }, /* index 126  */
566 { 5,  1,  0,   16,  0,  1,  3,  4 }, /* index 127  */
567 { 5,  1,  0,   66,  0,  1,  3,  4 }, /* index 128  */
568 { 5,  1,  0,  528,  0,  1,  3,  4 }, /* index 129  */
569 { 5,  1,  0,    2,  0,  2,  3,  4 }, /* index 130  */
570 { 5,  1,  0,  128,  0,  2,  3,  4 }, /* index 131  */
571 { 5,  1,  0,  132,  0,  2,  3,  4 }, /* index 132  */
572 { 5,  1,  0,  146,  0,  2,  3,  4 }, /* index 133  */
573 { 5,  1,  0,  341,  0,  2,  3,  4 }, /* index 134  */
574 { 5,  1,  0, 1023,  0,  2,  3,  4 }, /* index 135  */
575 { 5,  1,  0,  682,  0,  2,  3,  4 }, /* index 136  */
576 {12,  2,  1,  580,  0,  1,  3,  4 }, /* index 137  */
577 {12,  2,  0,   16,  0,  2,  3,  4 }, /* index 138  */
578 {12,  1,  0,   16,  0,  1,  3,  4 }, /* index 139  */
579 {12,  1,  0,   66,  0,  1,  3,  4 }, /* index 140  */
580 {12,  1,  0,  528,  0,  1,  3,  4 }, /* index 141  */
581 {12,  1,  0,    2,  0,  2,  3,  4 }, /* index 142  */
582 {12,  1,  0,  128,  0,  2,  3,  4 }, /* index 143  */
583 {12,  1,  0,  146,  0,  2,  3,  4 }, /* index 144  */
584 {12,  1,  0,  341,  0,  2,  3,  4 }, /* index 145  */
585 {12,  1,  0, 1023,  0,  2,  3,  4 }, /* index 146  */
586 { 6, 16,  1,  528,  0,  1,  2,  6 }, /* index 147  */
587 { 6, 16,  1,   16,  0,  2,  2,  6 }, /* index 148  */
588 { 6,  8,  1,  528,  0,  1,  2,  6 }, /* index 149  */
589 { 6,  8,  1,   16,  0,  2,  2,  6 }, /* index 150  */
590 { 6,  4,  0,  528,  0,  1,  2,  6 }, /* index 151  */
591 { 6,  4,  0,   16,  0,  2,  2,  6 }, /* index 152  */
592 { 6,  2,  1,  580,  0,  2,  2,  6 }, /* index 153  */
593 { 6,  2,  0,    2,  0,  2,  2,  6 }, /* index 154  */
594 { 6,  2,  0,   16,  0,  2,  2,  6 }, /* index 155  */
595 { 6,  2,  0,  128,  0,  2,  2,  6 }, /* index 156  */
596 { 6,  1,  0,   16,  0,  1,  2,  6 }, /* index 157  */
597 { 6,  1,  0,   66,  0,  1,  2,  6 }, /* index 158  */
598 { 6,  1,  0,  528,  0,  1,  2,  6 }, /* index 159  */
599 { 6,  1,  0,    2,  0,  2,  2,  6 }, /* index 160  */
600 { 6,  1,  0,  128,  0,  2,  2,  6 }, /* index 161  */
601 { 6,  1,  0,  132,  0,  2,  2,  6 }, /* index 162  */
602 { 6,  1,  0,  146,  0,  2,  2,  6 }, /* index 163  */
603 { 6,  1,  0,  341,  0,  2,  2,  6 }, /* index 164  */
604 { 6,  1,  0, 1023,  0,  2,  2,  6 }, /* index 165  */
605 { 6,  1,  0,  682,  0,  2,  2,  6 }, /* index 166  */
606 {13,  2,  1,  580,  0,  2,  2,  6 }, /* index 167  */
607 {13,  2,  0,   16,  0,  2,  2,  6 }, /* index 168  */
608 {13,  1,  0,   16,  0,  1,  2,  6 }, /* index 169  */
609 {13,  1,  0,   66,  0,  1,  2,  6 }, /* index 170  */
610 {13,  1,  0,  528,  0,  1,  2,  6 }, /* index 171  */
611 {13,  1,  0,    2,  0,  2,  2,  6 }, /* index 172  */
612 {13,  1,  0,  128,  0,  2,  2,  6 }, /* index 173  */
613 {13,  1,  0,  146,  0,  2,  2,  6 }, /* index 174  */
614 {13,  1,  0,  341,  0,  2,  2,  6 }, /* index 175  */
615 {13,  1,  0, 1023,  0,  2,  2,  6 }, /* index 176  */
616 { 7, 16,  0,  528,  0,  1,  7,  2 }, /* index 177  */
617 { 7, 16,  1,   16,  0,  2,  7,  2 }, /* index 178  */
618 { 7,  8,  0,  528,  0,  1,  7,  2 }, /* index 179  */
619 { 7,  8,  1,   16,  0,  2,  7,  2 }, /* index 180  */
620 { 7,  4,  0,  528,  0,  1,  7,  2 }, /* index 181  */
621 { 7,  4,  1,  528,  0,  1,  7,  2 }, /* index 182  */
622 { 7,  4,  0,   16,  0,  2,  7,  2 }, /* index 183  */
623 { 7,  2,  0,  528,  0,  1,  7,  2 }, /* index 184  */
624 { 7,  2,  0,    2,  0,  2,  7,  2 }, /* index 185  */
625 { 7,  2,  0,   16,  0,  2,  7,  2 }, /* index 186  */
626 { 7,  2,  0,  128,  0,  2,  7,  2 }, /* index 187  */
627 { 7,  1,  0,   16,  0,  1,  7,  2 }, /* index 188  */
628 { 7,  1,  0,   66,  0,  1,  7,  2 }, /* index 189  */
629 { 7,  1,  0,  528,  0,  1,  7,  2 }, /* index 190  */
630 { 7,  1,  0,    2,  0,  2,  7,  2 }, /* index 191  */
631 { 7,  1,  0,  128,  0,  2,  7,  2 }, /* index 192  */
632 { 7,  1,  0,  132,  0,  2,  7,  2 }, /* index 193  */
633 { 7,  1,  0,  146,  0,  2,  7,  2 }, /* index 194  */
634 { 7,  1,  0,  341,  0,  2,  7,  2 }, /* index 195  */
635 { 7,  1,  0, 1023,  0,  2,  7,  2 }, /* index 196  */
636 { 7,  1,  0,  682,  0,  2,  7,  2 }, /* index 197  */
637 { 8, 16,  0,  528,  0,  2,  1, 12 }, /* index 198  */
638 { 8, 16,  1,   16,  0,  2,  1, 12 }, /* index 199  */
639 { 8,  8,  0,  528,  0,  2,  1, 12 }, /* index 200  */
640 { 8,  8,  1,   16,  0,  2,  1, 12 }, /* index 201  */
641 { 8,  4,  0,  528,  0,  2,  1, 12 }, /* index 202  */
642 { 8,  4,  0,   16,  0,  2,  1, 12 }, /* index 203  */
643 { 8,  4,  1,  528,  0,  2,  1, 12 }, /* index 204  */
644 { 8,  2,  0,  528,  0,  2,  1, 12 }, /* index 205  */
645 { 8,  2,  0,    2,  0,  2,  1, 12 }, /* index 206  */
646 { 8,  2,  0,   16,  0,  2,  1, 12 }, /* index 207  */
647 { 8,  2,  0,  128,  0,  2,  1, 12 }, /* index 208  */
648 { 8,  1,  0,    2,  0,  2,  1, 12 }, /* index 209  */
649 { 8,  1,  0,   16,  0,  2,  1, 12 }, /* index 210  */
650 { 8,  1,  0,  128,  0,  2,  1, 12 }, /* index 211  */
651 { 8,  1,  0,   66,  0,  2,  1, 12 }, /* index 212  */
652 { 8,  1,  0,  132,  0,  2,  1, 12 }, /* index 213  */
653 { 8,  1,  0,  528,  0,  2,  1, 12 }, /* index 214  */
654 { 8,  1,  0,  146,  0,  2,  1, 12 }, /* index 215  */
655 { 8,  1,  0,  341,  0,  2,  1, 12 }, /* index 216  */
656 { 8,  1,  0, 1023,  0,  2,  1, 12 }, /* index 217  */
657 { 8,  1,  0,  682,  0,  2,  1, 12 }, /* index 218  */
658 { 9,  8,  1,   16,  0,  2,  7,  2 }, /* index 219  */
659 { 9,  4,  1,  528,  0,  1,  7,  2 }, /* index 220  */
660 { 9,  4,  0,   16,  0,  2,  7,  2 }, /* index 221  */
661 { 9,  2,  0,  528,  0,  1,  7,  2 }, /* index 222  */
662 { 9,  2,  0,    2,  0,  2,  7,  2 }, /* index 223  */
663 { 9,  2,  0,   16,  0,  2,  7,  2 }, /* index 224  */
664 { 9,  2,  0,  128,  0,  2,  7,  2 }, /* index 225  */
665 { 9,  1,  0,   16,  0,  1,  7,  2 }, /* index 226  */
666 { 9,  1,  0,   66,  0,  1,  7,  2 }, /* index 227  */
667 { 9,  1,  0,  528,  0,  1,  7,  2 }, /* index 228  */
668 { 9,  1,  0,    2,  0,  2,  7,  2 }, /* index 229  */
669 { 9,  1,  0,  128,  0,  2,  7,  2 }, /* index 230  */
670 { 9,  1,  0,  132,  0,  2,  7,  2 }, /* index 231  */
671 { 9,  1,  0,  146,  0,  2,  7,  2 }, /* index 232  */
672 { 9,  1,  0,  341,  0,  2,  7,  2 }, /* index 233  */
673 { 9,  1,  0, 1023,  0,  2,  7,  2 }, /* index 234  */
674 { 9,  1,  0,  682,  0,  2,  7,  2 }, /* index 235  */
675 {10, 16,  1,  528,  0,  1,  2,  6 }, /* index 236  */
676 {10, 16,  1,   16,  0,  2,  2,  6 }, /* index 237  */
677 {10,  8,  1,  528,  0,  1,  2,  6 }, /* index 238  */
678 {10,  8,  1,   16,  0,  2,  2,  6 }, /* index 239  */
679 {10,  4,  0,  528,  0,  1,  2,  6 }, /* index 240  */
680 {10,  4,  0,   16,  0,  2,  2,  6 }, /* index 241  */
681 {10,  2,  1,  580,  0,  2,  2,  6 }, /* index 242  */
682 {10,  2,  0,    2,  0,  2,  2,  6 }, /* index 243  */
683 {10,  2,  0,   16,  0,  2,  2,  6 }, /* index 244  */
684 {10,  2,  0,  128,  0,  2,  2,  6 }, /* index 245  */
685 {10,  1,  0,   16,  0,  1,  2,  6 }, /* index 246  */
686 {10,  1,  0,   66,  0,  1,  2,  6 }, /* index 247  */
687 {10,  1,  0,  528,  0,  1,  2,  6 }, /* index 248  */
688 {10,  1,  0,    2,  0,  2,  2,  6 }, /* index 249  */
689 {10,  1,  0,  128,  0,  2,  2,  6 }, /* index 250  */
690 {10,  1,  0,  132,  0,  2,  2,  6 }, /* index 251  */
691 {10,  1,  0,  146,  0,  2,  2,  6 }, /* index 252  */
692 {10,  1,  0,  341,  0,  2,  2,  6 }, /* index 253  */
693 {10,  1,  0, 1023,  0,  2,  2,  6 }, /* index 254  */
694 {10,  1,  0,  682,  0,  2,  2,  6 }  /* index 255  */
695 };
696 #endif
697
698 /* Defintion of delta value Table 6.1.2.1.1-5 spec 38.214 */
699 uint8_t puschDeltaTable[MAX_MU_PUSCH] = { 2, 3, 4, 6 };
700
701 uint16_t tbSizeTable[TOTAL_TBSIZE_VALUES] = {
702          24,    32,    40,    48,    56,    64,    72,    80,    88,    96, \
703         104,   112,   120,   128,   136,   144,   152,   160,   168,   176, \
704         184,   192,   208,   224,   240,   256,   272,   288,   304,   320, \
705         336,   352,   368,   384,   408,   432,   456,   480,   504,   528, \
706         552,   576,   608,   640,   672,   704,   736,   768,   808,   848, \
707         888,   928,   984,  1032,  1064,  1128,  1160,  1192,  1224,  1256, \
708        1288,  1320,  1352,  1416,  1480,  1544,  1608,  1672,  1736,  1800, \
709        1864,  1928,  2024,  2088,  2152,  2216,  2280,  2408,  2472,  2536, \
710        2600,  2664,  2728,  2792,  2856,  2976,  3104,  3240,  3368,  3496, \
711        3624,  3752,  3824 };
712
713 uint16_t mcsTable[32][3] = {
714       {   0,   2,   120},   /* mcs index  0 */ 
715       {   1,   2,   157},   /* mcs index  1 */ 
716       {   2,   2,   193},   /* mcs index  2 */ 
717       {   3,   2,   251},   /* mcs index  3 */ 
718       {   4,   2,   308},   /* mcs index  4 */ 
719       {   5,   2,   379},   /* mcs index  5 */ 
720       {   6,   2,   449},   /* mcs index  6 */ 
721       {   7,   2,   526},   /* mcs index  7 */ 
722       {   8,   2,   602},   /* mcs index  8 */ 
723       {   9,   2,   679},   /* mcs index  9 */ 
724       {  10,   4,   340},   /* mcs index 10 */ 
725       {  11,   4,   378},   /* mcs index 11 */ 
726       {  12,   4,   434},   /* mcs index 12 */ 
727       {  13,   4,   490},   /* mcs index 13 */ 
728       {  14,   4,   553},   /* mcs index 14 */ 
729       {  15,   4,   616},   /* mcs index 15 */
730       {  16,   4,   658},   /* mcs index 16 */
731       {  17,   6,   438},   /* mcs index 17 */
732       {  18,   6,   466},   /* mcs index 18 */
733       {  19,   6,   517},   /* mcs index 19 */
734       {  20,   6,   567},   /* mcs index 20 */
735       {  21,   6,   616},   /* mcs index 21 */
736       {  22,   6,   666},   /* mcs index 22 */
737       {  23,   6,   719},   /* mcs index 23 */
738       {  24,   6,   772},   /* mcs index 24 */
739       {  25,   6,   822},   /* mcs index 25 */
740       {  26,   6,   873},   /* mcs index 26 */
741       {  27,   6,   910},   /* mcs index 27 */
742       {  28,   6,   948},   /* mcs index 28 */
743       {  29,   2,     0},   /* mcs index 29 */
744       {  30,   4,     0},   /* mcs index 30 */
745       {  31,   6,     0}};  /* mcs index 31 */
746
747 /* PUCCH resource sets before dedicated PUCCH resource configuration */
748 /* Table 9.2.1-1 spec 38.213      */ 
749 uint8_t pucchResourceSet[MAX_PUCCH_RES_SET_IDX][4] = {
750 { 0,  12,  2,  0 }, /* index  0 */
751 { 0,  12,  2,  0 }, /* index  1 */
752 { 0,  12,  2,  3 }, /* index  2 */
753 { 1,  10,  4,  0 }, /* index  3 */
754 { 1,  10,  4,  0 }, /* index  4 */
755 { 1,  10,  4,  2 }, /* index  5 */
756 { 1,  10,  4,  4 }, /* index  6 */
757 { 1,   4, 10,  0 }, /* index  7 */
758 { 1,   4, 10,  0 }, /* index  8 */
759 { 1,   4, 10,  2 }, /* index  9 */
760 { 1,   4, 10,  4 }, /* index 10 */
761 { 1,   0, 14,  0 }, /* index 11 */
762 { 1,   0, 14,  0 }, /* index 12 */
763 { 1,   0, 14,  2 }, /* index 13 */
764 { 1,   0, 14,  4 }, /* index 14 */
765 { 1,   0, 14,  0 }, /* index 15 */
766 };
767
768 /* Minimum Msg3 scheduling time should be calculated based on N1+N2+NTAmax+0.5
769  * ms formula.
770  * Refer spec 38.213 section 8.3.
771  * Harcoding the minimum msg3 scheduling for now */
772 uint8_t minMsg3SchTime[MAX_NUM_MU] = {6, 6, 6, 6};
773
774 uint8_t defaultUlAckTbl[DEFAULT_UL_ACK_LIST_COUNT]= {1, 2, 3 , 4, 5, 6, 7, 8};
775
776 /**
777  * @brief Function to find first DMRS symbol in PDSCH
778  *
779  * @details
780  *
781  *     Function: findDmrsStartSymbol
782  *
783  *     This function finds first DMRS symbol using DMRS symbol 
784  *     position bitmap.
785  *
786  *  @param[in]  DMRS symbol position bitmap
787  *  @return     Success : First DRMS symbol
788  *              Failure : MAX_SYMB_PER_SLOT 
789  **/
790 uint8_t findDmrsStartSymbol(uint16_t dlDmrsSymbBitMap)
791 {
792    uint8_t position = 0;
793    uint16_t mask = 1;
794
795    while(position < MAX_SYMB_PER_SLOT)
796    {
797       if(dlDmrsSymbBitMap & mask)
798          break;  
799       mask = mask << 1;
800       position++;
801    }
802    return position;   
803 }
804
805 /**
806  * @brief Function to add a node to a linked list
807  *
808  * @details
809  *
810  *     Function: addNodeToLList
811  *
812  *     This function adds a new node to the linked list
813  *
814  *  @param[in]  Pointer to the list
815  *              Pointer to node to be added
816  *              Pointer to current node
817  *  @return     ROK
818  *              RFAILED
819  **/
820 uint8_t addNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode)
821 {
822    CmLList  *newNode;
823
824    SCH_ALLOC(newNode, sizeof(CmLList));
825    if(newNode)
826    {
827       newNode->node = (PTR)blockToAdd;
828       
829       if(currNode == NULLP)
830          cmLListAdd2Tail(llist, newNode);
831       else
832       {
833          llist->crnt = currNode;
834          cmLListInsAfterCrnt(llist, newNode);
835       }
836       return ROK;
837    } 
838    return RFAILED;
839 }
840
841 /**
842  * @brief Function to delete a node from linked list
843  *
844  * @details
845  *
846  *     Function: deleteNodeFromLList
847  *
848  *     This function deletes a node from the linked list
849  *
850  *  @param[in]  Pointer to the list
851  *              Pointer to node to be deleted
852  *  @return     Pointer to the deleted node
853  **/
854 uint8_t deleteNodeFromLList(CmLListCp *llist, CmLList *node)
855 {
856    node = cmLListDelFrm(llist, node);
857    SCH_FREE(node, sizeof(CmLList));
858
859    return ROK;
860 }
861
862 /**
863  * @brief Checks if requested PRBs are free
864  *
865  * @details
866  *
867  *     Function: isPrbAvailable
868  *
869  *     This functions loops through all free PRB blocks and 
870  *     checks if request PRB block is available for allocation
871  *
872  *  @param[in]  List of free PRB blocks
873  *              First PRB requested
874  *              Total number of PRB requested
875  *
876  *  @return     Returns Pointer to free block
877  *              NULL
878  **/
879 CmLList* isPrbAvailable(CmLListCp *freePrbBlockList, uint16_t startPrb, uint16_t numPrb)
880 {
881    uint16_t      endPrb = 0;
882    CmLList       *node = NULLP;
883    FreePrbBlock  *freeBlock = NULLP;
884
885    endPrb = startPrb + numPrb - 1; 
886
887    /* Iterate through all blocks of free PRB to check if requested PRBs can be assigned */
888    node = freePrbBlockList->first;
889    while(node)
890    {
891       freeBlock = (FreePrbBlock *)node->node;
892
893       /* Check if requested number of blocks can be allocated from the current block */
894       if(freeBlock->numFreePrb < numPrb)
895          continue;
896
897       /* Check if requested PRBs belong within the range of current free block */
898       if(((startPrb >= freeBlock->startPrb) && (startPrb <= freeBlock->endPrb)) && \
899          ((endPrb >= freeBlock->startPrb) && (endPrb <= freeBlock->endPrb)))
900       {
901          return node;
902       }
903
904       /* If current block is unable to provide resources, check the next block */
905       node = node->next;
906    }
907    return NULLP;
908 }
909
910 /**
911  * @brief Function to update free PRB list
912  *
913  * @details
914  *
915  *     Function: removeAllocatedPrbFromFreePrbList
916  *
917  *     This function removes the allocated PRBs from the
918  *     list of free PRBs
919  *
920  *  @param[in]  Pointer to the list
921  *              Pointer to node from which PRB was allocated
922  *              Start PRB allocated
923  *              Number of PRBs allocated
924  *  @return     void
925  **/
926 void removeAllocatedPrbFromFreePrbList(CmLListCp *freePrbBlockList, CmLList *node, uint16_t startPrb, uint16_t numPrb)
927 {
928    uint16_t      endPrb;
929    FreePrbBlock  *newBlock = NULLP;
930    FreePrbBlock  *freeBlock = (FreePrbBlock *)node->node;
931
932    if(!node) 
933       return;
934    
935    endPrb = startPrb + numPrb -1;
936
937    /* If the whole block is allocated, remove it from linked list */
938    if(freeBlock->numFreePrb == numPrb)
939    {
940       if(deleteNodeFromLList(freePrbBlockList, node) == ROK)
941          SCH_FREE(freeBlock, sizeof(FreePrbBlock));
942    }
943
944    /* If PRB is allocated from start of free block, move the start of free block
945     * after last alloctaed PRB */
946    else if(freeBlock->startPrb == startPrb)
947    {
948       freeBlock->startPrb = endPrb+1;
949       freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
950    }
951
952    /* If PRB is allocated from end of free block, move the end of free block
953     * before the first allocated PRB */
954    else if(freeBlock->endPrb == endPrb)
955    {
956       freeBlock->endPrb = startPrb-1;
957       freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
958    }
959
960    /* If PRBs are allocated somewhere in between the free block, split it into 2
961     * nodes. Fist node contains free PRBs after the allocated PRBs. Second node
962     * contains free PRBs present before the allocated PRBs */
963    else
964    {
965       /* Block 2 */
966       SCH_ALLOC(newBlock, sizeof(FreePrbBlock));
967       if(newBlock)
968       {
969          newBlock->startPrb = freeBlock->startPrb;
970          newBlock->endPrb = startPrb-1;
971          newBlock->numFreePrb = newBlock->endPrb - newBlock->startPrb +1;
972          addNodeToLList(freePrbBlockList, newBlock, node);
973       }
974
975       /* Block 1 */
976       freeBlock->startPrb = endPrb+1;
977       freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
978    }
979 }
980
981 /**
982  * @brief frequency domain allocation function. 
983  *
984  * @details
985  *
986  *     Function: schCalcTbSize
987  *     
988  *     This function finds the TBSize from table Table 5.1.3.2-1 spec 38.214
989  *     
990  *  @param[in]  payLoadSize - size of payload in bytes
991  *  @return     TBsize from the Table in bytes
992  **/
993 uint16_t schCalcTbSize(uint32_t payLoadSize)
994 {
995    uint8_t tbsIndex = 0;
996    uint16_t maxTbSize;
997
998    maxTbSize = tbSizeTable[TOTAL_TBSIZE_VALUES -1]/8;
999    if(payLoadSize >= maxTbSize)
1000       return maxTbSize;
1001
1002    payLoadSize = payLoadSize*8;
1003    while(payLoadSize > tbSizeTable[tbsIndex])
1004    {
1005       tbsIndex++;
1006    }
1007
1008    /* return the TBsize in bytes */
1009    return (tbSizeTable[tbsIndex]/8);
1010 }
1011
1012 /**
1013  * @brief frequency domain allocation function. 
1014  *
1015  * @details
1016  *
1017  *     Function: schCalcNumPrb
1018  *     
1019  *     This function calculates the number of PRbs 
1020  *     
1021  *  @param[in]  tbSize in bytes
1022  *  @param[in]  mcs
1023  *  @param[in]  number of symbols
1024  *  @return   number PRBs
1025  **/
1026 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols)
1027 {
1028    uint16_t numPrb = 0;
1029    uint16_t nre = 0;
1030    uint16_t nreDash = 0;
1031    uint8_t  qm     = mcsTable[mcs][1];
1032    uint16_t rValue = mcsTable[mcs][2];
1033    uint8_t  numLayer = 1;       /* v value */
1034    uint8_t  numDmrsRePerPrb = 12;
1035
1036    tbSize = tbSize * 8; //Calculate tbSize in bits
1037
1038    /* formula used for calculation of rbSize, 38.214 section 5.1.3.2 *
1039     * Ninfo = S . Nre . R . Qm . v                                       *
1040     * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh                       *
1041     * Nre = min(156,Nre') . nPrb                                     */
1042
1043    nre = ceil( (float)tbSize * 1024 / (qm * rValue * numLayer));
1044
1045    nreDash = ceil( (12 * numSymbols) - numDmrsRePerPrb - 0);
1046
1047    if (nreDash > 156)
1048       nreDash = 156;
1049
1050    numPrb = ceil((float)nre / nreDash);   
1051    return numPrb;
1052 }
1053
1054 /**
1055 * @brief calculation of transport block size.
1056 *
1057 * @details
1058 *
1059 *     Function: schCalcTbSizeFromNPrb
1060 *
1061 *     This function calculates the transport block size
1062 *
1063 *  @param[in]  nPrb is num PRB
1064 *  @param[in]  mcs
1065 *  @param[in]  number of symbols
1066 *  @return   tbSize
1067 **/
1068 uint16_t schCalcTbSizeFromNPrb(uint16_t numPrb, uint16_t mcs, uint8_t numSymbols)
1069 {   
1070    uint8_t  qm     = mcsTable[mcs][1];
1071    uint16_t rValue = mcsTable[mcs][2];
1072    uint16_t tbsIndex = 0;
1073    uint32_t tbSize = 0;
1074    uint32_t nre = 0;
1075    uint32_t nreDash = 0;
1076    uint32_t nInfo = 0;
1077    uint32_t n = 0;
1078    uint32_t nInfoDash = 0;
1079    uint32_t c = 0;
1080    const uint8_t  numLayer = 1;
1081    const uint16_t numRbSc = 12;
1082    const uint16_t numDmrsRes = 12;
1083    const uint16_t sf = 1;
1084 //   uint16_t numPrbOvrHead = 0;
1085    
1086   /* formula used for calculation of rbSize, 38.214 section 5.1.3.2  *
1087    * Ninfo = Nre . R . Qm . v   where [ NInfo is tbSize]             *
1088    * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh                        *
1089    * Nre = min(156,Nre') . nPrb                                      */
1090
1091    nreDash = MIN(156, ceil( (numRbSc * numSymbols) - numDmrsRes - 0));
1092    nre = nreDash * numPrb;
1093    nInfo = ceil(nre * qm * numLayer * rValue/(1024.0 * sf));
1094
1095    if(nInfo <= 3824)
1096    {
1097       n = MAX(3, (uint32_t)cmLog2(nInfo) - 6);
1098       nInfoDash = MAX(24, (1<<n)*(nInfo/(1<<n)));
1099       while(nInfoDash > tbSizeTable[tbsIndex])
1100       {
1101          tbsIndex++;
1102       }
1103       tbSize = tbSizeTable[tbsIndex];
1104    }
1105    else
1106    {
1107       n = (uint32_t)cmLog2(nInfo - 24) - 5;
1108       nInfoDash = MAX(3840, (1<<n)*ceil((nInfo - 24)/(1<<n)));
1109
1110       if(rValue<256)
1111       {
1112          c = ceil((nInfoDash + 24)/3816);
1113          tbSize = 8 * c * ceil((nInfoDash + 24)/(8 * c)) - 24;
1114       }
1115       else
1116       {
1117          if(nInfoDash > 8424)
1118          {
1119             c = ceil((nInfoDash + 24)/8424);
1120             tbSize = 8 * c * ceil((nInfoDash + 24)/(8 * c)) - 24;
1121          }
1122          else
1123          {
1124             tbSize = 8 * ceil((nInfoDash + 24)/(8)) - 24;
1125          }
1126       }
1127    }
1128    return tbSize;
1129 }
1130
1131 /**
1132  * @brief fetching ueCb from cellCb
1133  *
1134  * @details
1135  *
1136  *     Function: schGetUeCb
1137  *
1138  *     This function fetched UeCb based on crnti from cellCb
1139  *
1140  *  @param[in]  cellCb
1141  *  @param[in]  crnti
1142  *  @return     ueCb
1143  **/
1144 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti)
1145 {
1146    uint16_t ueId;
1147    GET_UE_ID(crnti, ueId);
1148    return &(cellCb->ueCb[ueId -1]);
1149 }
1150
1151 /**
1152  * @brief initialize UL slot info
1153  *
1154  * @details
1155  *
1156  *     Function: schInitUlSlot
1157  *
1158  *     This function intializes UL slot of the cell
1159  *
1160  *  @param[in]  schUlSlotInfo
1161  *  @return     void
1162  **/
1163 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo)
1164 {
1165    CmLList *node = NULLP, *next = NULLP;
1166    FreePrbBlock *freeBlock;
1167
1168    /* Delete the old blocks */
1169    if(schUlSlotInfo->prbAlloc.freePrbBlockList.count)
1170    {
1171       node = schUlSlotInfo->prbAlloc.freePrbBlockList.first;
1172    }
1173    while(node)
1174    {
1175       next = node->next;
1176       freeBlock = (FreePrbBlock *)node->node;
1177       if(deleteNodeFromLList(&schUlSlotInfo->prbAlloc.freePrbBlockList, node) == ROK)
1178          SCH_FREE(freeBlock, sizeof(FreePrbBlock));
1179       node = next;
1180    }
1181
1182    /* Initilize UL Slot info and mark all PRBs as free */
1183    memset(schUlSlotInfo, 0, sizeof(SchUlSlotInfo));
1184    cmLListInit(&schUlSlotInfo->prbAlloc.freePrbBlockList);
1185    SCH_ALLOC(freeBlock, sizeof(FreePrbBlock));
1186    if(freeBlock)
1187    {
1188       freeBlock->numFreePrb = MAX_NUM_RB;
1189       freeBlock->startPrb = 0;
1190       freeBlock->endPrb = MAX_NUM_RB-1;
1191       addNodeToLList(&schUlSlotInfo->prbAlloc.freePrbBlockList, freeBlock, NULL);
1192    }
1193
1194    schUlSlotInfo->puschCurrentPrb = PUSCH_START_RB;
1195    schUlSlotInfo->schPuschInfo = NULLP;
1196 }
1197
1198 /**
1199  * @brief initialize DL slot info
1200  *
1201  * @details
1202  *
1203  *     Function: schInitDlSlot
1204  *
1205  *     This function intializes DL slot of the cell
1206  *
1207  *  @param[in]  schDlSlotInfo
1208  *  @return     void
1209  **/
1210 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo)
1211 {
1212    CmLList *node = NULLP, *next = NULLP;
1213    FreePrbBlock *freeBlock;
1214
1215    /* Delete the old blocks */
1216    if(schDlSlotInfo->prbAlloc.freePrbBlockList.count)
1217       node = schDlSlotInfo->prbAlloc.freePrbBlockList.first;
1218    while(node)
1219    {
1220       next = node->next;
1221       freeBlock = (FreePrbBlock *)node->node;
1222       if(deleteNodeFromLList(&schDlSlotInfo->prbAlloc.freePrbBlockList, node) == ROK)
1223          SCH_FREE(freeBlock, sizeof(FreePrbBlock));
1224       node = next;
1225    }
1226
1227    /* Initilize DL Slot info and mark all PRBs as free */
1228    memset(schDlSlotInfo, 0, sizeof(SchDlSlotInfo));
1229    cmLListInit(&schDlSlotInfo->prbAlloc.freePrbBlockList);
1230    SCH_ALLOC(freeBlock, sizeof(FreePrbBlock));
1231    if(freeBlock)
1232    {
1233       freeBlock->numFreePrb = MAX_NUM_RB;
1234       freeBlock->startPrb = 0;
1235       freeBlock->endPrb = MAX_NUM_RB-1;
1236       addNodeToLList(&schDlSlotInfo->prbAlloc.freePrbBlockList, freeBlock, NULL);
1237    }
1238 }
1239
1240 /**
1241  * @brief Fill resource bit map
1242  *
1243  * @details
1244  *
1245  *     Function: fillPrbBitmap
1246  *
1247  *     This function updates bitMap to mark the allocated PRBs
1248  *
1249  *  @param[in]  schDlSlotInfo
1250  *  @return     void
1251  **/
1252 bool fillPrbBitmap(uint64_t *prbBitMap, uint16_t startPrb, uint16_t numPrb)
1253 {
1254    uint16_t bitMapIdx = 0;
1255    uint16_t offsetInFirstIdx = 0;
1256    uint32_t numBitsToSetInFirstIdx = 0;
1257    uint64_t mask = MASK_BIT64_ON;
1258    uint64_t bitmapBackup[PRB_BITMAP_MAX_IDX];
1259
1260    /* Store backup of the bitmap in order to roll back if PRB allocation fails */
1261    memcpy(bitmapBackup, prbBitMap, sizeof(bitmapBackup));
1262
1263    /* Calculate the bitmap idx and offset of bit in that idx, to start
1264     * allocating PRBs from */
1265    bitMapIdx = startPrb / PRB_BITMAP_IDX_LEN;
1266    offsetInFirstIdx = startPrb % PRB_BITMAP_IDX_LEN;
1267
1268    /* If number of PRBs allocated >= number of unset bits in first idx starting from offset bit
1269     * then set all bits in first idx starting from offset bit
1270     * else set bits equal to number of PRBs allocated
1271     */
1272    numBitsToSetInFirstIdx = \
1273       (numPrb >= (PRB_BITMAP_IDX_LEN-offsetInFirstIdx)) ? (PRB_BITMAP_IDX_LEN-offsetInFirstIdx) : numPrb;
1274
1275    mask = mask >> (PRB_BITMAP_IDX_LEN-numBitsToSetInFirstIdx);
1276    mask = mask<<offsetInFirstIdx;
1277
1278    /* If PRBs to be allocated are not already in use, mark these PRBs as allocated */
1279    if(!(prbBitMap[bitMapIdx] & mask))
1280    {
1281       prbBitMap[bitMapIdx] = prbBitMap[bitMapIdx] | mask;
1282
1283       bitMapIdx++;
1284       numPrb = numPrb - numBitsToSetInFirstIdx;
1285       /* Set all bits in a bitMapIdx until remaining numPrb is less than PRB_BITMAP_IDX_LEN */
1286       while(numPrb > PRB_BITMAP_IDX_LEN)
1287       {
1288          if(prbBitMap[bitMapIdx])
1289          {
1290             memcpy(prbBitMap, bitmapBackup, sizeof(bitmapBackup));
1291             return RFAILED;
1292          }
1293          prbBitMap[bitMapIdx] = MASK_BIT64_ON;
1294          bitMapIdx++;
1295          numPrb = numPrb - PRB_BITMAP_IDX_LEN;
1296       }
1297
1298       /* Set bits for the remaining PRBs */
1299       if(numPrb)
1300       {
1301          mask = MASK_BIT64_ON;
1302          mask = mask >> (PRB_BITMAP_IDX_LEN-numPrb);
1303          if(!(prbBitMap[bitMapIdx] & mask))
1304          {
1305             prbBitMap[bitMapIdx] = prbBitMap[bitMapIdx] | mask;
1306          }
1307          else
1308          {
1309             memcpy(prbBitMap, bitmapBackup, sizeof(bitmapBackup));
1310             return RFAILED;
1311          }
1312       }
1313    }
1314    else
1315    {
1316       return RFAILED;
1317    }
1318    
1319    return ROK;
1320 }
1321
1322
1323 /**************************************************************************
1324  *
1325  * @brief Update the LCID Node in LCLL as per ActionType
1326  *
1327  * @details
1328  *
1329  *    Function : handleLcLList
1330  *
1331  *    Functionality:
1332  *     Search LCID in LCLL or if not found, create,Delete, or return
1333  *     node for this LCID
1334  *
1335  * @params[in] I/P > lcLinkList pointer (LcInfo list)
1336  *             I/P > lcId
1337  *             I/P > ActionType (Create,Delete or Just search) 
1338  *
1339  * @return lcNode > Pointer to the Node for that LcInfo
1340  *         If NULLP, FATAL FAILURE
1341  *
1342  * ***********************************************************************/
1343 LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLcLL action)
1344 {
1345    CmLList  *node = NULLP;
1346    LcInfo *lcNode = NULLP;
1347    bool found = FALSE;
1348
1349    if(lcLL == NULLP)
1350    {
1351       DU_LOG("\nERROR  -->  SCH: LcList doesnt exist");
1352       return NULLP;
1353    }
1354    node = lcLL->first;
1355
1356    /*Traversing the LC LinkList*/
1357    while(node)
1358    {
1359       lcNode = (LcInfo *)node->node;
1360       if(lcNode->lcId == lcId)
1361       { 
1362          found = TRUE;
1363          break;
1364       }
1365       node = node->next;
1366    }//end of while
1367
1368    switch(action)
1369    {
1370       case SEARCH:
1371          {
1372             if(!found)
1373             {
1374                lcNode = NULLP;
1375             }
1376             return lcNode;
1377          }
1378
1379       case CREATE:
1380          {
1381             if(node != NULLP)
1382                return lcNode;
1383
1384             /*Need to add a new node for this LC*/
1385
1386             /*List is empty; Initialize the LL ControlPointer*/
1387             if(lcLL->count == 0)
1388             {
1389                cmLListInit(lcLL);
1390             }
1391
1392             lcNode = NULLP;
1393             /*Allocate the List*/
1394             SCH_ALLOC(lcNode, sizeof(LcInfo));
1395             if(lcNode)
1396             {
1397                lcNode->lcId = lcId;
1398                lcNode->reqBO = 0;
1399                lcNode->allocBO = 0;
1400                lcNode->allocPRB = 0;
1401             }
1402             else
1403             {
1404                DU_LOG("\nERROR  -->  SCH : Allocation of List failed,lcId:%d",lcId);
1405                return NULLP;
1406             }
1407
1408             if(addNodeToLList(lcLL, lcNode, NULLP) == RFAILED)
1409             {
1410                DU_LOG("\nERROR  -->  SCH : failed to Add Node,lcId:%d",lcId);
1411                SCH_FREE(lcNode, sizeof(LcInfo));
1412                return NULLP;
1413             }
1414             return lcNode;
1415          }
1416
1417       case DELETE:
1418          {
1419             if(!found ||  lcNode == NULLP)
1420             {
1421                DU_LOG("\nERROR  -->  SCH: LCID%d not found; thus Deletion unsuccessful",lcId);
1422             }
1423             else
1424             {
1425                if(deleteNodeFromLList(lcLL, node) == ROK)
1426                   SCH_FREE(lcNode, sizeof(LcInfo));
1427
1428                DU_LOG("\nDEBUG  -->  SCH: LCID%d Deleted successfully",lcId);
1429             }
1430             return NULLP; 
1431          }
1432       default:
1433          {
1434             DU_LOG("\nERROR  -->  SCH: Action type wrong: %d",action);
1435             break;
1436          }
1437    }
1438    return lcNode;
1439 }
1440
1441 /**************************************************************************
1442  *
1443  * @brief Update ReqPRB for a partiular LCID in LC Linklist 
1444  *
1445  * @details
1446  *
1447  *    Function : updateLcListReqPRB
1448  *
1449  *    Functionality:
1450  *     Update ReqPRB for a partiular LCID in LC Linklist 
1451  *
1452  * @params[in] I/P > lcLinkList pointer (LcInfo list)
1453  *             I/P > lcId
1454  *             I/P > reqPRB
1455  *             I/P > payloadSize
1456  *
1457  * @return ROK/RFAILED
1458  *
1459  * ***********************************************************************/
1460 uint8_t updateLcListReqPRB(CmLListCp *lcLL, uint8_t lcId, uint32_t payloadSize)
1461 {
1462    LcInfo    *lcNode = NULLP;
1463
1464    lcNode = handleLcLList(lcLL, lcId, CREATE);
1465
1466    if(lcNode == NULLP)
1467    {
1468       DU_LOG("\nERROR  -->  SCH : LC is neither present nor able to create in List lcId:%d",lcId);
1469       return RFAILED;
1470    }
1471    lcNode->reqBO = payloadSize;
1472    lcNode->allocBO = 0; 
1473    lcNode->allocPRB = 0; /*Re-Initializing the AllocPRB*/
1474    return ROK;
1475 }
1476
1477 /**************************************************************************
1478  *
1479  * @brief Delete entire LC Linklist 
1480  *
1481  * @details
1482  *
1483  *    Function : deleteLcLL
1484  *
1485  *    Functionality:
1486  *      Delete entire LC Linklist 
1487  *
1488  * @params[in] lcLinkList pointer (LcInfo list)
1489  *
1490  * @return void
1491  *
1492  * ***********************************************************************/
1493 void deleteLcLL(CmLListCp *lcLL)
1494 {
1495    CmLList *node = NULLP, *next = NULLP;
1496    LcInfo *lcNode = NULLP;
1497
1498    if(lcLL == NULLP)
1499    {
1500       DU_LOG("\nERROR  -->  SCH: LcList doesnt exist");
1501       return;
1502    }
1503    node = lcLL->first;
1504
1505    while(node)
1506    {
1507       next = node->next;
1508       lcNode = (LcInfo *)node->node;
1509       if(deleteNodeFromLList(lcLL, node) == ROK)
1510          SCH_FREE(lcNode, sizeof(LcInfo));
1511       node = next;
1512    }
1513 }
1514
1515 /****************************************************************************
1516  *
1517  * @brief Calculate the Estimated TBS Size based on Spec 38.421 , Sec 5.3.1.2
1518  *
1519  * @details
1520  *
1521  *    Function : calculateEstimateTBSize
1522  *
1523  *    Functionality:
1524  *       TBS Size calculation requires numPRB. Since exactPRB for reqBO is unknown thus 
1525  *       will give the PRB value(from 0 to maxRB) one by one and 
1526  *       try to find the TBS size closest to reqBO
1527  *
1528  * @params[in] I/P > reqBO, mcsIdx, num PDSCH symbols, 
1529  *             I/P > maxRB: Maximum PRB count to reach for calculating the TBS
1530  *             O/P > estPrb : Suitable PRB count for reaching the correct TBS
1531  *       
1532  *
1533  * @return TBS Size > Size which will can be allocated for this LC
1534  *        
1535  *
1536  *************************************************************************/
1537 uint32_t calculateEstimateTBSize(uint32_t reqBO, uint16_t mcsIdx,uint8_t numSymbols,\
1538                                    uint16_t maxPRB, uint16_t *estPrb)
1539 {
1540    uint32_t tbs = 0, effecBO = 0;
1541
1542    *estPrb = MIN_PRB;
1543    /*Loop Exit: Either estPRB reaches the maxRB or TBS is found greater than equal to reqBO*/
1544    do
1545    {
1546       tbs = schCalcTbSizeFromNPrb(*estPrb, mcsIdx, numSymbols);
1547
1548       /*TBS size calculated in above function is in Bits. 
1549        * So to convert it into Bytes , we right shift by 3. 
1550        * Eg: tbs=128 bits(1000 0000) ; Right Shift by 3: Tbs = 0001 0000(16 bytes)*/
1551       tbs = tbs >> 3;
1552       *estPrb += 1;
1553    }while((tbs < reqBO) && (*estPrb < maxPRB));
1554
1555    /*Effective BO is the Grant which can be provided for this LC.
1556     * Here,it is decided based on whether we can fully cater its requirment (reqBO) 
1557     * or has to provide lesser grant due to resource limitation.
1558     * Thus effective BO/Grant for this LC will be min of TBS calculated and reqBO*/
1559    effecBO = MIN(tbs,reqBO);
1560    return (effecBO);
1561 }
1562 /*Below function for printing will be used in future so disabling it for now*/
1563 #if 0
1564 /****************************************************************************
1565  *
1566  * @brief Print the LC in list for debugging purpose 
1567  *
1568  * @details
1569  *
1570  *    Function : printLcLL
1571  *
1572  *    Functionality:
1573  *            For debugging purpose, for printing the LC in the order and
1574  *            parameters
1575  *
1576  * @params[in] LcList pointer 
1577  *       
1578  * @return void 
1579  *        
1580  *************************************************************************/
1581 void printLcLL(CmLListCp *lcLL)
1582 {
1583    CmLList *node = NULLP;
1584    LcInfo *lcNode = NULLP;
1585
1586    if(lcLL == NULLP)
1587    {
1588       DU_LOG("\nINFO   -->  SCH: LcList doesnt exist");
1589       return;
1590    }
1591    node = lcLL->first;
1592    while(node)
1593    {
1594       lcNode = (LcInfo *)node->node;
1595       if(lcNode)
1596       {
1597          DU_LOG("\nINFO   -->  SCH : LcID:%d, [reqBO, allocBO, allocPRB]:[%d,%d,%d]",\
1598                lcNode->lcId,lcNode->reqBO, lcNode->allocBO, lcNode->allocPRB);
1599       }
1600
1601       node = node->next;
1602    }
1603 }
1604 #endif
1605
1606 #ifdef NR_TDD
1607
1608 /**
1609  * @brief determines slot/symbol format
1610  *
1611  * @details
1612  *
1613  *     Function : schGetSlotSymbFrmt 
1614  *      
1615  *      This API is invoked to determine if current slot is DL or UL
1616  *           
1617  *  @param[in]  uint16_t slot
1618  *  @param[in]  uint32_t bitMap from cellCb
1619  *  @return  SlotConfig
1620  *      -# DL    - 0 
1621  *      -# UL    - 1
1622  *      -# FLEXI - 2
1623  **/
1624 SlotConfig schGetSlotSymbFrmt(uint16_t slot, uint32_t bitMap)
1625 {
1626    uint32_t offset = (slot)*2;
1627    return (bitMap & 0x3<<offset)>>offset;
1628 #if 0
1629    SlotConfig slotFrmt;
1630    int mask1 = 0, mask2 = 0;
1631
1632    slot = (slot%n)*2;//n num of slots in defined periodicity or num of symbols
1633    mask1 = 1<<(slot);
1634    mask2 = 1<<(slot+1);
1635    slotFrmt = ((mask1 & bitMap)>>slot) + (2*((mask2 & bitMap)>>(slot+1)));
1636
1637    //printf("\n\n\n\n*****FormatType:%d Slot:%d****\n\n\n\n", slotFrmt, slot/2);
1638
1639    return slotFrmt;
1640 #endif
1641 }
1642
1643 /**
1644  * @brief Determine total length of configured slot pattern for specific 
1645  *    periodicity for TDD
1646  *
1647  * @details
1648  *
1649  *     Function : calculateSlotPatternLength 
1650  *      
1651  *      Determine total length of configured slot pattern for specific periodicity based
1652  *      on slot duration for TDD
1653  *           
1654  *  @param[in]  uint8_t scs, uint8_t periodicity 
1655  *
1656  *  @return uint8_t slotPatternLength 
1657  **/
1658
1659 uint8_t calculateSlotPatternLength(uint8_t scs, uint8_t periodicity)
1660 {
1661    uint8_t slotPatternLength =0;
1662    float   slotDuration = 0;
1663    
1664    /* Calculating the slot duration with the help of SCS.
1665     * This will provides the slot duration in ms like 1, 0.5, 0.25, 0.125. 
1666     * If scs value is SCS_30KHZ its enum value is 1, 
1667     * slotDuration = pow(0.5, 1);
1668     * slotDuration = 0.5 */
1669
1670    slotDuration = pow(0.5,scs);
1671
1672    /* Calculating length of pattern based on Transmission Periodicity. 
1673     * If periodicity = TX_PRDCTY_MS_5,
1674     * slotPatternLength = 5/0.5 
1675     * slotPatternLength = 10 i.e. {length of slot pattern DDDDDDDFUU}*/
1676
1677    switch(periodicity)
1678    {
1679       case TX_PRDCTY_MS_0P5:
1680          slotPatternLength = 0.5/slotDuration;
1681          break;
1682       case TX_PRDCTY_MS_0P625:
1683          slotPatternLength = 0.625/slotDuration;
1684          break;
1685       case TX_PRDCTY_MS_1:
1686          slotPatternLength = 1/slotDuration;
1687          break;
1688       case TX_PRDCTY_MS_1P25:
1689          slotPatternLength = 1.25/slotDuration;
1690          break;
1691       case TX_PRDCTY_MS_2:
1692          slotPatternLength = 2/slotDuration;
1693          break;
1694       case TX_PRDCTY_MS_2P5:
1695          slotPatternLength = 2.5/slotDuration;
1696          break;
1697       case TX_PRDCTY_MS_5:
1698          slotPatternLength = 5/slotDuration;
1699          break;
1700       case TX_PRDCTY_MS_10:
1701          slotPatternLength = 10/slotDuration;
1702          break;
1703    }
1704    return slotPatternLength;
1705 }
1706 #endif
1707
1708 /*
1709  * As per FAPI spec, 
1710  * Frequency domain resources is a bitmap defining non-overlapping groups of 6 PRBs in ascending order.
1711  * [TS38.213 10.1]. Bitmap of uint8 array. 45 bits.
1712  *
1713  * As per IAPI,
1714  * CORESET-freqdom.frequencyDomainResources : The bits of the bitmap have a one-to-one mapping with
1715  * non-overlapping groups of 6 RBs. The most significant bit of the first word corresponds to
1716  * the most significant bit defined in 38.331.
1717  *
1718  * FAPI and IAPI both are 45 bits. Mapped from bit 0 LS Byte for the FAPI and
1719  * bit 0 LS U32 entry for IAPI.
1720  * FAPI is to be filled in following format such that Intel L1 is able to decode it :
1721  *
1722  *            FAPI                                 IAPI 
1723  * FreqDomainResource[0] bits 7-0     ->    nFreqDomain[0] bits 7-0
1724  * FreqDomainResource[1] bits 7-0     ->    nFreqDomain[0] bits 15-8
1725  * FreqDomainResource[2] bits 7-0     ->    nFreqDomain[0] bits 23-16
1726  * FreqDomainResource[3] bits 7-0     ->    nFreqDomain[0] bits 31-24
1727  * FreqDomainResource[4] bits 7-0     ->    nFreqDomain[1] bits 7-0
1728  * FreqDomainResource[5] bits 7-0     ->    nFreqDomain[1] bits 15-8
1729  *
1730  * where for the last entry bits 7,6 and 5 are don't care in the FAPI and bits
1731  * 31-13 are don't care in the IAPI.
1732  */
1733 void covertFreqDomRsrcMapToIAPIFormat(uint8_t *sourceBitMap, uint8_t *destBitMap)
1734 {
1735    int8_t  idx;
1736    uint8_t  numBitsToShift = 0;
1737    uint64_t freqDomainResources = 0;
1738
1739    /* Bit operation to create a 64-bit integer that has
1740     * 48 LSBs [Bit 47 to Bit 0] mapped to sourceBitMap[0] to sourceBitMap[5]
1741     */
1742    for(idx = FREQ_DOM_RSRC_SIZE-1; idx >=0; idx--)
1743    {
1744       freqDomainResources |= ((uint64_t)sourceBitMap[idx] << numBitsToShift);
1745       numBitsToShift += 8;
1746    }
1747
1748    /* Right shift 3 bits because bits[2-0] are unused in sourceBitMap[5] */
1749    freqDomainResources = freqDomainResources >> 3;
1750
1751    /* Filling destBitMap such that LSB bit 0 of freqDomainResources maps to LSB 
1752     * of first word of destBitMap */
1753    numBitsToShift = 0;
1754    for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
1755    {
1756       destBitMap[idx] = freqDomainResources >> numBitsToShift;
1757       numBitsToShift += 8;
1758    }
1759 }
1760
1761 /**********************************************************************
1762          End of file
1763 **********************************************************************/