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