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