[Epic-ID: ODUHIGH-488][Task-ID: ODUHIGH-492] WG8 Alignment [RAR Scheduling + Downlink...
[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 uint8_t schCmnDlRvTbl[4] = {0, 2, 3, 1};
777 /**
778  * @brief Function to find first DMRS symbol in PDSCH
779  *
780  * @details
781  *
782  *     Function: findDmrsStartSymbol
783  *
784  *     This function finds first DMRS symbol using DMRS symbol 
785  *     position bitmap.
786  *
787  *  @param[in]  DMRS symbol position bitmap
788  *  @return     Success : First DRMS symbol
789  *              Failure : MAX_SYMB_PER_SLOT 
790  **/
791 uint8_t findDmrsStartSymbol(uint16_t dlDmrsSymbBitMap)
792 {
793    uint8_t position = 0;
794    uint16_t mask = 1;
795
796    while(position < MAX_SYMB_PER_SLOT)
797    {
798       if(dlDmrsSymbBitMap & mask)
799          break;  
800       mask = mask << 1;
801       position++;
802    }
803    return position;   
804 }
805
806 /**
807  * @brief Function to add a node to a linked list
808  *
809  * @details
810  *
811  *     Function: addNodeToLList
812  *
813  *     This function adds a new node to the linked list
814  *
815  *  @param[in]  Pointer to the list
816  *              Pointer to node to be added
817  *              Pointer to current node
818  *  @return     ROK
819  *              RFAILED
820  **/
821 uint8_t addNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode)
822 {
823    CmLList  *newNode;
824
825    SCH_ALLOC(newNode, sizeof(CmLList));
826    if(newNode)
827    {
828       newNode->node = (PTR)blockToAdd;
829       
830       if(currNode == NULLP)
831          cmLListAdd2Tail(llist, newNode);
832       else
833       {
834          llist->crnt = currNode;
835          cmLListInsAfterCrnt(llist, newNode);
836       }
837       return ROK;
838    } 
839    return RFAILED;
840 }
841
842 /**
843  * @brief Function to delete a node from linked list
844  *
845  * @details
846  *
847  *     Function: deleteNodeFromLList
848  *
849  *     This function deletes a node from the linked list
850  *
851  *  @param[in]  Pointer to the list
852  *              Pointer to node to be deleted
853  *  @return     Pointer to the deleted node
854  **/
855 uint8_t deleteNodeFromLList(CmLListCp *llist, CmLList *node)
856 {
857    node = cmLListDelFrm(llist, node);
858    SCH_FREE(node, sizeof(CmLList));
859
860    return ROK;
861 }
862
863 /**
864  * @brief Checks if requested PRBs are free
865  *
866  * @details
867  *
868  *     Function: isPrbAvailable
869  *
870  *     This functions loops through all free PRB blocks and 
871  *     checks if request PRB block is available for allocation
872  *
873  *  @param[in]  List of free PRB blocks
874  *              First PRB requested
875  *              Total number of PRB requested
876  *
877  *  @return     Returns Pointer to free block
878  *              NULL
879  **/
880 CmLList* isPrbAvailable(CmLListCp *freePrbBlockList, uint16_t startPrb, uint16_t numPrb)
881 {
882    uint16_t      endPrb = 0;
883    CmLList       *node = NULLP;
884    FreePrbBlock  *freeBlock = NULLP;
885
886    endPrb = startPrb + numPrb - 1; 
887
888    /* Iterate through all blocks of free PRB to check if requested PRBs can be assigned */
889    node = freePrbBlockList->first;
890    while(node)
891    {
892       freeBlock = (FreePrbBlock *)node->node;
893
894       /* Check if requested number of blocks can be allocated from the current block */
895       if(freeBlock->numFreePrb < numPrb)
896       {
897          DU_LOG("\nINFO   --> SCH: In isPrbAvailable, numFreePrb:%d is less than reqPrb:%d", freeBlock->numFreePrb, numPrb);
898          node = node->next;
899          continue;
900       }
901       /* Check if requested PRBs belong within the range of current free block */
902       if(((startPrb >= freeBlock->startPrb) && (startPrb <= freeBlock->endPrb)) && \
903          ((endPrb >= freeBlock->startPrb) && (endPrb <= freeBlock->endPrb)))
904       {
905          return node;
906       }
907
908       /* If current block is unable to provide resources, check the next block */
909       node = node->next;
910    }
911    return NULLP;
912 }
913
914 /**
915  * @brief Function to update free PRB list
916  *
917  * @details
918  *
919  *     Function: removeAllocatedPrbFromFreePrbList
920  *
921  *     This function removes the allocated PRBs from the
922  *     list of free PRBs
923  *
924  *  @param[in]  Pointer to the list
925  *              Pointer to node from which PRB was allocated
926  *              Start PRB allocated
927  *              Number of PRBs allocated
928  *  @return     void
929  **/
930 void removeAllocatedPrbFromFreePrbList(CmLListCp *freePrbBlockList, CmLList *node, uint16_t startPrb, uint16_t numPrb)
931 {
932    uint16_t      endPrb;
933    FreePrbBlock  *newBlock = NULLP;
934    FreePrbBlock  *freeBlock = (FreePrbBlock *)node->node;
935
936    if(!node) 
937       return;
938    
939    endPrb = startPrb + numPrb -1;
940
941    /* If the whole block is allocated, remove it from linked list */
942    if(freeBlock->numFreePrb == numPrb)
943    {
944       if(deleteNodeFromLList(freePrbBlockList, node) == ROK)
945          SCH_FREE(freeBlock, sizeof(FreePrbBlock));
946    }
947
948    /* If PRB is allocated from start of free block, move the start of free block
949     * after last alloctaed PRB */
950    else if(freeBlock->startPrb == startPrb)
951    {
952       freeBlock->startPrb = endPrb+1;
953       freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
954    }
955
956    /* If PRB is allocated from end of free block, move the end of free block
957     * before the first allocated PRB */
958    else if(freeBlock->endPrb == endPrb)
959    {
960       freeBlock->endPrb = startPrb-1;
961       freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
962    }
963
964    /* If PRBs are allocated somewhere in between the free block, split it into 2
965     * nodes. Fist node contains free PRBs after the allocated PRBs. Second node
966     * contains free PRBs present before the allocated PRBs */
967    else
968    {
969       /* Block 2 */
970       SCH_ALLOC(newBlock, sizeof(FreePrbBlock));
971       if(newBlock)
972       {
973          newBlock->startPrb = freeBlock->startPrb;
974          newBlock->endPrb = startPrb-1;
975          newBlock->numFreePrb = newBlock->endPrb - newBlock->startPrb +1;
976          addNodeToLList(freePrbBlockList, newBlock, node);
977       }
978
979       /* Block 1 */
980       freeBlock->startPrb = endPrb+1;
981       freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
982    }
983 }
984
985 /**
986  * @brief frequency domain allocation function. 
987  *
988  * @details
989  *
990  *     Function: schCalcTbSize
991  *     
992  *     This function finds the TBSize from table Table 5.1.3.2-1 spec 38.214
993  *     
994  *  @param[in]  payLoadSize - size of payload in bytes
995  *  @return     TBsize from the Table in bytes
996  **/
997 uint16_t schCalcTbSize(uint32_t payLoadSize)
998 {
999    uint8_t tbsIndex = 0;
1000    uint16_t maxTbSize;
1001
1002    maxTbSize = tbSizeTable[TOTAL_TBSIZE_VALUES -1]/8;
1003    if(payLoadSize >= maxTbSize)
1004       return maxTbSize;
1005
1006    payLoadSize = payLoadSize*8;
1007    while(payLoadSize > tbSizeTable[tbsIndex])
1008    {
1009       tbsIndex++;
1010    }
1011
1012    /* return the TBsize in bytes */
1013    return (tbSizeTable[tbsIndex]/8);
1014 }
1015
1016 /**
1017  * @brief frequency domain allocation function. 
1018  *
1019  * @details
1020  *
1021  *     Function: schCalcNumPrb
1022  *     
1023  *     This function calculates the number of PRbs 
1024  *     
1025  *  @param[in]  tbSize in bytes
1026  *  @param[in]  mcs
1027  *  @param[in]  number of symbols
1028  *  @return   number PRBs
1029  **/
1030 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols)
1031 {
1032    uint16_t numPrb = 0;
1033    uint16_t nre = 0;
1034    uint16_t nreDash = 0;
1035    uint8_t  qm     = mcsTable[mcs][1];
1036    uint16_t rValue = mcsTable[mcs][2];
1037    uint8_t  numLayer = 1;       /* v value */
1038    uint8_t  numDmrsRePerPrb = 12;
1039
1040    tbSize = tbSize * 8; //Calculate tbSize in bits
1041
1042    /* formula used for calculation of rbSize, 38.214 section 5.1.3.2 *
1043     * Ninfo = S . Nre . R . Qm . v                                       *
1044     * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh                       *
1045     * Nre = min(156,Nre') . nPrb                                     */
1046
1047    nre = ceil( (float)tbSize * 1024 / (qm * rValue * numLayer));
1048
1049    nreDash = ceil( (12 * numSymbols) - numDmrsRePerPrb - 0);
1050
1051    if (nreDash > 156)
1052       nreDash = 156;
1053
1054    numPrb = ceil((float)nre / nreDash);   
1055    return numPrb;
1056 }
1057
1058 /**
1059 * @brief calculation of transport block size.
1060 *
1061 * @details
1062 *
1063 *     Function: schCalcTbSizeFromNPrb
1064 *
1065 *     This function calculates the transport block size
1066 *
1067 *  @param[in]  nPrb is num PRB
1068 *  @param[in]  mcs
1069 *  @param[in]  number of symbols
1070 *  @return   tbSize
1071 **/
1072 uint16_t schCalcTbSizeFromNPrb(uint16_t numPrb, uint16_t mcs, uint8_t numSymbols)
1073 {   
1074    uint8_t  qm     = mcsTable[mcs][1];
1075    uint16_t rValue = mcsTable[mcs][2];
1076    uint16_t tbsIndex = 0;
1077    uint32_t tbSize = 0;
1078    uint32_t nre = 0;
1079    uint32_t nreDash = 0;
1080    uint32_t nInfo = 0;
1081    uint32_t n = 0;
1082    uint32_t nInfoDash = 0;
1083    uint32_t c = 0;
1084    const uint8_t  numLayer = 1;
1085    const uint16_t numRbSc = 12;
1086    const uint16_t numDmrsRes = 12;
1087    const uint16_t sf = 1;
1088 //   uint16_t numPrbOvrHead = 0;
1089    
1090   /* formula used for calculation of rbSize, 38.214 section 5.1.3.2  *
1091    * Ninfo = Nre . R . Qm . v   where [ NInfo is tbSize]             *
1092    * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh                        *
1093    * Nre = min(156,Nre') . nPrb                                      */
1094
1095    nreDash = MIN(156, ceil( (numRbSc * numSymbols) - numDmrsRes - 0));
1096    nre = nreDash * numPrb;
1097    nInfo = ceil(nre * qm * numLayer * rValue/(1024.0 * sf));
1098
1099    if(nInfo <= 3824)
1100    {
1101       n = MAX(3, (uint32_t)cmLog2(nInfo) - 6);
1102       nInfoDash = MAX(24, (1<<n)*(nInfo/(1<<n)));
1103       while(nInfoDash > tbSizeTable[tbsIndex])
1104       {
1105          tbsIndex++;
1106       }
1107       tbSize = tbSizeTable[tbsIndex];
1108    }
1109    else
1110    {
1111       n = (uint32_t)cmLog2(nInfo - 24) - 5;
1112       nInfoDash = MAX(3840, (1<<n)*ceil((nInfo - 24)/(1<<n)));
1113
1114       if(rValue<256)
1115       {
1116          c = ceil((nInfoDash + 24)/3816);
1117          tbSize = 8 * c * ceil((nInfoDash + 24)/(8 * c)) - 24;
1118       }
1119       else
1120       {
1121          if(nInfoDash > 8424)
1122          {
1123             c = ceil((nInfoDash + 24)/8424);
1124             tbSize = 8 * c * ceil((nInfoDash + 24)/(8 * c)) - 24;
1125          }
1126          else
1127          {
1128             tbSize = 8 * ceil((nInfoDash + 24)/(8)) - 24;
1129          }
1130       }
1131    }
1132    return tbSize;
1133 }
1134
1135 /**
1136  * @brief fetching ueCb from cellCb
1137  *
1138  * @details
1139  *
1140  *     Function: schGetUeCb
1141  *
1142  *     This function fetched UeCb based on crnti from cellCb
1143  *
1144  *  @param[in]  cellCb
1145  *  @param[in]  crnti
1146  *  @return     ueCb
1147  **/
1148 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti)
1149 {
1150    uint16_t ueId;
1151    GET_UE_ID(crnti, ueId);
1152    return &(cellCb->ueCb[ueId -1]);
1153 }
1154
1155 /**
1156  * @brief initialize UL slot info
1157  *
1158  * @details
1159  *
1160  *     Function: schInitUlSlot
1161  *
1162  *     This function intializes UL slot of the cell
1163  *
1164  *  @param[in]  schUlSlotInfo
1165  *  @return     void
1166  **/
1167 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo)
1168 {
1169    CmLList *node = NULLP, *next = NULLP;
1170    FreePrbBlock *freeBlock;
1171
1172    /* Delete the old blocks */
1173    if(schUlSlotInfo->prbAlloc.freePrbBlockList.count)
1174    {
1175       node = schUlSlotInfo->prbAlloc.freePrbBlockList.first;
1176    }
1177    while(node)
1178    {
1179       next = node->next;
1180       freeBlock = (FreePrbBlock *)node->node;
1181       if(deleteNodeFromLList(&schUlSlotInfo->prbAlloc.freePrbBlockList, node) == ROK)
1182          SCH_FREE(freeBlock, sizeof(FreePrbBlock));
1183       node = next;
1184    }
1185
1186    /* Initilize UL Slot info and mark all PRBs as free */
1187    memset(schUlSlotInfo, 0, sizeof(SchUlSlotInfo));
1188    cmLListInit(&schUlSlotInfo->prbAlloc.freePrbBlockList);
1189    SCH_ALLOC(freeBlock, sizeof(FreePrbBlock));
1190    if(freeBlock)
1191    {
1192       freeBlock->numFreePrb = MAX_NUM_RB;
1193       freeBlock->startPrb = 0;
1194       freeBlock->endPrb = MAX_NUM_RB-1;
1195       addNodeToLList(&schUlSlotInfo->prbAlloc.freePrbBlockList, freeBlock, NULL);
1196    }
1197
1198    schUlSlotInfo->puschCurrentPrb = PUSCH_START_RB;
1199    schUlSlotInfo->schPuschInfo = NULLP;
1200 }
1201
1202 /**
1203  * @brief initialize DL slot info
1204  *
1205  * @details
1206  *
1207  *     Function: schInitDlSlot
1208  *
1209  *     This function intializes DL slot of the cell
1210  *
1211  *  @param[in]  schDlSlotInfo
1212  *  @return     void
1213  **/
1214 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo)
1215 {
1216    CmLList *node = NULLP, *next = NULLP;
1217    FreePrbBlock *freeBlock;
1218
1219    /* Delete the old blocks */
1220    if(schDlSlotInfo->prbAlloc.freePrbBlockList.count)
1221       node = schDlSlotInfo->prbAlloc.freePrbBlockList.first;
1222    while(node)
1223    {
1224       next = node->next;
1225       freeBlock = (FreePrbBlock *)node->node;
1226       if(deleteNodeFromLList(&schDlSlotInfo->prbAlloc.freePrbBlockList, node) == ROK)
1227          SCH_FREE(freeBlock, sizeof(FreePrbBlock));
1228       node = next;
1229    }
1230
1231    /* Initilize DL Slot info and mark all PRBs as free */
1232    memset(schDlSlotInfo, 0, sizeof(SchDlSlotInfo));
1233    cmLListInit(&schDlSlotInfo->prbAlloc.freePrbBlockList);
1234    SCH_ALLOC(freeBlock, sizeof(FreePrbBlock));
1235    if(freeBlock)
1236    {
1237       freeBlock->numFreePrb = MAX_NUM_RB;
1238       freeBlock->startPrb = 0;
1239       freeBlock->endPrb = MAX_NUM_RB-1;
1240       addNodeToLList(&schDlSlotInfo->prbAlloc.freePrbBlockList, freeBlock, NULL);
1241    }
1242 }
1243
1244 /**
1245  * @brief Fill resource bit map
1246  *
1247  * @details
1248  *
1249  *     Function: fillPrbBitmap
1250  *
1251  *     This function updates bitMap to mark the allocated PRBs
1252  *
1253  *  @param[in]  schDlSlotInfo
1254  *  @return     void
1255  **/
1256 bool fillPrbBitmap(uint64_t *prbBitMap, uint16_t startPrb, uint16_t numPrb)
1257 {
1258    uint16_t bitMapIdx = 0;
1259    uint16_t offsetInFirstIdx = 0;
1260    uint32_t numBitsToSetInFirstIdx = 0;
1261    uint64_t mask = MASK_BIT64_ON;
1262    uint64_t bitmapBackup[PRB_BITMAP_MAX_IDX];
1263
1264    /* Store backup of the bitmap in order to roll back if PRB allocation fails */
1265    memcpy(bitmapBackup, prbBitMap, sizeof(bitmapBackup));
1266
1267    /* Calculate the bitmap idx and offset of bit in that idx, to start
1268     * allocating PRBs from */
1269    bitMapIdx = startPrb / PRB_BITMAP_IDX_LEN;
1270    offsetInFirstIdx = startPrb % PRB_BITMAP_IDX_LEN;
1271
1272    /* If number of PRBs allocated >= number of unset bits in first idx starting from offset bit
1273     * then set all bits in first idx starting from offset bit
1274     * else set bits equal to number of PRBs allocated
1275     */
1276    numBitsToSetInFirstIdx = \
1277       (numPrb >= (PRB_BITMAP_IDX_LEN-offsetInFirstIdx)) ? (PRB_BITMAP_IDX_LEN-offsetInFirstIdx) : numPrb;
1278
1279    mask = mask >> (PRB_BITMAP_IDX_LEN-numBitsToSetInFirstIdx);
1280    mask = mask<<offsetInFirstIdx;
1281
1282    /* If PRBs to be allocated are not already in use, mark these PRBs as allocated */
1283    if(!(prbBitMap[bitMapIdx] & mask))
1284    {
1285       prbBitMap[bitMapIdx] = prbBitMap[bitMapIdx] | mask;
1286
1287       bitMapIdx++;
1288       numPrb = numPrb - numBitsToSetInFirstIdx;
1289       /* Set all bits in a bitMapIdx until remaining numPrb is less than PRB_BITMAP_IDX_LEN */
1290       while(numPrb > PRB_BITMAP_IDX_LEN)
1291       {
1292          if(prbBitMap[bitMapIdx])
1293          {
1294             memcpy(prbBitMap, bitmapBackup, sizeof(bitmapBackup));
1295             return RFAILED;
1296          }
1297          prbBitMap[bitMapIdx] = MASK_BIT64_ON;
1298          bitMapIdx++;
1299          numPrb = numPrb - PRB_BITMAP_IDX_LEN;
1300       }
1301
1302       /* Set bits for the remaining PRBs */
1303       if(numPrb)
1304       {
1305          mask = MASK_BIT64_ON;
1306          mask = mask >> (PRB_BITMAP_IDX_LEN-numPrb);
1307          if(!(prbBitMap[bitMapIdx] & mask))
1308          {
1309             prbBitMap[bitMapIdx] = prbBitMap[bitMapIdx] | mask;
1310          }
1311          else
1312          {
1313             memcpy(prbBitMap, bitmapBackup, sizeof(bitmapBackup));
1314             return RFAILED;
1315          }
1316       }
1317    }
1318    else
1319    {
1320       return RFAILED;
1321    }
1322    
1323    return ROK;
1324 }
1325
1326
1327 /**************************************************************************
1328  *
1329  * @brief Update the LCID Node in LCLL as per ActionType
1330  *
1331  * @details
1332  *
1333  *    Function : handleLcLList
1334  *
1335  *    Functionality:
1336  *     Search LCID in LCLL or if not found, create,Delete, or return
1337  *     node for this LCID
1338  *
1339  * @params[in] I/P > lcLinkList pointer (LcInfo list)
1340  *             I/P > lcId
1341  *             I/P > ActionType (Create,Delete or Just search) 
1342  *
1343  * @return lcNode > Pointer to the Node for that LcInfo
1344  *         If NULLP, FATAL FAILURE
1345  *
1346  * ***********************************************************************/
1347 LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLL action)
1348 {
1349    CmLList  *node = NULLP;
1350    LcInfo *lcNode = NULLP;
1351    bool found = FALSE;
1352
1353    if(lcLL == NULLP)
1354    {
1355       DU_LOG("\nERROR  -->  SCH: LcList doesnt exist");
1356       return NULLP;
1357    }
1358    node = lcLL->first;
1359
1360    /*Traversing the LC LinkList*/
1361    while(node)
1362    {
1363       lcNode = (LcInfo *)node->node;
1364       if(lcNode->lcId == lcId)
1365       { 
1366          found = TRUE;
1367          break;
1368       }
1369       node = node->next;
1370    }//end of while
1371
1372    switch(action)
1373    {
1374       case SEARCH:
1375          {
1376             if(!found)
1377             {
1378                lcNode = NULLP;
1379             }
1380             return lcNode;
1381          }
1382
1383       case CREATE:
1384          {
1385             if(node != NULLP)
1386                return lcNode;
1387
1388             /*Need to add a new node for this LC*/
1389
1390             /*List is empty; Initialize the LL ControlPointer*/
1391             if(lcLL->count == 0)
1392             {
1393                cmLListInit(lcLL);
1394             }
1395
1396             lcNode = NULLP;
1397             /*Allocate the List*/
1398             SCH_ALLOC(lcNode, sizeof(LcInfo));
1399             if(lcNode)
1400             {
1401                lcNode->lcId = lcId;
1402                lcNode->reqBO = 0;
1403                lcNode->allocBO = 0;
1404                lcNode->allocPRB = 0;
1405             }
1406             else
1407             {
1408                DU_LOG("\nERROR  -->  SCH : Allocation of List failed,lcId:%d",lcId);
1409                return NULLP;
1410             }
1411
1412             if(addNodeToLList(lcLL, lcNode, NULLP) == RFAILED)
1413             {
1414                DU_LOG("\nERROR  -->  SCH : failed to Add Node,lcId:%d",lcId);
1415                SCH_FREE(lcNode, sizeof(LcInfo));
1416                return NULLP;
1417             }
1418             return lcNode;
1419          }
1420
1421       case DELETE:
1422          {
1423             if(!found ||  lcNode == NULLP)
1424             {
1425                DU_LOG("\nERROR  -->  SCH: LCID%d not found; thus Deletion unsuccessful",lcId);
1426             }
1427             else
1428             {
1429                if(deleteNodeFromLList(lcLL, node) == ROK)
1430                   SCH_FREE(lcNode, sizeof(LcInfo));
1431
1432                DU_LOG("\nDEBUG  -->  SCH: LCID%d Deleted successfully",lcId);
1433             }
1434             return NULLP; 
1435          }
1436       case PRINT:
1437       case TRAVERSE_ALL:
1438         {
1439            break;
1440         }
1441       default:
1442          {
1443             DU_LOG("\nERROR  -->  SCH: Action type wrong: %d",action);
1444             break;
1445          }
1446    }
1447    return lcNode;
1448 }
1449
1450 /**************************************************************************
1451  *
1452  * @brief Update ReqPRB for a partiular LCID in LC Linklist 
1453  *
1454  * @details
1455  *
1456  *    Function : updateLcListReqPRB
1457  *
1458  *    Functionality:
1459  *     Update ReqPRB for a partiular LCID in LC Linklist 
1460  *
1461  * @params[in] I/P > lcLinkList pointer (LcInfo list)
1462  *             I/P > lcId
1463  *             I/P > reqPRB
1464  *             I/P > payloadSize
1465  *
1466  * @return ROK/RFAILED
1467  *
1468  * ***********************************************************************/
1469 uint8_t updateLcListReqPRB(CmLListCp *lcLL, uint8_t lcId, uint32_t payloadSize)
1470 {
1471    LcInfo    *lcNode = NULLP;
1472    lcNode = handleLcLList(lcLL, lcId, CREATE);
1473
1474    if(lcNode == NULLP)
1475    {
1476       DU_LOG("\nERROR  -->  SCH : LC is neither present nor able to create in List lcId:%d",lcId);
1477       return RFAILED;
1478    }
1479
1480    lcNode->reqBO = payloadSize;
1481    lcNode->allocBO = 0;
1482    lcNode->allocPRB = 0; /*Re-Initializing the AllocPRB*/
1483    return ROK;
1484 }
1485
1486 /**************************************************************************
1487  *
1488  * @brief Delete entire LC Linklist 
1489  *
1490  * @details
1491  *
1492  *    Function : deleteLcLL
1493  *
1494  *    Functionality:
1495  *      Delete entire LC Linklist 
1496  *
1497  * @params[in] lcLinkList pointer (LcInfo list)
1498  *
1499  * @return void
1500  *
1501  * ***********************************************************************/
1502 void deleteLcLL(CmLListCp *lcLL)
1503 {
1504    CmLList *node = NULLP, *next = NULLP;
1505    LcInfo *lcNode = NULLP;
1506
1507    if(lcLL == NULLP)
1508    {
1509       DU_LOG("\nERROR  -->  SCH: LcList doesnt exist");
1510       return;
1511    }
1512    node = lcLL->first;
1513
1514    while(node)
1515    {
1516       next = node->next;
1517       lcNode = (LcInfo *)node->node;
1518       if(deleteNodeFromLList(lcLL, node) == ROK)
1519          SCH_FREE(lcNode, sizeof(LcInfo));
1520       node = next;
1521    }
1522 }
1523
1524 /****************************************************************************
1525  *
1526  * @brief Calculate the Estimated TBS Size based on Spec 38.421 , Sec 5.3.1.2
1527  *
1528  * @details
1529  *
1530  *    Function : calculateEstimateTBSize
1531  *
1532  *    Functionality:
1533  *       TBS Size calculation requires numPRB. Since exactPRB for reqBO is unknown thus 
1534  *       will give the PRB value(from 0 to maxRB) one by one and 
1535  *       try to find the TBS size closest to reqBO
1536  *
1537  * @params[in] I/P > reqBO, mcsIdx, num PDSCH symbols, 
1538  *             I/P > maxRB: Maximum PRB count to reach for calculating the TBS
1539  *             O/P > estPrb : Suitable PRB count for reaching the correct TBS
1540  *       
1541  *
1542  * @return TBS Size > Size which will can be allocated for this LC
1543  *        
1544  *
1545  *************************************************************************/
1546 uint32_t calculateEstimateTBSize(uint32_t reqBO, uint16_t mcsIdx, uint8_t numSymbols,\
1547                                    uint16_t maxPRB, uint16_t *estPrb)
1548 {
1549    uint32_t tbs = 0, effecBO = 0;
1550
1551    *estPrb = MIN_PRB;
1552    /*Loop Exit: Either estPRB reaches the maxRB or TBS is found greater than equal to reqBO*/
1553    do
1554    {
1555       tbs = schCalcTbSizeFromNPrb(*estPrb, mcsIdx, numSymbols);
1556
1557       /*TBS size calculated in above function is in Bits. 
1558        * So to convert it into Bytes , we right shift by 3. 
1559        * Eg: tbs=128 bits(1000 0000) ; Right Shift by 3: Tbs = 0001 0000(16 bytes)*/
1560       tbs = tbs >> 3;
1561       *estPrb += 1;
1562    }while((tbs < reqBO) && (*estPrb < maxPRB));
1563
1564    /*Effective BO is the Grant which can be provided for this LC.
1565     * Here,it is decided based on whether we can fully cater its requirment (reqBO) 
1566     * or has to provide lesser grant due to resource limitation.
1567     * Thus effective BO/Grant for this LC will be min of TBS calculated and reqBO*/
1568    effecBO = MIN(tbs,reqBO);
1569    return (effecBO);
1570 }
1571
1572
1573 /*******************************************************************
1574 *
1575 * @brief deleting Page Info node from PageInfo List
1576 *
1577 * @details
1578 *
1579 *    Function : schDeleteFromPageInfoList
1580 *
1581 *    Functionality: deleting page Info node from Page Info List
1582 *
1583 * @params[in] CmLListCp *list, CmLList *node 
1584 *
1585 * @return void 
1586 *
1587 * ****************************************************************/
1588 void schDeleteFromPageInfoList(CmLListCp *list, CmLList *node)
1589 {
1590    SchPageInfo *pageInfo;
1591
1592    if(node != NULLP)
1593    {
1594       pageInfo = (SchPageInfo *)node->node;
1595       if(deleteNodeFromLList(list, node) == ROK)
1596          SCH_FREE(pageInfo, sizeof(SchPageInfo));
1597    }
1598 }
1599
1600 /*******************************************************************
1601 *
1602 * @brief searching for Page at a particular SFN 
1603 *
1604 * @details
1605 *
1606 *    Function : schPageInfoSearchFromPageList
1607 *
1608 *    Functionality: searching for Page at a particular SFN 
1609 *
1610 * @params[in] SlotTimingInfo slotInfo, CmLListCp *storedPageList
1611 *
1612 * @return pointer to SchPageInfo
1613 *
1614 * ****************************************************************/
1615 CmLList *schPageInfoSearchFromPageList(SlotTimingInfo slotInfo, CmLListCp *storedPageList)
1616 {
1617    CmLList         *node = NULLP;
1618    SchPageInfo     *pageInfo = NULLP;
1619
1620    if(storedPageList->count)
1621    {
1622       CM_LLIST_FIRST_NODE(storedPageList, node);
1623       while(node)
1624       {
1625          pageInfo = (SchPageInfo*)node->node;
1626          if(pageInfo == NULLP)
1627          {
1628             DU_LOG("\nERROR  --> SCH: PageInfo empty");
1629          }
1630          else if(pageInfo->pageTxTime.sfn == slotInfo.sfn && 
1631                (pageInfo->pageTxTime.slot == slotInfo.slot))
1632          {
1633             return node;
1634          }
1635          node = node->next;
1636       }
1637    }
1638    return NULLP;
1639 }
1640
1641 /*Below function for printing will be used in future so disabling it for now*/
1642 #if 0
1643 /****************************************************************************
1644  *
1645  * @brief Print the LC in list for debugging purpose 
1646  *
1647  * @details
1648  *
1649  *    Function : printLcLL
1650  *
1651  *    Functionality:
1652  *            For debugging purpose, for printing the LC in the order and
1653  *            parameters
1654  *
1655  * @params[in] LcList pointer 
1656  *       
1657  * @return void 
1658  *        
1659  *************************************************************************/
1660 void printLcLL(CmLListCp *lcLL)
1661 {
1662    CmLList *node = NULLP;
1663    LcInfo *lcNode = NULLP;
1664
1665    if(lcLL == NULLP)
1666    {
1667       DU_LOG("\nINFO   -->  SCH: LcList doesnt exist");
1668       return;
1669    }
1670    node = lcLL->first;
1671    while(node)
1672    {
1673       lcNode = (LcInfo *)node->node;
1674       if(lcNode)
1675       {
1676          DU_LOG("\nINFO   -->  SCH : LcID:%d, [reqBO, allocBO, allocPRB]:[%d,%d,%d]",\
1677                lcNode->lcId,lcNode->reqBO, lcNode->allocBO, lcNode->allocPRB);
1678       }
1679
1680       node = node->next;
1681    }
1682 }
1683 #endif
1684
1685 #ifdef NR_TDD
1686
1687 /**
1688  * @brief determines slot/symbol format
1689  *
1690  * @details
1691  *
1692  *     Function : schGetSlotSymbFrmt 
1693  *      
1694  *      This API is invoked to determine if current slot is DL or UL
1695  *           
1696  *  @param[in]  uint16_t slot
1697  *  @param[in]  uint32_t bitMap from cellCb
1698  *  @return  SlotConfig
1699  *      -# DL    - 0 
1700  *      -# UL    - 1
1701  *      -# FLEXI - 2
1702  **/
1703 SlotConfig schGetSlotSymbFrmt(uint16_t slot, uint32_t bitMap)
1704 {
1705    uint32_t offset = (slot)*2;
1706    return (bitMap & 0x3<<offset)>>offset;
1707 #if 0
1708    SlotConfig slotFrmt;
1709    int mask1 = 0, mask2 = 0;
1710
1711    slot = (slot%n)*2;//n num of slots in defined periodicity or num of symbols
1712    mask1 = 1<<(slot);
1713    mask2 = 1<<(slot+1);
1714    slotFrmt = ((mask1 & bitMap)>>slot) + (2*((mask2 & bitMap)>>(slot+1)));
1715
1716    //printf("\n\n\n\n*****FormatType:%d Slot:%d****\n\n\n\n", slotFrmt, slot/2);
1717
1718    return slotFrmt;
1719 #endif
1720 }
1721
1722 /**
1723  * @brief Determine total length of configured slot pattern for specific 
1724  *    periodicity for TDD
1725  *
1726  * @details
1727  *
1728  *     Function : calculateSlotPatternLength 
1729  *      
1730  *      Determine total length of configured slot pattern for specific periodicity based
1731  *      on slot duration for TDD
1732  *           
1733  *  @param[in]  uint8_t scs, uint8_t periodicity 
1734  *
1735  *  @return uint8_t slotPatternLength 
1736  **/
1737
1738 uint8_t calculateSlotPatternLength(uint8_t scs, uint8_t periodicity)
1739 {
1740    uint8_t slotPatternLength =0;
1741    float   slotDuration = 0;
1742    
1743    /* Calculating the slot duration with the help of SCS.
1744     * This will provides the slot duration in ms like 1, 0.5, 0.25, 0.125. 
1745     * If scs value is SCS_30KHZ its enum value is 1, 
1746     * slotDuration = pow(0.5, 1);
1747     * slotDuration = 0.5 */
1748
1749    slotDuration = pow(0.5,scs);
1750
1751    /* Calculating length of pattern based on Transmission Periodicity. 
1752     * If periodicity = TX_PRDCTY_MS_5,
1753     * slotPatternLength = 5/0.5 
1754     * slotPatternLength = 10 i.e. {length of slot pattern DDDDDDDFUU}*/
1755
1756    switch(periodicity)
1757    {
1758       case TX_PRDCTY_MS_0P5:
1759          slotPatternLength = 0.5/slotDuration;
1760          break;
1761       case TX_PRDCTY_MS_0P625:
1762          slotPatternLength = 0.625/slotDuration;
1763          break;
1764       case TX_PRDCTY_MS_1:
1765          slotPatternLength = 1/slotDuration;
1766          break;
1767       case TX_PRDCTY_MS_1P25:
1768          slotPatternLength = 1.25/slotDuration;
1769          break;
1770       case TX_PRDCTY_MS_2:
1771          slotPatternLength = 2/slotDuration;
1772          break;
1773       case TX_PRDCTY_MS_2P5:
1774          slotPatternLength = 2.5/slotDuration;
1775          break;
1776       case TX_PRDCTY_MS_5:
1777          slotPatternLength = 5/slotDuration;
1778          break;
1779       case TX_PRDCTY_MS_10:
1780          slotPatternLength = 10/slotDuration;
1781          break;
1782    }
1783    return slotPatternLength;
1784 }
1785 #endif
1786
1787 /*
1788  * As per FAPI spec, 
1789  * Frequency domain resources is a bitmap defining non-overlapping groups of 6 PRBs in ascending order.
1790  * [TS38.213 10.1]. Bitmap of uint8 array. 45 bits.
1791  *
1792  * As per IAPI,
1793  * CORESET-freqdom.frequencyDomainResources : The bits of the bitmap have a one-to-one mapping with
1794  * non-overlapping groups of 6 RBs. The most significant bit of the first word corresponds to
1795  * the most significant bit defined in 38.331.
1796  *
1797  * FAPI and IAPI both are 45 bits. Mapped from bit 0 LS Byte for the FAPI and
1798  * bit 0 LS U32 entry for IAPI.
1799  * FAPI is to be filled in following format such that Intel L1 is able to decode it :
1800  *
1801  *            FAPI                                 IAPI 
1802  * FreqDomainResource[0] bits 7-0     ->    nFreqDomain[0] bits 7-0
1803  * FreqDomainResource[1] bits 7-0     ->    nFreqDomain[0] bits 15-8
1804  * FreqDomainResource[2] bits 7-0     ->    nFreqDomain[0] bits 23-16
1805  * FreqDomainResource[3] bits 7-0     ->    nFreqDomain[0] bits 31-24
1806  * FreqDomainResource[4] bits 7-0     ->    nFreqDomain[1] bits 7-0
1807  * FreqDomainResource[5] bits 7-0     ->    nFreqDomain[1] bits 15-8
1808  *
1809  * where for the last entry bits 7,6 and 5 are don't care in the FAPI and bits
1810  * 31-13 are don't care in the IAPI.
1811  */
1812 void covertFreqDomRsrcMapToIAPIFormat(uint8_t *sourceBitMap, uint8_t *destBitMap)
1813 {
1814    int8_t  idx;
1815    uint8_t  numBitsToShift = 0;
1816    uint64_t freqDomainResources = 0;
1817
1818    /* Bit operation to create a 64-bit integer that has
1819     * 48 LSBs [Bit 47 to Bit 0] mapped to sourceBitMap[0] to sourceBitMap[5]
1820     */
1821    for(idx = FREQ_DOM_RSRC_SIZE-1; idx >=0; idx--)
1822    {
1823       freqDomainResources |= ((uint64_t)sourceBitMap[idx] << numBitsToShift);
1824       numBitsToShift += 8;
1825    }
1826
1827    /* Right shift 3 bits because bits[2-0] are unused in sourceBitMap[5] */
1828    freqDomainResources = freqDomainResources >> 3;
1829
1830    /* Filling destBitMap such that LSB bit 0 of freqDomainResources maps to LSB 
1831     * of first word of destBitMap */
1832    numBitsToShift = 0;
1833    for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
1834    {
1835       destBitMap[idx] = freqDomainResources >> numBitsToShift;
1836       numBitsToShift += 8;
1837    }
1838 }
1839 /**********************************************************************
1840          End of file
1841 **********************************************************************/