if5_tools.c 7.3 KB
Newer Older
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr

  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE

 *******************************************************************************/

/*! \file PHY/LTE_TRANSPORT/if5_tools.c
* \brief 
* \author S. Sandeep Kumar, Raymond Knopp
* \date 2016
* \version 0.1
* \company Eurecom
* \email: ee13b1025@iith.ac.in, knopp@eurecom.fr 
* \note
* \warning
*/

#include "PHY/defs.h"

#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"


Sandeep Kumar's avatar
Sandeep Kumar committed
46
void send_IF5(PHY_VARS_eNB *eNB, openair0_timestamp proc_timestamp, int subframe, uint8_t *seqno, uint16_t packet_type) {      
47 48
  
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
Sandeep Kumar's avatar
Sandeep Kumar committed
49
  void *txp[fp->nb_antennas_tx], *rxp[fp->nb_antennas_rx]; 
50 51 52 53
  void *tx_buffer=NULL;

  uint16_t packet_id=0, i=0;
  
Sandeep Kumar's avatar
Sandeep Kumar committed
54
  if (packet_type == IF5_RRH_GW_DL) {
55 56 57 58
    unsigned int spp_eth  = eNB->ifdevice.openair0_cfg->samples_per_packet;
    unsigned int spsf     = eNB->ifdevice.openair0_cfg->samples_per_frame/10;
    
    for (i=0; i < fp->nb_antennas_tx; i++)
Sandeep Kumar's avatar
Sandeep Kumar committed
59
      txp[i] = (void*)&eNB->common_vars.txdata[0][i][subframe*fp->samples_per_tti];
60 61
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
62 63 64
      for (i=0; i < fp->nb_antennas_tx; i++)
        txp[i] += packet_id*spp_eth;
    
65
      eNB->ifdevice.trx_write_func(&eNB->ifdevice,
Sandeep Kumar's avatar
Sandeep Kumar committed
66
                                   (proc_timestamp - eNB->ifdevice.openair0_cfg->tx_sample_advance + packet_id*spp_eth),
Sandeep Kumar's avatar
Sandeep Kumar committed
67
                                   txp,
68 69 70 71 72
                                   spp_eth,
                                   fp->nb_antennas_tx,
                                   0);
    }
    
Sandeep Kumar's avatar
Sandeep Kumar committed
73 74 75 76 77 78 79 80
  } else if (packet_type == IF5_RRH_GW_UL) {
    unsigned int spp_eth  = eNB->ifdevice.openair0_cfg->samples_per_packet;
    unsigned int spsf     = eNB->ifdevice.openair0_cfg->samples_per_frame/10;
    
    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++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
81 82 83
      for (i=0; i < fp->nb_antennas_rx; i++)
        rxp[i] += packet_id*spp_eth;

Sandeep Kumar's avatar
Sandeep Kumar committed
84 85
      eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                   (proc_timestamp + packet_id*spp_eth),
Sandeep Kumar's avatar
Sandeep Kumar committed
86
                                   rxp,
Sandeep Kumar's avatar
Sandeep Kumar committed
87 88 89 90
                                   spp_eth,
                                   fp->nb_antennas_rx,
                                   0);
    }    
91
    
Sandeep Kumar's avatar
Sandeep Kumar committed
92
  } else if (packet_type == IF5_MOBIPASS) {    
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    uint16_t db_fulllength=640;
    
    __m128i *data_block=NULL, *data_block_head=NULL;

    __m128i *txp128;
    __m128i t0, t1;

    tx_buffer = memalign(16, MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + db_fulllength*sizeof(int16_t));
    IF5_mobipass_header_t *header = (IF5_mobipass_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block_head = (__m128i *)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + 4);
    
    header->flags = 0;
    header->fifo_status = 0;  
    header->seqno = *seqno;
    header->ack = 0;
    header->word0 = 0;  
    
Sandeep Kumar's avatar
Sandeep Kumar committed
110
    txp[0] = (void*)&eNB->common_vars.txdata[0][0][subframe*eNB->frame_parms.samples_per_tti];
111 112 113
    txp128 = (__m128i *) txp[0];
              
    for (packet_id=0; packet_id<(fp->samples_per_tti*2)/db_fulllength; packet_id++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
114
      header->time_stamp = proc_timestamp + packet_id*db_fulllength; 
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
      data_block = data_block_head; 
    
      for (i=0; i<db_fulllength>>3; i+=2) {
        t0 = _mm_srli_epi16(*txp128++, 4);
        t1 = _mm_srli_epi16(*txp128++, 4);   
        
        *data_block++ = _mm_packs_epi16(t0, t1);     
      }
      
      // Write the packet to the fronthaul
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                        packet_id,
                                        &tx_buffer,
                                        db_fulllength,
                                        1,
                                        IF5_MOBIPASS)) < 0) {
        perror("ETHERNET write for IF5_MOBIPASS\n");
      }
    
      header->seqno += 1;    
    }  
    *seqno = header->seqno;
Sandeep Kumar's avatar
Sandeep Kumar committed
137
    
138 139 140 141 142 143 144 145 146
  } else {    
    AssertFatal(1==0, "send_IF5 - Unknown packet_type %x", packet_type);     
  }  
  
  free(tx_buffer);
  return;  		    
}


Sandeep Kumar's avatar
Sandeep Kumar committed
147
void recv_IF5(PHY_VARS_eNB *eNB, openair0_timestamp *proc_timestamp, int subframe, uint16_t packet_type) {
148 149

  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
Sandeep Kumar's avatar
Sandeep Kumar committed
150
  void *txp[fp->nb_antennas_tx], *rxp[fp->nb_antennas_rx]; 
151 152 153 154
  void *rx_buffer=NULL;

  uint16_t packet_id=0, i=0;
  
Sandeep Kumar's avatar
Sandeep Kumar committed
155
  if (packet_type == IF5_RRH_GW_DL) {
156 157 158 159 160
    unsigned int spp_eth  = eNB->ifdevice.openair0_cfg->samples_per_packet;
    unsigned int spsf     = eNB->ifdevice.openair0_cfg->samples_per_frame/10;
    
    openair0_timestamp timestamp[spsf / spp_eth];
    
Sandeep Kumar's avatar
Sandeep Kumar committed
161 162
    for (i=0; i < fp->nb_antennas_tx; i++)
      txp[i] = (void*)&eNB->common_vars.txdata[0][i][subframe*fp->samples_per_tti];
163 164
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
165 166 167
      for (i=0; i < fp->nb_antennas_tx; i++)
        txp[i] += packet_id*spp_eth;

168 169
      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                  &timestamp[packet_id],
Sandeep Kumar's avatar
Sandeep Kumar committed
170
                                  txp,
171
                                  spp_eth,
Sandeep Kumar's avatar
Sandeep Kumar committed
172
                                  fp->nb_antennas_tx);
173 174
    }
    
Sandeep Kumar's avatar
Sandeep Kumar committed
175 176 177 178 179 180 181 182 183 184
    *proc_timestamp = timestamp[0];
    
  } else if (packet_type == IF5_RRH_GW_UL) {
    unsigned int spp_eth  = eNB->ifdevice.openair0_cfg->samples_per_packet;
    unsigned int spsf     = eNB->ifdevice.openair0_cfg->samples_per_frame/10;
    
    openair0_timestamp timestamp[spsf / spp_eth];
    
    for (i=0; i < fp->nb_antennas_rx; i++)
      rxp[i] = (void*)&eNB->common_vars.rxdata[0][i][subframe*fp->samples_per_tti];
185
    
Sandeep Kumar's avatar
Sandeep Kumar committed
186
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
187 188 189
      for (i=0; i < fp->nb_antennas_tx; i++)
        rxp[i] += packet_id*spp_eth;

Sandeep Kumar's avatar
Sandeep Kumar committed
190 191
      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                  &timestamp[packet_id],
Sandeep Kumar's avatar
Sandeep Kumar committed
192
                                  rxp,
Sandeep Kumar's avatar
Sandeep Kumar committed
193 194 195 196 197 198
                                  spp_eth,
                                  fp->nb_antennas_rx);
    }

    *proc_timestamp = timestamp[0];
      
199 200 201 202 203 204 205 206 207 208
  } else if (packet_type == IF5_MOBIPASS) {
    
    
  } else {
    AssertFatal(1==0, "recv_IF5 - Unknown packet_type %x", packet_type);     
  }  
  
  free(rx_buffer);  
  return;  
}