6f611b2cd6f2400b9cb3a1b1af76b967d3860181
[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_ZERO_CORR_CFG_IDX 16 /* max zero correlation config index */
27 #define MAC_TQ_SIZE    10        /* Timing Queue Size */
28 #define MAX_NUM_TIMER  1         /* MAX number of MAC timers */
29
30 #define DEFAULT_CELLS 1
31 #define SI_RNTI 0xFFFF
32 #define P_RNTI 0xFFFE
33
34 #define MAC_LCID_CCCH              0
35 #define MAC_LCID_MIN               1
36 #define MAC_LCID_MAX               32
37 #define MAC_LCID_RESERVED_MIN      33
38 #define MAC_LCID_RESERVED_MAX      51
39 #define MAC_LCID_CCCH_48BIT        52
40 #define MAC_LCID_BIT_RATE_QUERY    53
41 #define MAC_LCID_MULT_PHR_FOUR_OCT 54
42 #define MAC_LCID_CFG_GRANT_CFM     55
43 #define MAC_LCID_MULT_PHR_ONE_OCT  56
44 #define MAC_LCID_SINGLE_PHR        57
45 #define MAC_LCID_CRNTI             58
46 #define MAC_LCID_SHORT_TRUNC_BSR   59
47 #define MAC_LCID_LONG_TRUNC_BSR    60
48 #define MAC_LCID_SHORT_BSR         61
49 #define MAC_LCID_LONG_BSR          62
50 #define MAC_LCID_CRI               62
51 #define MAC_LCID_PADDING           63
52
53 /* Definitions for size of RAR PDU contents (in bits).
54  * Refer spec 38.321, sections 6.1.4, 6.2.2 and 6.2.3*/
55 #define E_BIT_SIZE 1
56 #define T_BIT_SIZE 1
57 #define R_BIT_SIZE 1
58 #define RAPID_SIZE 6
59 #define LC_ID_SIZE 6
60 #define TIMING_ADVANCE_SIZE 12
61 #define T_CRNTI_SIZE 16
62 /*  UL Grant is of size = 27 bits. Refer to Spec 38.213, Table 8.2-1 for
63  *  contents of UL grant in RAR */
64 #define FREQ_HOP_FLAG_SIZE 1
65 #define FREQ_RSRC_ALLOC_SIZE 14
66 #define TIME_RSRC_ALLOC_SIZE 4
67 #define MCS_SIZE 4
68 #define TPC_COMMAND_SIZE 3
69 #define CSI_REQUEST_SIZE 1
70
71 typedef struct macCellCb MacCellCb;
72
73 typedef enum
74 {
75    CELL_STATE_UP,
76    CELL_TO_BE_STOPPED,
77    CELL_STOP_IN_PROGRESS,
78 }CellState;        
79
80 typedef enum
81 {
82    UE_STATE_INACTIVE,
83    UE_STATE_ACTIVE
84 }UeState;
85
86 typedef enum
87 {
88    MAC_LC_STATE_INACTIVE,
89    MAC_LC_STATE_ACTIVE
90 }MacLcState;
91
92 typedef struct macDlSlot
93 {
94    DlSchedInfo dlInfo;
95 }MacDlSlot;
96
97 typedef struct macUlSlot
98 {
99    UlSchedInfo  ulInfo;
100 }MacUlSlot;
101
102 typedef struct macCbInfo
103 {
104    uint16_t    cellId;
105    uint16_t    crnti;
106    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
107    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
108    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
109    uint8_t     *msg4TxPdu;  /* muxed Pdu used for re-transmission */
110    uint16_t    msg4TbSize;  /* size required for msg4TxPdu */
111 }MacRaCbInfo;
112
113 typedef struct macCe
114 {
115    uint16_t macCeLcid;
116    uint8_t  macCeValue[6];
117 }MacCe;
118
119 typedef struct macCeInfo
120 {
121    uint16_t numCes;
122    MacCe macCe[MAX_MAC_CE];
123 }MacCeInfo;
124
125 typedef struct macDlInfo
126 {
127    uint16_t  lcId;
128    uint16_t  pduLen;
129    uint8_t  *dlPdu;
130 }MacDlInfo;
131
132 typedef struct macDlData
133 {
134    uint8_t  ueId;
135    uint16_t numPdu;
136    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
137 }MacDlData;
138
139 /* HARQ Process Info */
140 typedef struct dlHarqProcCb
141 {
142    uint8_t   procId;    /* HARQ Process Id */
143 }DlHarqProcCb;
144
145 /* DL HARQ entity */
146 typedef struct dlHarqEnt
147 {
148    uint8_t        maxReTx;            /* MAX HARQ retransmission */
149    uint8_t        numHarqProcs;       /* Number of HARQ procs */
150    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
151 }DlHarqEnt;
152
153 /* Uplink deidcated logical channel info */
154 typedef struct ulLcCb
155 {
156    uint8_t    lcId;         /* Logical Channel Id */
157    uint8_t    lcGrpId;      /* Logical Channel group */
158    MacLcState lcActive;     /* Is LC active ? */
159    /*Commenting as S-NSSAI and PDU session will be used in future scope*/
160    /*For eg: When we have to send these for AMBR cases*/
161    #if 0
162    uint16_t   pduSessionId; /*Pdu Session Id*/
163    Snssai     *snssai;      /*S-NSSAI assoc with LCID*/
164    #endif
165 }UlLcCb;
166
167 /* Downlink dedicated logical channel info */
168 typedef struct dlLcCb
169 {
170    uint8_t    lcId;        /* Logical channel Id */ 
171    MacLcState lcState;     /* Is LC active ? */
172    /*Commenting as S-NSSAI and PDU session will be used in future scope*/
173    /*For eg: When we have to send these info via FAPI to phy layer*/
174    #if 0
175    uint16_t   pduSessionId;/*Pdu Session Id*/
176    Snssai     *snssai;    /*S-NSSAI assoc with LCID*/
177    #endif
178 }DlLcCb;
179
180 /* BSR Information */
181 typedef struct macBsrTmrCfg
182 {
183    uint16_t   periodicTimer;
184    uint16_t   retxTimer;
185    uint16_t   srDelayTimer;
186 }MacBsrTmrCfg;
187
188 /* UE specific UL info */
189 typedef struct ueUlCb
190 {
191    uint8_t    maxReTx;     /* MAX HARQ retransmission */
192    uint8_t    numUlLc;     /* Number of uplink logical channels */       
193    UlLcCb     lcCb[MAX_NUM_LC];    /* Uplink dedicated logocal channels */
194 }UeUlCb;
195
196 /* UE specific DL Info */
197 typedef struct ueDlCb
198 {
199    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
200    uint8_t    numDlLc;        /* Number of downlink logical channels */
201    DlLcCb     lcCb[MAX_NUM_LC];  /* Downlink dedicated logical channels */
202 }UeDlCb;
203
204 /* UE Cb */
205 typedef struct macUeCb
206 {
207    uint16_t     ueIdx;    /* UE Idx assigned by DU APP */
208    uint16_t     crnti;    /* UE CRNTI */
209    MacCellCb    *cellCb;  /* Pointer to cellCb to whihc this UE belongs */
210    UeState      state;    /* Is UE active ? */
211    MacRaCbInfo  *raCb;    /* RA info */
212    MacBsrTmrCfg bsrTmrCfg;  /* BSR Timer Info */
213    UeUlCb       ulInfo;   /* UE specific UL info */
214    UeDlCb       dlInfo;   /* UE specific DL info */
215 }MacUeCb;
216
217 struct macCellCb
218 {
219    uint16_t    cellId;
220    CellState   state;
221    uint8_t     crntiMap;
222    MacRaCbInfo macRaCb[MAX_NUM_UE];
223    MacDlSlot   dlSlot[MAX_SLOTS];
224    MacUlSlot   ulSlot[MAX_SLOTS];
225    uint16_t    numActvUe;
226    MacUeCfg    *ueCfgTmpData[MAX_NUM_UE];
227    MacUeCb     ueCb[MAX_NUM_UE];
228    MacCellCfg  macCellCfg;
229    SlotTimingInfo currTime;
230 };
231
232 typedef struct macCb
233 {
234    Inst        macInst;
235    ProcId      procId;
236    uint8_t     tmrRes;                    /*!< Timer resolution */
237    CmTqCp      tmrTqCp;                   /*!< Timer Task Queue Cntrl Point */
238    CmTqType    tmrTq[MAC_TQ_SIZE];        /*!< Timer Task Queue */
239    CmTimer     tmrBlk[MAX_NUM_TIMER];     /*!< Timer Block */
240    MacCellCb   *macCell[MAX_NUM_CELL];
241 }MacCb;
242
243 /* global variable */
244 MacCb macCb;
245
246 /* Function declarations */
247 short int macActvTmr(Ent ent,Inst inst);
248 void fillRarPdu(RarInfo *rarInfo);
249 void createMacRaCb(RachIndInfo *rachIndInfo);
250 void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu);
251 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
252 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
253 uint8_t unpackRxData(uint16_t cellId, SlotTimingInfo slotInfo, RxDataIndPdu *rxDataIndPdu);
254 void fillMg4Pdu(DlMsgAlloc *msg4Alloc);
255 void buildAndSendMuxPdu(SlotTimingInfo currTimingInfo);
256 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer);
257 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize);
258 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
259    uint8_t lcId, uint16_t pduLen, uint8_t *pdu);
260 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo, uint8_t ueIdx, uint8_t schInfoIdx);
261 uint8_t macProcLongBsr(uint16_t cellId, uint16_t crnti,uint8_t numLcg,\
262                          DataVolInfo dataVolInfo[MAX_NUM_LOGICAL_CHANNEL_GROUPS]);
263 #endif
264 /**********************************************************************
265   End of file
266  **********************************************************************/