Enabled timer at MAC and SCH [Issue-ID: ODUHIGH-283]
[o-du/l2.git] / src / 5gnrmac / mac.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 #ifndef _MAC_H_
19 #define _MAC_H_
20
21 /* MAX values */
22 #define MAX_MAC_CE 6
23 #define MAX_CRI_SIZE 6
24 #define MAX_MAC_DL_PDU 16
25 #define MAX_NUM_HARQ_PROC  16
26 #define MAX_SLOT_SUPPORTED    10 /* numerology 0 15Khz */
27 #define MAX_ZERO_CORR_CFG_IDX 16 /* max zero correlation config index */
28 #define MAC_TQ_SIZE    10        /* Timing Queue Size */
29 #define MAX_NUM_TIMER  1         /* MAX number of MAC timers */
30
31 #define DEFAULT_CELLS 1
32 #define SI_RNTI 0xFFFF
33 #define P_RNTI 0xFFFE
34
35 #define MAC_LCID_CCCH              0
36 #define MAC_LCID_MIN               1
37 #define MAC_LCID_MAX               32
38 #define MAC_LCID_RESERVED_MIN      33
39 #define MAC_LCID_RESERVED_MAX      51
40 #define MAC_LCID_CCCH_48BIT        52
41 #define MAC_LCID_BIT_RATE_QUERY    53
42 #define MAC_LCID_MULT_PHR_FOUR_OCT 54
43 #define MAC_LCID_CFG_GRANT_CFM     55
44 #define MAC_LCID_MULT_PHR_ONE_OCT  56
45 #define MAC_LCID_SINGLE_PHR        57
46 #define MAC_LCID_CRNTI             58
47 #define MAC_LCID_SHORT_TRUNC_BSR   59
48 #define MAC_LCID_LONG_TRUNC_BSR    60
49 #define MAC_LCID_SHORT_BSR         61
50 #define MAC_LCID_LONG_BSR          62
51 #define MAC_LCID_CRI               62
52 #define MAC_LCID_PADDING           63
53
54 typedef struct macCellCb MacCellCb;
55
56 typedef enum
57 {
58    UE_STATE_INACTIVE,
59    UE_STATE_ACTIVE
60 }UeState;
61
62 typedef enum
63 {
64    MAC_LC_STATE_INACTIVE,
65    MAC_LC_STATE_ACTIVE
66 }MacLcState;
67
68 typedef struct macDlSlot
69 {
70    DlSchedInfo dlInfo;
71 }MacDlSlot;
72
73 typedef struct macUlSlot
74 {
75    UlSchedInfo  ulInfo;
76 }MacUlSlot;
77
78 typedef struct macCbInfo
79 {
80    uint16_t    cellId;
81    uint16_t    crnti;
82    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
83    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
84    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
85    uint8_t     *msg4TxPdu;  /* muxed Pdu used for re-transmission */
86    uint16_t    msg4TbSize;  /* size required for msg4TxPdu */
87 }MacRaCbInfo;
88
89 typedef struct macCe
90 {
91    uint16_t macCeLcid;
92    uint8_t  macCeValue[6];
93 }MacCe;
94
95 typedef struct macCeInfo
96 {
97    uint16_t numCes;
98    MacCe macCe[MAX_MAC_CE];
99 }MacCeInfo;
100
101 typedef struct macDlInfo
102 {
103    uint16_t  lcId;
104    uint16_t  pduLen;
105    uint8_t  *dlPdu;
106 }MacDlInfo;
107
108 typedef struct macDlData
109 {
110    uint16_t numPdu;
111    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
112 }MacDlData;
113
114 /* HARQ Process Info */
115 typedef struct dlHarqProcCb
116 {
117    uint8_t   procId;    /* HARQ Process Id */
118 }DlHarqProcCb;
119
120 /* DL HARQ entity */
121 typedef struct dlHarqEnt
122 {
123    uint8_t        maxReTx;            /* MAX HARQ retransmission */
124    uint8_t        numHarqProcs;       /* Number of HARQ procs */
125    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
126 }DlHarqEnt;
127
128 /* Uplink deidcated logical channel info */
129 typedef struct ulLcCb
130 {
131    uint8_t   lcId;      /* Logical Channel Id */
132    uint8_t   lcGrpId;   /* Logical Channel group */
133    MacLcState lcActive;  /* Is LC active ? */
134 }UlLcCb;
135
136 /* Downlink dedicated logical channel info */
137 typedef struct dlLcCb
138 {
139    uint8_t   lcId;      /* Logical channel Id */ 
140    MacLcState   lcState;  /* Is LC active ? */
141 }DlLcCb;
142
143 /* BSR Information */
144 typedef struct macBsrTmrCfg
145 {
146    uint16_t   periodicTimer;
147    uint16_t   retxTimer;
148    uint16_t   srDelayTimer;
149 }MacBsrTmrCfg;
150
151 /* UE specific UL info */
152 typedef struct ueUlCb
153 {
154    uint8_t    maxReTx;     /* MAX HARQ retransmission */
155    uint8_t    numUlLc;     /* Number of uplink logical channels */       
156    UlLcCb     lcCb[MAX_NUM_LC];    /* Uplink dedicated logocal channels */
157 }UeUlCb;
158
159 /* UE specific DL Info */
160 typedef struct ueDlCb
161 {
162    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
163    uint8_t    numDlLc;        /* Number of downlink logical channels */
164    DlLcCb     lcCb[MAX_NUM_LC];  /* Downlink dedicated logical channels */
165 }UeDlCb;
166
167 /* UE Cb */
168 typedef struct macUeCb
169 {
170    uint16_t     ueIdx;    /* UE Idx assigned by DU APP */
171    uint16_t     crnti;    /* UE CRNTI */
172    MacCellCb    *cellCb;  /* Pointer to cellCb to whihc this UE belongs */
173    UeState      state;    /* Is UE active ? */
174    MacRaCbInfo  *raCb;    /* RA info */
175    MacBsrTmrCfg bsrTmrCfg;  /* BSR Timer Info */
176    UeUlCb       ulInfo;   /* UE specific UL info */
177    UeDlCb       dlInfo;   /* UE specific DL info */
178 }MacUeCb;
179
180 struct macCellCb
181 {
182    uint16_t    cellId;
183    uint8_t     crntiMap;
184    MacRaCbInfo macRaCb[MAX_NUM_UE];
185    MacDlSlot   dlSlot[MAX_SLOT_SUPPORTED];
186    MacUlSlot   ulSlot[MAX_SLOT_SUPPORTED];
187    uint16_t    numActvUe;
188    MacUeCfg    *ueCfgTmpData[MAX_NUM_UE];
189    MacUeCb     ueCb[MAX_NUM_UE];
190    MacCellCfg  macCellCfg;
191    SlotIndInfo currTime;
192 };
193
194 typedef struct macCb
195 {
196    Inst       macInst;
197    ProcId     procId;
198    uint8_t    tmrRes;                    /*!< Timer resolution */
199    CmTqCp     tmrTqCp;                   /*!< Timer Task Queue Cntrl Point */
200    CmTqType   tmrTq[MAC_TQ_SIZE];        /*!< Timer Task Queue */
201    CmTimer    tmrBlk[MAX_NUM_TIMER];     /*!< Timer Block */
202    MacCellCb  *macCell[MAX_NUM_CELL];
203 }MacCb;
204
205 /* global variable */
206 MacCb macCb;
207
208 /* Function declarations */
209 short int macActvTmr(Ent ent,Inst inst);
210 void fillRarPdu(RarInfo *rarInfo);
211 void createMacRaCb(RachIndInfo *rachIndInfo);
212 void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu);
213 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
214 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
215 uint8_t unpackRxData(uint16_t cellId, SlotIndInfo slotInfo, RxDataIndPdu *rxDataIndPdu);
216 void fillMg4Pdu(DlMsgAlloc *msg4Alloc);
217 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo);
218 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer);
219 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize);
220 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotIndInfo slotInfo, \
221    uint8_t lcId, uint16_t pduLen, uint8_t *pdu);
222 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotIndInfo slotInfo);
223 #endif
224 /**********************************************************************
225   End of file
226  **********************************************************************/