mac_proto.h 14.9 KB
Newer Older
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * 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
 */

/*! \file mac_proto.h
 * \brief MAC functions prototypes for gNB
 * \author Navid Nikaein and Raymond Knopp, WEI-TAI CHEN
 * \date 2010 - 2014, 2018
 * \email navid.nikaein@eurecom.fr, kroempa@gmail.com
 * \version 1.0
 * \company Eurecom, NTUST
 */
30 31 32 33

#ifndef __LAYER2_NR_MAC_PROTO_H__
#define __LAYER2_NR_MAC_PROTO_H__

34
#include "PHY/defs_gNB.h"
35 36

#include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h"
37
#include "NR_TAG-Id.h"
38

39 40
#define MAX_ACK_BITS 2 //only format 0 is available for now

41 42
void set_cset_offset(uint16_t);

43 44
void mac_top_init_gNB(void);

45
void config_common(int Mod_idP,
46
                   int pdsch_AntennaPorts,
47 48
		   NR_ServingCellConfigCommon_t *scc
		   );
49

50
int rrc_mac_config_req_gNB(module_id_t Mod_idP, 
51
			   int ssb_SubcarrierOffset,
52
                           int pdsch_AntennaPorts,
53 54
                           int pusch_tgt_snrx10,
                           int pucch_tgt_snrx10,
55 56 57 58
                           NR_ServingCellConfigCommon_t *scc,
			   int nsa_flag,
			   uint32_t rnti,
			   NR_CellGroupConfig_t *secondaryCellGroup
59
                           );
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
60

61 62 63 64
void clear_nr_nfapi_information(gNB_MAC_INST * gNB, 
                                int CC_idP,
                                frame_t frameP, 
                                sub_frame_t subframeP);
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
65

66 67
void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
			       frame_t frame_rxP, sub_frame_t slot_rxP);
68

69 70
int nr_generate_dlsch_pdu(module_id_t Mod_idP,
                          unsigned char *sdus_payload,
71 72 73 74 75 76 77 78
                          unsigned char *mac_pdu,
                          unsigned char num_sdus,
                          unsigned short *sdu_lengths,
                          unsigned char *sdu_lcids,
                          unsigned char drx_cmd,
                          unsigned char *ue_cont_res_id,
                          unsigned short post_padding);

79 80 81 82
void nr_schedule_ue_spec(module_id_t module_id,
                         frame_t frame,
                         sub_frame_t slot,
                         int num_slots_per_tdd);
83

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
84 85
void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP);

86 87 88 89 90 91 92 93 94 95 96 97
/////// Random Access MAC-PHY interface functions and primitives ///////

void nr_schedule_RA(module_id_t module_idP, frame_t frameP, sub_frame_t slotP);

/* \brief Function to indicate a received preamble on PRACH.  It initiates the RA procedure.
@param module_idP Instance ID of gNB
@param preamble_index index of the received RA request
@param slotP Slot number on which to act
@param timing_offset Offset in samples of the received PRACH w.r.t. eNB timing. This is used to
@param rnti RA rnti corresponding to this PRACH preamble
@param rach_resource type (0=non BL/CE,1 CE level 0,2 CE level 1, 3 CE level 2,4 CE level 3)
*/
98 99
void nr_initiate_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t slotP,
                         uint16_t preamble_index, uint8_t freq_index, uint8_t symbol, int16_t timing_offset);
100 101 102 103 104

void nr_clear_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP);

int nr_allocate_CCEs(int module_idP, int CC_idP, frame_t frameP, sub_frame_t slotP, int test_only);

105
void nr_get_Msg3alloc(NR_ServingCellConfigCommon_t *scc,
106
                      NR_BWP_Uplink_t *ubwp,
107
                      sub_frame_t current_subframe,
108 109
                      frame_t current_frame,
                      NR_RA_t *ra);
110

cig's avatar
cig committed
111 112 113
/* \brief Function in gNB to fill RAR pdu when requested by PHY.
@param ra Instance of RA resources of gNB
@param dlsch_buffer Pointer to RAR input buffer
114 115
@param N_RB_UL Number of UL resource blocks
*/
116 117
void nr_fill_rar(uint8_t Mod_idP,
                 NR_RA_t * ra,
cig's avatar
cig committed
118
                 uint8_t * dlsch_buffer,
119
                 nfapi_nr_pusch_pdu_t  *pusch_pdu);
120 121


122 123
void schedule_nr_prach(module_id_t module_idP, frame_t frameP, sub_frame_t slotP);

124 125 126 127
uint16_t nr_mac_compute_RIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs);

/////// Phy test scheduler ///////

Raymond Knopp's avatar
Raymond Knopp committed
128 129 130 131
void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
                                   frame_t       frameP,
                                   sub_frame_t   subframeP);

132 133 134
void nr_fill_nfapi_dl_pdu(int Mod_id,
                          int UE_id,
                          int bwp_id,
135 136
                          NR_SearchSpace_t *ss,
                          NR_ControlResourceSet_t *coreset,
137 138 139 140 141 142 143 144 145 146 147 148 149 150
                          nfapi_nr_dl_tti_request_body_t *dl_req,
                          NR_sched_pucch *pucch_sched,
                          int nrOfLayers,
                          uint8_t mcs,
                          uint16_t rbSize,
                          uint16_t rbStart,
                          uint8_t numDmrsCdmGrpsNoData,
                          nfapi_nr_dmrs_type_e dmrsConfigType,
                          uint8_t table_idx,
                          uint16_t R,
                          uint8_t Qm,
                          uint32_t tbs,
                          int time_domain_assignment,
                          int StartSymbolIndex,
151 152 153
                          int NrOfSymbols,
                          uint8_t aggregation_level,
                          int CCEIndex);
Raymond Knopp's avatar
Raymond Knopp committed
154

155 156 157 158 159 160 161
int configure_fapi_dl_pdu_phytest(int Mod_id,
                                  nfapi_nr_dl_tti_request_body_t *dl_req,
                                  NR_sched_pucch *pucch_sched,
                                  uint8_t *mcsIndex,
                                  uint16_t *rbSize,
                                  uint16_t *rbStart);

162 163 164 165 166
void config_uldci(NR_BWP_Uplink_t *ubwp,
                  nfapi_nr_pusch_pdu_t *pusch_pdu,
                  nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15,
                  dci_pdu_rel15_t *dci_pdu_rel15,
                  int *dci_formats, int *rnti_types,
167
                  int time_domain_assignment, uint8_t tpc,
168
                  int n_ubwp, int bwp_id);
169

cig's avatar
cig committed
170 171 172 173 174
void configure_fapi_dl_Tx(module_id_t Mod_idP,
                          frame_t       frameP,
                          sub_frame_t   slotP,
                          nfapi_nr_dl_tti_request_body_t *dl_req,
                          nfapi_nr_pdu_t *tx_req,
175 176 177
                          int tbs_bytes,
                          int16_t pdu_index);

178 179
void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
                                   frame_t       frameP,
180
                                   sub_frame_t   slotP,
181
                                   NR_sched_pucch *pucch_sched,
Raymond Knopp's avatar
Raymond Knopp committed
182
                                   nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_config);
183

184
void nr_schedule_pusch(int Mod_idP,
185
                       int UE_id,
186 187
                       int num_slots_per_tdd,
                       int ul_slots,
188 189
                       frame_t       frameP,
                       sub_frame_t   slotP);
190

191 192 193 194 195 196
void nr_schedule_pucch(int Mod_idP,
                       int UE_id,
                       int nr_ulmix_slots,
                       frame_t frameP,
                       sub_frame_t slotP);

197 198 199 200 201
void nr_update_pucch_scheduling(int Mod_idP,
                                int UE_id,
                                frame_t frameP,
                                sub_frame_t slotP,
                                int slots_per_tdd,
Francesco Mani's avatar
Francesco Mani committed
202
                                int *pucch_id);
Francesco Mani's avatar
Francesco Mani committed
203 204 205 206 207

void get_pdsch_to_harq_feedback(int Mod_idP,
                                int UE_id,
                                NR_SearchSpace__searchSpaceType_PR ss_type,
                                uint8_t *pdsch_to_harq_feedback);
208
  
Raymond Knopp's avatar
Raymond Knopp committed
209
void nr_configure_css_dci_initial(nfapi_nr_dl_tti_pdcch_pdu_rel15_t* pdcch_pdu,
210 211 212 213 214 215 216 217 218 219
                                  nr_scs_e scs_common,
                                  nr_scs_e pdcch_scs,
                                  nr_frequency_range_e freq_range,
                                  uint8_t rmsi_pdcch_config,
                                  uint8_t ssb_idx,
                                  uint8_t k_ssb,
                                  uint16_t sfn_ssb,
                                  uint8_t n_ssb,
                                  uint16_t nb_slots_per_frame,
                                  uint16_t N_RB);
220
/*
221
int nr_is_dci_opportunity(nfapi_nr_search_space_t search_space,
222 223 224
                          nfapi_nr_coreset_t coreset,
                          uint16_t frame,
                          uint16_t slot,
225
                          nfapi_nr_config_request_scf_t cfg);
226
*/
Raymond Knopp's avatar
Raymond Knopp committed
227

228 229
void nr_configure_pucch(nfapi_nr_pucch_pdu_t* pucch_pdu,
			NR_ServingCellConfigCommon_t *scc,
230 231 232 233 234
			NR_BWP_Uplink_t *bwp,
                        uint8_t pucch_resource,
                        uint16_t O_uci,
                        uint16_t O_ack,
                        uint8_t SR_flag);
Francesco Mani's avatar
Francesco Mani committed
235

236 237 238 239
void find_search_space(int ss_type,
                       NR_BWP_Downlink_t *bwp,
                       NR_SearchSpace_t *ss);

240 241 242 243 244 245 246 247 248
void nr_configure_pdcch(gNB_MAC_INST *nr_mac,
                        nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu,
                        uint16_t rnti,
                        NR_SearchSpace_t *ss,
                        NR_ControlResourceSet_t *coreset,
                        NR_ServingCellConfigCommon_t *scc,
                        NR_BWP_Downlink_t *bwp,
                        uint8_t aggregation_level,
                        int CCEIndex);
Raymond Knopp's avatar
Raymond Knopp committed
249

250 251
void fill_dci_pdu_rel15(NR_ServingCellConfigCommon_t *scc,
                        NR_CellGroupConfig_t *secondaryCellGroup,
252
                        nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15,
cig's avatar
cig committed
253 254
                        dci_pdu_rel15_t *dci_pdu_rel15,
                        int *dci_formats,
Francesco Mani's avatar
Francesco Mani committed
255
                        int *rnti_types,
256
                        int N_RB,
Francesco Mani's avatar
Francesco Mani committed
257 258 259 260 261 262
                        int bwp_id);

void prepare_dci(NR_CellGroupConfig_t *secondaryCellGroup,
                 dci_pdu_rel15_t *dci_pdu_rel15,
                 nr_dci_format_t format,
                 int bwp_id);
263

264 265 266 267 268 269 270 271 272 273
/* find coreset within the search space */
NR_ControlResourceSet_t *get_coreset(NR_BWP_Downlink_t *bwp,
                                     NR_SearchSpace_t *ss,
                                     int ss_type);

/* find a search space within a BWP */
NR_SearchSpace_t *get_searchspace(
    NR_BWP_Downlink_t *bwp,
    NR_SearchSpace__searchSpaceType_PR target_ss);

274 275 276 277
void find_aggregation_candidates(uint8_t *aggregation_level,
                                 uint8_t *nr_of_candidates,
                                 NR_SearchSpace_t *ss);

278 279
uint8_t nr_get_tpc(int target, uint8_t cqi, int incr);

280
int get_spf(nfapi_nr_config_request_scf_t *cfg);
281

282
int to_absslot(nfapi_nr_config_request_scf_t *cfg,int frame,int slot);
283

Raymond Knopp's avatar
Raymond Knopp committed
284
void nr_get_tbs_dl(nfapi_nr_dl_tti_pdsch_pdu *pdsch_pdu,
285
		   int x_overhead,
286
                   uint8_t numdmrscdmgroupnodata,
287
                   uint8_t tb_scaling);
Raymond Knopp's avatar
Raymond Knopp committed
288 289 290 291 292 293 294
/** \brief Computes Q based on I_MCS PDSCH and table_idx for downlink. Implements MCS Tables from 38.214. */
uint8_t nr_get_Qm_dl(uint8_t Imcs, uint8_t table_idx);
uint32_t nr_get_code_rate_dl(uint8_t Imcs, uint8_t table_idx);

/** \brief Computes Q based on I_MCS PDSCH and table_idx for uplink. Implements MCS Tables from 38.214. */
uint8_t nr_get_Qm_ul(uint8_t Imcs, uint8_t table_idx);
uint32_t nr_get_code_rate_ul(uint8_t Imcs, uint8_t table_idx);
295 296 297 298 299

int NRRIV2BW(int locationAndBandwidth,int N_RB);

int NRRIV2PRBOFFSET(int locationAndBandwidth,int N_RB);

cig's avatar
cig committed
300
void dump_nr_ue_list(NR_UE_list_t *listP, int ul_flag);
301

cig's avatar
cig committed
302
int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP);
303

cig's avatar
cig committed
304
int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP);
305

Cedric Roux's avatar
Cedric Roux committed
306 307
void mac_remove_nr_ue(module_id_t mod_id, rnti_t rnti);

308
int allocate_nr_CCEs(gNB_MAC_INST *nr_mac,
309 310
                     NR_BWP_Downlink_t *bwp,
                     NR_ControlResourceSet_t *coreset,
cig's avatar
cig committed
311 312 313
                     int aggregation,
                     int search_space, // 0 common, 1 ue-specific
                     int UE_id,
314
                     int m);
315

cig's avatar
cig committed
316 317 318 319 320 321 322
int get_dlscs(nfapi_nr_config_request_t *cfg);

int get_ulscs(nfapi_nr_config_request_t *cfg);

int get_symbolsperslot(nfapi_nr_config_request_t *cfg);

int32_t get_nr_uldl_offset(int nr_bandP);
323

324
void config_nr_mib(int Mod_idP, 
325 326 327 328 329 330 331 332
                   int CC_idP,
                   int p_gNBP,
                   int subCarrierSpacingCommon,
                   uint32_t ssb_SubcarrierOffset,
                   int dmrs_TypeA_Position,
                   uint32_t pdcch_ConfigSIB1,
                   int cellBarred,
                   int intraFreqReselection);
333

334

335 336 337 338 339
void nr_generate_Msg2(module_id_t module_idP,
                      int CC_id,
                      frame_t frameP,
                      sub_frame_t slotP);

340 341
void nr_schedule_reception_msg3(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t slotP);

342 343 344 345
void schedule_fapi_ul_pdu(int Mod_idP,
                          frame_t frameP,
                          sub_frame_t slotP,
                          int num_slots_per_tdd,
346
                          int ul_slots,
347
                          int time_domain_assignment);
348

349 350
void nr_process_mac_pdu(
    module_id_t module_idP,
351
    rnti_t rnti,
352 353 354 355
    uint8_t CC_id,
    frame_t frameP,
    uint8_t *pduP,
    uint16_t mac_pdu_len);
356

357 358
int binomial(int n, int k);

359 360
bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot);

361

362 363 364 365 366 367 368 369 370 371
/* \brief Function to indicate a received SDU on ULSCH.
@param Mod_id Instance ID of gNB
@param CC_id Component carrier index
@param rnti RNTI of UE transmitting the SDU
@param sdu Pointer to received SDU
@param sdu_len Length of SDU
@param timing_advance timing advance adjustment after this pdu
@param ul_cqi Uplink CQI estimate after this pdu (SNR quantized to 8 bits, -64 ... 63.5 dB in .5dB steps)
*/
void nr_rx_sdu(const module_id_t gnb_mod_idP,
cig's avatar
cig committed
372 373 374 375 376 377
               const int CC_idP,
               const frame_t frameP,
               const sub_frame_t subframeP,
               const rnti_t rntiP,
               uint8_t * sduP,
               const uint16_t sdu_lenP,
378 379 380
               const uint16_t timing_advance,
               const uint8_t ul_cqi,
               const uint16_t rssi);
381

382
void handle_nr_ul_harq(uint16_t slot, NR_UE_sched_ctrl_t *sched_ctrl, NR_mac_stats_t *stats, nfapi_nr_crc_t crc_pdu);
383

384
void handle_nr_uci(NR_UL_IND_t *UL_info, NR_UE_sched_ctrl_t *sched_ctrl, NR_mac_stats_t *stats, int target_snrx10);
385
#endif /*__LAYER2_NR_MAC_PROTO_H__*/