if5_tools.c 14.1 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.0  (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
 */

22 23
/*! \file PHY/LTE_TRANSPORT/if5_tools.c
* \brief 
24
* \author S. Sandeep Kumar, Raymond Knopp, Tien-Thinh Nguyen
25 26 27
* \date 2016
* \version 0.1
* \company Eurecom
28
* \email: ee13b1025@iith.ac.in, knopp@eurecom.fr, tien-thinh.nguyen@eurecom.fr 
29 30 31 32 33 34 35
* \note
* \warning
*/

#include "PHY/defs.h"

#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
36
#include "UTIL/LOG/vcd_signal_dumper.h"
37 38 39
//#define DEBUG_DL_MOBIPASS
//#define DEBUG_UL_MOBIPASS
#define SUBFRAME_SKIP_NUM_MOBIPASS 8
40

41 42 43 44
int dummy_cnt = 0;
int subframe_skip_extra = 0;
int start_flag = 1;
int offset_cnt = 1;
Sandeep Kumar's avatar
Sandeep Kumar committed
45
void send_IF5(PHY_VARS_eNB *eNB, openair0_timestamp proc_timestamp, int subframe, uint8_t *seqno, uint16_t packet_type) {      
46 47
  
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
48 49
  int32_t *txp[fp->nb_antennas_tx], *rxp[fp->nb_antennas_rx]; 
  int32_t *tx_buffer=NULL;
50

51
  int8_t dummy_buffer[fp->samples_per_tti*2];
52
  uint16_t packet_id=0, i=0;
53 54 55

  uint32_t spp_eth  = (uint32_t) eNB->ifdevice.openair0_cfg->samples_per_packet;
  uint32_t spsf     = (uint32_t) eNB->ifdevice.openair0_cfg->samples_per_frame/10;
56
  
57 58
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF5, 1 );  

59 60
  if (packet_type == IF5_RRH_GW_DL) {    

61
    for (i=0; i < fp->nb_antennas_tx; i++)
Sandeep Kumar's avatar
Sandeep Kumar committed
62
      txp[i] = (void*)&eNB->common_vars.txdata[0][i][subframe*fp->samples_per_tti];
63 64
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
65 66

      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 1 );            
67
      eNB->ifdevice.trx_write_func(&eNB->ifdevice,
Sandeep Kumar's avatar
Sandeep Kumar committed
68
                                   (proc_timestamp + packet_id*spp_eth),
69
                                   (void**)txp,
70 71 72
                                   spp_eth,
                                   fp->nb_antennas_tx,
                                   0);
73
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 0 );  
74 75 76
      for (i=0; i < fp->nb_antennas_tx; i++)
        txp[i] += spp_eth;

77 78
    }
    
Sandeep Kumar's avatar
Sandeep Kumar committed
79
  } else if (packet_type == IF5_RRH_GW_UL) {
80
        
Sandeep Kumar's avatar
Sandeep Kumar committed
81 82 83 84
    for (i=0; i < fp->nb_antennas_rx; i++)
      rxp[i] = (void*)&eNB->common_vars.rxdata[0][i][subframe*fp->samples_per_tti];
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
85

86
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 1 );            
Sandeep Kumar's avatar
Sandeep Kumar committed
87 88
      eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                   (proc_timestamp + packet_id*spp_eth),
89
                                   (void**)rxp,
Sandeep Kumar's avatar
Sandeep Kumar committed
90 91 92
                                   spp_eth,
                                   fp->nb_antennas_rx,
                                   0);
93
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 0 );            
94 95 96
      for (i=0; i < fp->nb_antennas_rx; i++)
        rxp[i] += spp_eth;

Sandeep Kumar's avatar
Sandeep Kumar committed
97
    }    
98
    
Sandeep Kumar's avatar
Sandeep Kumar committed
99
  } else if (packet_type == IF5_MOBIPASS) {    
100
    uint16_t db_fulllength = PAYLOAD_MOBIPASS_NUM_SAMPLES;
101 102 103 104 105 106
    
    __m128i *data_block=NULL, *data_block_head=NULL;

    __m128i *txp128;
    __m128i t0, t1;

107 108
    // tx_buffer = memalign(16, MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + db_fulllength*sizeof(int16_t));
    tx_buffer = malloc(MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + db_fulllength*sizeof(int16_t));
109
    IF5_mobipass_header_t *header = (IF5_mobipass_header_t *)((uint8_t *)tx_buffer + MAC_HEADER_SIZE_BYTES);
110 111
    data_block_head = (__m128i *)((uint8_t *)tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t);
  
112 113 114 115 116 117
    header->flags = 0;
    header->fifo_status = 0;  
    header->seqno = *seqno;
    header->ack = 0;
    header->word0 = 0;  
    
Sandeep Kumar's avatar
Sandeep Kumar committed
118
    txp[0] = (void*)&eNB->common_vars.txdata[0][0][subframe*eNB->frame_parms.samples_per_tti];
119 120
    txp128 = (__m128i *) txp[0];
              
121
    for (packet_id=0; packet_id<fp->samples_per_tti/db_fulllength; packet_id++) {
122
      header->time_stamp = htonl((uint32_t)(proc_timestamp + packet_id*db_fulllength));
123 124
      data_block = data_block_head; 
    
125
      for (i=0; i<db_fulllength>>2; i+=2) {
126 127
        t0 = _mm_srai_epi16(*txp128++, 4);
        t1 = _mm_srai_epi16(*txp128++, 4);   
128 129
//        *data_block++ = _mm_packs_epi16(t0, t1);     
       _mm_storeu_si128(data_block++, _mm_packs_epi16(t0, t1));     
130 131 132 133 134
      }
      
      // Write the packet to the fronthaul
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                        packet_id,
135
                                        (void**)&tx_buffer,
136 137 138 139 140
                                        db_fulllength,
                                        1,
                                        IF5_MOBIPASS)) < 0) {
        perror("ETHERNET write for IF5_MOBIPASS\n");
      }
141 142 143 144 145
#ifdef DEBUG_DL_MOBIPASS
     if ((subframe==0)&&(dummy_cnt == 100)) {
        memcpy((void*)&dummy_buffer[packet_id*db_fulllength*2],(void*)data_block_head,db_fulllength*2);
      }
#endif
146 147 148
      header->seqno += 1;    
    }  
    *seqno = header->seqno;
149 150 151 152 153 154 155 156

#ifdef DEBUG_DL_MOBIPASS
    uint8_t txe;
    txe = dB_fixed(signal_energy(txp[0],fp->samples_per_tti));
    if (txe > 0){
      LOG_D(PHY,"[Mobipass] frame:%d, subframe:%d, energy %d\n", (proc_timestamp/(10*fp->samples_per_tti))&1023,subframe, txe);
    }
#endif  
157 158 159 160 161
  } else {    
    AssertFatal(1==0, "send_IF5 - Unknown packet_type %x", packet_type);     
  }  
  
  free(tx_buffer);
162
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF5, 0 );  
163 164 165 166 167 168 169 170 171 172
#ifdef DEBUG_DL_MOBIPASS 
  if(subframe==0) {
    if (dummy_cnt==100) {
      write_output("txsigmb.m","txs",(void*)dummy_buffer, fp->samples_per_tti,1, 5); 
      exit(-1);
    } else {
    dummy_cnt++;
    }
  }
#endif
173 174 175 176
  return;  		    
}


Sandeep Kumar's avatar
Sandeep Kumar committed
177
void recv_IF5(PHY_VARS_eNB *eNB, openair0_timestamp *proc_timestamp, int subframe, uint16_t packet_type) {
178 179

  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
180 181
  int32_t *txp[fp->nb_antennas_tx], *rxp[fp->nb_antennas_rx]; 

182
  uint16_t packet_id=0, i=0;
183 184
  int8_t dummy_buffer_rx[fp->samples_per_tti*2];
  uint8_t rxe;
185 186 187 188 189

  int32_t spp_eth  = (int32_t) eNB->ifdevice.openair0_cfg->samples_per_packet;
  int32_t spsf     = (int32_t) eNB->ifdevice.openair0_cfg->samples_per_frame/10;

  openair0_timestamp timestamp[spsf / spp_eth];
190 191

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF5, 1 );  
192
  
Sandeep Kumar's avatar
Sandeep Kumar committed
193
  if (packet_type == IF5_RRH_GW_DL) {
194
        
Sandeep Kumar's avatar
Sandeep Kumar committed
195 196
    for (i=0; i < fp->nb_antennas_tx; i++)
      txp[i] = (void*)&eNB->common_vars.txdata[0][i][subframe*fp->samples_per_tti];
197 198
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
199

200
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 1 );  
201 202
      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                  &timestamp[packet_id],
203
                                  (void**)txp,
204
                                  spp_eth,
Sandeep Kumar's avatar
Sandeep Kumar committed
205
                                  fp->nb_antennas_tx);
206
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 0 );  
207 208 209
      for (i=0; i < fp->nb_antennas_tx; i++)
        txp[i] += spp_eth;

210 211
    }
    
Sandeep Kumar's avatar
Sandeep Kumar committed
212 213
    *proc_timestamp = timestamp[0];
    
214
  } else if (packet_type == IF5_RRH_GW_UL) { 
Sandeep Kumar's avatar
Sandeep Kumar committed
215 216 217
    
    for (i=0; i < fp->nb_antennas_rx; i++)
      rxp[i] = (void*)&eNB->common_vars.rxdata[0][i][subframe*fp->samples_per_tti];
218
    
Sandeep Kumar's avatar
Sandeep Kumar committed
219
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
220
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 1 );            
Sandeep Kumar's avatar
Sandeep Kumar committed
221 222
      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                  &timestamp[packet_id],
223
                                  (void**)rxp,
Sandeep Kumar's avatar
Sandeep Kumar committed
224 225
                                  spp_eth,
                                  fp->nb_antennas_rx);
226
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 0 );            
227 228 229
      for (i=0; i < fp->nb_antennas_rx; i++)
        rxp[i] += spp_eth;

Sandeep Kumar's avatar
Sandeep Kumar committed
230 231 232 233
    }

    *proc_timestamp = timestamp[0];
      
234 235
  } else if (packet_type == IF5_MOBIPASS) {
    
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    uint16_t db_fulllength = PAYLOAD_MOBIPASS_NUM_SAMPLES;
    openair0_timestamp timestamp_mobipass[fp->samples_per_tti/db_fulllength];
    int lower_offset = 0;
    int  upper_offset = 70000;
    int subframe_skip = 0;
    int reset_flag = 0;
    int32_t *rx_buffer=NULL;
    __m128i *data_block=NULL, *data_block_head=NULL;
    __m128i *rxp128;
    __m128i r0, r1;

    //rx_buffer = memalign(16, MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + db_fulllength*sizeof(int16_t));
    rx_buffer = malloc(MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + db_fulllength*sizeof(int16_t));
    IF5_mobipass_header_t *header = (IF5_mobipass_header_t *)((uint8_t *)rx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block_head = (__m128i *)((uint8_t *)rx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t);
 
    rxp[0] = (void*)&eNB->common_vars.rxdata[0][0][subframe*eNB->frame_parms.samples_per_tti];
    rxp128 = (__m128i *) (rxp[0]);
 
    eNB_proc_t *proc = &eNB->proc;
/*
 //   while(packet_id<fp->samples_per_tti/db_fulllength) {
      data_block = data_block_head;

      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                       &ts0,
                                       (void**)&rx_buffer,
                                       db_fulllength,
                                        1
                                        );

      if ((header->seqno == 1)&&(first_packet==1))  { 
         first_packet = 0;  //ignore the packets before synchnorization
         packet_id = 0;
        ts_offset = ntohl(ts0);
      } 
      if (first_packet==0) { 
        packet_cnt++;
        ts = ntohl(ts0);
        packet_id = (ts-ts_offset)/db_fulllength;
        packet_id = packet_id % (fp->samples_per_tti/db_fulllength);

        printf("[IF5_tools]packet_id:%d\n", packet_id);
        // if (ts_stored == 0) {
        //   ts_stored = 1;
        *proc_timestamp = ntohl(ts - (packet_id*db_fulllength));
        // }
        rxp[0] = (void*)&eNB->common_vars.rxdata[0][0][(subframe*eNB->frame_parms.samples_per_tti)+packet_id*db_fulllength];
        rxp128 = (__m128i *) (rxp[0]);

        for (i=0; i<db_fulllength>>2; i+=2) {
          r0 = _mm_loadu_si128(data_block++);
          *rxp128++ =_mm_slli_epi16(_mm_srai_epi16(_mm_unpacklo_epi8(r0,r0),8),4);
          *rxp128++ =_mm_slli_epi16(_mm_srai_epi16(_mm_unpackhi_epi8(r0,r0),8),4);
        }
      }
  //  }//end while
*/
 

    packet_id=0; 
    while(packet_id<fp->samples_per_tti/db_fulllength) {
      data_block = data_block_head;

      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                       &timestamp_mobipass[packet_id],
                                       (void**)&rx_buffer,
                                       db_fulllength,
                                        1
                                        );
#ifdef DEBUG_UL_MOBIPASS
      if (((proc->timestamp_tx + lower_offset) > ntohl(timestamp_mobipass[packet_id])) || ((proc->timestamp_tx + upper_offset) < ntohl(timestamp_mobipass[packet_id]))) {
        //ignore the packet
        subframe_skip_extra = (subframe_skip_extra + 1)%67;         
       LOG_D("[Mobipass] ignored packet, id:[%d,%d], proc->timestamp_tx:%llu, proc->timestamp_rx:%llu, seqno:%d\n", packet_id,subframe_skip_extra, proc->timestamp_tx, ntohl(timestamp_mobipass[packet_id]), header->seqno);
      }             
#endif
      //skip SUBFRAME_SKIP_NUM_MOBIPASS additional UL packets
      if ((start_flag == 1) && (subframe_skip < SUBFRAME_SKIP_NUM_MOBIPASS)){
        subframe_skip++;
        offset_cnt = header->seqno;
      } else {
        if ((offset_cnt != header->seqno) && (start_flag == 0) && (proc->first_rx > 3)){
#ifdef DEBUG_UL_MOBIPASS
           LOG_D(PHY,"[Mobipass] Reset sequence number, offset_cnt:%d, header->seqno:%d, packet_id:%d\n", offset_cnt, header->seqno, packet_id);
#endif
           reset_flag=1;
        }
        if ((reset_flag == 1) && (proc->first_rx > 3 ) && (start_flag == 0) && (packet_id == 0)) {
           packet_id = 1;  
           reset_flag = 0;
        }
        start_flag = 0;

        //store rxdata and increase packet_id
        rxp[0] = (void*)&eNB->common_vars.rxdata[0][0][(subframe*eNB->frame_parms.samples_per_tti)+packet_id*db_fulllength];
        rxp128 = (__m128i *) (rxp[0]);
        for (i=0; i<db_fulllength>>2; i+=2) {
          r0 = _mm_loadu_si128(data_block++);
          *rxp128++ =_mm_slli_epi16(_mm_srai_epi16(_mm_unpacklo_epi8(r0,r0),8),4);
          *rxp128++ =_mm_slli_epi16(_mm_srai_epi16(_mm_unpackhi_epi8(r0,r0),8),4);
        }   
        packet_id++; 
        offset_cnt = (header->seqno+1)&255;
      }
    }//end while
  
      *proc_timestamp = ntohl(timestamp_mobipass[0]); 
#ifdef DEBUG_UL_MOBIPASS
   LOG_I(PHY,"[Mobipass][Recv_MOBIPASS] timestamp: %llu\n ",  *proc_timestamp);
if (eNB->CC_id>0) {
    rxe = dB_fixed(signal_energy(rxp[0],fp->samples_per_tti)); 
    if (rxe > 0){
      LOG_I(PHY,"[Mobipass] frame:%d, subframe:%d, energy %d\n", (*proc_timestamp/(10*fp->samples_per_tti))&1023,subframe, rxe);
//    write_output("rxsigmb.m","rxs",(void*)dummy_buffer_rx, fp->samples_per_tti,1, 5); 
//    exit(-1);
    }
}
#endif


   
358 359 360
  } else {
    AssertFatal(1==0, "recv_IF5 - Unknown packet_type %x", packet_type);     
  }  
361 362

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF5, 0 );  
363 364 365
  
  return;  
}