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