ixgbe_buf.c revision 73cd555c10e70dac413ae4b40de8450a291750ac
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER START
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * The contents of this file are subject to the terms of the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Common Development and Distribution License (the "License").
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * You may not use this file except in compliance with the License.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * You can obtain a copy of the license at:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * See the License for the specific language governing permissions
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and limitations under the License.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * When using or redistributing this file, you may do so under the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * License only. No other modification of this header is permitted.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If applicable, add the following below this CDDL HEADER, with the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * fields enclosed by brackets "[]" replaced with your own identifying
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * information: Portions Copyright [yyyy] [name of copyright owner]
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER END
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Use is subject to license terms.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_dma_buffer(ixgbe_t *, dma_buffer_t *, size_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA attributes for tx/rx descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA attributes for tx/rx buffers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA attributes for transmit.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA access attributes for descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA access attributes for buffers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_dma - Allocate DMA resources for all rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate receive desciptor ring and control block lists
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate transmit desciptor ring and control block lists
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_dma - Free all the DMA resources of all rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free DMA resources of rx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free DMA resources of tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_tbd_ring - Memory allocation for the tx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = sizeof (union ixgbe_adv_tx_desc) * tx_ring->ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If tx head write-back is enabled, an extra tbd is allocated
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * to save the head write-back value
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate a DMA handle for the transmit descriptor
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * memory area.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_alloc_handle(devinfo, &ixgbe_desc_dma_attr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory to DMA data to and from the transmit
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the entire transmit buffer descriptor area to zero
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocates DMA resources for the memory that was allocated by
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the ddi_dma_mem_alloc call. The DMA resources then get bound to the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the memory address
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_addr_bind_handle(tx_ring->tbd_area.dma_handle,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_ring = (union ixgbe_adv_tx_desc *)(uintptr_t)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_tbd_ring - Free the tx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ddi_dma_unbind_handle(tx_ring->tbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_rbd_ring - Memory allocation for the rx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = sizeof (union ixgbe_adv_rx_desc) * rx_ring->ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate a new DMA handle for the receive descriptor
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * memory area.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_alloc_handle(devinfo, &ixgbe_desc_dma_attr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory to DMA data to and from the receive
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the entire transmit buffer descriptor area to zero
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocates DMA resources for the memory that was allocated by
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the ddi_dma_mem_alloc call.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_addr_bind_handle(rx_ring->rbd_area.dma_handle,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->rbd_ring = (union ixgbe_adv_rx_desc *)(uintptr_t)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_rbd_ring - Free the rx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ddi_dma_unbind_handle(rx_ring->rbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_dma_buffer - Allocate DMA resources for a DMA buffer.
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_dma_buffer(ixgbe_t *ixgbe, dma_buffer_t *buf, size_t size)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_dma_buffer - Free one allocated area of dma memory and handle.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_tcb_lists - Memory allocation for the transmit control bolcks
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the work list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->work_list = kmem_zalloc(sizeof (tx_control_block_t *) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for tx work list");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list = kmem_zalloc(sizeof (tx_control_block_t *) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for tx free list");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the tx control blocks of free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for tx control blocks");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate dma memory for the tx control block of free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Pre-allocate dma handles for transmit. These dma handles
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * will be dynamically bound to the data buffers passed down
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * from the upper layers at the time of transmitting.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Pre-allocate transmit buffers for packets that the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * size is less than bcopy_thresh.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_tcb_lists - Release the memory allocated for
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the transmit control bolcks of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Free the tx dma handle for dynamical binding */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the dma handle is NULL, then we don't
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * have to check the remaining.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_rcb_lists - Memory allocation for the receive control blocks
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the work list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->work_list = kmem_zalloc(sizeof (rx_control_block_t *) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate memory for rx work list");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring->free_list = kmem_zalloc(sizeof (rx_control_block_t *) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for rx free list");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the rx control blocks for work list and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rcb_count = rx_ring->ring_size + rx_ring->free_list_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (rx_control_block_t *) * rx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for rx control blocks");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate dma memory for the rx control blocks
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Attach the rx control block to the work list */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Attach the rx control block to the free list */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_rcb_lists - Free the receive control blocks of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rcb_count = rx_ring->ring_size + rx_ring->free_list_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (rx_control_block_t *) * rx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_set_fma_flags - Set the attribute for fma support.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_desc_acc_attr.devacc_attr_access = DDI_FLAGERR_ACC;