FreeBSD/sys/dev/cadence/if_cgem.c
/* Create DMA'able descriptor rings. */
Create DMA'able descriptor rings.
Create DMA ' able descriptor rings .
static int
cgem_setup_descs(struct cgem_softc *sc)
{
	int i, err;
	sc->txring = NULL;
	sc->rxring = NULL;
	err = bus_dma_tag_create(bus_get_dma_tag(sc->dev), 1, 0,
				 BUS_SPACE_MAXADDR_32BIT,
				 BUS_SPACE_MAXADDR,
				 NULL, NULL,
				 MAX_DESC_RING_SIZE,
				 1,
				 MAX_DESC_RING_SIZE,
				 0,
				 busdma_lock_mutex,
				 &sc->sc_mtx,
				 &sc->desc_dma_tag);
	if (err)
		return (err);
	err = bus_dma_tag_create(bus_get_dma_tag(sc->dev), 1, 0,
				 BUS_SPACE_MAXADDR_32BIT,
				 BUS_SPACE_MAXADDR,
				 NULL, NULL,
				 MCLBYTES,
				 TX_MAX_DMA_SEGS,
				 MCLBYTES,
				 0,
				 busdma_lock_mutex,
				 &sc->sc_mtx,
				 &sc->mbuf_dma_tag);
	if (err)
		return (err);
	err = bus_dmamem_alloc(sc->desc_dma_tag,
			       (void **)&sc->rxring,
			       BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
			       &sc->rxring_dma_map);
	if (err)
		return (err);
	err = bus_dmamap_load(sc->desc_dma_tag, sc->rxring_dma_map,
			      (void *)sc->rxring,
			      CGEM_NUM_RX_DESCS*sizeof(struct cgem_rx_desc),
			      cgem_getaddr, &sc->rxring_physaddr,
			      BUS_DMA_NOWAIT);
	if (err)
		return (err);
	for (i = 0; i < CGEM_NUM_RX_DESCS; i++) {
		sc->rxring[i].addr = CGEM_RXDESC_OWN;
		sc->rxring[i].ctl = 0;
		sc->rxring_m[i] = NULL;
		sc->rxring_m_dmamap[i] = NULL;
	}
	sc->rxring[CGEM_NUM_RX_DESCS - 1].addr |= CGEM_RXDESC_WRAP;
	sc->rxring_hd_ptr = 0;
	sc->rxring_tl_ptr = 0;
	sc->rxring_queued = 0;
	err = bus_dmamem_alloc(sc->desc_dma_tag,
			       (void **)&sc->txring,
			       BUS_DMA_NOWAIT | BUS_DMA_COHERENT,
			       &sc->txring_dma_map);
	if (err)
		return (err);
	err = bus_dmamap_load(sc->desc_dma_tag, sc->txring_dma_map,
			      (void *)sc->txring,
			      CGEM_NUM_TX_DESCS*sizeof(struct cgem_tx_desc),
			      cgem_getaddr, &sc->txring_physaddr, 
			      BUS_DMA_NOWAIT);
	if (err)
		return (err);
	for (i = 0; i < CGEM_NUM_TX_DESCS; i++) {
		sc->txring[i].addr = 0;
		sc->txring[i].ctl = CGEM_TXDESC_USED;
		sc->txring_m[i] = NULL;
		sc->txring_m_dmamap[i] = NULL;
	}
	sc->txring[CGEM_NUM_TX_DESCS - 1].ctl |= CGEM_TXDESC_WRAP;
	sc->txring_hd_ptr = 0;
	sc->txring_tl_ptr = 0;
	sc->txring_queued = 0;
	return (0);
}
static int cgem_setup_descs ( struct cgem_softc * sc ) { int i , err ; sc -> txring = NULL ; sc -> rxring = NULL ; err = bus_dma_tag_create ( bus_get_dma_tag ( sc -> dev ) , 1 , 0 , BUS_SPACE_MAXADDR_32BIT , BUS_SPACE_MAXADDR , NULL , NULL , MAX_DESC_RING_SIZE , 1 , MAX_DESC_RING_SIZE , 0 , busdma_lock_mutex , & sc -> sc_mtx , & sc -> desc_dma_tag ) ; if ( err ) return ( err ) ; err = bus_dma_tag_create ( bus_get_dma_tag ( sc -> dev ) , 1 , 0 , BUS_SPACE_MAXADDR_32BIT , BUS_SPACE_MAXADDR , NULL , NULL , MCLBYTES , TX_MAX_DMA_SEGS , MCLBYTES , 0 , busdma_lock_mutex , & sc -> sc_mtx , & sc -> mbuf_dma_tag ) ; if ( err ) return ( err ) ; err = bus_dmamem_alloc ( sc -> desc_dma_tag , ( void * * ) & sc -> rxring , BUS_DMA_NOWAIT | BUS_DMA_COHERENT , & sc -> rxring_dma_map ) ; if ( err ) return ( err ) ; err = bus_dmamap_load ( sc -> desc_dma_tag , sc -> rxring_dma_map , ( void * ) sc -> rxring , CGEM_NUM_RX_DESCS * sizeof ( struct cgem_rx_desc ) , cgem_getaddr , & sc -> rxring_physaddr , BUS_DMA_NOWAIT ) ; if ( err ) return ( err ) ; for ( i = 0 ; i < CGEM_NUM_RX_DESCS ; i ++ ) { sc -> rxring [ i ] . addr = CGEM_RXDESC_OWN ; sc -> rxring [ i ] . ctl = 0 ; sc -> rxring_m [ i ] = NULL ; sc -> rxring_m_dmamap [ i ] = NULL ; } sc -> rxring [ CGEM_NUM_RX_DESCS - 1 ] . addr |= CGEM_RXDESC_WRAP ; sc -> rxring_hd_ptr = 0 ; sc -> rxring_tl_ptr = 0 ; sc -> rxring_queued = 0 ; err = bus_dmamem_alloc ( sc -> desc_dma_tag , ( void * * ) & sc -> txring , BUS_DMA_NOWAIT | BUS_DMA_COHERENT , & sc -> txring_dma_map ) ; if ( err ) return ( err ) ; err = bus_dmamap_load ( sc -> desc_dma_tag , sc -> txring_dma_map , ( void * ) sc -> txring , CGEM_NUM_TX_DESCS * sizeof ( struct cgem_tx_desc ) , cgem_getaddr , & sc -> txring_physaddr , BUS_DMA_NOWAIT ) ; if ( err ) return ( err ) ; for ( i = 0 ; i < CGEM_NUM_TX_DESCS ; i ++ ) { sc -> txring [ i ] . addr = 0 ; sc -> txring [ i ] . ctl = CGEM_TXDESC_USED ; sc -> txring_m [ i ] = NULL ; sc -> txring_m_dmamap [ i ] = NULL ; } sc -> txring [ CGEM_NUM_TX_DESCS - 1 ] . ctl |= CGEM_TXDESC_WRAP ; sc -> txring_hd_ptr = 0 ; sc -> txring_tl_ptr = 0 ; sc -> txring_queued = 0 ; return ( 0 ) ; }
Create DMA'able descriptor rings.
Create DMA ' able descriptor rings .
/* Allocate non-cached DMA space for RX and TX descriptors.
	 */ /* Set up a bus_dma_tag for mbufs. */ /* Allocate DMA memory in non-cacheable space. */ /* Load descriptor DMA memory. */ /* Initialize RX descriptors. */ /* Allocate DMA memory for TX descriptors in non-cacheable space. */ /* Load TX descriptor DMA memory. */ /* Initialize TX descriptor ring. */