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