1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
28 #include "sch_utils.h"
34 typedef struct schCellCb SchCellCb;
35 typedef struct schUeCb SchUeCb;
36 void schDlHqEntReset(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqEnt *hqE);
37 void schDlHqAddToFreeList(SchDlHqProcCb *hqP);
40 * @brief DL Harq entity intialization
44 * Function : schDlHqEntInit
46 * This function intialize DL Harq entity
48 * @param[in] SchCellCb *cellCb, cell cb pointer
49 * @param[in] SchUeCb *ueCb, ue cb pointer
53 void schDlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb)
55 ueCb->dlHqEnt.numHqPrcs = SCH_MAX_NUM_DL_HQ_PROC;
56 ueCb->dlHqEnt.maxHqTx = cellCb->schHqCfg.maxDlDataHqTx;
57 ueCb->dlHqEnt.cell = cellCb;
58 ueCb->dlHqEnt.ue =ueCb;
59 schDlHqEntReset(cellCb, ueCb, &ueCb->dlHqEnt);
62 * @brief DL Harq entity Reset
66 * Function : schDlHqEntReset
68 * This function Reset DL Harq entity
70 * @param[in] SchCellCb *cellCb, cell cb pointer
71 * @param[in] SchUeCb *ueCb, ue cb pointer
72 * @param[in] SchDlHqEnt *hqE, Dl Harq entity pointer
76 void schDlHqEntReset(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqEnt *hqE)
79 SchDlHqProcCb *hqP = NULL;
80 cmLListInit(&hqE->free);
81 cmLListInit(&hqE->inUse);
83 for(count=0; count < hqE->numHqPrcs; count++)
85 hqP = &(hqE->procs[count]);
88 hqP->maxHqTxPerHqP = hqE->maxHqTx;
89 hqP->dlHqEntLnk.node = (PTR)hqP;
90 hqP->dlHqProcLink.node = (PTR)hqP;
91 hqP->ulSlotLnk.node = (PTR)hqP;
92 cellCb->api->SchInitDlHqProcCb(hqP);
93 schDlHqAddToFreeList(hqP);
97 * @brief Add hq process to free list of DL Harq entity
101 * Function : schDlHqAddToFreeList
103 * This function adds hq process to free list of DL Harq entity
105 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
109 void schDlHqAddToFreeList(SchDlHqProcCb *hqP)
111 cmLListAdd2Tail(&(hqP->hqEnt->free), &hqP->dlHqEntLnk);
114 * @brief Delete hq process from free list of DL Harq entity
118 * Function : schDlHqDeleteFromFreeList
120 * This function deletes hq process to free list of DL Harq entity
122 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
126 void schDlHqDeleteFromFreeList(SchDlHqProcCb *hqP)
128 cmLListDelFrm(&(hqP->hqEnt->free), &hqP->dlHqEntLnk);
131 * @brief Add hq process to in use list of DL Harq entity
135 * Function : schDlHqAddToInUseList
137 * This function adds hq process to in use list of DL Harq entity
139 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
143 void schDlHqAddToInUseList(SchDlHqProcCb *hqP)
145 cmLListAdd2Tail(&(hqP->hqEnt->inUse), &hqP->dlHqEntLnk);
148 * @brief Delete hq process from in use list of DL Harq entity
152 * Function : schDlHqDeleteFromInUseList
154 * This function deletes hq process to in use list of DL Harq entity
156 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
160 void schDlHqDeleteFromInUseList(SchDlHqProcCb *hqP)
162 cmLListDelFrm(&(hqP->hqEnt->inUse), &hqP->dlHqEntLnk);
165 * @brief Get available Harq process from Harq entity
169 * Function : schDlGetAvlHqProcess
171 * This function fetches hq process from free list and puts in in use list
173 * @param[in] SchCellCb *cellCb, cell cb pointer
174 * @param[in] SchUeCb *ueCb, ue cb pointer
175 * @param[in] SchDlHqProcCb **hqP, Address of DL harq process pointer
180 uint8_t schDlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqProcCb **hqP)
183 if (ueCb->dlHqEnt.free.count == 0)
187 tmp = (SchDlHqProcCb*)(cmLListFirst(&(ueCb->dlHqEnt.free))->node);
192 schDlHqDeleteFromFreeList(tmp);
193 schDlHqAddToInUseList(tmp);
195 (*hqP)->maxHqTxPerHqP = ueCb->dlHqEnt.maxHqTx;
199 * @brief Release Harq process from the DL Harq entity
203 * Function : schDlReleaseHqProcess
205 * This function releases Harq process from DL Harq entity
207 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
211 void schDlReleaseHqProcess(SchDlHqProcCb *hqP)
213 SchCellCb *cellCb = NULLP;
216 cellCb = hqP->hqEnt->cell;
217 cellCb->api->SchFreeDlHqProcCb(hqP);
218 schDlHqDeleteFromInUseList(hqP);
219 schDlHqAddToFreeList(hqP);
223 /*******************************************************************
225 * @brief Handles sending DL HARQ process release to MAC
229 * Function : sendDlHarqProcReleaseToMac
232 * Sends DL DL HARQ process release to MAC from SCH
235 * @return ROK - success
238 * ****************************************************************/
239 uint8_t sendDlHarqProcReleaseToMac(SchDlHqProcCb *hqP, Inst inst)
242 SchRlsHqInfo *rlsHqInfo;
243 memset(&pst, 0, sizeof(Pst));
244 FILL_PST_SCH_TO_MAC(pst, inst);
245 pst.event = EVENT_DL_REL_HQ_PROC;
247 SCH_ALLOC(rlsHqInfo, sizeof(SchRlsHqInfo));
248 rlsHqInfo->cellId = hqP->hqEnt->cell->cellId;
249 rlsHqInfo->numUes = 1;
251 SCH_ALLOC(rlsHqInfo->ueHqInfo, sizeof(SchUeHqInfo)*rlsHqInfo->numUes);
252 rlsHqInfo->ueHqInfo[0].crnti = hqP->hqEnt->ue->crnti;
253 rlsHqInfo->ueHqInfo[0].hqProcId = hqP->procId;
255 return(MacMessageRouter(&pst, (void *)rlsHqInfo));
258 * @brief Release Harq process TB from the DL Harq process
262 * Function : schDlReleaseHqPTb
264 * This function releases Harq process TB from DL Harq proces
266 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
267 * @param[in] uint8_t tbIdx, TB index
268 * @param[in] bool togNdi, indication to toggle NDI bit
272 void schDlReleaseHqPTb(SchDlHqProcCb *hqP, uint8_t tbIdx, bool togNdi)
276 hqP->tbInfo[tbIdx].ndi ^= 1;
280 hqP->tbInfo[tbIdx].isAckNackDtx = HQ_ACK;
281 hqP->tbInfo[tbIdx].isEnabled = FALSE;
282 hqP->tbInfo[tbIdx].state = HQ_TB_ACKED;
283 hqP->tbInfo[tbIdx].txCntr = 0;
284 if (HQ_TB_ACKED == hqP->tbInfo[tbIdx^1].state)
286 schDlReleaseHqProcess(hqP);
287 sendDlHarqProcReleaseToMac(hqP, hqP->hqEnt->cell->instIdx);
292 * @brief Handles failure of HARQ process TB
296 * Function : schDlHqTbFail
298 * This function handles failure of HARQ process TB
300 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
301 * @param[in] uint8_t tbIdx, TB index
302 * @param[in] bool isMaxRetx, indicates max retransmission
306 void schDlHqTbFail(SchDlHqProcCb *hqP, uint8_t tbIdx, bool isMaxRetx)
310 schDlReleaseHqPTb(hqP, tbIdx, TRUE);
314 hqP->tbInfo[tbIdx].state = HQ_TB_NACKED;
315 if (HQ_TB_WAITING == hqP->tbInfo[tbIdx^1].state)
317 hqP->hqEnt->cell->api->SchAddToDlHqRetxList(hqP);
322 * @brief Handles Harq feedback for MSG4
326 * Function : schMsg4FeedbackUpdate
328 * This function handles Harq feedback for MSG4
330 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
331 * @param[in] uint8_t fdbk, Received feedback
335 void schMsg4FeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk)
337 hqP->tbInfo[0].isAckNackDtx = fdbk;
338 hqP->tbInfo[1].isAckNackDtx = HQ_TB_ACKED;
339 if (HQ_TB_ACKED == hqP->tbInfo[0].isAckNackDtx)
341 schDlReleaseHqPTb(hqP, 0, TRUE);
342 schDlReleaseHqPTb(hqP, 1, TRUE);
343 schMsg4Complete(hqP->hqEnt->ue);
347 if( hqP->tbInfo[0].txCntr >= hqP->hqEnt->cell->schHqCfg.maxMsg4HqTx)
349 schDlReleaseHqProcess(hqP);
350 hqP->hqEnt->ue->msg4HqProc = NULLP;
351 hqP->hqEnt->ue->retxMsg4HqProc = NULLP;
352 /* Delete UE and RA context */
354 hqP->hqEnt->cell->api->SchAddUeToSchedule(hqP->hqEnt->cell,hqP->hqEnt->ue->ueId);
355 hqP->hqEnt->ue->retxMsg4HqProc = hqP;
360 * @brief Handles Harq feedback for DL Data
364 * Function : schDlHqFeedbackUpdate
366 * This function handles Harq feedback for DL data
368 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
369 * @param[in] uint8_t fdbk1, Received feedback for TB -0
370 * @param[in] uint8_t fdbk2, Received feedback for TB -1
374 void schDlHqFeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk1, uint8_t fdbk2)
377 for (tbIdx = 0; tbIdx <2; tbIdx++)
379 if (HQ_TB_WAITING == hqP->tbInfo[tbIdx].state)
381 hqP->tbInfo[tbIdx].isAckNackDtx = (0 == tbIdx)?fdbk1:fdbk2;
383 if (TRUE == hqP->tbInfo[tbIdx].isEnabled)
385 if (HQ_TB_ACKED == hqP->tbInfo[tbIdx].isAckNackDtx)
387 schDlReleaseHqPTb(hqP, tbIdx, TRUE);
391 if(hqP->tbInfo[tbIdx].txCntr >= hqP->maxHqTxPerHqP)
393 schDlHqTbFail(hqP, tbIdx, TRUE);
397 schDlHqTbFail(hqP, tbIdx, FALSE);
405 * @brief Deletes HARQ Entity
409 * Function : schDlHqEntDelete
411 * This function deletes HARQ entity and its member paremeters
413 * @param[in] Pointer to UE
417 void schDlHqEntDelete(SchUeCb *ueCb)
422 cmLListDeleteLList(&ueCb->dlHqEnt.free);
423 cmLListDeleteLList(&ueCb->dlHqEnt.inUse);
424 for(count=0; count < ueCb->dlHqEnt.numHqPrcs; count++)
426 hqP = &(ueCb->dlHqEnt.procs[count]);
427 ueCb->cellCb->api->SchDeleteDlHqProcCb(hqP);
429 memset(&ueCb->dlHqEnt, 0, sizeof(SchDlHqEnt));
432 /**********************************************************************
434 **********************************************************************/