Merge "replaced cmMemSet, cmMemcpy with memset and memcpy resp AND Removed TRC()...
[o-du/l2.git] / src / 5gnrmac / rg_ram.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
19 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point fucntions
26   
27      File:     rg_ram.c
28   
29 **********************************************************************/
30
31 /** @file rg_ram.c
32 @brief This file has APIs to handle the random access procedure functionality.
33 */
34
35 static const char* RLOG_MODULE_NAME="MAC";
36 static int RLOG_FILE_ID=132;
37 static int RLOG_MODULE_ID=4096;
38
39 /* header include files (.h) */
40 #include "common_def.h"
41 #include "rg_env.h"        /* MAC Environment Defines */
42 #include "crg.h"           /* CRG Interface defines */
43 #include "rgu.h"           /* RGU Interface defines */
44 #include "tfu.h"           /* TFU Interface defines */
45 #include "rg_sch_inf.h"           /* RGR Interface defines */
46 #include "lrg.h"           /* LRG Interface defines */
47
48 #include "rg.h"            /* MAC defines */
49 #include "rg_err.h"        /* MAC error defines */
50
51 /* header/extern include files (.x) */
52
53 #include "crg.x"           /* CRG Interface includes */
54 #include "rgu.x"           /* RGU Interface includes */
55 #include "tfu.x"           /* TFU Interface includes */
56 #include "rg_sch_inf.x"    /* SCH Interface includes */
57 #include "rg_prg.x"        /* PRG Interface includes */
58 #include "lrg.x"           /* LRG Interface includes */
59
60 #include "du_app_mac_inf.h"
61 #include "rg.x"            /* MAC includes */
62
63 /* local defines */
64
65 /* local typedefs */
66  
67 /* forward references */
68
69 /***********************************************************
70  *
71  *     Func : rgRAMFreeUeCb
72  *
73  *
74  *     Desc :
75  *     - Processing Steps:
76  *        - Frees UE control block.
77  *
78  *     Ret  : Void
79  *
80  *     Notes:
81  *
82  *     File :
83  *
84  **********************************************************/
85 #ifdef ANSI
86 Void rgRAMFreeUeCb
87 (
88 Inst        inst,
89 RgUeCb      *ue
90 )
91 #else
92 Void rgRAMFreeUeCb(inst,ue)
93 Inst        inst;
94 RgUeCb      *ue;
95 #endif
96 {
97    rgDHMFreeUe(inst,&ue->dl.hqEnt);
98
99    /*ccpu00117052 - MOD - Passing double pointer for proper NULLP 
100                           assignment */
101    /* De-allocate the Ue */
102    rgFreeSBuf(inst,(Data **)&ue, sizeof(*ue));
103
104    /* Stack Crash problem for TRACE5 changes. Added the return below */
105    RETVOID;
106
107 }  /* rgRAMFreeUeCb */
108
109 /**
110  * @brief Handler for Random Access control block creation.
111  *
112  * @details
113  *
114  *     Function : rgRAMCreateUeCb
115  *                Creates a raCb and gives the same to scheduler for its updation.
116  *     
117  *
118  *  @param[in]       RgCellCb       *cell 
119  *  @param[in]       CmLteRnti      tmpCrnti 
120  *  @param[out]      RgErrInfo      *err
121  *  @return  RgUeCb*
122  **/
123 #ifdef ANSI
124 RgUeCb* rgRAMCreateUeCb
125 (
126 RgCellCb       *cell,
127 CmLteRnti      tmpCrnti,
128 Bool           insert,
129 RgErrInfo      *err
130 )
131 #else
132 RgUeCb* rgRAMCreateUeCb(cell, tmpCrnti, insert, err)
133 RgCellCb       *cell;
134 CmLteRnti      tmpCrnti;
135 Bool           insert;
136 RgErrInfo      *err;
137 #endif
138 {
139    Inst       inst = cell->macInst - RG_INST_START;
140    RgUeCb    *ueCb = NULLP;
141
142    RLOG_ARG1(L_INFO,DBG_CELLID,cell->cellId,"CREATE UECB FOR CRNTI:%d",
143              tmpCrnti);
144    /* Allocate the Ue control block */
145    if (rgAllocSBuf(inst,(Data **)&ueCb, sizeof(*ueCb)) != ROK)
146    {
147       RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,
148                 "Memory allocation FAILED for CRNTI:%d",tmpCrnti);
149       err->errCause = RGERR_RAM_MEM_EXHAUST;
150       return (NULLP);
151    }
152
153    /* Inititialize Ue control block */
154    ueCb->ueId = tmpCrnti;
155
156    /* Initialize the lists of the UE */
157    rgDBMInitUe(ueCb); 
158    
159    if(insert == TRUE)
160    {
161       /* MS_FIX : Remove stale UEs if present */
162       RgUeCb *staleUe = NULLP;
163       /* Insert the created raCb into raCb list of cell */
164       ueCb->rachLstEnt.next = NULLP;
165       ueCb->rachLstEnt.prev = NULLP;
166       ueCb->rachLstEnt.node = (PTR)(ueCb);
167       /* MS_FIX : Remove stale UEs if present */
168       staleUe = rgDBMGetUeCbFromRachLst (cell, tmpCrnti);
169       if (staleUe)
170       {
171          rgDBMDelUeCbFromRachLst(cell, staleUe);
172          rgRAMFreeUeCb(inst,staleUe);
173       }
174       rgDBMInsUeCbInRachLst(cell, ueCb);
175    }
176
177    return (ueCb);
178 }  /* rgRAMCreateUeCb */
179
180 /**
181  * @brief Function for handling cell delete.
182  *
183  * @details
184  *
185  *     Function : rgRAMFreeCell
186  *     
187  *     This function shall be invoked whenever a cell needs to be deleted.
188  *     This shall remove raCbs and raReqs stored in cell.
189  *     
190  *           
191  *  @param[in,out] RgCellCb  *cell
192  *  @return  S16
193  *      -# ROK 
194  **/
195 #ifdef ANSI
196 S16 rgRAMFreeCell
197 (
198 RgCellCb    *cell
199 )
200 #else
201 S16 rgRAMFreeCell(cell)
202 RgCellCb    *cell;
203 #endif
204 {
205    Inst    inst = cell->macInst - RG_INST_START;
206    RgUeCb  *ueCb;
207
208    /* Free CURRENT CRG cfg list */
209    while ((ueCb = rgDBMGetNextUeCbFromRachLst(cell, NULLP)) != NULLP)
210    {
211       rgDBMDelUeCbFromRachLst(cell, ueCb);
212       rgRAMFreeUeCb(inst,ueCb);
213    }
214
215    return ROK; 
216 } /* rgRAMFreeCell */
217 /**
218  * @brief Function for handling RA response scheduled for a subframe.
219  *
220  * @details
221  *
222  *     Function : rgHndlRaResp
223  *     
224  *     This function shall be invoked whenever scheduler is done with the
225  *     allocations of random access responses for a subframe RgSchMacSfAllocReq.
226  *
227  *     Processing steps :
228  *
229  *     This shall invoke RAM to create ueCbs for all the rapIds allocated and 
230  *     shall invoke MUX to create RAR PDUs for raRntis allocated.
231  *     
232  *           
233  *  @param[in] RgCellCb          *cell,
234  *  @param[in] CmLteTimingInfo   timingInfo,
235  *  @param[in] RgInfRarInfo      *rarInfo
236  *  @param[in/out] RgErrInfo     *err
237  *  @return  S16
238  *      -# ROK 
239  **/
240 #ifdef ANSI
241 S16 rgHndlRaResp
242 (
243 RgCellCb            *cell,
244 CmLteTimingInfo     timingInfo,
245 RgInfRarInfo        *rarInfo,
246 RgErrInfo           *err
247 )
248 #else
249 S16 rgHndlRaResp(cell, timingInfo, rarInfo, err)
250 RgCellCb            *cell;
251 CmLteTimingInfo     timingInfo;
252 RgInfRarInfo        *rarInfo;
253 RgErrInfo           *err;
254 #endif
255 {
256    U8       idx1,idx2;
257    Buffer   *rarPdu;
258    RgDlSf   *dlSf;
259    U8       idx;
260
261    if(NULLP == rarInfo->raRntiInfo)
262    {
263       return RFAILED;
264    }
265
266    idx = (timingInfo.slot % RG_NUM_SUB_FRAMES);
267    dlSf = &cell->subFrms[idx];
268
269    /* Create RAR PDUs for all the allocated RA-RNTIs */
270    for(idx1 = 0; idx1 < rarInfo->numRaRntis; idx1++)
271    {
272       if(ROK == (rgMUXBldRarPdu(cell, 
273                      &rarInfo->raRntiInfo[idx1], &rarPdu, err)))
274       {
275          /* Create RaCbs for all the rapIds allocated */
276          for(idx2 = 0; idx2 < rarInfo->raRntiInfo[idx1].numCrnti; idx2++)
277          {
278             if(FALSE == rarInfo->raRntiInfo[idx1].crntiInfo[idx2].isContFree)
279             {
280                if(rgRAMCreateUeCb(cell,
281                   rarInfo->raRntiInfo[idx1].crntiInfo[idx2].tmpCrnti, 
282                   TRUE, err) == NULLP)
283                {
284                   return RFAILED;
285                }
286             }
287          }
288          /* Store the created RAR PDU */
289          dlSf->raRsp[dlSf->numRaRsp].pdcch.rnti = 
290             rarInfo->raRntiInfo[idx1].raRnti;
291
292          dlSf->raRsp[dlSf->numRaRsp].pdcch.dci = 
293             rarInfo->raRntiInfo[idx1].dciInfo;
294
295          dlSf->raRsp[dlSf->numRaRsp].rar = rarPdu;
296          /* ccpu00132314-ADD-Adding txPower offset for the PDSCH transmission */
297          dlSf->raRsp[dlSf->numRaRsp].txPwrOffset =
298                rarInfo->txPwrOffset;
299
300          dlSf->numRaRsp++;
301       }
302       else
303       {
304          RLOG_ARG1(L_ERROR,DBG_CELLID,cell->cellId,"RARNTI:%d Creation of RAR"
305                   "PDU for failed", rarInfo->raRntiInfo[idx1].raRnti);
306          continue;
307       }
308    } /* end of raRntis loop */
309    return ROK;
310 } /* end of rgHndlRaResp */
311
312 /**********************************************************************
313  
314          End of file
315 **********************************************************************/