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