JIRA ID:[ODUHIGH-296]-Dl Data Changes from DUAPP to RLC
[o-du/l2.git] / src / 5gnrrlc / kw_ptli.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**
20   
21         Name:    LTE-RLC Layer - Lower Interface
22     
23         Type:    C file
24   
25         Desc:    C source code for the lower interface of LTE-RLC
26  
27         File:    kw_ptli.c
28   
29 *********************************************************************21*/
30
31 /** @file kw_ptli.c 
32 @brief RLC Lower Interface
33 */
34
35 \f
36 /* header (.h) include files */
37 #include "common_def.h"
38 #include "lkw.h"           /* LKW defines */
39 #include "ckw.h"           /* CKW defines */
40 #include "kwu.h"           /* KWU defines */
41 #include "rgu.h"           /* RGU defines */
42 #ifdef KW_PDCP
43 #include "cpj.h"           /* CPJ defines */
44 #include "pju.h"           /* PJU defines */
45 #include "lpj.h"           /* LPJ defines */
46 #endif
47 #include "kw_err.h"
48 #include "kw_env.h"        /* RLC environment options */
49 #include "kw.h"            /* RLC defines */
50
51 /* extern (.x) include files */
52 #include "lkw.x"           /* LKW */
53 #include "ckw.x"           /* CKW */
54 #include "kwu.x"           /* KWU */
55 #include "rgu.x"           /* RGU */
56 #ifdef KW_PDCP
57 #include "cpj.x"           /* CPJ defines */
58 #include "pju.x"           /* PJU defines */
59 #include "lpj.x"           /* LPJ defines */
60 #endif
61 #include "kw.x"
62 #include "ss_rbuf.h"
63 #include "ss_rbuf.x"
64
65 #ifndef LCKWLIRGU
66 #define PTKWRGU
67 #endif
68
69 #ifndef RG
70 #define PTKWRGU
71 #endif
72
73 #ifdef __cplusplus
74 extern "C" {
75 #endif /* __cplusplus */
76
77
78
79 #ifdef RLC_MAC_DAT_REQ_RBUF
80 S16 rlcLiRguDatReqRbuf(Pst *Post,SpId spId,Void *datReq);
81 #endif
82
83 #ifdef RLC_MAC_STA_RSP_RBUF
84 S16 rlcLiRguStaRspRbuf(Pst *Post,SpId spId,Void  *staRsp);
85 #endif
86 #if defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS)
87 S16 RlcDlHarqStaBatchProc (Void);
88 #endif
89
90 \f
91 /*********************************************************************
92  *             Primitives for RGU interface 
93  ********************************************************************/
94
95 /* RGU Bind Request primitive */
96
97 RguBndReq kwLiRguBndReqMt[] =
98 {
99 #ifdef LCKWLIRGU
100    cmPkRguBndReq,            /* 0 - loosely coupled */
101 #endif /* LCRGUIRGU */
102 #ifdef RG 
103    RgUiRguBndReq,            /* 1 - tightly coupled, MAC  */
104 #endif /* RG */
105 #ifdef LCKWLIRGU
106    cmPkRguBndReq,            /* 0 - loosely coupled */
107 #endif /* LCRGUIRGU */
108 };
109
110 /* RGU Unbind Request primitive */
111
112 RguBndReq kwLiRguUbndReqMt[] =
113 {
114 #ifdef LCKWLIRGU
115    cmPkRguUbndReq,            /* 0 - loosely coupled */
116 #endif /* LCRGUIRGU */
117 #ifdef RG 
118    RgUiRguUbndReq,            /* 1 - tightly coupled, MAC  */
119 #endif /* RG */
120 #ifdef LCKWLIRGU
121    cmPkRguUbndReq,            /* 0 - loosely coupled */
122 #endif /* LCRGUIRGU */
123 };
124
125 /* kw005.201 added support for L2 Measurement */
126 #ifdef LTE_L2_MEAS
127 #ifdef LTE_RLC_R9
128 /* RGU L2 Measurement Ul Ip Throughput Measurement Request primitive */
129
130 RguL2MUlThrpMeasReq kwLiRguL2MUlThrpMeasReqMt[] =
131 {
132 #ifdef LCKWLIRGU
133    cmPkRguL2MUlThrpMeasReq,            /* 0 - loosely coupled */
134 #endif /* LCRGUIRGU */
135 #ifdef RG 
136    RgUiRguL2MUlThrpMeasReq,            /* 1 - tightly coupled, MAC  */
137 #endif /* RG */
138 };
139 #endif /* LTE_RLC_R9 */
140 #endif /*  LTE_L2_MEAS */
141 \f
142 /****************************************************************************
143  *                         RGU Interface Mt functions
144  ***************************************************************************/
145 /**
146  *
147  * @brief 
148  *
149  *        Handler for RGU SAP bind Request.
150  *
151  * @b Description:
152  *
153  *        This function is used by RLC to request for binding to 
154  *        MAC for accessing MAC services.This function binds MAC's 
155  *        SAP (identified by spId) with the service user's SAP 
156  *        (identified by suId).
157  *
158  *  @param[in] pst   Post structure  
159  *  @param[in] suId  Service user SAP ID 
160  *  @param[in] spId  Service provider ID
161  *
162  *  @return  S16
163  *      -# ROK 
164  */
165
166 S16 RlcLiRguBndReq
167 (
168 Pst  *post,                       /* post structure */
169 SuId suId,                      /* Service User Id */
170 SpId spId                       /* Service Provider Id */
171 )
172 {
173
174    /* jump to specific primitive depending on configured selector */
175    (*kwLiRguBndReqMt[post->selector])(post, suId, spId);
176
177    return ROK;
178
179 } /* end of RlcLiRguBndReq */
180
181 \f
182 /**
183  *
184  * @brief 
185  *
186  *        Handler for bind confirmation from MAC.
187  *
188  * @b Description:
189  *
190  *        This function handles the bind confirmation received
191  *        from MAC. 
192  *
193  *  @param[in] post     - Post structure  
194  *  @param[in] suId    - Service provider SAP ID 
195  *  @param[in] reason  - Reason of confirmation
196  *
197  *  @return  S16
198  *      -# ROK 
199  */
200
201 S16 RlcLiRguUbndReq(Pst *post,SpId spId,Reason reason)
202 {
203
204    /* jump to specific primitive depending on configured selector */
205    (*kwLiRguUbndReqMt[post->selector])(post, spId, reason);
206
207    return ROK;
208
209 } /* end of RlcLiRguUbndReq */
210
211 /* kw005.201 added support for L2 Measurement */
212 #ifdef LTE_L2_MEAS
213 #ifdef LTE_RLC_R9
214 \f  
215 /**
216  *
217  * @brief 
218  *
219  *        Handler for sending ulThrpMeasReqInfo from RLC to MAC for UL ip throughput measurement. 
220  *
221  * @b Description:
222  *
223  *        This function sends ulThrpMeasReqInfo from RLC to MAC whenver UL ip throughput
224  * measurement is ON for a single or multiple qci in a UE. This is an indication for MAC
225  * to start the T2/T1 time stamps for the coresponding LCHs in the UE.
226  *
227  *  @param[in] post                    Post structure  
228  *  @param[in] spId                   Service Provider ID
229  *  @param[in] ulThrpMeasReqInfo      Ul ip measurement request info
230  *
231  *  @return  S16
232  *      -# ROK 
233  *      -# RFAILED
234  *
235  */
236 S16 RlcLiRguL2MUlThrpMeasReq(Pst *post,SpId spId,RguL2MUlThrpMeasReqInfo *l2mUlThrpMeasReq)
237 {
238
239    /* jump to specific primitive depending on configured selector */
240    (*kwLiRguL2MUlThrpMeasReqMt[post->selector])(post, spId, l2mUlThrpMeasReq);
241
242    return ROK;
243
244 } /* end of RlcLiRguL2MUlThrpMeasReq */
245
246 #endif /* LTE_RLC_R9 */
247 #endif /* LTE_L2_MEAS */
248
249
250 #ifdef MAC_RLC_UL_RBUF
251 S16 rlcUlBatchProc ARGS ((Void));
252 Void rlcUtlFreeUlRBuf ARGS((void));
253
254 S16 rlcUlBatchProc(Void)
255 {
256 /* Read from Ring Buffer and process PDCP packets */
257    RguDDatIndInfo   *datInd;
258    Void *elmIndx = NULLP;
259    static Pst rlcUlRbfuPst={1,1,ENTRLC,0,ENTMAC,0,PRIOR0,RTESPEC,EVTRLCULDAT,0,0,0,0};
260 /* Read from Ring Buffer and process PDCP packets */
261
262 #ifndef SS_RBUF
263    RguDedDatInd1 *rguDatInd = NULLP;
264    uint8_t rngBufDeqIndx = 0;
265
266    elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
267    while(NULLP != elmIndx)
268    {
269       rguDatInd = (RguDedDatInd1 *)elmIndx;
270       datInd = (RguDDatIndInfo*) rguDatInd->msg; 
271       SsRngInfoTbl[SS_RNG_BUF_ULMAC_TO_ULRLC].nPktProc++;//Number of pkt processed in tti
272       if(datInd != NULLP)
273       {
274          RlcProcDedLcUlData(&rlcUlRbfuPst, 0, datInd);
275       }
276       else
277       {
278          DU_LOG("\nERROR  -->  RLC UL : Received NULL buffer");
279       }
280       rguDatInd->msg=NULLP;
281       SRngIncrRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
282       elmIndx = NULLP;
283       rguDatInd = NULLP;
284
285       rngBufDeqIndx++;
286
287       //if(rngBufDeqIndx >= SS_RNG_MAX_ULMAC_TO_ULRLC_DQ_CNT)
288        // break;
289
290       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC)) == NULLP)
291       break;
292    }
293 #else
294    elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
295    while(NULLP != elmIndx)
296    {
297       datInd = (RguDDatIndInfo *)elmIndx;
298       RlcProcDedLcUlData(&rlcUlRbfuPst, 0, datInd);
299
300       elmIndx = NULLP;
301       datInd = NULLP;
302       SRngIncrRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
303
304       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC)) == NULLP)
305         break;
306    }
307 #endif
308    return ROK;
309
310 }
311
312 /**
313  *
314  * @brief 
315  *        Handler to clear Ring buffer from UL RLC
316  *
317  * @details
318  *         This function clears all the ring buffer content from  UL RLC
319  *
320  * @return  S16
321  *      -# ROK 
322  *      -# RFAILED
323  *
324  */
325 Void rlcUtlFreeUlRBuf(void)
326 {
327    RguDDatIndInfo *datInd;
328    PTR            elem;
329    uint8_t        numLch;
330    uint8_t        numPdu;
331
332    /* Free SS_RNG_BUF_ULMAC_TO_ULRLC  */
333    while((SDeqSRngBuf (SS_RNG_BUF_ULMAC_TO_ULRLC, &elem) == ROK))
334    {
335       datInd = (RguDDatIndInfo *)elem; 
336       for(numLch = 0; numLch< datInd->numLch; numLch++)
337       {
338          for(numPdu = 0; numPdu < datInd->lchData[numLch].pdu.numPdu; numPdu++)
339          {
340             if(datInd->lchData[numLch].pdu.mBuf[numPdu])
341             {
342                ODU_PUT_MSG_BUF(datInd->lchData[numLch].pdu.mBuf[numPdu]);
343             }
344          }
345       }
346       RLC_PST_FREE(0, 0, datInd, sizeof(RguDDatIndInfo)); 
347    }
348 }
349 #endif
350 #ifdef RLC_MAC_STA_RSP_RBUF
351 S16 rlcLiRguStaRspRbuf(Pst *post,SpId spId,Void *staRsp)
352 {
353    S16 ret1 = ROK;
354    
355    Void *elem = NULLP;
356
357    RguDStaRspInfo  *staRspInfo = NULL;
358    elem = SRngGetWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
359    if (NULLP != elem)
360    {
361       staRspInfo = (RguDStaRspInfo *)elem;
362       memcpy(staRspInfo, staRsp, sizeof(RguDStaRspInfo)); 
363       staRspInfo->post = *post;
364       SRngIncrWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
365       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC].pktRate++;
366    }   
367    else
368    {
369       DU_LOG("\nERROR  -->  RLC_DL : RLC DL STA RSP RBUF is FULL!!! ");
370       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC].pktDrop++;
371       ret1 = RFAILED;
372    }
373    return (ret1);
374 } /* cmPkRlcDatReq */
375
376 #endif
377 #ifdef RLC_MAC_DAT_REQ_RBUF
378 S16 rlcLiRguDatReqRbuf(Pst *post,SpId spId,Void *datReq)
379 {
380    S16 ret1 = ROK;
381    
382    Void *elem = NULLP;
383    RguInfoRingElem *datReqRing=NULLP;
384    elem = SRngGetWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ);
385    if (NULLP != elem)
386    {
387       datReqRing = (RguInfoRingElem *) elem;
388       datReqRing->spId = spId;
389       datReqRing->event = post->event;
390       datReqRing->msg =datReq;
391       SRngIncrWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ);
392       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ].pktRate++;
393    }   
394    else
395    {
396       DU_LOG("\nERROR  -->  RLC_DL : RLC DL DAT REQ RBUF is FULL!!! \n");
397       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ].pktDrop++;
398       ret1 = RFAILED;
399    }
400    return (ret1);
401 } /* cmPkRlcDatReq */
402
403 #endif 
404
405 #ifdef __cplusplus
406 }
407 #endif /* __cplusplus */
408 \f  
409 /********************************************************************30**
410          End of file
411 **********************************************************************/