int vi_send(struct vi* vi, struct pkt_buf* pkt_buf, int off, int len) { int rc; rc = ef_vi_transmit(&vi->vi, pkt_buf->addr[vi->net_if->id] + off, len, MK_TX_RQ_ID(pkt_buf->vi_owner->id, pkt_buf->id)); if( rc == 0 ) ++pkt_buf->n_refs; return rc; }
/* Handle an RX event on a VI. We forward the packet on the other VI. */ static void handle_rx(int rx_vi_i, int pkt_buf_i, int len) { int rc; int tx_vi_i = 2 - 1 - rx_vi_i; struct vi* rx_vi = &vis[rx_vi_i]; struct vi* tx_vi = &vis[tx_vi_i]; struct pkt_buf* pkt_buf = pkt_buf_from_id(pkt_buf_i); ++rx_vi->n_pkts; rc = ef_vi_transmit(&tx_vi->vi, pkt_buf->tx_ef_addr[tx_vi_i], len, pkt_buf->id); if( rc != 0 ) { assert(rc == -EAGAIN); /* TXQ is full. A real app might consider implementing an overflow * queue in software. We simply choose not to send. */ pkt_buf_free(pkt_buf); } }
static void rx_wait(void) { ef_request_id ids[EF_VI_TRANSMIT_BATCH]; ef_event evs[EF_VI_EVENT_POLL_MIN_EVS]; int n_ev, i; while( 1 ) { n_ev = ef_eventq_poll(&vi, evs, sizeof(evs) / sizeof(evs[0])); if( n_ev > 0 ) { for( i = 0; i < n_ev; ++i ) switch( EF_EVENT_TYPE(evs[i]) ) { case EF_EVENT_TYPE_RX: TEST(EF_EVENT_RX_SOP(evs[i]) == 1); TEST(EF_EVENT_RX_CONT(evs[i]) == 0); TEST((int) (rx_posted - rx_completed) > 0); ++rx_completed; return; case EF_EVENT_TYPE_TX: ef_vi_transmit_unbundle(&vi, &evs[i], ids); break; case EF_EVENT_TYPE_RX_DISCARD: fprintf(stderr, "ERROR: RX_DISCARD type=%d\n", EF_EVENT_RX_DISCARD_TYPE(evs[i])); break; case EF_EVENT_TYPE_TX_ERROR: fprintf(stderr, "ERROR: TX_ERROR type=%d\n", EF_EVENT_TX_ERROR_TYPE(evs[i])); break; default: fprintf(stderr, "ERROR: unexpected event "EF_EVENT_FMT"\n", EF_EVENT_PRI_ARG(evs[i])); break; } } else if( cfg_eventq_wait ) { TRY(ef_eventq_wait(&vi, driver_handle, ef_eventq_current(&vi), 0)); } else if( cfg_fd_wait ) { TRY(ef_vi_prime(&vi, driver_handle, ef_eventq_current(&vi))); struct pollfd pollfd = { .fd = driver_handle, .events = POLLIN, .revents = 0, }; TRY(poll(&pollfd, 1, -1)); } } } static void tx_send(void) { struct pkt_buf* pb = pkt_bufs[FIRST_TX_BUF]; ef_vi_transmit(&vi, pb->dma_buf_addr, tx_frame_len, 0); } /**********************************************************************/ static void pong_test(void) { int i; rx_post_8(); for( i = 0; i < cfg_iter; ++i ) { rx_wait(); tx_send(); if( i % 8 == 0 ) rx_post_8(); } }