[EPIC-ID: ODUHIGH-488][TASK-ID: ODUHIGH-494]Framework to support for slice based...
[o-du/l2.git] / src / 5gnrsch / sch_rr.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 /**
29  * @brief Handles retransmission for MSG3
30  *
31  * @details
32  *
33  *     Function : schMsg3RetxSchedulingForUe
34  *      
35  *      This function handles retransmission for MSG3
36  *           
37  *  @param[in]  SchRaCb *raCb, RA cb pointer
38  *  @return  
39  *      -# ROK
40  *      -# RFAILED
41  **/
42 uint8_t schMsg3RetxSchedulingForUe(SchRaCb *raCb)
43 {
44    bool      k2Found = false;
45    uint16_t             dciSlot = 0;
46    SlotTimingInfo       dciTime, msg3Time;
47    SchCellCb            *cell = NULLP;
48    SlotTimingInfo       currTime;
49    DciInfo  *dciInfo = NULLP;
50    cell = raCb->cell;
51    currTime = cell->slotInfo;
52
53    /* Calculating time frame to send DCI for MSG3 Retx*/
54    ADD_DELTA_TO_TIME(currTime, dciTime, PHY_DELTA_DL + SCHED_DELTA, cell->numSlots);
55 #ifdef NR_TDD
56    /* Consider this slot for sending DCI, only if it is a DL slot */
57    if(schGetSlotSymbFrmt(dciSlot, raCb->cell->slotFrmtBitMap) == DL_SLOT)
58 #endif
59    {
60       /* If PDCCH is already scheduled on this slot, cannot schedule PDSCH for another UE here. */
61       if(cell->schDlSlotInfo[dciSlot]->pdcchUe != 0)
62          return false;
63
64       k2Found = schGetMsg3K2(cell, &raCb->msg3HqProc, dciTime.slot, &msg3Time, TRUE);
65
66       if (!k2Found)
67       {
68          return RFAILED;
69       }
70       SCH_ALLOC(dciInfo, sizeof(DciInfo));
71       if(!dciInfo)
72       {
73          DU_LOG("\nERROR  -->  SCH : Memory Allocation failed for dciInfo alloc");
74          return RFAILED;
75       }
76       cell->schDlSlotInfo[msg3Time.slot]->ulGrant = dciInfo;
77       SCH_ALLOC(cell->schUlSlotInfo[msg3Time.slot]->schPuschInfo, sizeof(SchPuschInfo));
78       memset(dciInfo,0,sizeof(DciInfo));
79       schFillUlDciForMsg3Retx(raCb, cell->schUlSlotInfo[msg3Time.slot]->schPuschInfo, dciInfo);
80    }   
81    raCb->retxMsg3HqProc = NULLP;
82    return ROK;
83 }
84 /**
85  * @brief Get K2 value for MSG3
86  *
87  * @details
88  *
89  *     Function : schGetMsg3K2
90  *      
91  *      This function gets K2 for MSG3
92  *           
93  *  @param[in]  SchCellCb *cell, Cell cb struc pointer
94  *  @param[in]  SchUlHqProcCb* msg3HqProc, msg3 harq proc pointer
95  *  @param[in]  uint16_t dlTime, DL time of scheduling
96  *  @param[in]  SlotTimingInfo *msg3Time, MSG3 timing info
97  *  @param[in]  bool isRetx, indicates MSG3 retransmission
98  *  @return  
99  *      -# true
100  *      -# false
101  **/
102 bool schGetMsg3K2(SchCellCb *cell, SchUlHqProcCb* msg3HqProc, uint16_t dlTime, SlotTimingInfo *msg3Time, bool isRetx)
103 {
104    bool      k2Found = false;
105    uint8_t   k2TblIdx = 0;
106    uint8_t   k2Index = 0;
107    uint8_t   k2 = 0;
108    uint8_t   numK2 = 0;
109    uint8_t   puschMu = 0;
110    uint8_t   msg3Delta = 0, msg3MinSchTime = 0;
111 #ifdef NR_TDD
112    uint8_t   totalCfgSlot = 0;
113 #endif
114    SchK2TimingInfoTbl   *msg3K2InfoTbl=NULLP;
115    SlotTimingInfo       currTime, msg3TempTime;
116    currTime = cell->slotInfo;
117    puschMu = cell->cellCfg.numerology;
118
119    if (isRetx)
120    {
121       if(!msg3HqProc)
122          return false;
123
124       numK2 = cell->cellCfg.schInitialUlBwp.k2InfoTbl.k2TimingInfo[dlTime].numK2;
125       msg3K2InfoTbl = &cell->cellCfg.schInitialUlBwp.msg3K2InfoTbl;      
126       msg3MinSchTime = 0;
127       msg3Delta = 0;
128    }
129    else
130    {
131       numK2 = cell->cellCfg.schInitialUlBwp.msg3K2InfoTbl.k2TimingInfo[dlTime].numK2;
132       msg3K2InfoTbl = &cell->cellCfg.schInitialUlBwp.k2InfoTbl;
133       msg3MinSchTime = minMsg3SchTime[cell->cellCfg.numerology];
134       msg3Delta = puschDeltaTable[puschMu];      
135    }
136
137    for(k2TblIdx = 0; k2TblIdx < numK2; k2TblIdx++)
138    {
139       k2Index = msg3K2InfoTbl->k2TimingInfo[dlTime].k2Indexes[k2TblIdx];
140
141       k2 = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].k2;
142       if (isRetx)
143       {
144          if ((msg3HqProc->strtSymbl != cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].startSymbol) ||
145             (msg3HqProc->numSymbl != cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].symbolLength))
146          {
147             continue;
148          }
149       }
150       /* Delta is added to the slot allocation for msg3 based on 38.214 section 6.1.2.1 */
151       k2 = k2 + msg3Delta;
152       if(k2 >= msg3MinSchTime)
153       {
154          ADD_DELTA_TO_TIME(currTime, msg3TempTime, k2, cell->numSlots);
155 #ifdef NR_TDD
156          if(schGetSlotSymbFrmt(msg3TempTime.slot % totalCfgSlot, cell->slotFrmtBitMap) == DL_SLOT)
157             continue;
158 #endif
159          /* If PUSCH is already scheduled on this slot, another PUSCH
160           * pdu cannot be scheduled here */
161          if(cell->schUlSlotInfo[msg3TempTime.slot]->puschUe != 0)
162             continue;
163          k2Found = true;
164          break;
165       }
166    }
167    if (k2Found == true)
168    {
169       msg3Time->slot = msg3TempTime.slot;
170       msg3Time->sfn = msg3TempTime.sfn;
171       msg3Time->slot = msg3TempTime.slot;
172    }
173    return k2Found;
174 }
175 /**********************************************************************
176   End of file
177  **********************************************************************/