FreeBSD/sys/dev/e1000/if_em.c
/*********************************************************************
 *
 *  Refresh RX descriptor mbufs from system mbuf buffer pool.
 *
 **********************************************************************/
Refresh RX descriptor mbufs from system mbuf buffer pool.
Refresh RX descriptor mbufs from system mbuf buffer pool .
static void
em_refresh_mbufs(struct rx_ring *rxr, int limit)
{
	struct adapter		*adapter = rxr->adapter;
	struct mbuf		*m;
	bus_dma_segment_t	segs;
	struct em_rxbuffer	*rxbuf;
	int			i, j, error, nsegs;
	bool			cleaned = FALSE;
	i = j = rxr->next_to_refresh;
	if (++j == adapter->num_rx_desc)
		j = 0;
	while (j != limit) {
		rxbuf = &rxr->rx_buffers[i];
		if (rxbuf->m_head == NULL) {
			m = m_getjcl(M_NOWAIT, MT_DATA,
			    M_PKTHDR, adapter->rx_mbuf_sz);
			if (m == NULL)
				goto update;
		} else
			m = rxbuf->m_head;
		m->m_len = m->m_pkthdr.len = adapter->rx_mbuf_sz;
		m->m_flags |= M_PKTHDR;
		m->m_data = m->m_ext.ext_buf;
		error = bus_dmamap_load_mbuf_sg(rxr->rxtag, rxbuf->map,
		    m, &segs, &nsegs, BUS_DMA_NOWAIT);
		if (error != 0) {
			printf("Refresh mbufs: hdr dmamap load"
			    " failure - %d\n", error);
			m_free(m);
			rxbuf->m_head = NULL;
			goto update;
		}
		rxbuf->m_head = m;
		rxbuf->paddr = segs.ds_addr;
		bus_dmamap_sync(rxr->rxtag,
		    rxbuf->map, BUS_DMASYNC_PREREAD);
		em_setup_rxdesc(&rxr->rx_base[i], rxbuf);
		cleaned = TRUE;
		i = j; 
		rxr->next_to_refresh = i;
		if (++j == adapter->num_rx_desc)
			j = 0;
	}
update:
	if (cleaned)
		E1000_WRITE_REG(&adapter->hw,
		    E1000_RDT(rxr->me), rxr->next_to_refresh);
	return;
}
static void em_refresh_mbufs ( struct rx_ring * rxr , int limit ) { struct adapter * adapter = rxr -> adapter ; struct mbuf * m ; bus_dma_segment_t segs ; struct em_rxbuffer * rxbuf ; int i , j , error , nsegs ; bool cleaned = FALSE ; i = j = rxr -> next_to_refresh ; if ( ++ j == adapter -> num_rx_desc ) j = 0 ; while ( j != limit ) { rxbuf = & rxr -> rx_buffers [ i ] ; if ( rxbuf -> m_head == NULL ) { m = m_getjcl ( M_NOWAIT , MT_DATA , M_PKTHDR , adapter -> rx_mbuf_sz ) ; if ( m == NULL ) goto update ; } else m = rxbuf -> m_head ; m -> m_len = m -> m_pkthdr . len = adapter -> rx_mbuf_sz ; m -> m_flags |= M_PKTHDR ; m -> m_data = m -> m_ext . ext_buf ; error = bus_dmamap_load_mbuf_sg ( rxr -> rxtag , rxbuf -> map , m , & segs , & nsegs , BUS_DMA_NOWAIT ) ; if ( error != 0 ) { printf ( " " " \n " , error ) ; m_free ( m ) ; rxbuf -> m_head = NULL ; goto update ; } rxbuf -> m_head = m ; rxbuf -> paddr = segs . ds_addr ; bus_dmamap_sync ( rxr -> rxtag , rxbuf -> map , BUS_DMASYNC_PREREAD ) ; em_setup_rxdesc ( & rxr -> rx_base [ i ] , rxbuf ) ; cleaned = TRUE ; i = j ; rxr -> next_to_refresh = i ; if ( ++ j == adapter -> num_rx_desc ) j = 0 ; } update : if ( cleaned ) E1000_WRITE_REG ( & adapter -> hw , E1000_RDT ( rxr -> me ) , rxr -> next_to_refresh ) ; return ; }
Refresh RX descriptor mbufs from system mbuf buffer pool.
Refresh RX descriptor mbufs from system mbuf buffer pool .
/*
	** Get one descriptor beyond
	** our work mark to control
	** the loop.
	*/ /*
			** If we have a temporary resource shortage
			** that causes a failure, just abort refresh
			** for now, we will return to this point when
			** reinvoked from em_rxeof.
			*/ /* Use bus_dma machinery to setup the memory mapping  */ /* Next is precalulated for us */ /* Calculate next controlling index */ /*
	** Update the tail pointer only if,
	** and as far as we have refreshed.
	*/