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