FreeBSD/sys/dev/e1000/if_em.c
/*********************************************************************
 *
 *  Allocate memory for tx_buffer structures. The tx_buffer stores all
 *  the information needed to transmit a packet on the wire. This is
 *  called only once at attach, setup is done every reset.
 *
 **********************************************************************/
Allocate memory for tx_buffer structures. The tx_buffer stores all
the information needed to transmit a packet on the wire. This is
called only once at attach, setup is done every reset.
Allocate memory for tx_buffer structures . The tx_buffer stores all the information needed to transmit a packet on the wire . This is called only once at attach setup is done every reset .
static int
em_allocate_transmit_buffers(struct tx_ring *txr)
{
	struct adapter *adapter = txr->adapter;
	device_t dev = adapter->dev;
	struct em_txbuffer *txbuf;
	int error, i;
	if ((error = bus_dma_tag_create(bus_get_dma_tag(dev),
			       1, 0,			
			       BUS_SPACE_MAXADDR,	
			       BUS_SPACE_MAXADDR,	
			       NULL, NULL,		
			       EM_TSO_SIZE,		
			       EM_MAX_SCATTER,		
			       PAGE_SIZE,		
			       0,			
			       NULL,			
			       NULL,			
			       &txr->txtag))) {
		device_printf(dev,"Unable to allocate TX DMA tag\n");
		goto fail;
	}
	if (!(txr->tx_buffers =
	    (struct em_txbuffer *) malloc(sizeof(struct em_txbuffer) *
	    adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
		device_printf(dev, "Unable to allocate tx_buffer memory\n");
		error = ENOMEM;
		goto fail;
	}
	txbuf = txr->tx_buffers;
	for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
		error = bus_dmamap_create(txr->txtag, 0, &txbuf->map);
		if (error != 0) {
			device_printf(dev, "Unable to create TX DMA map\n");
			goto fail;
		}
	}
	return 0;
fail:
	em_free_transmit_structures(adapter);
	return (error);
}
static int em_allocate_transmit_buffers ( struct tx_ring * txr ) { struct adapter * adapter = txr -> adapter ; device_t dev = adapter -> dev ; struct em_txbuffer * txbuf ; int error , i ; if ( ( error = bus_dma_tag_create ( bus_get_dma_tag ( dev ) , 1 , 0 , BUS_SPACE_MAXADDR , BUS_SPACE_MAXADDR , NULL , NULL , EM_TSO_SIZE , EM_MAX_SCATTER , PAGE_SIZE , 0 , NULL , NULL , & txr -> txtag ) ) ) { device_printf ( dev , " \n " ) ; goto fail ; } if ( ! ( txr -> tx_buffers = ( struct em_txbuffer * ) malloc ( sizeof ( struct em_txbuffer ) * adapter -> num_tx_desc , M_DEVBUF , M_NOWAIT | M_ZERO ) ) ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } txbuf = txr -> tx_buffers ; for ( i = 0 ; i < adapter -> num_tx_desc ; i ++ , txbuf ++ ) { error = bus_dmamap_create ( txr -> txtag , 0 , & txbuf -> map ) ; if ( error != 0 ) { device_printf ( dev , " \n " ) ; goto fail ; } } return 0 ; fail : em_free_transmit_structures ( adapter ) ; return ( error ) ; }
Allocate memory for tx_buffer structures.
Allocate memory for tx_buffer structures .
/*
	 * Setup DMA descriptor areas.
	 */ /* alignment, bounds */ /* lowaddr */ /* highaddr */ /* filter, filterarg */ /* maxsize */ /* nsegments */ /* maxsegsize */ /* flags */ /* lockfunc */ /* lockfuncarg */ /* Create the descriptor buffer dma maps */ /* We free all, it handles case where we are in the middle */