hxge_txdma.c revision 1ed830817782694e7259ee818a2f8eee72233f1e
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <hxge_impl.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <hxge_txdma.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/llc1.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint32_t hxge_reclaim_pending = TXDMA_RECLAIM_PENDING_DEFAULT;
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint32_t hxge_tx_minfree = 64;
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint32_t hxge_tx_intr_thres = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint32_t hxge_tx_max_gathers = TX_MAX_GATHER_POINTERS;
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint32_t hxge_tx_tiny_pack = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint32_t hxge_tx_use_bcopy = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern uint32_t hxge_tx_ring_size;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeeextern uint32_t hxge_bcopy_thresh;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeeextern uint32_t hxge_dvma_thresh;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeeextern uint32_t hxge_dma_stream_thresh;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeeextern dma_method_t hxge_force_dma;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Device register access attributes for PIO. */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeeextern ddi_device_acc_attr_t hxge_dev_reg_acc_attr;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee/* Device descriptor access attributes for DMA. */
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern ddi_device_acc_attr_t hxge_dev_desc_dma_acc_attr;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee/* Device buffer access attributes for DMA. */
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern ddi_device_acc_attr_t hxge_dev_buf_dma_acc_attr;
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern ddi_dma_attr_t hxge_desc_dma_attr;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockextern ddi_dma_attr_t hxge_tx_dma_attr;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic hxge_status_t hxge_map_txdma(p_hxge_t hxgep);
f82bfe17f53efa8e4aca04a764d0352539201fb5gwstatic void hxge_unmap_txdma(p_hxge_t hxgep);
f82bfe17f53efa8e4aca04a764d0352539201fb5gwstatic hxge_status_t hxge_txdma_hw_start(p_hxge_t hxgep);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic void hxge_txdma_hw_stop(p_hxge_t hxgep);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic hxge_status_t hxge_map_txdma_channel(p_hxge_t hxgep, uint16_t channel,
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_hxge_dma_common_t *dma_buf_p, p_tx_ring_t *tx_desc_p,
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint32_t num_chunks, p_hxge_dma_common_t *dma_cntl_p,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee p_tx_mbox_t *tx_mbox_p);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic void hxge_unmap_txdma_channel(p_hxge_t hxgep, uint16_t channel,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic hxge_status_t hxge_map_txdma_channel_buf_ring(p_hxge_t hxgep, uint16_t,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee p_hxge_dma_common_t *, p_tx_ring_t *, uint32_t);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic void hxge_unmap_txdma_channel_buf_ring(p_hxge_t hxgep,
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_ring_t tx_ring_p);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic void hxge_map_txdma_channel_cfg_ring(p_hxge_t, uint16_t,
6b4acc8bd9d480535a4d057e291dc7c049f664d9ahrens p_hxge_dma_common_t *, p_tx_ring_t, p_tx_mbox_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic void hxge_unmap_txdma_channel_cfg_ring(p_hxge_t hxgep,
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic hxge_status_t hxge_txdma_start_channel(p_hxge_t hxgep, uint16_t channel,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic hxge_status_t hxge_txdma_stop_channel(p_hxge_t hxgep, uint16_t channel,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic p_tx_ring_t hxge_txdma_get_ring(p_hxge_t hxgep, uint16_t channel);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic hxge_status_t hxge_tx_err_evnts(p_hxge_t hxgep, uint_t index,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee p_hxge_ldv_t ldvp, tdc_stat_t cs);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic p_tx_mbox_t hxge_txdma_get_mbox(p_hxge_t hxgep, uint16_t channel);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic hxge_status_t hxge_txdma_fatal_err_recover(p_hxge_t hxgep,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee uint16_t channel, p_tx_ring_t tx_ring_p);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeestatic hxge_status_t hxge_tx_port_fatal_err_recover(p_hxge_t hxgep);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_status_t
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_init_txdma_channels(p_hxge_t hxgep)
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee{
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee hxge_status_t status = HXGE_OK;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee block_reset_t reset_reg;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_init_txdma_channels"));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /*
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * Reset TDC block from PEU to cleanup any unknown configuration.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * This may be resulted from previous reboot.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee reset_reg.value = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens reset_reg.bits.tdc_rst = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_REG_WR32(hxgep->hpi_handle, BLOCK_RESET, reset_reg.value);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DELAY(1000);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
fa9e4066f08beec538e775443c5be79dd423fcabahrens status = hxge_map_txdma(hxgep);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (status != HXGE_OK) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "<== hxge_init_txdma_channels: status 0x%x", status));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (status);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
fa9e4066f08beec538e775443c5be79dd423fcabahrens status = hxge_txdma_hw_start(hxgep);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (status != HXGE_OK) {
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee hxge_unmap_txdma(hxgep);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (status);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "<== hxge_init_txdma_channels: status 0x%x", status));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (HXGE_OK);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickvoid
99653d4ee642c6528e88224f12409a5f23060994eschrockhxge_uninit_txdma_channels(p_hxge_t hxgep)
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee{
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_uninit_txdma_channels"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens hxge_txdma_hw_stop(hxgep);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee hxge_unmap_txdma(hxgep);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_uinit_txdma_channels"));
9c9dc39aa72ac40bb2558d54adfa596d217135d9ek}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_setup_dma_common(p_hxge_dma_common_t dest_p, p_hxge_dma_common_t src_p,
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint32_t entries, uint32_t size)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens size_t tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens *dest_p = *src_p;
fa9e4066f08beec538e775443c5be79dd423fcabahrens tsize = size * entries;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dest_p->alength = tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dest_p->nblocks = entries;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dest_p->block_size = size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dest_p->offset += tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens src_p->kaddrp = (caddr_t)dest_p->kaddrp + tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens src_p->alength -= tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens src_p->dma_cookie.dmac_laddress += tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens src_p->dma_cookie.dmac_size -= tsize;
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_status_t
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_reset_txdma_channel(p_hxge_t hxgep, uint16_t channel, uint64_t reg_data)
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee{
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee hpi_status_t rs = HPI_SUCCESS;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hxge_status_t status = HXGE_OK;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hpi_handle_t handle;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((hxgep, TX_CTL, " ==> hxge_reset_txdma_channel"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
f82bfe17f53efa8e4aca04a764d0352539201fb5gw handle = HXGE_DEV_HPI_HANDLE(hxgep);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((reg_data & TDC_TDR_RST_MASK) == TDC_TDR_RST_MASK) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens rs = hpi_txdma_channel_reset(handle, channel);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
fa9e4066f08beec538e775443c5be79dd423fcabahrens rs = hpi_txdma_channel_control(handle, TXDMA_RESET, channel);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (rs != HPI_SUCCESS) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee status = HXGE_ERROR | rs;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee }
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /*
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * Reset the tail (kick) register to 0. (Hardware will not reset it. Tx
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * overflow fatal error if tail is not set to 0 after reset!
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens TXDMA_REG_WRITE64(handle, TDC_TDR_KICK, channel, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((hxgep, TX_CTL, " <== hxge_reset_txdma_channel"));
903a11ebdc8df157c4700150f41f1f262f4a8ae8rh
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (status);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_status_t
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_init_txdma_channel_event_mask(p_hxge_t hxgep, uint16_t channel,
fa9e4066f08beec538e775443c5be79dd423fcabahrens tdc_int_mask_t *mask_p)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens hpi_handle_t handle;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hpi_status_t rs = HPI_SUCCESS;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hxge_status_t status = HXGE_OK;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "<== hxge_init_txdma_channel_event_mask"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens handle = HXGE_DEV_HPI_HANDLE(hxgep);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
903a11ebdc8df157c4700150f41f1f262f4a8ae8rh /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Mask off tx_rng_oflow since it is a false alarm. The driver
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ensures not over flowing the hardware and check the hardware
fa9e4066f08beec538e775443c5be79dd423fcabahrens * status.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens mask_p->bits.tx_rng_oflow = 1;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock rs = hpi_txdma_event_mask(handle, OP_SET, channel, mask_p);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (rs != HPI_SUCCESS) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens status = HXGE_ERROR | rs;
9c9dc39aa72ac40bb2558d54adfa596d217135d9ek }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee "==> hxge_init_txdma_channel_event_mask"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (status);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_status_t
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_enable_txdma_channel(p_hxge_t hxgep,
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint16_t channel, p_tx_ring_t tx_desc_p, p_tx_mbox_t mbox_p)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens hpi_handle_t handle;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hpi_status_t rs = HPI_SUCCESS;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hxge_status_t status = HXGE_OK;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_enable_txdma_channel"));
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee handle = HXGE_DEV_HPI_HANDLE(hxgep);
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee /*
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Use configuration data composed at init time. Write to hardware the
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * transmit ring configurations.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee */
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee rs = hpi_txdma_ring_config(handle, OP_SET, channel,
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee (uint64_t *)&(tx_desc_p->tx_ring_cfig.value));
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (rs != HPI_SUCCESS) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (HXGE_ERROR | rs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Write to hardware the mailbox */
fa9e4066f08beec538e775443c5be79dd423fcabahrens rs = hpi_txdma_mbox_config(handle, OP_SET, channel,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (uint64_t *)&mbox_p->tx_mbox.dma_cookie.dmac_laddress);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (rs != HPI_SUCCESS) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (HXGE_ERROR | rs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Start the DMA engine. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens rs = hpi_txdma_channel_init_enable(handle, channel);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (rs != HPI_SUCCESS) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (HXGE_ERROR | rs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_enable_txdma_channel"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (status);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_fill_tx_hdr(p_mblk_t mp, boolean_t fill_len, boolean_t l4_cksum,
9c9dc39aa72ac40bb2558d54adfa596d217135d9ek int pkt_len, uint8_t npads, p_tx_pkt_hdr_all_t pkthdrp)
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee{
6b4acc8bd9d480535a4d057e291dc7c049f664d9ahrens p_tx_pkt_header_t hdrp;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee p_mblk_t nmp;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee uint64_t tmp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens size_t mblk_len;
fa9e4066f08beec538e775443c5be79dd423fcabahrens size_t iph_len;
fa9e4066f08beec538e775443c5be79dd423fcabahrens size_t hdrs_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint8_t *ip_buf;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint16_t eth_type;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint8_t ipproto;
fa9e4066f08beec538e775443c5be79dd423fcabahrens boolean_t is_vlan = B_FALSE;
fa9e4066f08beec538e775443c5be79dd423fcabahrens size_t eth_hdr_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint8_t hdrs_buf[sizeof (struct ether_header) + 64 + sizeof (uint32_t)];
fa9e4066f08beec538e775443c5be79dd423fcabahrens
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_fill_tx_hdr: mp $%p", mp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee /*
23b1152649c9108566b32df4271af4e0af580480maybee * Caller should zero out the headers first.
23b1152649c9108566b32df4271af4e0af580480maybee */
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp = (p_tx_pkt_header_t)&pkthdrp->pkthdr;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (fill_len) {
6b4acc8bd9d480535a4d057e291dc7c049f664d9ahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_fill_tx_hdr: pkt_len %d npads %d",
fa9e4066f08beec538e775443c5be79dd423fcabahrens pkt_len, npads));
fa9e4066f08beec538e775443c5be79dd423fcabahrens tmp = (uint64_t)pkt_len;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value |= (tmp << TX_PKT_HEADER_TOT_XFER_LEN_SHIFT);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens goto fill_tx_header_done;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens tmp = (uint64_t)npads;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value |= (tmp << TX_PKT_HEADER_PAD_SHIFT);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee /*
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * mp is the original data packet (does not include the Neptune
fa9e4066f08beec538e775443c5be79dd423fcabahrens * transmit header).
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens nmp = mp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens mblk_len = (size_t)nmp->b_wptr - (size_t)nmp->b_rptr;
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_fill_tx_hdr: mp $%p b_rptr $%p len %d",
fa9e4066f08beec538e775443c5be79dd423fcabahrens mp, nmp->b_rptr, mblk_len));
fa9e4066f08beec538e775443c5be79dd423fcabahrens ip_buf = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens bcopy(nmp->b_rptr, &hdrs_buf[0], sizeof (struct ether_vlan_header));
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_type = ntohs(((p_ether_header_t)hdrs_buf)->ether_type);
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> : hxge_fill_tx_hdr: (value 0x%llx) ether type 0x%x",
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_type, hdrp->value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (eth_type < ETHERMTU) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens tmp = 1ull;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value |= (tmp << TX_PKT_HEADER_LLC_SHIFT);
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_tx_pkt_hdr_init: LLC value 0x%llx", hdrp->value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (*(hdrs_buf + sizeof (struct ether_header)) ==
fa9e4066f08beec538e775443c5be79dd423fcabahrens LLC_SNAP_SAP) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_type = ntohs(*((uint16_t *)(hdrs_buf +
fa9e4066f08beec538e775443c5be79dd423fcabahrens sizeof (struct ether_header) + 6)));
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_tx_pkt_hdr_init: LLC ether type 0x%x",
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_type));
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
fa9e4066f08beec538e775443c5be79dd423fcabahrens goto fill_tx_header_done;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee } else if (eth_type == VLAN_ETHERTYPE) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens tmp = 1ull;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value |= (tmp << TX_PKT_HEADER_VLAN__SHIFT);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_type = ntohs(((struct ether_vlan_header *)
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrs_buf)->ether_type);
fa9e4066f08beec538e775443c5be79dd423fcabahrens is_vlan = B_TRUE;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_tx_pkt_hdr_init: VLAN value 0x%llx",
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!is_vlan) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_hdr_size = sizeof (struct ether_header);
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
fa9e4066f08beec538e775443c5be79dd423fcabahrens eth_hdr_size = sizeof (struct ether_vlan_header);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (eth_type) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens case ETHERTYPE_IP:
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (mblk_len > eth_hdr_size + sizeof (uint8_t)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ip_buf = nmp->b_rptr + eth_hdr_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens mblk_len -= eth_hdr_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens iph_len = ((*ip_buf) & 0x0f);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (mblk_len > (iph_len + sizeof (uint32_t))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ip_buf = nmp->b_rptr;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee ip_buf += eth_hdr_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee ip_buf = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock }
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ip_buf == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrs_size = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ((p_ether_header_t)hdrs_buf)->ether_type = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((nmp) && (hdrs_size < sizeof (hdrs_buf))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens mblk_len = (size_t)nmp->b_wptr -
fa9e4066f08beec538e775443c5be79dd423fcabahrens (size_t)nmp->b_rptr;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (mblk_len >=
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee (sizeof (hdrs_buf) - hdrs_size))
fa9e4066f08beec538e775443c5be79dd423fcabahrens mblk_len = sizeof (hdrs_buf) -
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrs_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens bcopy(nmp->b_rptr,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock &hdrs_buf[hdrs_size], mblk_len);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock hdrs_size += mblk_len;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock nmp = nmp->b_cont;
1934e92fc930c49429ad71a8ca97340f33227e78maybee }
1934e92fc930c49429ad71a8ca97340f33227e78maybee ip_buf = hdrs_buf;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ip_buf += eth_hdr_size;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens iph_len = ((*ip_buf) & 0x0f);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens }
c543ec060d1359f6c8a9507242521f344a2ac3efahrens ipproto = ip_buf[9];
c543ec060d1359f6c8a9507242521f344a2ac3efahrens
d90a49d672f767313fb19463579f6fe92b3353a8maybee tmp = (uint64_t)iph_len;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens hdrp->value |= (tmp << TX_PKT_HEADER_IHL_SHIFT);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens tmp = (uint64_t)(eth_hdr_size >> 1);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens hdrp->value |= (tmp << TX_PKT_HEADER_L3START_SHIFT);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens
d90a49d672f767313fb19463579f6fe92b3353a8maybee HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_fill_tx_hdr: IPv4 "
d90a49d672f767313fb19463579f6fe92b3353a8maybee " iph_len %d l3start %d eth_hdr_size %d proto 0x%x"
d90a49d672f767313fb19463579f6fe92b3353a8maybee "tmp 0x%x", iph_len, hdrp->bits.l3start, eth_hdr_size,
d90a49d672f767313fb19463579f6fe92b3353a8maybee ipproto, tmp));
d90a49d672f767313fb19463579f6fe92b3353a8maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
f82bfe17f53efa8e4aca04a764d0352539201fb5gw "==> hxge_tx_pkt_hdr_init: IP value 0x%llx", hdrp->value));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock break;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
c543ec060d1359f6c8a9507242521f344a2ac3efahrens case ETHERTYPE_IPV6:
c543ec060d1359f6c8a9507242521f344a2ac3efahrens hdrs_size = 0;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens ((p_ether_header_t)hdrs_buf)->ether_type = 0;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens while ((nmp) && (hdrs_size < sizeof (hdrs_buf))) {
c543ec060d1359f6c8a9507242521f344a2ac3efahrens mblk_len = (size_t)nmp->b_wptr - (size_t)nmp->b_rptr;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens if (mblk_len >= (sizeof (hdrs_buf) - hdrs_size))
c543ec060d1359f6c8a9507242521f344a2ac3efahrens mblk_len = sizeof (hdrs_buf) - hdrs_size;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens bcopy(nmp->b_rptr, &hdrs_buf[hdrs_size], mblk_len);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens hdrs_size += mblk_len;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens nmp = nmp->b_cont;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens }
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ip_buf = hdrs_buf;
d90a49d672f767313fb19463579f6fe92b3353a8maybee ip_buf += eth_hdr_size;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens
c543ec060d1359f6c8a9507242521f344a2ac3efahrens tmp = 1ull;
c543ec060d1359f6c8a9507242521f344a2ac3efahrens hdrp->value |= (tmp << TX_PKT_HEADER_IP_VER_SHIFT);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens
c543ec060d1359f6c8a9507242521f344a2ac3efahrens tmp = (eth_hdr_size >> 1);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens hdrp->value |= (tmp << TX_PKT_HEADER_L3START_SHIFT);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens
c543ec060d1359f6c8a9507242521f344a2ac3efahrens /* byte 6 is the next header protocol */
c543ec060d1359f6c8a9507242521f344a2ac3efahrens ipproto = ip_buf[6];
c543ec060d1359f6c8a9507242521f344a2ac3efahrens
c543ec060d1359f6c8a9507242521f344a2ac3efahrens HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_fill_tx_hdr: IPv6 "
c543ec060d1359f6c8a9507242521f344a2ac3efahrens " iph_len %d l3start %d eth_hdr_size %d proto 0x%x",
c543ec060d1359f6c8a9507242521f344a2ac3efahrens iph_len, hdrp->bits.l3start, eth_hdr_size, ipproto));
c543ec060d1359f6c8a9507242521f344a2ac3efahrens HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_tx_pkt_hdr_init: IPv6 "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "value 0x%llx", hdrp->value));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock break;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock default:
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_fill_tx_hdr: non-IP"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto fill_tx_header_done;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock }
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock switch (ipproto) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee case IPPROTO_TCP:
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_fill_tx_hdr: TCP (cksum flag %d)", l4_cksum));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (l4_cksum) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens tmp = 1ull;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee hdrp->value |= (tmp << TX_PKT_HEADER_PKT_TYPE_SHIFT);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "==> hxge_tx_pkt_hdr_init: TCP CKSUM"
fa9e4066f08beec538e775443c5be79dd423fcabahrens "value 0x%llx", hdrp->value));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick }
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick HXGE_DEBUG_MSG((NULL, TX_CTL,
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick "==> hxge_tx_pkt_hdr_init: TCP value 0x%llx", hdrp->value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens break;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee case IPPROTO_UDP:
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_fill_tx_hdr: UDP"));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (l4_cksum) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee tmp = 0x2ull;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value |= (tmp << TX_PKT_HEADER_PKT_TYPE_SHIFT);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum }
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "==> hxge_tx_pkt_hdr_init: UDP value 0x%llx",
fa9e4066f08beec538e775443c5be79dd423fcabahrens hdrp->value));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee break;
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick
fa9e4066f08beec538e775443c5be79dd423fcabahrens default:
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee goto fill_tx_header_done;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeefill_tx_header_done:
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "==> hxge_fill_tx_hdr: pkt_len %d npads %d value 0x%llx",
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee pkt_len, npads, hdrp->value));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL, "<== hxge_fill_tx_hdr"));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee}
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee/*ARGSUSED*/
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybeep_mblk_t
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybeehxge_tx_pkt_header_reserve(p_mblk_t mp, uint8_t *npads)
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee{
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee p_mblk_t newmp = NULL;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if ((newmp = allocb(TX_PKT_HEADER_SIZE, BPRI_MED)) == NULL) {
1934e92fc930c49429ad71a8ca97340f33227e78maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "<== hxge_tx_pkt_header_reserve: allocb failed"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (NULL);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock }
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock HXGE_DEBUG_MSG((NULL, TX_CTL,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "==> hxge_tx_pkt_header_reserve: get new mp"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock DB_TYPE(newmp) = M_DATA;
55434c770c89aa1b84474f2559a106803511aba0ek newmp->b_rptr = newmp->b_wptr = DB_LIM(newmp);
55434c770c89aa1b84474f2559a106803511aba0ek linkb(newmp, mp);
55434c770c89aa1b84474f2559a106803511aba0ek newmp->b_rptr -= TX_PKT_HEADER_SIZE;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==>hxge_tx_pkt_header_reserve: b_rptr $%p b_wptr $%p",
fa9e4066f08beec538e775443c5be79dd423fcabahrens newmp->b_rptr, newmp->b_wptr));
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "<== hxge_tx_pkt_header_reserve: use new mp"));
c543ec060d1359f6c8a9507242521f344a2ac3efahrens return (newmp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensint
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_tx_pkt_nmblocks(p_mblk_t mp, int *tot_xfer_len_p)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint_t nmblks;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ssize_t len;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint_t pkt_len;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_mblk_t nmp, bmp, tmp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint8_t *b_wptr;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_tx_pkt_nmblocks: mp $%p rptr $%p wptr $%p len %d",
fa9e4066f08beec538e775443c5be79dd423fcabahrens mp, mp->b_rptr, mp->b_wptr, MBLKL(mp)));
758f6e0b258f20dcb5b772642e2a18b998ee7927gw
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum nmp = mp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens bmp = mp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens nmblks = 0;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock pkt_len = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens *tot_xfer_len_p = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (nmp) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens len = MBLKL(nmp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_tx_pkt_nmblocks: "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "len %d pkt_len %d nmblks %d tot_xfer_len %d",
fa9e4066f08beec538e775443c5be79dd423fcabahrens len, pkt_len, nmblks, *tot_xfer_len_p));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (len <= 0) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee bmp = nmp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens nmp = nmp->b_cont;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "==> hxge_tx_pkt_nmblocks:"
fa9e4066f08beec538e775443c5be79dd423fcabahrens " len (0) pkt_len %d nmblks %d", pkt_len, nmblks));
fa9e4066f08beec538e775443c5be79dd423fcabahrens continue;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee *tot_xfer_len_p += len;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee HXGE_DEBUG_MSG((NULL, TX_CTL, "==> hxge_tx_pkt_nmblocks: "
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens "len %d pkt_len %d nmblks %d tot_xfer_len %d",
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum len, pkt_len, nmblks, *tot_xfer_len_p));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (len < hxge_bcopy_thresh) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens "==> hxge_tx_pkt_nmblocks: "
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens "len %d (< thresh) pkt_len %d nmblks %d",
9c9dc39aa72ac40bb2558d54adfa596d217135d9ek len, pkt_len, nmblks));
c543ec060d1359f6c8a9507242521f344a2ac3efahrens if (pkt_len == 0)
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee nmblks++;
fa9e4066f08beec538e775443c5be79dd423fcabahrens pkt_len += len;
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens if (pkt_len >= hxge_bcopy_thresh) {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens pkt_len = 0;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum len = 0;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum nmp = bmp;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum }
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum } else {
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum "==> hxge_tx_pkt_nmblocks: "
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum "len %d (> thresh) pkt_len %d nmblks %d",
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens len, pkt_len, nmblks));
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens pkt_len = 0;
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens nmblks++;
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens /*
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * Hardware limits the transfer length to 4K. If len is
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * more than 4K, we need to break it up to at most 2
fa9e4066f08beec538e775443c5be79dd423fcabahrens * more blocks.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (len > TX_MAX_TRANSFER_LENGTH) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint32_t nsegs;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((NULL, TX_CTL,
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee "==> hxge_tx_pkt_nmblocks: "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "len %d pkt_len %d nmblks %d nsegs %d",
fa9e4066f08beec538e775443c5be79dd423fcabahrens len, pkt_len, nmblks, nsegs));
fa9e4066f08beec538e775443c5be79dd423fcabahrens nsegs = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (len % (TX_MAX_TRANSFER_LENGTH * 2)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ++nsegs;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens do {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee b_wptr = nmp->b_rptr +
f676ed3419ae468da6c6831c143b0b54173e08d2ahrens TX_MAX_TRANSFER_LENGTH;
f676ed3419ae468da6c6831c143b0b54173e08d2ahrens nmp->b_wptr = b_wptr;
f676ed3419ae468da6c6831c143b0b54173e08d2ahrens if ((tmp = dupb(nmp)) == NULL) {
f676ed3419ae468da6c6831c143b0b54173e08d2ahrens return (0);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens }
c543ec060d1359f6c8a9507242521f344a2ac3efahrens tmp->b_rptr = b_wptr;
fa9e4066f08beec538e775443c5be79dd423fcabahrens tmp->b_wptr = nmp->b_wptr;
f676ed3419ae468da6c6831c143b0b54173e08d2ahrens tmp->b_cont = nmp->b_cont;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee nmp->b_cont = tmp;
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum nmblks++;
347a31bcb38b51837caee115d3979d3a981cc099ahrens if (--nsegs) {
347a31bcb38b51837caee115d3979d3a981cc099ahrens nmp = tmp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
c543ec060d1359f6c8a9507242521f344a2ac3efahrens } while (nsegs);
c543ec060d1359f6c8a9507242521f344a2ac3efahrens nmp = tmp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
1934e92fc930c49429ad71a8ca97340f33227e78maybee
1934e92fc930c49429ad71a8ca97340f33227e78maybee /*
1934e92fc930c49429ad71a8ca97340f33227e78maybee * Hardware limits the transmit gather pointers to 15.
1934e92fc930c49429ad71a8ca97340f33227e78maybee */
1934e92fc930c49429ad71a8ca97340f33227e78maybee if (nmp->b_cont && (nmblks + TX_GATHER_POINTERS_THRESHOLD) >
1934e92fc930c49429ad71a8ca97340f33227e78maybee TX_MAX_GATHER_POINTERS) {
1934e92fc930c49429ad71a8ca97340f33227e78maybee HXGE_DEBUG_MSG((NULL, TX_CTL,
1934e92fc930c49429ad71a8ca97340f33227e78maybee "==> hxge_tx_pkt_nmblocks: pull msg - "
1934e92fc930c49429ad71a8ca97340f33227e78maybee "len %d pkt_len %d nmblks %d",
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum len, pkt_len, nmblks));
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum /* Pull all message blocks from b_cont */
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if ((tmp = msgpullup(nmp->b_cont, -1)) == NULL) {
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum return (0);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum }
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum freemsg(nmp->b_cont);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum nmp->b_cont = tmp;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum pkt_len = 0;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum }
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum bmp = nmp;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum nmp = nmp->b_cont;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum }
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum HXGE_DEBUG_MSG((NULL, TX_CTL,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum "<== hxge_tx_pkt_nmblocks: rptr $%p wptr $%p "
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum "nmblks %d len %d tot_xfer_len %d",
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum mp->b_rptr, mp->b_wptr, nmblks, MBLKL(mp), *tot_xfer_len_p));
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum return (nmblks);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensboolean_t
fa9e4066f08beec538e775443c5be79dd423fcabahrenshxge_txdma_reclaim(p_hxge_t hxgep, p_tx_ring_t tx_ring_p, int nmblks)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens boolean_t status = B_TRUE;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_hxge_dma_common_t tx_desc_dma_p;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hxge_dma_common_t desc_area;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_desc_t tx_desc_ring_vp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_desc_t tx_desc_p;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_desc_t tx_desc_pp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx_desc_t r_tx_desc;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_msg_t tx_msg_ring;
fa9e4066f08beec538e775443c5be79dd423fcabahrens p_tx_msg_t tx_msg_p;
fa9e4066f08beec538e775443c5be79dd423fcabahrens hpi_handle_t handle;
fa9e4066f08beec538e775443c5be79dd423fcabahrens tdc_tdr_head_t tx_head;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum uint32_t pkt_len;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum uint_t tx_rd_index;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum uint16_t head_index, tail_index;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum uint8_t tdc;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum boolean_t head_wrap, tail_wrap;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum p_hxge_tx_ring_stats_t tdc_stats;
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum tdc_byte_cnt_t byte_cnt;
fa9e4066f08beec538e775443c5be79dd423fcabahrens tdc_tdr_qlen_t qlen;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee int rc;
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_reclaim"));
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee status = ((tx_ring_p->descs_pending < hxge_reclaim_pending) &&
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee (nmblks != 0));
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee HXGE_DEBUG_MSG((hxgep, TX_CTL,
fa9e4066f08beec538e775443c5be79dd423fcabahrens "==> hxge_txdma_reclaim: pending %d reclaim %d nmblks %d",
1934e92fc930c49429ad71a8ca97340f33227e78maybee tx_ring_p->descs_pending, hxge_reclaim_pending, nmblks));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (!status) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee tx_desc_dma_p = &tx_ring_p->tdc_desc;
fa9e4066f08beec538e775443c5be79dd423fcabahrens desc_area = tx_ring_p->tdc_desc;
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx_desc_ring_vp = tx_desc_dma_p->kaddrp;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tx_desc_ring_vp = (p_tx_desc_t)DMA_COMMON_VPTR(desc_area);
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tx_rd_index = tx_ring_p->rd_index;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tx_desc_p = &tx_desc_ring_vp[tx_rd_index];
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tx_msg_ring = tx_ring_p->tx_msg_ring;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tx_msg_p = &tx_msg_ring[tx_rd_index];
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tdc = tx_ring_p->tdc;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tdc_stats = tx_ring_p->tdc_stats;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee if (tx_ring_p->descs_pending > tdc_stats->tx_max_pend) {
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tdc_stats->tx_max_pend = tx_ring_p->descs_pending;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee }
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tail_index = tx_ring_p->wr_index;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tail_wrap = tx_ring_p->wr_index_wrap;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee /*
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee * tdc_byte_cnt reg can be used to get bytes transmitted. It
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee * includes padding too in case of runt packets.
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee */
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee handle = HXGE_DEV_HPI_HANDLE(hxgep);
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee TXDMA_REG_READ64(handle, TDC_BYTE_CNT, tdc, &byte_cnt.value);
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee tdc_stats->obytes_with_pad += byte_cnt.bits.byte_count;
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee HXGE_DEBUG_MSG((hxgep, TX_CTL,
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee "==> hxge_txdma_reclaim: tdc %d tx_rd_index %d "
da03de9920a5a87150a121e9851479c6b3364d8aMark Maybee "tail_index %d tail_wrap %d tx_desc_p $%p ($%p) ",
fa9e4066f08beec538e775443c5be79dd423fcabahrens tdc, tx_rd_index, tail_index, tail_wrap,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee tx_desc_p, (*(uint64_t *)tx_desc_p)));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Read the hardware maintained transmit head and wrap around
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * bit.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens TXDMA_REG_READ64(handle, TDC_TDR_HEAD, tdc, &tx_head.value);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee head_index = tx_head.bits.head;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee head_wrap = tx_head.bits.wrap;
fa9e4066f08beec538e775443c5be79dd423fcabahrens HXGE_DEBUG_MSG((hxgep, TX_CTL,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "==> hxge_txdma_reclaim: "
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee "tx_rd_index %d tail %d tail_wrap %d head %d wrap %d",
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee tx_rd_index, tail_index, tail_wrap, head_index, head_wrap));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /*
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * For debug only. This can be used to verify the qlen and make
fa9e4066f08beec538e775443c5be79dd423fcabahrens * sure the hardware is wrapping the Tdr correctly.
*/
TXDMA_REG_READ64(handle, TDC_TDR_QLEN, tdc, &qlen.value);
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: tdr_qlen %d tdr_pref_qlen %d",
qlen.bits.tdr_qlen, qlen.bits.tdr_pref_qlen));
if (head_index == tail_index) {
if (TXDMA_RING_EMPTY(head_index, head_wrap, tail_index,
tail_wrap) && (head_index == tx_rd_index)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: EMPTY"));
return (B_TRUE);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: Checking if ring full"));
if (TXDMA_RING_FULL(head_index, head_wrap, tail_index,
tail_wrap)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: full"));
return (B_FALSE);
}
}
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: tx_rd_index and head_index"));
/* XXXX: limit the # of reclaims */
tx_desc_pp = &r_tx_desc;
while ((tx_rd_index != head_index) &&
(tx_ring_p->descs_pending != 0)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: Checking if pending"));
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: descs_pending %d ",
tx_ring_p->descs_pending));
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: "
"(tx_rd_index %d head_index %d (tx_desc_p $%p)",
tx_rd_index, head_index, tx_desc_p));
tx_desc_pp->value = tx_desc_p->value;
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: "
"(tx_rd_index %d head_index %d "
"tx_desc_p $%p (desc value 0x%llx) ",
tx_rd_index, head_index,
tx_desc_pp, (*(uint64_t *)tx_desc_pp)));
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: dump desc:"));
/*
* tdc_byte_cnt reg can be used to get bytes
* transmitted
*/
pkt_len = tx_desc_pp->bits.tr_len;
tdc_stats->obytes += pkt_len;
tdc_stats->opackets += tx_desc_pp->bits.sop;
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: pkt_len %d "
"tdc channel %d opackets %d",
pkt_len, tdc, tdc_stats->opackets));
if (tx_msg_p->flags.dma_type == USE_DVMA) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"tx_desc_p = $%p tx_desc_pp = $%p "
"index = %d",
tx_desc_p, tx_desc_pp,
tx_ring_p->rd_index));
(void) dvma_unload(tx_msg_p->dvma_handle,
0, -1);
tx_msg_p->dvma_handle = NULL;
if (tx_ring_p->dvma_wr_index ==
tx_ring_p->dvma_wrap_mask) {
tx_ring_p->dvma_wr_index = 0;
} else {
tx_ring_p->dvma_wr_index++;
}
tx_ring_p->dvma_pending--;
} else if (tx_msg_p->flags.dma_type == USE_DMA) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: USE DMA"));
if (rc = ddi_dma_unbind_handle
(tx_msg_p->dma_handle)) {
cmn_err(CE_WARN, "hxge_reclaim: "
"ddi_dma_unbind_handle "
"failed. status %d", rc);
}
}
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_reclaim: count packets"));
/*
* count a chained packet only once.
*/
if (tx_msg_p->tx_message != NULL) {
freemsg(tx_msg_p->tx_message);
tx_msg_p->tx_message = NULL;
}
tx_msg_p->flags.dma_type = USE_NONE;
tx_rd_index = tx_ring_p->rd_index;
tx_rd_index = (tx_rd_index + 1) &
tx_ring_p->tx_wrap_mask;
tx_ring_p->rd_index = tx_rd_index;
tx_ring_p->descs_pending--;
tx_desc_p = &tx_desc_ring_vp[tx_rd_index];
tx_msg_p = &tx_msg_ring[tx_rd_index];
}
status = (nmblks <= ((int)tx_ring_p->tx_ring_size -
(int)tx_ring_p->descs_pending - TX_FULL_MARK));
if (status) {
cas32((uint32_t *)&tx_ring_p->queueing, 1, 0);
}
} else {
status = (nmblks <= ((int)tx_ring_p->tx_ring_size -
(int)tx_ring_p->descs_pending - TX_FULL_MARK));
}
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_reclaim status = 0x%08x", status));
return (status);
}
uint_t
hxge_tx_intr(caddr_t arg1, caddr_t arg2)
{
p_hxge_ldv_t ldvp = (p_hxge_ldv_t)arg1;
p_hxge_t hxgep = (p_hxge_t)arg2;
p_hxge_ldg_t ldgp;
uint8_t channel;
uint32_t vindex;
hpi_handle_t handle;
tdc_stat_t cs;
p_tx_ring_t *tx_rings;
p_tx_ring_t tx_ring_p;
hpi_status_t rs = HPI_SUCCESS;
uint_t serviced = DDI_INTR_UNCLAIMED;
hxge_status_t status = HXGE_OK;
if (ldvp == NULL) {
HXGE_DEBUG_MSG((NULL, INT_CTL,
"<== hxge_tx_intr: hxgep $%p ldvp $%p", hxgep, ldvp));
return (DDI_INTR_UNCLAIMED);
}
if (arg2 == NULL || (void *) ldvp->hxgep != arg2) {
hxgep = ldvp->hxgep;
}
/*
* If the interface is not started, just swallow the interrupt
* and don't rearm the logical device.
*/
if (hxgep->hxge_mac_state != HXGE_MAC_STARTED)
return (DDI_INTR_CLAIMED);
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_tx_intr: hxgep(arg2) $%p ldvp(arg1) $%p", hxgep, ldvp));
/*
* This interrupt handler is for a specific transmit dma channel.
*/
handle = HXGE_DEV_HPI_HANDLE(hxgep);
/* Get the control and status for this channel. */
channel = ldvp->channel;
ldgp = ldvp->ldgp;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_tx_intr: hxgep $%p ldvp (ldvp) $%p channel %d",
hxgep, ldvp, channel));
rs = hpi_txdma_control_status(handle, OP_GET, channel, &cs);
vindex = ldvp->vdma_index;
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_tx_intr:channel %d ring index %d status 0x%08x",
channel, vindex, rs));
if (!rs && cs.bits.marked) {
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_tx_intr:channel %d ring index %d "
"status 0x%08x (marked bit set)", channel, vindex, rs));
tx_rings = hxgep->tx_rings->rings;
tx_ring_p = tx_rings[vindex];
HXGE_DEBUG_MSG((hxgep, INT_CTL,
"==> hxge_tx_intr:channel %d ring index %d "
"status 0x%08x (marked bit set, calling reclaim)",
channel, vindex, rs));
MUTEX_ENTER(&tx_ring_p->lock);
(void) hxge_txdma_reclaim(hxgep, tx_rings[vindex], 0);
MUTEX_EXIT(&tx_ring_p->lock);
mac_tx_update(hxgep->mach);
}
/*
* Process other transmit control and status. Check the ldv state.
*/
status = hxge_tx_err_evnts(hxgep, ldvp->vdma_index, ldvp, cs);
/* Clear the error bits */
RXDMA_REG_WRITE64(handle, TDC_STAT, channel, cs.value);
/*
* Rearm this logical group if this is a single device group.
*/
if (ldgp->nldvs == 1) {
HXGE_DEBUG_MSG((hxgep, INT_CTL, "==> hxge_tx_intr: rearm"));
if (status == HXGE_OK) {
(void) hpi_intr_ldg_mgmt_set(handle, ldgp->ldg,
B_TRUE, ldgp->ldg_timer);
}
}
HXGE_DEBUG_MSG((hxgep, INT_CTL, "<== hxge_tx_intr"));
serviced = DDI_INTR_CLAIMED;
return (serviced);
}
void
hxge_txdma_stop(p_hxge_t hxgep)
{
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_stop"));
(void) hxge_tx_vmac_disable(hxgep);
(void) hxge_txdma_hw_mode(hxgep, HXGE_DMA_STOP);
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_stop"));
}
hxge_status_t
hxge_txdma_hw_mode(p_hxge_t hxgep, boolean_t enable)
{
int i, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t *tx_desc_rings;
hpi_handle_t handle;
hpi_status_t rs = HPI_SUCCESS;
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_mode: enable mode %d", enable));
if (!(hxgep->drv_state & STATE_HW_INITIALIZED)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_mode: not initialized"));
return (HXGE_ERROR);
}
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_mode: NULL global ring pointer"));
return (HXGE_ERROR);
}
tx_desc_rings = tx_rings->rings;
if (tx_desc_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_mode: NULL rings pointer"));
return (HXGE_ERROR);
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"<== hxge_txdma_hw_mode: no dma channel allocated"));
return (HXGE_ERROR);
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_mode: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_desc_rings, ndmas));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
for (i = 0; i < ndmas; i++) {
if (tx_desc_rings[i] == NULL) {
continue;
}
channel = tx_desc_rings[i]->tdc;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_mode: channel %d", channel));
if (enable) {
rs = hpi_txdma_channel_enable(handle, channel);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_mode: channel %d (enable) "
"rs 0x%x", channel, rs));
} else {
/*
* Stop the dma channel and waits for the stop done. If
* the stop done bit is not set, then force an error so
* TXC will stop. All channels bound to this port need
* to be stopped and reset after injecting an interrupt
* error.
*/
rs = hpi_txdma_channel_disable(handle, channel);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_mode: channel %d (disable) "
"rs 0x%x", channel, rs));
}
}
status = ((rs == HPI_SUCCESS) ? HXGE_OK : HXGE_ERROR | rs);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_txdma_hw_mode: status 0x%x", status));
return (status);
}
void
hxge_txdma_enable_channel(p_hxge_t hxgep, uint16_t channel)
{
hpi_handle_t handle;
HXGE_DEBUG_MSG((hxgep, DMA_CTL,
"==> hxge_txdma_enable_channel: channel %d", channel));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
/* enable the transmit dma channels */
(void) hpi_txdma_channel_enable(handle, channel);
HXGE_DEBUG_MSG((hxgep, DMA_CTL, "<== hxge_txdma_enable_channel"));
}
void
hxge_txdma_disable_channel(p_hxge_t hxgep, uint16_t channel)
{
hpi_handle_t handle;
HXGE_DEBUG_MSG((hxgep, DMA_CTL,
"==> hxge_txdma_disable_channel: channel %d", channel));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
/* stop the transmit dma channels */
(void) hpi_txdma_channel_disable(handle, channel);
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_disable_channel"));
}
int
hxge_txdma_stop_inj_err(p_hxge_t hxgep, int channel)
{
hpi_handle_t handle;
int status;
hpi_status_t rs = HPI_SUCCESS;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_stop_inj_err"));
/*
* Stop the dma channel waits for the stop done. If the stop done bit
* is not set, then create an error.
*/
handle = HXGE_DEV_HPI_HANDLE(hxgep);
rs = hpi_txdma_channel_disable(handle, channel);
status = ((rs == HPI_SUCCESS) ? HXGE_OK : HXGE_ERROR | rs);
if (status == HXGE_OK) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_stop_inj_err (channel %d): "
"stopped OK", channel));
return (status);
}
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_stop_inj_err (channel): stop failed (0x%x) "
" (injected error but still not stopped)", channel, rs));
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_stop_inj_err"));
return (status);
}
/*ARGSUSED*/
void
hxge_fixup_txdma_rings(p_hxge_t hxgep)
{
int index, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_fixup_txdma_rings"));
/*
* For each transmit channel, reclaim each descriptor and free buffers.
*/
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_fixup_txdma_rings: NULL ring pointer"));
return;
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_fixup_txdma_rings: no channel allocated"));
return;
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_fixup_txdma_rings: NULL rings pointer"));
return;
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_fixup_txdma_rings: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_rings->rings, ndmas));
for (index = 0; index < ndmas; index++) {
channel = tx_rings->rings[index]->tdc;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_fixup_txdma_rings: channel %d", channel));
hxge_txdma_fixup_channel(hxgep, tx_rings->rings[index],
channel);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_fixup_txdma_rings"));
}
/*ARGSUSED*/
void
hxge_txdma_fix_channel(p_hxge_t hxgep, uint16_t channel)
{
p_tx_ring_t ring_p;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_fix_channel"));
ring_p = hxge_txdma_get_ring(hxgep, channel);
if (ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_fix_channel"));
return;
}
if (ring_p->tdc != channel) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fix_channel: channel not matched "
"ring tdc %d passed channel", ring_p->tdc, channel));
return;
}
hxge_txdma_fixup_channel(hxgep, ring_p, channel);
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_fix_channel"));
}
/*ARGSUSED*/
void
hxge_txdma_fixup_channel(p_hxge_t hxgep, p_tx_ring_t ring_p, uint16_t channel)
{
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_fixup_channel"));
if (ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_channel: NULL ring pointer"));
return;
}
if (ring_p->tdc != channel) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_channel: channel not matched "
"ring tdc %d passed channel", ring_p->tdc, channel));
return;
}
MUTEX_ENTER(&ring_p->lock);
(void) hxge_txdma_reclaim(hxgep, ring_p, 0);
ring_p->rd_index = 0;
ring_p->wr_index = 0;
ring_p->ring_head.value = 0;
ring_p->ring_kick_tail.value = 0;
ring_p->descs_pending = 0;
MUTEX_EXIT(&ring_p->lock);
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_fixup_channel"));
}
/*ARGSUSED*/
void
hxge_txdma_hw_kick(p_hxge_t hxgep)
{
int index, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_hw_kick"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_kick: NULL ring pointer"));
return;
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_kick: no channel allocated"));
return;
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_kick: NULL rings pointer"));
return;
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_kick: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_rings->rings, ndmas));
for (index = 0; index < ndmas; index++) {
channel = tx_rings->rings[index]->tdc;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_kick: channel %d", channel));
hxge_txdma_hw_kick_channel(hxgep, tx_rings->rings[index],
channel);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_hw_kick"));
}
/*ARGSUSED*/
void
hxge_txdma_kick_channel(p_hxge_t hxgep, uint16_t channel)
{
p_tx_ring_t ring_p;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_kick_channel"));
ring_p = hxge_txdma_get_ring(hxgep, channel);
if (ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL, " hxge_txdma_kick_channel"));
return;
}
if (ring_p->tdc != channel) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_kick_channel: channel not matched "
"ring tdc %d passed channel", ring_p->tdc, channel));
return;
}
hxge_txdma_hw_kick_channel(hxgep, ring_p, channel);
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_kick_channel"));
}
/*ARGSUSED*/
void
hxge_txdma_hw_kick_channel(p_hxge_t hxgep, p_tx_ring_t ring_p, uint16_t channel)
{
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_hw_kick_channel"));
if (ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_kick_channel: NULL ring pointer"));
return;
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_hw_kick_channel"));
}
/*ARGSUSED*/
void
hxge_check_tx_hang(p_hxge_t hxgep)
{
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_check_tx_hang"));
/*
* Needs inputs from hardware for regs: head index had not moved since
* last timeout. packets not transmitted or stuffed registers.
*/
if (hxge_txdma_hung(hxgep)) {
hxge_fixup_hung_txdma_rings(hxgep);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_check_tx_hang"));
}
int
hxge_txdma_hung(p_hxge_t hxgep)
{
int index, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t tx_ring_p;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_hung"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hung: NULL ring pointer"));
return (B_FALSE);
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hung: no channel allocated"));
return (B_FALSE);
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hung: NULL rings pointer"));
return (B_FALSE);
}
for (index = 0; index < ndmas; index++) {
channel = tx_rings->rings[index]->tdc;
tx_ring_p = tx_rings->rings[index];
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_hung: channel %d", channel));
if (hxge_txdma_channel_hung(hxgep, tx_ring_p, channel)) {
return (B_TRUE);
}
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_hung"));
return (B_FALSE);
}
int
hxge_txdma_channel_hung(p_hxge_t hxgep, p_tx_ring_t tx_ring_p, uint16_t channel)
{
uint16_t head_index, tail_index;
boolean_t head_wrap, tail_wrap;
hpi_handle_t handle;
tdc_tdr_head_t tx_head;
uint_t tx_rd_index;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_channel_hung"));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_channel_hung: channel %d", channel));
MUTEX_ENTER(&tx_ring_p->lock);
(void) hxge_txdma_reclaim(hxgep, tx_ring_p, 0);
tail_index = tx_ring_p->wr_index;
tail_wrap = tx_ring_p->wr_index_wrap;
tx_rd_index = tx_ring_p->rd_index;
MUTEX_EXIT(&tx_ring_p->lock);
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_channel_hung: tdc %d tx_rd_index %d "
"tail_index %d tail_wrap %d ",
channel, tx_rd_index, tail_index, tail_wrap));
/*
* Read the hardware maintained transmit head and wrap around bit.
*/
(void) hpi_txdma_ring_head_get(handle, channel, &tx_head);
head_index = tx_head.bits.head;
head_wrap = tx_head.bits.wrap;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_channel_hung: "
"tx_rd_index %d tail %d tail_wrap %d head %d wrap %d",
tx_rd_index, tail_index, tail_wrap, head_index, head_wrap));
if (TXDMA_RING_EMPTY(head_index, head_wrap, tail_index, tail_wrap) &&
(head_index == tx_rd_index)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_channel_hung: EMPTY"));
return (B_FALSE);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_channel_hung: Checking if ring full"));
if (TXDMA_RING_FULL(head_index, head_wrap, tail_index, tail_wrap)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_txdma_channel_hung: full"));
return (B_TRUE);
}
/* If not full, check with hardware to see if it is hung */
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_channel_hung"));
return (B_FALSE);
}
/*ARGSUSED*/
void
hxge_fixup_hung_txdma_rings(p_hxge_t hxgep)
{
int index, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_fixup_hung_txdma_rings"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_fixup_hung_txdma_rings: NULL ring pointer"));
return;
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_fixup_hung_txdma_rings: no channel allocated"));
return;
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_fixup_hung_txdma_rings: NULL rings pointer"));
return;
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_fixup_hung_txdma_rings: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_rings->rings, ndmas));
for (index = 0; index < ndmas; index++) {
channel = tx_rings->rings[index]->tdc;
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_fixup_hung_txdma_rings: channel %d", channel));
hxge_txdma_fixup_hung_channel(hxgep, tx_rings->rings[index],
channel);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_fixup_hung_txdma_rings"));
}
/*ARGSUSED*/
void
hxge_txdma_fix_hung_channel(p_hxge_t hxgep, uint16_t channel)
{
p_tx_ring_t ring_p;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_fix_hung_channel"));
ring_p = hxge_txdma_get_ring(hxgep, channel);
if (ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fix_hung_channel"));
return;
}
if (ring_p->tdc != channel) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fix_hung_channel: channel not matched "
"ring tdc %d passed channel", ring_p->tdc, channel));
return;
}
hxge_txdma_fixup_channel(hxgep, ring_p, channel);
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_fix_hung_channel"));
}
/*ARGSUSED*/
void
hxge_txdma_fixup_hung_channel(p_hxge_t hxgep, p_tx_ring_t ring_p,
uint16_t channel)
{
hpi_handle_t handle;
int status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_fixup_hung_channel"));
if (ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_hung_channel: NULL ring pointer"));
return;
}
if (ring_p->tdc != channel) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_hung_channel: channel "
"not matched ring tdc %d passed channel",
ring_p->tdc, channel));
return;
}
/* Reclaim descriptors */
MUTEX_ENTER(&ring_p->lock);
(void) hxge_txdma_reclaim(hxgep, ring_p, 0);
MUTEX_EXIT(&ring_p->lock);
handle = HXGE_DEV_HPI_HANDLE(hxgep);
/*
* Stop the dma channel waits for the stop done. If the stop done bit
* is not set, then force an error.
*/
status = hpi_txdma_channel_disable(handle, channel);
if (!(status & HPI_TXDMA_STOP_FAILED)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_hung_channel: stopped OK "
"ring tdc %d passed channel %d", ring_p->tdc, channel));
return;
}
/* Stop done bit will be set as a result of error injection */
status = hpi_txdma_channel_disable(handle, channel);
if (!(status & HPI_TXDMA_STOP_FAILED)) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_hung_channel: stopped again"
"ring tdc %d passed channel", ring_p->tdc, channel));
return;
}
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_fixup_hung_channel: stop done still not set!! "
"ring tdc %d passed channel", ring_p->tdc, channel));
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_fixup_hung_channel"));
}
/*ARGSUSED*/
void
hxge_reclaim_rings(p_hxge_t hxgep)
{
int index, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t tx_ring_p;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_reclaim_ring"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_reclain_rimgs: NULL ring pointer"));
return;
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_reclain_rimgs: no channel allocated"));
return;
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_reclain_rimgs: NULL rings pointer"));
return;
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_reclain_rimgs: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_rings->rings, ndmas));
for (index = 0; index < ndmas; index++) {
channel = tx_rings->rings[index]->tdc;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> reclain_rimgs: channel %d",
channel));
tx_ring_p = tx_rings->rings[index];
MUTEX_ENTER(&tx_ring_p->lock);
(void) hxge_txdma_reclaim(hxgep, tx_ring_p, channel);
MUTEX_EXIT(&tx_ring_p->lock);
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_reclaim_rings"));
}
/*
* Static functions start here.
*/
static hxge_status_t
hxge_map_txdma(p_hxge_t hxgep)
{
int i, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t *tx_desc_rings;
p_tx_mbox_areas_t tx_mbox_areas_p;
p_tx_mbox_t *tx_mbox_p;
p_hxge_dma_pool_t dma_buf_poolp;
p_hxge_dma_pool_t dma_cntl_poolp;
p_hxge_dma_common_t *dma_buf_p;
p_hxge_dma_common_t *dma_cntl_p;
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_map_txdma"));
dma_buf_poolp = hxgep->tx_buf_pool_p;
dma_cntl_poolp = hxgep->tx_cntl_pool_p;
if (!dma_buf_poolp->buf_allocated || !dma_cntl_poolp->buf_allocated) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_map_txdma: buf not allocated"));
return (HXGE_ERROR);
}
ndmas = dma_buf_poolp->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_map_txdma: no dma allocated"));
return (HXGE_ERROR);
}
dma_buf_p = dma_buf_poolp->dma_buf_pool_p;
dma_cntl_p = dma_cntl_poolp->dma_buf_pool_p;
tx_rings = (p_tx_rings_t)KMEM_ZALLOC(sizeof (tx_rings_t), KM_SLEEP);
tx_desc_rings = (p_tx_ring_t *)KMEM_ZALLOC(
sizeof (p_tx_ring_t) * ndmas, KM_SLEEP);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_map_txdma: "
"tx_rings $%p tx_desc_rings $%p", tx_rings, tx_desc_rings));
tx_mbox_areas_p = (p_tx_mbox_areas_t)
KMEM_ZALLOC(sizeof (tx_mbox_areas_t), KM_SLEEP);
tx_mbox_p = (p_tx_mbox_t *)KMEM_ZALLOC(
sizeof (p_tx_mbox_t) * ndmas, KM_SLEEP);
/*
* Map descriptors from the buffer pools for each dma channel.
*/
for (i = 0; i < ndmas; i++) {
/*
* Set up and prepare buffer blocks, descriptors and mailbox.
*/
channel = ((p_hxge_dma_common_t)dma_buf_p[i])->dma_channel;
status = hxge_map_txdma_channel(hxgep, channel,
(p_hxge_dma_common_t *)&dma_buf_p[i],
(p_tx_ring_t *)&tx_desc_rings[i],
dma_buf_poolp->num_chunks[i],
(p_hxge_dma_common_t *)&dma_cntl_p[i],
(p_tx_mbox_t *)&tx_mbox_p[i]);
if (status != HXGE_OK) {
goto hxge_map_txdma_fail1;
}
tx_desc_rings[i]->index = (uint16_t)i;
tx_desc_rings[i]->tdc_stats = &hxgep->statsp->tdc_stats[i];
}
tx_rings->ndmas = ndmas;
tx_rings->rings = tx_desc_rings;
hxgep->tx_rings = tx_rings;
tx_mbox_areas_p->txmbox_areas_p = tx_mbox_p;
hxgep->tx_mbox_areas_p = tx_mbox_areas_p;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_map_txdma: "
"tx_rings $%p rings $%p", hxgep->tx_rings, hxgep->tx_rings->rings));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_map_txdma: "
"tx_rings $%p tx_desc_rings $%p",
hxgep->tx_rings, tx_desc_rings));
goto hxge_map_txdma_exit;
hxge_map_txdma_fail1:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma: uninit tx desc "
"(status 0x%x channel %d i %d)", hxgep, status, channel, i));
i--;
for (; i >= 0; i--) {
channel = ((p_hxge_dma_common_t)dma_buf_p[i])->dma_channel;
hxge_unmap_txdma_channel(hxgep, channel, tx_desc_rings[i],
tx_mbox_p[i]);
}
KMEM_FREE(tx_desc_rings, sizeof (p_tx_ring_t) * ndmas);
KMEM_FREE(tx_rings, sizeof (tx_rings_t));
KMEM_FREE(tx_mbox_p, sizeof (p_tx_mbox_t) * ndmas);
KMEM_FREE(tx_mbox_areas_p, sizeof (tx_mbox_areas_t));
hxge_map_txdma_exit:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma: (status 0x%x channel %d)", status, channel));
return (status);
}
static void
hxge_unmap_txdma(p_hxge_t hxgep)
{
int i, ndmas;
uint8_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t *tx_desc_rings;
p_tx_mbox_areas_t tx_mbox_areas_p;
p_tx_mbox_t *tx_mbox_p;
p_hxge_dma_pool_t dma_buf_poolp;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_unmap_txdma"));
dma_buf_poolp = hxgep->tx_buf_pool_p;
if (!dma_buf_poolp->buf_allocated) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"==> hxge_unmap_txdma: buf not allocated"));
return;
}
ndmas = dma_buf_poolp->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_unmap_txdma: no dma allocated"));
return;
}
tx_rings = hxgep->tx_rings;
tx_desc_rings = tx_rings->rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_unmap_txdma: NULL ring pointer"));
return;
}
tx_desc_rings = tx_rings->rings;
if (tx_desc_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_unmap_txdma: NULL ring pointers"));
return;
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_unmap_txdma: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_desc_rings, ndmas));
tx_mbox_areas_p = hxgep->tx_mbox_areas_p;
tx_mbox_p = tx_mbox_areas_p->txmbox_areas_p;
for (i = 0; i < ndmas; i++) {
channel = tx_desc_rings[i]->tdc;
(void) hxge_unmap_txdma_channel(hxgep, channel,
(p_tx_ring_t)tx_desc_rings[i],
(p_tx_mbox_t)tx_mbox_p[i]);
}
KMEM_FREE(tx_desc_rings, sizeof (p_tx_ring_t) * ndmas);
KMEM_FREE(tx_rings, sizeof (tx_rings_t));
KMEM_FREE(tx_mbox_p, sizeof (p_tx_mbox_t) * ndmas);
KMEM_FREE(tx_mbox_areas_p, sizeof (tx_mbox_areas_t));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_unmap_txdma"));
}
static hxge_status_t
hxge_map_txdma_channel(p_hxge_t hxgep, uint16_t channel,
p_hxge_dma_common_t *dma_buf_p, p_tx_ring_t *tx_desc_p,
uint32_t num_chunks, p_hxge_dma_common_t *dma_cntl_p,
p_tx_mbox_t *tx_mbox_p)
{
int status = HXGE_OK;
/*
* Set up and prepare buffer blocks, descriptors and mailbox.
*/
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel (channel %d)", channel));
/*
* Transmit buffer blocks
*/
status = hxge_map_txdma_channel_buf_ring(hxgep, channel,
dma_buf_p, tx_desc_p, num_chunks);
if (status != HXGE_OK) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_map_txdma_channel (channel %d): "
"map buffer failed 0x%x", channel, status));
goto hxge_map_txdma_channel_exit;
}
/*
* Transmit block ring, and mailbox.
*/
hxge_map_txdma_channel_cfg_ring(hxgep, channel, dma_cntl_p, *tx_desc_p,
tx_mbox_p);
goto hxge_map_txdma_channel_exit;
hxge_map_txdma_channel_fail1:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel: unmap buf"
"(status 0x%x channel %d)", status, channel));
hxge_unmap_txdma_channel_buf_ring(hxgep, *tx_desc_p);
hxge_map_txdma_channel_exit:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_map_txdma_channel: (status 0x%x channel %d)",
status, channel));
return (status);
}
/*ARGSUSED*/
static void
hxge_unmap_txdma_channel(p_hxge_t hxgep, uint16_t channel,
p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p)
{
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_unmap_txdma_channel (channel %d)", channel));
/* unmap tx block ring, and mailbox. */
(void) hxge_unmap_txdma_channel_cfg_ring(hxgep, tx_ring_p, tx_mbox_p);
/* unmap buffer blocks */
(void) hxge_unmap_txdma_channel_buf_ring(hxgep, tx_ring_p);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_unmap_txdma_channel"));
}
/*ARGSUSED*/
static void
hxge_map_txdma_channel_cfg_ring(p_hxge_t hxgep, uint16_t dma_channel,
p_hxge_dma_common_t *dma_cntl_p, p_tx_ring_t tx_ring_p,
p_tx_mbox_t *tx_mbox_p)
{
p_tx_mbox_t mboxp;
p_hxge_dma_common_t cntl_dmap;
p_hxge_dma_common_t dmap;
tdc_tdr_cfg_t *tx_ring_cfig_p;
tdc_tdr_kick_t *tx_ring_kick_p;
tdc_tdr_cfg_t *tx_cs_p;
tdc_int_mask_t *tx_evmask_p;
tdc_mbh_t *mboxh_p;
tdc_mbl_t *mboxl_p;
uint64_t tx_desc_len;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_cfg_ring"));
cntl_dmap = *dma_cntl_p;
dmap = (p_hxge_dma_common_t)&tx_ring_p->tdc_desc;
hxge_setup_dma_common(dmap, cntl_dmap, tx_ring_p->tx_ring_size,
sizeof (tx_desc_t));
/*
* Zero out transmit ring descriptors.
*/
bzero((caddr_t)dmap->kaddrp, dmap->alength);
tx_ring_cfig_p = &(tx_ring_p->tx_ring_cfig);
tx_ring_kick_p = &(tx_ring_p->tx_ring_kick);
tx_cs_p = &(tx_ring_p->tx_cs);
tx_evmask_p = &(tx_ring_p->tx_evmask);
tx_ring_cfig_p->value = 0;
tx_ring_kick_p->value = 0;
tx_cs_p->value = 0;
tx_evmask_p->value = 0;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_cfg_ring: channel %d des $%p",
dma_channel, dmap->dma_cookie.dmac_laddress));
tx_ring_cfig_p->value = 0;
/* Hydra len is 11 bits and the lower 5 bits are 0s */
tx_desc_len = (uint64_t)(tx_ring_p->tx_ring_size >> 5);
tx_ring_cfig_p->value =
(dmap->dma_cookie.dmac_laddress & TDC_TDR_CFG_ADDR_MASK) |
(tx_desc_len << TDC_TDR_CFG_LEN_SHIFT);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_cfg_ring: channel %d cfg 0x%llx",
dma_channel, tx_ring_cfig_p->value));
tx_cs_p->bits.reset = 1;
/* Map in mailbox */
mboxp = (p_tx_mbox_t)KMEM_ZALLOC(sizeof (tx_mbox_t), KM_SLEEP);
dmap = (p_hxge_dma_common_t)&mboxp->tx_mbox;
hxge_setup_dma_common(dmap, cntl_dmap, 1, sizeof (txdma_mailbox_t));
mboxh_p = (tdc_mbh_t *)&tx_ring_p->tx_mbox_mbh;
mboxl_p = (tdc_mbl_t *)&tx_ring_p->tx_mbox_mbl;
mboxh_p->value = mboxl_p->value = 0;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_cfg_ring: mbox 0x%lx",
dmap->dma_cookie.dmac_laddress));
mboxh_p->bits.mbaddr = ((dmap->dma_cookie.dmac_laddress >>
TDC_MBH_ADDR_SHIFT) & TDC_MBH_MASK);
mboxl_p->bits.mbaddr = ((dmap->dma_cookie.dmac_laddress &
TDC_MBL_MASK) >> TDC_MBL_SHIFT);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_cfg_ring: mbox 0x%lx",
dmap->dma_cookie.dmac_laddress));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_cfg_ring: hmbox $%p mbox $%p",
mboxh_p->bits.mbaddr, mboxl_p->bits.mbaddr));
/*
* Set page valid and no mask
*/
tx_ring_p->page_hdl.value = 0;
*tx_mbox_p = mboxp;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_map_txdma_channel_cfg_ring"));
}
/*ARGSUSED*/
static void
hxge_unmap_txdma_channel_cfg_ring(p_hxge_t hxgep,
p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p)
{
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_unmap_txdma_channel_cfg_ring: channel %d",
tx_ring_p->tdc));
KMEM_FREE(tx_mbox_p, sizeof (tx_mbox_t));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_unmap_txdma_channel_cfg_ring"));
}
static hxge_status_t
hxge_map_txdma_channel_buf_ring(p_hxge_t hxgep, uint16_t channel,
p_hxge_dma_common_t *dma_buf_p,
p_tx_ring_t *tx_desc_p, uint32_t num_chunks)
{
p_hxge_dma_common_t dma_bufp, tmp_bufp;
p_hxge_dma_common_t dmap;
hxge_os_dma_handle_t tx_buf_dma_handle;
p_tx_ring_t tx_ring_p;
p_tx_msg_t tx_msg_ring;
hxge_status_t status = HXGE_OK;
int ddi_status = DDI_SUCCESS;
int i, j, index;
uint32_t size, bsize;
uint32_t nblocks, nmsgs;
char qname[TASKQ_NAMELEN];
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_buf_ring"));
dma_bufp = tmp_bufp = *dma_buf_p;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
" hxge_map_txdma_channel_buf_ring: channel %d to map %d "
"chunks bufp $%p", channel, num_chunks, dma_bufp));
nmsgs = 0;
for (i = 0; i < num_chunks; i++, tmp_bufp++) {
nmsgs += tmp_bufp->nblocks;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_buf_ring: channel %d "
"bufp $%p nblocks %d nmsgs %d",
channel, tmp_bufp, tmp_bufp->nblocks, nmsgs));
}
if (!nmsgs) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_map_txdma_channel_buf_ring: channel %d "
"no msg blocks", channel));
status = HXGE_ERROR;
goto hxge_map_txdma_channel_buf_ring_exit;
}
tx_ring_p = (p_tx_ring_t)KMEM_ZALLOC(sizeof (tx_ring_t), KM_SLEEP);
tx_ring_p->hxgep = hxgep;
(void) snprintf(qname, TASKQ_NAMELEN, "hxge_%d_%d",
hxgep->instance, channel);
tx_ring_p->taskq = ddi_taskq_create(hxgep->dip, qname, 1,
TASKQ_DEFAULTPRI, 0);
if (tx_ring_p->taskq == NULL) {
goto hxge_map_txdma_channel_buf_ring_fail1;
}
MUTEX_INIT(&tx_ring_p->lock, NULL, MUTEX_DRIVER,
(void *) hxgep->interrupt_cookie);
/*
* Allocate transmit message rings and handles for packets not to be
* copied to premapped buffers.
*/
size = nmsgs * sizeof (tx_msg_t);
tx_msg_ring = KMEM_ZALLOC(size, KM_SLEEP);
for (i = 0; i < nmsgs; i++) {
ddi_status = ddi_dma_alloc_handle(hxgep->dip, &hxge_tx_dma_attr,
DDI_DMA_DONTWAIT, 0, &tx_msg_ring[i].dma_handle);
if (ddi_status != DDI_SUCCESS) {
status |= HXGE_DDI_FAILED;
break;
}
}
if (i < nmsgs) {
HXGE_DEBUG_MSG((hxgep, HXGE_ERR_CTL,
"Allocate handles failed."));
goto hxge_map_txdma_channel_buf_ring_fail1;
}
tx_ring_p->tdc = channel;
tx_ring_p->tx_msg_ring = tx_msg_ring;
tx_ring_p->tx_ring_size = nmsgs;
tx_ring_p->num_chunks = num_chunks;
if (!hxge_tx_intr_thres) {
hxge_tx_intr_thres = tx_ring_p->tx_ring_size / 4;
}
tx_ring_p->tx_wrap_mask = tx_ring_p->tx_ring_size - 1;
tx_ring_p->rd_index = 0;
tx_ring_p->wr_index = 0;
tx_ring_p->ring_head.value = 0;
tx_ring_p->ring_kick_tail.value = 0;
tx_ring_p->descs_pending = 0;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_buf_ring: channel %d "
"actual tx desc max %d nmsgs %d (config hxge_tx_ring_size %d)",
channel, tx_ring_p->tx_ring_size, nmsgs, hxge_tx_ring_size));
/*
* Map in buffers from the buffer pool.
*/
index = 0;
bsize = dma_bufp->block_size;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_map_txdma_channel_buf_ring: "
"dma_bufp $%p tx_rng_p $%p tx_msg_rng_p $%p bsize %d",
dma_bufp, tx_ring_p, tx_msg_ring, bsize));
for (i = 0; i < num_chunks; i++, dma_bufp++) {
bsize = dma_bufp->block_size;
nblocks = dma_bufp->nblocks;
tx_buf_dma_handle = dma_bufp->dma_handle;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_buf_ring: dma chunk %d "
"size %d dma_bufp $%p",
i, sizeof (hxge_dma_common_t), dma_bufp));
for (j = 0; j < nblocks; j++) {
tx_msg_ring[index].buf_dma_handle = tx_buf_dma_handle;
tx_msg_ring[index].offset_index = j;
dmap = &tx_msg_ring[index++].buf_dma;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_map_txdma_channel_buf_ring: j %d"
"dmap $%p", i, dmap));
hxge_setup_dma_common(dmap, dma_bufp, 1, bsize);
}
}
if (i < num_chunks) {
status = HXGE_ERROR;
goto hxge_map_txdma_channel_buf_ring_fail1;
}
*tx_desc_p = tx_ring_p;
goto hxge_map_txdma_channel_buf_ring_exit;
hxge_map_txdma_channel_buf_ring_fail1:
if (tx_ring_p->taskq) {
ddi_taskq_destroy(tx_ring_p->taskq);
tx_ring_p->taskq = NULL;
}
index--;
for (; index >= 0; index--) {
if (tx_msg_ring[index].dma_handle != NULL) {
ddi_dma_free_handle(&tx_msg_ring[index].dma_handle);
}
}
MUTEX_DESTROY(&tx_ring_p->lock);
KMEM_FREE(tx_msg_ring, size);
KMEM_FREE(tx_ring_p, sizeof (tx_ring_t));
status = HXGE_ERROR;
hxge_map_txdma_channel_buf_ring_exit:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_map_txdma_channel_buf_ring status 0x%x", status));
return (status);
}
/*ARGSUSED*/
static void
hxge_unmap_txdma_channel_buf_ring(p_hxge_t hxgep, p_tx_ring_t tx_ring_p)
{
p_tx_msg_t tx_msg_ring;
p_tx_msg_t tx_msg_p;
int i;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_unmap_txdma_channel_buf_ring"));
if (tx_ring_p == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_unmap_txdma_channel_buf_ring: NULL ringp"));
return;
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_unmap_txdma_channel_buf_ring: channel %d",
tx_ring_p->tdc));
MUTEX_ENTER(&tx_ring_p->lock);
tx_msg_ring = tx_ring_p->tx_msg_ring;
for (i = 0; i < tx_ring_p->tx_ring_size; i++) {
tx_msg_p = &tx_msg_ring[i];
if (tx_msg_p->flags.dma_type == USE_DVMA) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "entry = %d", i));
(void) dvma_unload(tx_msg_p->dvma_handle, 0, -1);
tx_msg_p->dvma_handle = NULL;
if (tx_ring_p->dvma_wr_index ==
tx_ring_p->dvma_wrap_mask) {
tx_ring_p->dvma_wr_index = 0;
} else {
tx_ring_p->dvma_wr_index++;
}
tx_ring_p->dvma_pending--;
} else if (tx_msg_p->flags.dma_type == USE_DMA) {
if (ddi_dma_unbind_handle(tx_msg_p->dma_handle)) {
cmn_err(CE_WARN, "hxge_unmap_tx_bug_ring: "
"ddi_dma_unbind_handle failed.");
}
}
if (tx_msg_p->tx_message != NULL) {
freemsg(tx_msg_p->tx_message);
tx_msg_p->tx_message = NULL;
}
}
for (i = 0; i < tx_ring_p->tx_ring_size; i++) {
if (tx_msg_ring[i].dma_handle != NULL) {
ddi_dma_free_handle(&tx_msg_ring[i].dma_handle);
}
}
MUTEX_EXIT(&tx_ring_p->lock);
if (tx_ring_p->taskq) {
ddi_taskq_destroy(tx_ring_p->taskq);
tx_ring_p->taskq = NULL;
}
MUTEX_DESTROY(&tx_ring_p->lock);
KMEM_FREE(tx_msg_ring, sizeof (tx_msg_t) * tx_ring_p->tx_ring_size);
KMEM_FREE(tx_ring_p, sizeof (tx_ring_t));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_unmap_txdma_channel_buf_ring"));
}
static hxge_status_t
hxge_txdma_hw_start(p_hxge_t hxgep)
{
int i, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t *tx_desc_rings;
p_tx_mbox_areas_t tx_mbox_areas_p;
p_tx_mbox_t *tx_mbox_p;
hxge_status_t status = HXGE_OK;
uint64_t tmp;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_start"));
/*
* Initialize REORD Table 1. Disable VMAC 2. Reset the FIFO Err Stat.
* 3. Scrub memory and check for errors.
*/
(void) hxge_tx_vmac_disable(hxgep);
/*
* Clear the error status
*/
HXGE_REG_WR64(hxgep->hpi_handle, TDC_FIFO_ERR_STAT, 0x7);
/*
* Scrub the rtab memory for the TDC and reset the TDC.
*/
HXGE_REG_WR64(hxgep->hpi_handle, TDC_REORD_TBL_DATA_HI, 0x0ULL);
HXGE_REG_WR64(hxgep->hpi_handle, TDC_REORD_TBL_DATA_LO, 0x0ULL);
for (i = 0; i < 256; i++) {
HXGE_REG_WR64(hxgep->hpi_handle, TDC_REORD_TBL_CMD,
(uint64_t)i);
/*
* Write the command register with an indirect read instruction
*/
tmp = (0x1ULL << 30) | i;
HXGE_REG_WR64(hxgep->hpi_handle, TDC_REORD_TBL_CMD, tmp);
/*
* Wait for status done
*/
tmp = 0;
do {
HXGE_REG_RD64(hxgep->hpi_handle, TDC_REORD_TBL_CMD,
&tmp);
} while (((tmp >> 31) & 0x1ULL) == 0x0);
}
for (i = 0; i < 256; i++) {
/*
* Write the command register with an indirect read instruction
*/
tmp = (0x1ULL << 30) | i;
HXGE_REG_WR64(hxgep->hpi_handle, TDC_REORD_TBL_CMD, tmp);
/*
* Wait for status done
*/
tmp = 0;
do {
HXGE_REG_RD64(hxgep->hpi_handle, TDC_REORD_TBL_CMD,
&tmp);
} while (((tmp >> 31) & 0x1ULL) == 0x0);
HXGE_REG_RD64(hxgep->hpi_handle, TDC_REORD_TBL_DATA_HI, &tmp);
if (0x1ff00ULL != (0x1ffffULL & tmp)) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "PANIC ReordTbl "
"unexpected data (hi), entry: %x, value: 0x%0llx\n",
i, (unsigned long long)tmp));
status = HXGE_ERROR;
}
HXGE_REG_RD64(hxgep->hpi_handle, TDC_REORD_TBL_DATA_LO, &tmp);
if (tmp != 0) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "PANIC ReordTbl "
"unexpected data (lo), entry: %x\n", i));
status = HXGE_ERROR;
}
HXGE_REG_RD64(hxgep->hpi_handle, TDC_FIFO_ERR_STAT, &tmp);
if (tmp != 0) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "PANIC ReordTbl "
"parity error, entry: %x, val 0x%llx\n",
i, (unsigned long long)tmp));
status = HXGE_ERROR;
}
HXGE_REG_RD64(hxgep->hpi_handle, TDC_FIFO_ERR_STAT, &tmp);
if (tmp != 0) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "PANIC ReordTbl "
"parity error, entry: %x\n", i));
status = HXGE_ERROR;
}
}
if (status != HXGE_OK)
goto hxge_txdma_hw_start_exit;
/*
* Reset FIFO Error Status for the TDC and enable FIFO error events.
*/
HXGE_REG_WR64(hxgep->hpi_handle, TDC_FIFO_ERR_STAT, 0x7);
HXGE_REG_WR64(hxgep->hpi_handle, TDC_FIFO_ERR_MASK, 0x0);
/*
* Initialize the Transmit DMAs.
*/
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_start: NULL ring pointer"));
return (HXGE_ERROR);
}
tx_desc_rings = tx_rings->rings;
if (tx_desc_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_start: NULL ring pointers"));
return (HXGE_ERROR);
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_start: no dma channel allocated"));
return (HXGE_ERROR);
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_start: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_desc_rings, ndmas));
tx_mbox_areas_p = hxgep->tx_mbox_areas_p;
tx_mbox_p = tx_mbox_areas_p->txmbox_areas_p;
/*
* Init the DMAs.
*/
for (i = 0; i < ndmas; i++) {
channel = tx_desc_rings[i]->tdc;
status = hxge_txdma_start_channel(hxgep, channel,
(p_tx_ring_t)tx_desc_rings[i],
(p_tx_mbox_t)tx_mbox_p[i]);
if (status != HXGE_OK) {
goto hxge_txdma_hw_start_fail1;
}
}
(void) hxge_tx_vmac_enable(hxgep);
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_start: tx_rings $%p rings $%p",
hxgep->tx_rings, hxgep->tx_rings->rings));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_start: tx_rings $%p tx_desc_rings $%p",
hxgep->tx_rings, tx_desc_rings));
goto hxge_txdma_hw_start_exit;
hxge_txdma_hw_start_fail1:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_start: disable (status 0x%x channel %d i %d)",
status, channel, i));
for (; i >= 0; i--) {
channel = tx_desc_rings[i]->tdc,
(void) hxge_txdma_stop_channel(hxgep, channel,
(p_tx_ring_t)tx_desc_rings[i],
(p_tx_mbox_t)tx_mbox_p[i]);
}
hxge_txdma_hw_start_exit:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_hw_start: (status 0x%x)", status));
return (status);
}
static void
hxge_txdma_hw_stop(p_hxge_t hxgep)
{
int i, ndmas;
uint16_t channel;
p_tx_rings_t tx_rings;
p_tx_ring_t *tx_desc_rings;
p_tx_mbox_areas_t tx_mbox_areas_p;
p_tx_mbox_t *tx_mbox_p;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_stop"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_stop: NULL ring pointer"));
return;
}
tx_desc_rings = tx_rings->rings;
if (tx_desc_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_stop: NULL ring pointers"));
return;
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_hw_stop: no dma channel allocated"));
return;
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_stop: "
"tx_rings $%p tx_desc_rings $%p", tx_rings, tx_desc_rings));
tx_mbox_areas_p = hxgep->tx_mbox_areas_p;
tx_mbox_p = tx_mbox_areas_p->txmbox_areas_p;
for (i = 0; i < ndmas; i++) {
channel = tx_desc_rings[i]->tdc;
(void) hxge_txdma_stop_channel(hxgep, channel,
(p_tx_ring_t)tx_desc_rings[i],
(p_tx_mbox_t)tx_mbox_p[i]);
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_hw_stop: "
"tx_rings $%p tx_desc_rings $%p", tx_rings, tx_desc_rings));
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_txdma_hw_stop"));
}
static hxge_status_t
hxge_txdma_start_channel(p_hxge_t hxgep, uint16_t channel,
p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p)
{
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_start_channel (channel %d)", channel));
/*
* TXDMA/TXC must be in stopped state.
*/
(void) hxge_txdma_stop_inj_err(hxgep, channel);
/*
* Reset TXDMA channel
*/
tx_ring_p->tx_cs.value = 0;
tx_ring_p->tx_cs.bits.reset = 1;
status = hxge_reset_txdma_channel(hxgep, channel,
tx_ring_p->tx_cs.value);
if (status != HXGE_OK) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_start_channel (channel %d)"
" reset channel failed 0x%x", channel, status));
goto hxge_txdma_start_channel_exit;
}
/*
* Initialize the TXDMA channel specific FZC control configurations.
* These FZC registers are pertaining to each TX channel (i.e. logical
* pages).
*/
status = hxge_init_fzc_txdma_channel(hxgep, channel,
tx_ring_p, tx_mbox_p);
if (status != HXGE_OK) {
goto hxge_txdma_start_channel_exit;
}
/*
* Initialize the event masks.
*/
tx_ring_p->tx_evmask.value = 0;
status = hxge_init_txdma_channel_event_mask(hxgep,
channel, &tx_ring_p->tx_evmask);
if (status != HXGE_OK) {
goto hxge_txdma_start_channel_exit;
}
/*
* Load TXDMA descriptors, buffers, mailbox, initialise the DMA
* channels and enable each DMA channel.
*/
status = hxge_enable_txdma_channel(hxgep, channel,
tx_ring_p, tx_mbox_p);
if (status != HXGE_OK) {
goto hxge_txdma_start_channel_exit;
}
hxge_txdma_start_channel_exit:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_txdma_start_channel"));
return (status);
}
/*ARGSUSED*/
static hxge_status_t
hxge_txdma_stop_channel(p_hxge_t hxgep, uint16_t channel,
p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p)
{
int status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_stop_channel: channel %d", channel));
/*
* Stop (disable) TXDMA and TXC (if stop bit is set and STOP_N_GO bit
* not set, the TXDMA reset state will not be set if reset TXDMA.
*/
(void) hxge_txdma_stop_inj_err(hxgep, channel);
/*
* Reset TXDMA channel
*/
tx_ring_p->tx_cs.value = 0;
tx_ring_p->tx_cs.bits.reset = 1;
status = hxge_reset_txdma_channel(hxgep, channel,
tx_ring_p->tx_cs.value);
if (status != HXGE_OK) {
goto hxge_txdma_stop_channel_exit;
}
hxge_txdma_stop_channel_exit:
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "<== hxge_txdma_stop_channel"));
return (status);
}
static p_tx_ring_t
hxge_txdma_get_ring(p_hxge_t hxgep, uint16_t channel)
{
int index, ndmas;
uint16_t tdc;
p_tx_rings_t tx_rings;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_get_ring"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_get_ring: NULL ring pointer"));
return (NULL);
}
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_get_ring: no channel allocated"));
return (NULL);
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_get_ring: NULL rings pointer"));
return (NULL);
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_get_ring: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_rings, ndmas));
for (index = 0; index < ndmas; index++) {
tdc = tx_rings->rings[index]->tdc;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_fixup_txdma_rings: channel %d", tdc));
if (channel == tdc) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_get_ring: tdc %d ring $%p",
tdc, tx_rings->rings[index]));
return (p_tx_ring_t)(tx_rings->rings[index]);
}
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_get_ring"));
return (NULL);
}
static p_tx_mbox_t
hxge_txdma_get_mbox(p_hxge_t hxgep, uint16_t channel)
{
int index, tdc, ndmas;
p_tx_rings_t tx_rings;
p_tx_mbox_areas_t tx_mbox_areas_p;
p_tx_mbox_t *tx_mbox_p;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_get_mbox"));
tx_rings = hxgep->tx_rings;
if (tx_rings == NULL) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_txdma_get_mbox: NULL ring pointer"));
return (NULL);
}
tx_mbox_areas_p = hxgep->tx_mbox_areas_p;
if (tx_mbox_areas_p == NULL) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_txdma_get_mbox: NULL mbox pointer"));
return (NULL);
}
tx_mbox_p = tx_mbox_areas_p->txmbox_areas_p;
ndmas = tx_rings->ndmas;
if (!ndmas) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_txdma_get_mbox: no channel allocated"));
return (NULL);
}
if (tx_rings->rings == NULL) {
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"<== hxge_txdma_get_mbox: NULL rings pointer"));
return (NULL);
}
HXGE_DEBUG_MSG((hxgep, MEM3_CTL, "==> hxge_txdma_get_mbox: "
"tx_rings $%p tx_desc_rings $%p ndmas %d",
tx_rings, tx_rings, ndmas));
for (index = 0; index < ndmas; index++) {
tdc = tx_rings->rings[index]->tdc;
HXGE_DEBUG_MSG((hxgep, MEM3_CTL,
"==> hxge_txdma_get_mbox: channel %d", tdc));
if (channel == tdc) {
HXGE_DEBUG_MSG((hxgep, TX_CTL,
"<== hxge_txdma_get_mbox: tdc %d ring $%p",
tdc, tx_rings->rings[index]));
return (p_tx_mbox_t)(tx_mbox_p[index]);
}
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_get_mbox"));
return (NULL);
}
/*ARGSUSED*/
static hxge_status_t
hxge_tx_err_evnts(p_hxge_t hxgep, uint_t index, p_hxge_ldv_t ldvp,
tdc_stat_t cs)
{
hpi_handle_t handle;
uint8_t channel;
p_tx_ring_t *tx_rings;
p_tx_ring_t tx_ring_p;
p_hxge_tx_ring_stats_t tdc_stats;
boolean_t txchan_fatal = B_FALSE;
hxge_status_t status = HXGE_OK;
tdc_drop_cnt_t drop_cnt;
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "==> hxge_tx_err_evnts"));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
channel = ldvp->channel;
tx_rings = hxgep->tx_rings->rings;
tx_ring_p = tx_rings[index];
tdc_stats = tx_ring_p->tdc_stats;
/* Get the error counts if any */
TXDMA_REG_READ64(handle, TDC_DROP_CNT, channel, &drop_cnt.value);
tdc_stats->count_hdr_size_err += drop_cnt.bits.hdr_size_error_count;
tdc_stats->count_runt += drop_cnt.bits.runt_count;
tdc_stats->count_abort += drop_cnt.bits.abort_count;
if (cs.bits.peu_resp_err) {
tdc_stats->peu_resp_err++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_PEU_RESP_ERR);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: peu_resp_err", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.pkt_size_hdr_err) {
tdc_stats->pkt_size_hdr_err++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_PKT_SIZE_HDR_ERR);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: pkt_size_hdr_err", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.runt_pkt_drop_err) {
tdc_stats->runt_pkt_drop_err++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_RUNT_PKT_DROP_ERR);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: runt_pkt_drop_err", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.pkt_size_err) {
tdc_stats->pkt_size_err++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_PKT_SIZE_ERR);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: pkt_size_err", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.tx_rng_oflow) {
tdc_stats->tx_rng_oflow++;
if (tdc_stats->tx_rng_oflow)
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: tx_rng_oflow", channel));
}
if (cs.bits.pref_par_err) {
tdc_stats->pref_par_err++;
/* Get the address of parity error read data */
TXDMA_REG_READ64(hxgep->hpi_handle, TDC_PREF_PAR_LOG,
channel, &tdc_stats->errlog.value);
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_PREF_PAR_ERR);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: pref_par_err", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.tdr_pref_cpl_to) {
tdc_stats->tdr_pref_cpl_to++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_TDR_PREF_CPL_TO);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: tdr_pref_cpl_to", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.pkt_cpl_to) {
tdc_stats->pkt_cpl_to++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_PKT_CPL_TO);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: pkt_cpl_to", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.invalid_sop) {
tdc_stats->invalid_sop++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_INVALID_SOP);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: invalid_sop", channel));
txchan_fatal = B_TRUE;
}
if (cs.bits.unexpected_sop) {
tdc_stats->unexpected_sop++;
HXGE_FM_REPORT_ERROR(hxgep, channel,
HXGE_FM_EREPORT_TDMC_UNEXPECTED_SOP);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_tx_err_evnts(channel %d): "
"fatal error: unexpected_sop", channel));
txchan_fatal = B_TRUE;
}
/* Clear error injection source in case this is an injected error */
TXDMA_REG_WRITE64(hxgep->hpi_handle, TDC_STAT_INT_DBG, channel, 0);
if (txchan_fatal) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
" hxge_tx_err_evnts: "
" fatal error on channel %d cs 0x%llx\n",
channel, cs.value));
status = hxge_txdma_fatal_err_recover(hxgep, channel,
tx_ring_p);
if (status == HXGE_OK) {
FM_SERVICE_RESTORED(hxgep);
}
}
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "<== hxge_tx_err_evnts"));
return (status);
}
hxge_status_t
hxge_txdma_handle_sys_errors(p_hxge_t hxgep)
{
hpi_handle_t handle;
hxge_status_t status = HXGE_OK;
tdc_fifo_err_stat_t fifo_stat;
hxge_tdc_sys_stats_t *tdc_sys_stats;
HXGE_DEBUG_MSG((hxgep, TX_CTL, "==> hxge_txdma_handle_sys_errors"));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
/*
* The FIFO is shared by all channels.
* Get the status of Reorder Buffer and Reorder Table Buffer Errors
*/
HXGE_REG_RD64(handle, TDC_FIFO_ERR_STAT, &fifo_stat.value);
/*
* Clear the error bits. Note that writing a 1 clears the bit. Writing
* a 0 does nothing.
*/
HXGE_REG_WR64(handle, TDC_FIFO_ERR_STAT, fifo_stat.value);
tdc_sys_stats = &hxgep->statsp->tdc_sys_stats;
if (fifo_stat.bits.reord_tbl_par_err) {
tdc_sys_stats->reord_tbl_par_err++;
HXGE_FM_REPORT_ERROR(hxgep, NULL,
HXGE_FM_EREPORT_TDMC_REORD_TBL_PAR);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_handle_sys_errors: fatal error: "
"reord_tbl_par_err"));
}
if (fifo_stat.bits.reord_buf_ded_err) {
tdc_sys_stats->reord_buf_ded_err++;
HXGE_FM_REPORT_ERROR(hxgep, NULL,
HXGE_FM_EREPORT_TDMC_REORD_BUF_DED);
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_handle_sys_errors: "
"fatal error: reord_buf_ded_err"));
}
if (fifo_stat.bits.reord_buf_sec_err) {
tdc_sys_stats->reord_buf_sec_err++;
if (tdc_sys_stats->reord_buf_sec_err == 1)
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_handle_sys_errors: "
"reord_buf_sec_err"));
}
if (fifo_stat.bits.reord_tbl_par_err ||
fifo_stat.bits.reord_buf_ded_err) {
status = hxge_tx_port_fatal_err_recover(hxgep);
if (status == HXGE_OK) {
FM_SERVICE_RESTORED(hxgep);
}
}
HXGE_DEBUG_MSG((hxgep, TX_CTL, "<== hxge_txdma_handle_sys_errors"));
return (status);
}
static hxge_status_t
hxge_txdma_fatal_err_recover(p_hxge_t hxgep, uint16_t channel,
p_tx_ring_t tx_ring_p)
{
hpi_handle_t handle;
hpi_status_t rs = HPI_SUCCESS;
p_tx_mbox_t tx_mbox_p;
hxge_status_t status = HXGE_OK;
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "==> hxge_txdma_fatal_err_recover"));
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"Recovering from TxDMAChannel#%d error...", channel));
/*
* Stop the dma channel waits for the stop done. If the stop done bit
* is not set, then create an error.
*/
handle = HXGE_DEV_HPI_HANDLE(hxgep);
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "stopping txdma channel(%d)",
channel));
MUTEX_ENTER(&tx_ring_p->lock);
rs = hpi_txdma_channel_control(handle, TXDMA_STOP, channel);
if (rs != HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_fatal_err_recover (channel %d): "
"stop failed ", channel));
goto fail;
}
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "reclaiming txdma channel(%d)",
channel));
(void) hxge_txdma_reclaim(hxgep, tx_ring_p, 0);
/*
* Reset TXDMA channel
*/
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "resetting txdma channel(%d)",
channel));
if ((rs = hpi_txdma_channel_control(handle, TXDMA_RESET, channel)) !=
HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_fatal_err_recover (channel %d)"
" reset channel failed 0x%x", channel, rs));
goto fail;
}
/*
* Reset the tail (kick) register to 0. (Hardware will not reset it. Tx
* overflow fatal error if tail is not set to 0 after reset!
*/
TXDMA_REG_WRITE64(handle, TDC_TDR_KICK, channel, 0);
/*
* Restart TXDMA channel
*
* Initialize the TXDMA channel specific FZC control configurations.
* These FZC registers are pertaining to each TX channel (i.e. logical
* pages).
*/
tx_mbox_p = hxge_txdma_get_mbox(hxgep, channel);
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "restarting txdma channel(%d)",
channel));
status = hxge_init_fzc_txdma_channel(hxgep, channel,
tx_ring_p, tx_mbox_p);
if (status != HXGE_OK)
goto fail;
/*
* Initialize the event masks.
*/
tx_ring_p->tx_evmask.value = 0;
status = hxge_init_txdma_channel_event_mask(hxgep, channel,
&tx_ring_p->tx_evmask);
if (status != HXGE_OK)
goto fail;
tx_ring_p->wr_index_wrap = B_FALSE;
tx_ring_p->wr_index = 0;
tx_ring_p->rd_index = 0;
/*
* Load TXDMA descriptors, buffers, mailbox, initialise the DMA
* channels and enable each DMA channel.
*/
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "enabling txdma channel(%d)",
channel));
status = hxge_enable_txdma_channel(hxgep, channel,
tx_ring_p, tx_mbox_p);
MUTEX_EXIT(&tx_ring_p->lock);
if (status != HXGE_OK)
goto fail;
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"Recovery Successful, TxDMAChannel#%d Restored", channel));
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "==> hxge_txdma_fatal_err_recover"));
return (HXGE_OK);
fail:
MUTEX_EXIT(&tx_ring_p->lock);
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL,
"hxge_txdma_fatal_err_recover (channel %d): "
"failed to recover this txdma channel", channel));
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "Recovery failed"));
return (status);
}
static hxge_status_t
hxge_tx_port_fatal_err_recover(p_hxge_t hxgep)
{
hpi_handle_t handle;
hpi_status_t rs = HPI_SUCCESS;
hxge_status_t status = HXGE_OK;
p_tx_ring_t *tx_desc_rings;
p_tx_rings_t tx_rings;
p_tx_ring_t tx_ring_p;
int i, ndmas;
uint16_t channel;
block_reset_t reset_reg;
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL,
"==> hxge_tx_port_fatal_err_recover"));
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"Recovering from TxPort error..."));
handle = HXGE_DEV_HPI_HANDLE(hxgep);
/* Reset TDC block from PEU for this fatal error */
reset_reg.value = 0;
reset_reg.bits.tdc_rst = 1;
HXGE_REG_WR32(handle, BLOCK_RESET, reset_reg.value);
HXGE_DELAY(1000);
/*
* Stop the dma channel waits for the stop done. If the stop done bit
* is not set, then create an error.
*/
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "stopping all DMA channels..."));
tx_rings = hxgep->tx_rings;
tx_desc_rings = tx_rings->rings;
ndmas = tx_rings->ndmas;
for (i = 0; i < ndmas; i++) {
if (tx_desc_rings[i] == NULL) {
continue;
}
tx_ring_p = tx_rings->rings[i];
MUTEX_ENTER(&tx_ring_p->lock);
}
for (i = 0; i < ndmas; i++) {
if (tx_desc_rings[i] == NULL) {
continue;
}
channel = tx_desc_rings[i]->tdc;
tx_ring_p = tx_rings->rings[i];
rs = hpi_txdma_channel_control(handle, TXDMA_STOP, channel);
if (rs != HPI_SUCCESS) {
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"==> hxge_txdma_fatal_err_recover (channel %d): "
"stop failed ", channel));
goto fail;
}
}
/*
* Do reclaim on all of th DMAs.
*/
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL, "reclaiming all DMA channels..."));
for (i = 0; i < ndmas; i++) {
if (tx_desc_rings[i] == NULL) {
continue;
}
tx_ring_p = tx_rings->rings[i];
(void) hxge_txdma_reclaim(hxgep, tx_ring_p, 0);
}
/* Restart the TDC */
if ((status = hxge_txdma_hw_start(hxgep)) != HXGE_OK)
goto fail;
for (i = 0; i < ndmas; i++) {
if (tx_desc_rings[i] == NULL) {
continue;
}
tx_ring_p = tx_rings->rings[i];
MUTEX_EXIT(&tx_ring_p->lock);
}
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL,
"Recovery Successful, TxPort Restored"));
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL,
"<== hxge_tx_port_fatal_err_recover"));
return (HXGE_OK);
fail:
for (i = 0; i < ndmas; i++) {
if (tx_desc_rings[i] == NULL) {
continue;
}
tx_ring_p = tx_rings->rings[i];
MUTEX_EXIT(&tx_ring_p->lock);
}
HXGE_ERROR_MSG((hxgep, HXGE_ERR_CTL, "Recovery failed"));
HXGE_DEBUG_MSG((hxgep, TX_ERR_CTL,
"hxge_txdma_fatal_err_recover (channel %d): "
"failed to recover this txdma channel"));
return (status);
}