9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER START
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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 *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * You can obtain a copy of the license at:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * http://www.opensolaris.org/os/licensing.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * See the License for the specific language governing permissions
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * and limitations under the License.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt *
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 *
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 *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * CDDL HEADER END
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China * Use is subject to license terms.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#include "ixgbe_sw.h"
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_tbd_ring(ixgbe_tx_ring_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_free_tbd_ring(ixgbe_tx_ring_t *);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinastatic int ixgbe_alloc_rbd_ring(ixgbe_rx_data_t *);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinastatic void ixgbe_free_rbd_ring(ixgbe_rx_data_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_dma_buffer(ixgbe_t *, dma_buffer_t *, size_t);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int ixgbe_alloc_tcb_lists(ixgbe_tx_ring_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void ixgbe_free_tcb_lists(ixgbe_tx_ring_t *);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinastatic int ixgbe_alloc_rcb_lists(ixgbe_rx_data_t *);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinastatic void ixgbe_free_rcb_lists(ixgbe_rx_data_t *);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#ifdef __sparc
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#define IXGBE_DMA_ALIGNMENT 0x0000000000002000ull
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#else
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#define IXGBE_DMA_ALIGNMENT 0x0000000000001000ull
9da57d7b0ddd8d73b676ce12c040362132cdd538bt#endif
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA attributes for tx/rx descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic ddi_dma_attr_t ixgbe_desc_dma_attr = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DMA_ATTR_V0, /* version number */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x0000000000000000ull, /* low address */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0xFFFFFFFFFFFFFFFFull, /* high address */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000000FFFFFFFFull, /* dma counter max */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DMA_ALIGNMENT, /* alignment */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000FFF, /* burst sizes */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000001, /* minimum transfer size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000000FFFFFFFFull, /* maximum transfer size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0xFFFFFFFFFFFFFFFFull, /* maximum segment size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 1, /* scatter/gather list length */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000001, /* granularity */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_FLAGERR /* DMA flags */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA attributes for tx/rx buffers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic ddi_dma_attr_t ixgbe_buf_dma_attr = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DMA_ATTR_V0, /* version number */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x0000000000000000ull, /* low address */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0xFFFFFFFFFFFFFFFFull, /* high address */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000000FFFFFFFFull, /* dma counter max */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt IXGBE_DMA_ALIGNMENT, /* alignment */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000FFF, /* burst sizes */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000001, /* minimum transfer size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000000FFFFFFFFull, /* maximum transfer size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0xFFFFFFFFFFFFFFFFull, /* maximum segment size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 1, /* scatter/gather list length */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000001, /* granularity */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_FLAGERR /* DMA flags */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA attributes for transmit.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic ddi_dma_attr_t ixgbe_tx_dma_attr = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DMA_ATTR_V0, /* version number */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x0000000000000000ull, /* low address */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0xFFFFFFFFFFFFFFFFull, /* high address */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000000FFFFFFFFull, /* dma counter max */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 1, /* alignment */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000FFF, /* burst sizes */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000001, /* minimum transfer size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000000FFFFFFFFull, /* maximum transfer size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0xFFFFFFFFFFFFFFFFull, /* maximum segment size */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt MAX_COOKIE, /* scatter/gather list length */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0x00000001, /* granularity */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_FLAGERR /* DMA flags */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA access attributes for descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic ddi_device_acc_attr_t ixgbe_desc_acc_attr = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DEVICE_ATTR_V0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_STRUCTURE_LE_ACC,
837c1ac4e72b7d86278cca88b1075af557f7d161Stephen Hanson DDI_STRICTORDER_ACC
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * DMA access attributes for buffers.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic ddi_device_acc_attr_t ixgbe_buf_acc_attr = {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DEVICE_ATTR_V0,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_NEVERSWAP_ACC,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_STRICTORDER_ACC
9da57d7b0ddd8d73b676ce12c040362132cdd538bt};
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_dma - Allocate DMA resources for all rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btint
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_dma(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_rx_ring_t *rx_ring;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_rx_data_t *rx_data;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate receive desciptor ring and control block lists
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[i];
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data = rx_ring->rx_data;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (ixgbe_alloc_rbd_ring(rx_data) != IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_dma_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (ixgbe_alloc_rcb_lists(rx_data) != IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_dma_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate transmit desciptor ring and control block lists
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_alloc_tbd_ring(tx_ring) != IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_dma_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe_alloc_tcb_lists(tx_ring) != IXGBE_SUCCESS)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_dma_failure;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btalloc_dma_failure:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_dma(ixgbe);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_dma - Free all the DMA resources of all rx/tx rings.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_free_dma(ixgbe_t *ixgbe)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_rx_ring_t *rx_ring;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_rx_data_t *rx_data;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_ring_t *tx_ring;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free DMA resources of rx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_rx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_ring = &ixgbe->rx_rings[i];
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data = rx_ring->rx_data;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_free_rbd_ring(rx_data);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_free_rcb_lists(rx_data);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Free DMA resources of tx rings
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < ixgbe->num_tx_rings; i++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring = &ixgbe->tx_rings[i];
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_tbd_ring(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_tcb_lists(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaint
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaixgbe_alloc_rx_ring_data(ixgbe_rx_ring_t *rx_ring)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_rx_data_t *rx_data;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_t *ixgbe = rx_ring->ixgbe;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China uint32_t rcb_count;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Allocate memory for software receive rings
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data = kmem_zalloc(sizeof (ixgbe_rx_data_t), KM_NOSLEEP);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data == NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_error(ixgbe, "Allocate software receive rings failed");
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (IXGBE_FAILURE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rx_ring = rx_ring;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China mutex_init(&rx_data->recycle_lock, NULL,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China MUTEX_DRIVER, DDI_INTR_PRI(ixgbe->intr_pri));
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->ring_size = ixgbe->rx_ring_size;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->free_list_size = ixgbe->rx_ring_size;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rcb_head = 0;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rcb_tail = 0;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rcb_free = rx_data->free_list_size;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Allocate memory for the work list.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->work_list = kmem_zalloc(sizeof (rx_control_block_t *) *
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->ring_size, KM_NOSLEEP);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->work_list == NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_error(ixgbe,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China "Could not allocate memory for rx work list");
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China goto alloc_rx_data_failure;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Allocate memory for the free list.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->free_list = kmem_zalloc(sizeof (rx_control_block_t *) *
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->free_list_size, KM_NOSLEEP);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->free_list == NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_error(ixgbe,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China "Cound not allocate memory for rx free list");
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China goto alloc_rx_data_failure;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China /*
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * Allocate memory for the rx control blocks for work list and
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China * free list.
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb_count = rx_data->ring_size + rx_data->free_list_size;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rcb_area =
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China kmem_zalloc(sizeof (rx_control_block_t) * rcb_count,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China KM_NOSLEEP);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rcb_area == NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_error(ixgbe,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China "Cound not allocate memory for rx control blocks");
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China goto alloc_rx_data_failure;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_ring->rx_data = rx_data;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (IXGBE_SUCCESS);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaalloc_rx_data_failure:
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_free_rx_ring_data(rx_data);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return (IXGBE_FAILURE);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavoid
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaixgbe_free_rx_ring_data(ixgbe_rx_data_t *rx_data)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China uint32_t rcb_count;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data == NULL)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China return;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ASSERT(rx_data->rcb_pending == 0);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb_count = rx_data->ring_size + rx_data->free_list_size;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rcb_area != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China kmem_free(rx_data->rcb_area,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China sizeof (rx_control_block_t) * rcb_count);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rcb_area = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->work_list != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China kmem_free(rx_data->work_list,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China sizeof (rx_control_block_t *) * rx_data->ring_size);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->work_list = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->free_list != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China kmem_free(rx_data->free_list,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China sizeof (rx_control_block_t *) * rx_data->free_list_size);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->free_list = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China mutex_destroy(&rx_data->recycle_lock);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China kmem_free(rx_data, sizeof (ixgbe_rx_data_t));
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China}
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_tbd_ring - Memory allocation for the tx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_tbd_ring(ixgbe_tx_ring_t *tx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int ret;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size_t size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size_t len;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t cookie_num;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_cookie_t cookie;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = tx_ring->ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size = sizeof (union ixgbe_adv_tx_desc) * tx_ring->ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If tx head write-back is enabled, an extra tbd is allocated
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * to save the head write-back value
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ixgbe->tx_head_wb_enable) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size += sizeof (union ixgbe_adv_tx_desc);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate a DMA handle for the transmit descriptor
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * memory area.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_alloc_handle(devinfo, &ixgbe_desc_dma_attr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &tx_ring->tbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate tbd dma handle: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory to DMA data to and from the transmit
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_mem_alloc(tx_ring->tbd_area.dma_handle,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size, &ixgbe_desc_acc_attr, DDI_DMA_CONSISTENT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (caddr_t *)&tx_ring->tbd_area.address,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &len, &tx_ring->tbd_area.acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate tbd dma memory: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tbd_area.dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&tx_ring->tbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the entire transmit buffer descriptor area to zero
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt bzero(tx_ring->tbd_area.address, len);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_addr_bind_handle(tx_ring->tbd_area.dma_handle,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL, (caddr_t)tx_ring->tbd_area.address,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt len, DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL, &cookie, &cookie_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_DMA_MAPPED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not bind tbd dma resource: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tbd_area.acc_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_mem_free(&tx_ring->tbd_area.acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tbd_area.dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&tx_ring->tbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(cookie_num == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_address = cookie.dmac_laddress;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.size = len;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_ring = (union ixgbe_adv_tx_desc *)(uintptr_t)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.address;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_tbd_ring - Free the tx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_free_tbd_ring(ixgbe_tx_ring_t *tx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tbd_area.dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ddi_dma_unbind_handle(tx_ring->tbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tbd_area.acc_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_mem_free(&tx_ring->tbd_area.acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tbd_area.dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&tx_ring->tbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.dma_address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_area.size = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tbd_ring = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_rbd_ring - Memory allocation for the rx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaixgbe_alloc_rbd_ring(ixgbe_rx_data_t *rx_data)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int ret;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size_t size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size_t len;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t cookie_num;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_cookie_t cookie;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_t *ixgbe = rx_data->rx_ring->ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt devinfo = ixgbe->dip;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China size = sizeof (union ixgbe_adv_rx_desc) * rx_data->ring_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate a new DMA handle for the receive descriptor
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * memory area.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_alloc_handle(devinfo, &ixgbe_desc_dma_attr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China &rx_data->rbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate rbd dma handle: %x", ret);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory to DMA data to and from the receive
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * descriptors.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ret = ddi_dma_mem_alloc(rx_data->rbd_area.dma_handle,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size, &ixgbe_desc_acc_attr, DDI_DMA_CONSISTENT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China (caddr_t *)&rx_data->rbd_area.address,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China &len, &rx_data->rbd_area.acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate rbd dma memory: %x", ret);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.acc_handle = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.address = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rbd_area.dma_handle != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ddi_dma_free_handle(&rx_data->rbd_area.dma_handle);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Initialize the entire transmit buffer descriptor area to zero
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China bzero(rx_data->rbd_area.address, len);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocates DMA resources for the memory that was allocated by
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the ddi_dma_mem_alloc call.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ret = ddi_dma_addr_bind_handle(rx_data->rbd_area.dma_handle,
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China NULL, (caddr_t)rx_data->rbd_area.address,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt len, DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL, &cookie, &cookie_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_DMA_MAPPED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not bind rbd dma resource: %x", ret);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_address = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rbd_area.acc_handle != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ddi_dma_mem_free(&rx_data->rbd_area.acc_handle);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.acc_handle = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rbd_area.dma_handle != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ddi_dma_free_handle(&rx_data->rbd_area.dma_handle);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(cookie_num == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_address = cookie.dmac_laddress;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.size = len;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_ring = (union ixgbe_adv_rx_desc *)(uintptr_t)
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.address;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_rbd_ring - Free the rx descriptors of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaixgbe_free_rbd_ring(ixgbe_rx_data_t *rx_data)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rbd_area.dma_handle != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China (void) ddi_dma_unbind_handle(rx_data->rbd_area.dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rbd_area.acc_handle != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ddi_dma_mem_free(&rx_data->rbd_area.acc_handle);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rx_data->rbd_area.dma_handle != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ddi_dma_free_handle(&rx_data->rbd_area.dma_handle);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.address = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.dma_address = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_area.size = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->rbd_ring = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_dma_buffer - Allocate DMA resources for a DMA buffer.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_dma_buffer(ixgbe_t *ixgbe, dma_buffer_t *buf, size_t size)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int ret;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_cookie_t cookie;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size_t len;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint_t cookie_num;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_alloc_handle(devinfo,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &ixgbe_buf_dma_attr, DDI_DMA_DONTWAIT,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt NULL, &buf->dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate dma buffer handle: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_mem_alloc(buf->dma_handle,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt size, &ixgbe_buf_acc_attr, DDI_DMA_STREAMING,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL, &buf->address,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &len, &buf->acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (buf->dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&buf->dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate dma buffer memory: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_addr_bind_handle(buf->dma_handle, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->address,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt len, DDI_DMA_RDWR | DDI_DMA_STREAMING,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL, &cookie, &cookie_num);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_DMA_MAPPED) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (buf->acc_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_mem_free(&buf->acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (buf->dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&buf->dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not bind dma buffer handle: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(cookie_num == 1);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_address = cookie.dmac_laddress;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->size = len;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->len = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_dma_buffer - Free one allocated area of dma memory and handle.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinavoid
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_free_dma_buffer(dma_buffer_t *buf)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (buf->dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt (void) ddi_dma_unbind_handle(buf->dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (buf->acc_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_mem_free(&buf->acc_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->acc_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->address = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (buf->dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&buf->dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->size = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt buf->len = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_tcb_lists - Memory allocation for the transmit control bolcks
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_alloc_tcb_lists(ixgbe_tx_ring_t *tx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int ret;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_control_block_t *tcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dma_buffer_t *tx_buf;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_t *ixgbe = tx_ring->ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dev_info_t *devinfo = ixgbe->dip;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the work list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->work_list = kmem_zalloc(sizeof (tx_control_block_t *) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->ring_size, KM_NOSLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->work_list == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for tx work list");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list = kmem_zalloc(sizeof (tx_control_block_t *) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list_size, KM_NOSLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->free_list == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(tx_ring->work_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->ring_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->work_list = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for tx free list");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the tx control blocks of free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tcb_area =
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_zalloc(sizeof (tx_control_block_t) *
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list_size, KM_NOSLEEP);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tcb_area == NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(tx_ring->work_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->ring_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->work_list = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(tx_ring->free_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Cound not allocate memory for tx control blocks");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate dma memory for the tx control block of free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tcb = tx_ring->tcb_area;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < tx_ring->free_list_size; i++, tcb++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(tcb != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list[i] = tcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
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 */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ddi_dma_alloc_handle(devinfo,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &ixgbe_tx_dma_attr,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt DDI_DMA_DONTWAIT, NULL,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt &tcb->tx_dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != DDI_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tcb->tx_dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt "Could not allocate tx dma handle: %x", ret);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_tcb_lists_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Pre-allocate transmit buffers for packets that the
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * size is less than bcopy_thresh.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_buf = &tcb->tx_buf;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ixgbe_alloc_dma_buffer(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_buf, ixgbe->tx_buf_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(tcb->tx_dma_handle != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&tcb->tx_dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tcb->tx_dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Allocate tx dma buffer failed");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_tcb_lists_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
edf70dc9b8e373c558a49c15c2d86be817d497fePaul Guo
edf70dc9b8e373c558a49c15c2d86be817d497fePaul Guo tcb->last_index = MAX_TX_RING_SIZE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btalloc_tcb_lists_fail:
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_tcb_lists(tx_ring);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_tcb_lists - Release the memory allocated for
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * the transmit control bolcks of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
9da57d7b0ddd8d73b676ce12c040362132cdd538btixgbe_free_tcb_lists(ixgbe_tx_ring_t *tx_ring)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_control_block_t *tcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tcb = tx_ring->tcb_area;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tcb == NULL)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < tx_ring->free_list_size; i++, tcb++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(tcb != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Free the tx dma handle for dynamical binding */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tcb->tx_dma_handle != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ddi_dma_free_handle(&tcb->tx_dma_handle);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tcb->tx_dma_handle = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * If the dma handle is NULL, then we don't
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * have to check the remaining.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538bt break;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_free_dma_buffer(&tcb->tx_buf);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->tcb_area != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(tx_ring->tcb_area,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t) * tx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->tcb_area = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->work_list != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(tx_ring->work_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->ring_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->work_list = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (tx_ring->free_list != NULL) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt kmem_free(tx_ring->free_list,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt sizeof (tx_control_block_t *) * tx_ring->free_list_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt tx_ring->free_list = NULL;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_alloc_rcb_lists - Memory allocation for the receive control blocks
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic int
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaixgbe_alloc_rcb_lists(ixgbe_rx_data_t *rx_data)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt int ret;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_control_block_t *rcb;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_t *ixgbe = rx_data->rx_ring->ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt dma_buffer_t *rx_buf;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t rcb_count;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * Allocate memory for the rx control blocks for work list and
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * free list.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb_count = rx_data->ring_size + rx_data->free_list_size;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb = rx_data->rcb_area;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < rcb_count; i++, rcb++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(rcb != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (i < rx_data->ring_size) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Attach the rx control block to the work list */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->work_list[i] = rcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt /* Attach the rx control block to the free list */
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rx_data->free_list[i - rx_data->ring_size] = rcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_buf = &rcb->rx_buf;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ret = ixgbe_alloc_dma_buffer(ixgbe,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_buf, ixgbe->rx_buf_size);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (ret != IXGBE_SUCCESS) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_error(ixgbe, "Allocate rx dma buffer failed");
9da57d7b0ddd8d73b676ce12c040362132cdd538bt goto alloc_rcb_lists_fail;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_buf->size -= IPHDR_ALIGN_ROOM;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_buf->address += IPHDR_ALIGN_ROOM;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_buf->dma_address += IPHDR_ALIGN_ROOM;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb->ref_cnt = 1;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb->rx_data = (ixgbe_rx_data_t *)rx_data;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rcb->free_rtn.free_func = ixgbe_rx_recycle;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rcb->free_rtn.free_arg = (char *)rcb;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China rcb->lro_prev = -1;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China rcb->lro_next = -1;
ffd8e8832e01f996f32459073f4dd308fe5265baWinson Wang - Sun Microsystems - Beijing China rcb->lro_pkt = B_FALSE;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rcb->mp = desballoc((unsigned char *)
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China rx_buf->address,
73cd555c10e70dac413ae4b40de8450a291750acBin Tu - Sun Microsystems - Beijing China rx_buf->size,
9da57d7b0ddd8d73b676ce12c040362132cdd538bt 0, &rcb->free_rtn);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_SUCCESS);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538btalloc_rcb_lists_fail:
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_free_rcb_lists(rx_data);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt return (IXGBE_FAILURE);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_free_rcb_lists - Free the receive control blocks of one ring.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btstatic void
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing Chinaixgbe_free_rcb_lists(ixgbe_rx_data_t *rx_data)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_t *ixgbe;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt rx_control_block_t *rcb;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt uint32_t rcb_count;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China uint32_t ref_cnt;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China int i;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe = rx_data->rx_ring->ixgbe;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China mutex_enter(&ixgbe->rx_pending_lock);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb = rx_data->rcb_area;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb_count = rx_data->ring_size + rx_data->free_list_size;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt for (i = 0; i < rcb_count; i++, rcb++) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ASSERT(rcb != NULL);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ref_cnt = atomic_dec_32_nv(&rcb->ref_cnt);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (ref_cnt == 0) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China if (rcb->mp != NULL) {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China freemsg(rcb->mp);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China rcb->mp = NULL;
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China }
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China ixgbe_free_dma_buffer(&rcb->rx_buf);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China } else {
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China atomic_inc_32(&rx_data->rcb_pending);
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China atomic_inc_32(&ixgbe->rcb_pending);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
ea65739ebec0cbd625d8c89e19592be58fa186a6chenlu chen - Sun Microsystems - Beijing China mutex_exit(&ixgbe->rx_pending_lock);
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}
9da57d7b0ddd8d73b676ce12c040362132cdd538bt
9da57d7b0ddd8d73b676ce12c040362132cdd538bt/*
9da57d7b0ddd8d73b676ce12c040362132cdd538bt * ixgbe_set_fma_flags - Set the attribute for fma support.
9da57d7b0ddd8d73b676ce12c040362132cdd538bt */
9da57d7b0ddd8d73b676ce12c040362132cdd538btvoid
837c1ac4e72b7d86278cca88b1075af557f7d161Stephen Hansonixgbe_set_fma_flags(int dma_flag)
9da57d7b0ddd8d73b676ce12c040362132cdd538bt{
9da57d7b0ddd8d73b676ce12c040362132cdd538bt if (dma_flag) {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_dma_attr.dma_attr_flags = DDI_DMA_FLAGERR;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_buf_dma_attr.dma_attr_flags = DDI_DMA_FLAGERR;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_desc_dma_attr.dma_attr_flags = DDI_DMA_FLAGERR;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt } else {
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_tx_dma_attr.dma_attr_flags = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_buf_dma_attr.dma_attr_flags = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt ixgbe_desc_dma_attr.dma_attr_flags = 0;
9da57d7b0ddd8d73b676ce12c040362132cdd538bt }
9da57d7b0ddd8d73b676ce12c040362132cdd538bt}