PHY_DELTA changes
[o-du/l2.git] / src / cm / mac_sch_interface.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 /* events */
20 #define EVENT_SCH_CELL_CFG      1
21 #define EVENT_SCH_CELL_CFG_CFM  2
22 #define EVENT_DL_ALLOC          3 
23 #define EVENT_UL_SCH_INFO       4 
24 #define EVENT_RACH_IND_TO_SCH        5
25 #define EVENT_CRC_IND_TO_SCH         6
26 #define EVENT_DL_RLC_BO_INFO_TO_SCH  7
27
28 /* selector */
29 #define MAC_SCH_LC_SELECTOR 0
30 #define MAC_SCH_TC_SELECTOR 1
31 #define MAC_SCH_LWLC_SELECTOR 2
32
33 /*macros*/
34 #define NO_SSB 0
35 #define SSB_TRANSMISSION 1
36 #define SSB_REPEAT 2
37 #define MAX_SSB_IDX 1 /* forcing it as 1 for now. Right value is 64 */
38
39 #define NO_SIB1 0
40 #define SIB1_TRANSMISSION 1
41 #define SIB1_REPITITION 2
42
43 #define MAX_NUM_PRG     1 /* max value should be later 275 */
44 #define MAX_DIG_BF_INTERFACES 0 /* max value should be later 255 */
45 #define MAX_CODEWORDS  1  /* max should be 2 */
46 #define SCH_HARQ_PROC_ID 1 /* harq proc id */
47 #define SCH_ALLOC_TYPE_1 1 /*sch res alloc type */
48
49 /* Datatype in UL SCH Info */
50 #define SCH_DATATYPE_PUSCH 1
51 #define SCH_DATATYPE_PUSCH_UCI 2
52 #define SCH_DATATYPE_UCI 4
53 #define SCH_DATATYPE_SRS 8
54 #define SCH_DATATYPE_PRACH 16
55
56 #define MAX_NUMBER_OF_CRC_IND_BITS 1
57 #define MAX_NUM_LOGICAL_CHANNELS   11
58 /* can we have a common numslot numscs between mac sch */
59 #define MAX_SLOTS 10
60 #define MAX_SFN   1024
61 #define CCCH_LCID  0
62 #define ADD_DELTA_TO_TIME(crntTime, toFill, incr)          \
63    if ((crntTime.slot + incr) > (MAX_SLOTS - 1))   \
64       toFill.sfn = (crntTime.sfn + 1);      \
65    else                                                  \
66       toFill.sfn = crntTime.sfn;                              \
67    toFill.slot = (crntTime.slot + incr) % MAX_SLOTS; \
68    if (toFill.sfn >= MAX_SFN) \
69    { \
70       toFill.sfn%=MAX_SFN; \
71    } \
72
73 /*structures*/
74
75
76 typedef enum
77 {
78         RSP_OK,
79         RSP_NOK
80 }schMacRsp;
81
82 typedef struct
83 {
84    uint32_t    ssbPbchPwr;       /* SSB block power */
85    uint8_t     scsCommon;           /* subcarrier spacing for common [0-3]*/
86    uint8_t     ssbOffsetPointA;  /* SSB sub carrier offset from point A */
87    SSBPeriod   ssbPeriod;        /* SSB Periodicity in msec */
88    uint8_t     ssbSubcOffset;    /* Subcarrier Offset(Kssb) */
89    uint32_t    nSSBMask[SSB_MASK_SIZE];      /* Bitmap for actually transmitted SSB. */
90 }SchSsbCfg;
91
92 typedef struct bwpCfg
93 {
94    uint8_t subcarrierSpacing;
95    uint8_t cyclicPrefix;
96    uint16_t BWPSize;
97    uint16_t BWPStart;
98 }BwpCfg;
99
100 typedef struct prg
101 {
102    uint16_t pmIdx;
103    uint16_t beamIdx[MAX_DIG_BF_INTERFACES];
104 } Prg;
105
106 typedef struct beamformingInfo
107 {
108    uint16_t numPrgs;
109    uint16_t prgSize;
110    uint8_t  digBfInterfaces;
111    Prg  prg[MAX_NUM_PRG];
112 } BeamformingInfo;
113
114 /* SIB1 PDSCH structures */
115
116 typedef struct codewordinfo
117 {
118    uint16_t targetCodeRate;
119    uint8_t  qamModOrder;
120    uint8_t  mcsIndex;
121    uint8_t  mcsTable;
122    uint8_t  rvIndex;
123    uint32_t tbSize;
124 } CodewordInfo;
125
126 typedef struct dmrsInfo
127 {
128    uint16_t dlDmrsSymbPos;
129    uint8_t  dmrsConfigType;
130    uint16_t dlDmrsScramblingId;
131    uint8_t  scid;
132    uint8_t  numDmrsCdmGrpsNoData;
133    uint16_t dmrsPorts;
134 } DmrsInfo;
135
136 typedef struct pdschFreqAlloc
137 {
138    uint8_t  resourceAlloc;
139    /* since we are using type-1, hence rbBitmap excluded */
140    uint16_t rbStart;
141    uint16_t rbSize;
142    uint8_t  vrbPrbMapping;
143 } PdschFreqAlloc;
144
145 typedef struct pdschTimeAlloc
146 {
147    uint8_t rowIndex;
148    uint8_t startSymbolIndex;
149    uint8_t numSymbols;
150 } PdschTimeAlloc;
151
152 typedef struct txPowerPdschInfo
153 {
154    uint8_t powerControlOffset;
155    uint8_t powerControlOffsetSS;
156 } TxPowerPdschInfo;
157
158 typedef struct pdschCfg
159 {
160    uint16_t pduBitmap;
161    uint16_t rnti;
162    uint16_t pduIndex;
163    uint8_t numCodewords;
164    CodewordInfo codeword[MAX_CODEWORDS];
165    uint16_t dataScramblingId;
166    uint8_t  numLayers;
167    uint8_t  transmissionScheme;
168    uint8_t  refPoint;
169    DmrsInfo dmrs;
170    PdschFreqAlloc freqAlloc;
171    PdschTimeAlloc timeAlloc;
172    BeamformingInfo beamPdschInfo;
173    TxPowerPdschInfo txPdschPower;
174 } PdschCfg;
175 /* SIB1 PDSCH structures end */
176
177 /* SIB1 interface structure */
178
179 typedef struct coresetCfg
180 {
181    uint8_t coreSet0Size;
182    uint8_t startSymbolIndex;
183    uint8_t durationSymbols;
184    uint8_t freqDomainResource[6];
185    uint8_t cceRegMappingType;
186    uint8_t regBundleSize;
187    uint8_t interleaverSize;
188    uint8_t coreSetType;
189    uint16_t shiftIndex;
190    uint8_t precoderGranularity;
191    uint8_t cceIndex;
192    uint8_t aggregationLevel;
193 } CoresetCfg;
194
195 typedef struct txPowerPdcchInfo
196 {
197    uint8_t powerValue;
198    uint8_t powerControlOffsetSS;
199 } TxPowerPdcchInfo;
200
201 typedef struct dlDCI
202 {
203    uint16_t rnti;
204    uint16_t scramblingId;
205    uint16_t scramblingRnti;
206    uint8_t cceIndex;
207    uint8_t aggregLevel;
208    BeamformingInfo beamPdcchInfo;
209    TxPowerPdcchInfo txPdcchPower;
210    PdschCfg     *pdschCfg;
211 } DlDCI;
212
213 typedef struct pdcchCfg
214 {
215    /* coreset-0 configuration */
216    CoresetCfg coreset0Cfg;
217
218    uint16_t numDlDci;
219    DlDCI    dci; /* as of now its only one DCI, later it will be numDlCi */
220 } PdcchCfg;
221 /* end of SIB1 PDCCH structures */
222
223 typedef struct
224 {
225    /* parameters recieved from DU-APP */
226    uint16_t sib1PduLen;
227    uint16_t sib1NewTxPeriod;
228    uint16_t sib1RepetitionPeriod;
229    uint8_t  coresetZeroIndex;     /* derived from 4 LSB of pdcchSib1 present in MIB */
230    uint8_t  searchSpaceZeroIndex; /* derived from 4 MSB of pdcchSib1 present in MIB */
231    uint16_t sib1Mcs;
232         
233         /* parameters derived in scheduler */
234         uint8_t n0;
235    BwpCfg bwp;
236    PdcchCfg sib1PdcchCfg;
237    PdschCfg sib1PdschCfg;
238 }SchSib1Cfg;
239
240 typedef struct schRachCfg
241 {
242    uint8_t      prachCfgIdx; /* PRACH config idx */
243    uint8_t      prachSubcSpacing; /* Subcarrier spacing of RACH */
244         uint16_t     msg1FreqStart;     /* Msg1-FrequencyStart */
245         uint8_t      msg1Fdm;             /* PRACH FDM (1,2,4,8) */
246    uint16_t     rootSeqIdx;        /* Root sequence index */
247    uint8_t      numRootSeq;        /* Number of root sequences required for FD */
248    uint16_t     k1;                /* Frequency Offset for each FD */
249    uint8_t      ssbPerRach;          /* SSB per RACH occassion */
250    uint8_t      prachMultCarrBand;    /* Presence of Multiple carriers in Band */
251         uint8_t      raContResTmr;        /* RA Contention Resoultion Timer */
252         uint8_t      rsrpThreshSsb;       /* RSRP Threshold SSB */
253    uint8_t      raRspWindow;         /* RA Response Window */
254 }SchRachCfg;
255
256 typedef struct schBwpParams
257 {
258    uint16_t firstPrb;
259    uint16_t numPrb;
260         uint8_t  scs;
261         uint8_t  cyclicPrefix;
262 }SchBwpParams;
263
264 typedef struct schCandidatesInfo
265 {
266    uint8_t aggLevel1;
267    uint8_t aggLevel2;
268    uint8_t aggLevel4;
269    uint8_t aggLevel8;
270    uint8_t aggLevel16;
271 }SchCandidatesInfo;
272
273 typedef struct schSearchSpaceCfg
274 {
275    uint8_t searchSpaceId;
276         uint8_t coresetId;
277         uint16_t monitoringSlot;
278         uint16_t duration;
279         uint16_t monitoringSymbol;
280         SchCandidatesInfo candidate;
281 }SchSearchSpaceCfg;
282
283 typedef struct schPdcchCfgCmn
284 {
285    SchSearchSpaceCfg commonSearchSpace;
286    uint8_t raSearchSpaceId;
287 }SchPdcchCfgCmn;
288
289 typedef struct schPdschCfgCmn
290 {
291    uint8_t k0;
292    uint8_t mappingType;
293    uint8_t startSymbol;
294    uint8_t lengthSymbol;
295 }SchPdschCfgCmn;
296
297 typedef struct schPuschCfgCmn
298 {
299    uint8_t k2;
300    uint8_t mappingType;
301    uint8_t startSymbol;
302    uint8_t lengthSymbol;
303 }SchPuschCfgCmn;
304
305 typedef struct schBwpDlCfg
306 {
307    SchBwpParams   bwp;
308         SchPdcchCfgCmn pdcchCommon;
309         SchPdschCfgCmn pdschCommon;
310 }SchBwpDlCfg;
311
312 typedef struct schBwpUlCfg
313 {
314    SchBwpParams   bwp;
315         SchPuschCfgCmn puschCommon;
316 }SchBwpUlCfg;
317
318 typedef struct schCellCfg
319 {
320    uint16_t    cellId;     /* Cell Id */
321    uint16_t    phyCellId;  /* Physical cell id */
322         uint8_t     bandwidth;  /* Supported B/W */
323    DuplexMode  dupMode;    /* Duplex type: TDD/FDD */
324         SchSsbCfg   ssbSchCfg;  /* SSB config */
325         SchSib1Cfg  sib1SchCfg; /* SIB1 config */
326    SchRachCfg  schRachCfg; /* PRACH config */
327         SchBwpDlCfg schInitialDlBwp; /* Initial DL BWP */
328         SchBwpUlCfg schInitialUlBwp; /* Initial UL BWP */
329         uint8_t     puschMu;         /* PUSCH MU */
330 }SchCellCfg;
331
332 typedef struct schCellCfgCfm
333 {
334    U16         cellId;     /* Cell Id */
335    schMacRsp   rsp;   
336 }SchCellCfgCfm;
337
338 typedef struct timeDomainAlloc
339 {
340    uint16_t startSymb;
341         uint16_t numSymb;
342 }TimeDomainAlloc;
343
344 typedef struct freqDomainAlloc
345 {
346    uint16_t startPrb;
347    uint16_t numPrb;
348 }FreqDomainAlloc;
349
350 typedef struct ssbInfo
351 {
352    uint8_t ssbIdx;          /* SSB Index */
353         TimeDomainAlloc tdAlloc; /* Time domain allocation */
354         FreqDomainAlloc fdAlloc; /* Freq domain allocation */
355 }SsbInfo;
356
357 typedef struct sib1AllocInfo
358 {
359    BwpCfg bwp;
360    PdcchCfg sib1PdcchCfg;
361    PdschCfg sib1PdschCfg;
362 } Sib1AllocInfo;
363
364 typedef struct prachSchInfo
365 {
366         uint8_t  numPrachOcas;   /* Num Prach Ocassions */
367    uint8_t  prachFormat;    /* PRACH Format */
368    uint8_t  numRa;          /* Freq domain ocassion */
369    uint8_t  prachStartSymb; /* Freq domain ocassion */
370 }PrachSchInfo;
371
372 /* Interface structure signifying DL broadcast allocation for SSB, SIB1 */
373 typedef struct dlBrdcstAlloc
374 {
375         /* Ssb transmission is determined as follows:
376          * 0 : No tranamission
377          * 1 : SSB Transmission
378          * 2 : SSB Repetition */
379         uint8_t ssbTrans;
380         uint8_t ssbIdxSupported;
381         SsbInfo ssbInfo[MAX_SSB_IDX];
382         /* Sib1 transmission is determined as follows:
383          * 0 : No tranamission
384          * 1 : SIB1 Transmission
385          * 2 : SIB1 Repetition */
386         U8 sib1Trans;
387         Sib1AllocInfo sib1Alloc;
388 }DlBrdcstAlloc;
389
390 typedef struct rarInfo
391 {
392    uint16_t raRnti;
393         uint8_t  RAPID;
394         uint16_t ta;
395         uint16_t msg3StartRb;
396         uint8_t  msg3NumRb;
397         uint16_t tcrnti;
398         uint8_t  rarPdu[8];
399         uint8_t  rarPduLen;
400 }RarInfo;
401
402 typedef struct rarAlloc
403 {
404    RarInfo rarInfo;
405    BwpCfg  bwp;
406    PdcchCfg rarPdcchCfg;
407    PdschCfg rarPdschCfg;
408 }RarAlloc;
409
410 typedef struct msg4Info
411 {
412         uint8_t  ndi;
413         uint8_t  harqProcNum;
414         uint8_t  dlAssignIdx;
415         uint8_t  pucchTpc;
416         uint8_t  pucchResInd;
417         uint8_t  harqFeedbackInd;
418         uint8_t  dciFormatId;
419    uint16_t crnti;
420    uint8_t  *msg4Pdu;
421    uint8_t  msg4PduLen;
422 }Msg4Info;
423
424 typedef struct msg4Alloc
425 {
426    Msg4Info msg4Info;
427    BwpCfg bwp;
428    PdcchCfg msg4PdcchCfg;
429    PdschCfg msg4PdschCfg;
430 }Msg4Alloc;
431
432 typedef struct schSlotValue
433 {
434         SlotIndInfo currentTime;
435         SlotIndInfo broadcastTime;
436         SlotIndInfo rarTime;
437         SlotIndInfo msg4Time;
438         SlotIndInfo dlMsgTime;
439 }SchSlotValue;
440
441 typedef struct dlSchedInfo
442 {
443    uint16_t cellId;  /* Cell Id */
444         SchSlotValue schSlotValue;
445
446         /* Allocation for broadcast messages */
447    bool isBroadcastPres;
448         DlBrdcstAlloc brdcstAlloc;
449
450         /* Allocation for RAR message */
451         //uint8_t isRarPres;
452         RarAlloc *rarAlloc;
453
454    /* Allocation from MSG4 */
455    Msg4Alloc *msg4Alloc;
456 }DlSchedInfo;
457
458 typedef struct tbInfo
459 {
460    uint8_t  mcs;    /* MCS */
461    uint8_t  ndi;    /* NDI */
462    uint8_t  rv;     /* Redundancy Version */
463    uint16_t tbSize; /* TB Size */
464 }TbInfo;
465
466 typedef struct schPuschInfo
467 {
468    uint8_t          harqProcId;   /* HARQ Process ID */
469    uint8_t          resAllocType; /* Resource allocation type */
470    FreqDomainAlloc  fdAlloc;      /* Freq domain allocation */
471    TimeDomainAlloc  tdAlloc;      /* Time domain allocation */
472    TbInfo           tbInfo;       /* TB info */
473 }SchPuschInfo;
474
475
476 typedef struct ulSchedInfo
477 {
478    uint16_t      cellId;         /* Cell Id */
479         uint16_t      crnti;          /* CRNI */
480         SlotIndInfo   slotIndInfo;    /* Slot Info: sfn, slot number */
481         uint8_t       dataType;       /* Type of info being scheduled */
482         PrachSchInfo  prachSchInfo;   /* Prach scheduling info */
483         SchPuschInfo  schPuschInfo;   /* Pusch scheduling info */
484 }UlSchedInfo;
485
486 typedef struct rachIndInfo
487 {
488    uint16_t    cellId;
489    uint16_t    crnti;
490    SlotIndInfo timingInfo;
491    uint8_t     slotIdx;
492    uint8_t     symbolIdx;
493    uint8_t     freqIdx;
494    uint8_t     preambleIdx;
495    uint16_t    timingAdv;
496 }RachIndInfo;
497
498
499 typedef struct crcIndInfo
500 {
501    uint16_t    cellId;
502    uint16_t    crnti;
503    SlotIndInfo timingInfo;
504    uint16_t    numCrcInd;
505    uint8_t     crcInd[MAX_NUMBER_OF_CRC_IND_BITS];
506 }CrcIndInfo;
507
508 typedef struct boInfo
509 {
510    uint8_t   lcId;
511    uint32_t  dataVolume;
512 }BOInfo;
513
514 typedef struct dlRlcBOInfo
515 {
516    uint16_t    cellId;
517    uint16_t    crnti;
518    uint16_t    numLc;
519    BOInfo      boInfo[MAX_NUM_LOGICAL_CHANNELS];
520 }DlRlcBOInfo;
521
522
523 /* function pointers */
524
525 typedef int (*SchCellCfgCfmFunc)    ARGS((
526    Pst            *pst,           /* Post Structure */                         
527    SchCellCfgCfm  *schCellCfgCfm  /* Cell Cfg Cfm */
528 ));
529
530 typedef int (*SchCellCfgFunc)    ARGS((
531    Pst            *pst,           /* Post Structure */                         
532    SchCellCfg  *schCellCfg     /* Cell Cfg  */
533 ));
534
535 typedef int (*SchMacDlAllocFunc)     ARGS((                     
536    Pst            *pst,       /* Post Structure */                         
537    DlSchedInfo    *dlSchedInfo    /* dl allocation Info */                      
538 ));
539
540 typedef int (*SchMacUlSchInfoFunc)     ARGS((                     
541    Pst         *pst,           /* Post Structure */                         
542    UlSchedInfo *ulSchedInfo         /* UL Alloc Sch  Info */                      
543 ));
544
545 /* function declarations */
546 int packMacSchSlotInd(Pst *pst, SlotIndInfo *slotInd);
547 int packSchMacDlAlloc(Pst *pst, DlSchedInfo  *dlSchedInfo);
548 int packSchMacUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo);
549 EXTERN int packSchCellCfg(Pst *pst, SchCellCfg  *schCellCfg);
550 EXTERN int packSchCellCfgCfm(Pst *pst, SchCellCfgCfm  *schCellCfgCfm);
551
552 EXTERN int MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo);
553 EXTERN int MacProcSchCellCfg(Pst *pst, SchCellCfg  *schCellCfg);
554 EXTERN int MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm  *schCellCfgCfm);
555 EXTERN int SchHdlCellCfgReq(Pst *pst, SchCellCfg *schCellCfg);
556 EXTERN int schActvInit(Ent entity, Inst instId, Region region, Reason reason);
557 EXTERN S16 SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
558 EXTERN int MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo);
559 typedef int (*MacSchRachIndFunc)(Pst *pst, RachIndInfo *rachInd);
560 int packMacSchRachInd(Pst *pst, RachIndInfo *rachInd);
561 int macSchRachInd(Pst *pst, RachIndInfo *rachInd);
562 typedef int (*MacSchCrcIndFunc)(Pst *pst, CrcIndInfo *crcInd);
563 int packMacSchCrcInd(Pst *pst, CrcIndInfo *crcInd);
564 int macSchCrcInd(Pst *pst, CrcIndInfo *crcInd);
565 typedef uint8_t (*MacSchDlRlcBoInfoFunc)(Pst *pst, DlRlcBOInfo *dlBoInfo);
566 uint8_t packMacSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo);
567 uint8_t macSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo);
568
569
570 /**********************************************************************
571   End of file
572  **********************************************************************/
573