FreeBSD/sys/dev/e1000/if_lem.c
/*********************************************************************
 *
 *  Allocate memory for tx_buffer structures. The tx_buffer stores all
 *  the information needed to transmit a packet on the wire.
 *
 **********************************************************************/
Allocate memory for tx_buffer structures. The tx_buffer stores all
the information needed to transmit a packet on the wire.
Allocate memory for tx_buffer structures . The tx_buffer stores all the information needed to transmit a packet on the wire .
static int
lem_allocate_transmit_structures(struct adapter *adapter)
{
	device_t dev = adapter->dev;
	struct em_buffer *tx_buffer;
	int error;
	if ((error = bus_dma_tag_create(bus_get_dma_tag(dev), 
				1, 0,			
				BUS_SPACE_MAXADDR,	
				BUS_SPACE_MAXADDR,	
				NULL, NULL,		
				MCLBYTES * EM_MAX_SCATTER,	
				EM_MAX_SCATTER,		
				MCLBYTES,		
				0,			
				NULL,			
				NULL,			
				&adapter->txtag)) != 0) {
		device_printf(dev, "Unable to allocate TX DMA tag\n");
		goto fail;
	}
	adapter->tx_buffer_area = malloc(sizeof(struct em_buffer) *
	    adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO);
	if (adapter->tx_buffer_area == NULL) {
		device_printf(dev, "Unable to allocate tx_buffer memory\n");
		error = ENOMEM;
		goto fail;
	}
	for (int i = 0; i < adapter->num_tx_desc; i++) {
		tx_buffer = &adapter->tx_buffer_area[i];
		error = bus_dmamap_create(adapter->txtag, 0, &tx_buffer->map);
		if (error != 0) {
			device_printf(dev, "Unable to create TX DMA map\n");
			goto fail;
		}
		tx_buffer->next_eop = -1;
	}
	return (0);
fail:
	lem_free_transmit_structures(adapter);
	return (error);
}
static int lem_allocate_transmit_structures ( struct adapter * adapter ) { device_t dev = adapter -> dev ; struct em_buffer * tx_buffer ; int error ; if ( ( error = bus_dma_tag_create ( bus_get_dma_tag ( dev ) , 1 , 0 , BUS_SPACE_MAXADDR , BUS_SPACE_MAXADDR , NULL , NULL , MCLBYTES * EM_MAX_SCATTER , EM_MAX_SCATTER , MCLBYTES , 0 , NULL , NULL , & adapter -> txtag ) ) != 0 ) { device_printf ( dev , " \n " ) ; goto fail ; } adapter -> tx_buffer_area = malloc ( sizeof ( struct em_buffer ) * adapter -> num_tx_desc , M_DEVBUF , M_NOWAIT | M_ZERO ) ; if ( adapter -> tx_buffer_area == NULL ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } for ( int i = 0 ; i < adapter -> num_tx_desc ; i ++ ) { tx_buffer = & adapter -> tx_buffer_area [ i ] ; error = bus_dmamap_create ( adapter -> txtag , 0 , & tx_buffer -> map ) ; if ( error != 0 ) { device_printf ( dev , " \n " ) ; goto fail ; } tx_buffer -> next_eop = -1 ; } return ( 0 ) ; fail : lem_free_transmit_structures ( adapter ) ; return ( error ) ; }
Allocate memory for tx_buffer structures.
Allocate memory for tx_buffer structures .
/*
	 * Create DMA tags for tx descriptors
	 */ /* parent */ /* alignment, bounds */ /* lowaddr */ /* highaddr */ /* filter, filterarg */ /* maxsize */ /* nsegments */ /* maxsegsize */ /* flags */ /* lockfunc */ /* lockarg */ /* Create the descriptor buffer dma maps */