FreeBSD/sys/dev/cadence/if_cgem.c
/* Fill receive descriptor ring with mbufs. */
Fill receive descriptor ring with mbufs.
Fill receive descriptor ring with mbufs .
static void
cgem_fill_rqueue(struct cgem_softc *sc)
{
	struct mbuf *m = NULL;
	bus_dma_segment_t segs[TX_MAX_DMA_SEGS];
	int nsegs;
	CGEM_ASSERT_LOCKED(sc);
	while (sc->rxring_queued < sc->rxbufs) {
		m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
		if (m == NULL)
			break;
		m->m_len = MCLBYTES;
		m->m_pkthdr.len = MCLBYTES;
		m->m_pkthdr.rcvif = sc->ifp;
		if (bus_dmamap_create(sc->mbuf_dma_tag, 0,
			      &sc->rxring_m_dmamap[sc->rxring_hd_ptr])) {
			sc->rxdmamapfails++;
			m_free(m);
			break;
		}
		if (bus_dmamap_load_mbuf_sg(sc->mbuf_dma_tag, 
			      sc->rxring_m_dmamap[sc->rxring_hd_ptr], m,
			      segs, &nsegs, BUS_DMA_NOWAIT)) {
			sc->rxdmamapfails++;
			bus_dmamap_destroy(sc->mbuf_dma_tag,
				   sc->rxring_m_dmamap[sc->rxring_hd_ptr]);
			sc->rxring_m_dmamap[sc->rxring_hd_ptr] = NULL;
			m_free(m);
			break;
		}
		sc->rxring_m[sc->rxring_hd_ptr] = m;
		bus_dmamap_sync(sc->mbuf_dma_tag,
				sc->rxring_m_dmamap[sc->rxring_hd_ptr],
				BUS_DMASYNC_PREREAD);
		sc->rxring[sc->rxring_hd_ptr].ctl = 0;
		if (sc->rxring_hd_ptr == CGEM_NUM_RX_DESCS - 1) {
			sc->rxring[sc->rxring_hd_ptr].addr = segs[0].ds_addr |
				CGEM_RXDESC_WRAP;
			sc->rxring_hd_ptr = 0;
		} else
			sc->rxring[sc->rxring_hd_ptr++].addr = segs[0].ds_addr;
		sc->rxring_queued++;
	}
}
static void cgem_fill_rqueue ( struct cgem_softc * sc ) { struct mbuf * m = NULL ; bus_dma_segment_t segs [ TX_MAX_DMA_SEGS ] ; int nsegs ; CGEM_ASSERT_LOCKED ( sc ) ; while ( sc -> rxring_queued < sc -> rxbufs ) { m = m_getcl ( M_NOWAIT , MT_DATA , M_PKTHDR ) ; if ( m == NULL ) break ; m -> m_len = MCLBYTES ; m -> m_pkthdr . len = MCLBYTES ; m -> m_pkthdr . rcvif = sc -> ifp ; if ( bus_dmamap_create ( sc -> mbuf_dma_tag , 0 , & sc -> rxring_m_dmamap [ sc -> rxring_hd_ptr ] ) ) { sc -> rxdmamapfails ++ ; m_free ( m ) ; break ; } if ( bus_dmamap_load_mbuf_sg ( sc -> mbuf_dma_tag , sc -> rxring_m_dmamap [ sc -> rxring_hd_ptr ] , m , segs , & nsegs , BUS_DMA_NOWAIT ) ) { sc -> rxdmamapfails ++ ; bus_dmamap_destroy ( sc -> mbuf_dma_tag , sc -> rxring_m_dmamap [ sc -> rxring_hd_ptr ] ) ; sc -> rxring_m_dmamap [ sc -> rxring_hd_ptr ] = NULL ; m_free ( m ) ; break ; } sc -> rxring_m [ sc -> rxring_hd_ptr ] = m ; bus_dmamap_sync ( sc -> mbuf_dma_tag , sc -> rxring_m_dmamap [ sc -> rxring_hd_ptr ] , BUS_DMASYNC_PREREAD ) ; sc -> rxring [ sc -> rxring_hd_ptr ] . ctl = 0 ; if ( sc -> rxring_hd_ptr == CGEM_NUM_RX_DESCS - 1 ) { sc -> rxring [ sc -> rxring_hd_ptr ] . addr = segs [ 0 ] . ds_addr | CGEM_RXDESC_WRAP ; sc -> rxring_hd_ptr = 0 ; } else sc -> rxring [ sc -> rxring_hd_ptr ++ ] . addr = segs [ 0 ] . ds_addr ; sc -> rxring_queued ++ ; } }
Fill receive descriptor ring with mbufs.
Fill receive descriptor ring with mbufs .
/* Get a cluster mbuf. */ /* Load map and plug in physical address. */ /* Sync cache with receive buffer. */ /* Write rx descriptor and increment head pointer. */