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)
217 cmLListDeleteLList(&hqP->dlLcPrbEst.dedLcList);
218 cmLListDeleteLList(&hqP->dlLcPrbEst.defLcList);
219 schDlHqDeleteFromInUseList(hqP);
220 schDlHqAddToFreeList(hqP);
224 /*******************************************************************
226 * @brief Handles sending DL HARQ process release to MAC
230 * Function : sendDlHarqProcReleaseToMac
233 * Sends DL DL HARQ process release to MAC from SCH
236 * @return ROK - success
239 * ****************************************************************/
240 uint8_t sendDlHarqProcReleaseToMac(SchDlHqProcCb *hqP, Inst inst)
243 SchRlsHqInfo *rlsHqInfo;
244 memset(&pst, 0, sizeof(Pst));
245 FILL_PST_SCH_TO_MAC(pst, inst);
246 pst.event = EVENT_DL_REL_HQ_PROC;
248 SCH_ALLOC(rlsHqInfo, sizeof(SchRlsHqInfo));
249 rlsHqInfo->cellId = hqP->hqEnt->cell->cellId;
250 rlsHqInfo->numUes = 1;
252 SCH_ALLOC(rlsHqInfo->ueHqInfo, sizeof(SchUeHqInfo)*rlsHqInfo->numUes);
253 rlsHqInfo->ueHqInfo[0].crnti = hqP->hqEnt->ue->crnti;
254 rlsHqInfo->ueHqInfo[0].hqProcId = hqP->procId;
256 return(*schMacDlReleaseHarqOpts[pst.selector])(&pst, rlsHqInfo);
259 * @brief Release Harq process TB from the DL Harq process
263 * Function : schDlReleaseHqPTb
265 * This function releases Harq process TB from DL Harq proces
267 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
268 * @param[in] uint8_t tbIdx, TB index
269 * @param[in] bool togNdi, indication to toggle NDI bit
273 void schDlReleaseHqPTb(SchDlHqProcCb *hqP, uint8_t tbIdx, bool togNdi)
277 hqP->tbInfo[tbIdx].ndi ^= 1;
281 hqP->tbInfo[tbIdx].isAckNackDtx = HQ_ACK;
282 hqP->tbInfo[tbIdx].isEnabled = FALSE;
283 hqP->tbInfo[tbIdx].state = HQ_TB_ACKED;
284 hqP->tbInfo[tbIdx].txCntr = 0;
285 if (HQ_TB_ACKED == hqP->tbInfo[tbIdx^1].state)
287 schDlReleaseHqProcess(hqP);
288 sendDlHarqProcReleaseToMac(hqP, hqP->hqEnt->cell->instIdx);
293 * @brief Handles failure of HARQ process TB
297 * Function : schDlHqTbFail
299 * This function handles failure of HARQ process TB
301 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
302 * @param[in] uint8_t tbIdx, TB index
303 * @param[in] bool isMaxRetx, indicates max retransmission
307 void schDlHqTbFail(SchDlHqProcCb *hqP, uint8_t tbIdx, bool isMaxRetx)
311 schDlReleaseHqPTb(hqP, tbIdx, TRUE);
315 hqP->tbInfo[tbIdx].state = HQ_TB_NACKED;
316 if (HQ_TB_WAITING == hqP->tbInfo[tbIdx^1].state)
318 cmLListAdd2Tail( &(hqP->hqEnt->ue->dlRetxHqList), &hqP->dlHqProcLink);
323 * @brief Handles Harq feedback for MSG4
327 * Function : schMsg4FeedbackUpdate
329 * This function handles Harq feedback for MSG4
331 * @param[in] SchDlHqProcCb *hqP, DL harq process pointer
332 * @param[in] uint8_t fdbk, Received feedback
336 void schMsg4FeedbackUpdate(SchDlHqProcCb *hqP, uint8_t fdbk)
338 hqP->tbInfo[0].isAckNackDtx = fdbk;
339 hqP->tbInfo[1].isAckNackDtx = HQ_TB_ACKED;
340 if (HQ_TB_ACKED == hqP->tbInfo[0].isAckNackDtx)
342 schDlReleaseHqPTb(hqP, 0, TRUE);
343 schDlReleaseHqPTb(hqP, 1, TRUE);
344 schMsg4Complete(hqP->hqEnt->ue);
348 if( hqP->tbInfo[0].txCntr >= hqP->hqEnt->cell->cellCfg.schHqCfg.maxMsg4HqTx)
350 schDlReleaseHqProcess(hqP);
351 hqP->hqEnt->ue->msg4Proc = NULLP;
352 hqP->hqEnt->ue->retxMsg4HqProc = NULLP;
353 /* Delete UE and RA context */
355 addUeToBeScheduled(hqP->hqEnt->cell,hqP->hqEnt->ue->ueId);
356 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);
398 addUeToBeScheduled(hqP->hqEnt->cell, hqP->hqEnt->ue->ueId);
404 /**********************************************************************
406 **********************************************************************/