mac_proto.h 18.4 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 "LAYER2/NR_MAC_gNB/nr_mac_gNB.h"
35
#include "NR_TAG-Id.h"
36

37 38
void set_cset_offset(uint16_t);

39 40
void mac_top_init_gNB(void);

41
void config_common(int Mod_idP,
42
                   int ssb_SubcarrierOffset,
43
                   int pdsch_AntennaPorts,
44
                   int pusch_AntennaPorts,
45 46
		   NR_ServingCellConfigCommon_t *scc
		   );
47

48 49
int rrc_mac_config_req_gNB(module_id_t Mod_idP,
                           int ssb_SubcarrierOffset,
50
                           int pdsch_AntennaPorts,
51
                           int pusch_AntennaPorts,
francescomani's avatar
francescomani committed
52
                           int sib1_tda,
53
                           NR_ServingCellConfigCommon_t *scc,
54
                           NR_BCCH_BCH_Message_t *mib,
rmagueta's avatar
rmagueta committed
55
		                       int add_ue,
56
			                     uint32_t rnti,
rmagueta's avatar
rmagueta committed
57
                           NR_CellGroupConfig_t *CellGroup);
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
58

59 60 61 62
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
63

64 65
void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
			       frame_t frame_rxP, sub_frame_t slot_rxP);
66

67 68 69
/* \brief main DL scheduler function. Calls a preprocessor to decide on
 * resource allocation, then "post-processes" resource allocation (nFAPI
 * messages, statistics, HARQ handling, CEs, ... */
70 71
void nr_schedule_ue_spec(module_id_t module_id,
                         frame_t frame,
72
                         sub_frame_t slot);
73

74 75 76 77 78 79
uint32_t schedule_control_sib1(module_id_t module_id,
                               int CC_id,
                               NR_Type0_PDCCH_CSS_config_t *type0_PDCCH_CSS_config,
                               int time_domain_allocation,
                               int startSymbolIndex,
                               int nrOfSymbols,
80
                               uint16_t dlDmrsSymbPos,
81 82
                               uint8_t candidate_idx,
                               int num_total_bytes);
83

84 85
/* \brief default FR1 DL preprocessor init routine, returns preprocessor to call */
nr_pp_impl_dl nr_init_fr1_dlsch_preprocessor(module_id_t module_id, int CC_id);
rmagueta's avatar
rmagueta committed
86

87
void schedule_nr_sib1(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP);
88

Robert Schmidt's avatar
Robert Schmidt committed
89
void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP);
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
90

91 92 93 94
/* \brief main UL scheduler function. Calls a preprocessor to decide on
 * resource allocation, then "post-processes" resource allocation (nFAPI
 * messages, statistics, HARQ handling, ... */
void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot);
95

96 97
/* \brief default FR1 UL preprocessor init routine, returns preprocessor to call */
nr_pp_impl_ul nr_init_fr1_ulsch_preprocessor(module_id_t module_id, int CC_id);
98

99 100 101 102 103 104 105 106 107 108 109 110
/////// 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)
*/
111 112
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);
113

114
void nr_clear_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP, NR_RA_t *ra);
115 116 117

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

118 119 120
void nr_get_Msg3alloc(module_id_t module_id,
                      int CC_id,
                      NR_ServingCellConfigCommon_t *scc,
121
                      NR_BWP_Uplink_t *ubwp,
122
                      sub_frame_t current_subframe,
123
                      frame_t current_frame,
124 125
                      NR_RA_t *ra,
                      int16_t *tdd_beam_association);
126

127 128
void nr_generate_Msg3_retransmission(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t slotP, NR_RA_t *ra);

cig's avatar
cig committed
129 130 131
/* \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
132 133
@param N_RB_UL Number of UL resource blocks
*/
134 135
void nr_fill_rar(uint8_t Mod_idP,
                 NR_RA_t * ra,
cig's avatar
cig committed
136
                 uint8_t * dlsch_buffer,
137
                 nfapi_nr_pusch_pdu_t  *pusch_pdu);
138

139 140
void fill_msg3_pusch_pdu(nfapi_nr_pusch_pdu_t *pusch_pdu,
                         NR_ServingCellConfigCommon_t *scc,
141
                         int round,
142 143 144 145 146 147
                         int startSymbolAndLength,
                         rnti_t rnti, int scs,
                         int bwp_size, int bwp_start,
                         int mappingtype, int fh,
                         int msg3_first_rb, int msg3_nb_rb);

148

149 150
void schedule_nr_prach(module_id_t module_idP, frame_t frameP, sub_frame_t slotP);

151 152 153 154
uint16_t nr_mac_compute_RIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs);

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

Robert Schmidt's avatar
Robert Schmidt committed
155 156 157 158
/* \brief preprocessor for phytest: schedules UE_id 0 with fixed MCS on all
 * freq resources */
void nr_preprocessor_phytest(module_id_t module_id,
                             frame_t frame,
159
                             sub_frame_t slot);
160 161
/* \brief UL preprocessor for phytest: schedules UE_id 0 with fixed MCS on a
 * fixed set of resources */
162
bool nr_ul_preprocessor_phytest(module_id_t module_id, frame_t frame, sub_frame_t slot);
Robert Schmidt's avatar
Robert Schmidt committed
163

Raymond Knopp's avatar
Raymond Knopp committed
164 165 166 167
void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
                                   frame_t       frameP,
                                   sub_frame_t   subframeP);

168 169 170 171 172 173 174 175 176
void handle_nr_uci_pucch_0_1(module_id_t mod_id,
                             frame_t frame,
                             sub_frame_t slot,
                             const nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_01);
void handle_nr_uci_pucch_2_3_4(module_id_t mod_id,
                               frame_t frame,
                               sub_frame_t slot,
                               const nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_234);

177

178
void config_uldci(const NR_BWP_Uplink_t *ubwp,
Eurecom's avatar
Eurecom committed
179 180
                  const NR_BWP_UplinkDedicated_t *ubwpd,
                  const NR_ServingCellConfigCommon_t *scc,
181
                  const nfapi_nr_pusch_pdu_t *pusch_pdu,
182
                  dci_pdu_rel15_t *dci_pdu_rel15,
183 184 185 186 187
                  int dci_format,
                  int time_domain_assignment,
                  uint8_t tpc,
                  int n_ubwp,
                  int bwp_id);
188

189 190 191 192
void nr_schedule_pucch(int Mod_idP,
                       frame_t frameP,
                       sub_frame_t slotP);

193 194
void nr_schedule_srs(int module_id, frame_t frame, sub_frame_t slot);

195 196 197 198 199
void nr_csirs_scheduling(int Mod_idP,
                         frame_t frame,
                         sub_frame_t slot,
                         int n_slots_frame);

200 201
void nr_csi_meas_reporting(int Mod_idP,
                           frame_t frameP,
202
                           sub_frame_t slotP);
203

204
int nr_acknack_scheduling(int Mod_idP,
205 206
                           int UE_id,
                           frame_t frameP,
207
                           sub_frame_t slotP,
208 209
                           int r_pucch,
                           int do_common);
Francesco Mani's avatar
Francesco Mani committed
210 211 212

void get_pdsch_to_harq_feedback(int Mod_idP,
                                int UE_id,
Eurecom's avatar
Eurecom committed
213
                                int bwp_id,
Francesco Mani's avatar
Francesco Mani committed
214
                                NR_SearchSpace__searchSpaceType_PR ss_type,
215
                                int *max_fb_time,
Francesco Mani's avatar
Francesco Mani committed
216
                                uint8_t *pdsch_to_harq_feedback);
217
  
Raymond Knopp's avatar
Raymond Knopp committed
218
void nr_configure_css_dci_initial(nfapi_nr_dl_tti_pdcch_pdu_rel15_t* pdcch_pdu,
219 220 221 222 223 224 225 226 227 228
                                  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);
229
/*
230
int nr_is_dci_opportunity(nfapi_nr_search_space_t search_space,
231 232 233
                          nfapi_nr_coreset_t coreset,
                          uint16_t frame,
                          uint16_t slot,
234
                          nfapi_nr_config_request_scf_t cfg);
235
*/
Raymond Knopp's avatar
Raymond Knopp committed
236

237
void nr_configure_pucch(nfapi_nr_pucch_pdu_t* pucch_pdu,
238 239 240
                        NR_ServingCellConfigCommon_t *scc,
                        NR_CellGroupConfig_t *CellGroup,
                        NR_BWP_Uplink_t *bwp,
Eurecom's avatar
Eurecom committed
241
                        NR_BWP_UplinkDedicated_t *bwpd,
242
                        uint16_t rnti,
243
                        uint8_t pucch_resource,
244
                        uint16_t O_csi,
245
                        uint16_t O_ack,
246
                        uint8_t O_sr,
247
			                  int r_pucch);
Francesco Mani's avatar
Francesco Mani committed
248

249 250 251 252
void find_search_space(int ss_type,
                       NR_BWP_Downlink_t *bwp,
                       NR_SearchSpace_t *ss);

253 254
void nr_configure_pdcch(gNB_MAC_INST *gNB_mac,
                        nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu,
255 256 257
                        NR_SearchSpace_t *ss,
                        NR_ControlResourceSet_t *coreset,
                        NR_ServingCellConfigCommon_t *scc,
258 259
                        NR_BWP_t *bwp,
                        NR_Type0_PDCCH_CSS_config_t *type0_PDCCH_CSS_config);
Raymond Knopp's avatar
Raymond Knopp committed
260

261
void fill_dci_pdu_rel15(const NR_ServingCellConfigCommon_t *scc,
262
                        const NR_CellGroupConfig_t *CellGroup,
263
                        nfapi_nr_dl_dci_pdu_t *pdcch_dci_pdu,
cig's avatar
cig committed
264
                        dci_pdu_rel15_t *dci_pdu_rel15,
265 266
                        int dci_formats,
                        int rnti_types,
267
                        int N_RB,
Francesco Mani's avatar
Francesco Mani committed
268 269
                        int bwp_id);

270
void prepare_dci(const NR_CellGroupConfig_t *CellGroup,
Francesco Mani's avatar
Francesco Mani committed
271 272 273
                 dci_pdu_rel15_t *dci_pdu_rel15,
                 nr_dci_format_t format,
                 int bwp_id);
274

275
/* find coreset within the search space */
276 277
NR_ControlResourceSet_t *get_coreset(module_id_t module_idP,
                                     NR_ServingCellConfigCommon_t *scc,
Eurecom's avatar
Eurecom committed
278
                                     void *bwp,
279
                                     NR_SearchSpace_t *ss,
280
                                     NR_SearchSpace__searchSpaceType_PR ss_type);
281 282

/* find a search space within a BWP */
283
NR_SearchSpace_t *get_searchspace(NR_ServingCellConfigCommon_t *scc,
284 285
                                  NR_BWP_DownlinkDedicated_t *bwp_Dedicated,
                                  NR_SearchSpace__searchSpaceType_PR target_ss);
286

287
long get_K2(NR_ServingCellConfigCommon_t *scc, NR_BWP_Uplink_t *ubwp, int time_domain_assignment, int mu);
288

289 290 291
void nr_set_pdsch_semi_static(const NR_ServingCellConfigCommon_t *scc,
                              const NR_CellGroupConfig_t *secondaryCellGroup,
                              const NR_BWP_Downlink_t *bwp,
rmagueta's avatar
rmagueta committed
292
                              const NR_BWP_DownlinkDedicated_t *bwpd0,
293
                              int tda,
294
                              const long dci_format,
295
                              NR_pdsch_semi_static_t *ps);
296

297 298
void nr_set_pusch_semi_static(const NR_ServingCellConfigCommon_t *scc,
                              const NR_BWP_Uplink_t *ubwp,
rmagueta's avatar
rmagueta committed
299
			                        const NR_BWP_UplinkDedicated_t *ubwpd,
300 301 302 303
                              long dci_format,
                              int tda,
                              uint8_t num_dmrs_cdm_grps_no_data,
                              NR_pusch_semi_static_t *ps);
304

305 306
uint8_t nr_get_tpc(int target, uint8_t cqi, int incr);

307
int get_spf(nfapi_nr_config_request_scf_t *cfg);
308

309
int to_absslot(nfapi_nr_config_request_scf_t *cfg,int frame,int slot);
310

Raymond Knopp's avatar
Raymond Knopp committed
311
void nr_get_tbs_dl(nfapi_nr_dl_tti_pdsch_pdu *pdsch_pdu,
312
		   int x_overhead,
313
                   uint8_t numdmrscdmgroupnodata,
314
                   uint8_t tb_scaling);
Raymond Knopp's avatar
Raymond Knopp committed
315 316 317 318 319 320 321
/** \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);
322 323 324 325 326

int NRRIV2BW(int locationAndBandwidth,int N_RB);

int NRRIV2PRBOFFSET(int locationAndBandwidth,int N_RB);

327 328 329 330 331 332 333 334 335
/* Functions to manage an NR_list_t */
void dump_nr_list(NR_list_t *listP);
void create_nr_list(NR_list_t *listP, int len);
void destroy_nr_list(NR_list_t *list);
void add_nr_list(NR_list_t *listP, int id);
void remove_nr_list(NR_list_t *listP, int id);
void add_tail_nr_list(NR_list_t *listP, int id);
void add_front_nr_list(NR_list_t *listP, int id);
void remove_front_nr_list(NR_list_t *listP);
336

cig's avatar
cig committed
337
int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP);
338

kn.raju's avatar
kn.raju committed
339 340
int find_nr_RA_id(module_id_t mod_idP, int CC_idP, rnti_t rntiP);

341
int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP, NR_CellGroupConfig_t *CellGroup);
342

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

345
void nr_mac_remove_ra_rnti(module_id_t mod_id, rnti_t rnti);
346

347
int allocate_nr_CCEs(gNB_MAC_INST *nr_mac,
348 349
                     NR_BWP_Downlink_t *bwp,
                     NR_ControlResourceSet_t *coreset,
cig's avatar
cig committed
350
                     int aggregation,
351 352 353
                     uint16_t Y,
                     int m,
                     int nr_of_candidates);
354

355 356
int nr_get_default_pucch_res(int pucch_ResourceCommon);

rangaswamy's avatar
rangaswamy committed
357
void compute_csi_bitlen(NR_CSI_MeasConfig_t *csi_MeasConfig, NR_UE_info_t *UE_info, int UE_id, module_id_t Mod_idP);
358

cig's avatar
cig committed
359 360 361 362 363 364
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);

365
void config_nr_mib(int Mod_idP, 
366 367 368 369 370 371 372 373
                   int CC_idP,
                   int p_gNBP,
                   int subCarrierSpacingCommon,
                   uint32_t ssb_SubcarrierOffset,
                   int dmrs_TypeA_Position,
                   uint32_t pdcch_ConfigSIB1,
                   int cellBarred,
                   int intraFreqReselection);
374

375 376 377 378 379
int nr_write_ce_dlsch_pdu(module_id_t module_idP,
                          const NR_UE_sched_ctrl_t *ue_sched_ctl,
                          unsigned char *mac_pdu,
                          unsigned char drx_cmd,
                          unsigned char *ue_cont_res_id);
380

381
void nr_generate_Msg2(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t slotP, NR_RA_t *ra);
382

383
void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t slotP, NR_RA_t *ra);
384

385
void nr_check_Msg4_Ack(module_id_t module_id, int CC_id, frame_t frame, sub_frame_t slot, NR_RA_t *ra);
386

387 388
int binomial(int n, int k);

389 390
bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot);

391
void fill_ssb_vrb_map (NR_COMMON_channels_t *cc, int rbStart, uint16_t symStart, int CC_id);
392

393

394 395 396 397 398 399 400 401 402 403
/* \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
404 405 406 407 408 409
               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,
410 411 412
               const uint16_t timing_advance,
               const uint8_t ul_cqi,
               const uint16_t rssi);
413

414 415
void handle_nr_ul_harq(const int CC_idP,
                       module_id_t mod_id,
416 417 418
                       frame_t frame,
                       sub_frame_t slot,
                       const nfapi_nr_crc_t *crc_pdu);
419

420 421
int16_t ssb_index_from_prach(module_id_t module_idP,
                             frame_t frameP,
422
			     sub_frame_t slotP,
423 424 425 426 427 428
                             uint16_t preamble_index,
                             uint8_t freq_index,
                             uint8_t symbol);

void find_SSB_and_RO_available(module_id_t module_idP);

429 430
void set_dl_dmrs_ports(NR_pdsch_semi_static_t *ps);

431 432 433
void calculate_preferred_dl_tda(module_id_t module_id, const NR_BWP_Downlink_t *bwp);
void calculate_preferred_ul_tda(module_id_t module_id, const NR_BWP_Uplink_t *ubwp);

ChiehChun's avatar
ChiehChun committed
434
bool find_free_CCE(module_id_t module_id, sub_frame_t slot, int UE_id);
435 436 437 438 439 440 441 442 443 444

bool nr_find_nb_rb(uint16_t Qm,
                   uint16_t R,
                   uint16_t nb_symb_sch,
                   uint16_t nb_dmrs_prb,
                   uint32_t bytes,
                   uint16_t nb_rb_max,
                   uint32_t *tbs,
                   uint16_t *nb_rb);

imad's avatar
imad committed
445 446
void nr_sr_reporting(int Mod_idP, frame_t frameP, sub_frame_t slotP);

447
void dump_mac_stats(gNB_MAC_INST *gNB, char *output, int strlen);
448
#endif /*__LAYER2_NR_MAC_PROTO_H__*/