FreeBSD/sys/mips/idt/if_kr.c
/*
 * Initialize an RX descriptor and attach an MBUF cluster.
 */
Initialize an RX descriptor and attach an MBUF cluster.
Initialize an RX descriptor and attach an MBUF cluster .
static int
kr_newbuf(struct kr_softc *sc, int idx)
{
	struct kr_desc		*desc;
	struct kr_rxdesc	*rxd;
	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;
	m_adj(m, sizeof(uint64_t));
	if (bus_dmamap_load_mbuf_sg(sc->kr_cdata.kr_rx_tag,
	    sc->kr_cdata.kr_rx_sparemap, m, segs, &nsegs, 0) != 0) {
		m_freem(m);
		return (ENOBUFS);
	}
	KASSERT(nsegs == 1, ("%s: %d segments returned!", __func__, nsegs));
	rxd = &sc->kr_cdata.kr_rxdesc[idx];
	if (rxd->rx_m != NULL) {
		bus_dmamap_sync(sc->kr_cdata.kr_rx_tag, rxd->rx_dmamap,
		    BUS_DMASYNC_POSTREAD);
		bus_dmamap_unload(sc->kr_cdata.kr_rx_tag, rxd->rx_dmamap);
	}
	map = rxd->rx_dmamap;
	rxd->rx_dmamap = sc->kr_cdata.kr_rx_sparemap;
	sc->kr_cdata.kr_rx_sparemap = map;
	bus_dmamap_sync(sc->kr_cdata.kr_rx_tag, rxd->rx_dmamap,
	    BUS_DMASYNC_PREREAD);
	rxd->rx_m = m;
	desc = rxd->desc;
	desc->kr_ca = segs[0].ds_addr;
	desc->kr_ctl |= KR_DMASIZE(segs[0].ds_len);
	rxd->saved_ca = desc->kr_ca ;
	rxd->saved_ctl = desc->kr_ctl ;
	return (0);
}
static int kr_newbuf ( struct kr_softc * sc , int idx ) { struct kr_desc * desc ; struct kr_rxdesc * rxd ; 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 ; m_adj ( m , sizeof ( uint64_t ) ) ; if ( bus_dmamap_load_mbuf_sg ( sc -> kr_cdata . kr_rx_tag , sc -> kr_cdata . kr_rx_sparemap , m , segs , & nsegs , 0 ) != 0 ) { m_freem ( m ) ; return ( ENOBUFS ) ; } KASSERT ( nsegs == 1 , ( " " , __func__ , nsegs ) ) ; rxd = & sc -> kr_cdata . kr_rxdesc [ idx ] ; if ( rxd -> rx_m != NULL ) { bus_dmamap_sync ( sc -> kr_cdata . kr_rx_tag , rxd -> rx_dmamap , BUS_DMASYNC_POSTREAD ) ; bus_dmamap_unload ( sc -> kr_cdata . kr_rx_tag , rxd -> rx_dmamap ) ; } map = rxd -> rx_dmamap ; rxd -> rx_dmamap = sc -> kr_cdata . kr_rx_sparemap ; sc -> kr_cdata . kr_rx_sparemap = map ; bus_dmamap_sync ( sc -> kr_cdata . kr_rx_tag , rxd -> rx_dmamap , BUS_DMASYNC_PREREAD ) ; rxd -> rx_m = m ; desc = rxd -> desc ; desc -> kr_ca = segs [ 0 ] . ds_addr ; desc -> kr_ctl |= KR_DMASIZE ( segs [ 0 ] . ds_len ) ; rxd -> saved_ca = desc -> kr_ca ; rxd -> saved_ctl = desc -> kr_ctl ; return ( 0 ) ; }
Initialize an RX descriptor and attach an MBUF cluster.
Initialize an RX descriptor and attach an MBUF cluster .