PUCCH CHANGES AT SCH AND LOWER MAC
[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 schPucchCfgCmn
308 {
309    uint8_t pucchResourceCommon;
310    uint8_t pucchGroupHopping;
311 }SchPucchCfgCmn;
312
313 typedef struct schPuschCfgCmn
314 {
315    uint8_t k2;
316    uint8_t mappingType;
317    uint8_t startSymbol;
318    uint8_t lengthSymbol;
319 }SchPuschCfgCmn;
320
321 typedef struct schBwpDlCfg
322 {
323    SchBwpParams   bwp;
324         SchPdcchCfgCmn pdcchCommon;
325         SchPdschCfgCmn pdschCommon;
326 }SchBwpDlCfg;
327
328 typedef struct schBwpUlCfg
329 {
330    SchBwpParams   bwp;
331         SchPucchCfgCmn pucchCommon;
332         SchPuschCfgCmn puschCommon;
333 }SchBwpUlCfg;
334
335 typedef struct schCellCfg
336 {
337    uint16_t    cellId;           /* Cell Id */
338    uint16_t    phyCellId;        /* Physical cell id */
339         uint8_t     bandwidth;        /* Supported B/W */
340    DuplexMode  dupMode;          /* Duplex type: TDD/FDD */
341         SchSsbCfg   ssbSchCfg;        /* SSB config */
342         SchSib1Cfg  sib1SchCfg;       /* SIB1 config */
343    SchRachCfg  schRachCfg;       /* PRACH config */
344         SchBwpDlCfg schInitialDlBwp;  /* Initial DL BWP */
345         SchBwpUlCfg schInitialUlBwp;  /* Initial UL BWP */
346         uint8_t     puschMu;          /* PUSCH MU */
347 }SchCellCfg;
348
349 typedef struct schCellCfgCfm
350 {
351    U16         cellId;     /* Cell Id */
352    schMacRsp   rsp;   
353 }SchCellCfgCfm;
354
355 typedef struct ssbInfo
356 {
357    uint8_t         ssbIdx;          /* SSB Index */
358         TimeDomainAlloc tdAlloc; /* Time domain allocation */
359         FreqDomainAlloc fdAlloc; /* Freq domain allocation */
360 }SsbInfo;
361
362 typedef struct sib1AllocInfo
363 {
364    BwpCfg bwp;
365    PdcchCfg sib1PdcchCfg;
366    PdschCfg sib1PdschCfg;
367 } Sib1AllocInfo;
368
369 typedef struct prachSchInfo
370 {
371         uint8_t  numPrachOcas;   /* Num Prach Ocassions */
372    uint8_t  prachFormat;    /* PRACH Format */
373    uint8_t  numRa;          /* Freq domain ocassion */
374    uint8_t  prachStartSymb; /* Freq domain ocassion */
375 }PrachSchInfo;
376
377 /* Interface structure signifying DL broadcast allocation for SSB, SIB1 */
378 typedef struct dlBrdcstAlloc
379 {
380         /* Ssb transmission is determined as follows:
381          * 0 : No tranamission
382          * 1 : SSB Transmission
383          * 2 : SSB Repetition */
384         uint8_t ssbTrans;
385         uint8_t ssbIdxSupported;
386         SsbInfo ssbInfo[MAX_SSB_IDX];
387         /* Sib1 transmission is determined as follows:
388          * 0 : No tranamission
389          * 1 : SIB1 Transmission
390          * 2 : SIB1 Repetition */
391         U8 sib1Trans;
392         Sib1AllocInfo sib1Alloc;
393 }DlBrdcstAlloc;
394
395 typedef struct rarInfo
396 {
397    uint16_t        raRnti;
398         uint8_t         RAPID;
399         uint16_t        ta;
400         FreqDomainAlloc msg3FreqAlloc;
401         uint16_t        tcrnti;
402         uint8_t         rarPdu[8];
403         uint8_t         rarPduLen;
404 }RarInfo;
405
406 typedef struct rarAlloc
407 {
408    RarInfo rarInfo;
409    BwpCfg  bwp;
410    PdcchCfg rarPdcchCfg;
411    PdschCfg rarPdschCfg;
412 }RarAlloc;
413
414 typedef struct msg4Info
415 {
416    uint16_t crnti;
417         uint8_t  ndi;
418         uint8_t  harqProcNum;
419         uint8_t  dlAssignIdx;
420         uint8_t  pucchTpc;
421         uint8_t  pucchResInd;
422         uint8_t  harqFeedbackInd;
423         uint8_t  dciFormatId;
424    uint8_t  *msg4Pdu;
425    uint16_t  msg4PduLen;
426 }Msg4Info;
427
428 typedef struct msg4Alloc
429 {
430    Msg4Info msg4Info;
431    BwpCfg bwp;
432    PdcchCfg msg4PdcchCfg;
433    PdschCfg msg4PdschCfg;
434 }Msg4Alloc;
435
436 typedef struct schSlotValue
437 {
438         SlotIndInfo currentTime;
439         SlotIndInfo broadcastTime;
440         SlotIndInfo rarTime;
441         SlotIndInfo msg4Time;
442         SlotIndInfo dlMsgTime;
443 }SchSlotValue;
444
445 typedef struct dlSchedInfo
446 {
447    uint16_t cellId;  /* Cell Id */
448         SchSlotValue schSlotValue;
449
450         /* Allocation for broadcast messages */
451    bool isBroadcastPres;
452         DlBrdcstAlloc brdcstAlloc;
453
454         /* Allocation for RAR message */
455         //uint8_t isRarPres;
456         RarAlloc *rarAlloc;
457
458    /* Allocation from MSG4 */
459    Msg4Alloc *msg4Alloc;
460 }DlSchedInfo;
461
462 typedef struct tbInfo
463 {
464    uint8_t  mcs;    /* MCS */
465    uint8_t  ndi;    /* NDI */
466    uint8_t  rv;     /* Redundancy Version */
467    uint16_t tbSize; /* TB Size */
468 }TbInfo;
469
470 typedef struct schPuschInfo
471 {
472    uint8_t          harqProcId;   /* HARQ Process ID */
473    uint8_t          resAllocType; /* Resource allocation type */
474    FreqDomainAlloc  fdAlloc;      /* Freq domain allocation */
475    TimeDomainAlloc  tdAlloc;      /* Time domain allocation */
476    TbInfo           tbInfo;       /* TB info */
477 }SchPuschInfo;
478
479 typedef struct schPucchInfo
480 {
481    uint16_t         rnti;
482    uint8_t          pucchFormat;
483    FreqDomainAlloc  fdAlloc;      /* Freq domain allocation */
484    TimeDomainAlloc  tdAlloc;      /* Time domain allocation */
485         uint8_t          srFlag;
486         uint8_t          harqFlag;
487         uint8_t          numHarqBits;
488         uint8_t          uciFlag;
489         uint8_t          numUciBits;
490 }SchPucchInfo;
491
492 typedef struct ulSchedInfo
493 {
494    uint16_t      cellId;         /* Cell Id */
495         uint16_t      crnti;          /* CRNI */
496         SlotIndInfo   slotIndInfo;    /* Slot Info: sfn, slot number */
497         uint8_t       dataType;       /* Type of info being scheduled */
498         PrachSchInfo  prachSchInfo;   /* Prach scheduling info */
499         SchPuschInfo  schPuschInfo;   /* Pusch scheduling info */
500         SchPucchInfo  schPucchInfo;   /* Pusch scheduling info */
501 }UlSchedInfo;
502
503 typedef struct rachIndInfo
504 {
505    uint16_t    cellId;
506    uint16_t    crnti;
507    SlotIndInfo timingInfo;
508    uint8_t     slotIdx;
509    uint8_t     symbolIdx;
510    uint8_t     freqIdx;
511    uint8_t     preambleIdx;
512    uint16_t    timingAdv;
513 }RachIndInfo;
514
515
516 typedef struct crcIndInfo
517 {
518    uint16_t    cellId;
519    uint16_t    crnti;
520    SlotIndInfo timingInfo;
521    uint16_t    numCrcInd;
522    uint8_t     crcInd[MAX_NUMBER_OF_CRC_IND_BITS];
523 }CrcIndInfo;
524
525 typedef struct boInfo
526 {
527    uint8_t   lcId;
528    uint32_t  dataVolume;
529 }BOInfo;
530
531 typedef struct dlRlcBOInfo
532 {
533    uint16_t    cellId;
534    uint16_t    crnti;
535    uint16_t    numLc;
536    BOInfo      boInfo[MAX_NUM_LOGICAL_CHANNELS];
537 }DlRlcBOInfo;
538
539
540 /* function pointers */
541
542 typedef int (*SchCellCfgCfmFunc)    ARGS((
543    Pst            *pst,           /* Post Structure */                         
544    SchCellCfgCfm  *schCellCfgCfm  /* Cell Cfg Cfm */
545 ));
546
547 typedef int (*SchCellCfgFunc)    ARGS((
548    Pst            *pst,           /* Post Structure */                         
549    SchCellCfg  *schCellCfg     /* Cell Cfg  */
550 ));
551
552 typedef int (*SchMacDlAllocFunc)     ARGS((                     
553    Pst            *pst,       /* Post Structure */                         
554    DlSchedInfo    *dlSchedInfo    /* dl allocation Info */                      
555 ));
556
557 typedef int (*SchMacUlSchInfoFunc)     ARGS((                     
558    Pst         *pst,           /* Post Structure */                         
559    UlSchedInfo *ulSchedInfo         /* UL Alloc Sch  Info */                      
560 ));
561
562 /* function declarations */
563 int packMacSchSlotInd(Pst *pst, SlotIndInfo *slotInd);
564 int packSchMacDlAlloc(Pst *pst, DlSchedInfo  *dlSchedInfo);
565 int packSchMacUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo);
566 EXTERN int packSchCellCfg(Pst *pst, SchCellCfg  *schCellCfg);
567 EXTERN int packSchCellCfgCfm(Pst *pst, SchCellCfgCfm  *schCellCfgCfm);
568
569 EXTERN int MacProcDlAlloc(Pst *pst, DlSchedInfo *dlSchedInfo);
570 EXTERN int MacProcSchCellCfg(Pst *pst, SchCellCfg  *schCellCfg);
571 EXTERN int MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm  *schCellCfgCfm);
572 EXTERN int SchHdlCellCfgReq(Pst *pst, SchCellCfg *schCellCfg);
573 EXTERN int schActvInit(Ent entity, Inst instId, Region region, Reason reason);
574 EXTERN S16 SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
575 EXTERN int MacProcUlSchInfo(Pst *pst, UlSchedInfo *ulSchedInfo);
576 typedef int (*MacSchRachIndFunc)(Pst *pst, RachIndInfo *rachInd);
577 int packMacSchRachInd(Pst *pst, RachIndInfo *rachInd);
578 int macSchRachInd(Pst *pst, RachIndInfo *rachInd);
579 typedef int (*MacSchCrcIndFunc)(Pst *pst, CrcIndInfo *crcInd);
580 int packMacSchCrcInd(Pst *pst, CrcIndInfo *crcInd);
581 int macSchCrcInd(Pst *pst, CrcIndInfo *crcInd);
582 typedef uint8_t (*MacSchDlRlcBoInfoFunc)(Pst *pst, DlRlcBOInfo *dlBoInfo);
583 uint8_t packMacSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo);
584 uint8_t macSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo);
585
586
587 /**********************************************************************
588   End of file
589  **********************************************************************/
590