xref: /onnv-gate/usr/src/uts/common/io/nxge/nxge_txdma.c (revision 8948:f1788c9523b2)
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*8948SMichael.Speer@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
233859Sml29623  * Use is subject to license terms.
243859Sml29623  */
253859Sml29623 
263859Sml29623 #include <sys/nxge/nxge_impl.h>
273859Sml29623 #include <sys/nxge/nxge_txdma.h>
286495Sspeer #include <sys/nxge/nxge_hio.h>
296495Sspeer #include <npi_tx_rd64.h>
306495Sspeer #include <npi_tx_wr64.h>
313859Sml29623 #include <sys/llc1.h>
323859Sml29623 
333859Sml29623 uint32_t 	nxge_reclaim_pending = TXDMA_RECLAIM_PENDING_DEFAULT;
348275SEric Cheng uint32_t	nxge_tx_minfree = 64;
353859Sml29623 uint32_t	nxge_tx_intr_thres = 0;
363859Sml29623 uint32_t	nxge_tx_max_gathers = TX_MAX_GATHER_POINTERS;
373859Sml29623 uint32_t	nxge_tx_tiny_pack = 1;
383859Sml29623 uint32_t	nxge_tx_use_bcopy = 1;
393859Sml29623 
403859Sml29623 extern uint32_t 	nxge_tx_ring_size;
413859Sml29623 extern uint32_t 	nxge_bcopy_thresh;
423859Sml29623 extern uint32_t 	nxge_dvma_thresh;
433859Sml29623 extern uint32_t 	nxge_dma_stream_thresh;
443859Sml29623 extern dma_method_t 	nxge_force_dma;
456611Sml29623 extern uint32_t		nxge_cksum_offload;
463859Sml29623 
473859Sml29623 /* Device register access attributes for PIO.  */
483859Sml29623 extern ddi_device_acc_attr_t nxge_dev_reg_acc_attr;
493859Sml29623 /* Device descriptor access attributes for DMA.  */
503859Sml29623 extern ddi_device_acc_attr_t nxge_dev_desc_dma_acc_attr;
513859Sml29623 /* Device buffer access attributes for DMA.  */
523859Sml29623 extern ddi_device_acc_attr_t nxge_dev_buf_dma_acc_attr;
533859Sml29623 extern ddi_dma_attr_t nxge_desc_dma_attr;
543859Sml29623 extern ddi_dma_attr_t nxge_tx_dma_attr;
553859Sml29623 
568275SEric Cheng extern void nxge_tx_ring_task(void *arg);
577906SMichael.Speer@Sun.COM 
586495Sspeer static nxge_status_t nxge_map_txdma(p_nxge_t, int);
596495Sspeer 
606495Sspeer static nxge_status_t nxge_txdma_hw_start(p_nxge_t, int);
613859Sml29623 
623859Sml29623 static nxge_status_t nxge_map_txdma_channel(p_nxge_t, uint16_t,
633859Sml29623 	p_nxge_dma_common_t *, p_tx_ring_t *,
643859Sml29623 	uint32_t, p_nxge_dma_common_t *,
653859Sml29623 	p_tx_mbox_t *);
666495Sspeer static void nxge_unmap_txdma_channel(p_nxge_t, uint16_t);
673859Sml29623 
683859Sml29623 static nxge_status_t nxge_map_txdma_channel_buf_ring(p_nxge_t, uint16_t,
693859Sml29623 	p_nxge_dma_common_t *, p_tx_ring_t *, uint32_t);
703859Sml29623 static void nxge_unmap_txdma_channel_buf_ring(p_nxge_t, p_tx_ring_t);
713859Sml29623 
723859Sml29623 static void nxge_map_txdma_channel_cfg_ring(p_nxge_t, uint16_t,
733859Sml29623 	p_nxge_dma_common_t *, p_tx_ring_t,
743859Sml29623 	p_tx_mbox_t *);
753859Sml29623 static void nxge_unmap_txdma_channel_cfg_ring(p_nxge_t,
763859Sml29623 	p_tx_ring_t, p_tx_mbox_t);
773859Sml29623 
783859Sml29623 static nxge_status_t nxge_txdma_start_channel(p_nxge_t, uint16_t,
793859Sml29623     p_tx_ring_t, p_tx_mbox_t);
806495Sspeer static nxge_status_t nxge_txdma_stop_channel(p_nxge_t, uint16_t);
813859Sml29623 
823859Sml29623 static p_tx_ring_t nxge_txdma_get_ring(p_nxge_t, uint16_t);
833859Sml29623 static nxge_status_t nxge_tx_err_evnts(p_nxge_t, uint_t,
843859Sml29623 	p_nxge_ldv_t, tx_cs_t);
853859Sml29623 static p_tx_mbox_t nxge_txdma_get_mbox(p_nxge_t, uint16_t);
863859Sml29623 static nxge_status_t nxge_txdma_fatal_err_recover(p_nxge_t,
873859Sml29623 	uint16_t, p_tx_ring_t);
883859Sml29623 
896495Sspeer static void nxge_txdma_fixup_hung_channel(p_nxge_t nxgep,
906495Sspeer     p_tx_ring_t ring_p, uint16_t channel);
916495Sspeer 
923859Sml29623 nxge_status_t
933859Sml29623 nxge_init_txdma_channels(p_nxge_t nxgep)
943859Sml29623 {
957950SMichael.Speer@Sun.COM 	nxge_grp_set_t	*set = &nxgep->tx_set;
967950SMichael.Speer@Sun.COM 	int		i, tdc, count;
977950SMichael.Speer@Sun.COM 	nxge_grp_t	*group;
988275SEric Cheng 	dc_map_t	map;
998275SEric Cheng 	int		dev_gindex;
1006495Sspeer 
1016495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_init_txdma_channels"));
1026495Sspeer 
1036495Sspeer 	for (i = 0, count = 0; i < NXGE_LOGICAL_GROUP_MAX; i++) {
1046495Sspeer 		if ((1 << i) & set->lg.map) {
1057950SMichael.Speer@Sun.COM 			group = set->group[i];
1068275SEric Cheng 			dev_gindex =
1078275SEric Cheng 			    nxgep->pt_config.hw_config.def_mac_txdma_grpid + i;
1088275SEric Cheng 			map = nxgep->pt_config.tdc_grps[dev_gindex].map;
1096495Sspeer 			for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
1108275SEric Cheng 				if ((1 << tdc) & map) {
1118275SEric Cheng 					if ((nxge_grp_dc_add(nxgep,
1128275SEric Cheng 					    group, VP_BOUND_TX, tdc)))
1137950SMichael.Speer@Sun.COM 						goto init_txdma_channels_exit;
1146495Sspeer 				}
1156495Sspeer 			}
1166495Sspeer 		}
1176495Sspeer 		if (++count == set->lg.count)
1186495Sspeer 			break;
1196495Sspeer 	}
1206495Sspeer 
1216495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_init_txdma_channels"));
1226495Sspeer 	return (NXGE_OK);
1237950SMichael.Speer@Sun.COM 
1247950SMichael.Speer@Sun.COM init_txdma_channels_exit:
1257950SMichael.Speer@Sun.COM 	for (i = 0, count = 0; i < NXGE_LOGICAL_GROUP_MAX; i++) {
1267950SMichael.Speer@Sun.COM 		if ((1 << i) & set->lg.map) {
1277950SMichael.Speer@Sun.COM 			group = set->group[i];
1288275SEric Cheng 			dev_gindex =
1298275SEric Cheng 			    nxgep->pt_config.hw_config.def_mac_txdma_grpid + i;
1308275SEric Cheng 			map = nxgep->pt_config.tdc_grps[dev_gindex].map;
1317950SMichael.Speer@Sun.COM 			for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
1328275SEric Cheng 				if ((1 << tdc) & map) {
1337950SMichael.Speer@Sun.COM 					nxge_grp_dc_remove(nxgep,
1347950SMichael.Speer@Sun.COM 					    VP_BOUND_TX, tdc);
1357950SMichael.Speer@Sun.COM 				}
1367950SMichael.Speer@Sun.COM 			}
1377950SMichael.Speer@Sun.COM 		}
1387950SMichael.Speer@Sun.COM 		if (++count == set->lg.count)
1397950SMichael.Speer@Sun.COM 			break;
1407950SMichael.Speer@Sun.COM 	}
1417950SMichael.Speer@Sun.COM 
1427950SMichael.Speer@Sun.COM 	return (NXGE_ERROR);
1438275SEric Cheng 
1446495Sspeer }
1456495Sspeer 
1466495Sspeer nxge_status_t
1476495Sspeer nxge_init_txdma_channel(
1486495Sspeer 	p_nxge_t nxge,
1496495Sspeer 	int channel)
1506495Sspeer {
1516495Sspeer 	nxge_status_t status;
1526495Sspeer 
1536495Sspeer 	NXGE_DEBUG_MSG((nxge, MEM2_CTL, "==> nxge_init_txdma_channel"));
1546495Sspeer 
1556495Sspeer 	status = nxge_map_txdma(nxge, channel);
1563859Sml29623 	if (status != NXGE_OK) {
1576495Sspeer 		NXGE_ERROR_MSG((nxge, NXGE_ERR_CTL,
1586495Sspeer 		    "<== nxge_init_txdma_channel: status 0x%x", status));
1596495Sspeer 		(void) npi_txdma_dump_tdc_regs(nxge->npi_handle, channel);
1603859Sml29623 		return (status);
1613859Sml29623 	}
1623859Sml29623 
1636495Sspeer 	status = nxge_txdma_hw_start(nxge, channel);
1643859Sml29623 	if (status != NXGE_OK) {
1656495Sspeer 		(void) nxge_unmap_txdma_channel(nxge, channel);
1666495Sspeer 		(void) npi_txdma_dump_tdc_regs(nxge->npi_handle, channel);
1673859Sml29623 		return (status);
1683859Sml29623 	}
1693859Sml29623 
1706495Sspeer 	if (!nxge->statsp->tdc_ksp[channel])
1716495Sspeer 		nxge_setup_tdc_kstats(nxge, channel);
1726495Sspeer 
1736495Sspeer 	NXGE_DEBUG_MSG((nxge, MEM2_CTL, "<== nxge_init_txdma_channel"));
1746495Sspeer 
1756495Sspeer 	return (status);
1763859Sml29623 }
1773859Sml29623 
1783859Sml29623 void
1793859Sml29623 nxge_uninit_txdma_channels(p_nxge_t nxgep)
1803859Sml29623 {
1816495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
1826495Sspeer 	int tdc;
1836495Sspeer 
1846495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "==> nxge_uninit_txdma_channels"));
1856495Sspeer 
1866495Sspeer 	if (set->owned.map == 0) {
1876495Sspeer 		NXGE_DEBUG_MSG((nxgep, MEM2_CTL,
1886495Sspeer 		    "nxge_uninit_txdma_channels: no channels"));
1896495Sspeer 		return;
1906495Sspeer 	}
1916495Sspeer 
1926495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
1936495Sspeer 		if ((1 << tdc) & set->owned.map) {
1946495Sspeer 			nxge_grp_dc_remove(nxgep, VP_BOUND_TX, tdc);
1956495Sspeer 		}
1966495Sspeer 	}
1976495Sspeer 
1986495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM2_CTL, "<== nxge_uninit_txdma_channels"));
1996495Sspeer }
2006495Sspeer 
2016495Sspeer void
2026495Sspeer nxge_uninit_txdma_channel(p_nxge_t nxgep, int channel)
2036495Sspeer {
2046495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_uninit_txdma_channel"));
2056495Sspeer 
2066495Sspeer 	if (nxgep->statsp->tdc_ksp[channel]) {
2076495Sspeer 		kstat_delete(nxgep->statsp->tdc_ksp[channel]);
2086495Sspeer 		nxgep->statsp->tdc_ksp[channel] = 0;
2096495Sspeer 	}
2106495Sspeer 
2116495Sspeer 	(void) nxge_txdma_stop_channel(nxgep, channel);
2126495Sspeer 	nxge_unmap_txdma_channel(nxgep, channel);
2133859Sml29623 
2143859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
2156929Smisaki 	    "<== nxge_uninit_txdma_channel"));
2163859Sml29623 }
2173859Sml29623 
2183859Sml29623 void
2193859Sml29623 nxge_setup_dma_common(p_nxge_dma_common_t dest_p, p_nxge_dma_common_t src_p,
2203859Sml29623 	uint32_t entries, uint32_t size)
2213859Sml29623 {
2223859Sml29623 	size_t		tsize;
2233859Sml29623 	*dest_p = *src_p;
2243859Sml29623 	tsize = size * entries;
2253859Sml29623 	dest_p->alength = tsize;
2263859Sml29623 	dest_p->nblocks = entries;
2273859Sml29623 	dest_p->block_size = size;
2283859Sml29623 	dest_p->offset += tsize;
2293859Sml29623 
2303859Sml29623 	src_p->kaddrp = (caddr_t)dest_p->kaddrp + tsize;
2313859Sml29623 	src_p->alength -= tsize;
2323859Sml29623 	src_p->dma_cookie.dmac_laddress += tsize;
2333859Sml29623 	src_p->dma_cookie.dmac_size -= tsize;
2343859Sml29623 }
2353859Sml29623 
2366495Sspeer /*
2376495Sspeer  * nxge_reset_txdma_channel
2386495Sspeer  *
2396495Sspeer  *	Reset a TDC.
2406495Sspeer  *
2416495Sspeer  * Arguments:
2426495Sspeer  * 	nxgep
2436495Sspeer  * 	channel		The channel to reset.
2446495Sspeer  * 	reg_data	The current TX_CS.
2456495Sspeer  *
2466495Sspeer  * Notes:
2476495Sspeer  *
2486495Sspeer  * NPI/NXGE function calls:
2496495Sspeer  *	npi_txdma_channel_reset()
2506495Sspeer  *	npi_txdma_channel_control()
2516495Sspeer  *
2526495Sspeer  * Registers accessed:
2536495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
2546495Sspeer  *	TX_RING_KICK	DMC+0x40018 Transmit Ring Kick
2556495Sspeer  *
2566495Sspeer  * Context:
2576495Sspeer  *	Any domain
2586495Sspeer  */
2593859Sml29623 nxge_status_t
2603859Sml29623 nxge_reset_txdma_channel(p_nxge_t nxgep, uint16_t channel, uint64_t reg_data)
2613859Sml29623 {
2623859Sml29623 	npi_status_t		rs = NPI_SUCCESS;
2633859Sml29623 	nxge_status_t		status = NXGE_OK;
2643859Sml29623 	npi_handle_t		handle;
2653859Sml29623 
2663859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, " ==> nxge_reset_txdma_channel"));
2673859Sml29623 
2683859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
2693859Sml29623 	if ((reg_data & TX_CS_RST_MASK) == TX_CS_RST_MASK) {
2703859Sml29623 		rs = npi_txdma_channel_reset(handle, channel);
2713859Sml29623 	} else {
2723859Sml29623 		rs = npi_txdma_channel_control(handle, TXDMA_RESET,
2736929Smisaki 		    channel);
2743859Sml29623 	}
2753859Sml29623 
2763859Sml29623 	if (rs != NPI_SUCCESS) {
2773859Sml29623 		status = NXGE_ERROR | rs;
2783859Sml29623 	}
2793859Sml29623 
2803859Sml29623 	/*
2813859Sml29623 	 * Reset the tail (kick) register to 0.
2823859Sml29623 	 * (Hardware will not reset it. Tx overflow fatal
2833859Sml29623 	 * error if tail is not set to 0 after reset!
2843859Sml29623 	 */
2853859Sml29623 	TXDMA_REG_WRITE64(handle, TX_RING_KICK_REG, channel, 0);
2863859Sml29623 
2873859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, " <== nxge_reset_txdma_channel"));
2883859Sml29623 	return (status);
2893859Sml29623 }
2903859Sml29623 
2916495Sspeer /*
2926495Sspeer  * nxge_init_txdma_channel_event_mask
2936495Sspeer  *
2946495Sspeer  *	Enable interrupts for a set of events.
2956495Sspeer  *
2966495Sspeer  * Arguments:
2976495Sspeer  * 	nxgep
2986495Sspeer  * 	channel	The channel to map.
2996495Sspeer  * 	mask_p	The events to enable.
3006495Sspeer  *
3016495Sspeer  * Notes:
3026495Sspeer  *
3036495Sspeer  * NPI/NXGE function calls:
3046495Sspeer  *	npi_txdma_event_mask()
3056495Sspeer  *
3066495Sspeer  * Registers accessed:
3076495Sspeer  *	TX_ENT_MSK	DMC+0x40020 Transmit Event Mask
3086495Sspeer  *
3096495Sspeer  * Context:
3106495Sspeer  *	Any domain
3116495Sspeer  */
3123859Sml29623 nxge_status_t
3133859Sml29623 nxge_init_txdma_channel_event_mask(p_nxge_t nxgep, uint16_t channel,
3143859Sml29623 		p_tx_dma_ent_msk_t mask_p)
3153859Sml29623 {
3163859Sml29623 	npi_handle_t		handle;
3173859Sml29623 	npi_status_t		rs = NPI_SUCCESS;
3183859Sml29623 	nxge_status_t		status = NXGE_OK;
3193859Sml29623 
3203859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
3216929Smisaki 	    "<== nxge_init_txdma_channel_event_mask"));
3223859Sml29623 
3233859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
3243859Sml29623 	rs = npi_txdma_event_mask(handle, OP_SET, channel, mask_p);
3253859Sml29623 	if (rs != NPI_SUCCESS) {
3263859Sml29623 		status = NXGE_ERROR | rs;
3273859Sml29623 	}
3283859Sml29623 
3293859Sml29623 	return (status);
3303859Sml29623 }
3313859Sml29623 
3326495Sspeer /*
3336495Sspeer  * nxge_init_txdma_channel_cntl_stat
3346495Sspeer  *
3356495Sspeer  *	Stop a TDC.  If at first we don't succeed, inject an error.
3366495Sspeer  *
3376495Sspeer  * Arguments:
3386495Sspeer  * 	nxgep
3396495Sspeer  * 	channel		The channel to stop.
3406495Sspeer  *
3416495Sspeer  * Notes:
3426495Sspeer  *
3436495Sspeer  * NPI/NXGE function calls:
3446495Sspeer  *	npi_txdma_control_status()
3456495Sspeer  *
3466495Sspeer  * Registers accessed:
3476495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
3486495Sspeer  *
3496495Sspeer  * Context:
3506495Sspeer  *	Any domain
3516495Sspeer  */
3523859Sml29623 nxge_status_t
3533859Sml29623 nxge_init_txdma_channel_cntl_stat(p_nxge_t nxgep, uint16_t channel,
3543859Sml29623 	uint64_t reg_data)
3553859Sml29623 {
3563859Sml29623 	npi_handle_t		handle;
3573859Sml29623 	npi_status_t		rs = NPI_SUCCESS;
3583859Sml29623 	nxge_status_t		status = NXGE_OK;
3593859Sml29623 
3603859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
3616929Smisaki 	    "<== nxge_init_txdma_channel_cntl_stat"));
3623859Sml29623 
3633859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
3643859Sml29623 	rs = npi_txdma_control_status(handle, OP_SET, channel,
3656929Smisaki 	    (p_tx_cs_t)&reg_data);
3663859Sml29623 
3673859Sml29623 	if (rs != NPI_SUCCESS) {
3683859Sml29623 		status = NXGE_ERROR | rs;
3693859Sml29623 	}
3703859Sml29623 
3713859Sml29623 	return (status);
3723859Sml29623 }
3733859Sml29623 
3746495Sspeer /*
3756495Sspeer  * nxge_enable_txdma_channel
3766495Sspeer  *
3776495Sspeer  *	Enable a TDC.
3786495Sspeer  *
3796495Sspeer  * Arguments:
3806495Sspeer  * 	nxgep
3816495Sspeer  * 	channel		The channel to enable.
3826495Sspeer  * 	tx_desc_p	channel's transmit descriptor ring.
3836495Sspeer  * 	mbox_p		channel's mailbox,
3846495Sspeer  *
3856495Sspeer  * Notes:
3866495Sspeer  *
3876495Sspeer  * NPI/NXGE function calls:
3886495Sspeer  *	npi_txdma_ring_config()
3896495Sspeer  *	npi_txdma_mbox_config()
3906495Sspeer  *	npi_txdma_channel_init_enable()
3916495Sspeer  *
3926495Sspeer  * Registers accessed:
3936495Sspeer  *	TX_RNG_CFIG	DMC+0x40000 Transmit Ring Configuration
3946495Sspeer  *	TXDMA_MBH	DMC+0x40030 TXDMA Mailbox High
3956495Sspeer  *	TXDMA_MBL	DMC+0x40038 TXDMA Mailbox Low
3966495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
3976495Sspeer  *
3986495Sspeer  * Context:
3996495Sspeer  *	Any domain
4006495Sspeer  */
4013859Sml29623 nxge_status_t
4023859Sml29623 nxge_enable_txdma_channel(p_nxge_t nxgep,
4033859Sml29623 	uint16_t channel, p_tx_ring_t tx_desc_p, p_tx_mbox_t mbox_p)
4043859Sml29623 {
4053859Sml29623 	npi_handle_t		handle;
4063859Sml29623 	npi_status_t		rs = NPI_SUCCESS;
4073859Sml29623 	nxge_status_t		status = NXGE_OK;
4083859Sml29623 
4093859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_enable_txdma_channel"));
4103859Sml29623 
4113859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
4123859Sml29623 	/*
4133859Sml29623 	 * Use configuration data composed at init time.
4143859Sml29623 	 * Write to hardware the transmit ring configurations.
4153859Sml29623 	 */
4163859Sml29623 	rs = npi_txdma_ring_config(handle, OP_SET, channel,
4176495Sspeer 	    (uint64_t *)&(tx_desc_p->tx_ring_cfig.value));
4183859Sml29623 
4193859Sml29623 	if (rs != NPI_SUCCESS) {
4203859Sml29623 		return (NXGE_ERROR | rs);
4213859Sml29623 	}
4223859Sml29623 
4236495Sspeer 	if (isLDOMguest(nxgep)) {
4246495Sspeer 		/* Add interrupt handler for this channel. */
4256495Sspeer 		if (nxge_hio_intr_add(nxgep, VP_BOUND_TX, channel) != NXGE_OK)
4266495Sspeer 			return (NXGE_ERROR);
4276495Sspeer 	}
4286495Sspeer 
4293859Sml29623 	/* Write to hardware the mailbox */
4303859Sml29623 	rs = npi_txdma_mbox_config(handle, OP_SET, channel,
4316929Smisaki 	    (uint64_t *)&mbox_p->tx_mbox.dma_cookie.dmac_laddress);
4323859Sml29623 
4333859Sml29623 	if (rs != NPI_SUCCESS) {
4343859Sml29623 		return (NXGE_ERROR | rs);
4353859Sml29623 	}
4363859Sml29623 
4373859Sml29623 	/* Start the DMA engine. */
4383859Sml29623 	rs = npi_txdma_channel_init_enable(handle, channel);
4393859Sml29623 
4403859Sml29623 	if (rs != NPI_SUCCESS) {
4413859Sml29623 		return (NXGE_ERROR | rs);
4423859Sml29623 	}
4433859Sml29623 
4443859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "<== nxge_enable_txdma_channel"));
4453859Sml29623 
4463859Sml29623 	return (status);
4473859Sml29623 }
4483859Sml29623 
4493859Sml29623 void
4503859Sml29623 nxge_fill_tx_hdr(p_mblk_t mp, boolean_t fill_len,
4513859Sml29623 		boolean_t l4_cksum, int pkt_len, uint8_t npads,
4526611Sml29623 		p_tx_pkt_hdr_all_t pkthdrp,
4536611Sml29623 		t_uscalar_t start_offset,
4546611Sml29623 		t_uscalar_t stuff_offset)
4553859Sml29623 {
4563859Sml29623 	p_tx_pkt_header_t	hdrp;
4573859Sml29623 	p_mblk_t 		nmp;
4583859Sml29623 	uint64_t		tmp;
4593859Sml29623 	size_t 			mblk_len;
4603859Sml29623 	size_t 			iph_len;
4613859Sml29623 	size_t 			hdrs_size;
4623859Sml29623 	uint8_t			hdrs_buf[sizeof (struct ether_header) +
4636929Smisaki 	    64 + sizeof (uint32_t)];
4645505Smisaki 	uint8_t			*cursor;
4653859Sml29623 	uint8_t 		*ip_buf;
4663859Sml29623 	uint16_t		eth_type;
4673859Sml29623 	uint8_t			ipproto;
4683859Sml29623 	boolean_t		is_vlan = B_FALSE;
4693859Sml29623 	size_t			eth_hdr_size;
4703859Sml29623 
4713859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_fill_tx_hdr: mp $%p", mp));
4723859Sml29623 
4733859Sml29623 	/*
4743859Sml29623 	 * Caller should zero out the headers first.
4753859Sml29623 	 */
4763859Sml29623 	hdrp = (p_tx_pkt_header_t)&pkthdrp->pkthdr;
4773859Sml29623 
4783859Sml29623 	if (fill_len) {
4793859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL,
4806929Smisaki 		    "==> nxge_fill_tx_hdr: pkt_len %d "
4816929Smisaki 		    "npads %d", pkt_len, npads));
4823859Sml29623 		tmp = (uint64_t)pkt_len;
4833859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_TOT_XFER_LEN_SHIFT);
4843859Sml29623 		goto fill_tx_header_done;
4853859Sml29623 	}
4863859Sml29623 
4876611Sml29623 	hdrp->value |= (((uint64_t)npads) << TX_PKT_HEADER_PAD_SHIFT);
4883859Sml29623 
4893859Sml29623 	/*
4903859Sml29623 	 * mp is the original data packet (does not include the
4913859Sml29623 	 * Neptune transmit header).
4923859Sml29623 	 */
4933859Sml29623 	nmp = mp;
4943859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_fill_tx_hdr: "
4956929Smisaki 	    "mp $%p b_rptr $%p len %d",
4966929Smisaki 	    mp, nmp->b_rptr, MBLKL(nmp)));
4975505Smisaki 	/* copy ether_header from mblk to hdrs_buf */
4985505Smisaki 	cursor = &hdrs_buf[0];
4995505Smisaki 	tmp = sizeof (struct ether_vlan_header);
5005505Smisaki 	while ((nmp != NULL) && (tmp > 0)) {
5015505Smisaki 		size_t buflen;
5025505Smisaki 		mblk_len = MBLKL(nmp);
5035512Smisaki 		buflen = min((size_t)tmp, mblk_len);
5045505Smisaki 		bcopy(nmp->b_rptr, cursor, buflen);
5055505Smisaki 		cursor += buflen;
5065505Smisaki 		tmp -= buflen;
5075505Smisaki 		nmp = nmp->b_cont;
5085505Smisaki 	}
5095505Smisaki 
5105505Smisaki 	nmp = mp;
5115505Smisaki 	mblk_len = MBLKL(nmp);
5123859Sml29623 	ip_buf = NULL;
5133859Sml29623 	eth_type = ntohs(((p_ether_header_t)hdrs_buf)->ether_type);
5143859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL, "==> : nxge_fill_tx_hdr: (value 0x%llx) "
5156929Smisaki 	    "ether type 0x%x", eth_type, hdrp->value));
5163859Sml29623 
5173859Sml29623 	if (eth_type < ETHERMTU) {
5183859Sml29623 		tmp = 1ull;
5193859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_LLC_SHIFT);
5203859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_hdr_init: LLC "
5216929Smisaki 		    "value 0x%llx", hdrp->value));
5223859Sml29623 		if (*(hdrs_buf + sizeof (struct ether_header))
5236929Smisaki 		    == LLC_SNAP_SAP) {
5243859Sml29623 			eth_type = ntohs(*((uint16_t *)(hdrs_buf +
5256929Smisaki 			    sizeof (struct ether_header) + 6)));
5263859Sml29623 			NXGE_DEBUG_MSG((NULL, TX_CTL,
5276929Smisaki 			    "==> nxge_tx_pkt_hdr_init: LLC ether type 0x%x",
5286929Smisaki 			    eth_type));
5293859Sml29623 		} else {
5303859Sml29623 			goto fill_tx_header_done;
5313859Sml29623 		}
5323859Sml29623 	} else if (eth_type == VLAN_ETHERTYPE) {
5333859Sml29623 		tmp = 1ull;
5343859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_VLAN__SHIFT);
5353859Sml29623 
5363859Sml29623 		eth_type = ntohs(((struct ether_vlan_header *)
5376929Smisaki 		    hdrs_buf)->ether_type);
5383859Sml29623 		is_vlan = B_TRUE;
5393859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_hdr_init: VLAN "
5406929Smisaki 		    "value 0x%llx", hdrp->value));
5413859Sml29623 	}
5423859Sml29623 
5433859Sml29623 	if (!is_vlan) {
5443859Sml29623 		eth_hdr_size = sizeof (struct ether_header);
5453859Sml29623 	} else {
5463859Sml29623 		eth_hdr_size = sizeof (struct ether_vlan_header);
5473859Sml29623 	}
5483859Sml29623 
5493859Sml29623 	switch (eth_type) {
5503859Sml29623 	case ETHERTYPE_IP:
5513859Sml29623 		if (mblk_len > eth_hdr_size + sizeof (uint8_t)) {
5523859Sml29623 			ip_buf = nmp->b_rptr + eth_hdr_size;
5533859Sml29623 			mblk_len -= eth_hdr_size;
5543859Sml29623 			iph_len = ((*ip_buf) & 0x0f);
5553859Sml29623 			if (mblk_len > (iph_len + sizeof (uint32_t))) {
5563859Sml29623 				ip_buf = nmp->b_rptr;
5573859Sml29623 				ip_buf += eth_hdr_size;
5583859Sml29623 			} else {
5593859Sml29623 				ip_buf = NULL;
5603859Sml29623 			}
5613859Sml29623 
5623859Sml29623 		}
5633859Sml29623 		if (ip_buf == NULL) {
5643859Sml29623 			hdrs_size = 0;
5653859Sml29623 			((p_ether_header_t)hdrs_buf)->ether_type = 0;
5663859Sml29623 			while ((nmp) && (hdrs_size <
5676929Smisaki 			    sizeof (hdrs_buf))) {
5683859Sml29623 				mblk_len = (size_t)nmp->b_wptr -
5696929Smisaki 				    (size_t)nmp->b_rptr;
5703859Sml29623 				if (mblk_len >=
5716929Smisaki 				    (sizeof (hdrs_buf) - hdrs_size))
5723859Sml29623 					mblk_len = sizeof (hdrs_buf) -
5736929Smisaki 					    hdrs_size;
5743859Sml29623 				bcopy(nmp->b_rptr,
5756929Smisaki 				    &hdrs_buf[hdrs_size], mblk_len);
5763859Sml29623 				hdrs_size += mblk_len;
5773859Sml29623 				nmp = nmp->b_cont;
5783859Sml29623 			}
5793859Sml29623 			ip_buf = hdrs_buf;
5803859Sml29623 			ip_buf += eth_hdr_size;
5813859Sml29623 			iph_len = ((*ip_buf) & 0x0f);
5823859Sml29623 		}
5833859Sml29623 
5843859Sml29623 		ipproto = ip_buf[9];
5853859Sml29623 
5863859Sml29623 		tmp = (uint64_t)iph_len;
5873859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_IHL_SHIFT);
5883859Sml29623 		tmp = (uint64_t)(eth_hdr_size >> 1);
5893859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_L3START_SHIFT);
5903859Sml29623 
5913859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_fill_tx_hdr: IPv4 "
5926929Smisaki 		    " iph_len %d l3start %d eth_hdr_size %d proto 0x%x"
5936929Smisaki 		    "tmp 0x%x",
5946929Smisaki 		    iph_len, hdrp->bits.hdw.l3start, eth_hdr_size,
5956929Smisaki 		    ipproto, tmp));
5963859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_hdr_init: IP "
5976929Smisaki 		    "value 0x%llx", hdrp->value));
5983859Sml29623 
5993859Sml29623 		break;
6003859Sml29623 
6013859Sml29623 	case ETHERTYPE_IPV6:
6023859Sml29623 		hdrs_size = 0;
6033859Sml29623 		((p_ether_header_t)hdrs_buf)->ether_type = 0;
6043859Sml29623 		while ((nmp) && (hdrs_size <
6056929Smisaki 		    sizeof (hdrs_buf))) {
6063859Sml29623 			mblk_len = (size_t)nmp->b_wptr - (size_t)nmp->b_rptr;
6073859Sml29623 			if (mblk_len >=
6086929Smisaki 			    (sizeof (hdrs_buf) - hdrs_size))
6093859Sml29623 				mblk_len = sizeof (hdrs_buf) -
6106929Smisaki 				    hdrs_size;
6113859Sml29623 			bcopy(nmp->b_rptr,
6126929Smisaki 			    &hdrs_buf[hdrs_size], mblk_len);
6133859Sml29623 			hdrs_size += mblk_len;
6143859Sml29623 			nmp = nmp->b_cont;
6153859Sml29623 		}
6163859Sml29623 		ip_buf = hdrs_buf;
6173859Sml29623 		ip_buf += eth_hdr_size;
6183859Sml29623 
6193859Sml29623 		tmp = 1ull;
6203859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_IP_VER_SHIFT);
6213859Sml29623 
6223859Sml29623 		tmp = (eth_hdr_size >> 1);
6233859Sml29623 		hdrp->value |= (tmp << TX_PKT_HEADER_L3START_SHIFT);
6243859Sml29623 
6253859Sml29623 		/* byte 6 is the next header protocol */
6263859Sml29623 		ipproto = ip_buf[6];
6273859Sml29623 
6283859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_fill_tx_hdr: IPv6 "
6296929Smisaki 		    " iph_len %d l3start %d eth_hdr_size %d proto 0x%x",
6306929Smisaki 		    iph_len, hdrp->bits.hdw.l3start, eth_hdr_size,
6316929Smisaki 		    ipproto));
6323859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_hdr_init: IPv6 "
6336929Smisaki 		    "value 0x%llx", hdrp->value));
6343859Sml29623 
6353859Sml29623 		break;
6363859Sml29623 
6373859Sml29623 	default:
6383859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_fill_tx_hdr: non-IP"));
6393859Sml29623 		goto fill_tx_header_done;
6403859Sml29623 	}
6413859Sml29623 
6423859Sml29623 	switch (ipproto) {
6433859Sml29623 	case IPPROTO_TCP:
6443859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL,
6456611Sml29623 		    "==> nxge_fill_tx_hdr: TCP (cksum flag %d)", l4_cksum));
6463859Sml29623 		if (l4_cksum) {
6476611Sml29623 			hdrp->value |= TX_CKSUM_EN_PKT_TYPE_TCP;
6486611Sml29623 			hdrp->value |=
6496611Sml29623 			    (((uint64_t)(start_offset >> 1)) <<
6506611Sml29623 			    TX_PKT_HEADER_L4START_SHIFT);
6516611Sml29623 			hdrp->value |=
6526611Sml29623 			    (((uint64_t)(stuff_offset >> 1)) <<
6536611Sml29623 			    TX_PKT_HEADER_L4STUFF_SHIFT);
6546611Sml29623 
6553859Sml29623 			NXGE_DEBUG_MSG((NULL, TX_CTL,
6566611Sml29623 			    "==> nxge_tx_pkt_hdr_init: TCP CKSUM "
6576611Sml29623 			    "value 0x%llx", hdrp->value));
6583859Sml29623 		}
6593859Sml29623 
6603859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_hdr_init: TCP "
6616611Sml29623 		    "value 0x%llx", hdrp->value));
6623859Sml29623 		break;
6633859Sml29623 
6643859Sml29623 	case IPPROTO_UDP:
6653859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_fill_tx_hdr: UDP"));
6663859Sml29623 		if (l4_cksum) {
6676611Sml29623 			if (!nxge_cksum_offload) {
6686611Sml29623 				uint16_t	*up;
6696611Sml29623 				uint16_t	cksum;
6706611Sml29623 				t_uscalar_t	stuff_len;
6716611Sml29623 
6726611Sml29623 				/*
6736611Sml29623 				 * The checksum field has the
6746611Sml29623 				 * partial checksum.
6756611Sml29623 				 * IP_CSUM() macro calls ip_cksum() which
6766611Sml29623 				 * can add in the partial checksum.
6776611Sml29623 				 */
6786611Sml29623 				cksum = IP_CSUM(mp, start_offset, 0);
6796611Sml29623 				stuff_len = stuff_offset;
6806611Sml29623 				nmp = mp;
6816611Sml29623 				mblk_len = MBLKL(nmp);
6826611Sml29623 				while ((nmp != NULL) &&
6836611Sml29623 				    (mblk_len < stuff_len)) {
6846611Sml29623 					stuff_len -= mblk_len;
6856611Sml29623 					nmp = nmp->b_cont;
6866611Sml29623 				}
6876611Sml29623 				ASSERT(nmp);
6886611Sml29623 				up = (uint16_t *)(nmp->b_rptr + stuff_len);
6896611Sml29623 
6906611Sml29623 				*up = cksum;
6916611Sml29623 				hdrp->value &= ~TX_CKSUM_EN_PKT_TYPE_UDP;
6926611Sml29623 				NXGE_DEBUG_MSG((NULL, TX_CTL,
6936611Sml29623 				    "==> nxge_tx_pkt_hdr_init: UDP offset %d "
6946611Sml29623 				    "use sw cksum "
6956611Sml29623 				    "write to $%p cksum 0x%x content up 0x%x",
6966611Sml29623 				    stuff_len,
6976611Sml29623 				    up,
6986611Sml29623 				    cksum,
6996611Sml29623 				    *up));
7006611Sml29623 			} else {
7016611Sml29623 				/* Hardware will compute the full checksum */
7026611Sml29623 				hdrp->value |= TX_CKSUM_EN_PKT_TYPE_UDP;
7036611Sml29623 				hdrp->value |=
7046611Sml29623 				    (((uint64_t)(start_offset >> 1)) <<
7056611Sml29623 				    TX_PKT_HEADER_L4START_SHIFT);
7066611Sml29623 				hdrp->value |=
7076611Sml29623 				    (((uint64_t)(stuff_offset >> 1)) <<
7086611Sml29623 				    TX_PKT_HEADER_L4STUFF_SHIFT);
7096611Sml29623 
7106611Sml29623 				NXGE_DEBUG_MSG((NULL, TX_CTL,
7116611Sml29623 				    "==> nxge_tx_pkt_hdr_init: UDP offset %d "
7126611Sml29623 				    " use partial checksum "
7136611Sml29623 				    "cksum 0x%x ",
7146611Sml29623 				    "value 0x%llx",
7156611Sml29623 				    stuff_offset,
7166611Sml29623 				    IP_CSUM(mp, start_offset, 0),
7176611Sml29623 				    hdrp->value));
7186611Sml29623 			}
7193859Sml29623 		}
7206611Sml29623 
7213859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL,
7226929Smisaki 		    "==> nxge_tx_pkt_hdr_init: UDP"
7236929Smisaki 		    "value 0x%llx", hdrp->value));
7243859Sml29623 		break;
7253859Sml29623 
7263859Sml29623 	default:
7273859Sml29623 		goto fill_tx_header_done;
7283859Sml29623 	}
7293859Sml29623 
7303859Sml29623 fill_tx_header_done:
7313859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL,
7326929Smisaki 	    "==> nxge_fill_tx_hdr: pkt_len %d  "
7336929Smisaki 	    "npads %d value 0x%llx", pkt_len, npads, hdrp->value));
7343859Sml29623 
7353859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL, "<== nxge_fill_tx_hdr"));
7363859Sml29623 }
7373859Sml29623 
7383859Sml29623 /*ARGSUSED*/
7393859Sml29623 p_mblk_t
7403859Sml29623 nxge_tx_pkt_header_reserve(p_mblk_t mp, uint8_t *npads)
7413859Sml29623 {
7423859Sml29623 	p_mblk_t 		newmp = NULL;
7433859Sml29623 
7443859Sml29623 	if ((newmp = allocb(TX_PKT_HEADER_SIZE, BPRI_MED)) == NULL) {
7453859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL,
7466929Smisaki 		    "<== nxge_tx_pkt_header_reserve: allocb failed"));
7473859Sml29623 		return (NULL);
7483859Sml29623 	}
7493859Sml29623 
7503859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL,
7516929Smisaki 	    "==> nxge_tx_pkt_header_reserve: get new mp"));
7523859Sml29623 	DB_TYPE(newmp) = M_DATA;
7533859Sml29623 	newmp->b_rptr = newmp->b_wptr = DB_LIM(newmp);
7543859Sml29623 	linkb(newmp, mp);
7553859Sml29623 	newmp->b_rptr -= TX_PKT_HEADER_SIZE;
7563859Sml29623 
7573859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL, "==>nxge_tx_pkt_header_reserve: "
7586929Smisaki 	    "b_rptr $%p b_wptr $%p",
7596929Smisaki 	    newmp->b_rptr, newmp->b_wptr));
7603859Sml29623 
7613859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL,
7626929Smisaki 	    "<== nxge_tx_pkt_header_reserve: use new mp"));
7633859Sml29623 
7643859Sml29623 	return (newmp);
7653859Sml29623 }
7663859Sml29623 
7673859Sml29623 int
7683859Sml29623 nxge_tx_pkt_nmblocks(p_mblk_t mp, int *tot_xfer_len_p)
7693859Sml29623 {
7703859Sml29623 	uint_t 			nmblks;
7713859Sml29623 	ssize_t			len;
7723859Sml29623 	uint_t 			pkt_len;
7733859Sml29623 	p_mblk_t 		nmp, bmp, tmp;
7743859Sml29623 	uint8_t 		*b_wptr;
7753859Sml29623 
7763859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL,
7776929Smisaki 	    "==> nxge_tx_pkt_nmblocks: mp $%p rptr $%p wptr $%p "
7786929Smisaki 	    "len %d", mp, mp->b_rptr, mp->b_wptr, MBLKL(mp)));
7793859Sml29623 
7803859Sml29623 	nmp = mp;
7813859Sml29623 	bmp = mp;
7823859Sml29623 	nmblks = 0;
7833859Sml29623 	pkt_len = 0;
7843859Sml29623 	*tot_xfer_len_p = 0;
7853859Sml29623 
7863859Sml29623 	while (nmp) {
7873859Sml29623 		len = MBLKL(nmp);
7883859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_nmblocks: "
7896929Smisaki 		    "len %d pkt_len %d nmblks %d tot_xfer_len %d",
7906929Smisaki 		    len, pkt_len, nmblks,
7916929Smisaki 		    *tot_xfer_len_p));
7923859Sml29623 
7933859Sml29623 		if (len <= 0) {
7943859Sml29623 			bmp = nmp;
7953859Sml29623 			nmp = nmp->b_cont;
7963859Sml29623 			NXGE_DEBUG_MSG((NULL, TX_CTL,
7976929Smisaki 			    "==> nxge_tx_pkt_nmblocks: "
7986929Smisaki 			    "len (0) pkt_len %d nmblks %d",
7996929Smisaki 			    pkt_len, nmblks));
8003859Sml29623 			continue;
8013859Sml29623 		}
8023859Sml29623 
8033859Sml29623 		*tot_xfer_len_p += len;
8043859Sml29623 		NXGE_DEBUG_MSG((NULL, TX_CTL, "==> nxge_tx_pkt_nmblocks: "
8056929Smisaki 		    "len %d pkt_len %d nmblks %d tot_xfer_len %d",
8066929Smisaki 		    len, pkt_len, nmblks,
8076929Smisaki 		    *tot_xfer_len_p));
8083859Sml29623 
8093859Sml29623 		if (len < nxge_bcopy_thresh) {
8103859Sml29623 			NXGE_DEBUG_MSG((NULL, TX_CTL,
8116929Smisaki 			    "==> nxge_tx_pkt_nmblocks: "
8126929Smisaki 			    "len %d (< thresh) pkt_len %d nmblks %d",
8136929Smisaki 			    len, pkt_len, nmblks));
8143859Sml29623 			if (pkt_len == 0)
8153859Sml29623 				nmblks++;
8163859Sml29623 			pkt_len += len;
8173859Sml29623 			if (pkt_len >= nxge_bcopy_thresh) {
8183859Sml29623 				pkt_len = 0;
8193859Sml29623 				len = 0;
8203859Sml29623 				nmp = bmp;
8213859Sml29623 			}
8223859Sml29623 		} else {
8233859Sml29623 			NXGE_DEBUG_MSG((NULL, TX_CTL,
8246929Smisaki 			    "==> nxge_tx_pkt_nmblocks: "
8256929Smisaki 			    "len %d (> thresh) pkt_len %d nmblks %d",
8266929Smisaki 			    len, pkt_len, nmblks));
8273859Sml29623 			pkt_len = 0;
8283859Sml29623 			nmblks++;
8293859Sml29623 			/*
8303859Sml29623 			 * Hardware limits the transfer length to 4K.
8313859Sml29623 			 * If len is more than 4K, we need to break
8323859Sml29623 			 * it up to at most 2 more blocks.
8333859Sml29623 			 */
8343859Sml29623 			if (len > TX_MAX_TRANSFER_LENGTH) {
8353859Sml29623 				uint32_t	nsegs;
8363859Sml29623 
8376495Sspeer 				nsegs = 1;
8383859Sml29623 				NXGE_DEBUG_MSG((NULL, TX_CTL,
8396929Smisaki 				    "==> nxge_tx_pkt_nmblocks: "
8406929Smisaki 				    "len %d pkt_len %d nmblks %d nsegs %d",
8416929Smisaki 				    len, pkt_len, nmblks, nsegs));
8423859Sml29623 				if (len % (TX_MAX_TRANSFER_LENGTH * 2)) {
8433859Sml29623 					++nsegs;
8443859Sml29623 				}
8453859Sml29623 				do {
8463859Sml29623 					b_wptr = nmp->b_rptr +
8476929Smisaki 					    TX_MAX_TRANSFER_LENGTH;
8483859Sml29623 					nmp->b_wptr = b_wptr;
8493859Sml29623 					if ((tmp = dupb(nmp)) == NULL) {
8503859Sml29623 						return (0);
8513859Sml29623 					}
8523859Sml29623 					tmp->b_rptr = b_wptr;
8533859Sml29623 					tmp->b_wptr = nmp->b_wptr;
8543859Sml29623 					tmp->b_cont = nmp->b_cont;
8553859Sml29623 					nmp->b_cont = tmp;
8563859Sml29623 					nmblks++;
8573859Sml29623 					if (--nsegs) {
8583859Sml29623 						nmp = tmp;
8593859Sml29623 					}
8603859Sml29623 				} while (nsegs);
8613859Sml29623 				nmp = tmp;
8623859Sml29623 			}
8633859Sml29623 		}
8643859Sml29623 
8653859Sml29623 		/*
8663859Sml29623 		 * Hardware limits the transmit gather pointers to 15.
8673859Sml29623 		 */
8683859Sml29623 		if (nmp->b_cont && (nmblks + TX_GATHER_POINTERS_THRESHOLD) >
8696929Smisaki 		    TX_MAX_GATHER_POINTERS) {
8703859Sml29623 			NXGE_DEBUG_MSG((NULL, TX_CTL,
8716929Smisaki 			    "==> nxge_tx_pkt_nmblocks: pull msg - "
8726929Smisaki 			    "len %d pkt_len %d nmblks %d",
8736929Smisaki 			    len, pkt_len, nmblks));
8743859Sml29623 			/* Pull all message blocks from b_cont */
8753859Sml29623 			if ((tmp = msgpullup(nmp->b_cont, -1)) == NULL) {
8763859Sml29623 				return (0);
8773859Sml29623 			}
8783859Sml29623 			freemsg(nmp->b_cont);
8793859Sml29623 			nmp->b_cont = tmp;
8803859Sml29623 			pkt_len = 0;
8813859Sml29623 		}
8823859Sml29623 		bmp = nmp;
8833859Sml29623 		nmp = nmp->b_cont;
8843859Sml29623 	}
8853859Sml29623 
8863859Sml29623 	NXGE_DEBUG_MSG((NULL, TX_CTL,
8876929Smisaki 	    "<== nxge_tx_pkt_nmblocks: rptr $%p wptr $%p "
8886929Smisaki 	    "nmblks %d len %d tot_xfer_len %d",
8896929Smisaki 	    mp->b_rptr, mp->b_wptr, nmblks,
8906929Smisaki 	    MBLKL(mp), *tot_xfer_len_p));
8913859Sml29623 
8923859Sml29623 	return (nmblks);
8933859Sml29623 }
8943859Sml29623 
8953859Sml29623 boolean_t
8963859Sml29623 nxge_txdma_reclaim(p_nxge_t nxgep, p_tx_ring_t tx_ring_p, int nmblks)
8973859Sml29623 {
8983859Sml29623 	boolean_t 		status = B_TRUE;
8993859Sml29623 	p_nxge_dma_common_t	tx_desc_dma_p;
9003859Sml29623 	nxge_dma_common_t	desc_area;
9013859Sml29623 	p_tx_desc_t 		tx_desc_ring_vp;
9023859Sml29623 	p_tx_desc_t 		tx_desc_p;
9033859Sml29623 	p_tx_desc_t 		tx_desc_pp;
9043859Sml29623 	tx_desc_t 		r_tx_desc;
9053859Sml29623 	p_tx_msg_t 		tx_msg_ring;
9063859Sml29623 	p_tx_msg_t 		tx_msg_p;
9073859Sml29623 	npi_handle_t		handle;
9083859Sml29623 	tx_ring_hdl_t		tx_head;
9093859Sml29623 	uint32_t 		pkt_len;
9103859Sml29623 	uint_t			tx_rd_index;
9113859Sml29623 	uint16_t		head_index, tail_index;
9123859Sml29623 	uint8_t			tdc;
9133859Sml29623 	boolean_t		head_wrap, tail_wrap;
9148275SEric Cheng 	p_nxge_tx_ring_stats_t tdc_stats;
9153859Sml29623 	int			rc;
9163859Sml29623 
9173859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_reclaim"));
9183859Sml29623 
9193859Sml29623 	status = ((tx_ring_p->descs_pending < nxge_reclaim_pending) &&
9206929Smisaki 	    (nmblks != 0));
9213859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
9226929Smisaki 	    "==> nxge_txdma_reclaim: pending %d  reclaim %d nmblks %d",
9236929Smisaki 	    tx_ring_p->descs_pending, nxge_reclaim_pending,
9246929Smisaki 	    nmblks));
9253859Sml29623 	if (!status) {
9263859Sml29623 		tx_desc_dma_p = &tx_ring_p->tdc_desc;
9273859Sml29623 		desc_area = tx_ring_p->tdc_desc;
9283859Sml29623 		handle = NXGE_DEV_NPI_HANDLE(nxgep);
9293859Sml29623 		tx_desc_ring_vp = tx_desc_dma_p->kaddrp;
9303859Sml29623 		tx_desc_ring_vp =
9316929Smisaki 		    (p_tx_desc_t)DMA_COMMON_VPTR(desc_area);
9323859Sml29623 		tx_rd_index = tx_ring_p->rd_index;
9333859Sml29623 		tx_desc_p = &tx_desc_ring_vp[tx_rd_index];
9343859Sml29623 		tx_msg_ring = tx_ring_p->tx_msg_ring;
9353859Sml29623 		tx_msg_p = &tx_msg_ring[tx_rd_index];
9363859Sml29623 		tdc = tx_ring_p->tdc;
9373859Sml29623 		tdc_stats = tx_ring_p->tdc_stats;
9383859Sml29623 		if (tx_ring_p->descs_pending > tdc_stats->tx_max_pend) {
9393859Sml29623 			tdc_stats->tx_max_pend = tx_ring_p->descs_pending;
9403859Sml29623 		}
9413859Sml29623 
9423859Sml29623 		tail_index = tx_ring_p->wr_index;
9433859Sml29623 		tail_wrap = tx_ring_p->wr_index_wrap;
9443859Sml29623 
9453859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
9466929Smisaki 		    "==> nxge_txdma_reclaim: tdc %d tx_rd_index %d "
9476929Smisaki 		    "tail_index %d tail_wrap %d "
9486929Smisaki 		    "tx_desc_p $%p ($%p) ",
9496929Smisaki 		    tdc, tx_rd_index, tail_index, tail_wrap,
9506929Smisaki 		    tx_desc_p, (*(uint64_t *)tx_desc_p)));
9513859Sml29623 		/*
9523859Sml29623 		 * Read the hardware maintained transmit head
9533859Sml29623 		 * and wrap around bit.
9543859Sml29623 		 */
9553859Sml29623 		TXDMA_REG_READ64(handle, TX_RING_HDL_REG, tdc, &tx_head.value);
9563859Sml29623 		head_index =  tx_head.bits.ldw.head;
9573859Sml29623 		head_wrap = tx_head.bits.ldw.wrap;
9583859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
9596929Smisaki 		    "==> nxge_txdma_reclaim: "
9606929Smisaki 		    "tx_rd_index %d tail %d tail_wrap %d "
9616929Smisaki 		    "head %d wrap %d",
9626929Smisaki 		    tx_rd_index, tail_index, tail_wrap,
9636929Smisaki 		    head_index, head_wrap));
9643859Sml29623 
9653859Sml29623 		if (head_index == tail_index) {
9663859Sml29623 			if (TXDMA_RING_EMPTY(head_index, head_wrap,
9676929Smisaki 			    tail_index, tail_wrap) &&
9686929Smisaki 			    (head_index == tx_rd_index)) {
9693859Sml29623 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
9706929Smisaki 				    "==> nxge_txdma_reclaim: EMPTY"));
9713859Sml29623 				return (B_TRUE);
9723859Sml29623 			}
9733859Sml29623 
9743859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
9756929Smisaki 			    "==> nxge_txdma_reclaim: Checking "
9766929Smisaki 			    "if ring full"));
9773859Sml29623 			if (TXDMA_RING_FULL(head_index, head_wrap, tail_index,
9786929Smisaki 			    tail_wrap)) {
9793859Sml29623 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
9806929Smisaki 				    "==> nxge_txdma_reclaim: full"));
9813859Sml29623 				return (B_FALSE);
9823859Sml29623 			}
9833859Sml29623 		}
9843859Sml29623 
9853859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
9866929Smisaki 		    "==> nxge_txdma_reclaim: tx_rd_index and head_index"));
9873859Sml29623 
9883859Sml29623 		tx_desc_pp = &r_tx_desc;
9893859Sml29623 		while ((tx_rd_index != head_index) &&
9906929Smisaki 		    (tx_ring_p->descs_pending != 0)) {
9913859Sml29623 
9923859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
9936929Smisaki 			    "==> nxge_txdma_reclaim: Checking if pending"));
9943859Sml29623 
9953859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
9966929Smisaki 			    "==> nxge_txdma_reclaim: "
9976929Smisaki 			    "descs_pending %d ",
9986929Smisaki 			    tx_ring_p->descs_pending));
9993859Sml29623 
10003859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
10016929Smisaki 			    "==> nxge_txdma_reclaim: "
10026929Smisaki 			    "(tx_rd_index %d head_index %d "
10036929Smisaki 			    "(tx_desc_p $%p)",
10046929Smisaki 			    tx_rd_index, head_index,
10056929Smisaki 			    tx_desc_p));
10063859Sml29623 
10073859Sml29623 			tx_desc_pp->value = tx_desc_p->value;
10083859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
10096929Smisaki 			    "==> nxge_txdma_reclaim: "
10106929Smisaki 			    "(tx_rd_index %d head_index %d "
10116929Smisaki 			    "tx_desc_p $%p (desc value 0x%llx) ",
10126929Smisaki 			    tx_rd_index, head_index,
10136929Smisaki 			    tx_desc_pp, (*(uint64_t *)tx_desc_pp)));
10143859Sml29623 
10153859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
10166929Smisaki 			    "==> nxge_txdma_reclaim: dump desc:"));
10173859Sml29623 
10183859Sml29623 			pkt_len = tx_desc_pp->bits.hdw.tr_len;
10193859Sml29623 			tdc_stats->obytes += pkt_len;
10203859Sml29623 			tdc_stats->opackets += tx_desc_pp->bits.hdw.sop;
10213859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
10226929Smisaki 			    "==> nxge_txdma_reclaim: pkt_len %d "
10236929Smisaki 			    "tdc channel %d opackets %d",
10246929Smisaki 			    pkt_len,
10256929Smisaki 			    tdc,
10266929Smisaki 			    tdc_stats->opackets));
10273859Sml29623 
10283859Sml29623 			if (tx_msg_p->flags.dma_type == USE_DVMA) {
10293859Sml29623 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
10306929Smisaki 				    "tx_desc_p = $%p "
10316929Smisaki 				    "tx_desc_pp = $%p "
10326929Smisaki 				    "index = %d",
10336929Smisaki 				    tx_desc_p,
10346929Smisaki 				    tx_desc_pp,
10356929Smisaki 				    tx_ring_p->rd_index));
10363859Sml29623 				(void) dvma_unload(tx_msg_p->dvma_handle,
10376929Smisaki 				    0, -1);
10383859Sml29623 				tx_msg_p->dvma_handle = NULL;
10393859Sml29623 				if (tx_ring_p->dvma_wr_index ==
10406929Smisaki 				    tx_ring_p->dvma_wrap_mask) {
10413859Sml29623 					tx_ring_p->dvma_wr_index = 0;
10423859Sml29623 				} else {
10433859Sml29623 					tx_ring_p->dvma_wr_index++;
10443859Sml29623 				}
10453859Sml29623 				tx_ring_p->dvma_pending--;
10463859Sml29623 			} else if (tx_msg_p->flags.dma_type ==
10476929Smisaki 			    USE_DMA) {
10483859Sml29623 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
10496929Smisaki 				    "==> nxge_txdma_reclaim: "
10506929Smisaki 				    "USE DMA"));
10513859Sml29623 				if (rc = ddi_dma_unbind_handle
10526929Smisaki 				    (tx_msg_p->dma_handle)) {
10533859Sml29623 					cmn_err(CE_WARN, "!nxge_reclaim: "
10546929Smisaki 					    "ddi_dma_unbind_handle "
10556929Smisaki 					    "failed. status %d", rc);
10563859Sml29623 				}
10573859Sml29623 			}
10583859Sml29623 			NXGE_DEBUG_MSG((nxgep, TX_CTL,
10596929Smisaki 			    "==> nxge_txdma_reclaim: count packets"));
10603859Sml29623 			/*
10613859Sml29623 			 * count a chained packet only once.
10623859Sml29623 			 */
10633859Sml29623 			if (tx_msg_p->tx_message != NULL) {
10648275SEric Cheng 				freemsg(tx_msg_p->tx_message);
10658275SEric Cheng 				tx_msg_p->tx_message = NULL;
10663859Sml29623 			}
10673859Sml29623 
10683859Sml29623 			tx_msg_p->flags.dma_type = USE_NONE;
10693859Sml29623 			tx_rd_index = tx_ring_p->rd_index;
10703859Sml29623 			tx_rd_index = (tx_rd_index + 1) &
10716929Smisaki 			    tx_ring_p->tx_wrap_mask;
10723859Sml29623 			tx_ring_p->rd_index = tx_rd_index;
10733859Sml29623 			tx_ring_p->descs_pending--;
10743859Sml29623 			tx_desc_p = &tx_desc_ring_vp[tx_rd_index];
10753859Sml29623 			tx_msg_p = &tx_msg_ring[tx_rd_index];
10763859Sml29623 		}
10773859Sml29623 
1078*8948SMichael.Speer@Sun.COM 		status = (nmblks <= ((int)tx_ring_p->tx_ring_size -
1079*8948SMichael.Speer@Sun.COM 		    (int)tx_ring_p->descs_pending - TX_FULL_MARK));
10803859Sml29623 		if (status) {
10813859Sml29623 			cas32((uint32_t *)&tx_ring_p->queueing, 1, 0);
10823859Sml29623 		}
10833859Sml29623 	} else {
1084*8948SMichael.Speer@Sun.COM 		status = (nmblks <= ((int)tx_ring_p->tx_ring_size -
1085*8948SMichael.Speer@Sun.COM 		    (int)tx_ring_p->descs_pending - TX_FULL_MARK));
10863859Sml29623 	}
10873859Sml29623 
10883859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
10896929Smisaki 	    "<== nxge_txdma_reclaim status = 0x%08x", status));
10903859Sml29623 
10913859Sml29623 	return (status);
10923859Sml29623 }
10933859Sml29623 
10946495Sspeer /*
10956495Sspeer  * nxge_tx_intr
10966495Sspeer  *
10976495Sspeer  *	Process a TDC interrupt
10986495Sspeer  *
10996495Sspeer  * Arguments:
11006495Sspeer  * 	arg1	A Logical Device state Vector (LSV) data structure.
11016495Sspeer  * 	arg2	nxge_t *
11026495Sspeer  *
11036495Sspeer  * Notes:
11046495Sspeer  *
11056495Sspeer  * NPI/NXGE function calls:
11066495Sspeer  *	npi_txdma_control_status()
11076495Sspeer  *	npi_intr_ldg_mgmt_set()
11086495Sspeer  *
11096495Sspeer  *	nxge_tx_err_evnts()
11106495Sspeer  *	nxge_txdma_reclaim()
11116495Sspeer  *
11126495Sspeer  * Registers accessed:
11136495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
11146495Sspeer  *	PIO_LDSV
11156495Sspeer  *
11166495Sspeer  * Context:
11176495Sspeer  *	Any domain
11186495Sspeer  */
11193859Sml29623 uint_t
11203859Sml29623 nxge_tx_intr(void *arg1, void *arg2)
11213859Sml29623 {
11223859Sml29623 	p_nxge_ldv_t		ldvp = (p_nxge_ldv_t)arg1;
11233859Sml29623 	p_nxge_t		nxgep = (p_nxge_t)arg2;
11243859Sml29623 	p_nxge_ldg_t		ldgp;
11253859Sml29623 	uint8_t			channel;
11263859Sml29623 	uint32_t		vindex;
11273859Sml29623 	npi_handle_t		handle;
11283859Sml29623 	tx_cs_t			cs;
11293859Sml29623 	p_tx_ring_t 		*tx_rings;
11303859Sml29623 	p_tx_ring_t 		tx_ring_p;
11313859Sml29623 	npi_status_t		rs = NPI_SUCCESS;
11323859Sml29623 	uint_t 			serviced = DDI_INTR_UNCLAIMED;
11333859Sml29623 	nxge_status_t 		status = NXGE_OK;
11343859Sml29623 
11353859Sml29623 	if (ldvp == NULL) {
11363859Sml29623 		NXGE_DEBUG_MSG((NULL, INT_CTL,
11376929Smisaki 		    "<== nxge_tx_intr: nxgep $%p ldvp $%p",
11386929Smisaki 		    nxgep, ldvp));
11393859Sml29623 		return (DDI_INTR_UNCLAIMED);
11403859Sml29623 	}
11413859Sml29623 
11423859Sml29623 	if (arg2 == NULL || (void *)ldvp->nxgep != arg2) {
11433859Sml29623 		nxgep = ldvp->nxgep;
11443859Sml29623 	}
11453859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
11466929Smisaki 	    "==> nxge_tx_intr: nxgep(arg2) $%p ldvp(arg1) $%p",
11476929Smisaki 	    nxgep, ldvp));
11486713Sspeer 
11496713Sspeer 	if ((!(nxgep->drv_state & STATE_HW_INITIALIZED)) ||
11506713Sspeer 	    (nxgep->nxge_mac_state != NXGE_MAC_STARTED)) {
11516713Sspeer 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
11526713Sspeer 		    "<== nxge_tx_intr: interface not started or intialized"));
11536713Sspeer 		return (DDI_INTR_CLAIMED);
11546713Sspeer 	}
11556713Sspeer 
11563859Sml29623 	/*
11573859Sml29623 	 * This interrupt handler is for a specific
11583859Sml29623 	 * transmit dma channel.
11593859Sml29623 	 */
11603859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
11613859Sml29623 	/* Get the control and status for this channel. */
11623859Sml29623 	channel = ldvp->channel;
11633859Sml29623 	ldgp = ldvp->ldgp;
11643859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
11656929Smisaki 	    "==> nxge_tx_intr: nxgep $%p ldvp (ldvp) $%p "
11666929Smisaki 	    "channel %d",
11676929Smisaki 	    nxgep, ldvp, channel));
11683859Sml29623 
11693859Sml29623 	rs = npi_txdma_control_status(handle, OP_GET, channel, &cs);
11703859Sml29623 	vindex = ldvp->vdma_index;
11713859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL,
11726929Smisaki 	    "==> nxge_tx_intr:channel %d ring index %d status 0x%08x",
11736929Smisaki 	    channel, vindex, rs));
11743859Sml29623 	if (!rs && cs.bits.ldw.mk) {
11753859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
11766929Smisaki 		    "==> nxge_tx_intr:channel %d ring index %d "
11776929Smisaki 		    "status 0x%08x (mk bit set)",
11786929Smisaki 		    channel, vindex, rs));
11793859Sml29623 		tx_rings = nxgep->tx_rings->rings;
11803859Sml29623 		tx_ring_p = tx_rings[vindex];
11813859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
11826929Smisaki 		    "==> nxge_tx_intr:channel %d ring index %d "
11836929Smisaki 		    "status 0x%08x (mk bit set, calling reclaim)",
11846929Smisaki 		    channel, vindex, rs));
11853859Sml29623 
11868275SEric Cheng 		nxge_tx_ring_task((void *)tx_ring_p);
11873859Sml29623 	}
11883859Sml29623 
11893859Sml29623 	/*
11903859Sml29623 	 * Process other transmit control and status.
11913859Sml29623 	 * Check the ldv state.
11923859Sml29623 	 */
11933859Sml29623 	status = nxge_tx_err_evnts(nxgep, ldvp->vdma_index, ldvp, cs);
11943859Sml29623 	/*
11953859Sml29623 	 * Rearm this logical group if this is a single device
11963859Sml29623 	 * group.
11973859Sml29623 	 */
11983859Sml29623 	if (ldgp->nldvs == 1) {
11993859Sml29623 		NXGE_DEBUG_MSG((nxgep, INT_CTL,
12006929Smisaki 		    "==> nxge_tx_intr: rearm"));
12013859Sml29623 		if (status == NXGE_OK) {
12026495Sspeer 			if (isLDOMguest(nxgep)) {
12036495Sspeer 				nxge_hio_ldgimgn(nxgep, ldgp);
12046495Sspeer 			} else {
12056495Sspeer 				(void) npi_intr_ldg_mgmt_set(handle, ldgp->ldg,
12066495Sspeer 				    B_TRUE, ldgp->ldg_timer);
12076495Sspeer 			}
12083859Sml29623 		}
12093859Sml29623 	}
12103859Sml29623 
12113859Sml29623 	NXGE_DEBUG_MSG((nxgep, INT_CTL, "<== nxge_tx_intr"));
12123859Sml29623 	serviced = DDI_INTR_CLAIMED;
12133859Sml29623 	return (serviced);
12143859Sml29623 }
12153859Sml29623 
12163859Sml29623 void
12176495Sspeer nxge_txdma_stop(p_nxge_t nxgep)	/* Dead */
12183859Sml29623 {
12193859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_stop"));
12203859Sml29623 
12213859Sml29623 	(void) nxge_link_monitor(nxgep, LINK_MONITOR_STOP);
12223859Sml29623 
12233859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_stop"));
12243859Sml29623 }
12253859Sml29623 
12263859Sml29623 void
12276495Sspeer nxge_txdma_stop_start(p_nxge_t nxgep) /* Dead */
12283859Sml29623 {
12293859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_stop_start"));
12303859Sml29623 
12313859Sml29623 	(void) nxge_txdma_stop(nxgep);
12323859Sml29623 
12333859Sml29623 	(void) nxge_fixup_txdma_rings(nxgep);
12343859Sml29623 	(void) nxge_txdma_hw_mode(nxgep, NXGE_DMA_START);
12353859Sml29623 	(void) nxge_tx_mac_enable(nxgep);
12363859Sml29623 	(void) nxge_txdma_hw_kick(nxgep);
12373859Sml29623 
12383859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_stop_start"));
12393859Sml29623 }
12403859Sml29623 
12416495Sspeer npi_status_t
12426495Sspeer nxge_txdma_channel_disable(
12436495Sspeer 	nxge_t *nxge,
12446495Sspeer 	int channel)
12456495Sspeer {
12466495Sspeer 	npi_handle_t	handle = NXGE_DEV_NPI_HANDLE(nxge);
12476495Sspeer 	npi_status_t	rs;
12486495Sspeer 	tdmc_intr_dbg_t	intr_dbg;
12496495Sspeer 
12506495Sspeer 	/*
12516495Sspeer 	 * Stop the dma channel and wait for the stop-done.
12526495Sspeer 	 * If the stop-done bit is not present, then force
12536495Sspeer 	 * an error so TXC will stop.
12546495Sspeer 	 * All channels bound to this port need to be stopped
12556495Sspeer 	 * and reset after injecting an interrupt error.
12566495Sspeer 	 */
12576495Sspeer 	rs = npi_txdma_channel_disable(handle, channel);
12586495Sspeer 	NXGE_DEBUG_MSG((nxge, MEM3_CTL,
12596929Smisaki 	    "==> nxge_txdma_channel_disable(%d) "
12606929Smisaki 	    "rs 0x%x", channel, rs));
12616495Sspeer 	if (rs != NPI_SUCCESS) {
12626495Sspeer 		/* Inject any error */
12636495Sspeer 		intr_dbg.value = 0;
12646495Sspeer 		intr_dbg.bits.ldw.nack_pref = 1;
12656495Sspeer 		NXGE_DEBUG_MSG((nxge, MEM3_CTL,
12666929Smisaki 		    "==> nxge_txdma_hw_mode: "
12676929Smisaki 		    "channel %d (stop failed 0x%x) "
12686929Smisaki 		    "(inject err)", rs, channel));
12696495Sspeer 		(void) npi_txdma_inj_int_error_set(
12706929Smisaki 		    handle, channel, &intr_dbg);
12716495Sspeer 		rs = npi_txdma_channel_disable(handle, channel);
12726495Sspeer 		NXGE_DEBUG_MSG((nxge, MEM3_CTL,
12736929Smisaki 		    "==> nxge_txdma_hw_mode: "
12746929Smisaki 		    "channel %d (stop again 0x%x) "
12756929Smisaki 		    "(after inject err)",
12766929Smisaki 		    rs, channel));
12776495Sspeer 	}
12786495Sspeer 
12796495Sspeer 	return (rs);
12806495Sspeer }
12816495Sspeer 
12826495Sspeer /*
12836495Sspeer  * nxge_txdma_hw_mode
12846495Sspeer  *
12856495Sspeer  *	Toggle all TDCs on (enable) or off (disable).
12866495Sspeer  *
12876495Sspeer  * Arguments:
12886495Sspeer  * 	nxgep
12896495Sspeer  * 	enable	Enable or disable a TDC.
12906495Sspeer  *
12916495Sspeer  * Notes:
12926495Sspeer  *
12936495Sspeer  * NPI/NXGE function calls:
12946495Sspeer  *	npi_txdma_channel_enable(TX_CS)
12956495Sspeer  *	npi_txdma_channel_disable(TX_CS)
12966495Sspeer  *	npi_txdma_inj_int_error_set(TDMC_INTR_DBG)
12976495Sspeer  *
12986495Sspeer  * Registers accessed:
12996495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
13006495Sspeer  *	TDMC_INTR_DBG	DMC + 0x40060 Transmit DMA Interrupt Debug
13016495Sspeer  *
13026495Sspeer  * Context:
13036495Sspeer  *	Any domain
13046495Sspeer  */
13053859Sml29623 nxge_status_t
13063859Sml29623 nxge_txdma_hw_mode(p_nxge_t nxgep, boolean_t enable)
13073859Sml29623 {
13086495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
13096495Sspeer 
13106495Sspeer 	npi_handle_t	handle;
13116495Sspeer 	nxge_status_t	status;
13126495Sspeer 	npi_status_t	rs;
13136495Sspeer 	int		tdc;
13143859Sml29623 
13153859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
13166929Smisaki 	    "==> nxge_txdma_hw_mode: enable mode %d", enable));
13173859Sml29623 
13183859Sml29623 	if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) {
13193859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
13206929Smisaki 		    "<== nxge_txdma_mode: not initialized"));
13213859Sml29623 		return (NXGE_ERROR);
13223859Sml29623 	}
13233859Sml29623 
13246495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
13253859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
13266495Sspeer 		    "<== nxge_txdma_hw_mode: NULL ring pointer(s)"));
13273859Sml29623 		return (NXGE_ERROR);
13283859Sml29623 	}
13293859Sml29623 
13306495Sspeer 	/* Enable or disable all of the TDCs owned by us. */
13313859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
13326495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
13336495Sspeer 		if ((1 << tdc) & set->owned.map) {
13346495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
13356495Sspeer 			if (ring) {
13366495Sspeer 				NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
13376495Sspeer 				    "==> nxge_txdma_hw_mode: channel %d", tdc));
13386495Sspeer 				if (enable) {
13396495Sspeer 					rs = npi_txdma_channel_enable
13406495Sspeer 					    (handle, tdc);
13413859Sml29623 					NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
13426495Sspeer 					    "==> nxge_txdma_hw_mode: "
13436495Sspeer 					    "channel %d (enable) rs 0x%x",
13446495Sspeer 					    tdc, rs));
13456495Sspeer 				} else {
13466495Sspeer 					rs = nxge_txdma_channel_disable
13476495Sspeer 					    (nxgep, tdc);
13483859Sml29623 				}
13493859Sml29623 			}
13503859Sml29623 		}
13513859Sml29623 	}
13523859Sml29623 
13533859Sml29623 	status = ((rs == NPI_SUCCESS) ? NXGE_OK : NXGE_ERROR | rs);
13543859Sml29623 
13553859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
13566929Smisaki 	    "<== nxge_txdma_hw_mode: status 0x%x", status));
13573859Sml29623 
13583859Sml29623 	return (status);
13593859Sml29623 }
13603859Sml29623 
13613859Sml29623 void
13623859Sml29623 nxge_txdma_enable_channel(p_nxge_t nxgep, uint16_t channel)
13633859Sml29623 {
13643859Sml29623 	npi_handle_t		handle;
13653859Sml29623 
13663859Sml29623 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
13676929Smisaki 	    "==> nxge_txdma_enable_channel: channel %d", channel));
13683859Sml29623 
13693859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
13703859Sml29623 	/* enable the transmit dma channels */
13713859Sml29623 	(void) npi_txdma_channel_enable(handle, channel);
13723859Sml29623 
13733859Sml29623 	NXGE_DEBUG_MSG((nxgep, DMA_CTL, "<== nxge_txdma_enable_channel"));
13743859Sml29623 }
13753859Sml29623 
13763859Sml29623 void
13773859Sml29623 nxge_txdma_disable_channel(p_nxge_t nxgep, uint16_t channel)
13783859Sml29623 {
13793859Sml29623 	npi_handle_t		handle;
13803859Sml29623 
13813859Sml29623 	NXGE_DEBUG_MSG((nxgep, DMA_CTL,
13826929Smisaki 	    "==> nxge_txdma_disable_channel: channel %d", channel));
13833859Sml29623 
13843859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
13853859Sml29623 	/* stop the transmit dma channels */
13863859Sml29623 	(void) npi_txdma_channel_disable(handle, channel);
13873859Sml29623 
13883859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_disable_channel"));
13893859Sml29623 }
13903859Sml29623 
13916495Sspeer /*
13926495Sspeer  * nxge_txdma_stop_inj_err
13936495Sspeer  *
13946495Sspeer  *	Stop a TDC.  If at first we don't succeed, inject an error.
13956495Sspeer  *
13966495Sspeer  * Arguments:
13976495Sspeer  * 	nxgep
13986495Sspeer  * 	channel		The channel to stop.
13996495Sspeer  *
14006495Sspeer  * Notes:
14016495Sspeer  *
14026495Sspeer  * NPI/NXGE function calls:
14036495Sspeer  *	npi_txdma_channel_disable()
14046495Sspeer  *	npi_txdma_inj_int_error_set()
14056495Sspeer  * #if defined(NXGE_DEBUG)
14066495Sspeer  *	nxge_txdma_regs_dump_channels(nxgep);
14076495Sspeer  * #endif
14086495Sspeer  *
14096495Sspeer  * Registers accessed:
14106495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
14116495Sspeer  *	TDMC_INTR_DBG	DMC + 0x40060 Transmit DMA Interrupt Debug
14126495Sspeer  *
14136495Sspeer  * Context:
14146495Sspeer  *	Any domain
14156495Sspeer  */
14163859Sml29623 int
14173859Sml29623 nxge_txdma_stop_inj_err(p_nxge_t nxgep, int channel)
14183859Sml29623 {
14193859Sml29623 	npi_handle_t		handle;
14203859Sml29623 	tdmc_intr_dbg_t		intr_dbg;
14213859Sml29623 	int			status;
14223859Sml29623 	npi_status_t		rs = NPI_SUCCESS;
14233859Sml29623 
14243859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_stop_inj_err"));
14253859Sml29623 	/*
14263859Sml29623 	 * Stop the dma channel waits for the stop done.
14273859Sml29623 	 * If the stop done bit is not set, then create
14283859Sml29623 	 * an error.
14293859Sml29623 	 */
14303859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
14313859Sml29623 	rs = npi_txdma_channel_disable(handle, channel);
14323859Sml29623 	status = ((rs == NPI_SUCCESS) ? NXGE_OK : NXGE_ERROR | rs);
14333859Sml29623 	if (status == NXGE_OK) {
14343859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
14356929Smisaki 		    "<== nxge_txdma_stop_inj_err (channel %d): "
14366929Smisaki 		    "stopped OK", channel));
14373859Sml29623 		return (status);
14383859Sml29623 	}
14393859Sml29623 
14403859Sml29623 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
14416929Smisaki 	    "==> nxge_txdma_stop_inj_err (channel %d): stop failed (0x%x) "
14426929Smisaki 	    "injecting error", channel, rs));
14433859Sml29623 	/* Inject any error */
14443859Sml29623 	intr_dbg.value = 0;
14453859Sml29623 	intr_dbg.bits.ldw.nack_pref = 1;
14463859Sml29623 	(void) npi_txdma_inj_int_error_set(handle, channel, &intr_dbg);
14473859Sml29623 
14483859Sml29623 	/* Stop done bit will be set as a result of error injection */
14493859Sml29623 	rs = npi_txdma_channel_disable(handle, channel);
14503859Sml29623 	status = ((rs == NPI_SUCCESS) ? NXGE_OK : NXGE_ERROR | rs);
14513859Sml29623 	if (!(rs & NPI_TXDMA_STOP_FAILED)) {
14523859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
14536929Smisaki 		    "<== nxge_txdma_stop_inj_err (channel %d): "
14546929Smisaki 		    "stopped OK ", channel));
14553859Sml29623 		return (status);
14563859Sml29623 	}
14573859Sml29623 
14583859Sml29623 #if	defined(NXGE_DEBUG)
14593859Sml29623 	nxge_txdma_regs_dump_channels(nxgep);
14603859Sml29623 #endif
14613859Sml29623 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
14626929Smisaki 	    "==> nxge_txdma_stop_inj_err (channel): stop failed (0x%x) "
14636929Smisaki 	    " (injected error but still not stopped)", channel, rs));
14643859Sml29623 
14653859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_stop_inj_err"));
14663859Sml29623 	return (status);
14673859Sml29623 }
14683859Sml29623 
14693859Sml29623 /*ARGSUSED*/
14703859Sml29623 void
14713859Sml29623 nxge_fixup_txdma_rings(p_nxge_t nxgep)
14723859Sml29623 {
14736495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
14746495Sspeer 	int tdc;
14753859Sml29623 
14763859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_fixup_txdma_rings"));
14773859Sml29623 
14786495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
14796495Sspeer 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
14806495Sspeer 		    "<== nxge_fixup_txdma_rings: NULL ring pointer(s)"));
14813859Sml29623 		return;
14823859Sml29623 	}
14833859Sml29623 
14846495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
14856495Sspeer 		if ((1 << tdc) & set->owned.map) {
14866495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
14876495Sspeer 			if (ring) {
14886495Sspeer 				NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
14896495Sspeer 				    "==> nxge_fixup_txdma_rings: channel %d",
14906495Sspeer 				    tdc));
14916495Sspeer 				nxge_txdma_fixup_channel(nxgep, ring, tdc);
14926495Sspeer 			}
14936495Sspeer 		}
14943859Sml29623 	}
14953859Sml29623 
14963859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_fixup_txdma_rings"));
14973859Sml29623 }
14983859Sml29623 
14993859Sml29623 /*ARGSUSED*/
15003859Sml29623 void
15013859Sml29623 nxge_txdma_fix_channel(p_nxge_t nxgep, uint16_t channel)
15023859Sml29623 {
15033859Sml29623 	p_tx_ring_t	ring_p;
15043859Sml29623 
15053859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_fix_channel"));
15063859Sml29623 	ring_p = nxge_txdma_get_ring(nxgep, channel);
15073859Sml29623 	if (ring_p == NULL) {
15083859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_fix_channel"));
15093859Sml29623 		return;
15103859Sml29623 	}
15113859Sml29623 
15123859Sml29623 	if (ring_p->tdc != channel) {
15133859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
15146929Smisaki 		    "<== nxge_txdma_fix_channel: channel not matched "
15156929Smisaki 		    "ring tdc %d passed channel",
15166929Smisaki 		    ring_p->tdc, channel));
15173859Sml29623 		return;
15183859Sml29623 	}
15193859Sml29623 
15203859Sml29623 	nxge_txdma_fixup_channel(nxgep, ring_p, channel);
15213859Sml29623 
15223859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_fix_channel"));
15233859Sml29623 }
15243859Sml29623 
15253859Sml29623 /*ARGSUSED*/
15263859Sml29623 void
15273859Sml29623 nxge_txdma_fixup_channel(p_nxge_t nxgep, p_tx_ring_t ring_p, uint16_t channel)
15283859Sml29623 {
15293859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_fixup_channel"));
15303859Sml29623 
15313859Sml29623 	if (ring_p == NULL) {
15323859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
15336929Smisaki 		    "<== nxge_txdma_fixup_channel: NULL ring pointer"));
15343859Sml29623 		return;
15353859Sml29623 	}
15363859Sml29623 
15373859Sml29623 	if (ring_p->tdc != channel) {
15383859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
15396929Smisaki 		    "<== nxge_txdma_fixup_channel: channel not matched "
15406929Smisaki 		    "ring tdc %d passed channel",
15416929Smisaki 		    ring_p->tdc, channel));
15423859Sml29623 		return;
15433859Sml29623 	}
15443859Sml29623 
15453859Sml29623 	MUTEX_ENTER(&ring_p->lock);
15463859Sml29623 	(void) nxge_txdma_reclaim(nxgep, ring_p, 0);
15473859Sml29623 	ring_p->rd_index = 0;
15483859Sml29623 	ring_p->wr_index = 0;
15493859Sml29623 	ring_p->ring_head.value = 0;
15503859Sml29623 	ring_p->ring_kick_tail.value = 0;
15513859Sml29623 	ring_p->descs_pending = 0;
15523859Sml29623 	MUTEX_EXIT(&ring_p->lock);
15533859Sml29623 
15543859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_fixup_channel"));
15553859Sml29623 }
15563859Sml29623 
15573859Sml29623 /*ARGSUSED*/
15583859Sml29623 void
15593859Sml29623 nxge_txdma_hw_kick(p_nxge_t nxgep)
15603859Sml29623 {
15616495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
15626495Sspeer 	int tdc;
15633859Sml29623 
15643859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_hw_kick"));
15653859Sml29623 
15666495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
15673859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
15686495Sspeer 		    "<== nxge_txdma_hw_kick: NULL ring pointer(s)"));
15693859Sml29623 		return;
15703859Sml29623 	}
15713859Sml29623 
15726495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
15736495Sspeer 		if ((1 << tdc) & set->owned.map) {
15746495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
15756495Sspeer 			if (ring) {
15766495Sspeer 				NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
15776495Sspeer 				    "==> nxge_txdma_hw_kick: channel %d", tdc));
15786495Sspeer 				nxge_txdma_hw_kick_channel(nxgep, ring, tdc);
15796495Sspeer 			}
15806495Sspeer 		}
15813859Sml29623 	}
15823859Sml29623 
15833859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_hw_kick"));
15843859Sml29623 }
15853859Sml29623 
15863859Sml29623 /*ARGSUSED*/
15873859Sml29623 void
15883859Sml29623 nxge_txdma_kick_channel(p_nxge_t nxgep, uint16_t channel)
15893859Sml29623 {
15903859Sml29623 	p_tx_ring_t	ring_p;
15913859Sml29623 
15923859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_kick_channel"));
15933859Sml29623 
15943859Sml29623 	ring_p = nxge_txdma_get_ring(nxgep, channel);
15953859Sml29623 	if (ring_p == NULL) {
15963859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
15976929Smisaki 		    " nxge_txdma_kick_channel"));
15983859Sml29623 		return;
15993859Sml29623 	}
16003859Sml29623 
16013859Sml29623 	if (ring_p->tdc != channel) {
16023859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
16036929Smisaki 		    "<== nxge_txdma_kick_channel: channel not matched "
16046929Smisaki 		    "ring tdc %d passed channel",
16056929Smisaki 		    ring_p->tdc, channel));
16063859Sml29623 		return;
16073859Sml29623 	}
16083859Sml29623 
16093859Sml29623 	nxge_txdma_hw_kick_channel(nxgep, ring_p, channel);
16103859Sml29623 
16113859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_kick_channel"));
16123859Sml29623 }
16133859Sml29623 
16143859Sml29623 /*ARGSUSED*/
16153859Sml29623 void
16163859Sml29623 nxge_txdma_hw_kick_channel(p_nxge_t nxgep, p_tx_ring_t ring_p, uint16_t channel)
16173859Sml29623 {
16183859Sml29623 
16193859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_hw_kick_channel"));
16203859Sml29623 
16213859Sml29623 	if (ring_p == NULL) {
16223859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
16236929Smisaki 		    "<== nxge_txdma_hw_kick_channel: NULL ring pointer"));
16243859Sml29623 		return;
16253859Sml29623 	}
16263859Sml29623 
16273859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_hw_kick_channel"));
16283859Sml29623 }
16293859Sml29623 
16306495Sspeer /*
16316495Sspeer  * nxge_check_tx_hang
16326495Sspeer  *
16336495Sspeer  *	Check the state of all TDCs belonging to nxgep.
16346495Sspeer  *
16356495Sspeer  * Arguments:
16366495Sspeer  * 	nxgep
16376495Sspeer  *
16386495Sspeer  * Notes:
16396495Sspeer  *	Called by nxge_hw.c:nxge_check_hw_state().
16406495Sspeer  *
16416495Sspeer  * NPI/NXGE function calls:
16426495Sspeer  *
16436495Sspeer  * Registers accessed:
16446495Sspeer  *
16456495Sspeer  * Context:
16466495Sspeer  *	Any domain
16476495Sspeer  */
16483859Sml29623 /*ARGSUSED*/
16493859Sml29623 void
16503859Sml29623 nxge_check_tx_hang(p_nxge_t nxgep)
16513859Sml29623 {
16523859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_check_tx_hang"));
16533859Sml29623 
16546713Sspeer 	if ((!(nxgep->drv_state & STATE_HW_INITIALIZED)) ||
16556713Sspeer 	    (nxgep->nxge_mac_state != NXGE_MAC_STARTED)) {
16566713Sspeer 		goto nxge_check_tx_hang_exit;
16576713Sspeer 	}
16586713Sspeer 
16593859Sml29623 	/*
16603859Sml29623 	 * Needs inputs from hardware for regs:
16613859Sml29623 	 *	head index had not moved since last timeout.
16623859Sml29623 	 *	packets not transmitted or stuffed registers.
16633859Sml29623 	 */
16643859Sml29623 	if (nxge_txdma_hung(nxgep)) {
16653859Sml29623 		nxge_fixup_hung_txdma_rings(nxgep);
16663859Sml29623 	}
16676713Sspeer 
16686713Sspeer nxge_check_tx_hang_exit:
16693859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_check_tx_hang"));
16703859Sml29623 }
16713859Sml29623 
16726495Sspeer /*
16736495Sspeer  * nxge_txdma_hung
16746495Sspeer  *
16756495Sspeer  *	Reset a TDC.
16766495Sspeer  *
16776495Sspeer  * Arguments:
16786495Sspeer  * 	nxgep
16796495Sspeer  * 	channel		The channel to reset.
16806495Sspeer  * 	reg_data	The current TX_CS.
16816495Sspeer  *
16826495Sspeer  * Notes:
16836495Sspeer  *	Called by nxge_check_tx_hang()
16846495Sspeer  *
16856495Sspeer  * NPI/NXGE function calls:
16866495Sspeer  *	nxge_txdma_channel_hung()
16876495Sspeer  *
16886495Sspeer  * Registers accessed:
16896495Sspeer  *
16906495Sspeer  * Context:
16916495Sspeer  *	Any domain
16926495Sspeer  */
16933859Sml29623 int
16943859Sml29623 nxge_txdma_hung(p_nxge_t nxgep)
16953859Sml29623 {
16967812SMichael.Speer@Sun.COM 	nxge_grp_set_t	*set = &nxgep->tx_set;
16977812SMichael.Speer@Sun.COM 	int		tdc;
16987812SMichael.Speer@Sun.COM 	boolean_t	shared;
16993859Sml29623 
17003859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_hung"));
17016495Sspeer 
17026495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
17033859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
17046495Sspeer 		    "<== nxge_txdma_hung: NULL ring pointer(s)"));
17053859Sml29623 		return (B_FALSE);
17063859Sml29623 	}
17073859Sml29623 
17086495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
17097812SMichael.Speer@Sun.COM 		/*
17107812SMichael.Speer@Sun.COM 		 * Grab the shared state of the TDC.
17117812SMichael.Speer@Sun.COM 		 */
17127812SMichael.Speer@Sun.COM 		if (isLDOMservice(nxgep)) {
17137812SMichael.Speer@Sun.COM 			nxge_hio_data_t *nhd =
17147812SMichael.Speer@Sun.COM 			    (nxge_hio_data_t *)nxgep->nxge_hw_p->hio;
17157812SMichael.Speer@Sun.COM 
17167812SMichael.Speer@Sun.COM 			MUTEX_ENTER(&nhd->lock);
17177812SMichael.Speer@Sun.COM 			shared = nxgep->tdc_is_shared[tdc];
17187812SMichael.Speer@Sun.COM 			MUTEX_EXIT(&nhd->lock);
17197812SMichael.Speer@Sun.COM 		} else {
17207812SMichael.Speer@Sun.COM 			shared = B_FALSE;
17217812SMichael.Speer@Sun.COM 		}
17227812SMichael.Speer@Sun.COM 
17237812SMichael.Speer@Sun.COM 		/*
17247812SMichael.Speer@Sun.COM 		 * Now, process continue to process.
17257812SMichael.Speer@Sun.COM 		 */
17267812SMichael.Speer@Sun.COM 		if (((1 << tdc) & set->owned.map) && !shared) {
17276495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
17286495Sspeer 			if (ring) {
17296495Sspeer 				if (nxge_txdma_channel_hung(nxgep, ring, tdc)) {
17306495Sspeer 					NXGE_DEBUG_MSG((nxgep, TX_CTL,
17316495Sspeer 					    "==> nxge_txdma_hung: TDC %d hung",
17326495Sspeer 					    tdc));
17336495Sspeer 					return (B_TRUE);
17346495Sspeer 				}
17356495Sspeer 			}
17363859Sml29623 		}
17373859Sml29623 	}
17383859Sml29623 
17393859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_hung"));
17403859Sml29623 
17413859Sml29623 	return (B_FALSE);
17423859Sml29623 }
17433859Sml29623 
17446495Sspeer /*
17456495Sspeer  * nxge_txdma_channel_hung
17466495Sspeer  *
17476495Sspeer  *	Reset a TDC.
17486495Sspeer  *
17496495Sspeer  * Arguments:
17506495Sspeer  * 	nxgep
17516495Sspeer  * 	ring		<channel>'s ring.
17526495Sspeer  * 	channel		The channel to reset.
17536495Sspeer  *
17546495Sspeer  * Notes:
17556495Sspeer  *	Called by nxge_txdma.c:nxge_txdma_hung()
17566495Sspeer  *
17576495Sspeer  * NPI/NXGE function calls:
17586495Sspeer  *	npi_txdma_ring_head_get()
17596495Sspeer  *
17606495Sspeer  * Registers accessed:
17616495Sspeer  *	TX_RING_HDL	DMC+0x40010 Transmit Ring Head Low
17626495Sspeer  *
17636495Sspeer  * Context:
17646495Sspeer  *	Any domain
17656495Sspeer  */
17663859Sml29623 int
17673859Sml29623 nxge_txdma_channel_hung(p_nxge_t nxgep, p_tx_ring_t tx_ring_p, uint16_t channel)
17683859Sml29623 {
17693859Sml29623 	uint16_t		head_index, tail_index;
17703859Sml29623 	boolean_t		head_wrap, tail_wrap;
17713859Sml29623 	npi_handle_t		handle;
17723859Sml29623 	tx_ring_hdl_t		tx_head;
17733859Sml29623 	uint_t			tx_rd_index;
17743859Sml29623 
17753859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_channel_hung"));
17763859Sml29623 
17773859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
17783859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
17796929Smisaki 	    "==> nxge_txdma_channel_hung: channel %d", channel));
17803859Sml29623 	MUTEX_ENTER(&tx_ring_p->lock);
17813859Sml29623 	(void) nxge_txdma_reclaim(nxgep, tx_ring_p, 0);
17823859Sml29623 
17833859Sml29623 	tail_index = tx_ring_p->wr_index;
17843859Sml29623 	tail_wrap = tx_ring_p->wr_index_wrap;
17853859Sml29623 	tx_rd_index = tx_ring_p->rd_index;
17863859Sml29623 	MUTEX_EXIT(&tx_ring_p->lock);
17873859Sml29623 
17883859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
17896929Smisaki 	    "==> nxge_txdma_channel_hung: tdc %d tx_rd_index %d "
17906929Smisaki 	    "tail_index %d tail_wrap %d ",
17916929Smisaki 	    channel, tx_rd_index, tail_index, tail_wrap));
17923859Sml29623 	/*
17933859Sml29623 	 * Read the hardware maintained transmit head
17943859Sml29623 	 * and wrap around bit.
17953859Sml29623 	 */
17963859Sml29623 	(void) npi_txdma_ring_head_get(handle, channel, &tx_head);
17973859Sml29623 	head_index =  tx_head.bits.ldw.head;
17983859Sml29623 	head_wrap = tx_head.bits.ldw.wrap;
17993859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
18006929Smisaki 	    "==> nxge_txdma_channel_hung: "
18016929Smisaki 	    "tx_rd_index %d tail %d tail_wrap %d "
18026929Smisaki 	    "head %d wrap %d",
18036929Smisaki 	    tx_rd_index, tail_index, tail_wrap,
18046929Smisaki 	    head_index, head_wrap));
18053859Sml29623 
18063859Sml29623 	if (TXDMA_RING_EMPTY(head_index, head_wrap,
18076929Smisaki 	    tail_index, tail_wrap) &&
18086929Smisaki 	    (head_index == tx_rd_index)) {
18093859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
18106929Smisaki 		    "==> nxge_txdma_channel_hung: EMPTY"));
18113859Sml29623 		return (B_FALSE);
18123859Sml29623 	}
18133859Sml29623 
18143859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
18156929Smisaki 	    "==> nxge_txdma_channel_hung: Checking if ring full"));
18163859Sml29623 	if (TXDMA_RING_FULL(head_index, head_wrap, tail_index,
18176929Smisaki 	    tail_wrap)) {
18183859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
18196929Smisaki 		    "==> nxge_txdma_channel_hung: full"));
18203859Sml29623 		return (B_TRUE);
18213859Sml29623 	}
18223859Sml29623 
18233859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_channel_hung"));
18243859Sml29623 
18253859Sml29623 	return (B_FALSE);
18263859Sml29623 }
18273859Sml29623 
18286495Sspeer /*
18296495Sspeer  * nxge_fixup_hung_txdma_rings
18306495Sspeer  *
18316495Sspeer  *	Disable a TDC.
18326495Sspeer  *
18336495Sspeer  * Arguments:
18346495Sspeer  * 	nxgep
18356495Sspeer  * 	channel		The channel to reset.
18366495Sspeer  * 	reg_data	The current TX_CS.
18376495Sspeer  *
18386495Sspeer  * Notes:
18396495Sspeer  *	Called by nxge_check_tx_hang()
18406495Sspeer  *
18416495Sspeer  * NPI/NXGE function calls:
18426495Sspeer  *	npi_txdma_ring_head_get()
18436495Sspeer  *
18446495Sspeer  * Registers accessed:
18456495Sspeer  *	TX_RING_HDL	DMC+0x40010 Transmit Ring Head Low
18466495Sspeer  *
18476495Sspeer  * Context:
18486495Sspeer  *	Any domain
18496495Sspeer  */
18503859Sml29623 /*ARGSUSED*/
18513859Sml29623 void
18523859Sml29623 nxge_fixup_hung_txdma_rings(p_nxge_t nxgep)
18533859Sml29623 {
18546495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
18556495Sspeer 	int tdc;
18563859Sml29623 
18573859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_fixup_hung_txdma_rings"));
18586495Sspeer 
18596495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
18603859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
18616495Sspeer 		    "<== nxge_fixup_hung_txdma_rings: NULL ring pointer(s)"));
18623859Sml29623 		return;
18633859Sml29623 	}
18643859Sml29623 
18656495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
18666495Sspeer 		if ((1 << tdc) & set->owned.map) {
18676495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
18686495Sspeer 			if (ring) {
18696495Sspeer 				nxge_txdma_fixup_hung_channel(nxgep, ring, tdc);
18706495Sspeer 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
18716495Sspeer 				    "==> nxge_fixup_hung_txdma_rings: TDC %d",
18726495Sspeer 				    tdc));
18736495Sspeer 			}
18746495Sspeer 		}
18753859Sml29623 	}
18763859Sml29623 
18773859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_fixup_hung_txdma_rings"));
18783859Sml29623 }
18793859Sml29623 
18806495Sspeer /*
18816495Sspeer  * nxge_txdma_fixup_hung_channel
18826495Sspeer  *
18836495Sspeer  *	'Fix' a hung TDC.
18846495Sspeer  *
18856495Sspeer  * Arguments:
18866495Sspeer  * 	nxgep
18876495Sspeer  * 	channel		The channel to fix.
18886495Sspeer  *
18896495Sspeer  * Notes:
18906495Sspeer  *	Called by nxge_fixup_hung_txdma_rings()
18916495Sspeer  *
18926495Sspeer  *	1. Reclaim the TDC.
18936495Sspeer  *	2. Disable the TDC.
18946495Sspeer  *
18956495Sspeer  * NPI/NXGE function calls:
18966495Sspeer  *	nxge_txdma_reclaim()
18976495Sspeer  *	npi_txdma_channel_disable(TX_CS)
18986495Sspeer  *	npi_txdma_inj_int_error_set(TDMC_INTR_DBG)
18996495Sspeer  *
19006495Sspeer  * Registers accessed:
19016495Sspeer  *	TX_CS		DMC+0x40028 Transmit Control And Status
19026495Sspeer  *	TDMC_INTR_DBG	DMC + 0x40060 Transmit DMA Interrupt Debug
19036495Sspeer  *
19046495Sspeer  * Context:
19056495Sspeer  *	Any domain
19066495Sspeer  */
19073859Sml29623 /*ARGSUSED*/
19083859Sml29623 void
19093859Sml29623 nxge_txdma_fix_hung_channel(p_nxge_t nxgep, uint16_t channel)
19103859Sml29623 {
19113859Sml29623 	p_tx_ring_t	ring_p;
19123859Sml29623 
19133859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_fix_hung_channel"));
19143859Sml29623 	ring_p = nxge_txdma_get_ring(nxgep, channel);
19153859Sml29623 	if (ring_p == NULL) {
19163859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
19176929Smisaki 		    "<== nxge_txdma_fix_hung_channel"));
19183859Sml29623 		return;
19193859Sml29623 	}
19203859Sml29623 
19213859Sml29623 	if (ring_p->tdc != channel) {
19223859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
19236929Smisaki 		    "<== nxge_txdma_fix_hung_channel: channel not matched "
19246929Smisaki 		    "ring tdc %d passed channel",
19256929Smisaki 		    ring_p->tdc, channel));
19263859Sml29623 		return;
19273859Sml29623 	}
19283859Sml29623 
19293859Sml29623 	nxge_txdma_fixup_channel(nxgep, ring_p, channel);
19303859Sml29623 
19313859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_fix_hung_channel"));
19323859Sml29623 }
19333859Sml29623 
19343859Sml29623 /*ARGSUSED*/
19353859Sml29623 void
19363859Sml29623 nxge_txdma_fixup_hung_channel(p_nxge_t nxgep, p_tx_ring_t ring_p,
19373859Sml29623 	uint16_t channel)
19383859Sml29623 {
19393859Sml29623 	npi_handle_t		handle;
19403859Sml29623 	tdmc_intr_dbg_t		intr_dbg;
19413859Sml29623 	int			status = NXGE_OK;
19423859Sml29623 
19433859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_fixup_hung_channel"));
19443859Sml29623 
19453859Sml29623 	if (ring_p == NULL) {
19463859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
19476929Smisaki 		    "<== nxge_txdma_fixup_channel: NULL ring pointer"));
19483859Sml29623 		return;
19493859Sml29623 	}
19503859Sml29623 
19513859Sml29623 	if (ring_p->tdc != channel) {
19523859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
19536929Smisaki 		    "<== nxge_txdma_fixup_hung_channel: channel "
19546929Smisaki 		    "not matched "
19556929Smisaki 		    "ring tdc %d passed channel",
19566929Smisaki 		    ring_p->tdc, channel));
19573859Sml29623 		return;
19583859Sml29623 	}
19593859Sml29623 
19603859Sml29623 	/* Reclaim descriptors */
19613859Sml29623 	MUTEX_ENTER(&ring_p->lock);
19623859Sml29623 	(void) nxge_txdma_reclaim(nxgep, ring_p, 0);
19633859Sml29623 	MUTEX_EXIT(&ring_p->lock);
19643859Sml29623 
19653859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
19663859Sml29623 	/*
19673859Sml29623 	 * Stop the dma channel waits for the stop done.
19683859Sml29623 	 * If the stop done bit is not set, then force
19693859Sml29623 	 * an error.
19703859Sml29623 	 */
19713859Sml29623 	status = npi_txdma_channel_disable(handle, channel);
19723859Sml29623 	if (!(status & NPI_TXDMA_STOP_FAILED)) {
19733859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
19746929Smisaki 		    "<== nxge_txdma_fixup_hung_channel: stopped OK "
19756929Smisaki 		    "ring tdc %d passed channel %d",
19766929Smisaki 		    ring_p->tdc, channel));
19773859Sml29623 		return;
19783859Sml29623 	}
19793859Sml29623 
19803859Sml29623 	/* Inject any error */
19813859Sml29623 	intr_dbg.value = 0;
19823859Sml29623 	intr_dbg.bits.ldw.nack_pref = 1;
19833859Sml29623 	(void) npi_txdma_inj_int_error_set(handle, channel, &intr_dbg);
19843859Sml29623 
19853859Sml29623 	/* Stop done bit will be set as a result of error injection */
19863859Sml29623 	status = npi_txdma_channel_disable(handle, channel);
19873859Sml29623 	if (!(status & NPI_TXDMA_STOP_FAILED)) {
19883859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
19896929Smisaki 		    "<== nxge_txdma_fixup_hung_channel: stopped again"
19906929Smisaki 		    "ring tdc %d passed channel",
19916929Smisaki 		    ring_p->tdc, channel));
19923859Sml29623 		return;
19933859Sml29623 	}
19943859Sml29623 
19953859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
19966929Smisaki 	    "<== nxge_txdma_fixup_hung_channel: stop done still not set!! "
19976929Smisaki 	    "ring tdc %d passed channel",
19986929Smisaki 	    ring_p->tdc, channel));
19993859Sml29623 
20003859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_fixup_hung_channel"));
20013859Sml29623 }
20023859Sml29623 
20033859Sml29623 /*ARGSUSED*/
20043859Sml29623 void
20053859Sml29623 nxge_reclaim_rings(p_nxge_t nxgep)
20063859Sml29623 {
20076495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
20086495Sspeer 	int tdc;
20096495Sspeer 
20106495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_reclaim_rings"));
20116495Sspeer 
20126495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
20133859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
20146495Sspeer 		    "<== nxge_fixup_hung_txdma_rings: NULL ring pointer(s)"));
20153859Sml29623 		return;
20163859Sml29623 	}
20173859Sml29623 
20186495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
20196495Sspeer 		if ((1 << tdc) & set->owned.map) {
20206495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
20216495Sspeer 			if (ring) {
20226495Sspeer 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
20236495Sspeer 				    "==> nxge_reclaim_rings: TDC %d", tdc));
20246495Sspeer 				MUTEX_ENTER(&ring->lock);
20258275SEric Cheng 				(void) nxge_txdma_reclaim(nxgep, ring, 0);
20266495Sspeer 				MUTEX_EXIT(&ring->lock);
20276495Sspeer 			}
20286495Sspeer 		}
20293859Sml29623 	}
20303859Sml29623 
20313859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_reclaim_rings"));
20323859Sml29623 }
20333859Sml29623 
20343859Sml29623 void
20353859Sml29623 nxge_txdma_regs_dump_channels(p_nxge_t nxgep)
20363859Sml29623 {
20376495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
20386495Sspeer 	npi_handle_t handle;
20396495Sspeer 	int tdc;
20406495Sspeer 
20416495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_regs_dump_channels"));
20423859Sml29623 
20433859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
20446495Sspeer 
20456495Sspeer 	if (!isLDOMguest(nxgep)) {
20466495Sspeer 		(void) npi_txdma_dump_fzc_regs(handle);
20476495Sspeer 
20486495Sspeer 		/* Dump TXC registers. */
20496495Sspeer 		(void) npi_txc_dump_fzc_regs(handle);
20506495Sspeer 		(void) npi_txc_dump_port_fzc_regs(handle, nxgep->function_num);
20513859Sml29623 	}
20523859Sml29623 
20536495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
20543859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
20556495Sspeer 		    "<== nxge_fixup_hung_txdma_rings: NULL ring pointer(s)"));
20563859Sml29623 		return;
20573859Sml29623 	}
20583859Sml29623 
20596495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
20606495Sspeer 		if ((1 << tdc) & set->owned.map) {
20616495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
20626495Sspeer 			if (ring) {
20636495Sspeer 				NXGE_DEBUG_MSG((nxgep, TX_CTL,
20646495Sspeer 				    "==> nxge_txdma_regs_dump_channels: "
20656495Sspeer 				    "TDC %d", tdc));
20666495Sspeer 				(void) npi_txdma_dump_tdc_regs(handle, tdc);
20676495Sspeer 
20686495Sspeer 				/* Dump TXC registers, if able to. */
20696495Sspeer 				if (!isLDOMguest(nxgep)) {
20706495Sspeer 					NXGE_DEBUG_MSG((nxgep, TX_CTL,
20716495Sspeer 					    "==> nxge_txdma_regs_dump_channels:"
20726495Sspeer 					    " FZC TDC %d", tdc));
20736495Sspeer 					(void) npi_txc_dump_tdc_fzc_regs
20746495Sspeer 					    (handle, tdc);
20756495Sspeer 				}
20766495Sspeer 				nxge_txdma_regs_dump(nxgep, tdc);
20776495Sspeer 			}
20786495Sspeer 		}
20793859Sml29623 	}
20803859Sml29623 
20813859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_regs_dump"));
20823859Sml29623 }
20833859Sml29623 
20843859Sml29623 void
20853859Sml29623 nxge_txdma_regs_dump(p_nxge_t nxgep, int channel)
20863859Sml29623 {
20873859Sml29623 	npi_handle_t		handle;
20883859Sml29623 	tx_ring_hdl_t 		hdl;
20893859Sml29623 	tx_ring_kick_t 		kick;
20903859Sml29623 	tx_cs_t 		cs;
20913859Sml29623 	txc_control_t		control;
20923859Sml29623 	uint32_t		bitmap = 0;
20933859Sml29623 	uint32_t		burst = 0;
20943859Sml29623 	uint32_t		bytes = 0;
20953859Sml29623 	dma_log_page_t		cfg;
20963859Sml29623 
20973859Sml29623 	printf("\n\tfunc # %d tdc %d ",
20986929Smisaki 	    nxgep->function_num, channel);
20993859Sml29623 	cfg.page_num = 0;
21003859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
21013859Sml29623 	(void) npi_txdma_log_page_get(handle, channel, &cfg);
21023859Sml29623 	printf("\n\tlog page func %d valid page 0 %d",
21036929Smisaki 	    cfg.func_num, cfg.valid);
21043859Sml29623 	cfg.page_num = 1;
21053859Sml29623 	(void) npi_txdma_log_page_get(handle, channel, &cfg);
21063859Sml29623 	printf("\n\tlog page func %d valid page 1 %d",
21076929Smisaki 	    cfg.func_num, cfg.valid);
21083859Sml29623 
21093859Sml29623 	(void) npi_txdma_ring_head_get(handle, channel, &hdl);
21103859Sml29623 	(void) npi_txdma_desc_kick_reg_get(handle, channel, &kick);
21113859Sml29623 	printf("\n\thead value is 0x%0llx",
21126929Smisaki 	    (long long)hdl.value);
21133859Sml29623 	printf("\n\thead index %d", hdl.bits.ldw.head);
21143859Sml29623 	printf("\n\tkick value is 0x%0llx",
21156929Smisaki 	    (long long)kick.value);
21163859Sml29623 	printf("\n\ttail index %d\n", kick.bits.ldw.tail);
21173859Sml29623 
21183859Sml29623 	(void) npi_txdma_control_status(handle, OP_GET, channel, &cs);
21193859Sml29623 	printf("\n\tControl statue is 0x%0llx", (long long)cs.value);
21203859Sml29623 	printf("\n\tControl status RST state %d", cs.bits.ldw.rst);
21213859Sml29623 
21223859Sml29623 	(void) npi_txc_control(handle, OP_GET, &control);
21233859Sml29623 	(void) npi_txc_port_dma_list_get(handle, nxgep->function_num, &bitmap);
21243859Sml29623 	(void) npi_txc_dma_max_burst(handle, OP_GET, channel, &burst);
21253859Sml29623 	(void) npi_txc_dma_bytes_transmitted(handle, channel, &bytes);
21263859Sml29623 
21273859Sml29623 	printf("\n\tTXC port control 0x%0llx",
21286929Smisaki 	    (long long)control.value);
21293859Sml29623 	printf("\n\tTXC port bitmap 0x%x", bitmap);
21303859Sml29623 	printf("\n\tTXC max burst %d", burst);
21313859Sml29623 	printf("\n\tTXC bytes xmt %d\n", bytes);
21323859Sml29623 
21333859Sml29623 	{
21343859Sml29623 		ipp_status_t status;
21353859Sml29623 
21363859Sml29623 		(void) npi_ipp_get_status(handle, nxgep->function_num, &status);
21375125Sjoycey #if defined(__i386)
21385125Sjoycey 		printf("\n\tIPP status 0x%llux\n", (uint64_t)status.value);
21395125Sjoycey #else
21403859Sml29623 		printf("\n\tIPP status 0x%lux\n", (uint64_t)status.value);
21415125Sjoycey #endif
21423859Sml29623 	}
21433859Sml29623 }
21443859Sml29623 
21453859Sml29623 /*
21466495Sspeer  * nxge_tdc_hvio_setup
21476495Sspeer  *
21486495Sspeer  *	I'm not exactly sure what this code does.
21496495Sspeer  *
21506495Sspeer  * Arguments:
21516495Sspeer  * 	nxgep
21526495Sspeer  * 	channel	The channel to map.
21536495Sspeer  *
21546495Sspeer  * Notes:
21556495Sspeer  *
21566495Sspeer  * NPI/NXGE function calls:
21576495Sspeer  *	na
21586495Sspeer  *
21596495Sspeer  * Context:
21606495Sspeer  *	Service domain?
21613859Sml29623  */
21626495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND)
21636495Sspeer static void
21646495Sspeer nxge_tdc_hvio_setup(
21656495Sspeer 	nxge_t *nxgep, int channel)
21663859Sml29623 {
21676495Sspeer 	nxge_dma_common_t	*data;
21686495Sspeer 	nxge_dma_common_t	*control;
21696495Sspeer 	tx_ring_t 		*ring;
21706495Sspeer 
21716495Sspeer 	ring = nxgep->tx_rings->rings[channel];
21726495Sspeer 	data = nxgep->tx_buf_pool_p->dma_buf_pool_p[channel];
21736495Sspeer 
21746495Sspeer 	ring->hv_set = B_FALSE;
21756495Sspeer 
21766495Sspeer 	ring->hv_tx_buf_base_ioaddr_pp =
21776495Sspeer 	    (uint64_t)data->orig_ioaddr_pp;
21786495Sspeer 	ring->hv_tx_buf_ioaddr_size =
21796495Sspeer 	    (uint64_t)data->orig_alength;
21806495Sspeer 
21816495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_map_txdma_channel: "
21826929Smisaki 	    "hv data buf base io $%p size 0x%llx (%d) buf base io $%p "
21836929Smisaki 	    "orig vatopa base io $%p orig_len 0x%llx (%d)",
21846929Smisaki 	    ring->hv_tx_buf_base_ioaddr_pp,
21856929Smisaki 	    ring->hv_tx_buf_ioaddr_size, ring->hv_tx_buf_ioaddr_size,
21866929Smisaki 	    data->ioaddr_pp, data->orig_vatopa,
21876929Smisaki 	    data->orig_alength, data->orig_alength));
21886495Sspeer 
21896495Sspeer 	control = nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel];
21906495Sspeer 
21916495Sspeer 	ring->hv_tx_cntl_base_ioaddr_pp =
21926495Sspeer 	    (uint64_t)control->orig_ioaddr_pp;
21936495Sspeer 	ring->hv_tx_cntl_ioaddr_size =
21946495Sspeer 	    (uint64_t)control->orig_alength;
21956495Sspeer 
21966495Sspeer 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_map_txdma_channel: "
21976929Smisaki 	    "hv cntl base io $%p orig ioaddr_pp ($%p) "
21986929Smisaki 	    "orig vatopa ($%p) size 0x%llx (%d 0x%x)",
21996929Smisaki 	    ring->hv_tx_cntl_base_ioaddr_pp,
22006929Smisaki 	    control->orig_ioaddr_pp, control->orig_vatopa,
22016929Smisaki 	    ring->hv_tx_cntl_ioaddr_size,
22026929Smisaki 	    control->orig_alength, control->orig_alength));
22036495Sspeer }
22043859Sml29623 #endif
22053859Sml29623 
22066495Sspeer static nxge_status_t
22076495Sspeer nxge_map_txdma(p_nxge_t nxgep, int channel)
22086495Sspeer {
22096495Sspeer 	nxge_dma_common_t	**pData;
22106495Sspeer 	nxge_dma_common_t	**pControl;
22116495Sspeer 	tx_ring_t 		**pRing, *ring;
22126495Sspeer 	tx_mbox_t		**mailbox;
22136495Sspeer 	uint32_t		num_chunks;
22146495Sspeer 
22156495Sspeer 	nxge_status_t		status = NXGE_OK;
22166495Sspeer 
22176495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL, "==> nxge_map_txdma"));
22186495Sspeer 
22196495Sspeer 	if (!nxgep->tx_cntl_pool_p->buf_allocated) {
22206495Sspeer 		if (nxge_alloc_tx_mem_pool(nxgep) != NXGE_OK) {
22216495Sspeer 			NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
22226495Sspeer 			    "<== nxge_map_txdma: buf not allocated"));
22236495Sspeer 			return (NXGE_ERROR);
22246495Sspeer 		}
22253859Sml29623 	}
22263859Sml29623 
22276495Sspeer 	if (nxge_alloc_txb(nxgep, channel) != NXGE_OK)
22286495Sspeer 		return (NXGE_ERROR);
22296495Sspeer 
22306495Sspeer 	num_chunks = nxgep->tx_buf_pool_p->num_chunks[channel];
22316495Sspeer 	pData = &nxgep->tx_buf_pool_p->dma_buf_pool_p[channel];
22326495Sspeer 	pControl = &nxgep->tx_cntl_pool_p->dma_buf_pool_p[channel];
22336495Sspeer 	pRing = &nxgep->tx_rings->rings[channel];
22346495Sspeer 	mailbox = &nxgep->tx_mbox_areas_p->txmbox_areas_p[channel];
22356495Sspeer 
22366495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL, "==> nxge_map_txdma: "
22376929Smisaki 	    "tx_rings $%p tx_desc_rings $%p",
22386929Smisaki 	    nxgep->tx_rings, nxgep->tx_rings->rings));
22393859Sml29623 
22403859Sml29623 	/*
22416495Sspeer 	 * Map descriptors from the buffer pools for <channel>.
22426495Sspeer 	 */
22436495Sspeer 
22446495Sspeer 	/*
22456495Sspeer 	 * Set up and prepare buffer blocks, descriptors
22466495Sspeer 	 * and mailbox.
22473859Sml29623 	 */
22486495Sspeer 	status = nxge_map_txdma_channel(nxgep, channel,
22496495Sspeer 	    pData, pRing, num_chunks, pControl, mailbox);
22506495Sspeer 	if (status != NXGE_OK) {
22516495Sspeer 		NXGE_ERROR_MSG((nxgep, MEM3_CTL,
22526929Smisaki 		    "==> nxge_map_txdma(%d): nxge_map_txdma_channel() "
22536929Smisaki 		    "returned 0x%x",
22546929Smisaki 		    nxgep, channel, status));
22556495Sspeer 		return (status);
22566495Sspeer 	}
22576495Sspeer 
22586495Sspeer 	ring = *pRing;
22596495Sspeer 
22606495Sspeer 	ring->index = (uint16_t)channel;
22616495Sspeer 	ring->tdc_stats = &nxgep->statsp->tdc_stats[channel];
22626495Sspeer 
22636495Sspeer #if defined(sun4v) && defined(NIU_LP_WORKAROUND)
22646495Sspeer 	if (isLDOMguest(nxgep)) {
22656495Sspeer 		(void) nxge_tdc_lp_conf(nxgep, channel);
22666495Sspeer 	} else {
22676495Sspeer 		nxge_tdc_hvio_setup(nxgep, channel);
22686495Sspeer 	}
22693859Sml29623 #endif
22706495Sspeer 
22716495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL, "==> nxge_map_txdma: "
22726495Sspeer 	    "(status 0x%x channel %d)", status, channel));
22733859Sml29623 
22743859Sml29623 	return (status);
22753859Sml29623 }
22763859Sml29623 
22773859Sml29623 static nxge_status_t
22783859Sml29623 nxge_map_txdma_channel(p_nxge_t nxgep, uint16_t channel,
22793859Sml29623 	p_nxge_dma_common_t *dma_buf_p,
22803859Sml29623 	p_tx_ring_t *tx_desc_p,
22813859Sml29623 	uint32_t num_chunks,
22823859Sml29623 	p_nxge_dma_common_t *dma_cntl_p,
22833859Sml29623 	p_tx_mbox_t *tx_mbox_p)
22843859Sml29623 {
22853859Sml29623 	int	status = NXGE_OK;
22863859Sml29623 
22873859Sml29623 	/*
22883859Sml29623 	 * Set up and prepare buffer blocks, descriptors
22893859Sml29623 	 * and mailbox.
22903859Sml29623 	 */
22916495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL,
22926929Smisaki 	    "==> nxge_map_txdma_channel (channel %d)", channel));
22933859Sml29623 	/*
22943859Sml29623 	 * Transmit buffer blocks
22953859Sml29623 	 */
22963859Sml29623 	status = nxge_map_txdma_channel_buf_ring(nxgep, channel,
22976929Smisaki 	    dma_buf_p, tx_desc_p, num_chunks);
22983859Sml29623 	if (status != NXGE_OK) {
22993859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
23006929Smisaki 		    "==> nxge_map_txdma_channel (channel %d): "
23016929Smisaki 		    "map buffer failed 0x%x", channel, status));
23023859Sml29623 		goto nxge_map_txdma_channel_exit;
23033859Sml29623 	}
23043859Sml29623 
23053859Sml29623 	/*
23063859Sml29623 	 * Transmit block ring, and mailbox.
23073859Sml29623 	 */
23083859Sml29623 	nxge_map_txdma_channel_cfg_ring(nxgep, channel, dma_cntl_p, *tx_desc_p,
23096929Smisaki 	    tx_mbox_p);
23103859Sml29623 
23113859Sml29623 	goto nxge_map_txdma_channel_exit;
23123859Sml29623 
23133859Sml29623 nxge_map_txdma_channel_fail1:
23146495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL,
23156929Smisaki 	    "==> nxge_map_txdma_channel: unmap buf"
23166929Smisaki 	    "(status 0x%x channel %d)",
23176929Smisaki 	    status, channel));
23183859Sml29623 	nxge_unmap_txdma_channel_buf_ring(nxgep, *tx_desc_p);
23193859Sml29623 
23203859Sml29623 nxge_map_txdma_channel_exit:
23216495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL,
23226929Smisaki 	    "<== nxge_map_txdma_channel: "
23236929Smisaki 	    "(status 0x%x channel %d)",
23246929Smisaki 	    status, channel));
23253859Sml29623 
23263859Sml29623 	return (status);
23273859Sml29623 }
23283859Sml29623 
23293859Sml29623 /*ARGSUSED*/
23303859Sml29623 static void
23316495Sspeer nxge_unmap_txdma_channel(p_nxge_t nxgep, uint16_t channel)
23323859Sml29623 {
23336495Sspeer 	tx_ring_t *ring;
23346495Sspeer 	tx_mbox_t *mailbox;
23356495Sspeer 
23363859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
23376929Smisaki 	    "==> nxge_unmap_txdma_channel (channel %d)", channel));
23383859Sml29623 	/*
23393859Sml29623 	 * unmap tx block ring, and mailbox.
23403859Sml29623 	 */
23416495Sspeer 	ring = nxgep->tx_rings->rings[channel];
23426495Sspeer 	mailbox = nxgep->tx_mbox_areas_p->txmbox_areas_p[channel];
23436495Sspeer 
23446495Sspeer 	(void) nxge_unmap_txdma_channel_cfg_ring(nxgep, ring, mailbox);
23453859Sml29623 
23463859Sml29623 	/* unmap buffer blocks */
23476495Sspeer 	(void) nxge_unmap_txdma_channel_buf_ring(nxgep, ring);
23486495Sspeer 
23496495Sspeer 	nxge_free_txb(nxgep, channel);
23503859Sml29623 
23513859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "<== nxge_unmap_txdma_channel"));
23523859Sml29623 }
23533859Sml29623 
23546495Sspeer /*
23556495Sspeer  * nxge_map_txdma_channel_cfg_ring
23566495Sspeer  *
23576495Sspeer  *	Map a TDC into our kernel space.
23586495Sspeer  *	This function allocates all of the per-channel data structures.
23596495Sspeer  *
23606495Sspeer  * Arguments:
23616495Sspeer  * 	nxgep
23626495Sspeer  * 	dma_channel	The channel to map.
23636495Sspeer  *	dma_cntl_p
23646495Sspeer  *	tx_ring_p	dma_channel's transmit ring
23656495Sspeer  *	tx_mbox_p	dma_channel's mailbox
23666495Sspeer  *
23676495Sspeer  * Notes:
23686495Sspeer  *
23696495Sspeer  * NPI/NXGE function calls:
23706495Sspeer  *	nxge_setup_dma_common()
23716495Sspeer  *
23726495Sspeer  * Registers accessed:
23736495Sspeer  *	none.
23746495Sspeer  *
23756495Sspeer  * Context:
23766495Sspeer  *	Any domain
23776495Sspeer  */
23783859Sml29623 /*ARGSUSED*/
23793859Sml29623 static void
23803859Sml29623 nxge_map_txdma_channel_cfg_ring(p_nxge_t nxgep, uint16_t dma_channel,
23813859Sml29623 	p_nxge_dma_common_t *dma_cntl_p,
23823859Sml29623 	p_tx_ring_t tx_ring_p,
23833859Sml29623 	p_tx_mbox_t *tx_mbox_p)
23843859Sml29623 {
23853859Sml29623 	p_tx_mbox_t 		mboxp;
23863859Sml29623 	p_nxge_dma_common_t 	cntl_dmap;
23873859Sml29623 	p_nxge_dma_common_t 	dmap;
23883859Sml29623 	p_tx_rng_cfig_t		tx_ring_cfig_p;
23893859Sml29623 	p_tx_ring_kick_t	tx_ring_kick_p;
23903859Sml29623 	p_tx_cs_t		tx_cs_p;
23913859Sml29623 	p_tx_dma_ent_msk_t	tx_evmask_p;
23923859Sml29623 	p_txdma_mbh_t		mboxh_p;
23933859Sml29623 	p_txdma_mbl_t		mboxl_p;
23943859Sml29623 	uint64_t		tx_desc_len;
23953859Sml29623 
23963859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
23976929Smisaki 	    "==> nxge_map_txdma_channel_cfg_ring"));
23983859Sml29623 
23993859Sml29623 	cntl_dmap = *dma_cntl_p;
24003859Sml29623 
24013859Sml29623 	dmap = (p_nxge_dma_common_t)&tx_ring_p->tdc_desc;
24023859Sml29623 	nxge_setup_dma_common(dmap, cntl_dmap, tx_ring_p->tx_ring_size,
24036929Smisaki 	    sizeof (tx_desc_t));
24043859Sml29623 	/*
24053859Sml29623 	 * Zero out transmit ring descriptors.
24063859Sml29623 	 */
24073859Sml29623 	bzero((caddr_t)dmap->kaddrp, dmap->alength);
24083859Sml29623 	tx_ring_cfig_p = &(tx_ring_p->tx_ring_cfig);
24093859Sml29623 	tx_ring_kick_p = &(tx_ring_p->tx_ring_kick);
24103859Sml29623 	tx_cs_p = &(tx_ring_p->tx_cs);
24113859Sml29623 	tx_evmask_p = &(tx_ring_p->tx_evmask);
24123859Sml29623 	tx_ring_cfig_p->value = 0;
24133859Sml29623 	tx_ring_kick_p->value = 0;
24143859Sml29623 	tx_cs_p->value = 0;
24153859Sml29623 	tx_evmask_p->value = 0;
24163859Sml29623 
24173859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24186929Smisaki 	    "==> nxge_map_txdma_channel_cfg_ring: channel %d des $%p",
24196929Smisaki 	    dma_channel,
24206929Smisaki 	    dmap->dma_cookie.dmac_laddress));
24213859Sml29623 
24223859Sml29623 	tx_ring_cfig_p->value = 0;
24233859Sml29623 	tx_desc_len = (uint64_t)(tx_ring_p->tx_ring_size >> 3);
24243859Sml29623 	tx_ring_cfig_p->value =
24256929Smisaki 	    (dmap->dma_cookie.dmac_laddress & TX_RNG_CFIG_ADDR_MASK) |
24266929Smisaki 	    (tx_desc_len << TX_RNG_CFIG_LEN_SHIFT);
24273859Sml29623 
24283859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24296929Smisaki 	    "==> nxge_map_txdma_channel_cfg_ring: channel %d cfg 0x%llx",
24306929Smisaki 	    dma_channel,
24316929Smisaki 	    tx_ring_cfig_p->value));
24323859Sml29623 
24333859Sml29623 	tx_cs_p->bits.ldw.rst = 1;
24343859Sml29623 
24353859Sml29623 	/* Map in mailbox */
24363859Sml29623 	mboxp = (p_tx_mbox_t)
24376929Smisaki 	    KMEM_ZALLOC(sizeof (tx_mbox_t), KM_SLEEP);
24383859Sml29623 	dmap = (p_nxge_dma_common_t)&mboxp->tx_mbox;
24393859Sml29623 	nxge_setup_dma_common(dmap, cntl_dmap, 1, sizeof (txdma_mailbox_t));
24403859Sml29623 	mboxh_p = (p_txdma_mbh_t)&tx_ring_p->tx_mbox_mbh;
24413859Sml29623 	mboxl_p = (p_txdma_mbl_t)&tx_ring_p->tx_mbox_mbl;
24423859Sml29623 	mboxh_p->value = mboxl_p->value = 0;
24433859Sml29623 
24443859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24456929Smisaki 	    "==> nxge_map_txdma_channel_cfg_ring: mbox 0x%lx",
24466929Smisaki 	    dmap->dma_cookie.dmac_laddress));
24473859Sml29623 
24483859Sml29623 	mboxh_p->bits.ldw.mbaddr = ((dmap->dma_cookie.dmac_laddress >>
24496929Smisaki 	    TXDMA_MBH_ADDR_SHIFT) & TXDMA_MBH_MASK);
24503859Sml29623 
24513859Sml29623 	mboxl_p->bits.ldw.mbaddr = ((dmap->dma_cookie.dmac_laddress &
24526929Smisaki 	    TXDMA_MBL_MASK) >> TXDMA_MBL_SHIFT);
24533859Sml29623 
24543859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24556929Smisaki 	    "==> nxge_map_txdma_channel_cfg_ring: mbox 0x%lx",
24566929Smisaki 	    dmap->dma_cookie.dmac_laddress));
24573859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24586929Smisaki 	    "==> nxge_map_txdma_channel_cfg_ring: hmbox $%p "
24596929Smisaki 	    "mbox $%p",
24606929Smisaki 	    mboxh_p->bits.ldw.mbaddr, mboxl_p->bits.ldw.mbaddr));
24613859Sml29623 	tx_ring_p->page_valid.value = 0;
24623859Sml29623 	tx_ring_p->page_mask_1.value = tx_ring_p->page_mask_2.value = 0;
24633859Sml29623 	tx_ring_p->page_value_1.value = tx_ring_p->page_value_2.value = 0;
24643859Sml29623 	tx_ring_p->page_reloc_1.value = tx_ring_p->page_reloc_2.value = 0;
24653859Sml29623 	tx_ring_p->page_hdl.value = 0;
24663859Sml29623 
24673859Sml29623 	tx_ring_p->page_valid.bits.ldw.page0 = 1;
24683859Sml29623 	tx_ring_p->page_valid.bits.ldw.page1 = 1;
24693859Sml29623 
24703859Sml29623 	tx_ring_p->max_burst.value = 0;
24713859Sml29623 	tx_ring_p->max_burst.bits.ldw.dma_max_burst = TXC_DMA_MAX_BURST_DEFAULT;
24723859Sml29623 
24733859Sml29623 	*tx_mbox_p = mboxp;
24743859Sml29623 
24753859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24766929Smisaki 	    "<== nxge_map_txdma_channel_cfg_ring"));
24773859Sml29623 }
24783859Sml29623 
24793859Sml29623 /*ARGSUSED*/
24803859Sml29623 static void
24813859Sml29623 nxge_unmap_txdma_channel_cfg_ring(p_nxge_t nxgep,
24823859Sml29623 	p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p)
24833859Sml29623 {
24843859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24856929Smisaki 	    "==> nxge_unmap_txdma_channel_cfg_ring: channel %d",
24866929Smisaki 	    tx_ring_p->tdc));
24873859Sml29623 
24883859Sml29623 	KMEM_FREE(tx_mbox_p, sizeof (tx_mbox_t));
24893859Sml29623 
24903859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
24916929Smisaki 	    "<== nxge_unmap_txdma_channel_cfg_ring"));
24923859Sml29623 }
24933859Sml29623 
24946495Sspeer /*
24956495Sspeer  * nxge_map_txdma_channel_buf_ring
24966495Sspeer  *
24976495Sspeer  *
24986495Sspeer  * Arguments:
24996495Sspeer  * 	nxgep
25006495Sspeer  * 	channel		The channel to map.
25016495Sspeer  *	dma_buf_p
25026495Sspeer  *	tx_desc_p	channel's descriptor ring
25036495Sspeer  *	num_chunks
25046495Sspeer  *
25056495Sspeer  * Notes:
25066495Sspeer  *
25076495Sspeer  * NPI/NXGE function calls:
25086495Sspeer  *	nxge_setup_dma_common()
25096495Sspeer  *
25106495Sspeer  * Registers accessed:
25116495Sspeer  *	none.
25126495Sspeer  *
25136495Sspeer  * Context:
25146495Sspeer  *	Any domain
25156495Sspeer  */
25163859Sml29623 static nxge_status_t
25173859Sml29623 nxge_map_txdma_channel_buf_ring(p_nxge_t nxgep, uint16_t channel,
25183859Sml29623 	p_nxge_dma_common_t *dma_buf_p,
25193859Sml29623 	p_tx_ring_t *tx_desc_p, uint32_t num_chunks)
25203859Sml29623 {
25213859Sml29623 	p_nxge_dma_common_t 	dma_bufp, tmp_bufp;
25223859Sml29623 	p_nxge_dma_common_t 	dmap;
25233859Sml29623 	nxge_os_dma_handle_t	tx_buf_dma_handle;
25243859Sml29623 	p_tx_ring_t 		tx_ring_p;
25253859Sml29623 	p_tx_msg_t 		tx_msg_ring;
25263859Sml29623 	nxge_status_t		status = NXGE_OK;
25273859Sml29623 	int			ddi_status = DDI_SUCCESS;
25283859Sml29623 	int			i, j, index;
25293859Sml29623 	uint32_t		size, bsize;
25303859Sml29623 	uint32_t 		nblocks, nmsgs;
25318275SEric Cheng 	char			qname[TASKQ_NAMELEN];
25323859Sml29623 
25333859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
25346929Smisaki 	    "==> nxge_map_txdma_channel_buf_ring"));
25353859Sml29623 
25363859Sml29623 	dma_bufp = tmp_bufp = *dma_buf_p;
25373859Sml29623 		NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
25383859Sml29623 		" nxge_map_txdma_channel_buf_ring: channel %d to map %d "
25393859Sml29623 		"chunks bufp $%p",
25406929Smisaki 		    channel, num_chunks, dma_bufp));
25413859Sml29623 
25423859Sml29623 	nmsgs = 0;
25433859Sml29623 	for (i = 0; i < num_chunks; i++, tmp_bufp++) {
25443859Sml29623 		nmsgs += tmp_bufp->nblocks;
25453859Sml29623 		NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
25466929Smisaki 		    "==> nxge_map_txdma_channel_buf_ring: channel %d "
25476929Smisaki 		    "bufp $%p nblocks %d nmsgs %d",
25486929Smisaki 		    channel, tmp_bufp, tmp_bufp->nblocks, nmsgs));
25493859Sml29623 	}
25503859Sml29623 	if (!nmsgs) {
25513859Sml29623 		NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
25526929Smisaki 		    "<== nxge_map_txdma_channel_buf_ring: channel %d "
25536929Smisaki 		    "no msg blocks",
25546929Smisaki 		    channel));
25553859Sml29623 		status = NXGE_ERROR;
25563859Sml29623 		goto nxge_map_txdma_channel_buf_ring_exit;
25573859Sml29623 	}
25583859Sml29623 
25593859Sml29623 	tx_ring_p = (p_tx_ring_t)
25606929Smisaki 	    KMEM_ZALLOC(sizeof (tx_ring_t), KM_SLEEP);
25613859Sml29623 	MUTEX_INIT(&tx_ring_p->lock, NULL, MUTEX_DRIVER,
25626929Smisaki 	    (void *)nxgep->interrupt_cookie);
25633952Sml29623 
25646713Sspeer 	(void) atomic_swap_32(&tx_ring_p->tx_ring_offline, NXGE_TX_RING_ONLINE);
25656886Sspeer 	tx_ring_p->tx_ring_busy = B_FALSE;
25663952Sml29623 	tx_ring_p->nxgep = nxgep;
25678275SEric Cheng 	tx_ring_p->tx_ring_handle = (mac_ring_handle_t)NULL;
25688275SEric Cheng 	(void) snprintf(qname, TASKQ_NAMELEN, "tx_%d_%d",
25698275SEric Cheng 	    nxgep->instance, channel);
25708275SEric Cheng 	tx_ring_p->taskq = ddi_taskq_create(nxgep->dip, qname, 1,
25718275SEric Cheng 	    TASKQ_DEFAULTPRI, 0);
25728275SEric Cheng 	if (tx_ring_p->taskq == NULL) {
25738275SEric Cheng 		goto nxge_map_txdma_channel_buf_ring_fail1;
25748275SEric Cheng 	}
25758275SEric Cheng 
25763859Sml29623 	/*
25773859Sml29623 	 * Allocate transmit message rings and handles for packets
25783859Sml29623 	 * not to be copied to premapped buffers.
25793859Sml29623 	 */
25803859Sml29623 	size = nmsgs * sizeof (tx_msg_t);
25813859Sml29623 	tx_msg_ring = KMEM_ZALLOC(size, KM_SLEEP);
25823859Sml29623 	for (i = 0; i < nmsgs; i++) {
25833859Sml29623 		ddi_status = ddi_dma_alloc_handle(nxgep->dip, &nxge_tx_dma_attr,
25846929Smisaki 		    DDI_DMA_DONTWAIT, 0,
25856929Smisaki 		    &tx_msg_ring[i].dma_handle);
25863859Sml29623 		if (ddi_status != DDI_SUCCESS) {
25873859Sml29623 			status |= NXGE_DDI_FAILED;
25883859Sml29623 			break;
25893859Sml29623 		}
25903859Sml29623 	}
25913859Sml29623 	if (i < nmsgs) {
25924185Sspeer 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
25934185Sspeer 		    "Allocate handles failed."));
25943859Sml29623 		goto nxge_map_txdma_channel_buf_ring_fail1;
25953859Sml29623 	}
25963859Sml29623 
25973859Sml29623 	tx_ring_p->tdc = channel;
25983859Sml29623 	tx_ring_p->tx_msg_ring = tx_msg_ring;
25993859Sml29623 	tx_ring_p->tx_ring_size = nmsgs;
26003859Sml29623 	tx_ring_p->num_chunks = num_chunks;
26013859Sml29623 	if (!nxge_tx_intr_thres) {
26023859Sml29623 		nxge_tx_intr_thres = tx_ring_p->tx_ring_size/4;
26033859Sml29623 	}
26043859Sml29623 	tx_ring_p->tx_wrap_mask = tx_ring_p->tx_ring_size - 1;
26053859Sml29623 	tx_ring_p->rd_index = 0;
26063859Sml29623 	tx_ring_p->wr_index = 0;
26073859Sml29623 	tx_ring_p->ring_head.value = 0;
26083859Sml29623 	tx_ring_p->ring_kick_tail.value = 0;
26093859Sml29623 	tx_ring_p->descs_pending = 0;
26103859Sml29623 
26113859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
26126929Smisaki 	    "==> nxge_map_txdma_channel_buf_ring: channel %d "
26136929Smisaki 	    "actual tx desc max %d nmsgs %d "
26146929Smisaki 	    "(config nxge_tx_ring_size %d)",
26156929Smisaki 	    channel, tx_ring_p->tx_ring_size, nmsgs,
26166929Smisaki 	    nxge_tx_ring_size));
26173859Sml29623 
26183859Sml29623 	/*
26193859Sml29623 	 * Map in buffers from the buffer pool.
26203859Sml29623 	 */
26213859Sml29623 	index = 0;
26223859Sml29623 	bsize = dma_bufp->block_size;
26233859Sml29623 
26243859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_map_txdma_channel_buf_ring: "
26256929Smisaki 	    "dma_bufp $%p tx_rng_p $%p "
26266929Smisaki 	    "tx_msg_rng_p $%p bsize %d",
26276929Smisaki 	    dma_bufp, tx_ring_p, tx_msg_ring, bsize));
26283859Sml29623 
26293859Sml29623 	tx_buf_dma_handle = dma_bufp->dma_handle;
26303859Sml29623 	for (i = 0; i < num_chunks; i++, dma_bufp++) {
26313859Sml29623 		bsize = dma_bufp->block_size;
26323859Sml29623 		nblocks = dma_bufp->nblocks;
26333859Sml29623 		NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
26346929Smisaki 		    "==> nxge_map_txdma_channel_buf_ring: dma chunk %d "
26356929Smisaki 		    "size %d dma_bufp $%p",
26366929Smisaki 		    i, sizeof (nxge_dma_common_t), dma_bufp));
26373859Sml29623 
26383859Sml29623 		for (j = 0; j < nblocks; j++) {
26393859Sml29623 			tx_msg_ring[index].buf_dma_handle = tx_buf_dma_handle;
26403859Sml29623 			dmap = &tx_msg_ring[index++].buf_dma;
26413859Sml29623 #ifdef TX_MEM_DEBUG
26423859Sml29623 			NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
26436929Smisaki 			    "==> nxge_map_txdma_channel_buf_ring: j %d"
26446929Smisaki 			    "dmap $%p", i, dmap));
26453859Sml29623 #endif
26463859Sml29623 			nxge_setup_dma_common(dmap, dma_bufp, 1,
26476929Smisaki 			    bsize);
26483859Sml29623 		}
26493859Sml29623 	}
26503859Sml29623 
26513859Sml29623 	if (i < num_chunks) {
26524185Sspeer 		status = NXGE_ERROR;
26533859Sml29623 		goto nxge_map_txdma_channel_buf_ring_fail1;
26543859Sml29623 	}
26553859Sml29623 
26563859Sml29623 	*tx_desc_p = tx_ring_p;
26573859Sml29623 
26583859Sml29623 	goto nxge_map_txdma_channel_buf_ring_exit;
26593859Sml29623 
26603859Sml29623 nxge_map_txdma_channel_buf_ring_fail1:
26618275SEric Cheng 	if (tx_ring_p->taskq) {
26628275SEric Cheng 		ddi_taskq_destroy(tx_ring_p->taskq);
26638275SEric Cheng 		tx_ring_p->taskq = NULL;
26643952Sml29623 	}
26653952Sml29623 
26663859Sml29623 	index--;
26673859Sml29623 	for (; index >= 0; index--) {
26684185Sspeer 		if (tx_msg_ring[index].dma_handle != NULL) {
26694185Sspeer 			ddi_dma_free_handle(&tx_msg_ring[index].dma_handle);
26703859Sml29623 		}
26713859Sml29623 	}
26723859Sml29623 	MUTEX_DESTROY(&tx_ring_p->lock);
26734185Sspeer 	KMEM_FREE(tx_msg_ring, size);
26743859Sml29623 	KMEM_FREE(tx_ring_p, sizeof (tx_ring_t));
26753859Sml29623 
26764185Sspeer 	status = NXGE_ERROR;
26774185Sspeer 
26783859Sml29623 nxge_map_txdma_channel_buf_ring_exit:
26793859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
26806929Smisaki 	    "<== nxge_map_txdma_channel_buf_ring status 0x%x", status));
26813859Sml29623 
26823859Sml29623 	return (status);
26833859Sml29623 }
26843859Sml29623 
26853859Sml29623 /*ARGSUSED*/
26863859Sml29623 static void
26873859Sml29623 nxge_unmap_txdma_channel_buf_ring(p_nxge_t nxgep, p_tx_ring_t tx_ring_p)
26883859Sml29623 {
26893859Sml29623 	p_tx_msg_t 		tx_msg_ring;
26903859Sml29623 	p_tx_msg_t 		tx_msg_p;
26913859Sml29623 	int			i;
26923859Sml29623 
26933859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
26946929Smisaki 	    "==> nxge_unmap_txdma_channel_buf_ring"));
26953859Sml29623 	if (tx_ring_p == NULL) {
26963859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
26976929Smisaki 		    "<== nxge_unmap_txdma_channel_buf_ring: NULL ringp"));
26983859Sml29623 		return;
26993859Sml29623 	}
27003859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
27016929Smisaki 	    "==> nxge_unmap_txdma_channel_buf_ring: channel %d",
27026929Smisaki 	    tx_ring_p->tdc));
27033859Sml29623 
27043859Sml29623 	tx_msg_ring = tx_ring_p->tx_msg_ring;
27056495Sspeer 
27066495Sspeer 	/*
27076495Sspeer 	 * Since the serialization thread, timer thread and
27086495Sspeer 	 * interrupt thread can all call the transmit reclaim,
27096495Sspeer 	 * the unmapping function needs to acquire the lock
27106495Sspeer 	 * to free those buffers which were transmitted
27116495Sspeer 	 * by the hardware already.
27126495Sspeer 	 */
27136495Sspeer 	MUTEX_ENTER(&tx_ring_p->lock);
27146495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
27156495Sspeer 	    "==> nxge_unmap_txdma_channel_buf_ring (reclaim): "
27166495Sspeer 	    "channel %d",
27176495Sspeer 	    tx_ring_p->tdc));
27186495Sspeer 	(void) nxge_txdma_reclaim(nxgep, tx_ring_p, 0);
27196495Sspeer 
27203859Sml29623 	for (i = 0; i < tx_ring_p->tx_ring_size; i++) {
27213859Sml29623 		tx_msg_p = &tx_msg_ring[i];
27223859Sml29623 		if (tx_msg_p->tx_message != NULL) {
27233859Sml29623 			freemsg(tx_msg_p->tx_message);
27243859Sml29623 			tx_msg_p->tx_message = NULL;
27253859Sml29623 		}
27263859Sml29623 	}
27273859Sml29623 
27283859Sml29623 	for (i = 0; i < tx_ring_p->tx_ring_size; i++) {
27293859Sml29623 		if (tx_msg_ring[i].dma_handle != NULL) {
27303859Sml29623 			ddi_dma_free_handle(&tx_msg_ring[i].dma_handle);
27313859Sml29623 		}
27326495Sspeer 		tx_msg_ring[i].dma_handle = NULL;
27333859Sml29623 	}
27343859Sml29623 
27356495Sspeer 	MUTEX_EXIT(&tx_ring_p->lock);
27366495Sspeer 
27378275SEric Cheng 	if (tx_ring_p->taskq) {
27388275SEric Cheng 		ddi_taskq_destroy(tx_ring_p->taskq);
27398275SEric Cheng 		tx_ring_p->taskq = NULL;
27403952Sml29623 	}
27413952Sml29623 
27423859Sml29623 	MUTEX_DESTROY(&tx_ring_p->lock);
27433859Sml29623 	KMEM_FREE(tx_msg_ring, sizeof (tx_msg_t) * tx_ring_p->tx_ring_size);
27443859Sml29623 	KMEM_FREE(tx_ring_p, sizeof (tx_ring_t));
27453859Sml29623 
27463859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
27476929Smisaki 	    "<== nxge_unmap_txdma_channel_buf_ring"));
27483859Sml29623 }
27493859Sml29623 
27503859Sml29623 static nxge_status_t
27516495Sspeer nxge_txdma_hw_start(p_nxge_t nxgep, int channel)
27523859Sml29623 {
27533859Sml29623 	p_tx_rings_t 		tx_rings;
27543859Sml29623 	p_tx_ring_t 		*tx_desc_rings;
27553859Sml29623 	p_tx_mbox_areas_t 	tx_mbox_areas_p;
27563859Sml29623 	p_tx_mbox_t		*tx_mbox_p;
27573859Sml29623 	nxge_status_t		status = NXGE_OK;
27583859Sml29623 
27593859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_txdma_hw_start"));
27603859Sml29623 
27613859Sml29623 	tx_rings = nxgep->tx_rings;
27623859Sml29623 	if (tx_rings == NULL) {
27633859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
27646929Smisaki 		    "<== nxge_txdma_hw_start: NULL ring pointer"));
27653859Sml29623 		return (NXGE_ERROR);
27663859Sml29623 	}
27673859Sml29623 	tx_desc_rings = tx_rings->rings;
27683859Sml29623 	if (tx_desc_rings == NULL) {
27693859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
27706929Smisaki 		    "<== nxge_txdma_hw_start: NULL ring pointers"));
27713859Sml29623 		return (NXGE_ERROR);
27723859Sml29623 	}
27733859Sml29623 
27746495Sspeer 	NXGE_ERROR_MSG((nxgep, MEM3_CTL, "==> nxge_txdma_hw_start: "
27756495Sspeer 	    "tx_rings $%p tx_desc_rings $%p", tx_rings, tx_desc_rings));
27763859Sml29623 
27773859Sml29623 	tx_mbox_areas_p = nxgep->tx_mbox_areas_p;
27783859Sml29623 	tx_mbox_p = tx_mbox_areas_p->txmbox_areas_p;
27793859Sml29623 
27806495Sspeer 	status = nxge_txdma_start_channel(nxgep, channel,
27816495Sspeer 	    (p_tx_ring_t)tx_desc_rings[channel],
27826495Sspeer 	    (p_tx_mbox_t)tx_mbox_p[channel]);
27836495Sspeer 	if (status != NXGE_OK) {
27846495Sspeer 		goto nxge_txdma_hw_start_fail1;
27853859Sml29623 	}
27863859Sml29623 
27873859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_txdma_hw_start: "
27886929Smisaki 	    "tx_rings $%p rings $%p",
27896929Smisaki 	    nxgep->tx_rings, nxgep->tx_rings->rings));
27903859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "==> nxge_txdma_hw_start: "
27916929Smisaki 	    "tx_rings $%p tx_desc_rings $%p",
27926929Smisaki 	    nxgep->tx_rings, tx_desc_rings));
27933859Sml29623 
27943859Sml29623 	goto nxge_txdma_hw_start_exit;
27953859Sml29623 
27963859Sml29623 nxge_txdma_hw_start_fail1:
27973859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
27986929Smisaki 	    "==> nxge_txdma_hw_start: disable "
27996929Smisaki 	    "(status 0x%x channel %d)", status, channel));
28003859Sml29623 
28013859Sml29623 nxge_txdma_hw_start_exit:
28023859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
28036929Smisaki 	    "==> nxge_txdma_hw_start: (status 0x%x)", status));
28043859Sml29623 
28053859Sml29623 	return (status);
28063859Sml29623 }
28073859Sml29623 
28086495Sspeer /*
28096495Sspeer  * nxge_txdma_start_channel
28106495Sspeer  *
28116495Sspeer  *	Start a TDC.
28126495Sspeer  *
28136495Sspeer  * Arguments:
28146495Sspeer  * 	nxgep
28156495Sspeer  * 	channel		The channel to start.
28166495Sspeer  * 	tx_ring_p	channel's transmit descriptor ring.
28176495Sspeer  * 	tx_mbox_p	channel' smailbox.
28186495Sspeer  *
28196495Sspeer  * Notes:
28206495Sspeer  *
28216495Sspeer  * NPI/NXGE function calls:
28226495Sspeer  *	nxge_reset_txdma_channel()
28236495Sspeer  *	nxge_init_txdma_channel_event_mask()
28246495Sspeer  *	nxge_enable_txdma_channel()
28256495Sspeer  *
28266495Sspeer  * Registers accessed:
28276495Sspeer  *	none directly (see functions above).
28286495Sspeer  *
28296495Sspeer  * Context:
28306495Sspeer  *	Any domain
28316495Sspeer  */
28323859Sml29623 static nxge_status_t
28333859Sml29623 nxge_txdma_start_channel(p_nxge_t nxgep, uint16_t channel,
28343859Sml29623     p_tx_ring_t tx_ring_p, p_tx_mbox_t tx_mbox_p)
28353859Sml29623 
28363859Sml29623 {
28373859Sml29623 	nxge_status_t		status = NXGE_OK;
28383859Sml29623 
28393859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
28403859Sml29623 		"==> nxge_txdma_start_channel (channel %d)", channel));
28413859Sml29623 	/*
28423859Sml29623 	 * TXDMA/TXC must be in stopped state.
28433859Sml29623 	 */
28443859Sml29623 	(void) nxge_txdma_stop_inj_err(nxgep, channel);
28453859Sml29623 
28463859Sml29623 	/*
28473859Sml29623 	 * Reset TXDMA channel
28483859Sml29623 	 */
28493859Sml29623 	tx_ring_p->tx_cs.value = 0;
28503859Sml29623 	tx_ring_p->tx_cs.bits.ldw.rst = 1;
28513859Sml29623 	status = nxge_reset_txdma_channel(nxgep, channel,
28523859Sml29623 			tx_ring_p->tx_cs.value);
28533859Sml29623 	if (status != NXGE_OK) {
28543859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
28553859Sml29623 			"==> nxge_txdma_start_channel (channel %d)"
28563859Sml29623 			" reset channel failed 0x%x", channel, status));
28573859Sml29623 		goto nxge_txdma_start_channel_exit;
28583859Sml29623 	}
28593859Sml29623 
28603859Sml29623 	/*
28613859Sml29623 	 * Initialize the TXDMA channel specific FZC control
28623859Sml29623 	 * configurations. These FZC registers are pertaining
28633859Sml29623 	 * to each TX channel (i.e. logical pages).
28643859Sml29623 	 */
28656495Sspeer 	if (!isLDOMguest(nxgep)) {
28666495Sspeer 		status = nxge_init_fzc_txdma_channel(nxgep, channel,
28676495Sspeer 		    tx_ring_p, tx_mbox_p);
28686495Sspeer 		if (status != NXGE_OK) {
28696495Sspeer 			goto nxge_txdma_start_channel_exit;
28706495Sspeer 		}
28713859Sml29623 	}
28723859Sml29623 
28733859Sml29623 	/*
28743859Sml29623 	 * Initialize the event masks.
28753859Sml29623 	 */
28763859Sml29623 	tx_ring_p->tx_evmask.value = 0;
28773859Sml29623 	status = nxge_init_txdma_channel_event_mask(nxgep,
28786495Sspeer 	    channel, &tx_ring_p->tx_evmask);
28793859Sml29623 	if (status != NXGE_OK) {
28803859Sml29623 		goto nxge_txdma_start_channel_exit;
28813859Sml29623 	}
28823859Sml29623 
28833859Sml29623 	/*
28843859Sml29623 	 * Load TXDMA descriptors, buffers, mailbox,
28853859Sml29623 	 * initialise the DMA channels and
28863859Sml29623 	 * enable each DMA channel.
28873859Sml29623 	 */
28883859Sml29623 	status = nxge_enable_txdma_channel(nxgep, channel,
28893859Sml29623 			tx_ring_p, tx_mbox_p);
28903859Sml29623 	if (status != NXGE_OK) {
28913859Sml29623 		goto nxge_txdma_start_channel_exit;
28923859Sml29623 	}
28933859Sml29623 
28943859Sml29623 nxge_txdma_start_channel_exit:
28953859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "<== nxge_txdma_start_channel"));
28963859Sml29623 
28973859Sml29623 	return (status);
28983859Sml29623 }
28993859Sml29623 
29006495Sspeer /*
29016495Sspeer  * nxge_txdma_stop_channel
29026495Sspeer  *
29036495Sspeer  *	Stop a TDC.
29046495Sspeer  *
29056495Sspeer  * Arguments:
29066495Sspeer  * 	nxgep
29076495Sspeer  * 	channel		The channel to stop.
29086495Sspeer  * 	tx_ring_p	channel's transmit descriptor ring.
29096495Sspeer  * 	tx_mbox_p	channel' smailbox.
29106495Sspeer  *
29116495Sspeer  * Notes:
29126495Sspeer  *
29136495Sspeer  * NPI/NXGE function calls:
29146495Sspeer  *	nxge_txdma_stop_inj_err()
29156495Sspeer  *	nxge_reset_txdma_channel()
29166495Sspeer  *	nxge_init_txdma_channel_event_mask()
29176495Sspeer  *	nxge_init_txdma_channel_cntl_stat()
29186495Sspeer  *	nxge_disable_txdma_channel()
29196495Sspeer  *
29206495Sspeer  * Registers accessed:
29216495Sspeer  *	none directly (see functions above).
29226495Sspeer  *
29236495Sspeer  * Context:
29246495Sspeer  *	Any domain
29256495Sspeer  */
29263859Sml29623 /*ARGSUSED*/
29273859Sml29623 static nxge_status_t
29286495Sspeer nxge_txdma_stop_channel(p_nxge_t nxgep, uint16_t channel)
29293859Sml29623 {
29306495Sspeer 	p_tx_ring_t tx_ring_p;
29316495Sspeer 	int status = NXGE_OK;
29323859Sml29623 
29333859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
29346929Smisaki 	    "==> nxge_txdma_stop_channel: channel %d", channel));
29353859Sml29623 
29363859Sml29623 	/*
29373859Sml29623 	 * Stop (disable) TXDMA and TXC (if stop bit is set
29383859Sml29623 	 * and STOP_N_GO bit not set, the TXDMA reset state will
29393859Sml29623 	 * not be set if reset TXDMA.
29403859Sml29623 	 */
29413859Sml29623 	(void) nxge_txdma_stop_inj_err(nxgep, channel);
29423859Sml29623 
29436495Sspeer 	tx_ring_p = nxgep->tx_rings->rings[channel];
29446495Sspeer 
29453859Sml29623 	/*
29463859Sml29623 	 * Reset TXDMA channel
29473859Sml29623 	 */
29483859Sml29623 	tx_ring_p->tx_cs.value = 0;
29493859Sml29623 	tx_ring_p->tx_cs.bits.ldw.rst = 1;
29503859Sml29623 	status = nxge_reset_txdma_channel(nxgep, channel,
29516929Smisaki 	    tx_ring_p->tx_cs.value);
29523859Sml29623 	if (status != NXGE_OK) {
29533859Sml29623 		goto nxge_txdma_stop_channel_exit;
29543859Sml29623 	}
29553859Sml29623 
29563859Sml29623 #ifdef HARDWARE_REQUIRED
29573859Sml29623 	/* Set up the interrupt event masks. */
29583859Sml29623 	tx_ring_p->tx_evmask.value = 0;
29593859Sml29623 	status = nxge_init_txdma_channel_event_mask(nxgep,
29606929Smisaki 	    channel, &tx_ring_p->tx_evmask);
29613859Sml29623 	if (status != NXGE_OK) {
29623859Sml29623 		goto nxge_txdma_stop_channel_exit;
29633859Sml29623 	}
29643859Sml29623 
29653859Sml29623 	/* Initialize the DMA control and status register */
29663859Sml29623 	tx_ring_p->tx_cs.value = TX_ENT_MSK_MK_ALL;
29673859Sml29623 	status = nxge_init_txdma_channel_cntl_stat(nxgep, channel,
29686929Smisaki 	    tx_ring_p->tx_cs.value);
29693859Sml29623 	if (status != NXGE_OK) {
29703859Sml29623 		goto nxge_txdma_stop_channel_exit;
29713859Sml29623 	}
29723859Sml29623 
29736495Sspeer 	tx_mbox_p = nxgep->tx_mbox_areas_p->txmbox_areas_p[channel];
29746495Sspeer 
29753859Sml29623 	/* Disable channel */
29763859Sml29623 	status = nxge_disable_txdma_channel(nxgep, channel,
29776495Sspeer 	    tx_ring_p, tx_mbox_p);
29783859Sml29623 	if (status != NXGE_OK) {
29793859Sml29623 		goto nxge_txdma_start_channel_exit;
29803859Sml29623 	}
29813859Sml29623 
29823859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL,
29836929Smisaki 	    "==> nxge_txdma_stop_channel: event done"));
29843859Sml29623 
29853859Sml29623 #endif
29863859Sml29623 
29873859Sml29623 nxge_txdma_stop_channel_exit:
29883859Sml29623 	NXGE_DEBUG_MSG((nxgep, MEM3_CTL, "<== nxge_txdma_stop_channel"));
29893859Sml29623 	return (status);
29903859Sml29623 }
29913859Sml29623 
29926495Sspeer /*
29936495Sspeer  * nxge_txdma_get_ring
29946495Sspeer  *
29956495Sspeer  *	Get the ring for a TDC.
29966495Sspeer  *
29976495Sspeer  * Arguments:
29986495Sspeer  * 	nxgep
29996495Sspeer  * 	channel
30006495Sspeer  *
30016495Sspeer  * Notes:
30026495Sspeer  *
30036495Sspeer  * NPI/NXGE function calls:
30046495Sspeer  *
30056495Sspeer  * Registers accessed:
30066495Sspeer  *
30076495Sspeer  * Context:
30086495Sspeer  *	Any domain
30096495Sspeer  */
30103859Sml29623 static p_tx_ring_t
30113859Sml29623 nxge_txdma_get_ring(p_nxge_t nxgep, uint16_t channel)
30123859Sml29623 {
30136495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
30146495Sspeer 	int tdc;
30153859Sml29623 
30163859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_get_ring"));
30173859Sml29623 
30186495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
30193859Sml29623 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
30206495Sspeer 		    "<== nxge_txdma_get_ring: NULL ring pointer(s)"));
30216495Sspeer 		goto return_null;
30223859Sml29623 	}
30233859Sml29623 
30246495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
30256495Sspeer 		if ((1 << tdc) & set->owned.map) {
30266495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
30276495Sspeer 			if (ring) {
30286495Sspeer 				if (channel == ring->tdc) {
30296495Sspeer 					NXGE_DEBUG_MSG((nxgep, TX_CTL,
30306495Sspeer 					    "<== nxge_txdma_get_ring: "
30316495Sspeer 					    "tdc %d ring $%p", tdc, ring));
30326495Sspeer 					return (ring);
30336495Sspeer 				}
30346495Sspeer 			}
30353859Sml29623 		}
30363859Sml29623 	}
30373859Sml29623 
30386495Sspeer return_null:
30396495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_get_ring: "
30406929Smisaki 	    "ring not found"));
30416495Sspeer 
30423859Sml29623 	return (NULL);
30433859Sml29623 }
30443859Sml29623 
30456495Sspeer /*
30466495Sspeer  * nxge_txdma_get_mbox
30476495Sspeer  *
30486495Sspeer  *	Get the mailbox for a TDC.
30496495Sspeer  *
30506495Sspeer  * Arguments:
30516495Sspeer  * 	nxgep
30526495Sspeer  * 	channel
30536495Sspeer  *
30546495Sspeer  * Notes:
30556495Sspeer  *
30566495Sspeer  * NPI/NXGE function calls:
30576495Sspeer  *
30586495Sspeer  * Registers accessed:
30596495Sspeer  *
30606495Sspeer  * Context:
30616495Sspeer  *	Any domain
30626495Sspeer  */
30633859Sml29623 static p_tx_mbox_t
30643859Sml29623 nxge_txdma_get_mbox(p_nxge_t nxgep, uint16_t channel)
30653859Sml29623 {
30666495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
30676495Sspeer 	int tdc;
30683859Sml29623 
30693859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_get_mbox"));
30703859Sml29623 
30716495Sspeer 	if (nxgep->tx_mbox_areas_p == 0 ||
30726495Sspeer 	    nxgep->tx_mbox_areas_p->txmbox_areas_p == 0) {
30736495Sspeer 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
30746495Sspeer 		    "<== nxge_txdma_get_mbox: NULL mailbox pointer(s)"));
30756495Sspeer 		goto return_null;
30763859Sml29623 	}
30773859Sml29623 
30786495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
30796495Sspeer 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
30806495Sspeer 		    "<== nxge_txdma_get_mbox: NULL ring pointer(s)"));
30816495Sspeer 		goto return_null;
30823859Sml29623 	}
30833859Sml29623 
30846495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
30856495Sspeer 		if ((1 << tdc) & set->owned.map) {
30866495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
30876495Sspeer 			if (ring) {
30886495Sspeer 				if (channel == ring->tdc) {
30896495Sspeer 					tx_mbox_t *mailbox = nxgep->
30906495Sspeer 					    tx_mbox_areas_p->
30916495Sspeer 					    txmbox_areas_p[tdc];
30926495Sspeer 					NXGE_DEBUG_MSG((nxgep, TX_CTL,
30936495Sspeer 					    "<== nxge_txdma_get_mbox: tdc %d "
30946495Sspeer 					    "ring $%p", tdc, mailbox));
30956495Sspeer 					return (mailbox);
30966495Sspeer 				}
30976495Sspeer 			}
30983859Sml29623 		}
30993859Sml29623 	}
31003859Sml29623 
31016495Sspeer return_null:
31026495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_get_mbox: "
31036929Smisaki 	    "mailbox not found"));
31046495Sspeer 
31053859Sml29623 	return (NULL);
31063859Sml29623 }
31073859Sml29623 
31086495Sspeer /*
31096495Sspeer  * nxge_tx_err_evnts
31106495Sspeer  *
31116495Sspeer  *	Recover a TDC.
31126495Sspeer  *
31136495Sspeer  * Arguments:
31146495Sspeer  * 	nxgep
31156495Sspeer  * 	index	The index to the TDC ring.
31166495Sspeer  * 	ldvp	Used to get the channel number ONLY.
31176495Sspeer  * 	cs	A copy of the bits from TX_CS.
31186495Sspeer  *
31196495Sspeer  * Notes:
31206495Sspeer  *	Calling tree:
31216495Sspeer  *	 nxge_tx_intr()
31226495Sspeer  *
31236495Sspeer  * NPI/NXGE function calls:
31246495Sspeer  *	npi_txdma_ring_error_get()
31256495Sspeer  *	npi_txdma_inj_par_error_get()
31266495Sspeer  *	nxge_txdma_fatal_err_recover()
31276495Sspeer  *
31286495Sspeer  * Registers accessed:
31296495Sspeer  *	TX_RNG_ERR_LOGH	DMC+0x40048 Transmit Ring Error Log High
31306495Sspeer  *	TX_RNG_ERR_LOGL DMC+0x40050 Transmit Ring Error Log Low
31316495Sspeer  *	TDMC_INJ_PAR_ERR (FZC_DMC + 0x45040) TDMC Inject Parity Error
31326495Sspeer  *
31336495Sspeer  * Context:
31346495Sspeer  *	Any domain	XXX Remove code which accesses TDMC_INJ_PAR_ERR.
31356495Sspeer  */
31363859Sml29623 /*ARGSUSED*/
31373859Sml29623 static nxge_status_t
31383859Sml29623 nxge_tx_err_evnts(p_nxge_t nxgep, uint_t index, p_nxge_ldv_t ldvp, tx_cs_t cs)
31393859Sml29623 {
31403859Sml29623 	npi_handle_t		handle;
31413859Sml29623 	npi_status_t		rs;
31423859Sml29623 	uint8_t			channel;
31433859Sml29623 	p_tx_ring_t 		*tx_rings;
31443859Sml29623 	p_tx_ring_t 		tx_ring_p;
31453859Sml29623 	p_nxge_tx_ring_stats_t	tdc_stats;
31463859Sml29623 	boolean_t		txchan_fatal = B_FALSE;
31473859Sml29623 	nxge_status_t		status = NXGE_OK;
31483859Sml29623 	tdmc_inj_par_err_t	par_err;
31493859Sml29623 	uint32_t		value;
31503859Sml29623 
31516495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX2_CTL, "==> nxge_tx_err_evnts"));
31523859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
31533859Sml29623 	channel = ldvp->channel;
31543859Sml29623 
31553859Sml29623 	tx_rings = nxgep->tx_rings->rings;
31563859Sml29623 	tx_ring_p = tx_rings[index];
31573859Sml29623 	tdc_stats = tx_ring_p->tdc_stats;
31583859Sml29623 	if ((cs.bits.ldw.pkt_size_err) || (cs.bits.ldw.pref_buf_par_err) ||
31596929Smisaki 	    (cs.bits.ldw.nack_pref) || (cs.bits.ldw.nack_pkt_rd) ||
31606929Smisaki 	    (cs.bits.ldw.conf_part_err) || (cs.bits.ldw.pkt_prt_err)) {
31613859Sml29623 		if ((rs = npi_txdma_ring_error_get(handle, channel,
31626929Smisaki 		    &tdc_stats->errlog)) != NPI_SUCCESS)
31633859Sml29623 			return (NXGE_ERROR | rs);
31643859Sml29623 	}
31653859Sml29623 
31663859Sml29623 	if (cs.bits.ldw.mbox_err) {
31673859Sml29623 		tdc_stats->mbox_err++;
31683859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
31696929Smisaki 		    NXGE_FM_EREPORT_TDMC_MBOX_ERR);
31703859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
31716929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
31726929Smisaki 		    "fatal error: mailbox", channel));
31733859Sml29623 		txchan_fatal = B_TRUE;
31743859Sml29623 	}
31753859Sml29623 	if (cs.bits.ldw.pkt_size_err) {
31763859Sml29623 		tdc_stats->pkt_size_err++;
31773859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
31786929Smisaki 		    NXGE_FM_EREPORT_TDMC_PKT_SIZE_ERR);
31793859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
31806929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
31816929Smisaki 		    "fatal error: pkt_size_err", channel));
31823859Sml29623 		txchan_fatal = B_TRUE;
31833859Sml29623 	}
31843859Sml29623 	if (cs.bits.ldw.tx_ring_oflow) {
31853859Sml29623 		tdc_stats->tx_ring_oflow++;
31863859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
31876929Smisaki 		    NXGE_FM_EREPORT_TDMC_TX_RING_OFLOW);
31883859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
31896929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
31906929Smisaki 		    "fatal error: tx_ring_oflow", channel));
31913859Sml29623 		txchan_fatal = B_TRUE;
31923859Sml29623 	}
31933859Sml29623 	if (cs.bits.ldw.pref_buf_par_err) {
31943859Sml29623 		tdc_stats->pre_buf_par_err++;
31953859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
31966929Smisaki 		    NXGE_FM_EREPORT_TDMC_PREF_BUF_PAR_ERR);
31973859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
31986929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
31996929Smisaki 		    "fatal error: pre_buf_par_err", channel));
32003859Sml29623 		/* Clear error injection source for parity error */
32013859Sml29623 		(void) npi_txdma_inj_par_error_get(handle, &value);
32023859Sml29623 		par_err.value = value;
32033859Sml29623 		par_err.bits.ldw.inject_parity_error &= ~(1 << channel);
32043859Sml29623 		(void) npi_txdma_inj_par_error_set(handle, par_err.value);
32053859Sml29623 		txchan_fatal = B_TRUE;
32063859Sml29623 	}
32073859Sml29623 	if (cs.bits.ldw.nack_pref) {
32083859Sml29623 		tdc_stats->nack_pref++;
32093859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
32106929Smisaki 		    NXGE_FM_EREPORT_TDMC_NACK_PREF);
32113859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32126929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
32136929Smisaki 		    "fatal error: nack_pref", channel));
32143859Sml29623 		txchan_fatal = B_TRUE;
32153859Sml29623 	}
32163859Sml29623 	if (cs.bits.ldw.nack_pkt_rd) {
32173859Sml29623 		tdc_stats->nack_pkt_rd++;
32183859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
32196929Smisaki 		    NXGE_FM_EREPORT_TDMC_NACK_PKT_RD);
32203859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32216929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
32226929Smisaki 		    "fatal error: nack_pkt_rd", channel));
32233859Sml29623 		txchan_fatal = B_TRUE;
32243859Sml29623 	}
32253859Sml29623 	if (cs.bits.ldw.conf_part_err) {
32263859Sml29623 		tdc_stats->conf_part_err++;
32273859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
32286929Smisaki 		    NXGE_FM_EREPORT_TDMC_CONF_PART_ERR);
32293859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32306929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
32316929Smisaki 		    "fatal error: config_partition_err", channel));
32323859Sml29623 		txchan_fatal = B_TRUE;
32333859Sml29623 	}
32343859Sml29623 	if (cs.bits.ldw.pkt_prt_err) {
32353859Sml29623 		tdc_stats->pkt_part_err++;
32363859Sml29623 		NXGE_FM_REPORT_ERROR(nxgep, nxgep->mac.portnum, channel,
32376929Smisaki 		    NXGE_FM_EREPORT_TDMC_PKT_PRT_ERR);
32383859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32396929Smisaki 		    "==> nxge_tx_err_evnts(channel %d): "
32406929Smisaki 		    "fatal error: pkt_prt_err", channel));
32413859Sml29623 		txchan_fatal = B_TRUE;
32423859Sml29623 	}
32433859Sml29623 
32443859Sml29623 	/* Clear error injection source in case this is an injected error */
32453859Sml29623 	TXDMA_REG_WRITE64(nxgep->npi_handle, TDMC_INTR_DBG_REG, channel, 0);
32463859Sml29623 
32473859Sml29623 	if (txchan_fatal) {
32483859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32496929Smisaki 		    " nxge_tx_err_evnts: "
32506929Smisaki 		    " fatal error on channel %d cs 0x%llx\n",
32516929Smisaki 		    channel, cs.value));
32523859Sml29623 		status = nxge_txdma_fatal_err_recover(nxgep, channel,
32536929Smisaki 		    tx_ring_p);
32543859Sml29623 		if (status == NXGE_OK) {
32553859Sml29623 			FM_SERVICE_RESTORED(nxgep);
32563859Sml29623 		}
32573859Sml29623 	}
32583859Sml29623 
32596495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX2_CTL, "<== nxge_tx_err_evnts"));
32603859Sml29623 
32613859Sml29623 	return (status);
32623859Sml29623 }
32633859Sml29623 
32643859Sml29623 static nxge_status_t
32656495Sspeer nxge_txdma_fatal_err_recover(
32666495Sspeer 	p_nxge_t nxgep,
32676495Sspeer 	uint16_t channel,
32686495Sspeer 	p_tx_ring_t tx_ring_p)
32693859Sml29623 {
32703859Sml29623 	npi_handle_t	handle;
32713859Sml29623 	npi_status_t	rs = NPI_SUCCESS;
32723859Sml29623 	p_tx_mbox_t	tx_mbox_p;
32733859Sml29623 	nxge_status_t	status = NXGE_OK;
32743859Sml29623 
32753859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_txdma_fatal_err_recover"));
32763859Sml29623 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32776929Smisaki 	    "Recovering from TxDMAChannel#%d error...", channel));
32783859Sml29623 
32793859Sml29623 	/*
32803859Sml29623 	 * Stop the dma channel waits for the stop done.
32813859Sml29623 	 * If the stop done bit is not set, then create
32823859Sml29623 	 * an error.
32833859Sml29623 	 */
32843859Sml29623 
32853859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
32863859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "TxDMA channel stop..."));
32873859Sml29623 	MUTEX_ENTER(&tx_ring_p->lock);
32883859Sml29623 	rs = npi_txdma_channel_control(handle, TXDMA_STOP, channel);
32893859Sml29623 	if (rs != NPI_SUCCESS) {
32903859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
32916929Smisaki 		    "==> nxge_txdma_fatal_err_recover (channel %d): "
32926929Smisaki 		    "stop failed ", channel));
32933859Sml29623 		goto fail;
32943859Sml29623 	}
32953859Sml29623 
32963859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "TxDMA channel reclaim..."));
32973859Sml29623 	(void) nxge_txdma_reclaim(nxgep, tx_ring_p, 0);
32983859Sml29623 
32993859Sml29623 	/*
33003859Sml29623 	 * Reset TXDMA channel
33013859Sml29623 	 */
33023859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "TxDMA channel reset..."));
33033859Sml29623 	if ((rs = npi_txdma_channel_control(handle, TXDMA_RESET, channel)) !=
33046929Smisaki 	    NPI_SUCCESS) {
33053859Sml29623 		NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
33066929Smisaki 		    "==> nxge_txdma_fatal_err_recover (channel %d)"
33076929Smisaki 		    " reset channel failed 0x%x", channel, rs));
33083859Sml29623 		goto fail;
33093859Sml29623 	}
33103859Sml29623 
33113859Sml29623 	/*
33123859Sml29623 	 * Reset the tail (kick) register to 0.
33133859Sml29623 	 * (Hardware will not reset it. Tx overflow fatal
33143859Sml29623 	 * error if tail is not set to 0 after reset!
33153859Sml29623 	 */
33163859Sml29623 	TXDMA_REG_WRITE64(handle, TX_RING_KICK_REG, channel, 0);
33173859Sml29623 
33183859Sml29623 	/* Restart TXDMA channel */
33193859Sml29623 
33206495Sspeer 	if (!isLDOMguest(nxgep)) {
33216495Sspeer 		tx_mbox_p = nxge_txdma_get_mbox(nxgep, channel);
33226495Sspeer 
33236495Sspeer 		// XXX This is a problem in HIO!
33246495Sspeer 		/*
33256495Sspeer 		 * Initialize the TXDMA channel specific FZC control
33266495Sspeer 		 * configurations. These FZC registers are pertaining
33276495Sspeer 		 * to each TX channel (i.e. logical pages).
33286495Sspeer 		 */
33296495Sspeer 		NXGE_DEBUG_MSG((nxgep, TX_CTL, "TxDMA channel restart..."));
33306495Sspeer 		status = nxge_init_fzc_txdma_channel(nxgep, channel,
33316495Sspeer 		    tx_ring_p, tx_mbox_p);
33326495Sspeer 		if (status != NXGE_OK)
33336495Sspeer 			goto fail;
33346495Sspeer 	}
33353859Sml29623 
33363859Sml29623 	/*
33373859Sml29623 	 * Initialize the event masks.
33383859Sml29623 	 */
33393859Sml29623 	tx_ring_p->tx_evmask.value = 0;
33403859Sml29623 	status = nxge_init_txdma_channel_event_mask(nxgep, channel,
33416929Smisaki 	    &tx_ring_p->tx_evmask);
33423859Sml29623 	if (status != NXGE_OK)
33433859Sml29623 		goto fail;
33443859Sml29623 
33453859Sml29623 	tx_ring_p->wr_index_wrap = B_FALSE;
33463859Sml29623 	tx_ring_p->wr_index = 0;
33473859Sml29623 	tx_ring_p->rd_index = 0;
33483859Sml29623 
33493859Sml29623 	/*
33503859Sml29623 	 * Load TXDMA descriptors, buffers, mailbox,
33513859Sml29623 	 * initialise the DMA channels and
33523859Sml29623 	 * enable each DMA channel.
33533859Sml29623 	 */
33543859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "TxDMA channel enable..."));
33553859Sml29623 	status = nxge_enable_txdma_channel(nxgep, channel,
33566929Smisaki 	    tx_ring_p, tx_mbox_p);
33573859Sml29623 	MUTEX_EXIT(&tx_ring_p->lock);
33583859Sml29623 	if (status != NXGE_OK)
33593859Sml29623 		goto fail;
33603859Sml29623 
33613859Sml29623 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
33626929Smisaki 	    "Recovery Successful, TxDMAChannel#%d Restored",
33636929Smisaki 	    channel));
33643859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_txdma_fatal_err_recover"));
33653859Sml29623 
33663859Sml29623 	return (NXGE_OK);
33673859Sml29623 
33683859Sml29623 fail:
33693859Sml29623 	MUTEX_EXIT(&tx_ring_p->lock);
33707906SMichael.Speer@Sun.COM 
33713859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL,
33726929Smisaki 	    "nxge_txdma_fatal_err_recover (channel %d): "
33736929Smisaki 	    "failed to recover this txdma channel", channel));
33743859Sml29623 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Recovery failed"));
33753859Sml29623 
33763859Sml29623 	return (status);
33773859Sml29623 }
33783859Sml29623 
33796495Sspeer /*
33806495Sspeer  * nxge_tx_port_fatal_err_recover
33816495Sspeer  *
33826495Sspeer  *	Attempt to recover from a fatal port error.
33836495Sspeer  *
33846495Sspeer  * Arguments:
33856495Sspeer  * 	nxgep
33866495Sspeer  *
33876495Sspeer  * Notes:
33886495Sspeer  *	How would a guest do this?
33896495Sspeer  *
33906495Sspeer  * NPI/NXGE function calls:
33916495Sspeer  *
33926495Sspeer  * Registers accessed:
33936495Sspeer  *
33946495Sspeer  * Context:
33956495Sspeer  *	Service domain
33966495Sspeer  */
33973859Sml29623 nxge_status_t
33983859Sml29623 nxge_tx_port_fatal_err_recover(p_nxge_t nxgep)
33993859Sml29623 {
34006495Sspeer 	nxge_grp_set_t *set = &nxgep->tx_set;
34016495Sspeer 	nxge_channel_t tdc;
34026495Sspeer 
34036495Sspeer 	tx_ring_t	*ring;
34046495Sspeer 	tx_mbox_t	*mailbox;
34056495Sspeer 
34063859Sml29623 	npi_handle_t	handle;
34076495Sspeer 	nxge_status_t	status;
34086495Sspeer 	npi_status_t	rs;
34093859Sml29623 
34103859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "<== nxge_tx_port_fatal_err_recover"));
34113859Sml29623 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34126495Sspeer 	    "Recovering from TxPort error..."));
34136495Sspeer 
34146495Sspeer 	if (isLDOMguest(nxgep)) {
34156495Sspeer 		return (NXGE_OK);
34166495Sspeer 	}
34176495Sspeer 
34186495Sspeer 	if (!(nxgep->drv_state & STATE_HW_INITIALIZED)) {
34196495Sspeer 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
34206495Sspeer 		    "<== nxge_tx_port_fatal_err_recover: not initialized"));
34216495Sspeer 		return (NXGE_ERROR);
34226495Sspeer 	}
34236495Sspeer 
34246495Sspeer 	if (nxgep->tx_rings == 0 || nxgep->tx_rings->rings == 0) {
34256495Sspeer 		NXGE_DEBUG_MSG((nxgep, TX_CTL,
34266495Sspeer 		    "<== nxge_tx_port_fatal_err_recover: "
34276495Sspeer 		    "NULL ring pointer(s)"));
34286495Sspeer 		return (NXGE_ERROR);
34296495Sspeer 	}
34306495Sspeer 
34316495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
34326495Sspeer 		if ((1 << tdc) & set->owned.map) {
34336495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
34346495Sspeer 			if (ring)
34356495Sspeer 				MUTEX_ENTER(&ring->lock);
34366495Sspeer 		}
34376495Sspeer 	}
34383859Sml29623 
34393859Sml29623 	handle = NXGE_DEV_NPI_HANDLE(nxgep);
34406495Sspeer 
34416495Sspeer 	/*
34426495Sspeer 	 * Stop all the TDCs owned by us.
34436495Sspeer 	 * (The shared TDCs will have been stopped by their owners.)
34446495Sspeer 	 */
34456495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
34466495Sspeer 		if ((1 << tdc) & set->owned.map) {
34476495Sspeer 			ring = nxgep->tx_rings->rings[tdc];
34486495Sspeer 			if (ring) {
34496495Sspeer 				rs = npi_txdma_channel_control
34506495Sspeer 				    (handle, TXDMA_STOP, tdc);
34516495Sspeer 				if (rs != NPI_SUCCESS) {
34526495Sspeer 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34536495Sspeer 					    "nxge_tx_port_fatal_err_recover "
34546495Sspeer 					    "(channel %d): stop failed ", tdc));
34556495Sspeer 					goto fail;
34566495Sspeer 				}
34576495Sspeer 			}
34583859Sml29623 		}
34593859Sml29623 	}
34603859Sml29623 
34616495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "Reclaiming all TDCs..."));
34626495Sspeer 
34636495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
34646495Sspeer 		if ((1 << tdc) & set->owned.map) {
34656495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
34667906SMichael.Speer@Sun.COM 			if (ring) {
34676495Sspeer 				(void) nxge_txdma_reclaim(nxgep, ring, 0);
34687906SMichael.Speer@Sun.COM 			}
34693859Sml29623 		}
34703859Sml29623 	}
34713859Sml29623 
34723859Sml29623 	/*
34736495Sspeer 	 * Reset all the TDCs.
34743859Sml29623 	 */
34756495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "Resetting all TDCs..."));
34766495Sspeer 
34776495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
34786495Sspeer 		if ((1 << tdc) & set->owned.map) {
34796495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
34806495Sspeer 			if (ring) {
34816495Sspeer 				if ((rs = npi_txdma_channel_control
34826929Smisaki 				    (handle, TXDMA_RESET, tdc))
34836495Sspeer 				    != NPI_SUCCESS) {
34846495Sspeer 					NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
34856495Sspeer 					    "nxge_tx_port_fatal_err_recover "
34866495Sspeer 					    "(channel %d) reset channel "
34876495Sspeer 					    "failed 0x%x", tdc, rs));
34886495Sspeer 					goto fail;
34896495Sspeer 				}
34906495Sspeer 			}
34916495Sspeer 			/*
34926495Sspeer 			 * Reset the tail (kick) register to 0.
34936495Sspeer 			 * (Hardware will not reset it. Tx overflow fatal
34946495Sspeer 			 * error if tail is not set to 0 after reset!
34956495Sspeer 			 */
34966495Sspeer 			TXDMA_REG_WRITE64(handle, TX_RING_KICK_REG, tdc, 0);
34973859Sml29623 		}
34986495Sspeer 	}
34996495Sspeer 
35006495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "Restarting all TDCs..."));
35016495Sspeer 
35026495Sspeer 	/* Restart all the TDCs */
35036495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
35046495Sspeer 		if ((1 << tdc) & set->owned.map) {
35056495Sspeer 			ring = nxgep->tx_rings->rings[tdc];
35066495Sspeer 			if (ring) {
35076495Sspeer 				mailbox = nxge_txdma_get_mbox(nxgep, tdc);
35086495Sspeer 				status = nxge_init_fzc_txdma_channel(nxgep, tdc,
35096495Sspeer 				    ring, mailbox);
35106495Sspeer 				ring->tx_evmask.value = 0;
35116495Sspeer 				/*
35126495Sspeer 				 * Initialize the event masks.
35136495Sspeer 				 */
35146495Sspeer 				status = nxge_init_txdma_channel_event_mask
35156495Sspeer 				    (nxgep, tdc, &ring->tx_evmask);
35166495Sspeer 
35176495Sspeer 				ring->wr_index_wrap = B_FALSE;
35186495Sspeer 				ring->wr_index = 0;
35196495Sspeer 				ring->rd_index = 0;
35206495Sspeer 
35216495Sspeer 				if (status != NXGE_OK)
35226495Sspeer 					goto fail;
35236495Sspeer 				if (status != NXGE_OK)
35246495Sspeer 					goto fail;
35256495Sspeer 			}
35263859Sml29623 		}
35276495Sspeer 	}
35286495Sspeer 
35296495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "Re-enabling all TDCs..."));
35306495Sspeer 
35316495Sspeer 	/* Re-enable all the TDCs */
35326495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
35336495Sspeer 		if ((1 << tdc) & set->owned.map) {
35346495Sspeer 			ring = nxgep->tx_rings->rings[tdc];
35356495Sspeer 			if (ring) {
35366495Sspeer 				mailbox = nxge_txdma_get_mbox(nxgep, tdc);
35376495Sspeer 				status = nxge_enable_txdma_channel(nxgep, tdc,
35386495Sspeer 				    ring, mailbox);
35396495Sspeer 				if (status != NXGE_OK)
35406495Sspeer 					goto fail;
35416495Sspeer 			}
35426495Sspeer 		}
35433859Sml29623 	}
35443859Sml29623 
35453859Sml29623 	/*
35466495Sspeer 	 * Unlock all the TDCs.
35473859Sml29623 	 */
35486495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
35496495Sspeer 		if ((1 << tdc) & set->owned.map) {
35506495Sspeer 			tx_ring_t *ring = nxgep->tx_rings->rings[tdc];
35516495Sspeer 			if (ring)
35526495Sspeer 				MUTEX_EXIT(&ring->lock);
35533859Sml29623 		}
35543859Sml29623 	}
35553859Sml29623 
35566495Sspeer 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Tx port recovery succeeded"));
35573859Sml29623 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_tx_port_fatal_err_recover"));
35583859Sml29623 
35593859Sml29623 	return (NXGE_OK);
35603859Sml29623 
35613859Sml29623 fail:
35626495Sspeer 	for (tdc = 0; tdc < NXGE_MAX_TDCS; tdc++) {
35636495Sspeer 		if ((1 << tdc) & set->owned.map) {
35646495Sspeer 			ring = nxgep->tx_rings->rings[tdc];
35656495Sspeer 			if (ring)
35666495Sspeer 				MUTEX_EXIT(&ring->lock);
35673859Sml29623 		}
35683859Sml29623 	}
35693859Sml29623 
35706495Sspeer 	NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "Tx port recovery failed"));
35716495Sspeer 	NXGE_DEBUG_MSG((nxgep, TX_CTL, "==> nxge_tx_port_fatal_err_recover"));
35723859Sml29623 
35733859Sml29623 	return (status);
35743859Sml29623 }
35753859Sml29623 
35766495Sspeer /*
35776495Sspeer  * nxge_txdma_inject_err
35786495Sspeer  *
35796495Sspeer  *	Inject an error into a TDC.
35806495Sspeer  *
35816495Sspeer  * Arguments:
35826495Sspeer  * 	nxgep
35836495Sspeer  * 	err_id	The error to inject.
35846495Sspeer  * 	chan	The channel to inject into.
35856495Sspeer  *
35866495Sspeer  * Notes:
35876495Sspeer  *	This is called from nxge_main.c:nxge_err_inject()
35886495Sspeer  *	Has this ioctl ever been used?
35896495Sspeer  *
35906495Sspeer  * NPI/NXGE function calls:
35916495Sspeer  *	npi_txdma_inj_par_error_get()
35926495Sspeer  *	npi_txdma_inj_par_error_set()
35936495Sspeer  *
35946495Sspeer  * Registers accessed:
35956495Sspeer  *	TDMC_INJ_PAR_ERR (FZC_DMC + 0x45040) TDMC Inject Parity Error
35966495Sspeer  *	TDMC_INTR_DBG	DMC + 0x40060 Transmit DMA Interrupt Debug
35976495Sspeer  *	TDMC_INTR_DBG	DMC + 0x40060 Transmit DMA Interrupt Debug
35986495Sspeer  *
35996495Sspeer  * Context:
36006495Sspeer  *	Service domain
36016495Sspeer  */
36023859Sml29623 void
36033859Sml29623 nxge_txdma_inject_err(p_nxge_t nxgep, uint32_t err_id, uint8_t chan)
36043859Sml29623 {
36053859Sml29623 	tdmc_intr_dbg_t		tdi;
36063859Sml29623 	tdmc_inj_par_err_t	par_err;
36073859Sml29623 	uint32_t		value;
36083859Sml29623 	npi_handle_t		handle;
36093859Sml29623 
36103859Sml29623 	switch (err_id) {
36113859Sml29623 
36123859Sml29623 	case NXGE_FM_EREPORT_TDMC_PREF_BUF_PAR_ERR:
36133859Sml29623 		handle = NXGE_DEV_NPI_HANDLE(nxgep);
36143859Sml29623 		/* Clear error injection source for parity error */
36153859Sml29623 		(void) npi_txdma_inj_par_error_get(handle, &value);
36163859Sml29623 		par_err.value = value;
36173859Sml29623 		par_err.bits.ldw.inject_parity_error &= ~(1 << chan);
36183859Sml29623 		(void) npi_txdma_inj_par_error_set(handle, par_err.value);
36193859Sml29623 
36203859Sml29623 		par_err.bits.ldw.inject_parity_error = (1 << chan);
36213859Sml29623 		(void) npi_txdma_inj_par_error_get(handle, &value);
36223859Sml29623 		par_err.value = value;
36233859Sml29623 		par_err.bits.ldw.inject_parity_error |= (1 << chan);
36243859Sml29623 		cmn_err(CE_NOTE, "!Write 0x%llx to TDMC_INJ_PAR_ERR_REG\n",
36256929Smisaki 		    (unsigned long long)par_err.value);
36263859Sml29623 		(void) npi_txdma_inj_par_error_set(handle, par_err.value);
36273859Sml29623 		break;
36283859Sml29623 
36293859Sml29623 	case NXGE_FM_EREPORT_TDMC_MBOX_ERR:
36303859Sml29623 	case NXGE_FM_EREPORT_TDMC_NACK_PREF:
36313859Sml29623 	case NXGE_FM_EREPORT_TDMC_NACK_PKT_RD:
36323859Sml29623 	case NXGE_FM_EREPORT_TDMC_PKT_SIZE_ERR:
36333859Sml29623 	case NXGE_FM_EREPORT_TDMC_TX_RING_OFLOW:
36343859Sml29623 	case NXGE_FM_EREPORT_TDMC_CONF_PART_ERR:
36353859Sml29623 	case NXGE_FM_EREPORT_TDMC_PKT_PRT_ERR:
36363859Sml29623 		TXDMA_REG_READ64(nxgep->npi_handle, TDMC_INTR_DBG_REG,
36376929Smisaki 		    chan, &tdi.value);
36383859Sml29623 		if (err_id == NXGE_FM_EREPORT_TDMC_PREF_BUF_PAR_ERR)
36393859Sml29623 			tdi.bits.ldw.pref_buf_par_err = 1;
36403859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_MBOX_ERR)
36413859Sml29623 			tdi.bits.ldw.mbox_err = 1;
36423859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_NACK_PREF)
36433859Sml29623 			tdi.bits.ldw.nack_pref = 1;
36443859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_NACK_PKT_RD)
36453859Sml29623 			tdi.bits.ldw.nack_pkt_rd = 1;
36463859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_PKT_SIZE_ERR)
36473859Sml29623 			tdi.bits.ldw.pkt_size_err = 1;
36483859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_TX_RING_OFLOW)
36493859Sml29623 			tdi.bits.ldw.tx_ring_oflow = 1;
36503859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_CONF_PART_ERR)
36513859Sml29623 			tdi.bits.ldw.conf_part_err = 1;
36523859Sml29623 		else if (err_id == NXGE_FM_EREPORT_TDMC_PKT_PRT_ERR)
36533859Sml29623 			tdi.bits.ldw.pkt_part_err = 1;
36545125Sjoycey #if defined(__i386)
36555125Sjoycey 		cmn_err(CE_NOTE, "!Write 0x%llx to TDMC_INTR_DBG_REG\n",
36566929Smisaki 		    tdi.value);
36575125Sjoycey #else
36583859Sml29623 		cmn_err(CE_NOTE, "!Write 0x%lx to TDMC_INTR_DBG_REG\n",
36596929Smisaki 		    tdi.value);
36605125Sjoycey #endif
36613859Sml29623 		TXDMA_REG_WRITE64(nxgep->npi_handle, TDMC_INTR_DBG_REG,
36626929Smisaki 		    chan, tdi.value);
36633859Sml29623 
36643859Sml29623 		break;
36653859Sml29623 	}
36663859Sml29623 }
3667