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