Moving all common header file into common_def.h file
[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 #ifdef EGTP_TEST
66 #include "mac_stub.h"
67 #endif /* EGTP_TEST */
68
69 #ifndef LCKWLIRGU
70 #define PTKWRGU
71 #endif
72
73 #ifndef RG
74 #define PTKWRGU
75 #endif
76
77 #ifdef __cplusplus
78 EXTERN "C" {
79 #endif /* __cplusplus */
80
81
82
83 #ifdef RLC_MAC_DAT_REQ_RBUF
84 PUBLIC S16 kwLiRguDatReqRbuf(Pst *Post,SpId spId,Void *datReq);
85 #endif
86
87 #ifdef RLC_MAC_STA_RSP_RBUF
88 PUBLIC S16 kwLiRguStaRspRbuf(Pst *Post,SpId spId,Void  *staRsp);
89 #endif
90 #if defined(MAC_RLC_HARQ_STA_RBUF) && defined(LTE_L2_MEAS)
91 EXTERN S16 KwDlHarqStaBatchProc (Void);
92 #endif
93
94 \f
95 /*********************************************************************
96  *             Primitives for RGU interface 
97  ********************************************************************/
98
99 /* RGU Bind Request primitive */
100
101 PUBLIC RguBndReq kwLiRguBndReqMt[] =
102 {
103 #ifdef LCKWLIRGU
104    cmPkRguBndReq,            /* 0 - loosely coupled */
105 #endif /* LCRGUIRGU */
106 #ifdef RG 
107    RgUiRguBndReq,            /* 1 - tightly coupled, MAC  */
108 #endif /* RG */
109 #ifdef LCKWLIRGU
110    cmPkRguBndReq,            /* 0 - loosely coupled */
111 #endif /* LCRGUIRGU */
112 };
113
114 /* RGU Unbind Request primitive */
115
116 PUBLIC RguBndReq kwLiRguUbndReqMt[] =
117 {
118 #ifdef LCKWLIRGU
119    cmPkRguUbndReq,            /* 0 - loosely coupled */
120 #endif /* LCRGUIRGU */
121 #ifdef RG 
122    RgUiRguUbndReq,            /* 1 - tightly coupled, MAC  */
123 #endif /* RG */
124 #ifdef LCKWLIRGU
125    cmPkRguUbndReq,            /* 0 - loosely coupled */
126 #endif /* LCRGUIRGU */
127 };
128
129 /* RGU Dedicated Channel Data Request primitive */
130
131 PUBLIC RlcMacDlData rlcMacSendDlDataOpts[] =
132 {
133 #ifdef EGTP_TEST
134    macStubSendDlData,
135    macStubSendDlData,
136    macStubSendDlData,
137 #else /* EGTP_TEST */
138 #ifdef LCKWLIRGU
139    packDlData,            /* 0 - loosely coupled */
140 #endif /* LCRGUIRGU */
141 #ifdef RG 
142    MacRlcProcDlData,      /* 1 - tightly coupled, MAC  */
143 #endif /* RG */
144 #ifdef LCKWLIRGU
145    packDlData,            /* 0 - loosely coupled */
146 #endif /* LCRGUIRGU */
147 #endif /* EGTP_TEST */
148 };
149
150
151 /* RLC logical Channel Status primitive */
152
153 PUBLIC RlcMacBoStatus rlcMacSendBOStatusOpts[] =
154 {
155 #ifdef EGTP_TEST
156    macStubBOStatus,
157    macStubBOStatus,
158    macStubBOStatus,
159 #else /* EGTP_TEST */
160 #ifdef LCKWLIRGU
161    packBOStatus,            /* 0 - loosely coupled */
162 #endif /* LCRGUIRGU */
163 #ifdef RG 
164    MacRlcProcBOStatus,            /* 1 - tightly coupled, MAC  */
165 #endif /* RG */
166 #ifdef LCKWLIRGU
167    packBOStatus,            /* 0 - LWLC loosely coupled */
168 #endif /* LCRGUIRGU */
169 #endif /* EGTP_TEST */
170 };
171
172 /* kw005.201 added support for L2 Measurement */
173 #ifdef LTE_L2_MEAS
174 #ifdef LTE_RLC_R9
175 /* RGU L2 Measurement Ul Ip Throughput Measurement Request primitive */
176
177 PUBLIC RguL2MUlThrpMeasReq kwLiRguL2MUlThrpMeasReqMt[] =
178 {
179 #ifdef LCKWLIRGU
180    cmPkRguL2MUlThrpMeasReq,            /* 0 - loosely coupled */
181 #endif /* LCRGUIRGU */
182 #ifdef RG 
183    RgUiRguL2MUlThrpMeasReq,            /* 1 - tightly coupled, MAC  */
184 #endif /* RG */
185 };
186 #endif /* LTE_RLC_R9 */
187 #endif /*  LTE_L2_MEAS */
188 \f
189 /****************************************************************************
190  *                         RGU Interface Mt functions
191  ***************************************************************************/
192 /**
193  *
194  * @brief 
195  *
196  *        Handler for RGU SAP bind Request.
197  *
198  * @b Description:
199  *
200  *        This function is used by RLC to request for binding to 
201  *        MAC for accessing MAC services.This function binds MAC's 
202  *        SAP (identified by spId) with the service user's SAP 
203  *        (identified by suId).
204  *
205  *  @param[in] pst   Post structure  
206  *  @param[in] suId  Service user SAP ID 
207  *  @param[in] spId  Service provider ID
208  *
209  *  @return  S16
210  *      -# ROK 
211  */
212
213 #ifdef ANSI
214 PUBLIC S16 KwLiRguBndReq
215 (
216 Pst  *post,                       /* post structure */
217 SuId suId,                      /* Service User Id */
218 SpId spId                       /* Service Provider Id */
219 )
220 #else
221 PUBLIC S16 KwLiRguBndReq(post, suId, spId)
222 Pst  *post;                       /* post structure */
223 SuId suId;                      /* Service User Id */
224 SpId spId;                      /* Service Provider Id */
225 #endif
226 {
227    TRC3(KwLiRguBndReq)
228
229    /* jump to specific primitive depending on configured selector */
230    (*kwLiRguBndReqMt[post->selector])(post, suId, spId);
231
232    RETVALUE(ROK);
233
234 } /* end of KwLiRguBndReq */
235
236 \f
237 /**
238  *
239  * @brief 
240  *
241  *        Handler for bind confirmation from MAC.
242  *
243  * @b Description:
244  *
245  *        This function handles the bind confirmation received
246  *        from MAC. 
247  *
248  *  @param[in] post     - Post structure  
249  *  @param[in] suId    - Service provider SAP ID 
250  *  @param[in] reason  - Reason of confirmation
251  *
252  *  @return  S16
253  *      -# ROK 
254  */
255
256 #ifdef ANSI
257 PUBLIC S16 KwLiRguUbndReq
258 (
259 Pst         *post,
260 SpId        spId,
261 Reason      reason
262 )
263 #else
264 PUBLIC S16 KwLiRguUbndReq(post, spId, reason)
265 Pst         *post;
266 SpId        spId;
267 Reason      reason;
268 #endif
269 {
270    TRC3(KwLiRguUbndReq)
271
272    /* jump to specific primitive depending on configured selector */
273    (*kwLiRguUbndReqMt[post->selector])(post, spId, reason);
274
275    RETVALUE(ROK);
276
277 } /* end of KwLiRguUbndReq */
278
279 \f  
280 /**
281  *
282  * @brief 
283  *
284  *        Handler for sending PDU(s) from RLC to MAC for dedicated logical channels. 
285  *
286  * @b Description:
287  *
288  *        This function sends PDU(s) to MAC via one or more dedicated 
289  *        logical channels along with the Buffer Occupancy of these
290  *        channels.
291  *
292  *  @param[in] post         Post structure  
293  *  @param[in] spId        Service Provider ID
294  *  @param[in] datIndInfo  Data Request Information 
295  *
296  *  @return  S16
297  *      -# ROK 
298  *      -# RFAILED
299  *
300  */
301 #ifdef ANSI
302 PUBLIC S16 RlcMacSendDlData
303 (
304 Pst               *post,
305 SpId              spId,
306 RlcMacData       *dlData
307 )
308 #else
309 PUBLIC S16 RlcMacSendDlData(post, spId, dlData)
310 Pst               *post;
311 SpId              spId;
312 RlcMacData        *dlData;
313 #endif
314 {
315    TRC3(RlcMacSendDlData)
316 #ifdef RLC_MAC_DAT_REQ_RBUF
317         post->event=EVTRGUDDATREQ;
318       if((kwLiRguDatReqRbuf(post, spId, datReq)) != ROK)
319       {
320
321       SPutStaticBuffer(post->region, post->pool,                      
322                       (Data *) datReq, sizeof(RguDDatReqInfo), 0);             
323          RETVALUE(RFAILED);
324       }
325 #else
326    /* jump to specific primitive depending on configured selector */
327    (*rlcMacSendDlDataOpts[post->selector])(post, spId, dlData);
328 #endif 
329    RETVALUE(ROK);
330
331 } /* end of KwLiRguDDatReq */
332
333
334 \f  
335 /**
336  *
337  * @brief  
338  *
339  *        Handler for reporting the Buffer Occupancy to MAC 
340  *        for logical channels.
341  *
342  * @b Description:
343  *
344  *        This function reports the Buffer Occupancy of one or more
345  *         logical channels to MAC. 
346  *
347  *  @param[in] post         Post structure  
348  *  @param[in] spId        Service Provider ID
349  *  @param[in] boSta       BO Status Information 
350  *
351  *  @return  S16
352  *      -# ROK 
353  *      -# RFAILED
354  *
355  */
356 #ifdef ANSI
357 PUBLIC S16 RlcMacSendBOStatus
358 (
359 Pst               *post,
360 SpId              spId,
361 RlcMacBOStatus    *boSta
362 )
363 #else
364 PUBLIC S16 RlcMacSendBOStatus(post, spId, staRsp)
365 Pst               *post;
366 SpId              spId;
367 RlcMacBOStatus    *boSta;
368 #endif
369 {
370    TRC3(RlcMacSendBOStatus)
371 #if defined(SPLIT_RLC_DL_TASK) && defined(RLC_MAC_STA_RSP_RBUF)
372        post->event= EVTRGUDSTARSP;
373       if((kwLiRguStaRspRbuf(post, spId, staRsp)) != ROK)
374       {
375          RETVALUE(RFAILED);
376       }
377 #endif 
378    /* jump to specific primitive depending on configured selector */
379    (*rlcMacSendBOStatusOpts[post->selector])(post, spId, boSta);
380
381    RETVALUE(ROK);
382
383 } /* end of RlcMacSendBOStatus */
384
385
386 /* kw005.201 added support for L2 Measurement */
387 #ifdef LTE_L2_MEAS
388 #ifdef LTE_RLC_R9
389 \f  
390 /**
391  *
392  * @brief 
393  *
394  *        Handler for sending ulThrpMeasReqInfo from RLC to MAC for UL ip throughput measurement. 
395  *
396  * @b Description:
397  *
398  *        This function sends ulThrpMeasReqInfo from RLC to MAC whenver UL ip throughput
399  * measurement is ON for a single or multiple qci in a UE. This is an indication for MAC
400  * to start the T2/T1 time stamps for the coresponding LCHs in the UE.
401  *
402  *  @param[in] post                    Post structure  
403  *  @param[in] spId                   Service Provider ID
404  *  @param[in] ulThrpMeasReqInfo      Ul ip measurement request info
405  *
406  *  @return  S16
407  *      -# ROK 
408  *      -# RFAILED
409  *
410  */
411 #ifdef ANSI
412 PUBLIC S16 KwLiRguL2MUlThrpMeasReq
413 (
414 Pst                     *post,
415 SpId                    spId,
416 RguL2MUlThrpMeasReqInfo *l2mUlThrpMeasReq
417 )
418 #else
419 PUBLIC S16 KwLiRguL2MUlThrpMeasReq(post, spId, l2mUlThrpMeasReq)
420 Pst                     *post;
421 SpId                    spId;
422 RguL2MUlThrpMeasReqInfo *l2mUlThrpMeasReq;
423 #endif
424 {
425    TRC3(KwLiRguL2MUlThrpMeasReq)
426
427    /* jump to specific primitive depending on configured selector */
428    (*kwLiRguL2MUlThrpMeasReqMt[post->selector])(post, spId, l2mUlThrpMeasReq);
429
430    RETVALUE(ROK);
431
432 } /* end of KwLiRguL2MUlThrpMeasReq */
433
434 #endif /* LTE_RLC_R9 */
435 #endif /* LTE_L2_MEAS */
436
437
438 #ifdef MAC_RLC_UL_RBUF
439 PUBLIC S16 kwUlBatchProc ARGS ((Void));
440 EXTERN Void kwUtlFreeUlRBuf ARGS((void));
441
442 #ifdef ANSI
443 PUBLIC S16 kwUlBatchProc
444 (
445 Void
446 )
447 #else
448 PUBLIC S16 kwUlBatchProc()
449 Void;
450 #endif
451 {
452 /* Read from Ring Buffer and process PDCP packets */
453    RguDDatIndInfo   *datInd;
454    Void *elmIndx = NULLP;
455    PRIVATE Pst rlcUlRbfuPst={1,1,ENTKW,0,ENTRG,0,PRIOR0,RTESPEC,EVTRLCULDAT,0,0,0,0};
456 /* Read from Ring Buffer and process PDCP packets */
457
458 #ifndef SS_RBUF
459    RguDedDatInd1 *rguDatInd = NULLP;
460    U8 rngBufDeqIndx = 0;
461
462    elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
463    while(NULLP != elmIndx)
464    {
465       rguDatInd = (RguDedDatInd1 *)elmIndx;
466       datInd = (RguDDatIndInfo*) rguDatInd->msg; 
467       SsRngInfoTbl[SS_RNG_BUF_ULMAC_TO_ULRLC].nPktProc++;;//Number of pkt processed in tti
468       if(datInd != NULLP)
469       {
470          KwLiRguDDatInd(&rlcUlRbfuPst, 0, datInd);
471       }
472       else
473       {
474          RLOG0(L_ERROR,"Received NULL buffer");
475       }
476       rguDatInd->msg=NULLP;
477       SRngIncrRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
478       elmIndx = NULLP;
479       rguDatInd = NULLP;
480
481       rngBufDeqIndx++;
482
483       //if(rngBufDeqIndx >= SS_RNG_MAX_ULMAC_TO_ULRLC_DQ_CNT)
484        // break;
485
486       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC)) == NULLP)
487       break;
488    }
489 #else
490    elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
491    while(NULLP != elmIndx)
492    {
493       datInd = (RguDDatIndInfo *)elmIndx;
494       KwLiRguDDatInd(&rlcUlRbfuPst, 0, datInd);
495
496       elmIndx = NULLP;
497       datInd = NULLP;
498       SRngIncrRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC);
499
500       if((elmIndx = SRngGetRIndx(SS_RNG_BUF_ULMAC_TO_ULRLC)) == NULLP)
501         break;
502    }
503 #endif
504    RETVALUE(ROK);
505
506 }
507
508 /**
509  *
510  * @brief 
511  *        Handler to clear Ring buffer from UL RLC
512  *
513  * @details
514  *         This function clears all the ring buffer content from  UL RLC
515  *
516  * @return  S16
517  *      -# ROK 
518  *      -# RFAILED
519  *
520  */
521 #ifdef ANSI
522 PUBLIC Void kwUtlFreeUlRBuf(void)
523 #else
524 PUBLIC Void kwUtlFreeUlRBuf()  
525 #endif
526 {
527    RguDDatIndInfo *datInd;
528    PTR            elem;
529    U8             numLch;
530    U8             numPdu;
531
532    TRC2(kwUtlFreeUlRBuf)
533    /* Free SS_RNG_BUF_ULMAC_TO_ULRLC  */
534    while((SDeqSRngBuf (SS_RNG_BUF_ULMAC_TO_ULRLC, &elem) == ROK))
535    {
536       datInd = (RguDDatIndInfo *)elem; 
537       for(numLch = 0; numLch< datInd->numLch; numLch++)
538       {
539          for(numPdu = 0; numPdu < datInd->lchData[numLch].pdu.numPdu; numPdu++)
540          {
541             if(datInd->lchData[numLch].pdu.mBuf[numPdu])
542             {
543                KW_FREE_BUF_WC(datInd->lchData[numLch].pdu.mBuf[numPdu]);
544             }
545          }
546       }
547       KW_PST_FREE(0, 0, datInd, sizeof(RguDDatIndInfo)); 
548    }
549 }
550 #endif
551 #ifdef RLC_MAC_STA_RSP_RBUF
552 #ifdef ANSI
553 PUBLIC S16 kwLiRguStaRspRbuf
554 (
555 Pst               *post,
556 SpId              spId,
557 Void             *staRsp
558 )
559 #else
560 PUBLIC S16 kwLiRguStaRspRbuf(post, spId, staRsp)
561 Pst               *post;
562 SpId              spId;
563 Void              *staRsp;
564 #endif /* ANSI */
565 {
566    S16 ret1 = ROK;
567    
568    Void *elem = NULLP;
569
570    RguDStaRspInfo  *staRspInfo = NULL;
571    elem = SRngGetWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
572    if (NULLP != elem)
573    {
574       staRspInfo = (RguDStaRspInfo *)elem;
575       cmMemcpy((U8 *)staRspInfo, (U8 *)staRsp, sizeof(RguDStaRspInfo)); 
576       staRspInfo->post = *post;
577       SRngIncrWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC);
578       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC].pktRate++;
579    }   
580    else
581    {
582       RLOG0(L_ERROR,"RLC DL STA RSP RBUF is FULL!!! ");
583       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC].pktDrop++;
584       ret1 = RFAILED;
585    }
586    RETVALUE(ret1);
587 } /* cmPkKwuDatReq */
588
589 #endif
590 #ifdef RLC_MAC_DAT_REQ_RBUF
591 #ifdef ANSI
592 PUBLIC S16 kwLiRguDatReqRbuf
593 (
594 Pst               *post,
595 SpId              spId,
596 Void             *datReq
597 )
598 #else
599 PUBLIC S16 kwLiRguDatReqRbuf(post, spId, datReq)
600 Pst               *post;
601 SpId              spId;
602 Void             *datReq;
603 #endif /* ANSI */
604 {
605    S16 ret1 = ROK;
606    
607    Void *elem = NULLP;
608    RguInfoRingElem *datReqRing=NULLP;
609    elem = SRngGetWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ);
610    if (NULLP != elem)
611    {
612       datReqRing = (RguInfoRingElem *) elem;
613       datReqRing->spId = spId;
614       datReqRing->event = post->event;
615       datReqRing->msg =datReq;
616       SRngIncrWIndx(SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ);
617       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ].pktRate++;
618    }   
619    else
620    {
621       printf("RLC DL DAT REQ RBUF is FULL!!! \n");
622       SsRngInfoTbl[SS_RNG_BUF_DLRLC_TO_DLMAC_DAT_REQ].pktDrop++;
623       ret1 = RFAILED;
624    }
625    RETVALUE(ret1);
626 } /* cmPkKwuDatReq */
627
628 #endif 
629
630 #ifdef __cplusplus
631 }
632 #endif /* __cplusplus */
633 \f  
634 /********************************************************************30**
635          End of file
636 **********************************************************************/