[ Jira id - ODUHIGH-593 ] Pack and unpack function nomenclature correction
[o-du/l2.git] / src / 5gnrsch / sch_harq_ul.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 #include "common_def.h"
19 #include "tfu.h"
20 #include "lrg.h"
21 #include "tfu.x"
22 #include "lrg.x"
23 #include "du_log.h"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
26 #include "sch.h"
27 #include "sch_tmr.h"
28 #include "sch_utils.h"
29 #ifdef NR_DRX
30 #include "sch_drx.h"
31 #endif
32 typedef struct schCellCb SchCellCb;
33 typedef struct schUeCb SchUeCb;
34 void schUlHqEntReset(SchCellCb *cellCb, SchUeCb *ueCb, SchUlHqEnt *hqE);
35 void schUlHqAddToFreeList(SchUlHqProcCb *hqP);
36 /**
37  * @brief UL Harq entity intialization
38  *
39  * @details
40  *
41  *     Function : schUlHqEntInit
42  *      
43  *      This function intialize UL Harq entity
44  *           
45  *  @param[in]  SchCellCb *cellCb, cell cb pointer
46  *  @param[in]  SchUeCb *ueCb, ue cb pointer
47  *  @return  
48  *      -# void
49  **/
50 void schUlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb)
51 {
52    ueCb->ulHqEnt.numHqPrcs = SCH_MAX_NUM_UL_HQ_PROC;
53    ueCb->ulHqEnt.maxHqTx  = cellCb->schHqCfg.maxUlDataHqTx;
54    ueCb->ulHqEnt.cell = cellCb;
55    ueCb->ulHqEnt.ue =ueCb;
56    schUlHqEntReset(cellCb, ueCb, &ueCb->ulHqEnt);
57 }
58 /**
59  * @brief UL Harq entity Reset
60  *
61  * @details
62  *
63  *     Function : schUlHqEntReset
64  *      
65  *      This function Reset UL Harq entity
66  *           
67  *  @param[in]  SchCellCb *cellCb, cell cb pointer
68  *  @param[in]  SchUeCb *ueCb, ue cb pointer
69  *  @param[in]  SchUlHqEnt *hqE, Ul Harq entity pointer
70  *  @return  
71  *      -# void
72  **/
73 void schUlHqEntReset(SchCellCb *cellCb, SchUeCb *ueCb, SchUlHqEnt *hqE)
74 {
75    uint8_t count = 0;
76    SchUlHqProcCb *hqP = NULL;
77    cmLListInit(&hqE->free);
78    cmLListInit(&hqE->inUse);
79    for(count=0; count < hqE->numHqPrcs; count++)
80    {
81       hqP = &(hqE->procs[count]);
82       hqP->procId = count;
83       hqP->hqEnt = hqE;
84       hqP->maxHqTxPerHqP = hqE->maxHqTx;
85       hqP->ulHqEntLnk.node = (PTR)hqP;
86       hqP->ulHqProcLink.node = (PTR)hqP;
87       hqP->ulSlotLnk.node = (PTR)hqP;
88       cellCb->api->SchInitUlHqProcCb(hqP);
89       schUlHqAddToFreeList(hqP);
90    }
91 }
92
93 /**
94  * @brief Add hq process to free list of UL Harq entity
95  *
96  * @details
97  *
98  *     Function : schUlHqAddToFreeList
99  *      
100  *      This function adds hq process to free list of UL Harq entity
101  *           
102  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
103  *  @return  
104  *      -# void
105  **/
106 void schUlHqAddToFreeList(SchUlHqProcCb *hqP)
107 {
108    cmLListAdd2Tail(&(hqP->hqEnt->free), &hqP->ulHqEntLnk);
109 }
110 /**
111  * @brief Delete hq process from free list of UL Harq entity
112  *
113  * @details
114  *
115  *     Function : schUlHqDeleteFromFreeList
116  *      
117  *      This function deletes hq process to free list of UL Harq entity
118  *           
119  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
120  *  @return  
121  *      -# void
122  **/
123 void schUlHqDeleteFromFreeList(SchUlHqProcCb *hqP)
124 {
125    if(hqP->hqEnt->free.count == 0)
126    {
127       DU_LOG("\n ERROR schUlHqDeleteFromInUseList no proc in in free\n");
128    }
129    cmLListDelFrm(&(hqP->hqEnt->free), &hqP->ulHqEntLnk);
130 }
131 /**
132  * @brief Add hq process to in use list of UL Harq entity
133  *
134  * @details
135  *
136  *     Function : schUlHqAddToInUseList
137  *      
138  *      This function adds hq process to in use list of UL Harq entity
139  *           
140  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
141  *  @return  
142  *      -# void
143  **/
144 void schUlHqAddToInUseList(SchUlHqProcCb *hqP)
145 {
146    cmLListAdd2Tail(&(hqP->hqEnt->inUse), &hqP->ulHqEntLnk);
147 }
148 /**
149  * @brief Delete hq process from in use list of UL Harq entity
150  *
151  * @details
152  *
153  *     Function : schUlHqDeleteFromInUseList
154  *      
155  *      This function deletes hq process to in use list of UL Harq entity
156  *           
157  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
158  *  @return  
159  *      -# void
160  **/
161 void schUlHqDeleteFromInUseList(SchUlHqProcCb *hqP)
162 {
163    if(hqP->hqEnt->inUse.count == 0)
164    {
165       DU_LOG("\n ERROR schUlHqDeleteFromInUseList no proc in in use\n");
166    }
167    cmLListDelFrm(&(hqP->hqEnt->inUse), &hqP->ulHqEntLnk);
168 }
169 /**
170  * @brief Get available Harq process from Harq entity
171  *
172  * @details
173  *
174  *     Function : schUlGetAvlHqProcess
175  *      
176  *      This function fetches hq process from free list and puts in in use list
177  *           
178  *  @param[in]  SchCellCb *cellCb, cell cb pointer
179  *  @param[in]  SchUeCb *ueCb, ue cb pointer
180  *  @param[in]  SchUlHqProcCb **hqP, Address of UL harq process pointer
181  *  @return  
182  *      -# ROK
183  *      -# RFAILED
184  **/
185 uint8_t schUlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchUlHqProcCb **hqP)
186 {
187    SchUlHqProcCb                  *tmp;
188    if (ueCb->ulHqEnt.free.count == 0)
189    {
190       return RFAILED;
191    }
192    tmp = (SchUlHqProcCb*)(cmLListFirst(&(ueCb->ulHqEnt.free))->node);
193    if (NULLP == tmp)
194    {
195       return RFAILED;
196    }
197    schUlHqDeleteFromFreeList(tmp);
198    schUlHqAddToInUseList(tmp);
199    *hqP = tmp;
200    (*hqP)->maxHqTxPerHqP = ueCb->ulHqEnt.maxHqTx;
201    return ROK;
202 }
203 /**
204  * @brief Release Harq process from the UL Harq entity
205  *
206  * @details
207  *
208  *     Function : schUlReleaseHqProcess
209  *      
210  *      This function releases Harq process from UL Harq entity
211  *           
212  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
213  *  @param[in]  Bool togNdi, indication to togle NDI bit
214  *  @return  
215  *      -# void
216  **/
217 void schUlReleaseHqProcess(SchUlHqProcCb *hqP, Bool togNdi)
218 {
219    SchCellCb  *cellCb = NULLP;
220    if (togNdi == TRUE)
221    {
222       hqP->tbInfo.ndi ^= 1;
223    }
224
225    cellCb = hqP->hqEnt->cell;
226    cellCb->api->SchFreeUlHqProcCb(hqP);
227    
228    schUlHqDeleteFromInUseList(hqP);
229    schUlHqAddToFreeList(hqP);
230 }
231 /**
232  * @brief Handles NACK for UL Harq process
233  *
234  * @details
235  *
236  *     Function : schUlHqProcessNack
237  *      
238  *      This function handle NACK for  UL Harq process
239  *           
240  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
241  *  @return  
242  *      -# void
243  **/
244 void schUlHqProcessNack(SchUlHqProcCb *hqP)
245 {
246    if (hqP->tbInfo.txCntr < hqP->maxHqTxPerHqP)
247    {
248        hqP->hqEnt->cell->api->SchAddToUlHqRetxList(hqP);
249    }
250    else
251    {
252       schUlReleaseHqProcess(hqP, TRUE);
253    }
254 }
255 /**
256  * @brief Handles ACK for UL Harq process
257  *
258  * @details
259  *
260  *     Function : schUlHqProcessAck
261  *      
262  *      This function handles ACK for UL Harq process
263  *           
264  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
265  *  @return  
266  *      -# void
267  **/
268 void schUlHqProcessAck(SchUlHqProcCb *hqP)
269 {
270    schUlReleaseHqProcess(hqP, TRUE);
271 }
272
273 /**
274  * @brief Deletes HARQ Entity
275  *
276  * @details
277  *
278  *     Function : schUlHqEntDelete
279  *      
280  *      This function deletes HARQ entity and its member paremeters
281  *           
282  *  @param[in]  Pointer to UE
283  *  @return  
284  *      -# void
285  **/
286 void schUlHqEntDelete(SchUeCb *ueCb)
287 {
288   uint8_t count;
289   SchUlHqProcCb *hqP;
290
291   cmLListDeleteLList(&ueCb->ulHqEnt.free);
292   cmLListDeleteLList(&ueCb->ulHqEnt.inUse);
293   for(count=0; count < ueCb->ulHqEnt.numHqPrcs; count++)
294   {
295      hqP = &(ueCb->ulHqEnt.procs[count]);
296      ueCb->cellCb->api->SchDeleteUlHqProcCb(hqP);
297   }
298   memset(&ueCb->ulHqEnt, 0, sizeof(SchUlHqEnt));
299 }
300
301 /**********************************************************************
302   End of file
303  **********************************************************************/