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