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