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