RLC BO, BO response and DL Data handling. [Issue-ID: ODUHIGH-181]
[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 EXTERN 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 #ifdef ANSI
167 S16 RlcLiRguBndReq
168 (
169 Pst  *post,                       /* post structure */
170 SuId suId,                      /* Service User Id */
171 SpId spId                       /* Service Provider Id */
172 )
173 #else
174 S16 RlcLiRguBndReq(post, suId, spId)
175 Pst  *post;                       /* post structure */
176 SuId suId;                      /* Service User Id */
177 SpId spId;                      /* Service Provider Id */
178 #endif
179 {
180    TRC3(RlcLiRguBndReq)
181
182    /* jump to specific primitive depending on configured selector */
183    (*kwLiRguBndReqMt[post->selector])(post, suId, spId);
184
185    return ROK;
186
187 } /* end of RlcLiRguBndReq */
188
189 \f
190 /**
191  *
192  * @brief 
193  *
194  *        Handler for bind confirmation from MAC.
195  *
196  * @b Description:
197  *
198  *        This function handles the bind confirmation received
199  *        from MAC. 
200  *
201  *  @param[in] post     - Post structure  
202  *  @param[in] suId    - Service provider SAP ID 
203  *  @param[in] reason  - Reason of confirmation
204  *
205  *  @return  S16
206  *      -# ROK 
207  */
208
209 #ifdef ANSI
210 S16 RlcLiRguUbndReq
211 (
212 Pst         *post,
213 SpId        spId,
214 Reason      reason
215 )
216 #else
217 S16 RlcLiRguUbndReq(post, spId, reason)
218 Pst         *post;
219 SpId        spId;
220 Reason      reason;
221 #endif
222 {
223    TRC3(RlcLiRguUbndReq)
224
225    /* jump to specific primitive depending on configured selector */
226    (*kwLiRguUbndReqMt[post->selector])(post, spId, reason);
227
228    return ROK;
229
230 } /* end of RlcLiRguUbndReq */
231
232 /* kw005.201 added support for L2 Measurement */
233 #ifdef LTE_L2_MEAS
234 #ifdef LTE_RLC_R9
235 \f  
236 /**
237  *
238  * @brief 
239  *
240  *        Handler for sending ulThrpMeasReqInfo from RLC to MAC for UL ip throughput measurement. 
241  *
242  * @b Description:
243  *
244  *        This function sends ulThrpMeasReqInfo from RLC to MAC whenver UL ip throughput
245  * measurement is ON for a single or multiple qci in a UE. This is an indication for MAC
246  * to start the T2/T1 time stamps for the coresponding LCHs in the UE.
247  *
248  *  @param[in] post                    Post structure  
249  *  @param[in] spId                   Service Provider ID
250  *  @param[in] ulThrpMeasReqInfo      Ul ip measurement request info
251  *
252  *  @return  S16
253  *      -# ROK 
254  *      -# RFAILED
255  *
256  */
257 #ifdef ANSI
258 S16 RlcLiRguL2MUlThrpMeasReq
259 (
260 Pst                     *post,
261 SpId                    spId,
262 RguL2MUlThrpMeasReqInfo *l2mUlThrpMeasReq
263 )
264 #else
265 S16 RlcLiRguL2MUlThrpMeasReq(post, spId, l2mUlThrpMeasReq)
266 Pst                     *post;
267 SpId                    spId;
268 RguL2MUlThrpMeasReqInfo *l2mUlThrpMeasReq;
269 #endif
270 {
271    TRC3(RlcLiRguL2MUlThrpMeasReq)
272
273    /* jump to specific primitive depending on configured selector */
274    (*kwLiRguL2MUlThrpMeasReqMt[post->selector])(post, spId, l2mUlThrpMeasReq);
275
276    return ROK;
277
278 } /* end of RlcLiRguL2MUlThrpMeasReq */
279
280 #endif /* LTE_RLC_R9 */
281 #endif /* LTE_L2_MEAS */
282
283
284 #ifdef MAC_RLC_UL_RBUF
285 S16 rlcUlBatchProc ARGS ((Void));
286 EXTERN Void rlcUtlFreeUlRBuf ARGS((void));
287
288 #ifdef ANSI
289 S16 rlcUlBatchProc
290 (
291 Void
292 )
293 #else
294 S16 rlcUlBatchProc()
295 Void;
296 #endif
297 {
298 /* Read from Ring Buffer and process PDCP packets */
299    RguDDatIndInfo   *datInd;
300    Void *elmIndx = NULLP;
301    PRIVATE Pst rlcUlRbfuPst={1,1,ENTRLC,0,ENTMAC,0,PRIOR0,RTESPEC,EVTRLCULDAT,0,0,0,0};
302 /* Read from Ring Buffer and process PDCP packets */
303
304 #ifndef SS_RBUF
305    RguDedDatInd1 *rguDatInd = NULLP;
306    U8 rngBufDeqIndx = 0;
307
308    elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
309    while(NULLP != elmIndx)
310    {
311       rguDatInd = (RguDedDatInd1 *)elmIndx;
312       datInd = (RguDDatIndInfo*) rguDatInd->msg; 
313       SsRngInfoTbl[SS_RNG_BUF_ULMAC_TO_ULRLC].nPktProc++;;//Number of pkt processed in tti
314       if(datInd != NULLP)
315       {
316          RlcProcDedLcUlData(&rlcUlRbfuPst, 0, datInd);
317       }
318       else
319       {
320          RLOG0(L_ERROR,"Received NULL buffer");
321       }
322       rguDatInd->msg=NULLP;
323       SRngIncrRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
324       elmIndx = NULLP;
325       rguDatInd = NULLP;
326
327       rngBufDeqIndx++;
328
329       //if(rngBufDeqIndx >= SS_RNG_MAX_ULMAC_TO_ULRLC_DQ_CNT)
330        // break;
331
332       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC)) == NULLP)
333       break;
334    }
335 #else
336    elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
337    while(NULLP != elmIndx)
338    {
339       datInd = (RguDDatIndInfo *)elmIndx;
340       RlcProcDedLcUlData(&rlcUlRbfuPst, 0, datInd);
341
342       elmIndx = NULLP;
343       datInd = NULLP;
344       SRngIncrRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
345
346       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC)) == NULLP)
347         break;
348    }
349 #endif
350    return ROK;
351
352 }
353
354 /**
355  *
356  * @brief 
357  *        Handler to clear Ring buffer from UL RLC
358  *
359  * @details
360  *         This function clears all the ring buffer content from  UL RLC
361  *
362  * @return  S16
363  *      -# ROK 
364  *      -# RFAILED
365  *
366  */
367 #ifdef ANSI
368 Void rlcUtlFreeUlRBuf(void)
369 #else
370 Void rlcUtlFreeUlRBuf()  
371 #endif
372 {
373    RguDDatIndInfo *datInd;
374    PTR            elem;
375    U8             numLch;
376    U8             numPdu;
377
378    TRC2(rlcUtlFreeUlRBuf)
379    /* Free SS_RNG_BUF_ULMAC_TO_ULRLC  */
380    while((SDeqSRngBuf (SS_RNG_BUF_ULMAC_TO_ULRLC, &elem) == ROK))
381    {
382       datInd = (RguDDatIndInfo *)elem; 
383       for(numLch = 0; numLch< datInd->numLch; numLch++)
384       {
385          for(numPdu = 0; numPdu < datInd->lchData[numLch].pdu.numPdu; numPdu++)
386          {
387             if(datInd->lchData[numLch].pdu.mBuf[numPdu])
388             {
389                RLC_FREE_BUF_WC(datInd->lchData[numLch].pdu.mBuf[numPdu]);
390             }
391          }
392       }
393       RLC_PST_FREE(0, 0, datInd, sizeof(RguDDatIndInfo)); 
394    }
395 }
396 #endif
397 #ifdef RLC_MAC_STA_RSP_RBUF
398 #ifdef ANSI
399 S16 rlcLiRguStaRspRbuf
400 (
401 Pst               *post,
402 SpId              spId,
403 Void             *staRsp
404 )
405 #else
406 S16 rlcLiRguStaRspRbuf(post, spId, staRsp)
407 Pst               *post;
408 SpId              spId;
409 Void              *staRsp;
410 #endif /* ANSI */
411 {
412    S16 ret1 = ROK;
413    
414    Void *elem = NULLP;
415
416    RguDStaRspInfo  *staRspInfo = NULL;
417    elem = SRngGetWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
418    if (NULLP != elem)
419    {
420       staRspInfo = (RguDStaRspInfo *)elem;
421       cmMemcpy((U8 *)staRspInfo, (U8 *)staRsp, sizeof(RguDStaRspInfo)); 
422       staRspInfo->post = *post;
423       SRngIncrWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
424       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC].pktRate++;
425    }   
426    else
427    {
428       RLOG0(L_ERROR,"RLC DL STA RSP RBUF is FULL!!! ");
429       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC].pktDrop++;
430       ret1 = RFAILED;
431    }
432    return (ret1);
433 } /* cmPkKwuDatReq */
434
435 #endif
436 #ifdef RLC_MAC_DAT_REQ_RBUF
437 #ifdef ANSI
438 S16 rlcLiRguDatReqRbuf
439 (
440 Pst               *post,
441 SpId              spId,
442 Void             *datReq
443 )
444 #else
445 S16 rlcLiRguDatReqRbuf(post, spId, datReq)
446 Pst               *post;
447 SpId              spId;
448 Void             *datReq;
449 #endif /* ANSI */
450 {
451    S16 ret1 = ROK;
452    
453    Void *elem = NULLP;
454    RguInfoRingElem *datReqRing=NULLP;
455    elem = SRngGetWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ);
456    if (NULLP != elem)
457    {
458       datReqRing = (RguInfoRingElem *) elem;
459       datReqRing->spId = spId;
460       datReqRing->event = post->event;
461       datReqRing->msg =datReq;
462       SRngIncrWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ);
463       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ].pktRate++;
464    }   
465    else
466    {
467       printf("RLC DL DAT REQ RBUF is FULL!!! \n");
468       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ].pktDrop++;
469       ret1 = RFAILED;
470    }
471    return (ret1);
472 } /* cmPkKwuDatReq */
473
474 #endif 
475
476 #ifdef __cplusplus
477 }
478 #endif /* __cplusplus */
479 \f  
480 /********************************************************************30**
481          End of file
482 **********************************************************************/