Cu ASN changes for DlRrcMessageTransfer
[o-du/l2.git] / src / 5gnrmac / mac_slot_ind.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 /* header include files (.h) */
19 #include "stdbool.h"
20 #include "envopt.h"        /* environment options */
21 #include "envdep.h"        /* environment dependent */
22 #include "envind.h"        /* environment independent */
23 #include "gen.h"           /* general */
24 #include "ssi.h"           /* system services */
25 #include "cm_tkns.h"       /* Common Token Defines */
26 #include "cm_llist.h"      /* Common Link List Defines */
27 #include "cm_hash.h"       /* Common Hash List Defines */
28 #include "cm_mblk.h"       /* common memory link list library */
29 #include "cm_lte.h"        /* Common LTE Defines */
30 #include "rgu.h"
31 #include "tfu.h"           /* RGU Interface includes */
32 #include "lrg.h"
33 #include "crg.h"           /* layer management defines for LTE-MAC */
34 #include "rg_sch_inf.h"           /* layer management defines for LTE-MAC */
35 #include "rg_env.h"   
36 #include "rg.h"
37
38 #include "gen.x"           /* general */
39 #include "ssi.x"           /* system services */
40 #include "cm5.x"           /* system services */
41 #include "cm_tkns.x"       /* Common Token Definitions */
42 #include "cm_llist.x"      /* Common Link List Definitions */
43 #include "cm_lib.x"        /* Common Library Definitions */
44 #include "cm_hash.x"       /* Common Hash List Definitions */
45 #include "cm_mblk.x"       /* common memory link list library */
46 #include "cm_lte.x"        /* Common LTE Defines */
47 #include "rgu.x"
48 #include "tfu.x"           /* RGU Interface includes */
49 #include "lrg.x"
50 #include "crg.x"           /* layer management typedefs for MAC */
51 #include "rg_sch_inf.x"    /* SCH interface typedefs */
52 #include "rg_prg.x"
53 #include "du_app_mac_inf.h"
54 #include "mac.h"
55 #include "du_log.h"
56 #include "rg.x"
57 #include "mac_upr_inf_api.h"
58
59 /* function pointers for packing slot ind from mac to sch */
60 MacSchSlotIndFunc macSchSlotIndOpts[] =
61 {
62    packMacSchSlotInd,
63    macSchSlotInd,
64    packMacSchSlotInd
65 };
66
67 /**
68  * @brief process DL allocation from scheduler
69  *
70  * @details
71  *
72  *     Function : MacProcDlAlloc 
73  *      
74  *      This function copied dl sch info in the mac slot info
75  *           
76  *  @param[in]  Pst            *pst
77  *  @param[in]  DL allocation from scheduler
78  *  @return  S16
79  *      -# ROK 
80  *      -# RFAILED 
81  **/
82 int MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo)
83 {
84    MacDlSlot *currDlSlot = NULLP;
85
86    if(dlSchedInfo != NULLP)
87    {
88                 if(dlSchedInfo->isBroadcastPres)
89                 {
90                    currDlSlot = &macCb.macCell->dlSlot[dlSchedInfo->schSlotValue.broadcastTime.slot];
91                    currDlSlot->dlInfo.isBroadcastPres = true;
92                         memcpy(&currDlSlot->dlInfo.brdcstAlloc, &dlSchedInfo->brdcstAlloc, sizeof(DlBrdcstAlloc));
93                 }
94
95                 if(dlSchedInfo->rarAlloc != NULLP)
96                 {
97                    currDlSlot = &macCb.macCell->dlSlot[dlSchedInfo->schSlotValue.rarTime.slot];
98                         currDlSlot->dlInfo.rarAlloc = dlSchedInfo->rarAlloc;
99
100          /* MUXing of RAR */
101                         fillRarPdu(&currDlSlot->dlInfo.rarAlloc->rarInfo);
102                 }
103
104                 if(dlSchedInfo->msg4Alloc != NULLP)
105       {
106          Msg4Alloc *msg4Alloc = NULLP;
107          MacDlData msg4DlData;
108          MacCeInfo  macCeData;
109
110                    currDlSlot = &macCb.macCell->dlSlot[dlSchedInfo->schSlotValue.msg4Time.slot];
111                         currDlSlot->dlInfo.msg4Alloc = dlSchedInfo->msg4Alloc; /* copy msg4 alloc pointer in MAC slot info */
112                         msg4Alloc = dlSchedInfo->msg4Alloc;
113
114          memset(&msg4DlData, 0, sizeof(MacDlData));
115          memset(&macCeData, 0, sizeof(MacCeInfo));
116
117          macCb.macCell->macRaCb[0].msg4TbSize = msg4Alloc->msg4PdschCfg.codeword[0].tbSize;
118  
119          if(macCb.macCell->macRaCb[0].msg4Pdu != NULLP)
120          {
121             MAC_ALLOC(msg4DlData.pduInfo[0].dlPdu, \
122               macCb.macCell->macRaCb[0].msg4PduLen);
123             if(msg4DlData.pduInfo[0].dlPdu != NULLP)
124             {
125                fillMsg4DlData(&msg4DlData);
126             }
127          }
128
129          /* MUXing for msg4 */
130          fillMacCe(&macCeData);
131          macMuxPdu(&msg4DlData, &macCeData, macCb.macCell->macRaCb[0].msg4TbSize);
132       
133          /* storing msg4 Pdu in macDlSlot */
134                         if(macCb.macCell->macRaCb[0].msg4TxPdu)
135                         {
136             msg4Alloc->msg4Info.msg4PduLen = macCb.macCell->macRaCb[0].msg4TbSize;
137             MAC_ALLOC(msg4Alloc->msg4Info.msg4Pdu, msg4Alloc->msg4Info.msg4PduLen);
138             if(msg4Alloc->msg4Info.msg4Pdu != NULLP)
139             {
140                                    memcpy(msg4Alloc->msg4Info.msg4Pdu, macCb.macCell->macRaCb[0].msg4TxPdu, \
141                                         msg4Alloc->msg4Info.msg4PduLen);
142             }
143                         }
144                         else
145                         {
146             DU_LOG("\nMAC: Failed at macMuxPdu()");
147                                 return RFAILED;
148                         }
149          /* TODO: Free all allocated memory, after the usage */
150          /* MAC_FREE(macCb.macCell->macRaCb[0].msg4TxPdu, \
151               macCb.macCell->macRaCb[0].msg4TbSize); // TODO: To be freed after re-transmission is successful.
152             MAC_FREE(dlSchedInfo->msg4Alloc->msg4Info.msg4Pdu,\
153               macCb.macCell->macRaCb[0].msg4PduLen); //TODO: To be freed after lower-mac is succesfull
154             MAC_FREE(msg4DlData.pduInfo[0].dlPdu, macCb.macCell->macRaCb[0].msg4PduLen);
155             MAC_FREE(macCb.macCell->macRaCb[0].msg4Pdu, macCb.macCell->macRaCb[0].msg4PduLen); */
156       }
157    }
158    return ROK;
159 }
160
161 /**
162  * @brief Transmission time interval indication from PHY.
163  *
164  * @details
165  *
166  *     Function : sendSlotIndMacToSch
167  * 
168  *      This API is invoked by MAC to send slot ind to scheduler.
169  *           
170  *  @param[in]  SlotIndInfo    *slotInd
171  *  @return  S16
172  *      -# ROK 
173  *      -# RFAILED 
174  **/
175 int sendSlotIndMacToSch(SlotIndInfo *slotInd)
176 {
177    /* fill Pst structure to send to lwr_mac to MAC */
178    Pst pst;
179
180    fillMacToSchPst(&pst);
181    pst.event = EVENT_SLOT_IND_TO_SCH;
182
183    return(*macSchSlotIndOpts[pst.selector])(&pst,slotInd);
184 }
185
186 /*******************************************************************
187  *
188  * @brief Send slot indication to DU APP
189  *
190  * @details
191  *
192  *    Function : sendSlotIndMacToDuApp
193  *
194  *    Functionality:
195  *       Send slot indication to DU APP
196  *
197  * @params[in] Slot indication info 
198  * @return ROK     - success
199  *         RFAILED - failure
200  *
201  * ****************************************************************/
202 int sendSlotIndMacToDuApp(SlotIndInfo *slotInd)
203 {
204    Pst pst;
205    uint16_t ret;
206    SlotInfo  *slotInfo;
207  
208    /*  Allocate sharable memory */
209    MAC_ALLOC_SHRABL_BUF(slotInfo, sizeof(SlotInfo));
210    if(!slotInfo)
211    {
212       DU_LOG("\nMAC : Slot Indication memory allocation failed");
213       return RFAILED;
214   }
215  
216   slotInfo->cellId = macCb.macCell->cellId;
217   slotInfo->sfn = slotInd->sfn;
218   slotInfo->slot = slotInd->slot;
219  
220   /* Fill Pst */
221   pst.selector  = DU_MAC_LWLC;
222   pst.srcEnt    = ENTRG;
223   pst.dstEnt    = ENTDUAPP;
224   pst.dstInst   = 0;
225   pst.srcInst   = macCb.macInst;
226   pst.dstProcId = rgCb[pst.srcInst].rgInit.procId;
227   pst.srcProcId = rgCb[pst.srcInst].rgInit.procId;
228   pst.region = MAC_MEM_REGION;
229   pst.pool = MAC_POOL;
230   pst.event = EVENT_MAC_SLOT_IND;
231   pst.route = 0;
232   pst.prior = 0;
233   pst.intfVer = 0;
234  
235   ret = MacDuAppSlotInd(&pst, slotInfo);
236   if(ret != ROK)
237   {
238      DU_LOG("\nMAC: Failed to send slot indication to DU APP");
239      MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, slotInfo, sizeof(SlotInfo));
240   }
241  
242   return ret;
243 } /* sendSlotIndMacToDuApp */
244
245
246 /**
247  * @brief Transmission time interval indication from PHY.
248  *
249  * @details
250  *
251  *     Function : fapiMacSlotInd 
252  *      
253  *      This API is invoked by PHY to indicate TTI indication to MAC for a cell.
254  *           
255  *  @param[in]  Pst            *pst
256  *  @param[in]  SuId           suId 
257  *  @param[in]  SlotIndInfo    *slotInd
258  *  @return  S16
259  *      -# ROK 
260  *      -# RFAILED 
261  **/
262 PUBLIC S16 fapiMacSlotInd 
263 (
264 Pst                 *pst, 
265 SlotIndInfo         *slotInd
266 )
267 {
268    S16              ret;
269    VOLATILE U32     startTime=0;
270    Inst             inst;
271
272    DU_LOG("\nMAC : Slot Indication received");
273    
274    inst = pst->dstInst;
275    /*starting Task*/
276    SStartTask(&startTime, PID_MAC_TTI_IND);
277
278    /* send slot indication to scheduler */
279    ret = sendSlotIndMacToSch(slotInd);
280    if(ret != ROK)
281    {
282       DU_LOG("\nMAC : Sending of slot ind msg from MAC to SCH failed");
283       RETVALUE(ret);
284    }
285
286    ret = macProcessSlotInd(inst,*slotInd);
287    if(ret != ROK)
288    {
289       DU_LOG("\nMAC : macProcessSlotInd failed");
290       RETVALUE(ret);
291    }
292
293    /* send slot indication to du app */
294    ret = sendSlotIndMacToDuApp(slotInd);
295    if(ret != ROK)
296    {
297       DU_LOG("\nMAC :Sending of slot ind msg from MAC to DU APP failed");
298       RETVALUE(ret);
299    }
300
301    /*stoping Task*/
302    SStopTask(startTime, PID_MAC_TTI_IND);
303
304    RETVALUE(ret);
305 }  /* fapiMacSlotInd */
306
307 /**********************************************************************
308   End of file
309  **********************************************************************/
310