FreeBSD/sys/dev/e1000/if_em.c
/*********************************************************************
 *
 *  Allocate memory for rx_buffer structures. Since we use one
 *  rx_buffer per received packet, the maximum number of rx_buffer's
 *  that we'll need is equal to the number of receive descriptors
 *  that we've allocated.
 *
 **********************************************************************/
Allocate memory for rx_buffer structures. Since we use one
rx_buffer per received packet, the maximum number of rx_buffer's
that we'll need is equal to the number of receive descriptors
that we've allocated.
Allocate memory for rx_buffer structures . Since we use one rx_buffer per received packet the maximum number of rx_buffer ' s that we ' ll need is equal to the number of receive descriptors that we ' ve allocated .
static int
em_allocate_receive_buffers(struct rx_ring *rxr)
{
	struct adapter		*adapter = rxr->adapter;
	device_t		dev = adapter->dev;
	struct em_rxbuffer	*rxbuf;
	int			error;
	rxr->rx_buffers = malloc(sizeof(struct em_rxbuffer) *
	    adapter->num_rx_desc, M_DEVBUF, M_NOWAIT | M_ZERO);
	if (rxr->rx_buffers == NULL) {
		device_printf(dev, "Unable to allocate rx_buffer memory\n");
		return (ENOMEM);
	}
	error = bus_dma_tag_create(bus_get_dma_tag(dev), 
				1, 0,			
				BUS_SPACE_MAXADDR,	
				BUS_SPACE_MAXADDR,	
				NULL, NULL,		
				MJUM9BYTES,		
				1,			
				MJUM9BYTES,		
				0,			
				NULL,			
				NULL,			
				&rxr->rxtag);
	if (error) {
		device_printf(dev, "%s: bus_dma_tag_create failed %d\n",
		    __func__, error);
		goto fail;
	}
	rxbuf = rxr->rx_buffers;
	for (int i = 0; i < adapter->num_rx_desc; i++, rxbuf++) {
		rxbuf = &rxr->rx_buffers[i];
		error = bus_dmamap_create(rxr->rxtag, 0, &rxbuf->map);
		if (error) {
			device_printf(dev, "%s: bus_dmamap_create failed: %d\n",
			    __func__, error);
			goto fail;
		}
	}
	return (0);
fail:
	em_free_receive_structures(adapter);
	return (error);
}
static int em_allocate_receive_buffers ( struct rx_ring * rxr ) { struct adapter * adapter = rxr -> adapter ; device_t dev = adapter -> dev ; struct em_rxbuffer * rxbuf ; int error ; rxr -> rx_buffers = malloc ( sizeof ( struct em_rxbuffer ) * adapter -> num_rx_desc , M_DEVBUF , M_NOWAIT | M_ZERO ) ; if ( rxr -> rx_buffers == NULL ) { device_printf ( dev , " \n " ) ; return ( ENOMEM ) ; } error = bus_dma_tag_create ( bus_get_dma_tag ( dev ) , 1 , 0 , BUS_SPACE_MAXADDR , BUS_SPACE_MAXADDR , NULL , NULL , MJUM9BYTES , 1 , MJUM9BYTES , 0 , NULL , NULL , & rxr -> rxtag ) ; if ( error ) { device_printf ( dev , " \n " , __func__ , error ) ; goto fail ; } rxbuf = rxr -> rx_buffers ; for ( int i = 0 ; i < adapter -> num_rx_desc ; i ++ , rxbuf ++ ) { rxbuf = & rxr -> rx_buffers [ i ] ; error = bus_dmamap_create ( rxr -> rxtag , 0 , & rxbuf -> map ) ; if ( error ) { device_printf ( dev , " \n " , __func__ , error ) ; goto fail ; } } return ( 0 ) ; fail : em_free_receive_structures ( adapter ) ; return ( error ) ; }
Allocate memory for rx_buffer structures.
Allocate memory for rx_buffer structures .
/* parent */ /* alignment, bounds */ /* lowaddr */ /* highaddr */ /* filter, filterarg */ /* maxsize */ /* nsegments */ /* maxsegsize */ /* flags */ /* lockfunc */ /* lockarg */