FreeBSD/sys/dev/e1000/if_lem.c
/*********************************************************************
 *
 *  Get a buffer from system mbuf buffer pool.
 *
 **********************************************************************/
Get a buffer from system mbuf buffer pool.
Get a buffer from system mbuf buffer pool .
static int
lem_get_buf(struct adapter *adapter, int i)
{
	struct mbuf		*m;
	bus_dma_segment_t	segs[1];
	bus_dmamap_t		map;
	struct em_buffer	*rx_buffer;
	int			error, nsegs;
	m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
	if (m == NULL) {
		adapter->mbuf_cluster_failed++;
		return (ENOBUFS);
	}
	m->m_len = m->m_pkthdr.len = MCLBYTES;
	if (adapter->max_frame_size <= (MCLBYTES - ETHER_ALIGN))
		m_adj(m, ETHER_ALIGN);
	error = bus_dmamap_load_mbuf_sg(adapter->rxtag,
	    adapter->rx_sparemap, m, segs, &nsegs, BUS_DMA_NOWAIT);
	if (error != 0) {
		m_free(m);
		return (error);
	}
	KASSERT(nsegs == 1, ("Too many segments returned!"));
	rx_buffer = &adapter->rx_buffer_area[i];
	if (rx_buffer->m_head != NULL)
		bus_dmamap_unload(adapter->rxtag, rx_buffer->map);
	map = rx_buffer->map;
	rx_buffer->map = adapter->rx_sparemap;
	adapter->rx_sparemap = map;
	bus_dmamap_sync(adapter->rxtag, rx_buffer->map, BUS_DMASYNC_PREREAD);
	rx_buffer->m_head = m;
	adapter->rx_desc_base[i].buffer_addr = htole64(segs[0].ds_addr);
	return (0);
}
static int lem_get_buf ( struct adapter * adapter , int i ) { struct mbuf * m ; bus_dma_segment_t segs [ 1 ] ; bus_dmamap_t map ; struct em_buffer * rx_buffer ; int error , nsegs ; m = m_getcl ( M_NOWAIT , MT_DATA , M_PKTHDR ) ; if ( m == NULL ) { adapter -> mbuf_cluster_failed ++ ; return ( ENOBUFS ) ; } m -> m_len = m -> m_pkthdr . len = MCLBYTES ; if ( adapter -> max_frame_size <= ( MCLBYTES - ETHER_ALIGN ) ) m_adj ( m , ETHER_ALIGN ) ; error = bus_dmamap_load_mbuf_sg ( adapter -> rxtag , adapter -> rx_sparemap , m , segs , & nsegs , BUS_DMA_NOWAIT ) ; if ( error != 0 ) { m_free ( m ) ; return ( error ) ; } KASSERT ( nsegs == 1 , ( " " ) ) ; rx_buffer = & adapter -> rx_buffer_area [ i ] ; if ( rx_buffer -> m_head != NULL ) bus_dmamap_unload ( adapter -> rxtag , rx_buffer -> map ) ; map = rx_buffer -> map ; rx_buffer -> map = adapter -> rx_sparemap ; adapter -> rx_sparemap = map ; bus_dmamap_sync ( adapter -> rxtag , rx_buffer -> map , BUS_DMASYNC_PREREAD ) ; rx_buffer -> m_head = m ; adapter -> rx_desc_base [ i ] . buffer_addr = htole64 ( segs [ 0 ] . ds_addr ) ; return ( 0 ) ; }
Get a buffer from system mbuf buffer pool.
Get a buffer from system mbuf buffer pool .
/*
	 * Using memory from the mbuf cluster pool, invoke the
	 * bus_dma machinery to arrange the memory mapping.
	 */ /* If nsegs is wrong then the stack is corrupt. */