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

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

86 87
/*! \brief gNB template for the Random access information */
typedef struct {
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  /// Flag to indicate this process is active
  RA_state_t state;
  /// 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;
104 105
  /// Msg3 time domain allocation index
  uint8_t Msg3_tda_id;
106 107 108 109 110 111 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 142 143
  /// 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 MCS
  uint8_t msg3_mcs;
  /// 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;
  /// RA search space
  NR_SearchSpace_t *ra_ss;
144
} NR_RA_t;
145

146
/*! \brief gNB common channels */
147
typedef struct {
Raymond Knopp's avatar
Raymond Knopp committed
148 149 150 151
  int physCellId;
  int p_gNB;
  int Ncp;
  int nr_band;
152
  lte_frame_type_t frame_type;
153
  uint64_t dl_CarrierFreq;
Raymond Knopp's avatar
Raymond Knopp committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  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
173
  NR_RA_t ra[NR_NB_RA_PROC_MAX];
Raymond Knopp's avatar
Raymond Knopp committed
174 175 176 177 178 179
  /// VRB map for common channels
  uint8_t vrb_map[100];
  /// VRB map for common channels and retransmissions by PHICH
  uint8_t vrb_map_UL[100];
  /// number of subframe allocation pattern available for MBSFN sync area
  uint8_t num_sf_allocation_pattern;
180 181
} NR_COMMON_channels_t;

182 183 184 185 186
/*! \brief scheduling control information set through an API (not used)*/
typedef struct {
  int dummy;
} NR_UE_sched_ctrl_t;

187
/*! \brief UE list used by gNB to order UEs/CC for scheduling*/
188 189 190
typedef struct {
  DLSCH_PDU DLSCH_pdu[4][MAX_MOBILES_PER_GNB];
  /// scheduling control info
191
  UE_sched_ctrl_t UE_sched_ctrl[MAX_MOBILES_PER_GNB];
192 193 194 195 196 197 198 199 200 201 202
  int next[MAX_MOBILES_PER_GNB];
  int head;
  int next_ul[MAX_MOBILES_PER_GNB];
  int head_ul;
  int avail;
  int num_UEs;
  boolean_t active[MAX_MOBILES_PER_GNB];
  rnti_t rnti[MAX_MOBILES_PER_GNB];
  NR_CellGroupConfig_t *secondaryCellGroup[MAX_MOBILES_PER_GNB];
} NR_UE_list_t;

203 204 205 206 207 208 209 210 211 212
/*! \brief top level eNB MAC structure */
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;
  /// frame counter
  frame_t                         frame;
213
  /// slot counter
214 215 216
  int                             slot;
  /// timing advance group
  NR_TAG_t                        *tag;
217 218
  /// Pointer to IF module instance for PHY
  NR_IF_Module_t                  *if_inst;
219 220 221 222
  /// TA command
  int                             ta_command;
  /// MAC CE flag indicating TA length
  int                             ta_len;
223
  /// Common cell resources
224 225 226 227
  NR_COMMON_channels_t common_channels[NFAPI_CC_MAX];
  /// current PDU index (BCH,DLSCH)
  uint16_t pdu_index[NFAPI_CC_MAX];

228
  /// NFAPI Config Request Structure
229
  nfapi_nr_config_request_scf_t     config[NFAPI_CC_MAX];
230
  /// NFAPI DL Config Request Structure
cig's avatar
cig committed
231
  nfapi_nr_dl_tti_request_t         DL_req[NFAPI_CC_MAX];
232 233
  /// NFAPI UL TTI Request Structure (this is from the new SCF specs)
  nfapi_nr_ul_tti_request_t         UL_tti_req[NFAPI_CC_MAX];
234
  /// NFAPI HI/DCI0 Config Request Structure
235
  nfapi_nr_ul_dci_request_t         UL_dci_req[NFAPI_CC_MAX];
236
  /// NFAPI DL PDU structure
cig's avatar
cig committed
237
  nfapi_nr_tx_data_request_t        TX_req[NFAPI_CC_MAX];
238

239
  NR_UE_list_t UE_list;
240

241 242 243
  /// UL handle
  uint32_t ul_handle;

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    // MAC function execution peformance profiler
  /// 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;
265 266
  /// CCE lists
  int cce_list[MAX_NUM_BWP][MAX_NUM_CORESET][MAX_NUM_CCE];
267 268
} gNB_MAC_INST;

269 270
typedef struct {

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
  uint8_t format_indicator; //1 bit
  uint16_t frequency_domain_assignment; //up to 16 bits
  uint8_t time_domain_assignment; // 4 bits
  uint8_t frequency_hopping_flag; //1 bit

  uint8_t ra_preamble_index; //6 bits
  uint8_t ss_pbch_index; //6 bits
  uint8_t prach_mask_index; //4 bits

  uint8_t vrb_to_prb_mapping; //0 or 1 bit
  uint8_t mcs; //5 bits
  uint8_t ndi; //1 bit
  uint8_t rv; //2 bits
  uint8_t harq_pid; //4 bits
  uint8_t dai; //0, 2 or 4 bits
  uint8_t dai1; //1 or 2 bits
  uint8_t dai2; //0 or 2 bits
  uint8_t tpc; //2 bits
  uint8_t pucch_resource_indicator; //3 bits
  uint8_t pdsch_to_harq_feedback_timing_indicator; //0, 1, 2 or 3 bits

  uint8_t short_messages_indicator; //2 bits
  uint8_t short_messages; //8 bits
  uint8_t tb_scaling; //2 bits

  uint8_t carrier_indicator; //0 or 3 bits
  uint8_t bwp_indicator; //0, 1 or 2 bits
  uint8_t prb_bundling_size_indicator; //0 or 1 bits
  uint8_t rate_matching_indicator; //0, 1 or 2 bits
  uint8_t zp_csi_rs_trigger; //0, 1 or 2 bits
  uint8_t transmission_configuration_indication; //0 or 3 bits
  uint8_t srs_request; //2 bits
  uint8_t cbgti; //CBG Transmission Information: 0, 2, 4, 6 or 8 bits
  uint8_t cbgfi; //CBG Flushing Out Information: 0 or 1 bit
  uint8_t dmrs_sequence_initialization; //0 or 1 bit

  uint8_t srs_resource_indicator;
  uint8_t precoding_information;
  uint8_t csi_request;
  uint8_t ptrs_dmrs_association;
  uint8_t beta_offset_indicator; //0 or 2 bits

  uint8_t slot_format_indicator_count;
  uint8_t *slot_format_indicators;

  uint8_t pre_emption_indication_count;
  uint16_t *pre_emption_indications; //14 bit

  uint8_t block_number_count;
  uint8_t *block_numbers;

  uint8_t ul_sul_indicator; //0 or 1 bit
  uint8_t antenna_ports;

  uint16_t reserved; //1_0/C-RNTI:10 bits, 1_0/P-RNTI: 6 bits, 1_0/SI-&RA-RNTI: 16 bits
  uint16_t padding;
327 328 329

} dci_pdu_rel15_t;

330
#endif /*__LAYER2_NR_MAC_GNB_H__ */