FreeBSD/sys/dev/e1000/if_lem.c
static int
lem_allocate_receive_structures(struct adapter *adapter)
{
	device_t dev = adapter->dev;
	struct em_buffer *rx_buffer;
	int i, error;

	adapter->rx_buffer_area = malloc(sizeof(struct em_buffer) *
	    adapter->num_rx_desc, M_DEVBUF, M_NOWAIT | M_ZERO);
	if (adapter->rx_buffer_area == NULL) {
		device_printf(dev, "Unable to allocate rx_buffer memory\n");
		return (ENOMEM);
	}

	error = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
				1, 0,			/* alignment, bounds */
				BUS_SPACE_MAXADDR,	/* lowaddr */
				BUS_SPACE_MAXADDR,	/* highaddr */
				NULL, NULL,		/* filter, filterarg */
				MCLBYTES,		/* maxsize */
				1,			/* nsegments */
				MCLBYTES,		/* maxsegsize */
				0,			/* flags */
				NULL,			/* lockfunc */
				NULL,			/* lockarg */
				&adapter->rxtag);
	if (error) {
		device_printf(dev, "%s: bus_dma_tag_create failed %d\n",
		    __func__, error);
		goto fail;
	}

	/* Create the spare map (used by getbuf) */
	error = bus_dmamap_create(adapter->rxtag, 0, &adapter->rx_sparemap);
	if (error) {
		device_printf(dev, "%s: bus_dmamap_create failed: %d\n",
		    __func__, error);
		goto fail;
	}

	rx_buffer = adapter->rx_buffer_area;
	for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
		error = bus_dmamap_create(adapter->rxtag, 0, &rx_buffer->map);
		if (error) {
			device_printf(dev, "%s: bus_dmamap_create failed: %d\n",
			    __func__, error);
			goto fail;
		}
	}

	return (0);

fail:
	lem_free_receive_structures(adapter);
	return (error);
}
/*********************************************************************
 *
 *  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
lem_allocate_receive_structures(struct adapter *adapter)
{
	device_t dev = adapter->dev;
	struct em_buffer *rx_buffer;
	int i, error;
	adapter->rx_buffer_area = malloc(sizeof(struct em_buffer) *
	    adapter->num_rx_desc, M_DEVBUF, M_NOWAIT | M_ZERO);
	if (adapter->rx_buffer_area == 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,		
				MCLBYTES,		
				1,			
				MCLBYTES,		
				0,			
				NULL,			
				NULL,			
				&adapter->rxtag);
	if (error) {
		device_printf(dev, "%s: bus_dma_tag_create failed %d\n",
		    __func__, error);
		goto fail;
	}
	error = bus_dmamap_create(adapter->rxtag, 0, &adapter->rx_sparemap);
	if (error) {
		device_printf(dev, "%s: bus_dmamap_create failed: %d\n",
		    __func__, error);
		goto fail;
	}
	rx_buffer = adapter->rx_buffer_area;
	for (i = 0; i < adapter->num_rx_desc; i++, rx_buffer++) {
		error = bus_dmamap_create(adapter->rxtag, 0, &rx_buffer->map);
		if (error) {
			device_printf(dev, "%s: bus_dmamap_create failed: %d\n",
			    __func__, error);
			goto fail;
		}
	}
	return (0);
fail:
	lem_free_receive_structures(adapter);
	return (error);
}
static int lem_allocate_receive_structures ( struct adapter * adapter ) { device_t dev = adapter -> dev ; struct em_buffer * rx_buffer ; int i , error ; adapter -> rx_buffer_area = malloc ( sizeof ( struct em_buffer ) * adapter -> num_rx_desc , M_DEVBUF , M_NOWAIT | M_ZERO ) ; if ( adapter -> rx_buffer_area == 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 , MCLBYTES , 1 , MCLBYTES , 0 , NULL , NULL , & adapter -> rxtag ) ; if ( error ) { device_printf ( dev , " \n " , __func__ , error ) ; goto fail ; } error = bus_dmamap_create ( adapter -> rxtag , 0 , & adapter -> rx_sparemap ) ; if ( error ) { device_printf ( dev , " \n " , __func__ , error ) ; goto fail ; } rx_buffer = adapter -> rx_buffer_area ; for ( i = 0 ; i < adapter -> num_rx_desc ; i ++ , rx_buffer ++ ) { error = bus_dmamap_create ( adapter -> rxtag , 0 , & rx_buffer -> map ) ; if ( error ) { device_printf ( dev , " \n " , __func__ , error ) ; goto fail ; } } return ( 0 ) ; fail : lem_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 */ /* Create the spare map (used by getbuf) */