xref: /onnv-gate/usr/src/uts/common/io/nxge/npi/npi_txc.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 /*
22*6929Smisaki  * 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_txc.h>
293859Sml29623 
303859Sml29623 /*
313859Sml29623  * Transmit Controller (TXC) Functions.
323859Sml29623  */
333859Sml29623 
343859Sml29623 uint64_t txc_fzc_dmc_offset[] = {
353859Sml29623 	TXC_DMA_MAX_BURST_REG,
363859Sml29623 	TXC_DMA_MAX_LENGTH_REG
373859Sml29623 };
383859Sml29623 
393859Sml29623 const char *txc_fzc_dmc_name[] = {
403859Sml29623 	"TXC_DMA_MAX_BURST_REG",
413859Sml29623 	"TXC_DMA_MAX_LENGTH_REG"
423859Sml29623 };
433859Sml29623 
443859Sml29623 uint64_t txc_fzc_offset [] = {
453859Sml29623 	TXC_CONTROL_REG,
463859Sml29623 	TXC_TRAINING_REG,
473859Sml29623 	TXC_DEBUG_SELECT_REG,
483859Sml29623 	TXC_MAX_REORDER_REG,
493859Sml29623 	TXC_INT_STAT_DBG_REG,
503859Sml29623 	TXC_INT_STAT_REG,
513859Sml29623 	TXC_INT_MASK_REG
523859Sml29623 };
533859Sml29623 
543859Sml29623 const char *txc_fzc_name [] = {
553859Sml29623 	"TXC_CONTROL_REG",
563859Sml29623 	"TXC_TRAINING_REG",
573859Sml29623 	"TXC_DEBUG_SELECT_REG",
583859Sml29623 	"TXC_MAX_REORDER_REG",
593859Sml29623 	"TXC_INT_STAT_DBG_REG",
603859Sml29623 	"TXC_INT_STAT_REG",
613859Sml29623 	"TXC_INT_MASK_REG"
623859Sml29623 };
633859Sml29623 
643859Sml29623 uint64_t txc_fzc_port_offset[] = {
653859Sml29623 	TXC_PORT_CTL_REG,
663859Sml29623 	TXC_PORT_DMA_ENABLE_REG,
673859Sml29623 	TXC_PKT_STUFFED_REG,
683859Sml29623 	TXC_PKT_XMIT_REG,
693859Sml29623 	TXC_ROECC_CTL_REG,
703859Sml29623 	TXC_ROECC_ST_REG,
713859Sml29623 	TXC_RO_DATA0_REG,
723859Sml29623 	TXC_RO_DATA1_REG,
733859Sml29623 	TXC_RO_DATA2_REG,
743859Sml29623 	TXC_RO_DATA3_REG,
753859Sml29623 	TXC_RO_DATA4_REG,
763859Sml29623 	TXC_SFECC_CTL_REG,
773859Sml29623 	TXC_SFECC_ST_REG,
783859Sml29623 	TXC_SF_DATA0_REG,
793859Sml29623 	TXC_SF_DATA1_REG,
803859Sml29623 	TXC_SF_DATA2_REG,
813859Sml29623 	TXC_SF_DATA3_REG,
823859Sml29623 	TXC_SF_DATA4_REG,
833859Sml29623 	TXC_RO_TIDS_REG,
843859Sml29623 	TXC_RO_STATE0_REG,
853859Sml29623 	TXC_RO_STATE1_REG,
863859Sml29623 	TXC_RO_STATE2_REG,
873859Sml29623 	TXC_RO_STATE3_REG,
883859Sml29623 	TXC_RO_CTL_REG,
893859Sml29623 	TXC_RO_ST_DATA0_REG,
903859Sml29623 	TXC_RO_ST_DATA1_REG,
913859Sml29623 	TXC_RO_ST_DATA2_REG,
923859Sml29623 	TXC_RO_ST_DATA3_REG,
933859Sml29623 	TXC_PORT_PACKET_REQ_REG
943859Sml29623 };
953859Sml29623 
963859Sml29623 const char *txc_fzc_port_name[] = {
973859Sml29623 	"TXC_PORT_CTL_REG",
983859Sml29623 	"TXC_PORT_DMA_ENABLE_REG",
993859Sml29623 	"TXC_PKT_STUFFED_REG",
1003859Sml29623 	"TXC_PKT_XMIT_REG",
1013859Sml29623 	"TXC_ROECC_CTL_REG",
1023859Sml29623 	"TXC_ROECC_ST_REG",
1033859Sml29623 	"TXC_RO_DATA0_REG",
1043859Sml29623 	"TXC_RO_DATA1_REG",
1053859Sml29623 	"TXC_RO_DATA2_REG",
1063859Sml29623 	"TXC_RO_DATA3_REG",
1073859Sml29623 	"TXC_RO_DATA4_REG",
1083859Sml29623 	"TXC_SFECC_CTL_REG",
1093859Sml29623 	"TXC_SFECC_ST_REG",
1103859Sml29623 	"TXC_SF_DATA0_REG",
1113859Sml29623 	"TXC_SF_DATA1_REG",
1123859Sml29623 	"TXC_SF_DATA2_REG",
1133859Sml29623 	"TXC_SF_DATA3_REG",
1143859Sml29623 	"TXC_SF_DATA4_REG",
1153859Sml29623 	"TXC_RO_TIDS_REG",
1163859Sml29623 	"TXC_RO_STATE0_REG",
1173859Sml29623 	"TXC_RO_STATE1_REG",
1183859Sml29623 	"TXC_RO_STATE2_REG",
1193859Sml29623 	"TXC_RO_STATE3_REG",
1203859Sml29623 	"TXC_RO_CTL_REG",
1213859Sml29623 	"TXC_RO_ST_DATA0_REG",
1223859Sml29623 	"TXC_RO_ST_DATA1_REG",
1233859Sml29623 	"TXC_RO_ST_DATA2_REG",
1243859Sml29623 	"TXC_RO_ST_DATA3_REG",
1253859Sml29623 	"TXC_PORT_PACKET_REQ_REG"
1263859Sml29623 };
1273859Sml29623 
1283859Sml29623 /*
1293859Sml29623  * npi_txc_dump_tdc_fzc_regs
1303859Sml29623  * Dumps the contents of TXC csrs and fzc registers
1313859Sml29623  *
1323859Sml29623  * Input:
1333859Sml29623  *	handle		- NPI handle
1343859Sml29623  *         tdc:      TX DMA number
1353859Sml29623  *
1363859Sml29623  * return:
1373859Sml29623  *     NPI_SUCCESS
1383859Sml29623  *     NPI_FAILURE
1393859Sml29623  *     NPI_TXC_CHANNEL_INVALID
1403859Sml29623  *
1413859Sml29623  */
1423859Sml29623 npi_status_t
npi_txc_dump_tdc_fzc_regs(npi_handle_t handle,uint8_t tdc)1433859Sml29623 npi_txc_dump_tdc_fzc_regs(npi_handle_t handle, uint8_t tdc)
1443859Sml29623 {
1453859Sml29623 	uint64_t		value, offset;
1463859Sml29623 	int 			num_regs, i;
1473859Sml29623 
1483859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(tdc));
1493859Sml29623 	if (!TXDMA_CHANNEL_VALID(tdc)) {
1503859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
151*6929Smisaki 		    "npi_txc_dump_tdc_fzc_regs"
152*6929Smisaki 		    " Invalid TDC number %d \n",
153*6929Smisaki 		    tdc));
1543859Sml29623 		return (NPI_FAILURE | NPI_TXC_CHANNEL_INVALID(tdc));
1553859Sml29623 	}
1563859Sml29623 
1573859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
158*6929Smisaki 	    "\nTXC FZC DMC Register Dump for Channel %d\n",
159*6929Smisaki 	    tdc));
1603859Sml29623 
1613859Sml29623 	num_regs = sizeof (txc_fzc_dmc_offset) / sizeof (uint64_t);
1623859Sml29623 	for (i = 0; i < num_regs; i++) {
1633859Sml29623 		offset = TXC_FZC_REG_CN_OFFSET(txc_fzc_dmc_offset[i], tdc);
1643859Sml29623 		NXGE_REG_RD64(handle, offset, &value);
1653859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
166*6929Smisaki 		    "%s\t 0x%08llx \n",
167*6929Smisaki 		    offset, txc_fzc_dmc_name[i], value));
1683859Sml29623 	}
1693859Sml29623 
1703859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
171*6929Smisaki 	    "\n TXC FZC Register Dump for Channel %d done\n", tdc));
1723859Sml29623 
1733859Sml29623 	return (NPI_SUCCESS);
1743859Sml29623 }
1753859Sml29623 
1763859Sml29623 /*
1773859Sml29623  * npi_txc_dump_fzc_regs
1783859Sml29623  * Dumps the contents of txc csrs and fzc registers
1793859Sml29623  *
1803859Sml29623  *
1813859Sml29623  * return:
1823859Sml29623  *     NPI_SUCCESS
1833859Sml29623  *     NPI_FAILURE
1843859Sml29623  *
1853859Sml29623  */
1863859Sml29623 npi_status_t
npi_txc_dump_fzc_regs(npi_handle_t handle)1873859Sml29623 npi_txc_dump_fzc_regs(npi_handle_t handle)
1883859Sml29623 {
1893859Sml29623 
1903859Sml29623 	uint64_t value;
1913859Sml29623 	int num_regs, i;
1923859Sml29623 
1933859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
194*6929Smisaki 	    "\nTXC FZC Common Register Dump\n"));
1953859Sml29623 
1963859Sml29623 	num_regs = sizeof (txc_fzc_offset) / sizeof (uint64_t);
1973859Sml29623 	for (i = 0; i < num_regs; i++) {
1983859Sml29623 		NXGE_REG_RD64(handle, txc_fzc_offset[i], &value);
1993859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
200*6929Smisaki 		    "%s\t 0x%08llx \n",
201*6929Smisaki 		    txc_fzc_offset[i], txc_fzc_name[i], value));
2023859Sml29623 	}
2033859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
204*6929Smisaki 	    "\n TXC FZC Common Register Dump Done \n"));
2053859Sml29623 
2063859Sml29623 	return (NPI_SUCCESS);
2073859Sml29623 }
2083859Sml29623 
2093859Sml29623 /*
2103859Sml29623  * npi_txc_dump_port_fzc_regs
2113859Sml29623  * Dumps the contents of TXC csrs and fzc registers
2123859Sml29623  *
2133859Sml29623  * Input:
2143859Sml29623  *	handle		- NPI handle
2153859Sml29623  *         port:      port number
2163859Sml29623  *
2173859Sml29623  * return:
2183859Sml29623  *     NPI_SUCCESS
2193859Sml29623  *     NPI_FAILURE
2203859Sml29623  *
2213859Sml29623  */
2223859Sml29623 npi_status_t
npi_txc_dump_port_fzc_regs(npi_handle_t handle,uint8_t port)2233859Sml29623 npi_txc_dump_port_fzc_regs(npi_handle_t handle, uint8_t port)
2243859Sml29623 {
2253859Sml29623 	uint64_t		value, offset;
2263859Sml29623 	int 			num_regs, i;
2273859Sml29623 
2283859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
2293859Sml29623 
2303859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
231*6929Smisaki 	    "\nTXC FZC PORT Register Dump for port %d\n", port));
2323859Sml29623 
2333859Sml29623 	num_regs = sizeof (txc_fzc_port_offset) / sizeof (uint64_t);
2343859Sml29623 	for (i = 0; i < num_regs; i++) {
2353859Sml29623 		offset = TXC_FZC_REG_PT_OFFSET(txc_fzc_port_offset[i], port);
2363859Sml29623 		NXGE_REG_RD64(handle, offset, &value);
2373859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
238*6929Smisaki 		    "%s\t 0x%08llx \n",
239*6929Smisaki 		    offset, txc_fzc_port_name[i], value));
2403859Sml29623 	}
2413859Sml29623 
2423859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
243*6929Smisaki 	    "\n TXC FZC Register Dump for port %d done\n", port));
2443859Sml29623 
2453859Sml29623 	return (NPI_SUCCESS);
2463859Sml29623 }
2473859Sml29623 
2483859Sml29623 /*
2493859Sml29623  * npi_txc_dma_max_burst():
2503859Sml29623  *	This function is called to configure the max burst bytes.
2513859Sml29623  *
2523859Sml29623  * Parameters:
2533859Sml29623  *	handle		- NPI handle
2543859Sml29623  *	op_mode		- OP_GET: get max burst value
2553859Sml29623  *			- OP_SET: set max burst value
2563859Sml29623  *	channel		- channel number (0 - 23)
2573859Sml29623  *	dma_max_burst_p - pointer to store or used for max burst value.
2583859Sml29623  * Return:
2593859Sml29623  *	NPI_SUCCESS	- If operation is complete successfully.
2603859Sml29623  *
2613859Sml29623  *	Error:
2623859Sml29623  *	NPI_FAILURE	-
2633859Sml29623  *		NPI_TXC_OPCODE_INVALID
2643859Sml29623  *		NPI_TXC_CHANNEL_INVALID
2653859Sml29623  */
2663859Sml29623 npi_status_t
npi_txc_dma_max_burst(npi_handle_t handle,io_op_t op_mode,uint8_t channel,uint32_t * dma_max_burst_p)2673859Sml29623 npi_txc_dma_max_burst(npi_handle_t handle, io_op_t op_mode, uint8_t channel,
2683859Sml29623 		uint32_t *dma_max_burst_p)
2693859Sml29623 {
2703859Sml29623 	uint64_t val;
2713859Sml29623 
2723859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
2733859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
2743859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
275*6929Smisaki 		    " npi_txc_dma_max_burst"
276*6929Smisaki 		    " Invalid Input: channel <0x%x>",
277*6929Smisaki 		    channel));
2783859Sml29623 		return (NPI_FAILURE | NPI_TXC_CHANNEL_INVALID(channel));
2793859Sml29623 	}
2803859Sml29623 
2813859Sml29623 	switch (op_mode) {
2823859Sml29623 	case OP_GET:
2833859Sml29623 		TXC_FZC_REG_READ64(handle, TXC_DMA_MAX_BURST_REG, channel,
284*6929Smisaki 		    &val);
2853859Sml29623 		*dma_max_burst_p = (uint32_t)val;
2863859Sml29623 		break;
2873859Sml29623 
2883859Sml29623 	case OP_SET:
2893859Sml29623 		TXC_FZC_REG_WRITE64(handle,
290*6929Smisaki 		    TXC_DMA_MAX_BURST_REG, channel, *dma_max_burst_p);
2913859Sml29623 		break;
2923859Sml29623 
2933859Sml29623 	default:
2943859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
295*6929Smisaki 		    " npi_txc_dma_max_burst"
296*6929Smisaki 		    " Invalid Input: burst <0x%x>",
297*6929Smisaki 		    op_mode));
2983859Sml29623 		return (NPI_FAILURE | NPI_TXC_OPCODE_INVALID(channel));
2993859Sml29623 	}
3003859Sml29623 
3013859Sml29623 	return (NPI_SUCCESS);
3023859Sml29623 }
3033859Sml29623 
3043859Sml29623 /*
3053859Sml29623  * npi_txc_dma_max_burst_set():
3063859Sml29623  *	This function is called to set the max burst bytes.
3073859Sml29623  *
3083859Sml29623  * Parameters:
3093859Sml29623  *	handle		- NPI handle
3103859Sml29623  *	channel		- channel number (0 - 23)
3113859Sml29623  *	max_burst 	- max burst to set
3123859Sml29623  * Return:
3133859Sml29623  *	NPI_SUCCESS	- If operation is complete successfully.
3143859Sml29623  *
3153859Sml29623  *	Error:
3163859Sml29623  *	NPI_FAILURE	-
3173859Sml29623  */
3183859Sml29623 npi_status_t
npi_txc_dma_max_burst_set(npi_handle_t handle,uint8_t channel,uint32_t max_burst)3193859Sml29623 npi_txc_dma_max_burst_set(npi_handle_t handle, uint8_t channel,
3203859Sml29623 		uint32_t max_burst)
3213859Sml29623 {
3223859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
3233859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
3243859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
325*6929Smisaki 		    " npi_txc_dma_max_burst_set"
326*6929Smisaki 		    " Invalid Input: channel <0x%x>",
327*6929Smisaki 		    channel));
3283859Sml29623 		return (NPI_FAILURE | NPI_TXC_CHANNEL_INVALID(channel));
3293859Sml29623 	}
3303859Sml29623 
3313859Sml29623 	TXC_FZC_REG_WRITE64(handle, TXC_DMA_MAX_BURST_REG,
332*6929Smisaki 	    channel, (uint64_t)max_burst);
3333859Sml29623 
3343859Sml29623 	return (NPI_SUCCESS);
3353859Sml29623 }
3363859Sml29623 
3373859Sml29623 /*
3383859Sml29623  * npi_txc_dma_bytes_transmitted():
3393859Sml29623  *	This function is called to get # of bytes transmitted by
3403859Sml29623  *	DMA (hardware register is cleared on read).
3413859Sml29623  *
3423859Sml29623  * Parameters:
3433859Sml29623  *	handle		- NPI handle
3443859Sml29623  *	channel		- channel number (0 - 23)
3453859Sml29623  *	dma_bytes_p 	- pointer to store bytes transmitted.
3463859Sml29623  * Return:
3473859Sml29623  *	NPI_SUCCESS	- If get is complete successfully.
3483859Sml29623  *
3493859Sml29623  *	Error:
3503859Sml29623  *	NPI_FAILURE	-
3513859Sml29623  *		NPI_TXC_PORT_INVALID
3523859Sml29623  */
3533859Sml29623 npi_status_t
npi_txc_dma_bytes_transmitted(npi_handle_t handle,uint8_t channel,uint32_t * dma_bytes_p)3543859Sml29623 npi_txc_dma_bytes_transmitted(npi_handle_t handle, uint8_t channel,
3553859Sml29623 		uint32_t *dma_bytes_p)
3563859Sml29623 {
3573859Sml29623 	uint64_t val;
3583859Sml29623 
3593859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
3603859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
3613859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
362*6929Smisaki 		    " npi_txc_dma_bytes_transmitted"
363*6929Smisaki 		    " Invalid Input: channel %d",
364*6929Smisaki 		    channel));
3653859Sml29623 		return (NPI_FAILURE | NPI_TXC_CHANNEL_INVALID(channel));
3663859Sml29623 	}
3673859Sml29623 
3683859Sml29623 	TXC_FZC_REG_READ64(handle, TXC_DMA_MAX_LENGTH_REG, channel, &val);
3693859Sml29623 	*dma_bytes_p = (uint32_t)val;
3703859Sml29623 
3713859Sml29623 	return (NPI_SUCCESS);
3723859Sml29623 }
3733859Sml29623 
3743859Sml29623 /*
3753859Sml29623  * npi_txc_control():
3763859Sml29623  *	This function is called to get or set the control register.
3773859Sml29623  *
3783859Sml29623  * Parameters:
3793859Sml29623  *	handle		- NPI handle
3803859Sml29623  *	op_mode		- OP_GET: get control register value
3813859Sml29623  *			  OP_SET: set control register value
3823859Sml29623  *	txc_control_p	- pointer to hardware defined data structure.
3833859Sml29623  * Return:
3843859Sml29623  *	NPI_SUCCESS	- If operation is complete successfully.
3853859Sml29623  *
3863859Sml29623  *	Error:
3873859Sml29623  *	NPI_FAILURE	-
3883859Sml29623  *		NPI_TXC_OPCODE_INVALID
3893859Sml29623  *		NPI_TXC_PORT_INVALID
3903859Sml29623  */
3913859Sml29623 npi_status_t
npi_txc_control(npi_handle_t handle,io_op_t op_mode,p_txc_control_t txc_control_p)3923859Sml29623 npi_txc_control(npi_handle_t handle, io_op_t op_mode,
3933859Sml29623 		p_txc_control_t txc_control_p)
3943859Sml29623 {
3953859Sml29623 	switch (op_mode) {
3963859Sml29623 	case OP_GET:
3973859Sml29623 		NXGE_REG_RD64(handle, TXC_CONTROL_REG, &txc_control_p->value);
3983859Sml29623 		break;
3993859Sml29623 
4003859Sml29623 	case OP_SET:
4013859Sml29623 		NXGE_REG_WR64(handle, TXC_CONTROL_REG,
402*6929Smisaki 		    txc_control_p->value);
4033859Sml29623 		break;
4043859Sml29623 
4053859Sml29623 	default:
4063859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
407*6929Smisaki 		    " npi_txc_control"
408*6929Smisaki 		    " Invalid Input:  control 0x%x",
409*6929Smisaki 		    op_mode));
4103859Sml29623 		return (NPI_FAILURE | NPI_TXC_OPCODE_INVALID(op_mode));
4113859Sml29623 	}
4123859Sml29623 
4133859Sml29623 	return (NPI_SUCCESS);
4143859Sml29623 }
4153859Sml29623 
4163859Sml29623 /*
4173859Sml29623  * npi_txc_global_enable():
4183859Sml29623  *	This function is called to globally enable TXC.
4193859Sml29623  *
4203859Sml29623  * Parameters:
4213859Sml29623  *	handle		- NPI handle
4223859Sml29623  * Return:
4233859Sml29623  *	NPI_SUCCESS	- If enable is complete successfully.
4243859Sml29623  *
4253859Sml29623  *	Error:
4263859Sml29623  */
4273859Sml29623 npi_status_t
npi_txc_global_enable(npi_handle_t handle)4283859Sml29623 npi_txc_global_enable(npi_handle_t handle)
4293859Sml29623 {
4303859Sml29623 	txc_control_t	cntl;
4313859Sml29623 	uint64_t	val;
4323859Sml29623 
4333859Sml29623 	cntl.value = 0;
4343859Sml29623 	cntl.bits.ldw.txc_enabled = 1;
4353859Sml29623 
4363859Sml29623 	NXGE_REG_RD64(handle, TXC_CONTROL_REG, &val);
4373859Sml29623 	NXGE_REG_WR64(handle, TXC_CONTROL_REG, val | cntl.value);
4383859Sml29623 
4393859Sml29623 	return (NPI_SUCCESS);
4403859Sml29623 }
4413859Sml29623 
4423859Sml29623 /*
4433859Sml29623  * npi_txc_global_disable():
4443859Sml29623  *	This function is called to globally disable TXC.
4453859Sml29623  *
4463859Sml29623  * Parameters:
4473859Sml29623  *	handle		- NPI handle
4483859Sml29623  * Return:
4493859Sml29623  *	NPI_SUCCESS	- If disable is complete successfully.
4503859Sml29623  *
4513859Sml29623  *	Error:
4523859Sml29623  */
4533859Sml29623 npi_status_t
npi_txc_global_disable(npi_handle_t handle)4543859Sml29623 npi_txc_global_disable(npi_handle_t handle)
4553859Sml29623 {
4563859Sml29623 	txc_control_t	cntl;
4573859Sml29623 	uint64_t	val;
4583859Sml29623 
4593859Sml29623 
4603859Sml29623 	cntl.value = 0;
4613859Sml29623 	cntl.bits.ldw.txc_enabled = 0;
4623859Sml29623 
4633859Sml29623 	NXGE_REG_RD64(handle, TXC_CONTROL_REG, &val);
4643859Sml29623 	NXGE_REG_WR64(handle, TXC_CONTROL_REG, val | cntl.value);
4653859Sml29623 
4663859Sml29623 	return (NPI_SUCCESS);
4673859Sml29623 }
4683859Sml29623 
4693859Sml29623 /*
4703859Sml29623  * npi_txc_control_clear():
4713859Sml29623  *	This function is called to clear all bits.
4723859Sml29623  *
4733859Sml29623  * Parameters:
4743859Sml29623  *	handle		- NPI handle
4753859Sml29623  * Return:
4763859Sml29623  *	NPI_SUCCESS	- If reset all bits to 0s is complete successfully.
4773859Sml29623  *
4783859Sml29623  *	Error:
4793859Sml29623  */
4803859Sml29623 npi_status_t
npi_txc_control_clear(npi_handle_t handle,uint8_t port)4813859Sml29623 npi_txc_control_clear(npi_handle_t handle, uint8_t port)
4823859Sml29623 {
4833859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
4843859Sml29623 
4853859Sml29623 	NXGE_REG_WR64(handle, TXC_PORT_CTL_REG, TXC_PORT_CNTL_CLEAR);
4863859Sml29623 
4873859Sml29623 	return (NPI_SUCCESS);
4883859Sml29623 }
4893859Sml29623 
4903859Sml29623 /*
4913859Sml29623  * npi_txc_training_set():
4923859Sml29623  *	This function is called to set the debug training vector.
4933859Sml29623  *
4943859Sml29623  * Parameters:
4953859Sml29623  *	handle			- NPI handle
4963859Sml29623  *	vector			- training vector to set.
4973859Sml29623  * Return:
4983859Sml29623  *	NPI_SUCCESS
4993859Sml29623  *
5003859Sml29623  *	Error:
5013859Sml29623  *	NPI_FAILURE		-
5023859Sml29623  */
5033859Sml29623 npi_status_t
npi_txc_training_set(npi_handle_t handle,uint32_t vector)5043859Sml29623 npi_txc_training_set(npi_handle_t handle, uint32_t vector)
5053859Sml29623 {
5063859Sml29623 	NXGE_REG_WR64(handle, TXC_TRAINING_REG, (uint64_t)vector);
5073859Sml29623 
5083859Sml29623 	return (NPI_SUCCESS);
5093859Sml29623 }
5103859Sml29623 
5113859Sml29623 /*
5123859Sml29623  * npi_txc_training_get():
5133859Sml29623  *	This function is called to get the debug training vector.
5143859Sml29623  *
5153859Sml29623  * Parameters:
5163859Sml29623  *	handle			- NPI handle
5173859Sml29623  *	vector_p		- pointer to store training vector.
5183859Sml29623  * Return:
5193859Sml29623  *	NPI_SUCCESS
5203859Sml29623  *
5213859Sml29623  *	Error:
5223859Sml29623  *	NPI_FAILURE		-
5233859Sml29623  */
5243859Sml29623 npi_status_t
npi_txc_training_get(npi_handle_t handle,uint32_t * vector_p)5253859Sml29623 npi_txc_training_get(npi_handle_t handle, uint32_t *vector_p)
5263859Sml29623 {
5273859Sml29623 	uint64_t val;
5283859Sml29623 
5293859Sml29623 	NXGE_REG_RD64(handle, (TXC_TRAINING_REG & TXC_TRAINING_VECTOR_MASK),
530*6929Smisaki 	    &val);
5313859Sml29623 	*vector_p = (uint32_t)val;
5323859Sml29623 
5333859Sml29623 	return (NPI_SUCCESS);
5343859Sml29623 }
5353859Sml29623 
5363859Sml29623 /*
5373859Sml29623  * npi_txc_port_enable():
5383859Sml29623  *	This function is called to enable a particular port.
5393859Sml29623  *
5403859Sml29623  * Parameters:
5413859Sml29623  *	handle		- NPI handle
5423859Sml29623  *	port		- port number (0 - 3)
5433859Sml29623  * Return:
5443859Sml29623  *	NPI_SUCCESS	- If port is enabled successfully.
5453859Sml29623  *
5463859Sml29623  *	Error:
5473859Sml29623  *	NPI_FAILURE	-
5483859Sml29623  *		NPI_TXC_PORT_INVALID
5493859Sml29623  */
5503859Sml29623 npi_status_t
npi_txc_port_enable(npi_handle_t handle,uint8_t port)5513859Sml29623 npi_txc_port_enable(npi_handle_t handle, uint8_t port)
5523859Sml29623 {
5533859Sml29623 	uint64_t val;
5543859Sml29623 
5553859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
5563859Sml29623 
5573859Sml29623 	NXGE_REG_RD64(handle, TXC_CONTROL_REG, &val);
5583859Sml29623 	NXGE_REG_WR64(handle, TXC_CONTROL_REG, val | (1 << port));
5593859Sml29623 
5603859Sml29623 	return (NPI_SUCCESS);
5613859Sml29623 }
5623859Sml29623 
5633859Sml29623 /*
5643859Sml29623  * npi_txc_port_disable():
5653859Sml29623  *	This function is called to disable a particular port.
5663859Sml29623  *
5673859Sml29623  * Parameters:
5683859Sml29623  *	handle		- NPI handle
5693859Sml29623  *	port		- port number (0 - 3)
5703859Sml29623  * Return:
5713859Sml29623  *	NPI_SUCCESS	- If port is disabled successfully.
5723859Sml29623  *
5733859Sml29623  *	Error:
5743859Sml29623  *	NPI_FAILURE	-
5753859Sml29623  *		NPI_TXC_PORT_INVALID
5763859Sml29623  */
5773859Sml29623 npi_status_t
npi_txc_port_disable(npi_handle_t handle,uint8_t port)5783859Sml29623 npi_txc_port_disable(npi_handle_t handle, uint8_t port)
5793859Sml29623 {
5803859Sml29623 	uint64_t val;
5813859Sml29623 
5823859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
5833859Sml29623 
5843859Sml29623 	NXGE_REG_RD64(handle, TXC_CONTROL_REG, &val);
5853859Sml29623 	NXGE_REG_WR64(handle, TXC_CONTROL_REG, (val & ~(1 << port)));
5863859Sml29623 
5873859Sml29623 	return (NPI_SUCCESS);
5883859Sml29623 }
5893859Sml29623 
5903859Sml29623 /*
5913859Sml29623  * npi_txc_port_dma_enable():
5923859Sml29623  *	This function is called to bind DMA channels (bitmap) to a port.
5933859Sml29623  *
5943859Sml29623  * Parameters:
5953859Sml29623  *	handle			- NPI handle
5963859Sml29623  *	port			- port number (0 - 3)
5973859Sml29623  *	port_dma_list_bitmap	- channels bitmap
5983859Sml29623  *				(1 to bind, 0 - 23 bits one bit/channel)
5993859Sml29623  * Return:
6003859Sml29623  *	NPI_SUCCESS		- If channels are bound successfully.
6013859Sml29623  *
6023859Sml29623  *	Error:
6033859Sml29623  *	NPI_FAILURE	-
6043859Sml29623  *		NPI_TXC_PORT_INVALID
6053859Sml29623  */
6063859Sml29623 npi_status_t
npi_txc_port_dma_enable(npi_handle_t handle,uint8_t port,uint32_t port_dma_list_bitmap)6073859Sml29623 npi_txc_port_dma_enable(npi_handle_t handle, uint8_t port,
6083859Sml29623 		uint32_t port_dma_list_bitmap)
6093859Sml29623 {
6103859Sml29623 
6113859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
6123859Sml29623 
6133859Sml29623 	TXC_FZC_CNTL_REG_WRITE64(handle, TXC_PORT_DMA_ENABLE_REG, port,
614*6929Smisaki 	    port_dma_list_bitmap);
6153859Sml29623 	return (NPI_SUCCESS);
6163859Sml29623 }
6173859Sml29623 
6183859Sml29623 npi_status_t
npi_txc_port_dma_list_get(npi_handle_t handle,uint8_t port,uint32_t * port_dma_list_bitmap)6193859Sml29623 npi_txc_port_dma_list_get(npi_handle_t handle, uint8_t port,
6203859Sml29623 		uint32_t *port_dma_list_bitmap)
6213859Sml29623 {
6223859Sml29623 	uint64_t val;
6233859Sml29623 
6243859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
6253859Sml29623 
6263859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_PORT_DMA_ENABLE_REG, port, &val);
6273859Sml29623 	*port_dma_list_bitmap = (uint32_t)(val & TXC_DMA_DMA_LIST_MASK);
6283859Sml29623 
6293859Sml29623 	return (NPI_SUCCESS);
6303859Sml29623 }
6313859Sml29623 
6323859Sml29623 /*
6333859Sml29623  * npi_txc_port_dma_channel_enable():
6343859Sml29623  *	This function is called to bind a channel to a port.
6353859Sml29623  *
6363859Sml29623  * Parameters:
6373859Sml29623  *	handle			- NPI handle
6383859Sml29623  *	port			- port number (0 - 3)
6393859Sml29623  *	channel			- channel number (0 - 23)
6403859Sml29623  * Return:
6413859Sml29623  *	NPI_SUCCESS		- If channel is bound successfully.
6423859Sml29623  *
6433859Sml29623  *	Error:
6443859Sml29623  *	NPI_FAILURE		-
6453859Sml29623  *		NPI_TXC_PORT_INVALID	-
6463859Sml29623  */
6473859Sml29623 npi_status_t
npi_txc_port_dma_channel_enable(npi_handle_t handle,uint8_t port,uint8_t channel)6483859Sml29623 npi_txc_port_dma_channel_enable(npi_handle_t handle, uint8_t port,
6493859Sml29623 		uint8_t channel)
6503859Sml29623 {
6513859Sml29623 	uint64_t val;
6523859Sml29623 
6533859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
6543859Sml29623 
6553859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
6563859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
6573859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
658*6929Smisaki 		    " npi_txc_port_dma_channel_enable"
659*6929Smisaki 		    " Invalid Input: channel <0x%x>", channel));
6603859Sml29623 		return (NPI_FAILURE | NPI_TXC_CHANNEL_INVALID(channel));
6613859Sml29623 	}
6623859Sml29623 
6633859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_PORT_DMA_ENABLE_REG, port, &val);
6643859Sml29623 	TXC_FZC_CNTL_REG_WRITE64(handle, TXC_PORT_DMA_ENABLE_REG, port,
665*6929Smisaki 	    (val | (1 << channel)));
6663859Sml29623 
6673859Sml29623 	return (NPI_SUCCESS);
6683859Sml29623 }
6693859Sml29623 
6703859Sml29623 /*
6713859Sml29623  * npi_txc_port_dma_channel_disable():
6723859Sml29623  *	This function is called to unbind a channel to a port.
6733859Sml29623  *
6743859Sml29623  * Parameters:
6753859Sml29623  *	handle			- NPI handle
6763859Sml29623  *	port			- port number (0 - 3)
6773859Sml29623  *	channel			- channel number (0 - 23)
6783859Sml29623  * Return:
6793859Sml29623  *	NPI_SUCCESS		- If channel is unbound successfully.
6803859Sml29623  *
6813859Sml29623  *	Error:
6823859Sml29623  *	NPI_FAILURE		-
6833859Sml29623  *		NPI_TXC_PORT_INVALID	-
6843859Sml29623  */
6853859Sml29623 npi_status_t
npi_txc_port_dma_channel_disable(npi_handle_t handle,uint8_t port,uint8_t channel)6863859Sml29623 npi_txc_port_dma_channel_disable(npi_handle_t handle, uint8_t port,
6873859Sml29623 		uint8_t channel)
6883859Sml29623 {
6893859Sml29623 	uint64_t val;
6903859Sml29623 
6913859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
6923859Sml29623 
6933859Sml29623 	ASSERT(TXDMA_CHANNEL_VALID(channel));
6943859Sml29623 	if (!TXDMA_CHANNEL_VALID(channel)) {
6953859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
696*6929Smisaki 		    " npi_txc_port_dma_channel_disable"
697*6929Smisaki 		    " Invalid Input: channel <0x%x>", channel));
6983859Sml29623 		return (NPI_FAILURE | NPI_TXC_CHANNEL_INVALID(channel));
6993859Sml29623 	}
7003859Sml29623 
7013859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_PORT_DMA_ENABLE_REG, port, &val)
7023859Sml29623 	TXC_FZC_CNTL_REG_WRITE64(handle, TXC_PORT_DMA_ENABLE_REG, port,
703*6929Smisaki 	    val & ~(1 << channel));
7043859Sml29623 
7053859Sml29623 	return (NPI_SUCCESS);
7063859Sml29623 }
7073859Sml29623 
7083859Sml29623 /*
7093859Sml29623  * npi_txc_max_reorder_set():
7103859Sml29623  *	This function is called to set the per port reorder resources
7113859Sml29623  *
7123859Sml29623  * Parameters:
7133859Sml29623  *	handle			- NPI handle
7143859Sml29623  *	port			- port to set
7153859Sml29623  *	reorder			- reorder resources (4 bits)
7163859Sml29623  * Return:
7173859Sml29623  *	NPI_SUCCESS
7183859Sml29623  *
7193859Sml29623  *	Error:
7203859Sml29623  *	NPI_FAILURE		-
7213859Sml29623  */
7223859Sml29623 npi_status_t
npi_txc_reorder_set(npi_handle_t handle,uint8_t port,uint8_t * reorder)7233859Sml29623 npi_txc_reorder_set(npi_handle_t handle, uint8_t port, uint8_t *reorder)
7243859Sml29623 {
7253859Sml29623 	uint64_t val;
7263859Sml29623 
7273859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
7283859Sml29623 
7293859Sml29623 	NXGE_REG_RD64(handle, TXC_MAX_REORDER_REG, &val);
7303859Sml29623 
7313859Sml29623 	val |= (*reorder << TXC_MAX_REORDER_SHIFT(port));
7323859Sml29623 
7333859Sml29623 	NXGE_REG_WR64(handle, TXC_MAX_REORDER_REG, val);
7343859Sml29623 
7353859Sml29623 	return (NPI_SUCCESS);
7363859Sml29623 }
7373859Sml29623 
7383859Sml29623 /*
7393859Sml29623  * npi_txc_reorder_get():
7403859Sml29623  *	This function is called to get the txc reorder resources.
7413859Sml29623  *
7423859Sml29623  * Parameters:
7433859Sml29623  *	handle			- NPI handle
7443859Sml29623  *	port			- port to get
7453859Sml29623  *	reorder			- data to be stored at
7463859Sml29623  * Return:
7473859Sml29623  *	NPI_SUCCESS
7483859Sml29623  *
7493859Sml29623  *	Error:
7503859Sml29623  *	NPI_FAILURE		-
7513859Sml29623  */
7523859Sml29623 npi_status_t
npi_txc_reorder_get(npi_handle_t handle,uint8_t port,uint32_t * reorder)7533859Sml29623 npi_txc_reorder_get(npi_handle_t handle, uint8_t port, uint32_t *reorder)
7543859Sml29623 {
7553859Sml29623 	uint64_t val;
7563859Sml29623 
7573859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
7583859Sml29623 
7593859Sml29623 	NXGE_REG_RD64(handle, TXC_MAX_REORDER_REG, &val);
7603859Sml29623 
7613859Sml29623 	*reorder = (uint8_t)(val >> TXC_MAX_REORDER_SHIFT(port));
7623859Sml29623 
7633859Sml29623 	return (NPI_SUCCESS);
7643859Sml29623 }
7653859Sml29623 
7663859Sml29623 /*
7673859Sml29623  * npi_txc_pkt_stuffed_get():
7683859Sml29623  *	This function is called to get total # of packets processed
7693859Sml29623  *	by reorder engine and packetAssy engine.
7703859Sml29623  *
7713859Sml29623  * Parameters:
7723859Sml29623  *	handle		- NPI handle
7733859Sml29623  *	port		- port number (0 - 3)
7743859Sml29623  *	pkt_assy_p 	- packets processed by Assy engine.
7753859Sml29623  *	pkt_reorder_p	- packets processed by reorder engine.
7763859Sml29623  *
7773859Sml29623  * Return:
7783859Sml29623  *	NPI_SUCCESS	- If get is complete successfully.
7793859Sml29623  *
7803859Sml29623  *	Error:
7813859Sml29623  *	NPI_FAILURE	-
7823859Sml29623  *		NPI_TXC_PORT_INVALID
7833859Sml29623  */
7843859Sml29623 npi_status_t
npi_txc_pkt_stuffed_get(npi_handle_t handle,uint8_t port,uint32_t * pkt_assy_p,uint32_t * pkt_reorder_p)7853859Sml29623 npi_txc_pkt_stuffed_get(npi_handle_t handle, uint8_t port,
7863859Sml29623 		uint32_t *pkt_assy_p, uint32_t *pkt_reorder_p)
7873859Sml29623 {
7883859Sml29623 	uint64_t		value;
7893859Sml29623 
7903859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
7913859Sml29623 
7923859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_PKT_STUFFED_REG, port, &value);
7933859Sml29623 	*pkt_assy_p = ((uint32_t)((value & TXC_PKT_STUFF_PKTASY_MASK) >>
794*6929Smisaki 	    TXC_PKT_STUFF_PKTASY_SHIFT));
7953859Sml29623 	*pkt_reorder_p = ((uint32_t)((value & TXC_PKT_STUFF_REORDER_MASK) >>
796*6929Smisaki 	    TXC_PKT_STUFF_REORDER_SHIFT));
7973859Sml29623 
7983859Sml29623 	return (NPI_SUCCESS);
7993859Sml29623 }
8003859Sml29623 
8013859Sml29623 /*
8023859Sml29623  * npi_txc_pkt_xmt_to_mac_get():
8033859Sml29623  *	This function is called to get total # of packets transmitted
8043859Sml29623  *	to the MAC.
8053859Sml29623  *
8063859Sml29623  * Parameters:
8073859Sml29623  *	handle		- NPI handle
8083859Sml29623  *	port		- port number (0 - 3)
8093859Sml29623  *	mac_bytes_p 	- bytes transmitted to the MAC.
8103859Sml29623  *	mac_pkts_p	- packets transmitted to the MAC.
8113859Sml29623  *
8123859Sml29623  * Return:
8133859Sml29623  *	NPI_SUCCESS	- If get is complete successfully.
8143859Sml29623  *
8153859Sml29623  *	Error:
8163859Sml29623  *	NPI_FAILURE	-
8173859Sml29623  *	NPI_TXC_PORT_INVALID
8183859Sml29623  */
8193859Sml29623 npi_status_t
npi_txc_pkt_xmt_to_mac_get(npi_handle_t handle,uint8_t port,uint32_t * mac_bytes_p,uint32_t * mac_pkts_p)8203859Sml29623 npi_txc_pkt_xmt_to_mac_get(npi_handle_t handle, uint8_t port,
8213859Sml29623 		uint32_t *mac_bytes_p, uint32_t *mac_pkts_p)
8223859Sml29623 {
8233859Sml29623 	uint64_t		value;
8243859Sml29623 
8253859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
8263859Sml29623 
8273859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_PKT_XMIT_REG, port, &value);
8283859Sml29623 	*mac_pkts_p = ((uint32_t)((value & TXC_PKTS_XMIT_MASK) >>
829*6929Smisaki 	    TXC_PKTS_XMIT_SHIFT));
8303859Sml29623 	*mac_bytes_p = ((uint32_t)((value & TXC_BYTES_XMIT_MASK) >>
831*6929Smisaki 	    TXC_BYTES_XMIT_SHIFT));
8323859Sml29623 
8333859Sml29623 	return (NPI_SUCCESS);
8343859Sml29623 }
8353859Sml29623 
8363859Sml29623 /*
8373859Sml29623  * npi_txc_get_ro_states():
8383859Sml29623  *	This function is called to get TXC's reorder state-machine states.
8393859Sml29623  *
8403859Sml29623  * Parameters:
8413859Sml29623  *	handle		- NPI handle
8423859Sml29623  *	port		- port number
8433859Sml29623  *	*states		- TXC Re-order states.
8443859Sml29623  *
8453859Sml29623  * Return:
8463859Sml29623  *	NPI_SUCCESS	- If get is complete successfully.
8473859Sml29623  *
8483859Sml29623  *	Error:
8493859Sml29623  *	NPI_FAILURE	-
8503859Sml29623  *	NPI_TXC_PORT_INVALID
8513859Sml29623  */
8523859Sml29623 npi_status_t
npi_txc_ro_states_get(npi_handle_t handle,uint8_t port,txc_ro_states_t * states)8533859Sml29623 npi_txc_ro_states_get(npi_handle_t handle, uint8_t port,
8543859Sml29623 				txc_ro_states_t *states)
8553859Sml29623 {
8563859Sml29623 	txc_ro_ctl_t	ctl;
8573859Sml29623 	txc_ro_tids_t	tids;
8583859Sml29623 	txc_ro_state0_t	s0;
8593859Sml29623 	txc_ro_state1_t	s1;
8603859Sml29623 	txc_ro_state2_t	s2;
8613859Sml29623 	txc_ro_state3_t	s3;
8623859Sml29623 	txc_roecc_st_t	ecc;
8633859Sml29623 	txc_ro_data0_t	d0;
8643859Sml29623 	txc_ro_data1_t	d1;
8653859Sml29623 	txc_ro_data2_t	d2;
8663859Sml29623 	txc_ro_data3_t	d3;
8673859Sml29623 	txc_ro_data4_t	d4;
8683859Sml29623 
8693859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
8703859Sml29623 
8713859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_ROECC_ST_REG, port, &ecc.value);
8723859Sml29623 	if ((ecc.bits.ldw.correct_error) || (ecc.bits.ldw.uncorrect_error)) {
8733859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_DATA0_REG, port,
874*6929Smisaki 		    &d0.value);
8753859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_DATA1_REG, port,
876*6929Smisaki 		    &d1.value);
8773859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_DATA2_REG, port,
878*6929Smisaki 		    &d2.value);
8793859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_DATA3_REG, port,
880*6929Smisaki 		    &d3.value);
8813859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_DATA4_REG, port,
882*6929Smisaki 		    &d4.value);
8833859Sml29623 		states->d0.value = d0.value;
8843859Sml29623 		states->d1.value = d1.value;
8853859Sml29623 		states->d2.value = d2.value;
8863859Sml29623 		states->d3.value = d3.value;
8873859Sml29623 		states->d4.value = d4.value;
8883859Sml29623 
8893859Sml29623 		ecc.bits.ldw.ecc_address = 0;
8903859Sml29623 		ecc.bits.ldw.correct_error = 0;
8913859Sml29623 		ecc.bits.ldw.uncorrect_error = 0;
8923859Sml29623 		ecc.bits.ldw.clr_st = 1;
8933859Sml29623 		TXC_FZC_CNTL_REG_WRITE64(handle, TXC_ROECC_ST_REG, port,
894*6929Smisaki 		    ecc.value);
8953859Sml29623 	}
8963859Sml29623 
8973859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_CTL_REG, port, &ctl.value);
8983859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_STATE0_REG, port, &s0.value);
8993859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_STATE1_REG, port, &s1.value);
9003859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_STATE2_REG, port, &s2.value);
9013859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_STATE3_REG, port, &s3.value);
9023859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_RO_TIDS_REG, port, &tids.value);
9033859Sml29623 
9043859Sml29623 	states->roecc.value = ctl.value;
9053859Sml29623 	states->st0.value = s0.value;
9063859Sml29623 	states->st1.value = s1.value;
9073859Sml29623 	states->st2.value = s2.value;
9083859Sml29623 	states->st3.value = s3.value;
9093859Sml29623 	states->ctl.value = ctl.value;
9103859Sml29623 	states->tids.value = tids.value;
9113859Sml29623 
9123859Sml29623 	ctl.bits.ldw.clr_fail_state = 1;
9133859Sml29623 	TXC_FZC_CNTL_REG_WRITE64(handle, TXC_RO_CTL_REG, port, ctl.value);
9143859Sml29623 
9153859Sml29623 	return (NPI_SUCCESS);
9163859Sml29623 }
9173859Sml29623 
9183859Sml29623 npi_status_t
npi_txc_ro_ecc_state_clr(npi_handle_t handle,uint8_t port)9193859Sml29623 npi_txc_ro_ecc_state_clr(npi_handle_t handle, uint8_t port)
9203859Sml29623 {
9213859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
9223859Sml29623 
9233859Sml29623 	TXC_FZC_CNTL_REG_WRITE64(handle, TXC_ROECC_ST_REG, port, 0);
9243859Sml29623 
9253859Sml29623 	return (NPI_SUCCESS);
9263859Sml29623 }
9273859Sml29623 
9283859Sml29623 /*
9293859Sml29623  * npi_txc_sf_states_get():
9303859Sml29623  *	This function is called to get TXC's store-forward state-machine states.
9313859Sml29623  *
9323859Sml29623  * Parameters:
9333859Sml29623  *	handle		- NPI handle
9343859Sml29623  *	port		- port number
9353859Sml29623  *	states		- TXC Store-forward states
9363859Sml29623  *
9373859Sml29623  * Return:
9383859Sml29623  *	NPI_SUCCESS	- If get is complete successfully.
9393859Sml29623  *
9403859Sml29623  *	Error:
9413859Sml29623  *	NPI_FAILURE	-
9423859Sml29623  *	NPI_TXC_PORT_INVALID
9433859Sml29623  */
9443859Sml29623 #ifdef lint
9453859Sml29623 /*ARGSUSED*/
9463859Sml29623 #endif
9473859Sml29623 npi_status_t
npi_txc_sf_states_get(npi_handle_t handle,uint8_t port,txc_sf_states_t * states)9483859Sml29623 npi_txc_sf_states_get(npi_handle_t handle, uint8_t port,
9493859Sml29623 				txc_sf_states_t *states)
9503859Sml29623 {
9513859Sml29623 	txc_sfecc_st_t	ecc;
9523859Sml29623 	txc_sf_data0_t	d0;
9533859Sml29623 	txc_sf_data1_t	d1;
9543859Sml29623 	txc_sf_data2_t	d2;
9553859Sml29623 	txc_sf_data3_t	d3;
9563859Sml29623 	txc_sf_data4_t	d4;
9573859Sml29623 
9583859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
9593859Sml29623 
9603859Sml29623 	TXC_FZC_CNTL_REG_READ64(handle, TXC_SFECC_ST_REG, port, &ecc.value);
9613859Sml29623 	if ((ecc.bits.ldw.correct_error) || (ecc.bits.ldw.uncorrect_error)) {
9623859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_SF_DATA0_REG, port,
963*6929Smisaki 		    &d0.value);
9643859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_SF_DATA1_REG, port,
965*6929Smisaki 		    &d1.value);
9663859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_SF_DATA2_REG, port,
967*6929Smisaki 		    &d2.value);
9683859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_SF_DATA3_REG, port,
969*6929Smisaki 		    &d3.value);
9703859Sml29623 		TXC_FZC_CNTL_REG_READ64(handle, TXC_SF_DATA4_REG, port,
971*6929Smisaki 		    &d4.value);
9723859Sml29623 		ecc.bits.ldw.ecc_address = 0;
9733859Sml29623 		ecc.bits.ldw.correct_error = 0;
9743859Sml29623 		ecc.bits.ldw.uncorrect_error = 0;
9753859Sml29623 		ecc.bits.ldw.clr_st = 1;
9763859Sml29623 		TXC_FZC_CNTL_REG_WRITE64(handle, TXC_SFECC_ST_REG, port,
977*6929Smisaki 		    ecc.value);
9783859Sml29623 	}
9793859Sml29623 
9803859Sml29623 	states->sfecc.value = ecc.value;
9813859Sml29623 	states->d0.value = d0.value;
9823859Sml29623 	states->d1.value = d1.value;
9833859Sml29623 	states->d2.value = d2.value;
9843859Sml29623 	states->d3.value = d3.value;
9853859Sml29623 	states->d4.value = d4.value;
9863859Sml29623 
9873859Sml29623 	return (NPI_SUCCESS);
9883859Sml29623 }
9893859Sml29623 
9903859Sml29623 npi_status_t
npi_txc_sf_ecc_state_clr(npi_handle_t handle,uint8_t port)9913859Sml29623 npi_txc_sf_ecc_state_clr(npi_handle_t handle, uint8_t port)
9923859Sml29623 {
9933859Sml29623 	ASSERT(IS_PORT_NUM_VALID(port));
9943859Sml29623 
9953859Sml29623 	TXC_FZC_CNTL_REG_WRITE64(handle, TXC_SFECC_ST_REG, port, 0);
9963859Sml29623 
9973859Sml29623 	return (NPI_SUCCESS);
9983859Sml29623 }
9993859Sml29623 
10003859Sml29623 /*
10013859Sml29623  * npi_txc_global_istatus_get():
10023859Sml29623  *	This function is called to get TXC's global interrupt status.
10033859Sml29623  *
10043859Sml29623  * Parameters:
10053859Sml29623  *	handle		- NPI handle
10063859Sml29623  *	istatus		- TXC global interrupt status
10073859Sml29623  *
10083859Sml29623  * Return:
10093859Sml29623  */
10103859Sml29623 void
npi_txc_global_istatus_get(npi_handle_t handle,txc_int_stat_t * istatus)10113859Sml29623 npi_txc_global_istatus_get(npi_handle_t handle, txc_int_stat_t *istatus)
10123859Sml29623 {
10133859Sml29623 	txc_int_stat_t	status;
10143859Sml29623 
10153859Sml29623 	NXGE_REG_RD64(handle, TXC_INT_STAT_REG, &status.value);
10163859Sml29623 
10173859Sml29623 	istatus->value = status.value;
10183859Sml29623 }
10193859Sml29623 
10203859Sml29623 /*
10213859Sml29623  * npi_txc_global_istatus_clear():
10223859Sml29623  *	This function is called to clear TXC's global interrupt status.
10233859Sml29623  *
10243859Sml29623  * Parameters:
10253859Sml29623  *	handle		- NPI handle
10263859Sml29623  *	istatus		- TXC global interrupt status
10273859Sml29623  *
10283859Sml29623  * Return:
10293859Sml29623  */
10303859Sml29623 void
npi_txc_global_istatus_clear(npi_handle_t handle,uint64_t istatus)10313859Sml29623 npi_txc_global_istatus_clear(npi_handle_t handle, uint64_t istatus)
10323859Sml29623 {
10333859Sml29623 	NXGE_REG_WR64(handle, TXC_INT_STAT_REG, istatus);
10343859Sml29623 }
10353859Sml29623 
10363859Sml29623 void
npi_txc_global_imask_set(npi_handle_t handle,uint8_t portn,uint8_t istatus)10373859Sml29623 npi_txc_global_imask_set(npi_handle_t handle, uint8_t portn, uint8_t istatus)
10383859Sml29623 {
10393859Sml29623 	uint64_t val;
10403859Sml29623 
10413859Sml29623 	NXGE_REG_RD64(handle, TXC_INT_MASK_REG, &val);
10423859Sml29623 	switch (portn) {
10433859Sml29623 	case 0:
10443859Sml29623 		val &= 0xFFFFFF00;
10453859Sml29623 		val |= istatus & 0x3F;
10463859Sml29623 		break;
10473859Sml29623 	case 1:
10483859Sml29623 		val &= 0xFFFF00FF;
10493859Sml29623 		val |= (istatus << 8) & 0x3F00;
10503859Sml29623 		break;
10513859Sml29623 	case 2:
10523859Sml29623 		val &= 0xFF00FFFF;
10533859Sml29623 		val |= (istatus << 16) & 0x3F0000;
10543859Sml29623 		break;
10553859Sml29623 	case 3:
10563859Sml29623 		val &= 0x00FFFFFF;
10573859Sml29623 		val |= (istatus << 24) & 0x3F000000;
10583859Sml29623 		break;
10593859Sml29623 	default:
10603859Sml29623 		;
10613859Sml29623 	}
10623859Sml29623 	NXGE_REG_WR64(handle, TXC_INT_MASK_REG, val);
10633859Sml29623 }
1064