Renamed SlotIndInfo to SlotTimingInfo [Issue-ID: ODUHIGH-354]
[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 typedef struct macCellCb MacCellCb;
54
55 typedef enum
56 {
57    CELL_STATE_UP,
58    CELL_TO_BE_STOPPED,
59    CELL_STOP_IN_PROGRESS,
60 }CellState;        
61
62 typedef enum
63 {
64    UE_STATE_INACTIVE,
65    UE_STATE_ACTIVE
66 }UeState;
67
68 typedef enum
69 {
70    MAC_LC_STATE_INACTIVE,
71    MAC_LC_STATE_ACTIVE
72 }MacLcState;
73
74 typedef struct macDlSlot
75 {
76    DlSchedInfo dlInfo;
77 }MacDlSlot;
78
79 typedef struct macUlSlot
80 {
81    UlSchedInfo  ulInfo;
82 }MacUlSlot;
83
84 typedef struct macCbInfo
85 {
86    uint16_t    cellId;
87    uint16_t    crnti;
88    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
89    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
90    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
91    uint8_t     *msg4TxPdu;  /* muxed Pdu used for re-transmission */
92    uint16_t    msg4TbSize;  /* size required for msg4TxPdu */
93 }MacRaCbInfo;
94
95 typedef struct macCe
96 {
97    uint16_t macCeLcid;
98    uint8_t  macCeValue[6];
99 }MacCe;
100
101 typedef struct macCeInfo
102 {
103    uint16_t numCes;
104    MacCe macCe[MAX_MAC_CE];
105 }MacCeInfo;
106
107 typedef struct macDlInfo
108 {
109    uint16_t  lcId;
110    uint16_t  pduLen;
111    uint8_t  *dlPdu;
112 }MacDlInfo;
113
114 typedef struct macDlData
115 {
116    uint16_t numPdu;
117    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
118 }MacDlData;
119
120 /* HARQ Process Info */
121 typedef struct dlHarqProcCb
122 {
123    uint8_t   procId;    /* HARQ Process Id */
124 }DlHarqProcCb;
125
126 /* DL HARQ entity */
127 typedef struct dlHarqEnt
128 {
129    uint8_t        maxReTx;            /* MAX HARQ retransmission */
130    uint8_t        numHarqProcs;       /* Number of HARQ procs */
131    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
132 }DlHarqEnt;
133
134 /* Uplink deidcated logical channel info */
135 typedef struct ulLcCb
136 {
137    uint8_t   lcId;      /* Logical Channel Id */
138    uint8_t   lcGrpId;   /* Logical Channel group */
139    MacLcState lcActive;  /* Is LC active ? */
140 }UlLcCb;
141
142 /* Downlink dedicated logical channel info */
143 typedef struct dlLcCb
144 {
145    uint8_t   lcId;      /* Logical channel Id */ 
146    MacLcState   lcState;  /* Is LC active ? */
147 }DlLcCb;
148
149 /* BSR Information */
150 typedef struct macBsrTmrCfg
151 {
152    uint16_t   periodicTimer;
153    uint16_t   retxTimer;
154    uint16_t   srDelayTimer;
155 }MacBsrTmrCfg;
156
157 /* UE specific UL info */
158 typedef struct ueUlCb
159 {
160    uint8_t    maxReTx;     /* MAX HARQ retransmission */
161    uint8_t    numUlLc;     /* Number of uplink logical channels */       
162    UlLcCb     lcCb[MAX_NUM_LC];    /* Uplink dedicated logocal channels */
163 }UeUlCb;
164
165 /* UE specific DL Info */
166 typedef struct ueDlCb
167 {
168    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
169    uint8_t    numDlLc;        /* Number of downlink logical channels */
170    DlLcCb     lcCb[MAX_NUM_LC];  /* Downlink dedicated logical channels */
171 }UeDlCb;
172
173 /* UE Cb */
174 typedef struct macUeCb
175 {
176    uint16_t     ueIdx;    /* UE Idx assigned by DU APP */
177    uint16_t     crnti;    /* UE CRNTI */
178    MacCellCb    *cellCb;  /* Pointer to cellCb to whihc this UE belongs */
179    UeState      state;    /* Is UE active ? */
180    MacRaCbInfo  *raCb;    /* RA info */
181    MacBsrTmrCfg bsrTmrCfg;  /* BSR Timer Info */
182    UeUlCb       ulInfo;   /* UE specific UL info */
183    UeDlCb       dlInfo;   /* UE specific DL info */
184 }MacUeCb;
185
186 struct macCellCb
187 {
188    uint16_t    cellId;
189    CellState   state;
190    uint8_t     crntiMap;
191    MacRaCbInfo macRaCb[MAX_NUM_UE];
192    MacDlSlot   dlSlot[MAX_SLOTS];
193    MacUlSlot   ulSlot[MAX_SLOTS];
194    uint16_t    numActvUe;
195    MacUeCfg    *ueCfgTmpData[MAX_NUM_UE];
196    MacUeCb     ueCb[MAX_NUM_UE];
197    MacCellCfg  macCellCfg;
198    SlotTimingInfo currTime;
199 };
200
201 typedef struct macCb
202 {
203    Inst       macInst;
204    ProcId     procId;
205    uint8_t    tmrRes;                    /*!< Timer resolution */
206    CmTqCp     tmrTqCp;                   /*!< Timer Task Queue Cntrl Point */
207    CmTqType   tmrTq[MAC_TQ_SIZE];        /*!< Timer Task Queue */
208    CmTimer    tmrBlk[MAX_NUM_TIMER];     /*!< Timer Block */
209    MacCellCb  *macCell[MAX_NUM_CELL];
210 }MacCb;
211
212 /* global variable */
213 MacCb macCb;
214
215 /* Function declarations */
216 short int macActvTmr(Ent ent,Inst inst);
217 void fillRarPdu(RarInfo *rarInfo);
218 void createMacRaCb(RachIndInfo *rachIndInfo);
219 void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu);
220 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
221 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
222 uint8_t unpackRxData(uint16_t cellId, SlotTimingInfo slotInfo, RxDataIndPdu *rxDataIndPdu);
223 void fillMg4Pdu(DlMsgAlloc *msg4Alloc);
224 void buildAndSendMuxPdu(SlotTimingInfo currTimingInfo);
225 uint8_t macProcUlCcchInd(uint16_t cellId, uint16_t crnti, uint16_t rrcContSize, uint8_t *rrcContainer);
226 uint8_t macProcShortBsr(uint16_t cellId, uint16_t crnti, uint8_t lcgId, uint32_t bufferSize);
227 uint8_t macProcUlData(uint16_t cellId, uint16_t rnti, SlotTimingInfo slotInfo, \
228    uint8_t lcId, uint16_t pduLen, uint8_t *pdu);
229 uint8_t sendSchedRptToRlc(DlSchedInfo dlInfo, SlotTimingInfo slotInfo);
230 #endif
231 /**********************************************************************
232   End of file
233  **********************************************************************/