FreeBSD/sys/dev/stge/if_stge.c
/*
 * stge_newbuf:
 *
 *	Add a receive buffer to the indicated descriptor.
 */
Add a receive buffer to the indicated descriptor.
Add a receive buffer to the indicated descriptor .
static int
stge_newbuf(struct stge_softc *sc, int idx)
{
	struct stge_rxdesc *rxd;
	struct stge_rfd *rfd;
	struct mbuf *m;
	bus_dma_segment_t segs[1];
	bus_dmamap_t map;
	int nsegs;
	m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
	if (m == NULL)
		return (ENOBUFS);
	m->m_len = m->m_pkthdr.len = MCLBYTES;
	if (sc->sc_if_framesize <= (MCLBYTES - ETHER_ALIGN))
		m_adj(m, ETHER_ALIGN);
	if (bus_dmamap_load_mbuf_sg(sc->sc_cdata.stge_rx_tag,
	    sc->sc_cdata.stge_rx_sparemap, m, segs, &nsegs, 0) != 0) {
		m_freem(m);
		return (ENOBUFS);
	}
	KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
	rxd = &sc->sc_cdata.stge_rxdesc[idx];
	if (rxd->rx_m != NULL) {
		bus_dmamap_sync(sc->sc_cdata.stge_rx_tag, rxd->rx_dmamap,
		    BUS_DMASYNC_POSTREAD);
		bus_dmamap_unload(sc->sc_cdata.stge_rx_tag, rxd->rx_dmamap);
	}
	map = rxd->rx_dmamap;
	rxd->rx_dmamap = sc->sc_cdata.stge_rx_sparemap;
	sc->sc_cdata.stge_rx_sparemap = map;
	bus_dmamap_sync(sc->sc_cdata.stge_rx_tag, rxd->rx_dmamap,
	    BUS_DMASYNC_PREREAD);
	rxd->rx_m = m;
	rfd = &sc->sc_rdata.stge_rx_ring[idx];
	rfd->rfd_frag.frag_word0 =
	    htole64(FRAG_ADDR(segs[0].ds_addr) | FRAG_LEN(segs[0].ds_len));
	rfd->rfd_status = 0;
	return (0);
}
static int stge_newbuf ( struct stge_softc * sc , int idx ) { struct stge_rxdesc * rxd ; struct stge_rfd * rfd ; struct mbuf * m ; bus_dma_segment_t segs [ 1 ] ; bus_dmamap_t map ; int nsegs ; m = m_getcl ( M_NOWAIT , MT_DATA , M_PKTHDR ) ; if ( m == NULL ) return ( ENOBUFS ) ; m -> m_len = m -> m_pkthdr . len = MCLBYTES ; if ( sc -> sc_if_framesize <= ( MCLBYTES - ETHER_ALIGN ) ) m_adj ( m , ETHER_ALIGN ) ; if ( bus_dmamap_load_mbuf_sg ( sc -> sc_cdata . stge_rx_tag , sc -> sc_cdata . stge_rx_sparemap , m , segs , & nsegs , 0 ) != 0 ) { m_freem ( m ) ; return ( ENOBUFS ) ; } KASSERT ( nsegs == 1 , ( " " , __func__ , nsegs ) ) ; rxd = & sc -> sc_cdata . stge_rxdesc [ idx ] ; if ( rxd -> rx_m != NULL ) { bus_dmamap_sync ( sc -> sc_cdata . stge_rx_tag , rxd -> rx_dmamap , BUS_DMASYNC_POSTREAD ) ; bus_dmamap_unload ( sc -> sc_cdata . stge_rx_tag , rxd -> rx_dmamap ) ; } map = rxd -> rx_dmamap ; rxd -> rx_dmamap = sc -> sc_cdata . stge_rx_sparemap ; sc -> sc_cdata . stge_rx_sparemap = map ; bus_dmamap_sync ( sc -> sc_cdata . stge_rx_tag , rxd -> rx_dmamap , BUS_DMASYNC_PREREAD ) ; rxd -> rx_m = m ; rfd = & sc -> sc_rdata . stge_rx_ring [ idx ] ; rfd -> rfd_frag . frag_word0 = htole64 ( FRAG_ADDR ( segs [ 0 ] . ds_addr ) | FRAG_LEN ( segs [ 0 ] . ds_len ) ) ; rfd -> rfd_status = 0 ; return ( 0 ) ; }
stge_newbuf:
      Add a receive buffer to the indicated descriptor.
stge_newbuf : Add a receive buffer to the indicated descriptor .
/*
	 * The hardware requires 4bytes aligned DMA address when JUMBO
	 * frame is used.
	 */