Ejemplo n.º 1
0
/* Read from a Netmap device, creating a new packet.
 
   TODO: avoid extra copy by holding netmap buffer.  Also 
   investigate zero copy. */
struct fp_packet*
fp_netmap_recv(struct fp_device* device)
{
  struct fp_netmap_device* dev = (struct fp_netmap_device*)device;
  unsigned char const* src;
  unsigned char* dst;
  struct fp_packet* packet;

  src = nm_nextpkt(dev->handle, &dev->header);
  if (src == NULL)
    return NULL; /* nothing waiting */

  /* Copy the buffer and create a new packet for it. */
  dst = (unsigned char*)malloc(dev->header.len);
  memcpy(dst, src, dev->header.len);

  /* Allocate a flowpath packet. */
  /* TODO: replace dev_handle(NULL) with netmap buffer */
  /* TODO: retrieve timestamp from ring */
  packet = fp_packet_create(dst, dev->header.len, 0
                            NULL, FP_BUF_NETMAP);
  return packet;
}
Ejemplo n.º 2
0
static void
pci_vtnet_netmap_rx(struct pci_vtnet_softc *sc)
{
	struct iovec iov[VTNET_MAXSEGS], *riov;
	struct vqueue_info *vq;
	void *vrx;
	int len, n;
	uint16_t idx;

	/*
	 * Should never be called without a valid netmap descriptor
	 */
	assert(sc->vsc_nmd != NULL);

	/*
	 * But, will be called when the rx ring hasn't yet
	 * been set up or the guest is resetting the device.
	 */
	if (!sc->vsc_rx_ready || sc->resetting) {
		/*
		 * Drop the packet and try later.
		 */
		(void) nm_nextpkt(sc->vsc_nmd, (void *)dummybuf);
		return;
	}

	/*
	 * Check for available rx buffers
	 */
	vq = &sc->vsc_queues[VTNET_RXQ];
	if (!vq_has_descs(vq)) {
		/*
		 * Drop the packet and try later.  Interrupt on
		 * empty, if that's negotiated.
		 */
		(void) nm_nextpkt(sc->vsc_nmd, (void *)dummybuf);
		vq_endchains(vq, 1);
		return;
	}

	do {
		/*
		 * Get descriptor chain.
		 */
		n = vq_getchain(vq, &idx, iov, VTNET_MAXSEGS, NULL);
		assert(n >= 1 && n <= VTNET_MAXSEGS);

		/*
		 * Get a pointer to the rx header, and use the
		 * data immediately following it for the packet buffer.
		 */
		vrx = iov[0].iov_base;
		riov = rx_iov_trim(iov, &n, sc->rx_vhdrlen);

		len = pci_vtnet_netmap_readv(sc->vsc_nmd, riov, n);

		if (len == 0) {
			/*
			 * No more packets, but still some avail ring
			 * entries.  Interrupt if needed/appropriate.
			 */
			vq_retchain(vq);
			vq_endchains(vq, 0);
			return;
		}

		/*
		 * The only valid field in the rx packet header is the
		 * number of buffers if merged rx bufs were negotiated.
		 */
		memset(vrx, 0, sc->rx_vhdrlen);

		if (sc->rx_merge) {
			struct virtio_net_rxhdr *vrxh;

			vrxh = vrx;
			vrxh->vrh_bufs = 1;
		}

		/*
		 * Release this chain and handle more chains.
		 */
		vq_relchain(vq, idx, len + sc->rx_vhdrlen);
	} while (vq_has_descs(vq));

	/* Interrupt if needed, including for NOTIFY_ON_EMPTY. */
	vq_endchains(vq, 1);
}