From f3126586f3f6d325ec6b50a99d6b97ec84937f36 Mon Sep 17 00:00:00 2001
From: francescomani <email@francescomani.it>
Date: Tue, 7 Feb 2023 11:35:55 +0100
Subject: [PATCH] removing constant max number of xlsch

---
 common/openairinterface5g_limits.h            |  3 -
 executables/nr-gnb.c                          |  2 +-
 nfapi/oai_integration/nfapi_pnf.c             |  4 +-
 openair1/PHY/INIT/nr_init.c                   | 44 ++++++++-----
 .../PHY/NR_ESTIMATION/nr_measurements_gNB.c   | 42 ++++++-------
 openair1/PHY/NR_TRANSPORT/nr_ulsch.c          |  4 +-
 .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c  |  2 +-
 openair1/PHY/defs_gNB.h                       | 61 ++++++++++---------
 openair1/SCHED_NR/fapi_nr_l1.c                |  7 +--
 openair1/SCHED_NR/phy_procedures_nr_gNB.c     |  4 +-
 10 files changed, 92 insertions(+), 81 deletions(-)

diff --git a/common/openairinterface5g_limits.h b/common/openairinterface5g_limits.h
index 534c125226..b3ae99d047 100644
--- a/common/openairinterface5g_limits.h
+++ b/common/openairinterface5g_limits.h
@@ -10,10 +10,7 @@
 #        define NUMBER_OF_ULSCH_MAX 8
 #        define NUMBER_OF_DLSCH_MAX 8 
 #        define NUMBER_OF_SRS_MAX 16
-#        define NUMBER_OF_NR_ULSCH_MAX MAX_MOBILES_PER_GNB
-#        define NUMBER_OF_NR_DLSCH_MAX MAX_MOBILES_PER_GNB
 #        define NUMBER_OF_SCH_STATS_MAX 16
-#        define NUMBER_OF_NR_SCH_STATS_MAX MAX_MOBILES_PER_GNB
 
 #        define NUMBER_FRAMES_PHY_UE_INACTIVE 10
 
diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c
index 83f0a05e69..93462620ac 100644
--- a/executables/nr-gnb.c
+++ b/executables/nr-gnb.c
@@ -182,7 +182,7 @@ void rx_func(void *param)
       stats->active = false;
   }
   // disactivate ULSCH structure if it is inactive for a given number of frames
-  for (int i = 0; i < NUMBER_OF_NR_ULSCH_MAX; i++) {
+  for (int i = 0; i < gNB->max_nb_pusch; i++) {
     NR_gNB_ULSCH_t *ulsch = gNB->ulsch[i];
     if (ulsch->active && (((frame_rx - ulsch->harq_process->frame + 1024) % 1024) > NUMBER_FRAMES_PHY_UE_INACTIVE))
       ulsch->active = false;
diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c
index 0ba6df03b9..275a42c736 100644
--- a/nfapi/oai_integration/nfapi_pnf.c
+++ b/nfapi/oai_integration/nfapi_pnf.c
@@ -1220,8 +1220,8 @@ int pnf_phy_dl_tti_req(gNB_L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t *pnf_p7,
       if (tx_data != NULL) {
         uint8_t *dlsch_sdu = (uint8_t *)tx_data->TLVs[0].value.direct;
         //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() DLSCH:pdu_index:%d handle_nfapi_dlsch_pdu(eNB, proc_rxtx, dlsch_pdu, transport_blocks:%d sdu:%p) eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols:%d\n", __FUNCTION__, rel8_pdu->pdu_index, rel8_pdu->transport_blocks, dlsch_sdu, eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols);
-        AssertFatal(msgTx->num_pdsch_slot < NUMBER_OF_NR_DLSCH_MAX,"Number of PDSCH PDUs %d exceeded the limit %d\n",
-          msgTx->num_pdsch_slot, NUMBER_OF_NR_DLSCH_MAX);
+        AssertFatal(msgTx->num_pdsch_slot < gNB->max_nb_pdsch,"Number of PDSCH PDUs %d exceeded the limit %d\n",
+          msgTx->num_pdsch_slot, gNB->max_nb_pdsch);
         handle_nr_nfapi_pdsch_pdu(msgTx, pdsch_pdu, dlsch_sdu);
       } 
       else {
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index 9a74f093b1..861f8ac56f 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -508,7 +508,6 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB)
   nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
   NR_gNB_COMMON *const common_vars  = &gNB->common_vars;
   NR_gNB_PRACH *const prach_vars   = &gNB->prach_vars;
-  NR_gNB_PUSCH **const pusch_vars   = gNB->pusch_vars;
 
   int i;
   int Ptx=cfg->carrier_config.num_tx_ant.value;
@@ -532,6 +531,8 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB)
   if (gNB->ldpc_offload_flag)
     load_nrLDPClib_offload(); 
 
+  gNB->max_nb_pdsch = MAX_MOBILES_PER_GNB;
+
   init_codebook_gNB(gNB);
   init_ul_delay_table(fp);
 
@@ -684,7 +685,8 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB)
   int nb_re_pusch = N_RB_UL * NR_NB_SC_PER_RB;
   int nb_re_pusch2 = nb_re_pusch + (nb_re_pusch&7);
 
-  for (int ULSCH_id = 0; ULSCH_id < NUMBER_OF_NR_ULSCH_MAX; ULSCH_id++) {
+  NR_gNB_PUSCH **pusch_vars = (NR_gNB_PUSCH **)malloc16_clear(gNB->max_nb_pusch * sizeof(NR_gNB_PUSCH*));
+  for (int ULSCH_id = 0; ULSCH_id < gNB->max_nb_pusch; ULSCH_id++) {
     pusch_vars[ULSCH_id] = (NR_gNB_PUSCH *)malloc16_clear( sizeof(NR_gNB_PUSCH) );
     pusch_vars[ULSCH_id]->rxdataF_ext           = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_estimates       = (int32_t **)malloc16(n_buf*sizeof(int32_t *) );
@@ -836,7 +838,7 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
   free_and_zero(prach_vars->prach_ifft);
 
   NR_gNB_PUSCH** pusch_vars = gNB->pusch_vars;
-  for (int ULSCH_id = 0; ULSCH_id < NUMBER_OF_NR_ULSCH_MAX; ULSCH_id++) {
+  for (int ULSCH_id = 0; ULSCH_id < gNB->max_nb_pusch; ULSCH_id++) {
     for (int i=0; i< max_ul_mimo_layers; i++)
       free_and_zero(pusch_vars[ULSCH_id]->llr_layers[i]);
     for (int i = 0; i < Prx; i++) {
@@ -955,7 +957,8 @@ void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,
 }
 
 
-void nr_phy_config_request(NR_PHY_Config_t *phy_config) {
+void nr_phy_config_request(NR_PHY_Config_t *phy_config)
+{
   uint8_t Mod_id = phy_config->Mod_id;
   uint8_t short_sequence, num_sequences, rootSequenceIndex, fd_occasion;
   NR_DL_FRAME_PARMS *fp = &RC.gNB[Mod_id]->frame_parms;
@@ -1007,16 +1010,19 @@ void nr_phy_config_request(NR_PHY_Config_t *phy_config) {
   LOG_I(PHY,"gNB %d configured\n",Mod_id);
 }
 
-void init_DLSCH_struct(PHY_VARS_gNB *gNB, processingData_L1tx_t *msg) {
+void init_DLSCH_struct(PHY_VARS_gNB *gNB, processingData_L1tx_t *msg)
+{
   NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
   nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
   uint16_t grid_size = cfg->carrier_config.dl_grid_size[fp->numerology_index].value;
   msg->num_pdsch_slot = 0;
 
+  msg->dlsch = (NR_gNB_DLSCH_t ***)malloc16(gNB->max_nb_pdsch * sizeof(NR_gNB_DLSCH_t **));
   int num_cw = NR_MAX_NB_LAYERS > 4? 2:1;
-  for (int i = 0; i < NUMBER_OF_NR_DLSCH_MAX; i++) {
-    LOG_D(PHY,"Allocating Transport Channel Buffers for DLSCH %d/%d\n", i, NUMBER_OF_NR_DLSCH_MAX);
-    for (int j=0; j<num_cw; j++) {
+  for (int i = 0; i < gNB->max_nb_pdsch; i++) {
+    LOG_I(PHY,"Allocating Transport Channel Buffers for DLSCH %d/%d\n", i, gNB->max_nb_pdsch);
+    msg->dlsch[i] = (NR_gNB_DLSCH_t **)malloc16(num_cw * sizeof(NR_gNB_DLSCH_t *));
+    for (int j = 0; j < num_cw; j++) {
       msg->dlsch[i][j] = new_gNB_dlsch(fp, grid_size);
       AssertFatal(msg->dlsch[i][j]!=NULL,"Can't initialize dlsch %d \n", i);
     }
@@ -1029,9 +1035,13 @@ void reset_DLSCH_struct(const PHY_VARS_gNB *gNB, processingData_L1tx_t *msg)
   const nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
   const uint16_t grid_size = cfg->carrier_config.dl_grid_size[fp->numerology_index].value;
   int num_cw = NR_MAX_NB_LAYERS > 4? 2:1;
-  for (int i = 0; i < NUMBER_OF_NR_DLSCH_MAX; i++)
-    for (int j=0; j<num_cw; j++)
+  for (int i = 0; i < gNB->max_nb_pdsch; i++) {
+    for (int j=0; j<num_cw; j++) {
       free_gNB_dlsch(&msg->dlsch[i][j], grid_size, fp);
+      free(msg->dlsch[i][j]);
+    }
+    free(msg->dlsch[i]);
+  }
 }
 
 void init_nr_transport(PHY_VARS_gNB *gNB)
@@ -1066,8 +1076,11 @@ void init_nr_transport(PHY_VARS_gNB *gNB)
     buffer_ul_slots = (nb_ul_slots_period < slot_ahead) ? nb_ul_slots_period : slot_ahead;
 
   gNB->max_nb_pucch = MAX_MOBILES_PER_GNB * buffer_ul_slots;
+  gNB->max_nb_pusch = MAX_MOBILES_PER_GNB * buffer_ul_slots;
   gNB->max_nb_srs = buffer_ul_slots << 1; // assuming at most 2 SRS per slot
 
+  gNB->measurements.ulsch_measurements = (ULSCH_MEASUREMENTS_gNB *) malloc16(gNB->max_nb_pusch * sizeof(ULSCH_MEASUREMENTS_gNB));
+
   gNB->pucch = (NR_gNB_PUCCH_t **) malloc16(gNB->max_nb_pucch * sizeof(NR_gNB_PUCCH_t*));
   for (int i = 0; i < gNB->max_nb_pucch; i++) {
     LOG_D(PHY,"Allocating Transport Channel Buffers for PUCCH %d/%d\n", i, gNB->max_nb_pucch);
@@ -1082,12 +1095,10 @@ void init_nr_transport(PHY_VARS_gNB *gNB)
     AssertFatal(gNB->srs[i]!=NULL,"Can't initialize srs %d \n", i);
   }
 
-  for (int i = 0; i < NUMBER_OF_NR_ULSCH_MAX; i++) {
-
-    LOG_D(PHY,"Allocating Transport Channel Buffers for ULSCH  %d/%d\n", i, NUMBER_OF_NR_ULSCH_MAX);
-
+  gNB->ulsch = (NR_gNB_ULSCH_t **) malloc16(gNB->max_nb_pusch * sizeof(NR_gNB_ULSCH_t*));
+  for (int i = 0; i < gNB->max_nb_pusch; i++) {
+    LOG_I(PHY,"Allocating Transport Channel Buffers for ULSCH  %d/%d\n", i, gNB->max_nb_pusch);
     gNB->ulsch[i] = new_gNB_ulsch(gNB->max_ldpc_iterations, fp->N_RB_UL);
-
     if (!gNB->ulsch[i]) {
       LOG_E(PHY,"Can't get gNB ulsch structures\n");
       exit(-1);
@@ -1111,6 +1122,7 @@ void reset_nr_transport(PHY_VARS_gNB *gNB)
     free_gNB_srs(gNB->srs[i]);
   free(gNB->srs);
 
-  for (int i = 0; i < NUMBER_OF_NR_ULSCH_MAX; i++)
+  for (int i = 0; i < gNB->max_nb_pusch; i++)
     free_gNB_ulsch(&gNB->ulsch[i], fp->N_RB_UL);
+  free(gNB->ulsch);
 }
diff --git a/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c b/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c
index 96b832ceab..293442721a 100644
--- a/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c
+++ b/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c
@@ -211,10 +211,10 @@ void gNB_I0_measurements(PHY_VARS_gNB *gNB,int slot, int first_symb,int num_symb
 void nr_gnb_measurements(PHY_VARS_gNB *gNB, uint8_t ulsch_id, unsigned char harq_pid, unsigned char symbol, uint8_t nrOfLayers)
 {
 
-  int rx_power_tot[NUMBER_OF_NR_ULSCH_MAX];
-  int rx_power[NUMBER_OF_NR_ULSCH_MAX][NB_ANTENNAS_RX];
-  unsigned short rx_power_avg_dB[NUMBER_OF_NR_ULSCH_MAX];
-  unsigned short rx_power_tot_dB[NUMBER_OF_NR_ULSCH_MAX];
+  int rx_power_tot = 0;
+  int rx_power[NB_ANTENNAS_RX];
+  unsigned short rx_power_avg_dB;
+  unsigned short rx_power_tot_dB;
 
   double rx_gain = openair0_cfg[0].rx_gain[0];
   double rx_gain_offset = openair0_cfg[0].rx_gain_offset[0];
@@ -223,43 +223,41 @@ void nr_gnb_measurements(PHY_VARS_gNB *gNB, uint8_t ulsch_id, unsigned char harq
   int ch_offset = fp->ofdm_symbol_size * symbol;
   int N_RB_UL = gNB->ulsch[ulsch_id]->harq_process->ulsch_pdu.rb_size;
 
-  rx_power_tot[ulsch_id] = 0;
-
   for (int aarx = 0; aarx < fp->nb_antennas_rx; aarx++){
 
-    rx_power[ulsch_id][aarx] = 0;
+    rx_power[aarx] = 0;
 
     for (int aatx = 0; aatx < nrOfLayers; aatx++){
 
-      meas->rx_spatial_power[ulsch_id][aatx][aarx] = (signal_energy_nodc(&gNB->pusch_vars[ulsch_id]->ul_ch_estimates[aatx*fp->nb_antennas_rx+aarx][ch_offset], N_RB_UL * NR_NB_SC_PER_RB));
+      meas->ulsch_measurements[ulsch_id].rx_spatial_power[aatx][aarx] = (signal_energy_nodc(&gNB->pusch_vars[ulsch_id]->ul_ch_estimates[aatx*fp->nb_antennas_rx+aarx][ch_offset], N_RB_UL * NR_NB_SC_PER_RB));
 
-      if (meas->rx_spatial_power[ulsch_id][aatx][aarx] < 0) {
-        meas->rx_spatial_power[ulsch_id][aatx][aarx] = 0;
+      if (meas->ulsch_measurements[ulsch_id].rx_spatial_power[aatx][aarx] < 0) {
+        meas->ulsch_measurements[ulsch_id].rx_spatial_power[aatx][aarx] = 0;
       }
 
-      meas->rx_spatial_power_dB[ulsch_id][aatx][aarx] = (unsigned short) dB_fixed(meas->rx_spatial_power[ulsch_id][aatx][aarx]);
-      rx_power[ulsch_id][aarx] += meas->rx_spatial_power[ulsch_id][aatx][aarx];
+      meas->ulsch_measurements[ulsch_id].rx_spatial_power_dB[aatx][aarx] = (unsigned short) dB_fixed(meas->ulsch_measurements[ulsch_id].rx_spatial_power[aatx][aarx]);
+      rx_power[aarx] += meas->ulsch_measurements[ulsch_id].rx_spatial_power[aatx][aarx];
 
     }
-    LOG_D(PHY, "[ULSCH ID %d] RX power in antenna %d = %d\n", ulsch_id, aarx, rx_power[ulsch_id][aarx]);
+    LOG_D(PHY, "[ULSCH ID %d] RX power in antenna %d = %d\n", ulsch_id, aarx, rx_power[aarx]);
 
-    rx_power_tot[ulsch_id] += rx_power[ulsch_id][aarx];
+    rx_power_tot += rx_power[aarx];
 
   }
 
-  rx_power_tot_dB[ulsch_id] = (unsigned short) dB_fixed(rx_power_tot[ulsch_id]);
-  rx_power_avg_dB[ulsch_id] = rx_power_tot_dB[ulsch_id];
+  rx_power_tot_dB = (unsigned short) dB_fixed(rx_power_tot);
+  rx_power_avg_dB = rx_power_tot_dB;
 
-  meas->wideband_cqi_tot[ulsch_id] = dB_fixed2(rx_power_tot[ulsch_id], meas->n0_power_tot);
-  meas->rx_rssi_dBm[ulsch_id] = rx_power_avg_dB[ulsch_id] + 30 - 10 * log10(pow(2, 30)) - (rx_gain - rx_gain_offset) - dB_fixed(fp->ofdm_symbol_size);
+  meas->ulsch_measurements[ulsch_id].wideband_cqi_tot = dB_fixed2(rx_power_tot, meas->n0_power_tot);
+  meas->ulsch_measurements[ulsch_id].rx_rssi_dBm = rx_power_avg_dB + 30 - 10 * log10(pow(2, 30)) - (rx_gain - rx_gain_offset) - dB_fixed(fp->ofdm_symbol_size);
 
   LOG_D(PHY, "[ULSCH %d] RSSI %d dBm/RE, RSSI (digital) %d dB (N_RB_UL %d), WBand CQI tot %d dB, N0 Power tot %d, RX Power tot %d\n",
     ulsch_id,
-    meas->rx_rssi_dBm[ulsch_id],
-    rx_power_avg_dB[ulsch_id],
+    meas->ulsch_measurements[ulsch_id].rx_rssi_dBm,
+    rx_power_avg_dB,
     N_RB_UL,
-    meas->wideband_cqi_tot[ulsch_id],
+    meas->ulsch_measurements[ulsch_id].wideband_cqi_tot,
     meas->n0_power_tot,
-    rx_power_tot[ulsch_id]);
+    rx_power_tot);
 
 }
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch.c
index 2430b6e2fa..c7c35e6865 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch.c
@@ -40,7 +40,7 @@ int16_t find_nr_ulsch(PHY_VARS_gNB *gNB, uint16_t rnti, int pid, int frame)
   int16_t first_free_index = -1;
   AssertFatal(gNB != NULL,"gNB is null\n");
 
-  for (int i = 0; i < NUMBER_OF_NR_ULSCH_MAX; i++) {
+  for (int i = 0; i < gNB->max_nb_pusch; i++) {
     NR_gNB_ULSCH_t *ulsch = gNB->ulsch[i];
     AssertFatal(ulsch != NULL, "gNB->ulsch[%d] is null\n", i);
     if(!ulsch->active) {
@@ -64,7 +64,7 @@ void nr_fill_ulsch(PHY_VARS_gNB *gNB,
  
   int harq_pid = ulsch_pdu->pusch_data.harq_process_id;
   int ulsch_id = find_nr_ulsch(gNB, ulsch_pdu->rnti, harq_pid, frame);
-  AssertFatal((ulsch_id >= 0) && (ulsch_id < NUMBER_OF_NR_ULSCH_MAX),
+  AssertFatal((ulsch_id >= 0) && (ulsch_id < gNB->max_nb_pusch),
               "illegal or no ulsch_id found!!! rnti %04x ulsch_id %d\n",ulsch_pdu->rnti,ulsch_id);
 
   NR_gNB_ULSCH_t  *ulsch = gNB->ulsch[ulsch_id];
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index 67f33cbd6a..c96fc64866 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -1885,7 +1885,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                                     &max_ch);
       }
 
-      nr_gnb_measurements(gNB, ulsch_id, harq_pid, symbol,rel15_ul->nrOfLayers);
+      nr_gnb_measurements(gNB, ulsch_id, harq_pid, symbol, rel15_ul->nrOfLayers);
 
       for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) {
         if (symbol == rel15_ul->start_symbol_index) {
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 9a59214877..8f9148fc05 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -503,7 +503,32 @@ typedef struct gNB_L1_proc_t_s {
   gNB_L1_rxtx_proc_t L1_proc, L1_proc_tx;
 } gNB_L1_proc_t;
 
-
+typedef struct {
+  //! estimated received spatial signal power (linear)
+  unsigned int   rx_spatial_power[NB_ANTENNAS_TX][NB_ANTENNAS_RX];
+  //! estimated received spatial signal power (dB)
+  unsigned int rx_spatial_power_dB[NB_ANTENNAS_TX][NB_ANTENNAS_RX];
+  //! estimated rssi (dBm)
+  int rx_rssi_dBm;
+  //! estimated correlation (wideband linear) between spatial channels (computed in dlsch_demodulation)
+  int rx_correlation[2];
+  //! estimated correlation (wideband dB) between spatial channels (computed in dlsch_demodulation)
+  int rx_correlation_dB[2];
+  /// Wideband CQI (= SINR)
+  int wideband_cqi[MAX_NUM_RU_PER_gNB];
+  /// Wideband CQI in dB (= SINR dB)
+  int wideband_cqi_dB[MAX_NUM_RU_PER_gNB];
+  /// Wideband CQI (sum of all RX antennas, in dB)
+  char wideband_cqi_tot;
+  /// Subband CQI per RX antenna and RB (= SINR)
+  int subband_cqi[MAX_NUM_RU_PER_gNB][275];
+  /// Total Subband CQI and RB (= SINR)
+  int subband_cqi_tot[275];
+  /// Subband CQI in dB and RB (= SINR dB)
+  int subband_cqi_dB[MAX_NUM_RU_PER_gNB][275];
+  /// Total Subband CQI and RB
+  int subband_cqi_tot_dB[275];
+} ULSCH_MEASUREMENTS_gNB;
 
 typedef struct {
   // common measurements
@@ -529,31 +554,8 @@ typedef struct {
   int n0_subband_power_tot_dBm[275];
 
   // gNB measurements (per user)
-  //! estimated received spatial signal power (linear)
-  unsigned int   rx_spatial_power[NUMBER_OF_NR_ULSCH_MAX][NB_ANTENNAS_TX][NB_ANTENNAS_RX];
-  //! estimated received spatial signal power (dB)
-  unsigned int rx_spatial_power_dB[NUMBER_OF_NR_ULSCH_MAX][NB_ANTENNAS_TX][NB_ANTENNAS_RX];
-  //! estimated rssi (dBm)
-  int            rx_rssi_dBm[NUMBER_OF_NR_ULSCH_MAX];
-  //! estimated correlation (wideband linear) between spatial channels (computed in dlsch_demodulation)
-  int            rx_correlation[NUMBER_OF_NR_ULSCH_MAX][2];
-  //! estimated correlation (wideband dB) between spatial channels (computed in dlsch_demodulation)
-  int            rx_correlation_dB[NUMBER_OF_NR_ULSCH_MAX][2];
+  ULSCH_MEASUREMENTS_gNB *ulsch_measurements;
 
-  /// Wideband CQI (= SINR)
-  int            wideband_cqi[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB];
-  /// Wideband CQI in dB (= SINR dB)
-  int            wideband_cqi_dB[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB];
-  /// Wideband CQI (sum of all RX antennas, in dB)
-  char           wideband_cqi_tot[NUMBER_OF_NR_ULSCH_MAX];
-  /// Subband CQI per RX antenna and RB (= SINR)
-  int            subband_cqi[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB][275];
-  /// Total Subband CQI and RB (= SINR)
-  int            subband_cqi_tot[NUMBER_OF_NR_ULSCH_MAX][275];
-  /// Subband CQI in dB and RB (= SINR dB)
-  int            subband_cqi_dB[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB][275];
-  /// Total Subband CQI and RB
-  int            subband_cqi_tot_dB[NUMBER_OF_NR_ULSCH_MAX][275];
   /// PRACH background noise level
   int            prach_I0;
 
@@ -609,14 +611,17 @@ typedef struct PHY_VARS_gNB_s {
   
   int max_nb_pucch;
   int max_nb_srs;
+  int max_nb_pdsch;
+  int max_nb_pusch;
+
   NR_gNB_PBCH        pbch;
   NR_gNB_COMMON      common_vars;
   NR_gNB_PRACH       prach_vars;
   NR_gNB_PRS         prs_vars;
-  NR_gNB_PUSCH       *pusch_vars[NUMBER_OF_NR_ULSCH_MAX];
+  NR_gNB_PUSCH       **pusch_vars;
   NR_gNB_PUCCH_t     **pucch;
   NR_gNB_SRS_t       **srs;
-  NR_gNB_ULSCH_t     *ulsch[NUMBER_OF_NR_ULSCH_MAX];  // [Nusers times]
+  NR_gNB_ULSCH_t     **ulsch;
   NR_gNB_PHY_STATS_t phy_stats[MAX_MOBILES_PER_GNB];
   t_nrPolar_params    **polarParams;
 
@@ -811,7 +816,7 @@ typedef struct processingData_L1tx {
   nfapi_nr_dl_tti_pdcch_pdu pdcch_pdu[NFAPI_NR_MAX_NB_CORESETS];
   nfapi_nr_ul_dci_request_pdus_t ul_pdcch_pdu[NFAPI_NR_MAX_NB_CORESETS];
   NR_gNB_CSIRS_t csirs_pdu[NR_SYMBOLS_PER_SLOT];
-  NR_gNB_DLSCH_t *dlsch[NUMBER_OF_NR_DLSCH_MAX][2];
+  NR_gNB_DLSCH_t ***dlsch;
   NR_gNB_SSB_t ssb[64];
   uint16_t num_pdsch_slot;
   int num_dl_pdcch;
diff --git a/openair1/SCHED_NR/fapi_nr_l1.c b/openair1/SCHED_NR/fapi_nr_l1.c
index 798b85f1e8..9f0e50e583 100644
--- a/openair1/SCHED_NR/fapi_nr_l1.c
+++ b/openair1/SCHED_NR/fapi_nr_l1.c
@@ -135,7 +135,6 @@ void handle_nr_nfapi_pdsch_pdu(processingData_L1tx_t *msgTx,
 void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO)
 {
   
-  PHY_VARS_gNB *gNB;
   // copy data from L2 interface into L1 structures
   module_id_t                   Mod_id       = Sched_INFO->module_id;
   nfapi_nr_dl_tti_request_t     *DL_req      = Sched_INFO->DL_req;
@@ -148,7 +147,7 @@ void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO)
   AssertFatal(RC.gNB!=NULL,"RC.gNB is null\n");
   AssertFatal(RC.gNB[Mod_id]!=NULL,"RC.gNB[%d] is null\n",Mod_id);
 
-  gNB = RC.gNB[Mod_id];
+  PHY_VARS_gNB *gNB = RC.gNB[Mod_id];
   start_meas(&gNB->schedule_response_stats);
 
   nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
@@ -204,8 +203,8 @@ void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO)
             AssertFatal(TX_req->pdu_list[pduIndex].num_TLV == 1, "TX_req->pdu_list[%d].num_TLV %d != 1\n",
             pduIndex,TX_req->pdu_list[pduIndex].num_TLV);
             uint8_t *sdu = (uint8_t *)TX_req->pdu_list[pduIndex].TLVs[0].value.direct;
-            AssertFatal(msgTx->num_pdsch_slot < NUMBER_OF_NR_DLSCH_MAX,"Number of PDSCH PDUs %d exceeded the limit %d\n",
-                        msgTx->num_pdsch_slot, NUMBER_OF_NR_DLSCH_MAX);
+            AssertFatal(msgTx->num_pdsch_slot < gNB->max_nb_pdsch,"Number of PDSCH PDUs %d exceeded the limit %d\n",
+                        msgTx->num_pdsch_slot, gNB->max_nb_pdsch);
             handle_nr_nfapi_pdsch_pdu(msgTx,&dl_tti_pdu->pdsch_pdu, sdu);
         }
       }
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index a9471dd6cc..7ec28872f7 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -552,7 +552,7 @@ void fill_ul_rb_mask(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx) {
     }
   }
 
-  for (int ULSCH_id = 0; ULSCH_id < NUMBER_OF_NR_ULSCH_MAX; ULSCH_id++) {
+  for (int ULSCH_id = 0; ULSCH_id < gNB->max_nb_pusch; ULSCH_id++) {
     NR_gNB_ULSCH_t *ulsch = gNB->ulsch[ULSCH_id];
     int harq_pid;
     NR_UL_gNB_HARQ_t *ulsch_harq = ulsch_harq = ulsch->harq_process;
@@ -772,7 +772,7 @@ int phy_procedures_gNB_uespec_RX(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx)
     }
   }
 
-  for (int ULSCH_id = 0; ULSCH_id < NUMBER_OF_NR_ULSCH_MAX; ULSCH_id++) {
+  for (int ULSCH_id = 0; ULSCH_id < gNB->max_nb_pusch; ULSCH_id++) {
 
     NR_gNB_ULSCH_t *ulsch = gNB->ulsch[ULSCH_id];
     NR_UL_gNB_HARQ_t *ulsch_harq = ulsch->harq_process;
-- 
2.26.2