Trigger_macCellCfg
[o-du/l2.git] / src / 5gnrmac / rg.h
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  
21     Name:   MAC layer
22  
23     Type:   H include file
24  
25     Desc:   Defines required by LTE-MAC
26  
27     File:   rg.h
28  
29 **********************************************************************/
30  
31 /** @file rg.h
32 @brief This file contains definitons for Mac.
33 */
34 \f
35  
36 #ifndef __RGH__
37 #define __RGH__
38
39 #include "rl_interface.h"
40 #include "rl_common.h"
41
42
43 #ifdef L2_OPTMZ
44 #include "gen.x"           /* general layer */
45 #include "ssi.x"           /* system service interface */
46 #include "ss_strm.h"
47 #include "ss_strm.x"
48 #include "ss_queue.h"
49 #include "ss_queue.x"
50 #include "ss_task.x"
51 #include "ss_msg.x" 
52
53 #define RG_MAC_HDR_SIZE 250
54 #define RG_MAC_CE_SIZE  250
55 U32 MacPtrAddress;
56 U32 macHeader[2];
57
58 #define RG_ADD_DBuf(_dBuf,_size,_mBuf)\
59 { \
60   SsMsgInfo *mInfo = NULLP; \
61   mInfo = (SsMsgInfo *)_mBuf->b_rptr; \
62   ssGetDBufOfSize(mInfo->region,_size, &_dBuf); \
63   SUpdMsg(_mBuf, _dBuf,0);\
64   _dBuf->b_wptr = _dBuf->b_rptr =  (_dBuf->b_datap->db_base + 5);\
65   MacPtrAddress = (U32)_dBuf->b_wptr;\
66 }
67 #endif
68
69
70
71 #define RGLAYERNAME     "MAC"
72 #define RG_MAX_TB_PER_UE 2
73 #define RG_MAX_BCCH_DLSCH 2
74 #define RG_INVALID_RNTI   0x0000
75
76 #define RG_MAX_NUM_DED_LC 10       /* maximum dedicated logical channels in a UE */
77 #define RG_MAX_NUM_CMN_LC 5       /* maximum number of common logical 
78                                      channels in a cell */
79 #define RG_MAX_LCG_PER_UE 4
80 #define RG_CON_RES_ID_SZ  6
81 #define RG_MAX_RA_RNTI   60
82
83 /* Added support for SPS*/
84 #ifdef LTEMAC_SPS
85 #define RG_ADDL_SPS_OCC_FOR_EXP_REL 2
86
87 #define RG_SPS_SID_PACKET_SIZE 10
88 #define RG_SPS_LCG_ID  1
89
90 #endif
91
92 /* Well known RNTIS */
93 #define RG_SI_RNTI        0xffff
94 #define RG_P_RNTI         0xfffe
95
96 #define RG_MAX_UPPERSAP               3
97 #define RG_MAX_LOWERSAP               1 
98 #define RG_TQ_SIZE                    10   /* Timing Queue Size */
99 #define RG_MAX_TIMER     RG_MAX_LOWERSAP   /* MAX number of MAC timers */
100 #define RG_NMB_CELL_HASHBIN           10   /* Number of Hash Bins for cell hash
101                                               table */
102 #define RG_NMB_UE_HASHBIN             10   /* Number of Hash Bins for UE hash
103                                               table */        
104 #define RG_BNDREQ_TMR    1    /* Bind Request timer event value */
105 #define RG_MAX_BNDRETRY  2    /* Max number of Bind Retries for TFU SAP */
106
107
108 #define RG_UE_TQ_SIZE    10   /* Timing Queue Size */
109
110 #define RG_INVALID_SCHD_TYPE 255
111 #define RG_MAX_UE_PER_CELL 0xFFFF /*!< Maximum number of UEs per cell */
112 #ifdef EIGHT_UE_PER_TTI_CHANGES
113 #define RG_MAX_UE_BIN_PER_CELL 1024 /*!< Maximum number of UE bins per cell */
114 #else
115 #define RG_MAX_UE_BIN_PER_CELL 128 /*!< Maximum number of UE bins per cell */
116 #endif
117 #define RG_MIN_DL_BW       6    /*!< Minimum Downlink bandwidth in RBs */
118 #define RG_MAX_DL_BW       110  /*!< Maximum Downlink bandwidth in RBs */
119 #define RG_MIN_UL_BW       6    /*!< Minimum Uplink bandwidth in RBs */
120 #define RG_MAX_UL_BW       110  /*!< Maximum Uplink bandwidth in RBs */
121 #define RG_MIN_CFI_VAL     1    /*!< Minimum value for CFI */
122 #define RG_MAX_CFI_VAL     3    /*!< Maximum value for CFI */
123 #define RG_QM_BPSK         2    /*!< Qm value for BPSK */
124 #define RG_QM_QPSK         4    /*!< Qm value for QPSK */
125 #define RG_QM_64QAM        6    /*!< Qm value for 64QAM */
126 #define RG_MIN_SRS_SFCFG_IDX 0  /*!< Minimum value for SRS subframe 
127                                      configurtion index */
128 #define RG_MAX_SRS_SFCFG_IDX 15  /*!< Maximum value for SRS subframe 
129                                      configurtion index */
130 #define RG_MAX_SRS_TX_OFFSET 8    /*!< Maximum number of SRS transmission 
131                                     offsets per cell */
132 #define RG_MIN_MAC_RNTI      10   /*!< Minimum value of RNTI to be managed by 
133                                     MAC */
134
135 /* HARQ related MACROs */
136 #define RG_NUM_DL_HQ_PROC 8
137 #define RG_NUM_UL_HQ_PROC 8
138 #define RG_MIN_HQ_TX 1
139
140 /* Group power related MACROs */
141 #define RG_MAX_GRP_PWR_FMT3_IDX  15   /*!< Maximum index value for group power format 3 */
142 #define RG_MAX_GRP_PWR_FMT3A_IDX 31   /*!< Maximum index value for group power format 3A */
143
144 /* MACROs to indicate cell specific config for cell to be active */
145 #define RG_BCCH_BCH_CFG_DONE      (1<<0)
146 #define RG_BCCH_DLSCH_CFG1_DONE    (1<<1)
147 #define RG_BCCH_DLSCH_CFG2_DONE    (1<<2)
148 #define RG_PCCH_CFG_DONE          (1<<3)
149 #define RG_UL_CCCH_CFG_DONE       (1<<4)
150 #define RG_DL_CCCH_CFG_DONE       (1<<5)
151 #define RG_SCHD_CFG_DONE          (1<<6)
152 #define RG_CELL_ACTIVE (RG_BCCH_BCH_CFG_DONE | RG_BCCH_DLSCH_CFG1_DONE |  RG_BCCH_DLSCH_CFG2_DONE | RG_PCCH_CFG_DONE | RG_UL_CCCH_CFG_DONE | RG_DL_CCCH_CFG_DONE)
153 /* Logical channel realated MACROs */
154 #define RG_INVALID_LCG_ID  255
155 #define RG_INVALID_LC_ID   255
156 #define RG_BCCH_BCH_IDX   0
157 #define RG_BCCH_DLSCH_IDX 1
158 #define RG_PCCH_IDX 2
159
160 /* constants for MIN & MAX qci*/
161 #define RG_QCI_MIN 1
162 #define RG_QCI_MAX 9
163
164 /* PUCCH related macros */
165 #define RG_PUCCH_MAXVAL_CS    7   /*!< Maximum value for cyclic shift of PUCCH */
166 #define RG_PUCCH_MINVAL_DS    1   /*!< Mininmum value for delta shift of PUCCH */
167 #define RG_PUCCH_MAXVAL_DS    3   /*!< Maximum value for delta shift of PUCCH */
168
169 /* DUX related macros */
170 #define RG_LCID_MASK 0x3F
171
172 #define RG_LCID_LEN 0x6
173 #define RG_CCCH_LCID 0x00
174 #define RG_DEDLC_MIN_LCID 0x01
175 #define RG_DEDLC_MAX_LCID 0x0A
176 #define RG_RES_MIN_LCID 0x0B
177 #define RG_RES_MAX_LCID 0x18
178 #define RG_EXT_PHR_LCID 0x19
179 #define RG_PHR_LCID 0x1A
180 #define RG_CRNTI_LCID 0X1B
181 #define RG_TRUNC_BSR_LCID 0X1C
182 #define RG_SHORT_BSR_LCID 0X1D
183 #define RG_LONG_BSR_LCID  0X1E
184 #define RG_PAD_LCID 0x3F
185 #define RG_MAX_EXTN_PAD_SUBHDRS 0x02
186 #define RG_REF_PCMAX  0xFF
187
188 #define RG_CCCH_SDU_PRSNT     (1<<0)
189 #define RG_CRNTI_CE_PRSNT     (1<<1)
190 #define RG_PHR_CE_PRSNT       (1<<2)
191 #define RG_TRUNC_BSR_CE_PRSNT (1<<3)
192 #define RG_SHORT_BSR_CE_PRSNT (1<<4)
193 #define RG_LONG_BSR_CE_PRSNT  (1<<5)
194 /* L2_COUNTERS */
195 #define RG_ACTIVE_LC_PRSNT  (1<<6)
196
197 #ifdef LTEMAC_SPS
198 #define RG_UL_SPS_ACT_PRSNT (1<<7)
199 #endif
200 #define RG_EXT_PHR_CE_PRSNT (1<<8)
201
202 /* LOGICAL CHANNEL */
203 #define RG_MAX_LC_PER_UE      10
204 /* Maximum number of common logical channel control blocks */
205 #define RG_MAX_CMN_LC_CB      3
206 #define RG_MAX_BCCH           2
207
208 #ifdef LTE_ADV
209 #define RG_MAX_SCELL_PER_UE   7  /*!< MAX SCell can be Added per Cell */
210 #endif /* LTE_ADV */
211
212 #define RG_OPTM_NUM_DED_LC    3
213
214 /* Random access related MACROs */
215 #define RG_MAX_RA_PREAMBLE_FMT 3 /*!< Maximun value of Random access preamble 
216                                       format */
217 #define RG_MAX_RA_WINSIZE    10  /*!< Maximum size of Random access response 
218                                       window in subframes */
219 #define RG_MIN_RA_WINSIZE    2   /*!< Minimum size of Random access response 
220                                       window in subframes */
221 #define RG_MIN_NUM_RA_PREAMBLE 4 /*!< Minimum number of Random access 
222                                       preambles */
223 #define RG_MAX_NUM_RA_PREAMBLE 64 /*!< Maximim number of Random access 
224                                       preambles */
225 #define RG_NUM_RA_RB     6
226
227 #define RG_MAX_RA_RSP_ALLOC    4 /*!< Maximum number of Random access
228                                       allocations */
229 #define RG_CRG_CFG 1          /* CRG configuration element */
230 #define RG_RGR_CFG 2          /* RGR configuration element */
231
232 #define RG_NUM_ITBS         27
233 #define RG_MAX_NUM_RB       110
234
235 #define RG_MAX_NUM_PAD_HDRS 2
236
237 /* Changes for MIMO feature addition */
238 /* Removed dependency on MIMO compile-time flag */
239 #define RG_MAX_LYR_PERCW    2
240
241 #ifdef LTE_TDD
242 #define RG_MAX_DL_HARQ_NUM   15
243 #else
244 #define RG_MAX_DL_HARQ_NUM   8 
245 #endif
246
247 #define MAC_MEM_REGION     4
248 #define MAC_POOL 1
249 /* allocate and zero out a MAC static buffer */
250 #define MAC_ALLOC(_datPtr, _size)                            \
251 {                                                            \
252    S16 _ret;                                                 \
253    _ret = SGetSBuf(MAC_MEM_REGION, MAC_POOL,                 \
254                     (Data **)&_datPtr, _size);               \
255    if(_ret == ROK)                                           \
256       cmMemset((U8*)_datPtr, 0, _size);                      \
257    else                                                      \
258       _datPtr = NULLP;                                       \
259 }
260
261 /* free a static buffer */
262 #define MAC_FREE(_datPtr, _size)                             \
263    if(_datPtr)                                               \
264       SPutSBuf(MAC_MEM_REGION, MAC_POOL,                     \
265          (Data *)_datPtr, _size);
266
267 #define RG_LCG_ISCFGD(lcg) ((lcg)->lcgId != RG_INVALID_LCG_ID)
268 /* Corrected the check for dlCcchId */
269 #define RG_DLCCCH_ISCFGD(cell) ((cell)->dlCcchId != RG_INVALID_LC_ID)
270 #define RG_ULCCCH_ISCFGD(cell) ((cell)->ulCcchId != RG_INVALID_LC_ID)
271 /* After merging from 2.1 to 2.2 */
272 #define RG_CALC_SF_DIFF(_time1, _time2)\
273    (_time1.sfn*RG_NUM_SUB_FRAMES_5G+_time1.subframe) < (_time2.sfn*RG_NUM_SUB_FRAMES_5G+_time2.subframe)?\
274      ((_time1.sfn+RG_MAX_SFN)*RG_NUM_SUB_FRAMES_5G+_time1.subframe) -\
275        (_time2.sfn*RG_NUM_SUB_FRAMES_5G+_time2.subframe) : \
276      (_time1.sfn*RG_NUM_SUB_FRAMES_5G+_time1.subframe) - (_time2.sfn*RG_NUM_SUB_FRAMES_5G+_time2.subframe)
277 /*LTE_L2_MEAS_PHASE2*/
278 #define RG_CALC_SFN_SF_DIFF(_time1,_sfnCycle, _time2)\
279 (((_time1.sfn+RG_MAX_SFN * _sfnCycle)*RG_NUM_SUB_FRAMES_5G) + _time1.subframe -\
280 (_time2.sfn*RG_NUM_SUB_FRAMES_5G + _time2.subframe))
281
282 #define RG_EXT_LCID(_lcId, _byte) {\
283       (_lcId) = (_byte) & RG_LCID_MASK; \
284 }
285 #define RG_EXT_FORMT_BIT(_fmtBit, _byte) {\
286       (_fmtBit) = ((_byte) >> RG_LCID_LEN) & 0x01; \
287 }
288
289 #define RG_EXT_EXTN_BIT(_extnBit, _byte) {\
290       (_extnBit) = ((_byte) >> RG_LCID_LEN) & 0x01; \
291 }
292
293 #ifndef MS_MBUF_CORRUPTION
294 #define MS_BUF_ADD_ALLOC_CALLER()
295 #endif
296
297 #define RG_PACK_PAD(_padBuf,_size,_sduBuf) { \
298   Buffer *sduEnd = NULLP; \
299   SsMsgInfo *mInfo = NULLP; \
300   mInfo = (SsMsgInfo *)_sduBuf->b_rptr; \
301   ssGetDBufOfSize(mInfo->region,_size, &_padBuf); \
302   if (_padBuf == NULLP) \
303   { \
304     RLOG0(L_ERROR, "RGERR_MUX_BLD_CEHDR_FAIL");\
305     RETVALUE(RFAILED);\
306   } \
307   if (mInfo->endptr == NULLP) { \
308     sduEnd = _sduBuf; \
309     }\
310   else \
311   {  \
312     sduEnd = mInfo->endptr; \
313   } \
314   sduEnd->b_cont = _padBuf; \
315   padBuf->b_wptr += _size; \
316   mInfo = (SsMsgInfo *)_sduBuf->b_rptr; \
317   mInfo->endptr = _padBuf; \
318   mInfo->len += _size; \
319 }
320
321 #define RG_PACK_SDU(_sdusBuf, _sduBuf, _ret) {\
322    _ret = SCatMsg(_sdusBuf, _sduBuf, M1M2);\
323 }
324
325 #define RG_PACK_LAST_SDU_SHDR(_subHdr, _lcId, _mBuf, _ret) {\
326    _ret = ROK;\
327    _subHdr.shLen = 1;\
328    _subHdr.shData[0] = (0x1F & _lcId);\
329    MS_BUF_ADD_ALLOC_CALLER(); \
330    _ret = SAddPstMsgMult(&_subHdr.shData[0], _subHdr.shLen, _mBuf);\
331 }
332
333 #define RGADDTOCRNTTIME(crntTime, toFill, incr)          \
334    if ((crntTime.subframe + incr) > (RG_NUM_SUB_FRAMES_5G - 1))   \
335       toFill.sfn = (crntTime.sfn + 1);      \
336    else                                                  \
337       toFill.sfn = crntTime.sfn;                              \
338    toFill.subframe = (crntTime.subframe + incr) % RG_NUM_SUB_FRAMES_5G; \
339    if (toFill.sfn >= RG_MAX_SFN) \
340    { \
341       toFill.hSfn = (crntTime.hSfn + 1)%RG_MAX_SFN; \
342       toFill.sfn%=RG_MAX_SFN; \
343    } \
344    else \
345    { \
346       toFill.hSfn = crntTime.hSfn; \
347    }
348
349 #define RGSUBFRMCRNTTIME(crntTime, toFill, dcr)    \
350 {                                                  \
351    if (crntTime.sfn == 0)                          \
352 {                                                  \
353    if ((crntTime.subframe - (dcr)) < 0)              \
354    {                                               \
355       toFill.sfn = RG_MAX_SFN - 1;                 \
356    }                                               \
357    else                                            \
358    {                                               \
359    toFill.sfn = crntTime.sfn;                      \
360    }                                               \
361 }                                                  \
362 else                                               \
363 {                                                  \
364    if ((crntTime.subframe - (dcr)) < 0)              \
365    {                                               \
366    toFill.sfn = crntTime.sfn - 1;                  \
367    }                                               \
368    else                                            \
369    toFill.sfn = crntTime.sfn;                      \
370 }                                                  \
371 toFill.subframe = (RG_NUM_SUB_FRAMES_5G + crntTime.subframe - (dcr)) % (RG_NUM_SUB_FRAMES_5G);                                   \
372 }
373
374 #define RGCPYTIMEINFO(src, dst)  \
375    dst.hSfn        = src.hSfn;     \
376    dst.sfn        = src.sfn;     \
377    dst.subframe   = src.subframe;
378 #define RG_TIMEINFO_SAME(x, y) ((x.sfn == y.sfn) && (x.subframe == y.subframe))
379
380
381 #define rgPBuf(_inst)  rgCb[_inst].rgInit.prntBuf
382
383 /* Debug Prints for MAC */
384 #ifdef DEBUGP
385 #define RGDBGERRNEW(_inst,_args)          \
386                   DBGP(&rgCb[_inst].rgInit, RGLAYERNAME, DBGMASK_ERR, _args)
387 #define RGDBGINFONEW(_inst,_args)         \
388                   DBGP(&rgCb[_inst].rgInit, RGLAYERNAME, DBGMASK_INFO, _args)
389 #else
390 #define RGDBGERRNEW(_inst,_args) 
391 #define RGDBGINFONEW(_inst,_args)
392 #endif /* #ifdef DEBUGP */
393 #define RGDBGPRM(_inst,_args) 
394 #define RGDBGERR(_inst,_args) 
395 #define RGDBGINFO(_inst,_args)
396
397 #ifdef ERRCLS_KW
398 #define RG_NULL_CHECK(_inst, _ptr )     \
399    if((_ptr) == NULLP)  \
400    {                                               \
401       RGDBGERRNEW(_inst, (rgPBuf(_inst),"Null Pointer detected"));\
402       SExit();\
403    }
404 #define RG_ARRAY_BOUND_CHECK(_inst, _array, _idxVal)     \
405    if((_idxVal) >= (sizeof(_array)/sizeof(_array[0]))) \
406    {                                               \
407       RGDBGERRNEW(_inst, (rgPBuf(_inst),"Array Bound Check Failed"));\
408       SExit();\
409    }
410 #else
411 #define RG_NULL_CHECK(_inst, _ptr )     
412 #define RG_ARRAY_BOUND_CHECK(_inst, _array, _idxVal)     
413 #endif
414
415 /* Macro to free the message buffer and initialize it to zero */
416 /***********************************************************
417  *
418  *     Name : RG_FREE_MSG
419  *
420  *     Desc : Macro to free the message buffer and initialize it to zero
421  *            
422  *     Input  : mBuf - message buffer pointer to be retunrned
423  *
424  *     Output : None.
425  *
426  *     Notes: None
427  *
428  **********************************************************/
429 #define RG_FREE_MSG(_buf)\
430 {\
431    if (NULLP != (_buf)) \
432    { \
433       SPutMsg((_buf)); \
434       _buf = NULLP; \
435    } \
436 }
437
438 #define RG_FREE_MEM(_mem)\
439 {\
440    if (NULLP != (_mem)) \
441    { \
442       cmFreeMem((_mem)); \
443       _mem = NULLP; \
444    } \
445 }
446
447 #ifdef L2_OPTMZ
448 #define RG_FREE_TB(_tb)\
449 {\
450    U32 lchIdx, pduIdx;\
451    SResetMBuf(_tb->macHdr);\
452    SResetMBuf(_tb->macCes);\
453    _tb->tbPres = FALSE;\
454    _tb->tbSize = 0;\
455    _tb->padSize = 0;\
456    for(lchIdx = 0; lchIdx < _tb->numLch; lchIdx++) \
457    {\
458       for(pduIdx = 0; pduIdx < _tb->lchInfo[lchIdx].numPdu; pduIdx++)\
459       {\
460           if(_tb->lchInfo[lchIdx].mBuf[pduIdx] != NULL)\
461           {\
462             SPutMsg(_tb->lchInfo[lchIdx].mBuf[pduIdx]);\
463             _tb->lchInfo[lchIdx].freeBuff = FALSE;\
464           }\
465           _tb->lchInfo[lchIdx].mBuf[pduIdx] = NULL;\
466       }\
467       _tb->lchInfo[lchIdx].numPdu = 0;\
468    }\
469    _tb->numLch = 0;\
470 }
471
472 #define RG_FREE_SAVED_TB(_tb)\
473 {\
474    U32 lchIdx, pduIdx;\
475    RG_FREE_MSG(_tb->macHdr);\
476    RG_FREE_MSG(_tb->macCes);\
477    _tb->tbPres = FALSE;\
478    _tb->tbSize = 0;\
479    _tb->padSize = 0;\
480    for(lchIdx = 0; lchIdx < 10; lchIdx++) \
481    {\
482       for(pduIdx = 0; pduIdx < 4; pduIdx++)\
483       {\
484           if(_tb->lchInfo[lchIdx].freeBuff == TRUE)\
485           {\
486             SPutMsg(_tb->lchInfo[lchIdx].mBuf[pduIdx]);\
487             _tb->lchInfo[lchIdx].freeBuff = FALSE;\
488           }\
489           _tb->lchInfo[lchIdx].mBuf[pduIdx] = NULL;\
490       }\
491       _tb->lchInfo[lchIdx].numPdu = 0;\
492    }\
493    _tb->numLch = 0;\
494 }
495
496 #endif
497
498 /***********************************************************
499  *
500  *     Name : RG_DROP_RGUDDATREQ_MBUF
501  *
502  *     Desc : Macro to free the message buffers and initialize them to zero
503  *            
504  *     Input  : _datreq - Dedicated Data Request pointer which has mBufs
505  *              to be freed
506  *     
507  *     Output : None.
508  *
509  *     Notes: None
510  *
511  **********************************************************/
512 #define RG_DROP_RGUDDATREQ_MBUF(_datReq)\
513 {\
514    U32 idx5,idx6,idx7;\
515    for (idx5=0; idx5 < _datReq.nmbOfTbs; idx5++)\
516    {\
517       for (idx6=0; idx6 < _datReq.datReqTb[idx5].nmbLch; idx6++)\
518       {\
519          for (idx7=0; \
520                idx7 < _datReq.datReqTb[idx5].lchData[idx6].pdu.numPdu; \
521                idx7++)\
522          {\
523             RG_FREE_MSG(_datReq.datReqTb[idx5].\
524                   lchData[idx6].pdu.mBuf[idx7]);\
525          }\
526       }\
527    }\
528 }
529
530 /***********************************************************
531  *
532  *     Name : RG_DROP_RGUCDATREQ_MBUF
533  *
534  *     Desc : Macro to free the message buffers and initialize them to zero
535  *            
536  *     Input  : _datreq - Common Data Request pointer which has mBufs
537  *              to be freed
538  *     
539  *     Output : None.
540  *
541  *     Notes: None
542  *
543  **********************************************************/
544 #define RG_DROP_RGUCDATREQ_MBUF(_datReq)\
545 {\
546    if (_datReq != NULLP)\
547    {\
548       RG_FREE_MSG(_datReq->pdu);\
549    }\
550 }
551
552 /* RRM_SP1_START */
553 #define RG_UPD_GBR_PRB(_cellCb, _qci, _prbUsed) {\
554    if(_qci <= RG_MAX_QCI_REPORTS)\
555    {\
556       _cellCb->qcisUlPrbCnt[_qci-1] += _prbUsed;\
557    }\
558 }
559 /* RRM_SP1_END */
560
561 /* Macros for memory region and pool determination */
562 #define RG_GET_MEM_REGION(rgCb)  (rgCb.rgInit.region)
563 #define RG_GET_MEM_POOL(rgCb)    (rgCb.rgInit.pool)
564
565
566 /* MUX related macros */
567 #define RG_RAR_SHDR_LEN                1
568 #define RG_RAR_ELEM_LEN                6
569 #define RG_MAX_SDU_SUB_HDR_LEN         3
570 #define RG_MAX_PAD_ARR_SZ              4096 /* Changing from 400 to 4096 */
571 #define RG_PAD_BYTE                    0x00
572
573 #define RG_HDR_TYPE_CRES                1
574 #define RG_HDR_TYPE_TA                  2
575 #ifdef LTE_ADV
576 #define RG_HDR_TYPE_SCELL_ACT           3
577 #endif
578
579 #define RG_SDU_SHDR_LEN 1
580 #define RG_FIXDSZ_CE_SHDR_LEN 1
581 #define RG_PAD_SHDR_LEN 1
582 #define RG_CRES_LEN    6
583 #define RG_TA_LEN      1
584 #ifdef LTE_ADV
585 #define RG_SCELL_ACT_CE_LEN 1
586 #define RG_SCELL_CE_ELM_LEN (RG_FIXDSZ_CE_SHDR_LEN+RG_SCELL_ACT_CE_LEN)
587 #endif
588 #define RG_CRES_ELM_LEN (RG_FIXDSZ_CE_SHDR_LEN+RG_CRES_LEN)
589 #define RG_TA_ELM_LEN   (RG_FIXDSZ_CE_SHDR_LEN+RG_TA_LEN)
590
591
592 /* Values of below macros not yet defined in 5G-NR hence using LTE values till
593  * They are defined
594  */
595 #define RG_CRES_LCID_IDX               0x1C
596 #define RG_TA_LCID_IDX                 0x1D
597 #ifdef LTE_ADV
598 #define RG_SCELL_LCID_IDX              0x1B
599 #endif
600 #define RG_PAD_LCID_IDX               0x3F
601
602 /* Structure member offset computation macro    */
603 #define OffsetOf(type, field)                                                 \
604          (PTR) (&(((type *) NULLP)->field))
605
606 #define RG_MAX_SUBFRAMES_IN_SFN        9
607 #define RG_MAX_SFN                     1024
608 #ifdef RGAC_5GTF
609 #define RG_NUM_SUB_FRAMES              50
610 #else
611 #define RG_NUM_SUB_FRAMES              10
612 #endif
613 #define RG_NUM_SUB_FRAMES_5G           50
614 /* RRM_SP1_START */
615 #define RG_MAX_QCI_REPORTS         4
616 /* RRM_SP1_END */
617
618 #ifdef LTE_L2_MEAS
619 #define RG_NUM_UL_SUB_FRAMES              16
620 #define RG_MAX_QCI_VALUE                  10
621
622 #ifdef EIGHT_UE_PER_TTI_CHANGES 
623 /* Tuned according to TDD Cfg Mode2 and 2UE/TTI.
624  *  * Need to tune if NumUE/TTI is increased */
625 #define RG_MAX_DFRD_FREE_BUFS             64 /* 64 - 8UE/TTI */
626 #define RG_MAX_FREE_BUFS_PERTTI           16 /* 16 - 8UE/TTI */
627 #endif
628
629 #define RG_CALC_SF_DIFF(_time1, _time2)\
630       (_time1.sfn*RG_NUM_SUB_FRAMES_5G+_time1.subframe) < (_time2.sfn*RG_NUM_SUB_FRAMES_5G+_time2.subframe)?\
631      ((_time1.sfn+RG_MAX_SFN)*RG_NUM_SUB_FRAMES_5G+_time1.subframe) -\
632        (_time2.sfn*RG_NUM_SUB_FRAMES_5G+_time2.subframe) : \
633      (_time1.sfn*RG_NUM_SUB_FRAMES_5G+_time1.subframe) - (_time2.sfn*RG_NUM_SUB_FRAMES_5G+_time2.subframe)
634
635 #define RG_TTI_CYCLE_INVLD                0xFFFFFFFF     
636 #define RG_CALC_TTI_CNT(_cellCb, _ttiCnt)\
637      _ttiCnt = (RG_NUM_SUB_FRAMES_5G * (_cellCb->crntTime.sfn + (_cellCb->ttiCycle * 1024)) )+\
638                _cellCb->crntTime.subframe;
639 #endif /* LTE_L2_MEAS */
640
641 /* Tuned according to TDD Cfg Mode2 and 2UE/TTI.
642  * Need to tune if NumUE/TTI is increased */
643 #define RG_MAX_DFRD_FREE_BUFS             32 /* 16- 2 UE per TTI 32 - 4UE/TTI */
644 #define RG_MAX_FREE_BUFS_PERTTI           8 /* 4 - 2 Ue per TTI, 8 - 4UE/TTI */
645
646
647 /* Define for the block size for memory allocation */
648 /* RG_BLKSZ changed from 2048 to 1500*/
649 #define RG_BLKSZ                       1500
650
651 /* Defines for RGU Statistics types */
652 #define RG_RGU_SDU_DROP 1
653 #define RG_RGU_SDU_RCVD 2
654
655 /* MACROS for General Statistics */
656 #define RG_CFG_ADD      1
657 #define RG_CFG_DEL      2
658
659 #define RG_HQ_FDB_IND_CB_TYPE_HQ_ENT      1
660 #define RG_HQ_FDB_IND_CB_TYPE_RA_CB       2
661
662 /* MACRO for validating the mac instance id */
663 #define RG_IS_INST_VALID(_inst)\
664 {\
665    if(_inst >= RG_MAX_INST)\
666    {\
667       RETVALUE(RFAILED);\
668    }\
669 }
670
671 /* 
672  * Removed unused hash-define which defines the
673  * index for releasing the subframe.
674  */
675
676 /* Value used to set nDmrs in uplink grant if nDmrs is not applicable */
677 #define RG_INVALID_NDMRS  10
678
679 #define RG_SEND_TRC_IND(_inst,_mBuf, _event) rgLMMTrcInd(_inst,_mBuf, _event)
680
681 /* Note: Any changes to these enums should reflect to */
682 /** @details Enums for special argument
683  *
684 */
685 typedef enum
686 {
687    RG_DIAG_NA
688 } RgDiagSplArg;
689  
690 #ifdef SS_DIAG 
691 #define RG_DIAG_LVL0(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)                        \
692 {                                                                                                \
693    if(rgCb[_inst].rgInit.logMask & SS_DIAG_LVL0)                                                         \
694    {                                                                                             \
695       ssDiagFix(_tknId, _splArgEnum, ENTRG, rgCb[_inst].rgInit.inst, SS_DIAG_LVL0, SS_DIAG_MSG_TYPE_FIXED, _splArg, _arg1, _arg2, _arg3, _arg4, _string);\
696    }                                                                                             \
697 }
698
699 /** @details Macro definition for LTE-MAC error logs
700  *  
701 */
702 #define RG_DIAG_LVL1(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)            \
703 {                                                                 \
704    if(rgCb[_inst].rgInit.logMask & SS_DIAG_LVL1)                             \
705    {                                                              \
706       ssDiagFix(_tknId, _splArgEnum, ENTRG, rgCb[_inst].rgInit.inst, SS_DIAG_LVL1, SS_DIAG_MSG_TYPE_FIXED, _splArg, _arg1, _arg2, _arg3, _arg4, _string);\
707    }                                                              \
708 }
709
710 /** @details Macro definition for LTE-MAC critical logs
711  *  
712 */
713 #define RG_DIAG_LVL2(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)       \
714 {                                                              \
715    if(rgCb[_inst].rgInit.logMask & SS_DIAG_LVL2)                            \
716    {                                                              \
717       ssDiagFix(_tknId, _splArgEnum, ENTRG, rgCb[_inst].rgInit.inst, SS_DIAG_LVL2, SS_DIAG_MSG_TYPE_FIXED, _splArg, _arg1, _arg2, _arg3, _arg4, _string);\
718    }                                                              \
719 }
720
721 /** @details Macro definition for LTE-MAC logs 
722  *  
723 */
724 #define RG_DIAG_LVL3(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)        \
725 {                                                              \
726    if(rgCb[_inst].rgInit.logMask & SS_DIAG_LVL3)                            \
727    {                                                              \
728       ssDiagFix(_tknId, _splArgEnum, ENTRG, rgCb[_inst].rgInit.inst, SS_DIAG_LVL3, SS_DIAG_MSG_TYPE_FIXED, _splArg, _arg1, _arg2, _arg3, _arg4, _string);\
729    }                                                              \
730 }
731
732 /** @details Macro definition for LTE-MAC logs
733  *  
734 */
735 #define RG_DIAG_LVL4(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)        \
736 {                                                              \
737    if(rgCb[_inst].rgInit.logMask & SS_DIAG_LVL4)                            \
738    {                                                              \
739       ssDiagFix(_tknId, _splArgEnum, ENTRG, rgCb[_inst].rgInit.inst, SS_DIAG_LVL4, SS_DIAG_MSG_TYPE_FIXED, _splArg, _arg1, _arg2, _arg3, _arg4, _string);\
740    }                                                              \
741 }
742   
743 #else
744
745 #define RG_DIAG_LVL0(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)                        \
746 {                                                                                                \
747 }
748
749 /** @details Macro definition for LTE-MAC error logs
750  *  
751 */
752 #define RG_DIAG_LVL1(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)            \
753 {                                                                 \
754 }
755
756 /** @details Macro definition for LTE-MAC critical logs
757  *  
758 */
759 #define RG_DIAG_LVL2(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)       \
760 {                                                              \
761 }
762
763 /** @details Macro definition for LTE-MAC logs 
764  *  
765 */
766 #define RG_DIAG_LVL3(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)        \
767 {                                                              \
768 }
769
770 /** @details Macro definition for LTE-MAC logs
771  *  
772 */
773 #define RG_DIAG_LVL4(_inst,_tknId, _splArgEnum, _splArg, _string, _arg1, _arg2, _arg3, _arg4)        \
774 {                                                              \
775 }
776 #endif
777 #define DEFAULT_CELLS 1
778 #endif /* __RGH__ */
779 \f
780 /**********************************************************************
781          End of file
782 **********************************************************************/