nr_mac_gNB.h 14.3 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

71
/* Defs */
72 73 74
#define MAX_NUM_BWP 2
#define MAX_NUM_CORESET 2
#define MAX_NUM_CCE 90
75 76
/*!\brief Maximum number of random access process */
#define NR_NB_RA_PROC_MAX 4
77
#define MAX_NUM_OF_SSB 64
78

cig's avatar
cig committed
79 80 81 82 83 84
typedef enum {
  RA_IDLE = 0,
  Msg2 = 1,
  WAIT_Msg3 = 2,
  Msg4 = 3,
  WAIT_Msg4_ACK = 4
Raymond Knopp's avatar
Raymond Knopp committed
85
} RA_gNB_state_t;
cig's avatar
cig committed
86

87 88 89 90 91
typedef struct NR_preamble_ue {
  uint8_t num_preambles;
  uint8_t *preamble_list;
} NR_preamble_ue_t;

92 93
/*! \brief gNB template for the Random access information */
typedef struct {
94
  /// Flag to indicate this process is active
Raymond Knopp's avatar
Raymond Knopp committed
95
  RA_gNB_state_t state;
96 97 98 99 100 101 102 103 104 105 106 107 108 109
  /// 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;
110 111
  /// Msg3 time domain allocation index
  uint8_t Msg3_tda_id;
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  /// 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;
  /// 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;
142 143
  /// Msg3 pusch pdu
  nfapi_nr_pusch_pdu_t pusch_pdu;
144 145 146 147 148 149
  /// TBS used for Msg4
  int msg4_TBsize;
  /// MCS used for Msg4
  int msg4_mcs;
  /// RA search space
  NR_SearchSpace_t *ra_ss;
150 151
  // Beam index
  uint8_t beam_id;
152 153 154 155 156 157
  /// secondaryCellGroup for UE in NSA that is to come
  NR_CellGroupConfig_t *secondaryCellGroup;
  /// 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
158 159
  /// CFRA flag
  bool cfra;
160
} NR_RA_t;
161

162
/*! \brief gNB common channels */
163
typedef struct {
Raymond Knopp's avatar
Raymond Knopp committed
164 165 166 167
  int physCellId;
  int p_gNB;
  int Ncp;
  int nr_band;
168
  lte_frame_type_t frame_type;
169
  uint64_t dl_CarrierFreq;
Raymond Knopp's avatar
Raymond Knopp committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  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;
  /// Outgoing RAR pdu for PHY
  RAR_PDU RAR_pdu;
  /// Template for RA computations
189
  NR_RA_t ra[NR_NB_RA_PROC_MAX];
Raymond Knopp's avatar
Raymond Knopp committed
190
  /// VRB map for common channels
191
  uint16_t vrb_map[275];
Raymond Knopp's avatar
Raymond Knopp committed
192
  /// VRB map for common channels and retransmissions by PHICH
193
  uint16_t vrb_map_UL[275];
Raymond Knopp's avatar
Raymond Knopp committed
194 195
  /// number of subframe allocation pattern available for MBSFN sync area
  uint8_t num_sf_allocation_pattern;
196 197 198 199 200 201 202 203 204 205
  ///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];
206 207
} NR_COMMON_channels_t;

208 209 210

// SP ZP CSI-RS Resource Set Activation/Deactivation MAC CE
typedef struct sp_zp_csirs {
211 212 213 214 215
  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
216 217 218 219 220
} 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 {
221 222 223 224 225 226 227 228 229
  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 ];
230 231 232
} csi_rs_im_t;

typedef struct pdcchStateInd {
233 234 235 236
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t coresetId;
  uint8_t tciStateId;
237 238 239
} pdcchStateInd_t;

typedef struct SPCSIReportingpucch {
240 241 242 243
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  bool s0tos3_actDeact[4];
244 245 246 247
} SPCSIReportingpucch_t;

#define MAX_APERIODIC_TRIGGER_STATES 128 //38.331                               
typedef struct aperiodicCSI_triggerStateSelection {
248 249 250 251 252
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  uint8_t highestTriggerStateSelected;
  bool triggerStateSelection[MAX_APERIODIC_TRIGGER_STATES];
253 254 255 256
} aperiodicCSI_triggerStateSelection_t;

#define MAX_TCI_STATES 128 //38.331                                             
typedef struct pdschTciStatesActDeact {
257 258 259 260 261
  bool is_scheduled;
  uint8_t servingCellId;
  uint8_t bwpId;
  uint8_t highestTciStateActivated;
  bool tciStateActDeact[MAX_TCI_STATES];
262 263 264
} pdschTciStatesActDeact_t;

typedef struct UE_info {
265 266 267 268 269 270
  sp_zp_csirs_t sp_zp_csi_rs;
  csi_rs_im_t csi_im;
  pdcchStateInd_t pdcch_state_ind;
  SPCSIReportingpucch_t SP_CSI_reporting_pucch;
  aperiodicCSI_triggerStateSelection_t aperi_CSI_trigger;
  pdschTciStatesActDeact_t pdsch_TCI_States_ActDeact;
271 272 273
} NR_UE_mac_ce_ctrl_t;


274 275 276
typedef struct NR_sched_pucch {
  int frame;
  int ul_slot;
277 278 279
  bool sr_flag;
  int csi_bits;
  bool simultaneous_harqcsi;
280
  uint8_t dai_c;
Francesco Mani's avatar
Francesco Mani committed
281 282
  uint8_t timing_indicator;
  uint8_t resource_indicator;
283 284
} NR_sched_pucch;

285 286 287 288 289 290 291
typedef struct NR_sched_pusch {
  int frame;
  int slot;
  bool active;
  nfapi_nr_pusch_pdu_t pusch_pdu;
} NR_sched_pusch;

292
typedef struct NR_UE_harq {
293
  uint8_t is_waiting;
294 295
  uint8_t ndi;
  uint8_t round;
296
  uint16_t feedback_slot;
297 298
} NR_UE_harq_t;

Robert Schmidt's avatar
Robert Schmidt committed
299 300 301 302 303 304 305 306
typedef struct NR_UE_old_sched {
  uint16_t rbSize;
  int time_domain_allocation;
  uint8_t mcsTableIdx;
  uint8_t mcs;
  uint8_t numDmrsCdmGrpsNoData;
} NR_UE_ret_info_t;

307 308 309 310 311 312 313 314 315 316 317 318 319
typedef enum {
  INACTIVE = 0,
  ACTIVE_NOT_SCHED,
  ACTIVE_SCHED
} NR_UL_harq_states_t;

typedef struct NR_UE_ul_harq {
  uint8_t ndi;
  uint8_t round;
  uint16_t last_tx_slot;
  NR_UL_harq_states_t state;
} NR_UE_ul_harq_t;

320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

typedef struct {
  uint8_t nb_ssbri_cri;
  uint8_t cri_ssbri_bitlen;
  uint8_t rsrp_bitlen;
  uint8_t diff_rsrp_bitlen;
}CRI_SSBRI_RSRP_bitlen_t;


#define MAX_CSI_RESOURCE_SET_IN_CSI_RESOURCE_CONFIG 16
typedef struct nr_csi_report {
  NR_CSI_ReportConfig__reportQuantity_PR reportQuantity_type;
  NR_CSI_ResourceConfig__csi_RS_ResourceSetList_PR CSI_Resource_type;
  uint8_t nb_of_nzp_csi_report;
  uint8_t nb_of_csi_ssb_report;
  CRI_SSBRI_RSRP_bitlen_t CSI_report_bitlen[MAX_CSI_RESOURCE_SET_IN_CSI_RESOURCE_CONFIG];
} nr_csi_report_t;


339
/*! \brief scheduling control information set through an API */
340
typedef struct {
341 342 343 344 345
  /// 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];

346 347
  /// the currently active BWP in DL
  NR_BWP_Downlink_t *active_bwp;
348
  NR_sched_pucch **sched_pucch;
349 350
  /// selected PUCCH index, if scheduled
  int pucch_sched_idx;
351
  int pucch_occ_idx;
352
  NR_sched_pusch *sched_pusch;
353 354 355

  /// CCE index and aggregation, should be coherent with cce_list
  NR_SearchSpace_t *search_space;
356 357 358
  NR_ControlResourceSet_t *coreset;
  int cce_index;
  uint8_t aggregation_level;
359

360 361 362 363
  /// RB allocation within active BWP
  uint16_t rbSize;
  uint16_t rbStart;

364 365 366
  // time-domain allocation for scheduled RBs
  int time_domain_allocation;

367 368 369 370 371
  /// MCS-related infos
  uint8_t mcsTableIdx;
  uint8_t mcs;
  uint8_t numDmrsCdmGrpsNoData;

Robert Schmidt's avatar
Robert Schmidt committed
372 373 374
  /// Retransmission-related information
  NR_UE_ret_info_t retInfo[NR_MAX_NB_HARQ_PROCESSES];

375
  uint16_t ta_frame;
376
  int16_t ta_update;
377
  bool ta_apply;
378 379
  uint8_t tpc0;
  uint8_t tpc1;
380
  uint16_t ul_rssi;
381
  uint8_t current_harq_pid;
382
  NR_UE_harq_t harq_processes[NR_MAX_NB_HARQ_PROCESSES];
383
  NR_UE_ul_harq_t ul_harq_processes[NR_MAX_NB_HARQ_PROCESSES];
384 385
  int dummy;
  NR_UE_mac_ce_ctrl_t UE_mac_ce_ctrl;// MAC CE related information
386 387
} NR_UE_sched_ctrl_t;

388 389 390 391 392 393 394 395 396 397 398 399 400
typedef struct {

  int lc_bytes_tx[64];
  int lc_bytes_rx[64];
  int dlsch_rounds[8];
  int dlsch_errors;
  int dlsch_total_bytes;
  int ulsch_rounds[8];
  int ulsch_errors;
  int ulsch_total_bytes_scheduled;
  int ulsch_total_bytes_rx;
} NR_mac_stats_t;

Robert Schmidt's avatar
Robert Schmidt committed
401 402 403 404 405 406 407 408

/*! \brief UNR_E_list_t is a "list" of users within UE_info_t. Especial useful in
 * the scheduler and to keep "classes" of users. */
typedef struct {
  int head;
  int next[MAX_MOBILES_PER_GNB];
} NR_UE_list_t;

409
/*! \brief UE list used by gNB to order UEs/CC for scheduling*/
410
#define MAX_CSI_REPORTCONFIG 48
411 412 413
typedef struct {
  DLSCH_PDU DLSCH_pdu[4][MAX_MOBILES_PER_GNB];
  /// scheduling control info
414
  nr_csi_report_t csi_report_template[MAX_MOBILES_PER_GNB][MAX_CSI_REPORTCONFIG];
415
  NR_UE_sched_ctrl_t UE_sched_ctrl[MAX_MOBILES_PER_GNB];
416
  NR_mac_stats_t mac_stats[MAX_MOBILES_PER_GNB];
Robert Schmidt's avatar
Robert Schmidt committed
417
  NR_UE_list_t list;
418
  int num_UEs;
419
  bool active[MAX_MOBILES_PER_GNB];
420 421
  rnti_t rnti[MAX_MOBILES_PER_GNB];
  NR_CellGroupConfig_t *secondaryCellGroup[MAX_MOBILES_PER_GNB];
422 423 424 425
  /// CCE indexing
  int Y[MAX_MOBILES_PER_GNB][3][160];
  int m[MAX_MOBILES_PER_GNB];
  int num_pdcch_cand[MAX_MOBILES_PER_GNB][MAX_NUM_CORESET];
426 427
  // UE selected beam index
  uint8_t UE_beam_index[MAX_MOBILES_PER_GNB];
428
} NR_UE_info_t;
429

430 431 432 433 434
typedef void (*nr_pp_impl_dl)(module_id_t mod_id,
                              frame_t frame,
                              sub_frame_t slot,
                              int num_slots_per_tdd);

435
/*! \brief top level eNB MAC structure */
436 437 438 439 440 441 442
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;
443 444
  /// timing advance group
  NR_TAG_t                        *tag;
445 446
  /// Pointer to IF module instance for PHY
  NR_IF_Module_t                  *if_inst;
447 448
  /// Pusch target SNR
  int                             pusch_target_snrx10;
449 450
  /// Pucch target SNR
  int                             pucch_target_snrx10;
451
  /// Common cell resources
452 453 454 455
  NR_COMMON_channels_t common_channels[NFAPI_CC_MAX];
  /// current PDU index (BCH,DLSCH)
  uint16_t pdu_index[NFAPI_CC_MAX];

456
  /// NFAPI Config Request Structure
457
  nfapi_nr_config_request_scf_t     config[NFAPI_CC_MAX];
458
  /// NFAPI DL Config Request Structure
cig's avatar
cig committed
459
  nfapi_nr_dl_tti_request_t         DL_req[NFAPI_CC_MAX];
460 461
  /// NFAPI UL TTI Request Structure (this is from the new SCF specs)
  nfapi_nr_ul_tti_request_t         UL_tti_req[NFAPI_CC_MAX];
462
  /// NFAPI HI/DCI0 Config Request Structure
463
  nfapi_nr_ul_dci_request_t         UL_dci_req[NFAPI_CC_MAX];
464
  /// NFAPI DL PDU structure
cig's avatar
cig committed
465
  nfapi_nr_tx_data_request_t        TX_req[NFAPI_CC_MAX];
466

467
  NR_UE_info_t UE_info;
468

469 470 471
  /// UL handle
  uint32_t ul_handle;

472
  // MAC function execution peformance profiler
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
  /// 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;
493 494
  /// CCE lists
  int cce_list[MAX_NUM_BWP][MAX_NUM_CORESET][MAX_NUM_CCE];
495 496
  /// current slot
  int current_slot;
497 498 499

  /// DL preprocessor for differentiated scheduling
  nr_pp_impl_dl pre_processor_dl;
500 501
} gNB_MAC_INST;

502
#endif /*__LAYER2_NR_MAC_GNB_H__ */