FreeBSD/sys/dev/ixl/ixl_pf_main.c
/*
 * Fill out fields in queue struct and setup tx/rx memory and structs
 */
Fill out fields in queue struct and setup tx/rx memory and structs
Fill out fields in queue struct and setup tx / rx memory and structs
static int
ixl_setup_queue(struct ixl_queue *que, struct ixl_pf *pf, int index)
{
	device_t dev = pf->dev;
	struct i40e_hw *hw = &pf->hw;
	struct ixl_vsi *vsi = &pf->vsi;
	struct tx_ring *txr = &que->txr;
	struct rx_ring *rxr = &que->rxr;
	int error = 0;
	int rsize, tsize;
	que->num_desc = pf->ringsz;
	que->me = index;
	que->vsi = vsi;
	txr->que = que;
	txr->tail = I40E_QTX_TAIL(que->me);
	snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)",
	    device_get_nameunit(dev), que->me);
	mtx_init(&txr->mtx, txr->mtx_name, NULL, MTX_DEF);
	tsize = roundup2((que->num_desc *
	    sizeof(struct i40e_tx_desc)) +
	    sizeof(u32), DBA_ALIGN);
	if (i40e_allocate_dma_mem(hw,
	    &txr->dma, i40e_mem_reserved, tsize, DBA_ALIGN)) {
		device_printf(dev,
		    "Unable to allocate TX Descriptor memory\n");
		error = ENOMEM;
		goto fail;
	}
	txr->base = (struct i40e_tx_desc *)txr->dma.va;
	bzero((void *)txr->base, tsize);
	if (ixl_allocate_tx_data(que)) {
		device_printf(dev,
		    "Critical Failure setting up TX structures\n");
		error = ENOMEM;
		goto fail;
	}
	txr->br = buf_ring_alloc(DEFAULT_TXBRSZ, M_DEVBUF,
	    M_NOWAIT, &txr->mtx);
	if (txr->br == NULL) {
		device_printf(dev,
		    "Critical Failure setting up TX buf ring\n");
		error = ENOMEM;
		goto fail;
	}
	rsize = roundup2(que->num_desc *
	    sizeof(union i40e_rx_desc), DBA_ALIGN);
	rxr->que = que;
	rxr->tail = I40E_QRX_TAIL(que->me);
	snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)",
	    device_get_nameunit(dev), que->me);
	mtx_init(&rxr->mtx, rxr->mtx_name, NULL, MTX_DEF);
	if (i40e_allocate_dma_mem(hw,
	    &rxr->dma, i40e_mem_reserved, rsize, 4096)) {
		device_printf(dev,
		    "Unable to allocate RX Descriptor memory\n");
		error = ENOMEM;
		goto fail;
	}
	rxr->base = (union i40e_rx_desc *)rxr->dma.va;
	bzero((void *)rxr->base, rsize);
	if (ixl_allocate_rx_data(que)) {
		device_printf(dev,
		    "Critical Failure setting up receive structs\n");
		error = ENOMEM;
		goto fail;
	}
	return (0);
fail:
	if (rxr->base)
		i40e_free_dma_mem(&pf->hw, &rxr->dma);
	if (mtx_initialized(&rxr->mtx))
		mtx_destroy(&rxr->mtx);
	if (txr->br) {
		buf_ring_free(txr->br, M_DEVBUF);
		txr->br = NULL;
	}
	if (txr->base)
		i40e_free_dma_mem(&pf->hw, &txr->dma);
	if (mtx_initialized(&txr->mtx))
		mtx_destroy(&txr->mtx);
	return (error);
}
static int ixl_setup_queue ( struct ixl_queue * que , struct ixl_pf * pf , int index ) { device_t dev = pf -> dev ; struct i40e_hw * hw = & pf -> hw ; struct ixl_vsi * vsi = & pf -> vsi ; struct tx_ring * txr = & que -> txr ; struct rx_ring * rxr = & que -> rxr ; int error = 0 ; int rsize , tsize ; que -> num_desc = pf -> ringsz ; que -> me = index ; que -> vsi = vsi ; txr -> que = que ; txr -> tail = I40E_QTX_TAIL ( que -> me ) ; snprintf ( txr -> mtx_name , sizeof ( txr -> mtx_name ) , " " , device_get_nameunit ( dev ) , que -> me ) ; mtx_init ( & txr -> mtx , txr -> mtx_name , NULL , MTX_DEF ) ; tsize = roundup2 ( ( que -> num_desc * sizeof ( struct i40e_tx_desc ) ) + sizeof ( u32 ) , DBA_ALIGN ) ; if ( i40e_allocate_dma_mem ( hw , & txr -> dma , i40e_mem_reserved , tsize , DBA_ALIGN ) ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } txr -> base = ( struct i40e_tx_desc * ) txr -> dma . va ; bzero ( ( void * ) txr -> base , tsize ) ; if ( ixl_allocate_tx_data ( que ) ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } txr -> br = buf_ring_alloc ( DEFAULT_TXBRSZ , M_DEVBUF , M_NOWAIT , & txr -> mtx ) ; if ( txr -> br == NULL ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } rsize = roundup2 ( que -> num_desc * sizeof ( union i40e_rx_desc ) , DBA_ALIGN ) ; rxr -> que = que ; rxr -> tail = I40E_QRX_TAIL ( que -> me ) ; snprintf ( rxr -> mtx_name , sizeof ( rxr -> mtx_name ) , " " , device_get_nameunit ( dev ) , que -> me ) ; mtx_init ( & rxr -> mtx , rxr -> mtx_name , NULL , MTX_DEF ) ; if ( i40e_allocate_dma_mem ( hw , & rxr -> dma , i40e_mem_reserved , rsize , 4096 ) ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } rxr -> base = ( union i40e_rx_desc * ) rxr -> dma . va ; bzero ( ( void * ) rxr -> base , rsize ) ; if ( ixl_allocate_rx_data ( que ) ) { device_printf ( dev , " \n " ) ; error = ENOMEM ; goto fail ; } return ( 0 ) ; fail : if ( rxr -> base ) i40e_free_dma_mem ( & pf -> hw , & rxr -> dma ) ; if ( mtx_initialized ( & rxr -> mtx ) ) mtx_destroy ( & rxr -> mtx ) ; if ( txr -> br ) { buf_ring_free ( txr -> br , M_DEVBUF ) ; txr -> br = NULL ; } if ( txr -> base ) i40e_free_dma_mem ( & pf -> hw , & txr -> dma ) ; if ( mtx_initialized ( & txr -> mtx ) ) mtx_destroy ( & txr -> mtx ) ; return ( error ) ; }
Fill out fields in queue struct and setup tx/rx memory and structs
Fill out fields in queue struct and setup tx / rx memory and structs
/* ERJ: A lot of references to external objects... */ /* Initialize the TX lock */ /* Create the TX descriptor ring */ /* Now allocate transmit soft structs for the ring */ /* Allocate a buf ring */ /* Initialize the RX side lock */ /* Allocate receive soft structs for the ring*/