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