static void ef_vi_init(struct client_state* cs, const char* interface)
{
  cs->pio_pkt_len = 0;
  cs->pio_in_use = ! cfg_delegated;
  TRY( ef_driver_open(&(cs->dh)) );
  TRY( ef_pd_alloc_by_name(&(cs->pd), cs->dh, interface, EF_PD_DEFAULT) );
  TRY( ef_vi_alloc_from_pd(&(cs->vi), cs->dh, &(cs->pd), cs->dh,
                              -1, 0,-1, NULL, -1, EF_VI_FLAGS_DEFAULT) );
  TRY( ef_pio_alloc(&(cs->pio), cs->dh, &(cs->pd), -1, cs->dh));
  TRY( ef_pio_link_vi(&(cs->pio), cs->dh, &(cs->vi), cs->dh));
}
Example #2
0
static void do_init(int ifindex)
{
  enum ef_pd_flags pd_flags = 0;
  ef_filter_spec filter_spec;
  struct pkt_buf* pb;
  enum ef_vi_flags vi_flags = 0;
  int i;

  if( cfg_use_vf )
    pd_flags |= EF_PD_VF;
  if( cfg_phys_mode )
    pd_flags |= EF_PD_PHYS_MODE;
  if( cfg_disable_tx_push )
    vi_flags |= EF_VI_TX_PUSH_DISABLE;

  /* Allocate virtual interface. */
  TRY(ef_driver_open(&driver_handle));
  TRY(ef_pd_alloc(&pd, driver_handle, ifindex, pd_flags));
  TRY(ef_vi_alloc_from_pd(&vi, driver_handle, &pd, driver_handle,
                          -1, -1, -1, NULL, -1, vi_flags));
#ifdef __x86_64__
  TRY(ef_pio_alloc(&pio, driver_handle, &pd, -1, driver_handle));
  TRY(ef_pio_link_vi(&pio, driver_handle, &vi, driver_handle));
#else
  /* PIO is only available on x86_64 systems */
  TEST(0);
#endif

  ef_filter_spec_init(&filter_spec, EF_FILTER_FLAG_NONE);
  TRY(ef_filter_spec_set_ip4_local(&filter_spec, IPPROTO_UDP,
                                   sa_local.sin_addr.s_addr,
                                   sa_local.sin_port));
  TRY(ef_vi_filter_add(&vi, driver_handle, &filter_spec, NULL));

  {
    int bytes = (N_RX_BUFS + 1) * RX_BUF_SIZE;
    void* p;
    TEST(posix_memalign(&p, 4096, bytes) == 0);
    TRY(ef_memreg_alloc(&memreg, driver_handle, &pd, driver_handle, p, bytes));
    for( i = 0; i <= N_RX_BUFS; ++i ) {
      pkt_bufs[i] = (void*) ((char*) p + i * RX_BUF_SIZE);
      pkt_bufs[i]->dma_buf_addr = ef_memreg_dma_addr(&memreg, i * RX_BUF_SIZE);
    }
  }

  for( i = 0; i <= N_RX_BUFS; ++i ) {
    pb = pkt_bufs[i];
    pb->id = i;
    pb->dma_buf_addr += MEMBER_OFFSET(struct pkt_buf, dma_buf);
  }

  init_udp_pkt(pkt_bufs[N_RX_BUFS]->dma_buf, cfg_payload_len);
  tx_frame_len = cfg_payload_len + header_size();
}