[Epic-ID: ODUHIGH-][Task-ID: ODUHIGH-]WG8 alignment | Cell conf
[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->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       cellCb->api->SchInitUlHqProcCb(hqP);
88       schUlHqAddToFreeList(hqP);
89    }
90 }
91
92 /**
93  * @brief Add hq process to free list of UL Harq entity
94  *
95  * @details
96  *
97  *     Function : schUlHqAddToFreeList
98  *      
99  *      This function adds hq process to free list of UL Harq entity
100  *           
101  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
102  *  @return  
103  *      -# void
104  **/
105 void schUlHqAddToFreeList(SchUlHqProcCb *hqP)
106 {
107    cmLListAdd2Tail(&(hqP->hqEnt->free), &hqP->ulHqEntLnk);
108 }
109 /**
110  * @brief Delete hq process from free list of UL Harq entity
111  *
112  * @details
113  *
114  *     Function : schUlHqDeleteFromFreeList
115  *      
116  *      This function deletes hq process to free list of UL Harq entity
117  *           
118  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
119  *  @return  
120  *      -# void
121  **/
122 void schUlHqDeleteFromFreeList(SchUlHqProcCb *hqP)
123 {
124    if(hqP->hqEnt->free.count == 0)
125    {
126       DU_LOG("\n ERROR schUlHqDeleteFromInUseList no proc in in free\n");
127    }
128    cmLListDelFrm(&(hqP->hqEnt->free), &hqP->ulHqEntLnk);
129 }
130 /**
131  * @brief Add hq process to in use list of UL Harq entity
132  *
133  * @details
134  *
135  *     Function : schUlHqAddToInUseList
136  *      
137  *      This function adds hq process to in use list of UL Harq entity
138  *           
139  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
140  *  @return  
141  *      -# void
142  **/
143 void schUlHqAddToInUseList(SchUlHqProcCb *hqP)
144 {
145    cmLListAdd2Tail(&(hqP->hqEnt->inUse), &hqP->ulHqEntLnk);
146 }
147 /**
148  * @brief Delete hq process from in use list of UL Harq entity
149  *
150  * @details
151  *
152  *     Function : schUlHqDeleteFromInUseList
153  *      
154  *      This function deletes hq process to in use list of UL Harq entity
155  *           
156  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
157  *  @return  
158  *      -# void
159  **/
160 void schUlHqDeleteFromInUseList(SchUlHqProcCb *hqP)
161 {
162    if(hqP->hqEnt->inUse.count == 0)
163    {
164       DU_LOG("\n ERROR schUlHqDeleteFromInUseList no proc in in use\n");
165    }
166    cmLListDelFrm(&(hqP->hqEnt->inUse), &hqP->ulHqEntLnk);
167 }
168 /**
169  * @brief Get available Harq process from Harq entity
170  *
171  * @details
172  *
173  *     Function : schUlGetAvlHqProcess
174  *      
175  *      This function fetches hq process from free list and puts in in use list
176  *           
177  *  @param[in]  SchCellCb *cellCb, cell cb pointer
178  *  @param[in]  SchUeCb *ueCb, ue cb pointer
179  *  @param[in]  SchUlHqProcCb **hqP, Address of UL harq process pointer
180  *  @return  
181  *      -# ROK
182  *      -# RFAILED
183  **/
184 uint8_t schUlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchUlHqProcCb **hqP)
185 {
186    SchUlHqProcCb                  *tmp;
187    if (ueCb->ulHqEnt.free.count == 0)
188    {
189       return RFAILED;
190    }
191    tmp = (SchUlHqProcCb*)(cmLListFirst(&(ueCb->ulHqEnt.free))->node);
192    if (NULLP == tmp)
193    {
194       return RFAILED;
195    }
196    schUlHqDeleteFromFreeList(tmp);
197    schUlHqAddToInUseList(tmp);
198    *hqP = tmp;
199    (*hqP)->maxHqTxPerHqP = ueCb->ulHqEnt.maxHqTx;
200    return ROK;
201 }
202 /**
203  * @brief Release Harq process from the UL Harq entity
204  *
205  * @details
206  *
207  *     Function : schUlReleaseHqProcess
208  *      
209  *      This function releases Harq process from UL Harq entity
210  *           
211  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
212  *  @param[in]  Bool togNdi, indication to togle NDI bit
213  *  @return  
214  *      -# void
215  **/
216 void schUlReleaseHqProcess(SchUlHqProcCb *hqP, Bool togNdi)
217 {
218    SchCellCb  *cellCb = NULLP;
219    if (togNdi == TRUE)
220    {
221       hqP->tbInfo.ndi ^= 1;
222    }
223
224    cellCb = hqP->hqEnt->cell;
225    cellCb->api->SchFreeUlHqProcCb(hqP);
226    
227    schUlHqDeleteFromInUseList(hqP);
228    schUlHqAddToFreeList(hqP);
229 }
230 /**
231  * @brief Handles NACK for UL Harq process
232  *
233  * @details
234  *
235  *     Function : schUlHqProcessNack
236  *      
237  *      This function handle NACK for  UL Harq process
238  *           
239  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
240  *  @return  
241  *      -# void
242  **/
243 void schUlHqProcessNack(SchUlHqProcCb *hqP)
244 {
245    if (hqP->tbInfo.txCntr < hqP->maxHqTxPerHqP)
246    {
247        hqP->hqEnt->cell->api->SchAddToUlHqRetxList(hqP);
248    }
249    else
250    {
251       schUlReleaseHqProcess(hqP, TRUE);
252    }
253 }
254 /**
255  * @brief Handles ACK for UL Harq process
256  *
257  * @details
258  *
259  *     Function : schUlHqProcessAck
260  *      
261  *      This function handles ACK for UL Harq process
262  *           
263  *  @param[in]  SchUlHqProcCb *hqP, UL harq process pointer
264  *  @return  
265  *      -# void
266  **/
267 void schUlHqProcessAck(SchUlHqProcCb *hqP)
268 {
269    schUlReleaseHqProcess(hqP, TRUE);
270 }
271
272 /**
273  * @brief Deletes HARQ Entity
274  *
275  * @details
276  *
277  *     Function : schUlHqEntDelete
278  *      
279  *      This function deletes HARQ entity and its member paremeters
280  *           
281  *  @param[in]  Pointer to UE
282  *  @return  
283  *      -# void
284  **/
285 void schUlHqEntDelete(SchUeCb *ueCb)
286 {
287   uint8_t count;
288   SchUlHqProcCb *hqP;
289
290   cmLListDeleteLList(&ueCb->ulHqEnt.free);
291   cmLListDeleteLList(&ueCb->ulHqEnt.inUse);
292   for(count=0; count < ueCb->ulHqEnt.numHqPrcs; count++)
293   {
294      hqP = &(ueCb->ulHqEnt.procs[count]);
295      ueCb->cellCb->api->SchDeleteUlHqProcCb(hqP);
296   }
297   memset(&ueCb->ulHqEnt, 0, sizeof(SchUlHqEnt));
298 }
299
300 /**********************************************************************
301   End of file
302  **********************************************************************/