xref: /onnv-gate/usr/src/uts/common/io/nxge/npi/npi_txdma.c (revision 6929:a596171cbf16)
13859Sml29623 /*
23859Sml29623  * CDDL HEADER START
33859Sml29623  *
43859Sml29623  * The contents of this file are subject to the terms of the
53859Sml29623  * Common Development and Distribution License (the "License").
63859Sml29623  * You may not use this file except in compliance with the License.
73859Sml29623  *
83859Sml29623  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93859Sml29623  * or http://www.opensolaris.org/os/licensing.
103859Sml29623  * See the License for the specific language governing permissions
113859Sml29623  * and limitations under the License.
123859Sml29623  *
133859Sml29623  * When distributing Covered Code, include this CDDL HEADER in each
143859Sml29623  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153859Sml29623  * If applicable, add the following below this CDDL HEADER, with the
163859Sml29623  * fields enclosed by brackets "[]" replaced with your own identifying
173859Sml29623  * information: Portions Copyright [yyyy] [name of copyright owner]
183859Sml29623  *
193859Sml29623  * CDDL HEADER END
203859Sml29623  */
213859Sml29623 /*
226495Sspeer  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233859Sml29623  * Use is subject to license terms.
243859Sml29623  */
253859Sml29623 
263859Sml29623 #pragma ident	"%Z%%M%	%I%	%E% SMI"
273859Sml29623 
283859Sml29623 #include <npi_txdma.h>
296495Sspeer #include <npi_tx_rd64.h>
306495Sspeer #include <npi_tx_wr64.h>
313859Sml29623 
323859Sml29623 #define	TXDMA_WAIT_LOOP		10000
333859Sml29623 #define	TXDMA_WAIT_MSEC		5
343859Sml29623 
353859Sml29623 static npi_status_t npi_txdma_control_reset_wait(npi_handle_t handle,
363859Sml29623 	uint8_t channel);
373859Sml29623 static npi_status_t npi_txdma_control_stop_wait(npi_handle_t handle,
383859Sml29623 	uint8_t channel);
393859Sml29623 static npi_status_t npi_txdma_control_resume_wait(npi_handle_t handle,
403859Sml29623 	uint8_t channel);
413859Sml29623 
423859Sml29623 uint64_t tdc_dmc_offset[] = {
433859Sml29623 	TX_RNG_CFIG_REG,
443859Sml29623 	TX_RING_HDL_REG,
453859Sml29623 	TX_RING_KICK_REG,
463859Sml29623 	TX_ENT_MSK_REG,
473859Sml29623 	TX_CS_REG,
483859Sml29623 	TXDMA_MBH_REG,
493859Sml29623 	TXDMA_MBL_REG,
503859Sml29623 	TX_DMA_PRE_ST_REG,
513859Sml29623 	TX_RNG_ERR_LOGH_REG,
523859Sml29623 	TX_RNG_ERR_LOGL_REG,
533859Sml29623 	TDMC_INTR_DBG_REG,
543859Sml29623 	TX_CS_DBG_REG
553859Sml29623 };
563859Sml29623 
573859Sml29623 const char *tdc_dmc_name[] = {
583859Sml29623 	"TX_RNG_CFIG_REG",
593859Sml29623 	"TX_RING_HDL_REG",
603859Sml29623 	"TX_RING_KICK_REG",
613859Sml29623 	"TX_ENT_MSK_REG",
623859Sml29623 	"TX_CS_REG",
633859Sml29623 	"TXDMA_MBH_REG",
643859Sml29623 	"TXDMA_MBL_REG",
653859Sml29623 	"TX_DMA_PRE_ST_REG",
663859Sml29623 	"TX_RNG_ERR_LOGH_REG",
673859Sml29623 	"TX_RNG_ERR_LOGL_REG",
683859Sml29623 	"TDMC_INTR_DBG_REG",
693859Sml29623 	"TX_CS_DBG_REG"
703859Sml29623 };
713859Sml29623 
723859Sml29623 uint64_t tdc_fzc_offset [] = {
733859Sml29623 	TX_LOG_PAGE_VLD_REG,
743859Sml29623 	TX_LOG_PAGE_MASK1_REG,
753859Sml29623 	TX_LOG_PAGE_VAL1_REG,
763859Sml29623 	TX_LOG_PAGE_MASK2_REG,
773859Sml29623 	TX_LOG_PAGE_VAL2_REG,
783859Sml29623 	TX_LOG_PAGE_RELO1_REG,
793859Sml29623 	TX_LOG_PAGE_RELO2_REG,
803859Sml29623 	TX_LOG_PAGE_HDL_REG
813859Sml29623 };
823859Sml29623 
833859Sml29623 const char *tdc_fzc_name [] = {
843859Sml29623 	"TX_LOG_PAGE_VLD_REG",
853859Sml29623 	"TX_LOG_PAGE_MASK1_REG",
863859Sml29623 	"TX_LOG_PAGE_VAL1_REG",
873859Sml29623 	"TX_LOG_PAGE_MASK2_REG",
883859Sml29623 	"TX_LOG_PAGE_VAL2_REG",
893859Sml29623 	"TX_LOG_PAGE_RELO1_REG",
903859Sml29623 	"TX_LOG_PAGE_RELO2_REG",
913859Sml29623 	"TX_LOG_PAGE_HDL_REG"
923859Sml29623 };
933859Sml29623 
943859Sml29623 uint64_t tx_fzc_offset[] = {
953859Sml29623 	TX_ADDR_MD_REG,
963859Sml29623 	TDMC_INJ_PAR_ERR_REG,
973859Sml29623 	TDMC_DBG_SEL_REG,
986495Sspeer 	TDMC_TRAINING_REG,
996495Sspeer 	TXC_PORT_DMA_ENABLE_REG,
1006495Sspeer 	TXC_DMA_MAX_BURST_REG
1013859Sml29623 };
1023859Sml29623 
1033859Sml29623 const char *tx_fzc_name[] = {
1043859Sml29623 	"TX_ADDR_MD_REG",
1053859Sml29623 	"TDMC_INJ_PAR_ERR_REG",
1063859Sml29623 	"TDMC_DBG_SEL_REG",
1076495Sspeer 	"TDMC_TRAINING_REG",
1086495Sspeer 	"TXC_PORT_DMA_ENABLE_REG",
1096495Sspeer 	"TXC_DMA_MAX_BURST_REG"
1103859Sml29623 };
1113859Sml29623 
1123859Sml29623 #define	NUM_TDC_DMC_REGS	(sizeof (tdc_dmc_offset) / sizeof (uint64_t))
1133859Sml29623 #define	NUM_TX_FZC_REGS	(sizeof (tx_fzc_offset) / sizeof (uint64_t))
1143859Sml29623 
1153859Sml29623 /*
1163859Sml29623  * npi_txdma_dump_tdc_regs
1173859Sml29623  * Dumps the contents of tdc csrs and fzc registers
1183859Sml29623  *
1193859Sml29623  * Input:
1203859Sml29623  *         tdc:      TX DMA number
1213859Sml29623  *
1223859Sml29623  * return:
1233859Sml29623  *     NPI_SUCCESS
1243859Sml29623  *     NPI_FAILURE
1253859Sml29623  *     NPI_TXDMA_CHANNEL_INVALID
1263859Sml29623  *
1273859Sml29623  */
1283859Sml29623 npi_status_t
npi_txdma_dump_tdc_regs(npi_handle_t handle,uint8_t tdc)1293859Sml29623 npi_txdma_dump_tdc_regs(npi_handle_t handle, uint8_t tdc)
1303859Sml29623 {
1313859Sml29623 
1323859Sml29623 	uint64_t		value, offset;
1333859Sml29623 	int 			num_regs, i;
1343859Sml29623 
1353859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(tdc));
1363859Sml29623 	if (!TXDMA_CHANNEL_VALID(tdc)) {
1373859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
138*6929Smisaki 		    "npi_txdma_dump_tdc_regs"
139*6929Smisaki 		    " Invalid TDC number %d \n",
140*6929Smisaki 		    tdc));
1413859Sml29623 
1423859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(tdc));
1433859Sml29623 	}
1443859Sml29623 
1453859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
146*6929Smisaki 	    "\nTXDMA DMC Register Dump for Channel %d\n",
147*6929Smisaki 	    tdc));
1483859Sml29623 
1493859Sml29623 	num_regs = NUM_TDC_DMC_REGS;
1503859Sml29623 	for (i = 0; i < num_regs; i++) {
1513859Sml29623 		TXDMA_REG_READ64(handle, tdc_dmc_offset[i], tdc, &value);
1523859Sml29623 		offset = NXGE_TXDMA_OFFSET(tdc_dmc_offset[i], handle.is_vraddr,
153*6929Smisaki 		    tdc);
1543859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
155*6929Smisaki 		    "%s\t 0x%016llx \n",
156*6929Smisaki 		    offset, tdc_dmc_name[i],
157*6929Smisaki 		    value));
1583859Sml29623 	}
1593859Sml29623 
1603859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
161*6929Smisaki 	    "\n TXDMA Register Dump for Channel %d done\n", tdc));
1623859Sml29623 
1633859Sml29623 	return (NPI_SUCCESS);
1643859Sml29623 }
1653859Sml29623 
1663859Sml29623 /*
1673859Sml29623  * npi_txdma_dump_fzc_regs
1683859Sml29623  * Dumps the contents of tdc csrs and fzc registers
1693859Sml29623  *
1703859Sml29623  * Input:
1713859Sml29623  *         tdc:      TX DMA number
1723859Sml29623  *
1733859Sml29623  * return:
1743859Sml29623  *     NPI_SUCCESS
1753859Sml29623  *     NPI_FAILURE
1763859Sml29623  *     NPI_TXDMA_CHANNEL_INVALID
1773859Sml29623  *
1783859Sml29623  */
1793859Sml29623 npi_status_t
npi_txdma_dump_fzc_regs(npi_handle_t handle)1803859Sml29623 npi_txdma_dump_fzc_regs(npi_handle_t handle)
1813859Sml29623 {
1823859Sml29623 
1833859Sml29623 	uint64_t value;
1843859Sml29623 	int num_regs, i;
1853859Sml29623 
1863859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
187*6929Smisaki 	    "\nFZC_DMC Common Register Dump\n"));
1883859Sml29623 
1893859Sml29623 	num_regs = NUM_TX_FZC_REGS;
1903859Sml29623 	for (i = 0; i < num_regs; i++) {
1915125Sjoycey #if defined(__i386)
1925125Sjoycey 		NXGE_REG_RD64(handle, (uint32_t)tx_fzc_offset[i], &value);
1935125Sjoycey #else
1943859Sml29623 		NXGE_REG_RD64(handle, tx_fzc_offset[i], &value);
1955125Sjoycey #endif
1963859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
197*6929Smisaki 		    "%s\t 0x%08llx \n",
198*6929Smisaki 		    tx_fzc_offset[i],
199*6929Smisaki 		    tx_fzc_name[i], value));
2003859Sml29623 	}
2013859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
202*6929Smisaki 	    "\n TXDMA FZC_DMC Register Dump Done \n"));
2033859Sml29623 
2043859Sml29623 	return (NPI_SUCCESS);
2053859Sml29623 }
2063859Sml29623 
2073859Sml29623 npi_status_t
npi_txdma_tdc_regs_zero(npi_handle_t handle,uint8_t tdc)2083859Sml29623 npi_txdma_tdc_regs_zero(npi_handle_t handle, uint8_t tdc)
2093859Sml29623 {
2103859Sml29623 	uint64_t		value;
2113859Sml29623 	int 			num_regs, i;
2123859Sml29623 
2133859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(tdc));
2143859Sml29623 	if (!TXDMA_CHANNEL_VALID(tdc)) {
2153859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
216*6929Smisaki 		    "npi_txdma_tdc_regs_zero"
217*6929Smisaki 		    " InvaliInvalid TDC number %d \n",
218*6929Smisaki 		    tdc));
2193859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(tdc));
2203859Sml29623 	}
2213859Sml29623 
2223859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
223*6929Smisaki 	    "\nTXDMA DMC Register (zero) for Channel %d\n",
224*6929Smisaki 	    tdc));
2253859Sml29623 
2263859Sml29623 	num_regs = NUM_TDC_DMC_REGS;
2273859Sml29623 	value = 0;
2283859Sml29623 	for (i = 0; i < num_regs; i++) {
2295125Sjoycey 		TXDMA_REG_WRITE64(handle, tdc_dmc_offset[i], tdc, value);
2303859Sml29623 	}
2313859Sml29623 
2323859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
233*6929Smisaki 	    "\nTXDMA FZC_DMC Register clear for Channel %d\n",
234*6929Smisaki 	    tdc));
2353859Sml29623 
2363859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
237*6929Smisaki 	    "\n TXDMA Register Clear to 0s for Channel %d done\n", tdc));
2383859Sml29623 
2393859Sml29623 	return (NPI_SUCCESS);
2403859Sml29623 }
2413859Sml29623 
2423859Sml29623 /*
2433859Sml29623  * npi_txdma_address_mode32_set():
2443859Sml29623  *	This function is called to only support 32 bit addressing.
2453859Sml29623  *
2463859Sml29623  * Parameters:
2473859Sml29623  *	handle		- NPI handle
2483859Sml29623  *	mode_enable	- B_TRUE  (enable 32 bit mode)
2493859Sml29623  *			  B_FALSE (disable 32 bit mode)
2503859Sml29623  *
2513859Sml29623  * Return:
2523859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
2533859Sml29623  *
2543859Sml29623  *	Error:
2553859Sml29623  *	NONE
2563859Sml29623  */
2573859Sml29623 npi_status_t
npi_txdma_mode32_set(npi_handle_t handle,boolean_t mode_enable)2583859Sml29623 npi_txdma_mode32_set(npi_handle_t handle, boolean_t mode_enable)
2593859Sml29623 {
2603859Sml29623 	tx_addr_md_t		mode32;
2613859Sml29623 
2623859Sml29623 	mode32.value = 0;
2633859Sml29623 	if (mode_enable) {
2643859Sml29623 		mode32.bits.ldw.mode32 = 1;
2653859Sml29623 	} else {
2663859Sml29623 		mode32.bits.ldw.mode32 = 0;
2673859Sml29623 	}
2683859Sml29623 	NXGE_REG_WR64(handle, TX_ADDR_MD_REG, mode32.value);
2693859Sml29623 
2703859Sml29623 	return (NPI_SUCCESS);
2713859Sml29623 }
2723859Sml29623 
2733859Sml29623 /*
2743859Sml29623  * npi_txdma_log_page_set():
2753859Sml29623  *	This function is called to configure a logical page
2763859Sml29623  *	(valid bit, mask, value, relocation).
2773859Sml29623  *
2783859Sml29623  * Parameters:
2793859Sml29623  *	handle		- NPI handle
2803859Sml29623  *	cfgp		- pointer to NPI defined data structure:
2813859Sml29623  *				- page valid
2823859Sml29623  * 				- mask
2833859Sml29623  *				- value
2843859Sml29623  *				- relocation
2853859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
2863859Sml29623  *
2873859Sml29623  * Return:
2883859Sml29623  *	NPI_SUCCESS		- If configurations are set successfully.
2893859Sml29623  *
2903859Sml29623  *	Error:
2913859Sml29623  *	NPI_FAILURE -
2923859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
2933859Sml29623  *		NPI_TXDMA_FUNC_INVALID	-
2943859Sml29623  *		NPI_TXDMA_PAGE_INVALID	-
2953859Sml29623  */
2963859Sml29623 npi_status_t
npi_txdma_log_page_set(npi_handle_t handle,uint8_t channel,p_dma_log_page_t cfgp)2973859Sml29623 npi_txdma_log_page_set(npi_handle_t handle, uint8_t channel,
2983859Sml29623 		p_dma_log_page_t cfgp)
2993859Sml29623 {
3003859Sml29623 	log_page_vld_t		vld;
3013859Sml29623 	int			status;
3023859Sml29623 	uint64_t		val;
3033859Sml29623 	dma_log_page_t		cfg;
3043859Sml29623 
3053859Sml29623 	DMA_LOG_PAGE_FN_VALIDATE(channel, cfgp->page_num, cfgp->func_num,
306*6929Smisaki 	    status);
3073859Sml29623 	if (status) {
3083859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
309*6929Smisaki 		    " npi_txdma_log_page_set"
310*6929Smisaki 		    " npi_status <0x%x>", status));
3113859Sml29623 		return (status);
3123859Sml29623 	}
3133859Sml29623 
3143859Sml29623 	TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VLD_REG, channel, 0);
3153859Sml29623 	TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VLD_REG, channel, &val);
3163859Sml29623 
3173859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
318*6929Smisaki 	    "\n==> npi_txdma_log_page_set: WRITE 0 and "
319*6929Smisaki 	    " READ back 0x%llx\n ", val));
3203859Sml29623 
3213859Sml29623 	vld.value = 0;
3223859Sml29623 	TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VLD_REG, channel, &val);
3233859Sml29623 
3243859Sml29623 	val &= 0x3;
3253859Sml29623 	vld.value |= val;
3263859Sml29623 
3273859Sml29623 	vld.value = 0;
3283859Sml29623 	vld.bits.ldw.func = cfgp->func_num;
3293859Sml29623 
3303859Sml29623 	if (!cfgp->page_num) {
3313859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_MASK1_REG,
332*6929Smisaki 		    channel, (cfgp->mask & DMA_LOG_PAGE_MASK_MASK));
3333859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VAL1_REG,
334*6929Smisaki 		    channel, (cfgp->value & DMA_LOG_PAGE_VALUE_MASK));
3353859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_RELO1_REG,
336*6929Smisaki 		    channel, (cfgp->reloc & DMA_LOG_PAGE_RELO_MASK));
3373859Sml29623 	} else {
3383859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_MASK2_REG,
339*6929Smisaki 		    channel, (cfgp->mask & DMA_LOG_PAGE_MASK_MASK));
3403859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VAL2_REG,
341*6929Smisaki 		    channel, (cfgp->value & DMA_LOG_PAGE_VALUE_MASK));
3423859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_RELO2_REG,
343*6929Smisaki 		    channel, (cfgp->reloc & DMA_LOG_PAGE_RELO_MASK));
3443859Sml29623 	}
3453859Sml29623 
3463859Sml29623 	TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VLD_REG, channel,
347*6929Smisaki 	    vld.value | (cfgp->valid << cfgp->page_num));
3483859Sml29623 
3493859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_REG_CTL,
350*6929Smisaki 	    "\n==> npi_txdma_log_page_set: vld value "
351*6929Smisaki 	    " 0x%llx function %d page_valid01 0x%x\n",
352*6929Smisaki 	    vld.value,
353*6929Smisaki 	    vld.bits.ldw.func,
354*6929Smisaki 	    (cfgp->valid << cfgp->page_num)));
3553859Sml29623 
3563859Sml29623 
3573859Sml29623 	cfg.page_num = 0;
3583859Sml29623 	cfg.func_num = 0;
3593859Sml29623 	(void) npi_txdma_log_page_get(handle, channel, &cfg);
3603859Sml29623 	cfg.page_num = 1;
3613859Sml29623 	(void) npi_txdma_log_page_get(handle, channel, &cfg);
3623859Sml29623 
3633859Sml29623 	return (status);
3643859Sml29623 }
3653859Sml29623 
3663859Sml29623 /*
3673859Sml29623  * npi_txdma_log_page_get():
3683859Sml29623  *	This function is called to get a logical page
3693859Sml29623  *	(valid bit, mask, value, relocation).
3703859Sml29623  *
3713859Sml29623  * Parameters:
3723859Sml29623  *	handle		- NPI handle
3733859Sml29623  *	cfgp		- Get the following values (NPI defined structure):
3743859Sml29623  *				- page valid
3753859Sml29623  * 				- mask
3763859Sml29623  *				- value
3773859Sml29623  *				- relocation
3783859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
3793859Sml29623  *
3803859Sml29623  * Return:
3813859Sml29623  *	NPI_SUCCESS		- If configurations are read successfully.
3823859Sml29623  *
3833859Sml29623  *	Error:
3843859Sml29623  *	NPI_FAILURE -
3853859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
3863859Sml29623  *		NPI_TXDMA_FUNC_INVALID	-
3873859Sml29623  *		NPI_TXDMA_PAGE_INVALID	-
3883859Sml29623  */
3893859Sml29623 npi_status_t
npi_txdma_log_page_get(npi_handle_t handle,uint8_t channel,p_dma_log_page_t cfgp)3903859Sml29623 npi_txdma_log_page_get(npi_handle_t handle, uint8_t channel,
3913859Sml29623 		p_dma_log_page_t cfgp)
3923859Sml29623 {
3933859Sml29623 	log_page_vld_t		vld;
3943859Sml29623 	int			status;
3953859Sml29623 	uint64_t		val;
3963859Sml29623 
3973859Sml29623 	DMA_LOG_PAGE_VALIDATE(channel, cfgp->page_num, status);
3983859Sml29623 	if (status) {
3993859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_REG_CTL,
400*6929Smisaki 		    " npi_txdma_log_page_get"
401*6929Smisaki 		    " npi_status <0x%x>", status));
4023859Sml29623 		return (status);
4033859Sml29623 	}
4043859Sml29623 
4053859Sml29623 	vld.value = 0;
4063859Sml29623 	vld.bits.ldw.func = cfgp->func_num;
4073859Sml29623 	TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VLD_REG, channel, &val);
4083859Sml29623 
4093859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
410*6929Smisaki 	    "\n==> npi_txdma_log_page_get: read value "
411*6929Smisaki 	    " function %d  value 0x%llx\n",
412*6929Smisaki 	    cfgp->func_num, val));
4133859Sml29623 
4143859Sml29623 	vld.value |= val;
4153859Sml29623 	cfgp->func_num = vld.bits.ldw.func;
4163859Sml29623 
4173859Sml29623 	if (!cfgp->page_num) {
4183859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_MASK1_REG, channel, &val);
4193859Sml29623 		cfgp->mask = val & DMA_LOG_PAGE_MASK_MASK;
4203859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VAL1_REG, channel, &val);
4213859Sml29623 		cfgp->value = val & DMA_LOG_PAGE_VALUE_MASK;
4223859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_RELO1_REG, channel, &val);
4233859Sml29623 		cfgp->reloc = val & DMA_LOG_PAGE_RELO_MASK;
4243859Sml29623 		cfgp->valid = vld.bits.ldw.page0;
4253859Sml29623 	} else {
4263859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_MASK2_REG, channel, &val);
4273859Sml29623 		cfgp->mask = val & DMA_LOG_PAGE_MASK_MASK;
4283859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VAL2_REG, channel, &val);
4293859Sml29623 		cfgp->value = val & DMA_LOG_PAGE_VALUE_MASK;
4303859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_RELO2_REG, channel, &val);
4313859Sml29623 		cfgp->reloc = val & DMA_LOG_PAGE_RELO_MASK;
4323859Sml29623 		cfgp->valid = vld.bits.ldw.page1;
4333859Sml29623 	}
4343859Sml29623 
4353859Sml29623 	return (status);
4363859Sml29623 }
4373859Sml29623 
4383859Sml29623 /*
4393859Sml29623  * npi_txdma_log_page_handle_set():
4403859Sml29623  *	This function is called to program a page handle
4413859Sml29623  *	(bits [63:44] of a 64-bit address to generate
4423859Sml29623  *	a 64 bit address)
4433859Sml29623  *
4443859Sml29623  * Parameters:
4453859Sml29623  *	handle		- NPI handle
4463859Sml29623  *	hdl_p		- pointer to a logical page handle
4473859Sml29623  *			  hardware data structure (log_page_hdl_t).
4483859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
4493859Sml29623  *
4503859Sml29623  * Return:
4513859Sml29623  *	NPI_SUCCESS		- If configurations are set successfully.
4523859Sml29623  *
4533859Sml29623  *	Error:
4543859Sml29623  *	NPI_FAILURE -
4553859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
4563859Sml29623  *		NPI_TXDMA_FUNC_INVALID	-
4573859Sml29623  *		NPI_TXDMA_PAGE_INVALID	-
4583859Sml29623  */
4593859Sml29623 npi_status_t
npi_txdma_log_page_handle_set(npi_handle_t handle,uint8_t channel,p_log_page_hdl_t hdl_p)4603859Sml29623 npi_txdma_log_page_handle_set(npi_handle_t handle, uint8_t channel,
4613859Sml29623 		p_log_page_hdl_t hdl_p)
4623859Sml29623 {
4633859Sml29623 	int			status = NPI_SUCCESS;
4643859Sml29623 
4653859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
4663859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
4673859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
468*6929Smisaki 		    " npi_txdma_log_page_handle_set"
469*6929Smisaki 		    " Invalid Input: channel <0x%x>",
470*6929Smisaki 		    channel));
4713859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
4723859Sml29623 	}
4733859Sml29623 
4743859Sml29623 	TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_HDL_REG,
475*6929Smisaki 	    channel, hdl_p->value);
4763859Sml29623 
4773859Sml29623 	return (status);
4783859Sml29623 }
4793859Sml29623 
4803859Sml29623 /*
4813859Sml29623  * npi_txdma_log_page_config():
4823859Sml29623  *	This function is called to IO operations on
4833859Sml29623  *	 a logical page to set, get, clear
4843859Sml29623  *	valid bit, mask, value, relocation).
4853859Sml29623  *
4863859Sml29623  * Parameters:
4873859Sml29623  *	handle		- NPI handle
4883859Sml29623  *	op_mode		- OP_GET, OP_SET, OP_CLEAR
4893859Sml29623  *	type		- NPI specific config type
4903859Sml29623  *			   TXDMA_LOG_PAGE_MASK
4913859Sml29623  *			   TXDMA_LOG_PAGE_VALUE
4923859Sml29623  *			   TXDMA_LOG_PAGE_RELOC
4933859Sml29623  *			   TXDMA_LOG_PAGE_VALID
4943859Sml29623  *			   TXDMA_LOG_PAGE_ALL
4953859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
4963859Sml29623  *	cfgp		- pointer to the NPI config structure.
4973859Sml29623  * Return:
4983859Sml29623  *	NPI_SUCCESS		- If configurations are read successfully.
4993859Sml29623  *
5003859Sml29623  *	Error:
5013859Sml29623  *	NPI_FAILURE		-
5023859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
5033859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
5043859Sml29623  *		NPI_TXDMA_FUNC_INVALID	-
5053859Sml29623  *		NPI_TXDMA_PAGE_INVALID	-
5063859Sml29623  */
5073859Sml29623 npi_status_t
npi_txdma_log_page_config(npi_handle_t handle,io_op_t op_mode,txdma_log_cfg_t type,uint8_t channel,p_dma_log_page_t cfgp)5083859Sml29623 npi_txdma_log_page_config(npi_handle_t handle, io_op_t op_mode,
5093859Sml29623 		txdma_log_cfg_t type, uint8_t channel,
5103859Sml29623 		p_dma_log_page_t cfgp)
5113859Sml29623 {
5123859Sml29623 	int			status = NPI_SUCCESS;
5133859Sml29623 	uint64_t		val;
5143859Sml29623 
5153859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
5163859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
5173859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
518*6929Smisaki 		    " npi_txdma_log_page_config"
519*6929Smisaki 		    " Invalid Input: channel <0x%x>",
520*6929Smisaki 		    channel));
5213859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
5223859Sml29623 	}
5233859Sml29623 
5243859Sml29623 	switch (op_mode) {
5253859Sml29623 	case OP_GET:
5263859Sml29623 		switch (type) {
5273859Sml29623 		case TXDMA_LOG_PAGE_ALL:
5283859Sml29623 			return (npi_txdma_log_page_get(handle, channel,
529*6929Smisaki 			    cfgp));
5303859Sml29623 		case TXDMA_LOG_PAGE_MASK:
5313859Sml29623 			if (!cfgp->page_num) {
5323859Sml29623 				TX_LOG_REG_READ64(handle, TX_LOG_PAGE_MASK1_REG,
533*6929Smisaki 				    channel, &val);
5343859Sml29623 				cfgp->mask = val & DMA_LOG_PAGE_MASK_MASK;
5353859Sml29623 			} else {
5363859Sml29623 				TX_LOG_REG_READ64(handle, TX_LOG_PAGE_MASK2_REG,
537*6929Smisaki 				    channel, &val);
5383859Sml29623 				cfgp->mask = val & DMA_LOG_PAGE_MASK_MASK;
5393859Sml29623 			}
5403859Sml29623 			break;
5413859Sml29623 
5423859Sml29623 		case TXDMA_LOG_PAGE_VALUE:
5433859Sml29623 			if (!cfgp->page_num) {
5443859Sml29623 				TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VAL1_REG,
545*6929Smisaki 				    channel, &val);
5463859Sml29623 				cfgp->value = val & DMA_LOG_PAGE_VALUE_MASK;
5473859Sml29623 			} else {
5483859Sml29623 				TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VAL2_REG,
549*6929Smisaki 				    channel, &val);
5503859Sml29623 				cfgp->value = val & DMA_LOG_PAGE_VALUE_MASK;
5513859Sml29623 			}
5523859Sml29623 			break;
5533859Sml29623 
5543859Sml29623 		case TXDMA_LOG_PAGE_RELOC:
5553859Sml29623 			if (!cfgp->page_num) {
5563859Sml29623 				TX_LOG_REG_READ64(handle, TX_LOG_PAGE_RELO1_REG,
557*6929Smisaki 				    channel, &val);
5583859Sml29623 				cfgp->reloc = val & DMA_LOG_PAGE_RELO_MASK;
5593859Sml29623 			} else {
5603859Sml29623 				TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VAL2_REG,
561*6929Smisaki 				    channel, &val);
5623859Sml29623 				cfgp->reloc = val & DMA_LOG_PAGE_RELO_MASK;
5633859Sml29623 			}
5643859Sml29623 			break;
5653859Sml29623 
5663859Sml29623 		default:
5673859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
568*6929Smisaki 			    " npi_txdma_log_page_config"
569*6929Smisaki 			    " Invalid Input: pageconfig <0x%x>",
570*6929Smisaki 			    type));
5713859Sml29623 			return (NPI_FAILURE |
572*6929Smisaki 			    NPI_TXDMA_OPCODE_INVALID(channel));
5733859Sml29623 		}
5743859Sml29623 
5753859Sml29623 		break;
5763859Sml29623 
5773859Sml29623 	case OP_SET:
5783859Sml29623 	case OP_CLEAR:
5793859Sml29623 		if (op_mode == OP_CLEAR) {
5803859Sml29623 			cfgp->valid = 0;
5813859Sml29623 			cfgp->mask = cfgp->func_num = 0;
5823859Sml29623 			cfgp->value = cfgp->reloc = 0;
5833859Sml29623 		}
5843859Sml29623 		switch (type) {
5853859Sml29623 		case TXDMA_LOG_PAGE_ALL:
5863859Sml29623 			return (npi_txdma_log_page_set(handle, channel,
587*6929Smisaki 			    cfgp));
5883859Sml29623 		case TXDMA_LOG_PAGE_MASK:
5893859Sml29623 			if (!cfgp->page_num) {
5903859Sml29623 				TX_LOG_REG_WRITE64(handle,
591*6929Smisaki 				    TX_LOG_PAGE_MASK1_REG, channel,
592*6929Smisaki 				    (cfgp->mask & DMA_LOG_PAGE_MASK_MASK));
5933859Sml29623 			} else {
5943859Sml29623 				TX_LOG_REG_WRITE64(handle,
595*6929Smisaki 				    TX_LOG_PAGE_MASK2_REG, channel,
596*6929Smisaki 				    (cfgp->mask & DMA_LOG_PAGE_MASK_MASK));
5973859Sml29623 			}
5983859Sml29623 			break;
5993859Sml29623 
6003859Sml29623 		case TXDMA_LOG_PAGE_VALUE:
6013859Sml29623 			if (!cfgp->page_num) {
6023859Sml29623 				TX_LOG_REG_WRITE64(handle,
603*6929Smisaki 				    TX_LOG_PAGE_VAL1_REG, channel,
604*6929Smisaki 				    (cfgp->value & DMA_LOG_PAGE_VALUE_MASK));
6053859Sml29623 			} else {
6063859Sml29623 				TX_LOG_REG_WRITE64(handle,
607*6929Smisaki 				    TX_LOG_PAGE_VAL2_REG, channel,
608*6929Smisaki 				    (cfgp->value & DMA_LOG_PAGE_VALUE_MASK));
6093859Sml29623 			}
6103859Sml29623 			break;
6113859Sml29623 
6123859Sml29623 		case TXDMA_LOG_PAGE_RELOC:
6133859Sml29623 			if (!cfgp->page_num) {
6143859Sml29623 				TX_LOG_REG_WRITE64(handle,
615*6929Smisaki 				    TX_LOG_PAGE_RELO1_REG, channel,
616*6929Smisaki 				    (cfgp->reloc & DMA_LOG_PAGE_RELO_MASK));
6173859Sml29623 			} else {
6183859Sml29623 				TX_LOG_REG_WRITE64(handle,
619*6929Smisaki 				    TX_LOG_PAGE_RELO2_REG, channel,
620*6929Smisaki 				    (cfgp->reloc & DMA_LOG_PAGE_RELO_MASK));
6213859Sml29623 			}
6223859Sml29623 			break;
6233859Sml29623 
6243859Sml29623 		default:
6253859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
626*6929Smisaki 			    " npi_txdma_log_page_config"
627*6929Smisaki 			    " Invalid Input: pageconfig <0x%x>",
628*6929Smisaki 			    type));
6293859Sml29623 			return (NPI_FAILURE |
630*6929Smisaki 			    NPI_TXDMA_OPCODE_INVALID(channel));
6313859Sml29623 		}
6323859Sml29623 
6333859Sml29623 		break;
6343859Sml29623 	default:
6353859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
636*6929Smisaki 		    " npi_txdma_log_page_config"
637*6929Smisaki 		    " Invalid Input: op <0x%x>",
638*6929Smisaki 		    op_mode));
6393859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
6403859Sml29623 	}
6413859Sml29623 
6423859Sml29623 	return (status);
6433859Sml29623 }
6443859Sml29623 
6453859Sml29623 /*
6463859Sml29623  * npi_txdma_log_page_vld_config():
6473859Sml29623  *	This function is called to configure the logical
6483859Sml29623  *	page valid register.
6493859Sml29623  *
6503859Sml29623  * Parameters:
6513859Sml29623  *	handle		- NPI handle
6523859Sml29623  *	op_mode		- OP_GET: get valid page configuration
6533859Sml29623  *			  OP_SET: set valid page configuration
6543859Sml29623  *			  OP_UPDATE: update valid page configuration
6553859Sml29623  *			  OP_CLEAR: reset both valid pages to
6563859Sml29623  *			  not defined (0).
6573859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
6583859Sml29623  *	vld_p		- pointer to hardware defined log page valid register.
6593859Sml29623  * Return:
6603859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
6613859Sml29623  *
6623859Sml29623  *	Error:
6633859Sml29623  *	NPI_FAILURE -
6643859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
6653859Sml29623  *		NPI_TXDMA_OPCODE_INVALID -
6663859Sml29623  */
6673859Sml29623 npi_status_t
npi_txdma_log_page_vld_config(npi_handle_t handle,io_op_t op_mode,uint8_t channel,p_log_page_vld_t vld_p)6683859Sml29623 npi_txdma_log_page_vld_config(npi_handle_t handle, io_op_t op_mode,
6693859Sml29623 		uint8_t channel, p_log_page_vld_t vld_p)
6703859Sml29623 {
6713859Sml29623 	int			status = NPI_SUCCESS;
6723859Sml29623 	log_page_vld_t		vld;
6733859Sml29623 
6743859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
6753859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
6763859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
677*6929Smisaki 		    " npi_txdma_log_page_vld_config"
678*6929Smisaki 		    " Invalid Input: channel <0x%x>",
679*6929Smisaki 		    channel));
6803859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
6813859Sml29623 	}
6823859Sml29623 
6833859Sml29623 	switch (op_mode) {
6843859Sml29623 	case OP_GET:
6853859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VLD_REG, channel,
686*6929Smisaki 		    &vld_p->value);
6873859Sml29623 		break;
6883859Sml29623 
6893859Sml29623 	case OP_SET:
6903859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VLD_REG,
691*6929Smisaki 		    channel, vld_p->value);
6923859Sml29623 		break;
6933859Sml29623 
6943859Sml29623 	case OP_UPDATE:
6953859Sml29623 		TX_LOG_REG_READ64(handle, TX_LOG_PAGE_VLD_REG, channel,
696*6929Smisaki 		    &vld.value);
6973859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VLD_REG,
698*6929Smisaki 		    channel, vld.value | vld_p->value);
6993859Sml29623 		break;
7003859Sml29623 
7013859Sml29623 	case OP_CLEAR:
7023859Sml29623 		TX_LOG_REG_WRITE64(handle, TX_LOG_PAGE_VLD_REG,
703*6929Smisaki 		    channel, 0);
7043859Sml29623 		break;
7053859Sml29623 
7063859Sml29623 	default:
7073859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
708*6929Smisaki 		    " npi_txdma_log_pag_vld_cofig"
709*6929Smisaki 		    " Invalid Input: pagevld <0x%x>",
710*6929Smisaki 		    op_mode));
7113859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
7123859Sml29623 	}
7133859Sml29623 
7143859Sml29623 	return (status);
7153859Sml29623 }
7163859Sml29623 
7173859Sml29623 /*
7183859Sml29623  * npi_txdma_channel_reset():
7193859Sml29623  *	This function is called to reset a transmit DMA channel.
7203859Sml29623  *	(This function is used to reset a channel and reinitialize
7213859Sml29623  *	 all other bits except RST_STATE).
7223859Sml29623  *
7233859Sml29623  * Parameters:
7243859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
7253859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
7263859Sml29623  *			  (If virtualization flag is not set, then
7273859Sml29623  *			   logical channel is the same as the hardware
7283859Sml29623  *			   channel number).
7293859Sml29623  *
7303859Sml29623  * Return:
7313859Sml29623  *	NPI_SUCCESS		- If reset is complete successfully.
7323859Sml29623  *
7333859Sml29623  *	Error:
7343859Sml29623  *	NPI_FAILURE	-
7353859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
7363859Sml29623  *		NPI_TXDMA_RESET_FAILED -
7373859Sml29623  */
7383859Sml29623 npi_status_t
npi_txdma_channel_reset(npi_handle_t handle,uint8_t channel)7393859Sml29623 npi_txdma_channel_reset(npi_handle_t handle, uint8_t channel)
7403859Sml29623 {
7413859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
742*6929Smisaki 	    " npi_txdma_channel_reset"
743*6929Smisaki 	    " RESETTING",
744*6929Smisaki 	    channel));
7453859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_RESET, channel));
7463859Sml29623 }
7473859Sml29623 
7483859Sml29623 /*
7493859Sml29623  * npi_txdma_channel_init_enable():
7503859Sml29623  *	This function is called to start a transmit DMA channel after reset.
7513859Sml29623  *
7523859Sml29623  * Parameters:
7533859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
7543859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
7553859Sml29623  *			  (If virtualization flag is not set, then
7563859Sml29623  *			   logical channel is the same as the hardware
7573859Sml29623  *			   channel number).
7583859Sml29623  * Return:
7593859Sml29623  *	NPI_SUCCESS		- If DMA channel is started successfully.
7603859Sml29623  *
7613859Sml29623  *	Error:
7623859Sml29623  *	NPI_FAILURE	-
7633859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
7643859Sml29623  */
7653859Sml29623 npi_status_t
npi_txdma_channel_init_enable(npi_handle_t handle,uint8_t channel)7663859Sml29623 npi_txdma_channel_init_enable(npi_handle_t handle, uint8_t channel)
7673859Sml29623 {
7683859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_INIT_START, channel));
7693859Sml29623 }
7703859Sml29623 
7713859Sml29623 /*
7723859Sml29623  * npi_txdma_channel_enable():
7733859Sml29623  *	This function is called to start a transmit DMA channel.
7743859Sml29623  *
7753859Sml29623  * Parameters:
7763859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
7773859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
7783859Sml29623  *			  (If virtualization flag is not set, then
7793859Sml29623  *			   logical channel is the same as the hardware
7803859Sml29623  *			   channel number).
7813859Sml29623  * Return:
7823859Sml29623  *	NPI_SUCCESS		- If DMA channel is stopped successfully.
7833859Sml29623  *
7843859Sml29623  *	Error:
7853859Sml29623  *	NPI_FAILURE	-
7863859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
7873859Sml29623  */
7883859Sml29623 
7893859Sml29623 npi_status_t
npi_txdma_channel_enable(npi_handle_t handle,uint8_t channel)7903859Sml29623 npi_txdma_channel_enable(npi_handle_t handle, uint8_t channel)
7913859Sml29623 {
7923859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_START, channel));
7933859Sml29623 }
7943859Sml29623 
7953859Sml29623 /*
7963859Sml29623  * npi_txdma_channel_disable():
7973859Sml29623  *	This function is called to stop a transmit DMA channel.
7983859Sml29623  *
7993859Sml29623  * Parameters:
8003859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
8013859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
8023859Sml29623  *			  (If virtualization flag is not set, then
8033859Sml29623  *			   logical channel is the same as the hardware
8043859Sml29623  *			   channel number).
8053859Sml29623  * Return:
8063859Sml29623  *	NPI_SUCCESS		- If DMA channel is stopped successfully.
8073859Sml29623  *
8083859Sml29623  *	Error:
8093859Sml29623  *	NPI_FAILURE	-
8103859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
8113859Sml29623  *		NPI_TXDMA_STOP_FAILED -
8123859Sml29623  */
8133859Sml29623 npi_status_t
npi_txdma_channel_disable(npi_handle_t handle,uint8_t channel)8143859Sml29623 npi_txdma_channel_disable(npi_handle_t handle, uint8_t channel)
8153859Sml29623 {
8163859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_STOP, channel));
8173859Sml29623 }
8183859Sml29623 
8193859Sml29623 /*
8203859Sml29623  * npi_txdma_channel_resume():
8213859Sml29623  *	This function is called to restart a transmit DMA channel.
8223859Sml29623  *
8233859Sml29623  * Parameters:
8243859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
8253859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
8263859Sml29623  *			  (If virtualization flag is not set, then
8273859Sml29623  *			   logical channel is the same as the hardware
8283859Sml29623  *			   channel number).
8293859Sml29623  * Return:
8303859Sml29623  *	NPI_SUCCESS		- If DMA channel is stopped successfully.
8313859Sml29623  *
8323859Sml29623  *	Error:
8333859Sml29623  *	NPI_FAILURE	-
8343859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
8353859Sml29623  *		NPI_TXDMA_RESUME_FAILED -
8363859Sml29623  */
8373859Sml29623 npi_status_t
npi_txdma_channel_resume(npi_handle_t handle,uint8_t channel)8383859Sml29623 npi_txdma_channel_resume(npi_handle_t handle, uint8_t channel)
8393859Sml29623 {
8403859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_RESUME, channel));
8413859Sml29623 }
8423859Sml29623 
8433859Sml29623 /*
8443859Sml29623  * npi_txdma_channel_mmk_clear():
8453859Sml29623  *	This function is called to clear MMK bit.
8463859Sml29623  *
8473859Sml29623  * Parameters:
8483859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
8493859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
8503859Sml29623  *			  (If virtualization flag is not set, then
8513859Sml29623  *			   logical channel is the same as the hardware
8523859Sml29623  *			   channel number).
8533859Sml29623  * Return:
8543859Sml29623  *	NPI_SUCCESS		- If MMK is reset successfully.
8553859Sml29623  *
8563859Sml29623  *	Error:
8573859Sml29623  *	NPI_FAILURE	-
8583859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
8593859Sml29623  */
8603859Sml29623 npi_status_t
npi_txdma_channel_mmk_clear(npi_handle_t handle,uint8_t channel)8613859Sml29623 npi_txdma_channel_mmk_clear(npi_handle_t handle, uint8_t channel)
8623859Sml29623 {
8633859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_CLEAR_MMK, channel));
8643859Sml29623 }
8653859Sml29623 
8663859Sml29623 /*
8673859Sml29623  * npi_txdma_channel_mbox_enable():
8683859Sml29623  *	This function is called to enable the mailbox update.
8693859Sml29623  *
8703859Sml29623  * Parameters:
8713859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
8723859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
8733859Sml29623  *			  (If virtualization flag is not set, then
8743859Sml29623  *			   logical channel is the same as the hardware
8753859Sml29623  *			   channel number).
8763859Sml29623  * Return:
8773859Sml29623  *	NPI_SUCCESS		- If mailbox is enabled successfully.
8783859Sml29623  *
8793859Sml29623  *	Error:
8803859Sml29623  *	NPI_HW_ERROR		-
8813859Sml29623  *	NPI_FAILURE	-
8823859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID -
8833859Sml29623  */
8843859Sml29623 npi_status_t
npi_txdma_channel_mbox_enable(npi_handle_t handle,uint8_t channel)8853859Sml29623 npi_txdma_channel_mbox_enable(npi_handle_t handle, uint8_t channel)
8863859Sml29623 {
8873859Sml29623 	return (npi_txdma_channel_control(handle, TXDMA_MBOX_ENABLE, channel));
8883859Sml29623 }
8893859Sml29623 
8903859Sml29623 /*
8913859Sml29623  * npi_txdma_channel_control():
8923859Sml29623  *	This function is called to control a transmit DMA channel
8933859Sml29623  *	for reset, start or stop.
8943859Sml29623  *
8953859Sml29623  * Parameters:
8963859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
8973859Sml29623  *	control		- NPI defined control type supported
8983859Sml29623  *				- TXDMA_INIT_RESET
8993859Sml29623  * 				- TXDMA_INIT_START
9003859Sml29623  *				- TXDMA_RESET
9013859Sml29623  *				- TXDMA_START
9023859Sml29623  *				- TXDMA_STOP
9033859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
9043859Sml29623  *			  (If virtualization flag is not set, then
9053859Sml29623  *			   logical channel is the same as the hardware
9063859Sml29623  *
9073859Sml29623  * Return:
9083859Sml29623  *	NPI_SUCCESS		- If reset is complete successfully.
9093859Sml29623  *
9103859Sml29623  *	Error:
9113859Sml29623  *	NPI_FAILURE		-
9123859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
9133859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
9143859Sml29623  *		NPI_TXDMA_RESET_FAILED	-
9153859Sml29623  *		NPI_TXDMA_STOP_FAILED	-
9163859Sml29623  *		NPI_TXDMA_RESUME_FAILED	-
9173859Sml29623  */
9183859Sml29623 npi_status_t
npi_txdma_channel_control(npi_handle_t handle,txdma_cs_cntl_t control,uint8_t channel)9193859Sml29623 npi_txdma_channel_control(npi_handle_t handle, txdma_cs_cntl_t control,
9203859Sml29623 		uint8_t channel)
9213859Sml29623 {
9223859Sml29623 	int		status = NPI_SUCCESS;
9233859Sml29623 	tx_cs_t		cs;
9243859Sml29623 
9253859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
9263859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
9273859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
928*6929Smisaki 		    " npi_txdma_channel_control"
929*6929Smisaki 		    " Invalid Input: channel <0x%x>",
930*6929Smisaki 		    channel));
9313859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
9323859Sml29623 	}
9333859Sml29623 
9343859Sml29623 	switch (control) {
9353859Sml29623 	case TXDMA_INIT_RESET:
9363859Sml29623 		cs.value = 0;
9373859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs.value);
9383859Sml29623 		cs.bits.ldw.rst = 1;
9393859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9403859Sml29623 		return (npi_txdma_control_reset_wait(handle, channel));
9413859Sml29623 
9423859Sml29623 	case TXDMA_INIT_START:
9433859Sml29623 		cs.value = 0;
9443859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9453859Sml29623 		break;
9463859Sml29623 
9473859Sml29623 	case TXDMA_RESET:
9483859Sml29623 		/*
9493859Sml29623 		 * Sets reset bit only (Hardware will reset all
9503859Sml29623 		 * the RW bits but leave the RO bits alone.
9513859Sml29623 		 */
9523859Sml29623 		cs.value = 0;
9533859Sml29623 		cs.bits.ldw.rst = 1;
9543859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9553859Sml29623 		return (npi_txdma_control_reset_wait(handle, channel));
9563859Sml29623 
9573859Sml29623 	case TXDMA_START:
9583859Sml29623 		/* Enable the DMA channel */
9593859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs.value);
9603859Sml29623 		cs.bits.ldw.stop_n_go = 0;
9613859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9623859Sml29623 		break;
9633859Sml29623 
9643859Sml29623 	case TXDMA_STOP:
9653859Sml29623 		/* Disable the DMA channel */
9663859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs.value);
9673859Sml29623 		cs.bits.ldw.stop_n_go = 1;
9683859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9693859Sml29623 		status = npi_txdma_control_stop_wait(handle, channel);
9703859Sml29623 		if (status) {
9713859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
972*6929Smisaki 			    "Cannot stop channel %d (TXC hung!)",
973*6929Smisaki 			    channel));
9743859Sml29623 		}
9753859Sml29623 		break;
9763859Sml29623 
9773859Sml29623 	case TXDMA_RESUME:
9783859Sml29623 		/* Resume the packet transmission after stopping */
9793859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs.value);
9803859Sml29623 		cs.value |= ~TX_CS_STOP_N_GO_MASK;
9813859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9823859Sml29623 		return (npi_txdma_control_resume_wait(handle, channel));
9833859Sml29623 
9843859Sml29623 	case TXDMA_CLEAR_MMK:
9853859Sml29623 		/* Write 1 to MK bit to clear the MMK bit */
9863859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs.value);
9873859Sml29623 		cs.bits.ldw.mk = 1;
9883859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9893859Sml29623 		break;
9903859Sml29623 
9913859Sml29623 	case TXDMA_MBOX_ENABLE:
9923859Sml29623 		/*
9933859Sml29623 		 * Write 1 to MB bit to enable mailbox update
9943859Sml29623 		 * (cleared to 0 by hardware after update).
9953859Sml29623 		 */
9963859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs.value);
9973859Sml29623 		cs.bits.ldw.mb = 1;
9983859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs.value);
9993859Sml29623 		break;
10003859Sml29623 
10013859Sml29623 	default:
10023859Sml29623 		status =  (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
10033859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1004*6929Smisaki 		    " npi_txdma_channel_control"
1005*6929Smisaki 		    " Invalid Input: control <0x%x>",
1006*6929Smisaki 		    control));
10073859Sml29623 	}
10083859Sml29623 
10093859Sml29623 	return (status);
10103859Sml29623 }
10113859Sml29623 
10123859Sml29623 /*
10133859Sml29623  * npi_txdma_control_status():
10143859Sml29623  *	This function is called to operate on the control
10153859Sml29623  *	and status register.
10163859Sml29623  *
10173859Sml29623  * Parameters:
10183859Sml29623  *	handle		- NPI handle
10193859Sml29623  *	op_mode		- OP_GET: get hardware control and status
10203859Sml29623  *			  OP_SET: set hardware control and status
10213859Sml29623  *			  OP_UPDATE: update hardware control and status.
10223859Sml29623  *			  OP_CLEAR: clear control and status register to 0s.
10233859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
10243859Sml29623  *	cs_p		- pointer to hardware defined control and status
10253859Sml29623  *			  structure.
10263859Sml29623  * Return:
10273859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
10283859Sml29623  *
10293859Sml29623  *	Error:
10303859Sml29623  *	NPI_FAILURE		-
10313859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
10323859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
10333859Sml29623  *		NPI_TXDMA_FUNC_INVALID	-
10343859Sml29623  */
10353859Sml29623 npi_status_t
npi_txdma_control_status(npi_handle_t handle,io_op_t op_mode,uint8_t channel,p_tx_cs_t cs_p)10363859Sml29623 npi_txdma_control_status(npi_handle_t handle, io_op_t op_mode,
10373859Sml29623 		uint8_t channel, p_tx_cs_t cs_p)
10383859Sml29623 {
10393859Sml29623 	int		status = NPI_SUCCESS;
10403859Sml29623 	tx_cs_t		txcs;
10413859Sml29623 
10423859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
10433859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
10443859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1045*6929Smisaki 		    " npi_txdma_control_status"
1046*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1047*6929Smisaki 		    channel));
10483859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
10493859Sml29623 	}
10503859Sml29623 
10513859Sml29623 	switch (op_mode) {
10523859Sml29623 	case OP_GET:
10533859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &cs_p->value);
10543859Sml29623 		break;
10553859Sml29623 
10563859Sml29623 	case OP_SET:
10573859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel, cs_p->value);
10583859Sml29623 		break;
10593859Sml29623 
10603859Sml29623 	case OP_UPDATE:
10613859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &txcs.value);
10623859Sml29623 		TXDMA_REG_WRITE64(handle, TX_CS_REG, channel,
1063*6929Smisaki 		    cs_p->value | txcs.value);
10643859Sml29623 		break;
10653859Sml29623 
10663859Sml29623 	default:
10673859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1068*6929Smisaki 		    " npi_txdma_control_status"
1069*6929Smisaki 		    " Invalid Input: control <0x%x>",
1070*6929Smisaki 		    op_mode));
10713859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
10723859Sml29623 	}
10733859Sml29623 
10743859Sml29623 	return (status);
10753859Sml29623 
10763859Sml29623 }
10773859Sml29623 
10783859Sml29623 /*
10793859Sml29623  * npi_txdma_event_mask():
10803859Sml29623  *	This function is called to operate on the event mask
10813859Sml29623  *	register which is used for generating interrupts..
10823859Sml29623  *	and status register.
10833859Sml29623  *
10843859Sml29623  * Parameters:
10853859Sml29623  *	handle		- NPI handle
10863859Sml29623  *	op_mode		- OP_GET: get hardware event mask
10873859Sml29623  *			  OP_SET: set hardware interrupt event masks
10883859Sml29623  *			  OP_CLEAR: clear control and status register to 0s.
10893859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
10903859Sml29623  *	mask_p		- pointer to hardware defined event mask
10913859Sml29623  *			  structure.
10923859Sml29623  * Return:
10933859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
10943859Sml29623  *
10953859Sml29623  *	Error:
10963859Sml29623  *	NPI_FAILURE		-
10973859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
10983859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
10993859Sml29623  */
11003859Sml29623 npi_status_t
npi_txdma_event_mask(npi_handle_t handle,io_op_t op_mode,uint8_t channel,p_tx_dma_ent_msk_t mask_p)11013859Sml29623 npi_txdma_event_mask(npi_handle_t handle, io_op_t op_mode,
11023859Sml29623 		uint8_t channel, p_tx_dma_ent_msk_t mask_p)
11033859Sml29623 {
11043859Sml29623 	int			status = NPI_SUCCESS;
11053859Sml29623 	tx_dma_ent_msk_t	mask;
11063859Sml29623 
11073859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
11083859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
11093859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1110*6929Smisaki 		    " npi_txdma_event_mask"
1111*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1112*6929Smisaki 		    channel));
11133859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
11143859Sml29623 	}
11153859Sml29623 
11163859Sml29623 	switch (op_mode) {
11173859Sml29623 	case OP_GET:
11183859Sml29623 		TXDMA_REG_READ64(handle, TX_ENT_MSK_REG, channel,
1119*6929Smisaki 		    &mask_p->value);
11203859Sml29623 		break;
11213859Sml29623 
11223859Sml29623 	case OP_SET:
11233859Sml29623 		TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
1124*6929Smisaki 		    mask_p->value);
11253859Sml29623 		break;
11263859Sml29623 
11273859Sml29623 	case OP_UPDATE:
11283859Sml29623 		TXDMA_REG_READ64(handle, TX_ENT_MSK_REG, channel, &mask.value);
11293859Sml29623 		TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
1130*6929Smisaki 		    mask_p->value | mask.value);
11313859Sml29623 		break;
11323859Sml29623 
11333859Sml29623 	default:
11343859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1135*6929Smisaki 		    " npi_txdma_event_mask"
1136*6929Smisaki 		    " Invalid Input: eventmask <0x%x>",
1137*6929Smisaki 		    op_mode));
11383859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
11393859Sml29623 	}
11403859Sml29623 
11413859Sml29623 	return (status);
11423859Sml29623 }
11433859Sml29623 
11443859Sml29623 /*
11453859Sml29623  * npi_txdma_event_mask_config():
11463859Sml29623  *	This function is called to operate on the event mask
11473859Sml29623  *	register which is used for generating interrupts..
11483859Sml29623  *	and status register.
11493859Sml29623  *
11503859Sml29623  * Parameters:
11513859Sml29623  *	handle		- NPI handle
11523859Sml29623  *	op_mode		- OP_GET: get hardware event mask
11533859Sml29623  *			  OP_SET: set hardware interrupt event masks
11543859Sml29623  *			  OP_CLEAR: clear control and status register to 0s.
11553859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
11563859Sml29623  *	cfgp		- pointer to NPI defined event mask
11573859Sml29623  *			  enum data type.
11583859Sml29623  * Return:
11593859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
11603859Sml29623  *
11613859Sml29623  *	Error:
11623859Sml29623  *	NPI_FAILURE		-
11633859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
11643859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
11653859Sml29623  */
11663859Sml29623 npi_status_t
npi_txdma_event_mask_config(npi_handle_t handle,io_op_t op_mode,uint8_t channel,txdma_ent_msk_cfg_t * mask_cfgp)11673859Sml29623 npi_txdma_event_mask_config(npi_handle_t handle, io_op_t op_mode,
11683859Sml29623 		uint8_t channel, txdma_ent_msk_cfg_t *mask_cfgp)
11693859Sml29623 {
11703859Sml29623 	int		status = NPI_SUCCESS;
11716495Sspeer 	uint64_t	configuration = *mask_cfgp;
11723859Sml29623 	uint64_t	value;
11733859Sml29623 
11743859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
11753859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
11763859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1177*6929Smisaki 		    " npi_txdma_event_mask_config"
1178*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1179*6929Smisaki 		    channel));
11803859Sml29623 
11813859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
11823859Sml29623 	}
11833859Sml29623 
11843859Sml29623 	switch (op_mode) {
11853859Sml29623 	case OP_GET:
11866495Sspeer 		TXDMA_REG_READ64(handle, TX_ENT_MSK_REG, channel,
11876495Sspeer 		    (uint64_t *)mask_cfgp);
11883859Sml29623 		break;
11893859Sml29623 
11903859Sml29623 	case OP_SET:
11913859Sml29623 		TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
11926495Sspeer 		    configuration);
11933859Sml29623 		break;
11943859Sml29623 
11953859Sml29623 	case OP_UPDATE:
11963859Sml29623 		TXDMA_REG_READ64(handle, TX_ENT_MSK_REG, channel, &value);
11973859Sml29623 		TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
11986495Sspeer 		    configuration | value);
11993859Sml29623 		break;
12003859Sml29623 
12013859Sml29623 	case OP_CLEAR:
12023859Sml29623 		TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
1203*6929Smisaki 		    CFG_TXDMA_MASK_ALL);
12043859Sml29623 		break;
12053859Sml29623 	default:
12063859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1207*6929Smisaki 		    " npi_txdma_event_mask_config"
1208*6929Smisaki 		    " Invalid Input: eventmask <0x%x>",
1209*6929Smisaki 		    op_mode));
12103859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
12113859Sml29623 	}
12123859Sml29623 
12133859Sml29623 	return (status);
12143859Sml29623 }
12153859Sml29623 
12163859Sml29623 /*
12173859Sml29623  * npi_txdma_event_mask_mk_out():
12183859Sml29623  *	This function is called to mask out the packet transmit marked event.
12193859Sml29623  *
12203859Sml29623  * Parameters:
12213859Sml29623  *	handle		- NPI handle
12223859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
12233859Sml29623  *			  enum data type.
12243859Sml29623  * Return:
12253859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
12263859Sml29623  *
12273859Sml29623  *	Error:
12283859Sml29623  *	NPI_FAILURE		-
12293859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
12303859Sml29623  */
12313859Sml29623 npi_status_t
npi_txdma_event_mask_mk_out(npi_handle_t handle,uint8_t channel)12323859Sml29623 npi_txdma_event_mask_mk_out(npi_handle_t handle, uint8_t channel)
12333859Sml29623 {
12346495Sspeer 	uint64_t event_mask;
12356495Sspeer 	int	status = NPI_SUCCESS;
12363859Sml29623 
12373859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
12383859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
12393859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1240*6929Smisaki 		    " npi_txdma_event_mask_mk_out"
1241*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1242*6929Smisaki 		    channel));
12433859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
12443859Sml29623 	}
12453859Sml29623 
12463859Sml29623 	TXDMA_REG_READ64(handle, TX_ENT_MSK_REG, channel, &event_mask);
12473859Sml29623 	TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
1248*6929Smisaki 	    event_mask & (~TX_ENT_MSK_MK_MASK));
12493859Sml29623 
12503859Sml29623 	return (status);
12513859Sml29623 }
12523859Sml29623 
12533859Sml29623 /*
12543859Sml29623  * npi_txdma_event_mask_mk_in():
12553859Sml29623  *	This function is called to set the mask for the the packet marked event.
12563859Sml29623  *
12573859Sml29623  * Parameters:
12583859Sml29623  *	handle		- NPI handle
12593859Sml29623  *	channel		- hardware TXDMA channel from 0 to 23.
12603859Sml29623  *			  enum data type.
12613859Sml29623  * Return:
12623859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
12633859Sml29623  *
12643859Sml29623  *	Error:
12653859Sml29623  *	NPI_FAILURE		-
12663859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
12673859Sml29623  */
12683859Sml29623 npi_status_t
npi_txdma_event_mask_mk_in(npi_handle_t handle,uint8_t channel)12693859Sml29623 npi_txdma_event_mask_mk_in(npi_handle_t handle, uint8_t channel)
12703859Sml29623 {
12716495Sspeer 	uint64_t event_mask;
12726495Sspeer 	int	status = NPI_SUCCESS;
12733859Sml29623 
12743859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
12753859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
12763859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1277*6929Smisaki 		    " npi_txdma_event_mask_mk_in"
1278*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1279*6929Smisaki 		    channel));
12803859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
12813859Sml29623 	}
12823859Sml29623 
12833859Sml29623 	TXDMA_REG_READ64(handle, TX_ENT_MSK_REG, channel, &event_mask);
12843859Sml29623 	TXDMA_REG_WRITE64(handle, TX_ENT_MSK_REG, channel,
1285*6929Smisaki 	    event_mask | TX_ENT_MSK_MK_MASK);
12863859Sml29623 
12873859Sml29623 	return (status);
12883859Sml29623 }
12893859Sml29623 
12903859Sml29623 /*
12913859Sml29623  * npi_txdma_ring_addr_set():
12923859Sml29623  *	This function is called to configure the transmit descriptor
12933859Sml29623  *	ring address and its size.
12943859Sml29623  *
12953859Sml29623  * Parameters:
12963859Sml29623  *	handle		- NPI handle (virtualization flag must be defined
12973859Sml29623  *			  if its register pointer is from the virtual region).
12983859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
12993859Sml29623  *			  (If virtualization flag is not set, then
13003859Sml29623  *			   logical channel is the same as the hardware
13013859Sml29623  *			   channel number).
13023859Sml29623  *	start_addr	- starting address of the descriptor
13033859Sml29623  *	len		- maximum length of the descriptor
13043859Sml29623  *			  (in number of 64 bytes block).
13053859Sml29623  * Return:
13063859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
13073859Sml29623  *
13083859Sml29623  *	Error:
13093859Sml29623  *	NPI_FAILURE		-
13103859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
13113859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
13123859Sml29623  */
13133859Sml29623 npi_status_t
npi_txdma_ring_addr_set(npi_handle_t handle,uint8_t channel,uint64_t start_addr,uint32_t len)13143859Sml29623 npi_txdma_ring_addr_set(npi_handle_t handle, uint8_t channel,
13153859Sml29623 		uint64_t start_addr, uint32_t len)
13163859Sml29623 {
13173859Sml29623 	int		status = NPI_SUCCESS;
13183859Sml29623 	tx_rng_cfig_t	cfg;
13193859Sml29623 
13203859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
13213859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
13223859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1323*6929Smisaki 		    " npi_txdma_ring_addr_set"
1324*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1325*6929Smisaki 		    channel));
13263859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
13273859Sml29623 	}
13283859Sml29623 
13293859Sml29623 	cfg.value = ((start_addr & TX_RNG_CFIG_ADDR_MASK) |
1330*6929Smisaki 	    (((uint64_t)len) << TX_RNG_CFIG_LEN_SHIFT));
13313859Sml29623 	TXDMA_REG_WRITE64(handle, TX_RNG_CFIG_REG, channel, cfg.value);
13323859Sml29623 
13333859Sml29623 	return (status);
13343859Sml29623 }
13353859Sml29623 
13363859Sml29623 /*
13373859Sml29623  * npi_txdma_ring_config():
13383859Sml29623  *	This function is called to config a descriptor ring
13393859Sml29623  *	by using the hardware defined data.
13403859Sml29623  *
13413859Sml29623  * Parameters:
13423859Sml29623  *	handle		- NPI handle (virtualization flag must be defined
13433859Sml29623  *			  if its register pointer is from the virtual region).
13443859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
13453859Sml29623  *			  (If virtualization flag is not set, then
13463859Sml29623  *			   logical channel is the same as the hardware
13473859Sml29623  *			   channel number).
13483859Sml29623  *	op_mode		- OP_GET: get transmit ring configuration
13493859Sml29623  *			  OP_SET: set transmit ring configuration
13503859Sml29623  *	reg_data	- pointer to hardware defined transmit ring
13513859Sml29623  *			  configuration data structure.
13523859Sml29623  * Return:
13533859Sml29623  *	NPI_SUCCESS		- If set/get is complete successfully.
13543859Sml29623  *
13553859Sml29623  *	Error:
13563859Sml29623  *	NPI_FAILURE		-
13573859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
13583859Sml29623  */
13593859Sml29623 npi_status_t
npi_txdma_ring_config(npi_handle_t handle,io_op_t op_mode,uint8_t channel,uint64_t * reg_data)13603859Sml29623 npi_txdma_ring_config(npi_handle_t handle, io_op_t op_mode,
13613859Sml29623 		uint8_t channel, uint64_t *reg_data)
13623859Sml29623 {
13633859Sml29623 	int		status = NPI_SUCCESS;
13643859Sml29623 
13653859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
13663859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
13673859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1368*6929Smisaki 		    " npi_txdma_ring_config"
1369*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1370*6929Smisaki 		    channel));
13713859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
13723859Sml29623 	}
13733859Sml29623 
13743859Sml29623 	switch (op_mode) {
13753859Sml29623 	case OP_GET:
13763859Sml29623 		TXDMA_REG_READ64(handle, TX_RNG_CFIG_REG, channel, reg_data);
13773859Sml29623 		break;
13783859Sml29623 
13793859Sml29623 	case OP_SET:
13803859Sml29623 		TXDMA_REG_WRITE64(handle, TX_RNG_CFIG_REG, channel,
1381*6929Smisaki 		    *reg_data);
13823859Sml29623 		break;
13833859Sml29623 
13843859Sml29623 	default:
13853859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1386*6929Smisaki 		    " npi_txdma_ring_config"
1387*6929Smisaki 		    " Invalid Input: ring_config <0x%x>",
1388*6929Smisaki 		    op_mode));
13893859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
13903859Sml29623 	}
13913859Sml29623 
13923859Sml29623 	return (status);
13933859Sml29623 }
13943859Sml29623 
13953859Sml29623 /*
13963859Sml29623  * npi_txdma_mbox_config():
13973859Sml29623  *	This function is called to config the mailbox address
13983859Sml29623  *
13993859Sml29623  * Parameters:
14003859Sml29623  *	handle		- NPI handle (virtualization flag must be defined
14013859Sml29623  *			  if its register pointer is from the virtual region).
14023859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
14033859Sml29623  *			  (If virtualization flag is not set, then
14043859Sml29623  *			   logical channel is the same as the hardware
14053859Sml29623  *			   channel number).
14063859Sml29623  *	op_mode		- OP_GET: get the mailbox address
14073859Sml29623  *			  OP_SET: set the mailbox address
14083859Sml29623  *	reg_data	- pointer to the mailbox address.
14093859Sml29623  * Return:
14103859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
14113859Sml29623  *
14123859Sml29623  *	Error:
14133859Sml29623  *	NPI_FAILURE		-
14143859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
14153859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
14163859Sml29623  */
14173859Sml29623 npi_status_t
npi_txdma_mbox_config(npi_handle_t handle,io_op_t op_mode,uint8_t channel,uint64_t * mbox_addr)14183859Sml29623 npi_txdma_mbox_config(npi_handle_t handle, io_op_t op_mode,
14193859Sml29623 		uint8_t channel, uint64_t *mbox_addr)
14203859Sml29623 {
14213859Sml29623 	int		status = NPI_SUCCESS;
14223859Sml29623 	txdma_mbh_t	mh;
14233859Sml29623 	txdma_mbl_t	ml;
14243859Sml29623 
14253859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
14263859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
14273859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1428*6929Smisaki 		    " npi_txdma_mbox_config"
1429*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1430*6929Smisaki 		    channel));
14313859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
14323859Sml29623 	}
14333859Sml29623 
14343859Sml29623 	mh.value = ml.value = 0;
14353859Sml29623 
14363859Sml29623 	switch (op_mode) {
14373859Sml29623 	case OP_GET:
14383859Sml29623 		TXDMA_REG_READ64(handle, TXDMA_MBH_REG, channel, &mh.value);
14393859Sml29623 		TXDMA_REG_READ64(handle, TXDMA_MBL_REG, channel, &ml.value);
14403859Sml29623 		*mbox_addr = ml.value;
14413859Sml29623 		*mbox_addr |= (mh.value << TXDMA_MBH_ADDR_SHIFT);
14423859Sml29623 
14433859Sml29623 		break;
14443859Sml29623 
14453859Sml29623 	case OP_SET:
14463859Sml29623 		ml.bits.ldw.mbaddr = ((*mbox_addr & TXDMA_MBL_MASK) >>
1447*6929Smisaki 		    TXDMA_MBL_SHIFT);
14483859Sml29623 		TXDMA_REG_WRITE64(handle, TXDMA_MBL_REG, channel, ml.value);
14493859Sml29623 		mh.bits.ldw.mbaddr = ((*mbox_addr >> TXDMA_MBH_ADDR_SHIFT) &
1450*6929Smisaki 		    TXDMA_MBH_MASK);
14513859Sml29623 		TXDMA_REG_WRITE64(handle, TXDMA_MBH_REG, channel, mh.value);
14523859Sml29623 
14533859Sml29623 		break;
14543859Sml29623 
14553859Sml29623 	default:
14563859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1457*6929Smisaki 		    " npi_txdma_mbox_config"
1458*6929Smisaki 		    " Invalid Input: mbox <0x%x>",
1459*6929Smisaki 		    op_mode));
14603859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_OPCODE_INVALID(channel));
14613859Sml29623 	}
14623859Sml29623 
14633859Sml29623 	return (status);
14643859Sml29623 
14653859Sml29623 }
14663859Sml29623 
14673859Sml29623 /*
14683859Sml29623  * npi_txdma_desc_gather_set():
14693859Sml29623  *	This function is called to set up a transmit descriptor entry.
14703859Sml29623  *
14713859Sml29623  * Parameters:
14723859Sml29623  *	handle		- NPI handle (register pointer is the
14733859Sml29623  *			  descriptor address in memory).
14743859Sml29623  *	desc_p		- pointer to a descriptor
14753859Sml29623  *	gather_index	- which entry (starts from index 0 to 15)
14763859Sml29623  *	mark		- mark bit (only valid if it is the first gather).
14773859Sml29623  *	ngathers	- number of gather pointers to set to the first gather.
14783859Sml29623  *	dma_ioaddr	- starting dma address of an IO buffer to write.
14793859Sml29623  *			  (SAD)
14803859Sml29623  *	transfer_len	- transfer len.
14813859Sml29623  * Return:
14823859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
14833859Sml29623  *
14843859Sml29623  *	Error:
14853859Sml29623  *	NPI_FAILURE		-
14863859Sml29623  *		NPI_TXDMA_OPCODE_INVALID	-
14873859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
14883859Sml29623  *		NPI_TXDMA_XFER_LEN_INVALID	-
14893859Sml29623  */
14903859Sml29623 npi_status_t
npi_txdma_desc_gather_set(npi_handle_t handle,p_tx_desc_t desc_p,uint8_t gather_index,boolean_t mark,uint8_t ngathers,uint64_t dma_ioaddr,uint32_t transfer_len)14913859Sml29623 npi_txdma_desc_gather_set(npi_handle_t handle,
14923859Sml29623 		p_tx_desc_t desc_p, uint8_t gather_index,
14933859Sml29623 		boolean_t mark, uint8_t ngathers,
14943859Sml29623 		uint64_t dma_ioaddr, uint32_t transfer_len)
14953859Sml29623 {
14963859Sml29623 	int		status;
14973859Sml29623 
14983859Sml29623 	status = NPI_TXDMA_GATHER_INDEX(gather_index);
14993859Sml29623 	if (status) {
15003859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1501*6929Smisaki 		    " npi_txdma_desc_gather_set"
1502*6929Smisaki 		    " Invalid Input: gather_index <0x%x>",
1503*6929Smisaki 		    gather_index));
15043859Sml29623 		return (status);
15053859Sml29623 	}
15063859Sml29623 
15073859Sml29623 	if (transfer_len > TX_MAX_TRANSFER_LENGTH) {
15083859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1509*6929Smisaki 		    " npi_txdma_desc_gather_set"
1510*6929Smisaki 		    " Invalid Input: tr_len <0x%x>",
1511*6929Smisaki 		    transfer_len));
15123859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_XFER_LEN_INVALID);
15133859Sml29623 	}
15143859Sml29623 
15153859Sml29623 	if (gather_index == 0) {
15163859Sml29623 		desc_p->bits.hdw.sop = 1;
15173859Sml29623 		desc_p->bits.hdw.mark = mark;
15183859Sml29623 		desc_p->bits.hdw.num_ptr = ngathers;
15193859Sml29623 		NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1520*6929Smisaki 		    "npi_txdma_gather_set: SOP len %d (%d)",
1521*6929Smisaki 		    desc_p->bits.hdw.tr_len, transfer_len));
15223859Sml29623 	}
15233859Sml29623 
15243859Sml29623 	desc_p->bits.hdw.tr_len = transfer_len;
15253859Sml29623 	desc_p->bits.hdw.sad = dma_ioaddr >> 32;
15263859Sml29623 	desc_p->bits.ldw.sad = dma_ioaddr & 0xffffffff;
15273859Sml29623 
15283859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1529*6929Smisaki 	    "npi_txdma_gather_set: xfer len %d to set (%d)",
1530*6929Smisaki 	    desc_p->bits.hdw.tr_len, transfer_len));
15313859Sml29623 
15323859Sml29623 	NXGE_MEM_PIO_WRITE64(handle, desc_p->value);
15333859Sml29623 
15343859Sml29623 	return (status);
15353859Sml29623 }
15363859Sml29623 
15373859Sml29623 /*
15383859Sml29623  * npi_txdma_desc_sop_set():
15393859Sml29623  *	This function is called to set up the first gather entry.
15403859Sml29623  *
15413859Sml29623  * Parameters:
15423859Sml29623  *	handle		- NPI handle (register pointer is the
15433859Sml29623  *			  descriptor address in memory).
15443859Sml29623  *	desc_p		- pointer to a descriptor
15453859Sml29623  *	mark		- mark bit (only valid if it is the first gather).
15463859Sml29623  *	ngathers	- number of gather pointers to set to the first gather.
15473859Sml29623  * Return:
15483859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
15493859Sml29623  *
15503859Sml29623  *	Error:
15513859Sml29623  */
15523859Sml29623 npi_status_t
npi_txdma_desc_gather_sop_set(npi_handle_t handle,p_tx_desc_t desc_p,boolean_t mark_mode,uint8_t ngathers)15533859Sml29623 npi_txdma_desc_gather_sop_set(npi_handle_t handle,
15543859Sml29623 		p_tx_desc_t desc_p,
15553859Sml29623 		boolean_t mark_mode,
15563859Sml29623 		uint8_t ngathers)
15573859Sml29623 {
15583859Sml29623 	int		status = NPI_SUCCESS;
15593859Sml29623 
15603859Sml29623 	desc_p->bits.hdw.sop = 1;
15613859Sml29623 	desc_p->bits.hdw.mark = mark_mode;
15623859Sml29623 	desc_p->bits.hdw.num_ptr = ngathers;
15633859Sml29623 
15643859Sml29623 	NXGE_MEM_PIO_WRITE64(handle, desc_p->value);
15653859Sml29623 
15663859Sml29623 	return (status);
15673859Sml29623 }
15683859Sml29623 npi_status_t
npi_txdma_desc_gather_sop_set_1(npi_handle_t handle,p_tx_desc_t desc_p,boolean_t mark_mode,uint8_t ngathers,uint32_t extra)15693859Sml29623 npi_txdma_desc_gather_sop_set_1(npi_handle_t handle,
15703859Sml29623 		p_tx_desc_t desc_p,
15713859Sml29623 		boolean_t mark_mode,
15723859Sml29623 		uint8_t ngathers,
15733859Sml29623 		uint32_t extra)
15743859Sml29623 {
15753859Sml29623 	int		status = NPI_SUCCESS;
15763859Sml29623 
15773859Sml29623 	desc_p->bits.hdw.sop = 1;
15783859Sml29623 	desc_p->bits.hdw.mark = mark_mode;
15793859Sml29623 	desc_p->bits.hdw.num_ptr = ngathers;
15803859Sml29623 	desc_p->bits.hdw.tr_len += extra;
15813859Sml29623 
15823859Sml29623 	NXGE_MEM_PIO_WRITE64(handle, desc_p->value);
15833859Sml29623 
15843859Sml29623 	return (status);
15853859Sml29623 }
15863859Sml29623 
15873859Sml29623 npi_status_t
npi_txdma_desc_set_xfer_len(npi_handle_t handle,p_tx_desc_t desc_p,uint32_t transfer_len)15883859Sml29623 npi_txdma_desc_set_xfer_len(npi_handle_t handle,
15893859Sml29623 		p_tx_desc_t desc_p,
15903859Sml29623 		uint32_t transfer_len)
15913859Sml29623 {
15923859Sml29623 	int		status = NPI_SUCCESS;
15933859Sml29623 
15943859Sml29623 	desc_p->bits.hdw.tr_len = transfer_len;
15953859Sml29623 
15963859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1597*6929Smisaki 	    "npi_set_xfer_len: len %d (%d)",
1598*6929Smisaki 	    desc_p->bits.hdw.tr_len, transfer_len));
15993859Sml29623 
16003859Sml29623 	NXGE_MEM_PIO_WRITE64(handle, desc_p->value);
16013859Sml29623 
16023859Sml29623 	return (status);
16033859Sml29623 }
16043859Sml29623 
16053859Sml29623 npi_status_t
npi_txdma_desc_set_zero(npi_handle_t handle,uint16_t entries)16063859Sml29623 npi_txdma_desc_set_zero(npi_handle_t handle, uint16_t entries)
16073859Sml29623 {
16083859Sml29623 	uint32_t	offset;
16093859Sml29623 	int		i;
16103859Sml29623 
16113859Sml29623 	/*
16123859Sml29623 	 * Assume no wrapped around.
16133859Sml29623 	 */
16143859Sml29623 	offset = 0;
16153859Sml29623 	for (i = 0; i < entries; i++) {
16163859Sml29623 		NXGE_REG_WR64(handle, offset, 0);
16173859Sml29623 		offset += (i * TXDMA_DESC_SIZE);
16183859Sml29623 	}
16193859Sml29623 
16203859Sml29623 	return (NPI_SUCCESS);
16213859Sml29623 }
16223859Sml29623 
16233859Sml29623 npi_status_t
npi_txdma_desc_mem_get(npi_handle_t handle,uint16_t index,p_tx_desc_t desc_p)16243859Sml29623 npi_txdma_desc_mem_get(npi_handle_t handle, uint16_t index,
16253859Sml29623 		p_tx_desc_t desc_p)
16263859Sml29623 {
16273859Sml29623 	int		status = NPI_SUCCESS;
16283859Sml29623 
16293859Sml29623 	npi_txdma_dump_desc_one(handle, desc_p, index);
16303859Sml29623 
16313859Sml29623 	return (status);
16323859Sml29623 
16333859Sml29623 }
16343859Sml29623 
16353859Sml29623 /*
16363859Sml29623  * npi_txdma_desc_kick_reg_set():
16373859Sml29623  *	This function is called to kick the transmit  to start transmission.
16383859Sml29623  *
16393859Sml29623  * Parameters:
16403859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
16413859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
16423859Sml29623  *			  (If virtualization flag is not set, then
16433859Sml29623  *			   logical channel is the same as the hardware
16443859Sml29623  *			   channel number).
16453859Sml29623  *	tail_index	- index into the transmit descriptor
16463859Sml29623  *	wrap		- toggle bit to indicate if the tail index is
16473859Sml29623  *			  wrapped around.
16483859Sml29623  *
16493859Sml29623  * Return:
16503859Sml29623  *	NPI_SUCCESS		- If set is complete successfully.
16513859Sml29623  *
16523859Sml29623  *	Error:
16533859Sml29623  *	NPI_FAILURE		-
16543859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
16553859Sml29623  */
16563859Sml29623 npi_status_t
npi_txdma_desc_kick_reg_set(npi_handle_t handle,uint8_t channel,uint16_t tail_index,boolean_t wrap)16573859Sml29623 npi_txdma_desc_kick_reg_set(npi_handle_t handle, uint8_t channel,
16583859Sml29623 		uint16_t tail_index, boolean_t wrap)
16593859Sml29623 {
16603859Sml29623 	int			status = NPI_SUCCESS;
16613859Sml29623 	tx_ring_kick_t		kick;
16623859Sml29623 
16633859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
16643859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
16653859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1666*6929Smisaki 		    " npi_txdma_desc_kick_reg_set"
1667*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1668*6929Smisaki 		    channel));
16693859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
16703859Sml29623 	}
16713859Sml29623 
16723859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1673*6929Smisaki 	    " npi_txdma_desc_kick_reg_set: "
1674*6929Smisaki 	    " KICKING channel %d",
1675*6929Smisaki 	    channel));
16763859Sml29623 
16773859Sml29623 	/* Toggle the wrap around bit */
16783859Sml29623 	kick.value = 0;
16793859Sml29623 	kick.bits.ldw.wrap = wrap;
16803859Sml29623 	kick.bits.ldw.tail = tail_index;
16813859Sml29623 
16823859Sml29623 	/* Kick start the Transmit kick register */
16833859Sml29623 	TXDMA_REG_WRITE64(handle, TX_RING_KICK_REG, channel, kick.value);
16843859Sml29623 
16853859Sml29623 	return (status);
16863859Sml29623 }
16873859Sml29623 
16883859Sml29623 /*
16893859Sml29623  * npi_txdma_desc_kick_reg_get():
16903859Sml29623  *	This function is called to kick the transmit  to start transmission.
16913859Sml29623  *
16923859Sml29623  * Parameters:
16933859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
16943859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
16953859Sml29623  *			  (If virtualization flag is not set, then
16963859Sml29623  *			   logical channel is the same as the hardware
16973859Sml29623  *			   channel number).
16983859Sml29623  *	tail_index	- index into the transmit descriptor
16993859Sml29623  *	wrap		- toggle bit to indicate if the tail index is
17003859Sml29623  *			  wrapped around.
17013859Sml29623  *
17023859Sml29623  * Return:
17033859Sml29623  *	NPI_SUCCESS		- If get is complete successfully.
17043859Sml29623  *
17053859Sml29623  *	Error:
17063859Sml29623  *	NPI_FAILURE		-
17073859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
17083859Sml29623  */
17093859Sml29623 npi_status_t
npi_txdma_desc_kick_reg_get(npi_handle_t handle,uint8_t channel,p_tx_ring_kick_t kick_p)17103859Sml29623 npi_txdma_desc_kick_reg_get(npi_handle_t handle, uint8_t channel,
17113859Sml29623 		p_tx_ring_kick_t kick_p)
17123859Sml29623 {
17133859Sml29623 	int		status = NPI_SUCCESS;
17143859Sml29623 
17153859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
17163859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
17173859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1718*6929Smisaki 		    " npi_txdma_desc_kick_reg_get"
1719*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1720*6929Smisaki 		    channel));
17213859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
17223859Sml29623 	}
17233859Sml29623 
17243859Sml29623 	TXDMA_REG_READ64(handle, TX_RING_KICK_REG, channel, &kick_p->value);
17253859Sml29623 
17263859Sml29623 	return (status);
17273859Sml29623 }
17283859Sml29623 
17293859Sml29623 /*
17303859Sml29623  * npi_txdma_ring_head_get():
17313859Sml29623  *	This function is called to get the transmit ring head index.
17323859Sml29623  *
17333859Sml29623  * Parameters:
17343859Sml29623  *	handle		- NPI handle (virtualization flag must be defined).
17353859Sml29623  *	channel		- logical TXDMA channel from 0 to 23.
17363859Sml29623  *			  (If virtualization flag is not set, then
17373859Sml29623  *			   logical channel is the same as the hardware
17383859Sml29623  *			   channel number).
17393859Sml29623  *	hdl_p		- pointer to the hardware defined transmit
17403859Sml29623  *			  ring header data (head index and wrap bit).
17413859Sml29623  *
17423859Sml29623  * Return:
17433859Sml29623  *	NPI_SUCCESS		- If get is complete successfully.
17443859Sml29623  *
17453859Sml29623  *	Error:
17463859Sml29623  *	NPI_FAILURE		-
17473859Sml29623  *		NPI_TXDMA_CHANNEL_INVALID	-
17483859Sml29623  */
17493859Sml29623 npi_status_t
npi_txdma_ring_head_get(npi_handle_t handle,uint8_t channel,p_tx_ring_hdl_t hdl_p)17503859Sml29623 npi_txdma_ring_head_get(npi_handle_t handle, uint8_t channel,
17513859Sml29623 		p_tx_ring_hdl_t hdl_p)
17523859Sml29623 {
17533859Sml29623 	int		status = NPI_SUCCESS;
17543859Sml29623 
17553859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
17563859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
17573859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1758*6929Smisaki 		    " npi_txdma_ring_head_get"
1759*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1760*6929Smisaki 		    channel));
17613859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
17623859Sml29623 	}
17633859Sml29623 
17643859Sml29623 	TXDMA_REG_READ64(handle, TX_RING_HDL_REG, channel, &hdl_p->value);
17653859Sml29623 
17663859Sml29623 	return (status);
17673859Sml29623 }
17683859Sml29623 
17693859Sml29623 /*ARGSUSED*/
17703859Sml29623 npi_status_t
npi_txdma_channel_mbox_get(npi_handle_t handle,uint8_t channel,p_txdma_mailbox_t mbox_p)17713859Sml29623 npi_txdma_channel_mbox_get(npi_handle_t handle, uint8_t channel,
17723859Sml29623 		p_txdma_mailbox_t mbox_p)
17733859Sml29623 {
17743859Sml29623 	int		status = NPI_SUCCESS;
17753859Sml29623 
17763859Sml29623 	return (status);
17773859Sml29623 
17783859Sml29623 }
17793859Sml29623 
17803859Sml29623 npi_status_t
npi_txdma_channel_pre_state_get(npi_handle_t handle,uint8_t channel,p_tx_dma_pre_st_t prep)17813859Sml29623 npi_txdma_channel_pre_state_get(npi_handle_t handle, uint8_t channel,
17823859Sml29623 		p_tx_dma_pre_st_t prep)
17833859Sml29623 {
17843859Sml29623 	int		status = NPI_SUCCESS;
17853859Sml29623 
17863859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
17873859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
17883859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1789*6929Smisaki 		    " npi_txdma_channel_pre_state_get"
1790*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1791*6929Smisaki 		    channel));
17923859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
17933859Sml29623 	}
17943859Sml29623 
17953859Sml29623 	TXDMA_REG_READ64(handle, TX_DMA_PRE_ST_REG, channel, &prep->value);
17963859Sml29623 
17973859Sml29623 	return (status);
17983859Sml29623 }
17993859Sml29623 
18003859Sml29623 npi_status_t
npi_txdma_ring_error_get(npi_handle_t handle,uint8_t channel,p_txdma_ring_errlog_t ring_errlog_p)18013859Sml29623 npi_txdma_ring_error_get(npi_handle_t handle, uint8_t channel,
18023859Sml29623 		p_txdma_ring_errlog_t ring_errlog_p)
18033859Sml29623 {
18043859Sml29623 	tx_rng_err_logh_t	logh;
18053859Sml29623 	tx_rng_err_logl_t	logl;
18063859Sml29623 	int			status = NPI_SUCCESS;
18073859Sml29623 
18083859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
18093859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
18103859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1811*6929Smisaki 		    " npi_txdma_ring_error_get"
1812*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1813*6929Smisaki 		    channel));
18143859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
18153859Sml29623 	}
18163859Sml29623 
18173859Sml29623 	logh.value = 0;
18183859Sml29623 	TXDMA_REG_READ64(handle, TX_RNG_ERR_LOGH_REG, channel, &logh.value);
18193859Sml29623 	TXDMA_REG_READ64(handle, TX_RNG_ERR_LOGL_REG, channel, &logl.value);
18203859Sml29623 	ring_errlog_p->logh.bits.ldw.err = logh.bits.ldw.err;
18213859Sml29623 	ring_errlog_p->logh.bits.ldw.merr = logh.bits.ldw.merr;
18223859Sml29623 	ring_errlog_p->logh.bits.ldw.errcode = logh.bits.ldw.errcode;
18233859Sml29623 	ring_errlog_p->logh.bits.ldw.err_addr = logh.bits.ldw.err_addr;
18243859Sml29623 	ring_errlog_p->logl.bits.ldw.err_addr = logl.bits.ldw.err_addr;
18253859Sml29623 
18263859Sml29623 	return (status);
18273859Sml29623 }
18283859Sml29623 
18293859Sml29623 npi_status_t
npi_txdma_inj_par_error_clear(npi_handle_t handle)18303859Sml29623 npi_txdma_inj_par_error_clear(npi_handle_t handle)
18313859Sml29623 {
18323859Sml29623 	NXGE_REG_WR64(handle, TDMC_INJ_PAR_ERR_REG, 0);
18333859Sml29623 
18343859Sml29623 	return (NPI_SUCCESS);
18353859Sml29623 }
18363859Sml29623 
18373859Sml29623 npi_status_t
npi_txdma_inj_par_error_set(npi_handle_t handle,uint32_t err_bits)18383859Sml29623 npi_txdma_inj_par_error_set(npi_handle_t handle, uint32_t err_bits)
18393859Sml29623 {
18403859Sml29623 	tdmc_inj_par_err_t	inj;
18413859Sml29623 
18423859Sml29623 	inj.value = 0;
18433859Sml29623 	inj.bits.ldw.inject_parity_error = (err_bits & TDMC_INJ_PAR_ERR_MASK);
18443859Sml29623 	NXGE_REG_WR64(handle, TDMC_INJ_PAR_ERR_REG, inj.value);
18453859Sml29623 
18463859Sml29623 	return (NPI_SUCCESS);
18473859Sml29623 }
18483859Sml29623 
18493859Sml29623 npi_status_t
npi_txdma_inj_par_error_update(npi_handle_t handle,uint32_t err_bits)18503859Sml29623 npi_txdma_inj_par_error_update(npi_handle_t handle, uint32_t err_bits)
18513859Sml29623 {
18523859Sml29623 	tdmc_inj_par_err_t	inj;
18533859Sml29623 
18543859Sml29623 	inj.value = 0;
18553859Sml29623 	NXGE_REG_RD64(handle, TDMC_INJ_PAR_ERR_REG, &inj.value);
18563859Sml29623 	inj.value |= (err_bits & TDMC_INJ_PAR_ERR_MASK);
18573859Sml29623 	NXGE_REG_WR64(handle, TDMC_INJ_PAR_ERR_REG, inj.value);
18583859Sml29623 
18593859Sml29623 	return (NPI_SUCCESS);
18603859Sml29623 }
18613859Sml29623 
18623859Sml29623 npi_status_t
npi_txdma_inj_par_error_get(npi_handle_t handle,uint32_t * err_bits)18633859Sml29623 npi_txdma_inj_par_error_get(npi_handle_t handle, uint32_t *err_bits)
18643859Sml29623 {
18653859Sml29623 	tdmc_inj_par_err_t	inj;
18663859Sml29623 
18673859Sml29623 	inj.value = 0;
18683859Sml29623 	NXGE_REG_RD64(handle, TDMC_INJ_PAR_ERR_REG, &inj.value);
18693859Sml29623 	*err_bits = (inj.value & TDMC_INJ_PAR_ERR_MASK);
18703859Sml29623 
18713859Sml29623 	return (NPI_SUCCESS);
18723859Sml29623 }
18733859Sml29623 
18743859Sml29623 npi_status_t
npi_txdma_dbg_sel_set(npi_handle_t handle,uint8_t dbg_sel)18753859Sml29623 npi_txdma_dbg_sel_set(npi_handle_t handle, uint8_t dbg_sel)
18763859Sml29623 {
18773859Sml29623 	tdmc_dbg_sel_t		dbg;
18783859Sml29623 
18793859Sml29623 	dbg.value = 0;
18803859Sml29623 	dbg.bits.ldw.dbg_sel = (dbg_sel & TDMC_DBG_SEL_MASK);
18813859Sml29623 
18823859Sml29623 	NXGE_REG_WR64(handle, TDMC_DBG_SEL_REG, dbg.value);
18833859Sml29623 
18843859Sml29623 	return (NPI_SUCCESS);
18853859Sml29623 }
18863859Sml29623 
18873859Sml29623 npi_status_t
npi_txdma_training_vector_set(npi_handle_t handle,uint32_t training_vector)18883859Sml29623 npi_txdma_training_vector_set(npi_handle_t handle, uint32_t training_vector)
18893859Sml29623 {
18903859Sml29623 	tdmc_training_t		vec;
18913859Sml29623 
18923859Sml29623 	vec.value = 0;
18933859Sml29623 	vec.bits.ldw.vec = training_vector;
18943859Sml29623 
18953859Sml29623 	NXGE_REG_WR64(handle, TDMC_TRAINING_REG, vec.value);
18963859Sml29623 
18973859Sml29623 	return (NPI_SUCCESS);
18983859Sml29623 }
18993859Sml29623 
19003859Sml29623 /*
19013859Sml29623  * npi_txdma_dump_desc_one(npi_handle_t handle, p_tx_desc_t desc_p,
19023859Sml29623  *	int desc_index)
19033859Sml29623  *
19043859Sml29623  *	Dumps the contents of transmit descriptors.
19053859Sml29623  *
19063859Sml29623  * Parameters:
19073859Sml29623  *	handle		- NPI handle (register pointer is the
19083859Sml29623  *			  descriptor address in memory).
19093859Sml29623  *	desc_p		- pointer to place the descriptor contents
19103859Sml29623  *	desc_index	- descriptor index
19113859Sml29623  *
19123859Sml29623  */
19133859Sml29623 /*ARGSUSED*/
19143859Sml29623 void
npi_txdma_dump_desc_one(npi_handle_t handle,p_tx_desc_t desc_p,int desc_index)19153859Sml29623 npi_txdma_dump_desc_one(npi_handle_t handle, p_tx_desc_t desc_p, int desc_index)
19163859Sml29623 {
19173859Sml29623 
19183859Sml29623 	tx_desc_t 		desc, *desp;
19193859Sml29623 #ifdef NXGE_DEBUG
19203859Sml29623 	uint64_t		sad;
19213859Sml29623 	int			xfer_len;
19223859Sml29623 #endif
19233859Sml29623 
19243859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1925*6929Smisaki 	    "\n==> npi_txdma_dump_desc_one: dump "
1926*6929Smisaki 	    " desc_p $%p descriptor entry %d\n",
1927*6929Smisaki 	    desc_p, desc_index));
19283859Sml29623 	desc.value = 0;
19293859Sml29623 	desp = ((desc_p != NULL) ? desc_p : (p_tx_desc_t)&desc);
19303859Sml29623 	desp->value = NXGE_MEM_PIO_READ64(handle);
19313859Sml29623 #ifdef NXGE_DEBUG
19323859Sml29623 	sad = (desp->value & TX_PKT_DESC_SAD_MASK);
19333859Sml29623 	xfer_len = ((desp->value & TX_PKT_DESC_TR_LEN_MASK) >>
1934*6929Smisaki 	    TX_PKT_DESC_TR_LEN_SHIFT);
19353859Sml29623 #endif
19363859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL, "\n\t: value 0x%llx\n"
1937*6929Smisaki 	    "\t\tsad $%p\ttr_len %d len %d\tnptrs %d\tmark %d sop %d\n",
1938*6929Smisaki 	    desp->value,
1939*6929Smisaki 	    sad,
1940*6929Smisaki 	    desp->bits.hdw.tr_len,
1941*6929Smisaki 	    xfer_len,
1942*6929Smisaki 	    desp->bits.hdw.num_ptr,
1943*6929Smisaki 	    desp->bits.hdw.mark,
1944*6929Smisaki 	    desp->bits.hdw.sop));
19453859Sml29623 
19463859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1947*6929Smisaki 	    "\n<== npi_txdma_dump_desc_one: Done \n"));
19483859Sml29623 
19493859Sml29623 }
19503859Sml29623 
19513859Sml29623 /*ARGSUSED*/
19523859Sml29623 void
npi_txdma_dump_hdr(npi_handle_t handle,p_tx_pkt_header_t hdrp)19533859Sml29623 npi_txdma_dump_hdr(npi_handle_t handle, p_tx_pkt_header_t hdrp)
19543859Sml29623 {
19553859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1956*6929Smisaki 	    "\n==> npi_txdma_dump_hdr: dump\n"));
19573859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1958*6929Smisaki 	    "\n\t: value 0x%llx\n"
1959*6929Smisaki 	    "\t\tpkttype 0x%x\tip_ver %d\tllc %d\tvlan %d \tihl %d\n"
1960*6929Smisaki 	    "\t\tl3start %d\tl4start %d\tl4stuff %d\n"
1961*6929Smisaki 	    "\t\txferlen %d\tpad %d\n",
1962*6929Smisaki 	    hdrp->value,
1963*6929Smisaki 	    hdrp->bits.hdw.cksum_en_pkt_type,
1964*6929Smisaki 	    hdrp->bits.hdw.ip_ver,
1965*6929Smisaki 	    hdrp->bits.hdw.llc,
1966*6929Smisaki 	    hdrp->bits.hdw.vlan,
1967*6929Smisaki 	    hdrp->bits.hdw.ihl,
1968*6929Smisaki 	    hdrp->bits.hdw.l3start,
1969*6929Smisaki 	    hdrp->bits.hdw.l4start,
1970*6929Smisaki 	    hdrp->bits.hdw.l4stuff,
1971*6929Smisaki 	    hdrp->bits.ldw.tot_xfer_len,
1972*6929Smisaki 	    hdrp->bits.ldw.pad));
19733859Sml29623 
19743859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_TDC_CTL,
1975*6929Smisaki 	    "\n<== npi_txdma_dump_hdr: Done \n"));
19763859Sml29623 }
19773859Sml29623 
19783859Sml29623 npi_status_t
npi_txdma_inj_int_error_set(npi_handle_t handle,uint8_t channel,p_tdmc_intr_dbg_t erp)19793859Sml29623 npi_txdma_inj_int_error_set(npi_handle_t handle, uint8_t channel,
19803859Sml29623 	p_tdmc_intr_dbg_t erp)
19813859Sml29623 {
19823859Sml29623 	int		status = NPI_SUCCESS;
19833859Sml29623 
19843859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
19853859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
19863859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1987*6929Smisaki 		    " npi_txdma_inj_int_error_set"
1988*6929Smisaki 		    " Invalid Input: channel <0x%x>",
1989*6929Smisaki 		    channel));
19903859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_CHANNEL_INVALID(channel));
19913859Sml29623 	}
19923859Sml29623 
19933859Sml29623 	TXDMA_REG_WRITE64(handle, TDMC_INTR_DBG_REG, channel, erp->value);
19943859Sml29623 
19953859Sml29623 	return (status);
19963859Sml29623 }
19973859Sml29623 
19983859Sml29623 /*
19993859Sml29623  * Static functions start here.
20003859Sml29623  */
20013859Sml29623 static npi_status_t
npi_txdma_control_reset_wait(npi_handle_t handle,uint8_t channel)20023859Sml29623 npi_txdma_control_reset_wait(npi_handle_t handle, uint8_t channel)
20033859Sml29623 {
20043859Sml29623 
20053859Sml29623 	tx_cs_t		txcs;
20063859Sml29623 	int		loop = 0;
20073859Sml29623 
20083859Sml29623 	do {
20093859Sml29623 		NXGE_DELAY(TXDMA_WAIT_MSEC);
20103859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &txcs.value);
20113859Sml29623 		if (!txcs.bits.ldw.rst) {
20123859Sml29623 			return (NPI_SUCCESS);
20133859Sml29623 		}
20143859Sml29623 		loop++;
20153859Sml29623 	} while (loop < TXDMA_WAIT_LOOP);
20163859Sml29623 
20173859Sml29623 	if (loop == TXDMA_WAIT_LOOP) {
20183859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2019*6929Smisaki 		    "npi_txdma_control_reset_wait: RST bit not "
2020*6929Smisaki 		    "cleared to 0 txcs.bits 0x%llx", txcs.value));
20213859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_RESET_FAILED);
20223859Sml29623 	}
20233859Sml29623 	return (NPI_SUCCESS);
20243859Sml29623 }
20253859Sml29623 
20263859Sml29623 static npi_status_t
npi_txdma_control_stop_wait(npi_handle_t handle,uint8_t channel)20273859Sml29623 npi_txdma_control_stop_wait(npi_handle_t handle, uint8_t channel)
20283859Sml29623 {
20293859Sml29623 	tx_cs_t		txcs;
20303859Sml29623 	int		loop = 0;
20313859Sml29623 
20323859Sml29623 	do {
20333859Sml29623 		NXGE_DELAY(TXDMA_WAIT_MSEC);
20343859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &txcs.value);
20353859Sml29623 		if (txcs.bits.ldw.sng_state) {
20363859Sml29623 			return (NPI_SUCCESS);
20373859Sml29623 		}
20383859Sml29623 		loop++;
20393859Sml29623 	} while (loop < TXDMA_WAIT_LOOP);
20403859Sml29623 
20413859Sml29623 	if (loop == TXDMA_WAIT_LOOP) {
20423859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2043*6929Smisaki 		    "npi_txdma_control_stop_wait: SNG_STATE not "
2044*6929Smisaki 		    "set to 1 txcs.bits 0x%llx", txcs.value));
20453859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_STOP_FAILED);
20463859Sml29623 	}
20473859Sml29623 
20483859Sml29623 	return (NPI_SUCCESS);
20493859Sml29623 }
20503859Sml29623 
20513859Sml29623 static npi_status_t
npi_txdma_control_resume_wait(npi_handle_t handle,uint8_t channel)20523859Sml29623 npi_txdma_control_resume_wait(npi_handle_t handle, uint8_t channel)
20533859Sml29623 {
20543859Sml29623 	tx_cs_t		txcs;
20553859Sml29623 	int		loop = 0;
20563859Sml29623 
20573859Sml29623 	do {
20583859Sml29623 		NXGE_DELAY(TXDMA_WAIT_MSEC);
20593859Sml29623 		TXDMA_REG_READ64(handle, TX_CS_REG, channel, &txcs.value);
20603859Sml29623 		if (!txcs.bits.ldw.sng_state) {
20613859Sml29623 			return (NPI_SUCCESS);
20623859Sml29623 		}
20633859Sml29623 		loop++;
20643859Sml29623 	} while (loop < TXDMA_WAIT_LOOP);
20653859Sml29623 
20663859Sml29623 	if (loop == TXDMA_WAIT_LOOP) {
20673859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
2068*6929Smisaki 		    "npi_txdma_control_resume_wait: sng_state not "
2069*6929Smisaki 		    "set to 0 txcs.bits 0x%llx", txcs.value));
20703859Sml29623 		return (NPI_FAILURE | NPI_TXDMA_RESUME_FAILED);
20713859Sml29623 	}
20723859Sml29623 
20733859Sml29623 	return (NPI_SUCCESS);
20743859Sml29623 }
2075