nr_mac_gNB.h 23.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
22
/*! \file mac.h
23
* \brief MAC data structures, constant, and function prototype
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
24 25
* \author Navid Nikaein and Raymond Knopp, WIE-TAI CHEN
* \date 2011, 2018
26
* \version 0.5
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
27 28
* \company Eurecom, NTUST
* \email navid.nikaein@eurecom.fr, kroempa@gmail.com
29 30 31 32 33 34 35 36 37

*/
/** @defgroup _oai2  openair2 Reference Implementation
 * @ingroup _ref_implementation_
 * @{
 */

/*@}*/

38 39
#ifndef __LAYER2_NR_MAC_GNB_H__
#define __LAYER2_NR_MAC_GNB_H__
40 41 42 43 44

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

45 46 47 48 49 50
/* Commmon */
#include "targets/ARCH/COMMON/common_lib.h"
#include "COMMON/platform_constants.h"
#include "common/ran_context.h"

/* RRC */
51
#include "NR_BCCH-BCH-Message.h"
52
#include "NR_CellGroupConfig.h"
53
#include "NR_ServingCellConfigCommon.h"
54
#include "NR_MeasConfig.h"
55

56 57 58 59 60
/* PHY */
#include "PHY/defs_gNB.h"
#include "PHY/TOOLS/time_meas.h"

/* Interface */
61
#include "nfapi_nr_interface_scf.h"
62
#include "NR_PHY_INTERFACE/NR_IF_Module.h"
63

64
/* MAC */
Guy De Souza's avatar
Guy De Souza committed
65 66
#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_proto.h"
67
#include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
68 69
#include "LAYER2/NR_MAC_COMMON/nr_mac_common.h"
#include "NR_TAG.h"
70

Laurent's avatar
Laurent committed
71
#include <openair3/UICC/usim_interface.h>
laurent's avatar
laurent committed
72 73


74
/* Defs */
75
#define MAX_NUM_BWP 2
76
#define MAX_NUM_CORESET 12
77
#define MAX_NUM_CCE 90
78
#define MAX_HARQ_ROUNDS 4
79 80
/*!\brief Maximum number of random access process */
#define NR_NB_RA_PROC_MAX 4
81
#define MAX_NUM_OF_SSB 64
82

83 84 85 86 87 88 89 90 91
/*! \brief NR_list_t is a "list" (of users, HARQ processes, slices, ...).
 * Especially useful in the scheduler and to keep "classes" of users. */
typedef struct {
  int head;
  int *next;
  int tail;
  int len;
} NR_list_t;

cig's avatar
cig committed
92 93 94 95
typedef enum {
  RA_IDLE = 0,
  Msg2 = 1,
  WAIT_Msg3 = 2,
96 97 98
  Msg3_retransmission = 3,
  Msg4 = 4,
  WAIT_Msg4_ACK = 5
Raymond Knopp's avatar
Raymond Knopp committed
99
} RA_gNB_state_t;
cig's avatar
cig committed
100

101 102 103 104 105
typedef struct NR_preamble_ue {
  uint8_t num_preambles;
  uint8_t *preamble_list;
} NR_preamble_ue_t;

106 107 108 109 110 111 112 113 114 115 116 117 118 119
typedef struct NR_sched_pdcch {
  uint16_t BWPSize;
  uint16_t BWPStart;
  uint8_t CyclicPrefix;
  uint8_t SubcarrierSpacing;
  uint8_t StartSymbolIndex;
  uint8_t CceRegMappingType;
  uint8_t RegBundleSize;
  uint8_t InterleaverSize;
  uint16_t ShiftIndex;
  uint8_t DurationSymbols;
  int n_rb;
} NR_sched_pdcch_t;

120 121
/*! \brief gNB template for the Random access information */
typedef struct {
122
  /// Flag to indicate this process is active
Raymond Knopp's avatar
Raymond Knopp committed
123
  RA_gNB_state_t state;
124 125 126 127 128 129 130 131 132 133 134 135 136 137
  /// BWP id of RA process
  int bwp_id;
  /// CORESET0 configured flag
  int coreset0_configured;
  /// Slot where preamble was received
  uint8_t preamble_slot;
  /// Subframe where Msg2 is to be sent
  uint8_t Msg2_slot;
  /// Frame where Msg2 is to be sent
  frame_t Msg2_frame;
  /// Subframe where Msg3 is to be sent
  sub_frame_t Msg3_slot;
  /// Frame where Msg3 is to be sent
  frame_t Msg3_frame;
138 139
  /// Msg3 time domain allocation index
  uint8_t Msg3_tda_id;
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  /// Subframe where Msg4 is to be sent
  sub_frame_t Msg4_slot;
  /// Frame where Msg4 is to be sent
  frame_t Msg4_frame;
  /// harq_pid used for Msg4 transmission
  uint8_t harq_pid;
  /// UE RNTI allocated during RAR
  rnti_t rnti;
  /// RA RNTI allocated from received PRACH
  uint16_t RA_rnti;
  /// Received preamble_index
  uint8_t preamble_index;
  /// Received UE Contention Resolution Identifier
  uint8_t cont_res_id[6];
  /// Timing offset indicated by PHY
  int16_t timing_offset;
  /// Timeout for RRC connection
  int16_t RRC_timer;
  /// Msg3 first RB
  uint8_t msg3_first_rb;
  /// Msg3 number of RB
  uint8_t msg3_nb_rb;
162 163
  /// Msg3 BWP start
  uint8_t msg3_bwp_start;
164 165 166 167 168 169 170 171 172 173 174 175
  /// Msg3 TPC command
  uint8_t msg3_TPC;
  /// Msg3 ULdelay command
  uint8_t msg3_ULdelay;
  /// Msg3 cqireq command
  uint8_t msg3_cqireq;
  /// Round of Msg3 HARQ
  uint8_t msg3_round;
  /// TBS used for Msg4
  int msg4_TBsize;
  /// MCS used for Msg4
  int msg4_mcs;
176 177
  /// MAC PDU length for Msg4
  int mac_pdu_length;
178 179
  /// RA search space
  NR_SearchSpace_t *ra_ss;
180 181 182
  /// RA Coreset
  NR_ControlResourceSet_t *coreset;
  NR_sched_pdcch_t *sched_pdcch;
183 184
  // Beam index
  uint8_t beam_id;
185 186
  /// CellGroup for UE that is to come (NSA is non-null, null for SA)
  NR_CellGroupConfig_t *CellGroup;
187 188 189 190
  /// Preambles for contention-free access
  NR_preamble_ue_t preambles;
  /// NSA: the UEs C-RNTI to use
  rnti_t crnti;
Francesco Mani's avatar
Francesco Mani committed
191 192
  /// CFRA flag
  bool cfra;
193
} NR_RA_t;
194

195
/*! \brief gNB common channels */
196
typedef struct {
Raymond Knopp's avatar
Raymond Knopp committed
197 198 199 200
  int physCellId;
  int p_gNB;
  int Ncp;
  int nr_band;
201
  lte_frame_type_t frame_type;
202
  uint64_t dl_CarrierFreq;
Raymond Knopp's avatar
Raymond Knopp committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
  NR_BCCH_BCH_Message_t *mib;
  NR_ServingCellConfigCommon_t *ServingCellConfigCommon;
  NR_ARFCN_ValueEUTRA_t ul_CarrierFreq;
  long ul_Bandwidth;
  /// Outgoing MIB PDU for PHY
  MIB_PDU MIB_pdu;
  /// Outgoing BCCH pdu for PHY
  BCCH_PDU BCCH_pdu;
  /// Outgoing BCCH DCI allocation
  uint32_t BCCH_alloc_pdu;
  /// Outgoing CCCH pdu for PHY
  CCCH_PDU CCCH_pdu;
  /// Outgoing PCCH DCI allocation
  uint32_t PCCH_alloc_pdu;
  /// Outgoing PCCH pdu for PHY
  PCCH_PDU PCCH_pdu;
  /// Template for RA computations
220
  NR_RA_t ra[NR_NB_RA_PROC_MAX];
Raymond Knopp's avatar
Raymond Knopp committed
221
  /// VRB map for common channels
222
  uint16_t vrb_map[275];
Robert Schmidt's avatar
Robert Schmidt committed
223 224 225
  /// VRB map for common channels and PUSCH, dynamically allocated because
  /// length depends on number of slots and RBs
  uint16_t *vrb_map_UL;
Raymond Knopp's avatar
Raymond Knopp committed
226 227
  /// number of subframe allocation pattern available for MBSFN sync area
  uint8_t num_sf_allocation_pattern;
228 229 230 231 232 233 234 235 236 237
  ///Number of active SSBs
  uint8_t num_active_ssb;
  //Total available prach occasions per configuration period
  uint32_t total_prach_occasions_per_config_period;
  //Total available prach occasions
  uint32_t total_prach_occasions;
  //Max Association period
  uint8_t max_association_period;
  //SSB index
  uint8_t ssb_index[MAX_NUM_OF_SSB];
kn.raju's avatar
kn.raju committed
238 239
  //CB preambles for each SSB
  uint8_t cb_preambles_per_ssb;
240 241
} NR_COMMON_channels_t;

242 243 244

// SP ZP CSI-RS Resource Set Activation/Deactivation MAC CE
typedef struct sp_zp_csirs {
245 246 247 248 249
  bool is_scheduled;     //ZP CSI-RS ACT/Deact MAC CE is scheduled
  bool act_deact;        //Activation/Deactivation indication
  uint8_t serv_cell_id;  //Identity of Serving cell for which MAC CE applies
  uint8_t bwpid;         //Downlink BWP id
  uint8_t rsc_id;        //SP ZP CSI-RS resource set
250 251 252 253 254
} sp_zp_csirs_t;

//SP CSI-RS / CSI-IM Resource Set Activation/Deactivation MAC CE
#define MAX_CSI_RESOURCE_SET 64
typedef struct csi_rs_im {
255 256 257 258 259 260 261 262 263
  bool is_scheduled;
  bool act_deact;
  uint8_t serv_cellid;
  uint8_t bwp_id;
  bool im;
  uint8_t csi_im_rsc_id;
  uint8_t nzp_csi_rsc_id;
  uint8_t nb_tci_resource_set_id;
  uint8_t tci_state_id [ MAX_CSI_RESOURCE_SET ];
264 265 266
} csi_rs_im_t;

typedef struct pdcchStateInd {
267 268 269 270
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t coresetId;
  uint8_t tciStateId;
271
  bool tci_present_inDCI;
272 273
} pdcchStateInd_t;

274 275 276 277 278 279 280 281
typedef struct pucchSpatialRelation {
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  uint8_t pucchResourceId;
  bool s0tos7_actDeact[8];
} pucchSpatialRelation_t;

282
typedef struct SPCSIReportingpucch {
283 284 285 286
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  bool s0tos3_actDeact[4];
287 288 289 290
} SPCSIReportingpucch_t;

#define MAX_APERIODIC_TRIGGER_STATES 128 //38.331                               
typedef struct aperiodicCSI_triggerStateSelection {
291 292 293 294 295
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  uint8_t highestTriggerStateSelected;
  bool triggerStateSelection[MAX_APERIODIC_TRIGGER_STATES];
296 297 298 299
} aperiodicCSI_triggerStateSelection_t;

#define MAX_TCI_STATES 128 //38.331                                             
typedef struct pdschTciStatesActDeact {
300 301 302 303 304
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  uint8_t highestTciStateActivated;
  bool tciStateActDeact[MAX_TCI_STATES];
305
  uint8_t codepoint[8];
306 307 308
} pdschTciStatesActDeact_t;

typedef struct UE_info {
309 310 311
  sp_zp_csirs_t sp_zp_csi_rs;
  csi_rs_im_t csi_im;
  pdcchStateInd_t pdcch_state_ind;
312
  pucchSpatialRelation_t pucch_spatial_relation;
313 314 315
  SPCSIReportingpucch_t SP_CSI_reporting_pucch;
  aperiodicCSI_triggerStateSelection_t aperi_CSI_trigger;
  pdschTciStatesActDeact_t pdsch_TCI_States_ActDeact;
316 317
} NR_UE_mac_ce_ctrl_t;

318 319 320
typedef struct NR_sched_pucch {
  int frame;
  int ul_slot;
321 322 323
  bool sr_flag;
  int csi_bits;
  bool simultaneous_harqcsi;
324
  uint8_t dai_c;
Francesco Mani's avatar
Francesco Mani committed
325 326
  uint8_t timing_indicator;
  uint8_t resource_indicator;
327
  int r_pucch;
328
} NR_sched_pucch_t;
329

330 331 332 333 334
/* PUSCH semi-static configuration: as long as the TDA and DCI format remain
 * the same over the same uBWP and search space, there is no need to
 * recalculate all S/L, MCS table, or DMRS-related parameters over and over
 * again. Hence, we store them in this struct for easy reference. */
typedef struct NR_pusch_semi_static_t {
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
  int dci_format;
  int time_domain_allocation;
  uint8_t num_dmrs_cdm_grps_no_data;

  int startSymbolIndex;
  int nrOfSymbols;

  NR_PUSCH_Config_t *pusch_Config;
  uint8_t transform_precoding;
  uint8_t mcs_table;

  long mapping_type;
  NR_DMRS_UplinkConfig_t *NR_DMRS_UplinkConfig;
  uint16_t dmrs_config_type;
  uint16_t ul_dmrs_symb_pos;
  uint8_t num_dmrs_symb;
  uint8_t N_PRB_DMRS;
352
} NR_pusch_semi_static_t;
353

354 355 356
typedef struct NR_sched_pusch {
  int frame;
  int slot;
357 358 359 360 361 362 363

  /// RB allocation within active uBWP
  uint16_t rbSize;
  uint16_t rbStart;

  /// MCS
  uint8_t mcs;
364 365 366 367 368

  /// TBS-related info
  uint16_t R;
  uint8_t Qm;
  uint32_t tb_size;
369 370 371

  /// UL HARQ PID to use for this UE, or -1 for "any new"
  int8_t ul_harq_pid;
372 373 374 375 376

  /// the Time Domain Allocation used for this transmission. Note that this is
  /// only important for retransmissions; otherwise, the TDA in
  /// NR_pusch_semi_static_t has precedence
  int time_domain_allocation;
377
} NR_sched_pusch_t;
378

379 380 381 382 383 384 385 386 387 388
/* PDSCH semi-static configuratio: as long as the TDA/DMRS/mcsTable remains the
 * same, there is no need to recalculate all S/L or DMRS-related parameters
 * over and over again.  Hence, we store them in this struct for easy
 * reference. */
typedef struct NR_pdsch_semi_static {
  int time_domain_allocation;
  uint8_t numDmrsCdmGrpsNoData;

  int startSymbolIndex;
  int nrOfSymbols;
389
  uint8_t nrOfLayers;
390
  uint8_t mcsTableIdx;
391
  uint8_t dmrs_ports_id;
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
  uint8_t N_PRB_DMRS;
  uint8_t N_DMRS_SLOT;
  uint16_t dl_dmrs_symb_pos;
  nfapi_nr_dmrs_type_e dmrsConfigType;
} NR_pdsch_semi_static_t;

typedef struct NR_sched_pdsch {
  /// RB allocation within active BWP
  uint16_t rbSize;
  uint16_t rbStart;

  /// MCS-related infos
  uint8_t mcs;

  /// TBS-related info
  uint16_t R;
  uint8_t Qm;
  uint32_t tb_size;

  /// DL HARQ PID to use for this UE, or -1 for "any new"
  int8_t dl_harq_pid;

414 415 416
  // pucch format allocation
  uint8_t pucch_allocation;

417 418 419 420 421 422
  /// the Time Domain Allocation used for this transmission. Note that this is
  /// only important for retransmissions; otherwise, the TDA in
  /// NR_pdsch_semi_static_t has precedence
  int time_domain_allocation;
} NR_sched_pdsch_t;

423
typedef struct NR_UE_harq {
424
  bool is_waiting;
425 426
  uint8_t ndi;
  uint8_t round;
427
  uint16_t feedback_frame;
428
  uint16_t feedback_slot;
429

430 431
  /* Transport block to be sent using this HARQ process, its size is in
   * sched_pdsch */
432 433
  uint32_t tb[16384];
  uint32_t tb_size;
434 435 436

  /// sched_pdsch keeps information on MCS etc used for the initial transmission
  NR_sched_pdsch_t sched_pdsch;
437 438
} NR_UE_harq_t;

439 440
//! fixme : need to enhace for the multiple TB CQI report

Robert Schmidt's avatar
Robert Schmidt committed
441 442 443 444 445
typedef struct NR_DL_bler_stats {
  frame_t last_frame_slot;
  float bler;
  float rd2_bler;
  uint8_t mcs;
446
  uint64_t dlsch_rounds[8];
Robert Schmidt's avatar
Robert Schmidt committed
447
} NR_DL_bler_stats_t;
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469

//
/*! As per spec 38.214 section 5.2.1.4.2
 * - if the UE is configured with the higher layer parameter groupBasedBeamReporting set to 'disabled', the UE shall report in
  a single report nrofReportedRS (higher layer configured) different CRI or SSBRI for each report setting.
 * - if the UE is configured with the higher layer parameter groupBasedBeamReporting set to 'enabled', the UE shall report in a
  single reporting instance two different CRI or SSBRI for each report setting, where CSI-RS and/or SSB
  resources can be received simultaneously by the UE either with a single spatial domain receive filter, or with
  multiple simultaneous spatial domain receive filter
*/
#define MAX_NR_OF_REPORTED_RS 4

typedef enum NR_CSI_Report_Config {
  CSI_Report_PR_cri_ri_li_pmi_cqi_report,
  CSI_Report_PR_ssb_cri_report
} NR_CSI_Report_Config_PR;
struct CRI_RI_LI_PMI_CQI {
  uint8_t cri;
  uint8_t ri;
  uint8_t li;
  uint8_t pmi_x1;
  uint8_t pmi_x2;
470 471
  uint8_t wb_cqi_1tb;
  uint8_t wb_cqi_2tb;
472
};
r.karey's avatar
r.karey committed
473

474 475 476 477 478 479
typedef struct CRI_SSB_RSRP {
  uint8_t nr_ssbri_cri;
  uint8_t CRI_SSBRI[MAX_NR_OF_REPORTED_RS];
  uint8_t RSRP;
  uint8_t diff_RSRP[MAX_NR_OF_REPORTED_RS - 1];
} CRI_SSB_RSRP_t;
r.karey's avatar
r.karey committed
480

481 482 483 484 485 486 487 488 489 490
struct CSI_Report {
  NR_CSI_Report_Config_PR present;
  union Config_CSI_Report {
    struct CRI_RI_LI_PMI_CQI cri_ri_li_pmi_cqi_report;
    struct CRI_SSB_RSRP ssb_cri_report;
  } choice;
};

#define MAX_SR_BITLEN 8

r.karey's avatar
r.karey committed
491 492 493 494 495
typedef struct {
  uint8_t nb_ssbri_cri;
  uint8_t cri_ssbri_bitlen;
  uint8_t rsrp_bitlen;
  uint8_t diff_rsrp_bitlen;
496 497 498 499 500 501 502 503 504 505
}L1_RSRP_bitlen_t;

typedef struct{
  uint8_t cri_bitlen;
  uint8_t ri_bitlen;
  uint8_t li_bitlen;
  uint8_t pmi_x1_bitlen;
  uint8_t pmi_x2_bitlen;
  uint8_t cqi_bitlen;
} CSI_Meas_bitlen_t;
r.karey's avatar
r.karey committed
506 507 508 509

typedef struct nr_csi_report {
  NR_CSI_ReportConfig__reportQuantity_PR reportQuantity_type;
  long periodicity;
510
  uint16_t offset;
511 512 513
  long ** SSB_Index_list;
  long ** CSI_Index_list;
//  uint8_t nb_of_nzp_csi_report;
r.karey's avatar
r.karey committed
514
  uint8_t nb_of_csi_ssb_report;
515 516
  L1_RSRP_bitlen_t CSI_report_bitlen;
  CSI_Meas_bitlen_t csi_meas_bitlen;
r.karey's avatar
r.karey committed
517 518
} nr_csi_report_t;

519 520 521 522 523 524
/*! As per the spec 38.212 and table:  6.3.1.1.2-12 in a single UCI sequence we can have multiple CSI_report 
  the number of CSI_report will depend on number of CSI resource sets that are configured in CSI-ResourceConfig RRC IE
  From spec 38.331 from the IE CSI-ResourceConfig for SSB RSRP reporting we can configure only one resource set 
  From spec 38.214 section 5.2.1.2 For periodic and semi-persistent CSI Resource Settings, the number of CSI-RS Resource Sets configured is limited to S=1
 */
#define MAX_CSI_RESOURCE_SET_IN_CSI_RESOURCE_CONFIG 16
Robert Schmidt's avatar
Robert Schmidt committed
525

526 527 528 529 530 531 532
typedef enum {
  INACTIVE = 0,
  ACTIVE_NOT_SCHED,
  ACTIVE_SCHED
} NR_UL_harq_states_t;

typedef struct NR_UE_ul_harq {
533
  bool is_waiting;
534 535
  uint8_t ndi;
  uint8_t round;
536 537
  uint16_t feedback_slot;

538 539
  /// sched_pusch keeps information on MCS etc used for the initial transmission
  NR_sched_pusch_t sched_pusch;
540 541
} NR_UE_ul_harq_t;

542
/*! \brief scheduling control information set through an API */
543
#define MAX_CSI_REPORTS 48
544
typedef struct {
545 546
  /// the currently active BWP in DL
  NR_BWP_Downlink_t *active_bwp;
547 548
  /// the currently active BWP in UL
  NR_BWP_Uplink_t *active_ubwp;
549 550 551
  /// CCE index and aggregation, should be coherent with cce_list
  NR_SearchSpace_t *search_space;
  NR_ControlResourceSet_t *coreset;
552
  NR_sched_pdcch_t *sched_pdcch;
553 554 555 556 557

  /// CCE index and Aggr. Level are shared for PUSCH/PDSCH allocation decisions
  /// corresponding to the sched_pusch/sched_pdsch structures below
  int cce_index;
  uint8_t aggregation_level;
Eurecom's avatar
Eurecom committed
558 559
  /// maximum aggregation level for UE, can be used to select level
  int maxL;
560 561 562
  /// PUCCH scheduling information. Array of two: HARQ+SR in the first field,
  /// CSI in second.  This order is important for nr_acknack_scheduling()!
  NR_sched_pucch_t sched_pucch[2];
563

564 565 566
  /// PUSCH semi-static configuration: is not cleared across TTIs
  NR_pusch_semi_static_t pusch_semi_static;
  /// Sched PDSCH: scheduling decisions, copied into HARQ and cleared every TTI
567
  NR_sched_pusch_t sched_pusch;
568

569 570
  /// uplink bytes that are currently scheduled
  int sched_ul_bytes;
571 572 573
  /// estimation of the UL buffer size
  int estimated_ul_buffer;

574 575 576 577
  /// PHR info: power headroom level (dB)
  int ph;
  /// PHR info: nominal UE transmit power levels (dBm)
  int pcmax;
578

579 580 581 582
  /// PDSCH semi-static configuration: is not cleared across TTIs
  NR_pdsch_semi_static_t pdsch_semi_static;
  /// Sched PDSCH: scheduling decisions, copied into HARQ and cleared every TTI
  NR_sched_pdsch_t sched_pdsch;
583 584 585
  /// For UL synchronization: store last UL scheduling grant
  frame_t last_ul_frame;
  sub_frame_t last_ul_slot;
586

587 588 589 590
  /// total amount of data awaiting for this UE
  uint32_t num_total_bytes;
  /// per-LC status data
  mac_rlc_status_resp_t rlc_status[MAX_NUM_LCID];
Robert Schmidt's avatar
Robert Schmidt committed
591

Robert Schmidt's avatar
Robert Schmidt committed
592 593 594
  /// Estimation of HARQ from BLER
  NR_DL_bler_stats_t dl_bler_stats;

595
  int lcid_mask;
Eurecom's avatar
Eurecom committed
596
  int lcid_to_schedule;
597
  uint16_t ta_frame;
598
  int16_t ta_update;
599
  bool ta_apply;
600 601
  uint8_t tpc0;
  uint8_t tpc1;
602 603 604
  int raw_rssi;
  int pusch_snrx10;
  int pucch_snrx10;
605
  uint16_t ul_rssi;
606
  uint8_t current_harq_pid;
607 608 609
  int pusch_consecutive_dtx_cnt;
  int pucch_consecutive_dtx_cnt;
  int ul_failure;
610
  struct CSI_Report CSI_report[MAX_CSI_REPORTS];
Robert Schmidt's avatar
Robert Schmidt committed
611 612
  bool SR;

613
  /// information about every HARQ process
614
  NR_UE_harq_t harq_processes[NR_MAX_NB_HARQ_PROCESSES];
615 616 617 618 619 620
  /// HARQ processes that are free
  NR_list_t available_dl_harq;
  /// HARQ processes that await feedback
  NR_list_t feedback_dl_harq;
  /// HARQ processes that await retransmission
  NR_list_t retrans_dl_harq;
621
  /// information about every UL HARQ process
622
  NR_UE_ul_harq_t ul_harq_processes[NR_MAX_NB_HARQ_PROCESSES];
623 624 625 626 627 628
  /// UL HARQ processes that are free
  NR_list_t available_ul_harq;
  /// UL HARQ processes that await feedback
  NR_list_t feedback_ul_harq;
  /// UL HARQ processes that await retransmission
  NR_list_t retrans_ul_harq;
629
  NR_UE_mac_ce_ctrl_t UE_mac_ce_ctrl;// MAC CE related information
630 631
} NR_UE_sched_ctrl_t;

632
typedef struct {
Laurent's avatar
Laurent committed
633 634
  boolean_t fiveG_connected;
  uicc_t *uicc;
laurent's avatar
laurent committed
635
} NRUEcontext_t;
636

Laurent's avatar
Laurent committed
637
typedef struct {
638 639 640 641 642
  uint64_t lc_bytes_tx[64];
  uint64_t lc_bytes_rx[64];
  uint64_t dlsch_rounds[8];
  uint64_t dlsch_errors;
  uint64_t dlsch_total_bytes;
643
  int dlsch_current_bytes;
644 645 646 647 648
  uint64_t ulsch_rounds[8];
  uint64_t ulsch_errors;
  uint32_t ulsch_DTX;
  uint64_t ulsch_total_bytes_scheduled;
  uint64_t ulsch_total_bytes_rx;
649
  int ulsch_current_bytes;
650
  uint32_t pucch0_DTX;
651 652
  int cumul_rsrp;
  uint8_t num_rsrp_meas;
653 654
} NR_mac_stats_t;

Robert Schmidt's avatar
Robert Schmidt committed
655

656
/*! \brief UE list used by gNB to order UEs/CC for scheduling*/
657
#define MAX_CSI_REPORTCONFIG 48
658 659
typedef struct {
  /// scheduling control info
660
  nr_csi_report_t csi_report_template[MAX_MOBILES_PER_GNB][MAX_CSI_REPORTCONFIG];
661
  NR_UE_sched_ctrl_t UE_sched_ctrl[MAX_MOBILES_PER_GNB];
662
  NR_mac_stats_t mac_stats[MAX_MOBILES_PER_GNB];
663
  NR_list_t list;
664
  int num_UEs;
665

666
  bool active[MAX_MOBILES_PER_GNB];
667
  rnti_t rnti[MAX_MOBILES_PER_GNB];
668
  NR_CellGroupConfig_t *CellGroup[MAX_MOBILES_PER_GNB];
669 670 671
  /// CCE indexing
  int Y[MAX_MOBILES_PER_GNB][3][160];
  int m[MAX_MOBILES_PER_GNB];
672 673
  // UE selected beam index
  uint8_t UE_beam_index[MAX_MOBILES_PER_GNB];
674
  bool Msg4_ACKed[MAX_MOBILES_PER_GNB];
675

676
} NR_UE_info_t;
677

678 679
typedef void (*nr_pp_impl_dl)(module_id_t mod_id,
                              frame_t frame,
680
                              sub_frame_t slot);
681
typedef bool (*nr_pp_impl_ul)(module_id_t mod_id,
682
                              frame_t frame,
683
                              sub_frame_t slot);
684

685
/*! \brief top level eNB MAC structure */
686 687 688 689 690 691 692
typedef struct gNB_MAC_INST_s {
  /// Ethernet parameters for northbound midhaul interface
  eth_params_t                    eth_params_n;
  /// Ethernet parameters for fronthaul interface
  eth_params_t                    eth_params_s;
  /// Module
  module_id_t                     Mod_id;
693 694
  /// timing advance group
  NR_TAG_t                        *tag;
695 696
  /// Pointer to IF module instance for PHY
  NR_IF_Module_t                  *if_inst;
697
  pthread_t                       stats_thread;
698 699
  /// Pusch target SNR
  int                             pusch_target_snrx10;
700 701
  /// Pucch target SNR
  int                             pucch_target_snrx10;
702 703 704 705
  /// PUCCH Failure threshold (compared to consecutive PUCCH DTX)
  int                             pucch_failure_thres;
  /// PUSCH Failure threshold (compared to consecutive PUSCH DTX)
  int                             pusch_failure_thres;
706 707
  /// Subcarrier Offset
  int                             ssb_SubcarrierOffset;
francescomani's avatar
francescomani committed
708 709
  /// SIB1 Time domain allocation
  int                             sib1_tda;
710
  /// Common cell resources
711 712 713
  NR_COMMON_channels_t common_channels[NFAPI_CC_MAX];
  /// current PDU index (BCH,DLSCH)
  uint16_t pdu_index[NFAPI_CC_MAX];
714 715
  int num_ulprbbl;
  int ulprbbl[275];
716
  /// NFAPI Config Request Structure
717
  nfapi_nr_config_request_scf_t     config[NFAPI_CC_MAX];
718
  /// NFAPI DL Config Request Structure
cig's avatar
cig committed
719
  nfapi_nr_dl_tti_request_t         DL_req[NFAPI_CC_MAX];
720 721 722
  /// a PDCCH PDU groups DCIs per BWP and CORESET. The following structure
  /// keeps pointers to PDCCH PDUs within DL_req so that we can easily track
  /// PDCCH PDUs per CC/BWP/CORESET
723
  nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_idx[NFAPI_CC_MAX][MAX_NUM_CORESET];
724 725
  /// NFAPI UL TTI Request Structure, simple pointer into structure
  /// UL_tti_req_ahead for current frame/slot
726
  nfapi_nr_ul_tti_request_t        *UL_tti_req[NFAPI_CC_MAX];
727 728 729
  /// NFAPI UL TTI Request Structure for future TTIs, dynamically allocated
  /// because length depends on number of slots
  nfapi_nr_ul_tti_request_t        *UL_tti_req_ahead[NFAPI_CC_MAX];
730
  /// NFAPI HI/DCI0 Config Request Structure
731
  nfapi_nr_ul_dci_request_t         UL_dci_req[NFAPI_CC_MAX];
732
  /// NFAPI DL PDU structure
cig's avatar
cig committed
733
  nfapi_nr_tx_data_request_t        TX_req[NFAPI_CC_MAX];
734
  int pdcch_cand[MAX_NUM_CORESET];
735
  NR_UE_info_t UE_info;
736

737 738
  /// UL handle
  uint32_t ul_handle;
yaojie's avatar
yaojie committed
739
  //UE_info_t UE_info;
740

741
  // MAC function execution peformance profiler
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
  /// processing time of eNB scheduler
  time_stats_t eNB_scheduler;
  /// processing time of eNB scheduler for SI
  time_stats_t schedule_si;
  /// processing time of eNB scheduler for Random access
  time_stats_t schedule_ra;
  /// processing time of eNB ULSCH scheduler
  time_stats_t schedule_ulsch;
  /// processing time of eNB DCI generation
  time_stats_t fill_DLSCH_dci;
  /// processing time of eNB MAC preprocessor
  time_stats_t schedule_dlsch_preprocessor;
  /// processing time of eNB DLSCH scheduler
  time_stats_t schedule_dlsch;  // include rlc_data_req + MAC header + preprocessor
  /// processing time of eNB MCH scheduler
  time_stats_t schedule_mch;
  /// processing time of eNB ULSCH reception
  time_stats_t rx_ulsch_sdu;  // include rlc_data_ind
  /// processing time of eNB PCH scheduler
  time_stats_t schedule_pch;
762
  /// list of allocated beams per period
763
  int16_t *tdd_beam_association;
764 765 766 767 768 769 770 771 772 773 774 775 776

  /// bitmap of DLSCH slots, can hold up to 160 slots
  uint64_t dlsch_slot_bitmap[3];
  /// Lookup for preferred time domain allocation for BWP, in DL, slots
  /// dynamically allocated
  int *preferred_dl_tda[MAX_NUM_BWP];
  /// bitmap of ULSCH slots, can hold up to 160 slots
  uint64_t ulsch_slot_bitmap[3];
  /// Lookup for preferred time domain allocation for UL BWP, dynamically
  /// allocated. The index refers to the DL slot, and the indicated TDA's k2
  /// points to the right UL slot
  int *preferred_ul_tda[MAX_NUM_BWP];

777
  /// maximum number of slots before a UE will be scheduled ULSCH automatically
778
  uint32_t ulsch_max_frame_inactivity;
779

780 781
  /// DL preprocessor for differentiated scheduling
  nr_pp_impl_dl pre_processor_dl;
782 783
  /// UL preprocessor for differentiated scheduling
  nr_pp_impl_ul pre_processor_ul;
784 785

  NR_UE_sched_ctrl_t *sched_ctrlCommon;
786 787
  uint16_t cset0_bwp_start;
  uint16_t cset0_bwp_size;
788
  NR_Type0_PDCCH_CSS_config_t type0_PDCCH_CSS_config[64];
789

790
  bool first_MIB;
Robert Schmidt's avatar
Robert Schmidt committed
791 792 793 794
  double dl_bler_target_upper;
  double dl_bler_target_lower;
  double dl_rd2_bler_threshold;
  uint8_t dl_max_mcs;
795 796
} gNB_MAC_INST;

797
#endif /*__LAYER2_NR_MAC_GNB_H__ */