FreeBSD/sys/dev/vnic/nicvf_queues.c
/* Allocate memory for a queue's descriptors */
Allocate memory for a queue's descriptors
Allocate memory for a queue ' s descriptors
static int
nicvf_alloc_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem,
    int q_len, int desc_size, int align_bytes)
{
	int err, err_dmat;
	err = bus_dma_tag_create(
	    bus_get_dma_tag(nic->dev),		
	    align_bytes,			
	    0,					
	    BUS_SPACE_MAXADDR,			
	    BUS_SPACE_MAXADDR,			
	    NULL, NULL,				
	    (q_len * desc_size),		
	    1,					
	    (q_len * desc_size),		
	    0,					
	    NULL, NULL,				
	    &dmem->dmat);			
	if (err != 0) {
		device_printf(nic->dev,
		    "Failed to create busdma tag for descriptors ring\n");
		return (err);
	}
	err = bus_dmamem_alloc(
	    dmem->dmat,				
	    &dmem->base,			
	    (BUS_DMA_NOWAIT | BUS_DMA_ZERO),	
	    &dmem->dmap);			
	if (err != 0) {
		device_printf(nic->dev, "Failed to allocate DMA safe memory for"
		    "descriptors ring\n");
		goto dmamem_fail;
	}
	err = bus_dmamap_load(
	    dmem->dmat,
	    dmem->dmap,
	    dmem->base,
	    (q_len * desc_size),		
	    nicvf_dmamap_q_cb,			
	    &dmem->phys_base,			
	    BUS_DMA_NOWAIT);
	if (err != 0) {
		device_printf(nic->dev,
		    "Cannot load DMA map of descriptors ring\n");
		goto dmamap_fail;
	}
	dmem->q_len = q_len;
	dmem->size = (desc_size * q_len);
	return (0);
dmamap_fail:
	bus_dmamem_free(dmem->dmat, dmem->base, dmem->dmap);
	dmem->phys_base = 0;
dmamem_fail:
	err_dmat = bus_dma_tag_destroy(dmem->dmat);
	dmem->base = NULL;
	KASSERT(err_dmat == 0,
	    ("%s: Trying to destroy BUSY DMA tag", __func__));
	return (err);
}
static int nicvf_alloc_q_desc_mem ( struct nicvf * nic , struct q_desc_mem * dmem , int q_len , int desc_size , int align_bytes ) { int err , err_dmat ; err = bus_dma_tag_create ( bus_get_dma_tag ( nic -> dev ) , align_bytes , 0 , BUS_SPACE_MAXADDR , BUS_SPACE_MAXADDR , NULL , NULL , ( q_len * desc_size ) , 1 , ( q_len * desc_size ) , 0 , NULL , NULL , & dmem -> dmat ) ; if ( err != 0 ) { device_printf ( nic -> dev , " \n " ) ; return ( err ) ; } err = bus_dmamem_alloc ( dmem -> dmat , & dmem -> base , ( BUS_DMA_NOWAIT | BUS_DMA_ZERO ) , & dmem -> dmap ) ; if ( err != 0 ) { device_printf ( nic -> dev , " " " \n " ) ; goto dmamem_fail ; } err = bus_dmamap_load ( dmem -> dmat , dmem -> dmap , dmem -> base , ( q_len * desc_size ) , nicvf_dmamap_q_cb , & dmem -> phys_base , BUS_DMA_NOWAIT ) ; if ( err != 0 ) { device_printf ( nic -> dev , " \n " ) ; goto dmamap_fail ; } dmem -> q_len = q_len ; dmem -> size = ( desc_size * q_len ) ; return ( 0 ) ; dmamap_fail : bus_dmamem_free ( dmem -> dmat , dmem -> base , dmem -> dmap ) ; dmem -> phys_base = 0 ; dmamem_fail : err_dmat = bus_dma_tag_destroy ( dmem -> dmat ) ; dmem -> base = NULL ; KASSERT ( err_dmat == 0 , ( " " , __func__ ) ) ; return ( err ) ; }
Allocate memory for a queue's descriptors
Allocate memory for a queue ' s descriptors
/* Create DMA tag first */ /* parent tag */ /* alignment */ /* boundary */ /* lowaddr */ /* highaddr */ /* filtfunc, filtfuncarg */ /* maxsize */ /* nsegments */ /* maxsegsize */ /* flags */ /* lockfunc, lockfuncarg */ /* dmat */ /* Allocate segment of continuous DMA safe memory */ /* DMA tag */ /* virtual address */ /* flags */ /* DMA map */ /* allocation size */ /* map to DMA address cb. */ /* physical address */