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"
27 #include "sch_utils.h"
30 SchMacDlReleaseHarqFunc schMacDlReleaseHarqOpts[] =
32 packSchMacDlReleaseHarq,
33 MacSchReleaseDlHarqProc,
34 packSchMacDlReleaseHarq
37 typedef struct schCellCb SchCellCb;
38 typedef struct schUeCb SchUeCb;
39 void schDlHqEntReset(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqEnt *hqE);
40 void schDlHqAddToFreeList(SchDlHqProcCb *hqP);
43 * @brief DL Harq entity intialization
47 * Function : schDlHqEntInit
49 * This function intialize DL Harq entity
51 * @param[in] SchCellCb *cellCb, cell cb pointer
52 * @param[in] SchUeCb *ueCb, ue cb pointer
56 void schDlHqEntInit(SchCellCb *cellCb, SchUeCb *ueCb)
58 ueCb->dlHqEnt.numHqPrcs = SCH_MAX_NUM_DL_HQ_PROC;
59 ueCb->dlHqEnt.maxHqTx = cellCb->cellCfg.schHqCfg.maxDlDataHqTx;
60 ueCb->dlHqEnt.cell = cellCb;
61 ueCb->dlHqEnt.ue =ueCb;
62 schDlHqEntReset(cellCb, ueCb, &ueCb->dlHqEnt);
65 * @brief DL Harq entity Reset
69 * Function : schDlHqEntReset
71 * This function Reset DL Harq entity
73 * @param[in] SchCellCb *cellCb, cell cb pointer
74 * @param[in] SchUeCb *ueCb, ue cb pointer
75 * @param[in] SchDlHqEnt *hqE, Dl Harq entity pointer
79 void schDlHqEntReset(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqEnt *hqE)
82 SchDlHqProcCb *hqP = NULL;
83 cmLListInit(&hqE->free);
84 cmLListInit(&hqE->inUse);
86 for(count=0; count < hqE->numHqPrcs; count++)
88 hqP = &(hqE->procs[count]);
91 hqP->maxHqTxPerHqP = hqE->maxHqTx;
92 hqP->dlHqEntLnk.node = (PTR)hqP;
93 hqP->dlHqProcLink.node = (PTR)hqP;
94 hqP->ulSlotLnk.node = (PTR)hqP;
95 schDlHqAddToFreeList(hqP);
99 * @brief Add hq process to free list of DL Harq entity
103 * Function : schDlHqAddToFreeList
105 * This function adds hq process to free list of DL Harq entity
107 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
111 void schDlHqAddToFreeList(SchDlHqProcCb *hqP)
113 cmLListAdd2Tail(&(hqP->hqEnt->free), &hqP->dlHqEntLnk);
116 * @brief Delete hq process from free list of DL Harq entity
120 * Function : schDlHqDeleteFromFreeList
122 * This function deletes hq process to free list of DL Harq entity
124 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
128 void schDlHqDeleteFromFreeList(SchDlHqProcCb *hqP)
130 cmLListDelFrm(&(hqP->hqEnt->free), &hqP->dlHqEntLnk);
133 * @brief Add hq process to in use list of DL Harq entity
137 * Function : schDlHqAddToInUseList
139 * This function adds hq process to in use list of DL Harq entity
141 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
145 void schDlHqAddToInUseList(SchDlHqProcCb *hqP)
147 cmLListAdd2Tail(&(hqP->hqEnt->inUse), &hqP->dlHqEntLnk);
150 * @brief Delete hq process from in use list of DL Harq entity
154 * Function : schDlHqDeleteFromInUseList
156 * This function deletes hq process to in use list of DL Harq entity
158 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
162 void schDlHqDeleteFromInUseList(SchDlHqProcCb *hqP)
164 cmLListDelFrm(&(hqP->hqEnt->inUse), &hqP->dlHqEntLnk);
167 * @brief Get available Harq process from Harq entity
171 * Function : schDlGetAvlHqProcess
173 * This function fetches hq process from free list and puts in in use list
175 * @param[in] SchCellCb *cellCb, cell cb pointer
176 * @param[in] SchUeCb *ueCb, ue cb pointer
177 * @param[in] SchDlHqProcCb **hqP, Address of DL harq process pointer
182 uint8_t schDlGetAvlHqProcess(SchCellCb *cellCb, SchUeCb *ueCb, SchDlHqProcCb **hqP)
185 if (ueCb->dlHqEnt.free.count == 0)
189 tmp = (SchDlHqProcCb*)(cmLListFirst(&(ueCb->dlHqEnt.free))->node);
194 schDlHqDeleteFromFreeList(tmp);
195 schDlHqAddToInUseList(tmp);
197 (*hqP)->maxHqTxPerHqP = ueCb->dlHqEnt.maxHqTx;
201 * @brief Release Harq process from the DL Harq entity
205 * Function : schDlReleaseHqProcess
207 * This function releases Harq process from DL Harq entity
209 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
213 void schDlReleaseHqProcess(SchDlHqProcCb *hqP)
215 cmLListDeleteLList(&hqP->dlLcPrbEst.dedLcList);
216 cmLListDeleteLList(&hqP->dlLcPrbEst.defLcList);
217 schDlHqDeleteFromInUseList(hqP);
218 schDlHqAddToFreeList(hqP);
221 /*******************************************************************
223 * @brief Handles sending DL HARQ process release to MAC
227 * Function : sendDlHarqProcReleaseToMac
230 * Sends DL DL HARQ process release to MAC from SCH
233 * @return ROK - success
236 * ****************************************************************/
237 uint8_t sendDlHarqProcReleaseToMac(SchDlHqProcCb *hqP, Inst inst)
240 SchRlsHqInfo *rlsHqInfo;
241 memset(&pst, 0, sizeof(Pst));
242 FILL_PST_SCH_TO_MAC(pst, inst);
243 pst.event = EVENT_DL_REL_HQ_PROC;
245 SCH_ALLOC(rlsHqInfo, sizeof(SchRlsHqInfo));
246 rlsHqInfo->cellId = hqP->hqEnt->cell->cellId;
247 rlsHqInfo->numUes = 1;
249 SCH_ALLOC(rlsHqInfo->ueHqInfo, sizeof(SchUeHqInfo)*rlsHqInfo->numUes);
250 rlsHqInfo->ueHqInfo[0].crnti = hqP->hqEnt->ue->crnti;
251 rlsHqInfo->ueHqInfo[0].hqProcId = hqP->procId;
253 return(*schMacDlReleaseHarqOpts[pst.selector])(&pst, rlsHqInfo);
256 * @brief Release Harq process TB from the DL Harq process
260 * Function : schDlReleaseHqPTb
262 * This function releases Harq process TB from DL Harq proces
264 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
265 * @param[in] uint8_t tbIdx, TB index
266 * @param[in] bool togNdi, indication to toggle NDI bit
270 void schDlReleaseHqPTb(SchDlHqProcCb *hqP, uint8_t tbIdx, bool togNdi)
274 hqP->tbInfo[tbIdx].ndi ^= 1;
278 hqP->tbInfo[tbIdx].isAckNackDtx = HQ_ACK;
279 hqP->tbInfo[tbIdx].isEnabled = FALSE;
280 hqP->tbInfo[tbIdx].state = HQ_TB_ACKED;
281 hqP->tbInfo[tbIdx].txCntr = 0;
282 if (HQ_TB_ACKED == hqP->tbInfo[tbIdx^1].state)
284 schDlReleaseHqProcess(hqP);
285 sendDlHarqProcReleaseToMac(hqP, hqP->hqEnt->cell->instIdx);
290 * @brief Handles failure of HARQ process TB
294 * Function : schDlHqTbFail
296 * This function handles failure of HARQ process TB
298 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
299 * @param[in] uint8_t tbIdx, TB index
300 * @param[in] bool isMaxRetx, indicates max retransmission
304 void schDlHqTbFail(SchDlHqProcCb *hqP, uint8_t tbIdx, bool isMaxRetx)
308 schDlReleaseHqPTb(hqP, tbIdx, TRUE);
312 hqP->tbInfo[tbIdx].state = HQ_TB_NACKED;
313 if (HQ_TB_WAITING == hqP->tbInfo[tbIdx^1].state)
315 cmLListAdd2Tail( &(hqP->hqEnt->ue->dlRetxHqList), &hqP->dlHqProcLink);
320 * @brief Handles Harq feedback for MSG4
324 * Function : schMsg4FeedbackUpdate
326 * This function handles Harq feedback for MSG4
328 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
329 * @param[in] uint8_t fdbk, Received feedback
333 void schMsg4FeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk)
335 hqP->tbInfo[0].isAckNackDtx = fdbk;
336 hqP->tbInfo[1].isAckNackDtx = HQ_TB_ACKED;
337 if (HQ_TB_ACKED == hqP->tbInfo[0].isAckNackDtx)
339 schDlReleaseHqPTb(hqP, 0, TRUE);
340 schDlReleaseHqPTb(hqP, 1, TRUE);
341 schMsg4Complete(hqP->hqEnt->ue);
345 if( hqP->tbInfo[0].txCntr >= hqP->hqEnt->cell->cellCfg.schHqCfg.maxMsg4HqTx)
347 schDlReleaseHqProcess(hqP);
348 hqP->hqEnt->ue->msg4Proc = NULLP;
349 hqP->hqEnt->ue->retxMsg4HqProc = NULLP;
350 /* Delete UE and RA context */
352 addUeToBeScheduled(hqP->hqEnt->cell,hqP->hqEnt->ue->ueId);
353 hqP->hqEnt->ue->retxMsg4HqProc = hqP;
357 * @brief Handles Harq feedback for DL Data
361 * Function : schDlHqFeedbackUpdate
363 * This function handles Harq feedback for DL data
365 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
366 * @param[in] uint8_t fdbk1, Received feedback for TB -0
367 * @param[in] uint8_t fdbk2, Received feedback for TB -1
371 void schDlHqFeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk1, uint8_t fdbk2)
374 for (tbIdx = 0; tbIdx <2; tbIdx++)
376 if (HQ_TB_WAITING == hqP->tbInfo[tbIdx].state)
378 hqP->tbInfo[tbIdx].isAckNackDtx = (0 == tbIdx)?fdbk1:fdbk2;
380 if (TRUE == hqP->tbInfo[tbIdx].isEnabled)
382 if (HQ_TB_ACKED == hqP->tbInfo[tbIdx].isAckNackDtx)
384 schDlReleaseHqPTb(hqP, tbIdx, TRUE);
388 if(hqP->tbInfo[tbIdx].txCntr >= hqP->maxHqTxPerHqP)
390 schDlHqTbFail(hqP, tbIdx, TRUE);
394 schDlHqTbFail(hqP, tbIdx, FALSE);
395 addUeToBeScheduled(hqP->hqEnt->cell, hqP->hqEnt->ue->ueId);
401 /**********************************************************************
403 **********************************************************************/