Merge "UE CB creation at MAC and SCH [Issue-ID: ODUHIGH-177]"
[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 #include <stdio.h>
22
23 /* header include files (.h) */
24 #include "envopt.h"        /* environment options */
25 #include "envdep.h"        /* environment dependent */
26 #include "envind.h"        /* environment independent */
27 #include "gen.h"           /* general */
28 #include "ssi.h"           /* system services */
29 #include "cm_tkns.h"       /* Common Token Defines */
30 #include "cm_llist.h"      /* Common Link List Defines */
31 #include "cm_hash.h"       /* Common Hash List Defines */
32 #include "cm_lte.h"        /* Common LTE Defines */
33 #include "cm_mblk.h"        /* Common LTE Defines */
34 #include "rgu.h"           /* RGU interface includes*/
35 #include "tfu.h"           /* TFU Interface defines */
36 #include "lrg.h"
37 #include "du_app_mac_inf.h"
38 #include "mac_sch_interface.h"
39 #include "rg.h"
40
41 /* header/extern include files (.x) */
42 #include "gen.x"           /* general */
43 #include "ssi.x"           /* system services */
44 #include "cm_tkns.x"       /* Common Token Definitions */
45 #include "cm_llist.x"      /* Common Link List Definitions */
46 #include "cm_lib.x"        /* Common Library Definitions */
47 #include "cm_hash.x"       /* Common Hash List Definitions */
48 #include "cm_lte.x"        /* Common LTE Defines */
49 #include "cm_mblk.x"        /* Common LTE Defines */
50 #include "rgu.x"           
51 #include "tfu.x"           /* RGU Interface includes */
52 #include "lrg.x"
53
54 #define MAX_SLOT_SUPPORTED    10 /* numerology 0 15Khz */
55 #define MAX_ZERO_CORR_CFG_IDX 16 /* max zero correlation config index */
56 #define SI_RNTI 0xFFFF
57 #define P_RNTI 0xFFFE
58 #define MAX_MAC_CE 6
59 #define MAX_UE 1
60 #define MAX_CRI_SIZE 6
61 #define MAX_MAC_DL_PDU 10
62 #define MAX_NUM_HARQ_PROC  16
63
64 #define PERIODIC_BSR_TMR_1MS    1
65 #define PERIODIC_BSR_TMR_5MS    5
66 #define PERIODIC_BSR_TMR_10MS   10
67 #define PERIODIC_BSR_TMR_16MS   16
68 #define PERIODIC_BSR_TMR_20MS   20
69 #define PERIODIC_BSR_TMR_32MS   32
70 #define PERIODIC_BSR_TMR_40MS   40
71 #define PERIODIC_BSR_TMR_60MS   60
72 #define PERIODIC_BSR_TMR_80MS   80
73 #define PERIODIC_BSR_TMR_128MS   128
74 #define PERIODIC_BSR_TMR_160MS   160
75 #define PERIODIC_BSR_TMR_320MS   320
76 #define PERIODIC_BSR_TMR_640MS   640
77 #define PERIODIC_BSR_TMR_1280MS  1280
78 #define PERIODIC_BSR_TMR_2560MS  2560
79
80 #define RETX_BSR_TMR_10MS    10
81 #define RETX_BSR_TMR_20MS    20
82 #define RETX_BSR_TMR_40MS    40
83 #define RETX_BSR_TMR_80MS    80
84 #define RETX_BSR_TMR_160MS   160
85 #define RETX_BSR_TMR_320MS   320
86 #define RETX_BSR_TMR_640MS   640
87 #define RETX_BSR_TMR_1280MS   1280
88 #define RETX_BSR_TMR_2560MS   2560
89 #define RETX_BSR_TMR_5120MS   5120
90 #define RETX_BSR_TMR_10240MS  10240
91
92 #define SR_DELAY_TMR_20MS     20
93 #define SR_DELAY_TMR_40MS     40
94 #define SR_DELAY_TMR_64MS     64
95 #define SR_DELAY_TMR_128MS    128
96 #define SR_DELAY_TMR_512MS    512
97 #define SR_DELAY_TMR_1024MS   1024
98 #define SR_DELAY_TMR_2560MS   2560
99
100 #define MAC_LCID_CCCH              0
101 #define MAC_DEDLC_MIN_LCID         1
102 #define MAC_DEDLC_MAX_LCID         32
103 #define MAC_LCID_RESERVED_MIN      33
104 #define MAC_LCID_RESERVED_MAX      51
105 #define MAC_LCID_CCCH_48BIT        52
106 #define MAC_LCID_BIT_RATE_QUERY    53
107 #define MAC_LCID_MULT_PHR_FOUR_OCT 54
108 #define MAC_LCID_CFG_GRANT_CFM     55
109 #define MAC_LCID_MULT_PHR_ONE_OCT  56
110 #define MAC_LCID_SINGLE_PHR        57
111 #define MAC_LCID_CRNTI             58
112 #define MAC_LCID_SHORT_TRUNC_BSR   59
113 #define MAC_LCID_LONG_TRUNC_BSR    60
114 #define MAC_LCID_SHORT_BSR         61
115 #define MAC_LCID_LONG_BSR          62
116 #define MAC_LCID_CRI               62
117 #define MAC_LCID_PADDING           63
118
119 typedef struct macCellCb MacCellCb;
120
121 typedef enum
122 {
123    UE_STATE_INACTIVE,
124    UE_STATE_ACTIVE
125 }UeState;
126
127 typedef enum
128 {
129    LC_STATE_INACTIVE,
130    LC_STATE_ACTIVE
131 }LcState;
132
133 typedef struct macDlSlot
134 {
135    DlSchedInfo dlInfo;
136 }MacDlSlot;
137
138 typedef struct macUlSlot
139 {
140    UlSchedInfo  ulInfo;
141 }MacUlSlot;
142
143 typedef struct macCbInfo
144 {
145    uint16_t    cellId;
146    uint16_t    crnti;
147    uint8_t     msg3Pdu[6];  /* used as CRI value during muxing */
148    uint8_t     *msg4Pdu;    /* storing DL-CCCH Ind Pdu */
149    uint16_t    msg4PduLen;  /* storing DL-CCCH Ind Pdu Len */
150    uint8_t     *msg4TxPdu;  /* muxed Pdu used for re-transmission */
151    uint16_t    msg4TbSize;  /* size required for msg4TxPdu */
152 }MacRaCbInfo;
153
154 typedef struct macCe
155 {
156    uint16_t macCeLcid;
157    uint8_t  macCeValue[6];
158 }MacCe;
159
160 typedef struct macCeInfo
161 {
162    uint16_t numCes;
163    MacCe macCe[MAX_MAC_CE];
164 }MacCeInfo;
165
166 typedef struct macDlInfo
167 {
168    uint16_t  lcId;
169    uint16_t  pduLen;
170    uint8_t  *dlPdu;
171 }MacDlInfo;
172
173 typedef struct macDlData
174 {
175    uint16_t numPdu;
176    MacDlInfo  pduInfo[MAX_MAC_DL_PDU];
177 }MacDlData;
178
179 /* HARQ Process Info */
180 typedef struct dlHarqProcCb
181 {
182    uint8_t   procId;    /* HARQ Process Id */
183 }DlHarqProcCb;
184
185 /* DL HARQ entity */
186 typedef struct dlHarqEnt
187 {
188    uint8_t        maxReTx;            /* MAX HARQ retransmission */
189    uint8_t        numHarqProcs;       /* Number of HARQ procs */
190    DlHarqProcCb   harqProcCb[MAX_NUM_HARQ_PROC];
191 }DlHarqEnt;
192
193 /* Uplink deidcated logical channel info */
194 typedef struct ulLcCb
195 {
196    uint8_t   lcId;      /* Logical Channel Id */
197    uint8_t   lcGrpId;   /* Logical Channel group */
198    LcState   lcActive;  /* Is LC active ? */
199 }UlLcCb;
200
201 /* Downlink dedicated logical channel info */
202 typedef struct dlLcCb
203 {
204    uint8_t   lcId;      /* Logical channel Id */ 
205    LcState   lcState;  /* Is LC active ? */
206 }DlLcCb;
207
208 /* BSR Information */
209 typedef struct macBsrTmrCfg
210 {
211    uint16_t   periodicTimer;
212    uint16_t   retxTimer;
213    uint16_t   srDelayTimer;
214 }MacBsrTmrCfg;
215
216 /* UE specific UL info */
217 typedef struct ueUlCb
218 {
219    uint8_t    maxReTx;     /* MAX HARQ retransmission */
220    uint8_t    numUlLc;     /* Number of uplink logical channels */       
221    UlLcCb     lcCb[MAX_NUM_LOGICAL_CHANNELS];    /* Uplink dedicated logocal channels */
222 }UeUlCb;
223
224 /* UE specific DL Info */
225 typedef struct ueDlCb
226 {
227    DlHarqEnt  dlHarqEnt;      /* DL HARQ entity */
228    uint8_t    numDlLc;        /* Number of downlink logical channels */
229    DlLcCb     lcCb[MAX_NUM_LOGICAL_CHANNELS];  /* Downlink dedicated logical channels */
230 }UeDlCb;
231
232 /* UE Cb */
233 typedef struct macUeCb
234 {
235    uint16_t     ueIdx;    /* UE Idx assigned by DU APP */
236    uint16_t     crnti;    /* UE CRNTI */
237    MacCellCb    *cellCb;  /* Pointer to cellCb to whihc this UE belongs */
238    UeState      state;    /* Is UE active ? */
239    MacRaCbInfo  *raCb;    /* RA info */
240    MacBsrTmrCfg bsrTmrCfg;  /* BSR Timer Info */
241    UeUlCb       ulInfo;   /* UE specific UL info */
242    UeDlCb       dlInfo;   /* UE specific DL info */
243 }MacUeCb;
244
245 struct macCellCb
246 {
247    uint16_t    cellId;
248    MacRaCbInfo macRaCb[MAX_UE];
249    MacDlSlot   dlSlot[MAX_SLOT_SUPPORTED];
250    MacUlSlot   ulSlot[MAX_SLOT_SUPPORTED];
251    uint16_t    numActvUe;
252    MacUeCb     ueCb[MAX_UE];
253 };
254
255 typedef struct macCb
256 {
257    Inst       macInst;
258    ProcId     procId;
259    MacCellCb  *macCell;
260 }MacCb;
261
262 /* global variable */
263 MacCb macCb;
264 void fillMacToSchPst(Pst *pst);
265 void fillRarPdu(RarInfo *rarInfo);
266 void createMacRaCb(uint16_t cellId, uint16_t crnti);
267 void fillMsg4DlData(MacDlData *dlData, uint8_t *msg4Pdu);
268 void fillMacCe(MacCeInfo  *macCeData, uint8_t *msg3Pdu);
269 void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *msg4TxPdu, uint16_t tbSize);
270 int unpackRxData(RxDataIndPdu *rxDataIndPdu);
271 uint16_t macSendUlCcchInd(uint8_t *rrcContainer, uint16_t cellId, uint16_t crnti);
272 void fillMg4Pdu(Msg4Alloc *msg4Alloc);
273 void buildAndSendMuxPdu(SlotIndInfo currTimingInfo);
274
275 #endif
276 /**********************************************************************
277   End of file
278  **********************************************************************/